profesorfalken / jProcesses

Get crossplatform processes details with Java
Apache License 2.0
63 stars 26 forks source link

Time under windows #9

Closed Gobliins closed 8 years ago

Gobliins commented 8 years ago

Process startTime returns only hh:mm:ss instead of a complete date.

I fixed this in my Programm inside WindowsProcessesService.java by adding the missing vlaues:

`private static String normalizeValue(String origKey, String origValue) { ..... if ("CreationDate".equals(origKey)) { if (!origValue.isEmpty()) { String year = origValue.substring(0, 4); String month = origValue.substring(4, 6); String day = origValue.substring(6, 8); String hour = origValue.substring(8, 10); String minutes = origValue.substring(10, 12); String seconds = origValue.substring(12, 14);

            return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
        }
    }`
profesorfalken commented 8 years ago

Hi!, Yes I remember now... I had done it on purpose, because on Linux/bsd/mac systems we only have the time and I wanted to be consistent in the date format for all operating systems.

I will think a little bit how to solve it (another field windows specific maybe...). I will keep you updated.

Thank you

profesorfalken commented 8 years ago

Hi again, I have created a map that stores specific data that is not common in all OS. In the case of full process starting time, you could retrieve it just doing:

processInfo.getExtraData().get("start_datetime"));

In relation with perfomance, I have seen that I perform two calls. One to recover 90% of information and another expensive call only to recover user name and CPU usage. If this data is not strictly necessary to you you can just avoid this check using:

JProcesses.fastMode = true;
//And then use JProcesses normally

You should experiment an improvement of at least 2x in performance.

Here you are the snapshot version to tests this changes: https://oss.sonatype.org/content/repositories/snapshots/org/jprocesses/jProcesses/1.4-SNAPSHOT/jProcesses-1.4-20160419.192659-1.jar

If it is OK for you, I will build the 1.4 version.

Thank you

Gobliins commented 8 years ago

Ok i have tried it, yes it runs much faster and the date comes out correctly. N1 one. Before you release 1.4 however, i think i have an issue under Linux which i would like to share if i am sure that it's not a problem of my environment.

profesorfalken commented 8 years ago

Ok I close this issue then

Gobliins commented 8 years ago

JProcesses.fastMode is not available in Jprocesses 1.5, also the getExtraData("start_datetime") is missing under linux

profesorfalken commented 8 years ago

Hello,

The fastMode still exist, but the way to call it is more integrated in the API.

For example:

JProcesses.get().fastMode().getProcessList();

As I had stated above in my first response, "on Linux/bsd/mac systems we only have the time", not the date. The map is normally used to store data that is specific to a system.

Gobliins commented 8 years ago

Ok when i understand ocrrectly:

//Use BSD sytle to get data in order to be compatible with Mac Systems(thanks to jkuharev for this tip)
private static final String PS_COLUMNS = "pid,ruser,vsize,rss,%cpu,start,cputime,nice,ucomm";
private  ps -ewo pid,lstart,cmd
final String PS_FULL_COMMAND = "pid,command";

with this:

ps -ewo pid,lstart,cmd

the lstart parameter gives day and time.

I think i will rewrite the code to use it, maybe you think about using also date and time. Background is: we need to identify processes, and the PID is not enough since a process could end and a process with same PID can start again. Therefore we need to check the start time.

profesorfalken commented 8 years ago

Ok I will take a look

Thanks for the info

profesorfalken commented 8 years ago

In this version you should have the "start_datetime" in the map and will come exactly with the same format as the windows implementation.

https://oss.sonatype.org/content/repositories/snapshots/org/jprocesses/jProcesses/1.6-SNAPSHOT/jProcesses-1.6-20160610.200328-4.jar

Gobliins commented 8 years ago

Hi, i tried it under Windows it's working and under Linux it's working "sometimes".... ..and on some processes i get:

Jun 20, 2016 9:38:05 AM org.jutils.jprocesses.util.ProcessesUtils parseUnixLongTimeToFullDate SCHWERWIEGEND: null java.text.ParseException: Unparseable date: "10 Sun Apr 10 00:14:31" at java.text.DateFormat.parse(DateFormat.java:366) at org.jutils.jprocesses.util.ProcessesUtils.parseUnixLongTimeToFullDate(ProcessesUtils.java:171) at org.jutils.jprocesses.info.UnixProcessesService.parseList(UnixProcessesService.java:68) at org.jutils.jprocesses.info.AbstractProcessesService.getList(AbstractProcessesService.java:54) at org.jutils.jprocesses.info.AbstractProcessesService.getList(AbstractProcessesService.java:46) at org.jutils.jprocesses.info.AbstractProcessesService.getList(AbstractProcessesService.java:36) at org.jutils.jprocesses.JProcesses.getProcessList(JProcesses.java:61) at main.App.main(App.java:19)

profesorfalken commented 8 years ago

This is strange. Normally the date with lstart should return the format: "10 Sun Apr 10 00:14:31 2016" but in this case you do not have the year: "10 Sun Apr 10 00:14:31"

This makes the parsing fail because it tries to format from: "EEE MMM dd HH:mm:ss yyyy"

Can you try this code?: https://oss.sonatype.org/content/repositories/snapshots/org/jprocesses/jProcesses/1.6-SNAPSHOT/jProcesses-1.6-20160702.134629-5.jar

Gobliins commented 8 years ago

Hello, i will try the jar in the next days, we have server release atm and i am very busy recently

profesorfalken commented 8 years ago

Hi, No problem. Do it when you can.

Joholland commented 8 years ago

I ran into the same issue and found the root cause. It is a off by one on the index, because PS is not consistent about returning the start column.

https://github.com/profesorfalken/jProcesses/issues/15

profesorfalken commented 8 years ago

Yes, I confirm that it is the same problem.

I close them this issue and I will handle/fix it in #15