Get the total amount of time a process is active

Hi

I want to get the total amount of time that a process is active or the timestamp that it was created/started.

I tried the %SYS.ProcessQuery class, but I did not find any related information.

Is there any way to get this information from a process?

I'm using Caché 2017.

  • 0
  • 0
  • 103
  • 4
  • 2

Answers

This info does not seem to be available by default.

You can define JOB^%ZSTART that would set global:

Set ^TimeStarted($job) = $h

And JOB^%ZSTOP:

Kill ^TimeStarted($job)

And reference this global to get process start time.

Did you check GetCPUTime() method of that class?

I tried this method. But it seems that it returns from the current process, not from the referenced process.

%SYS>s p1 = ##class(%SYS.ProcessQuery).Open("P3276") w p1.GetCPUTime()
63,47
%SYS>s p2 = ##class(%SYS.ProcessQuery).Open("P7796") w p2.GetCPUTime()
63,47
%SYS>w ##class(%SYS.ProcessQuery).GetCPUTime()
63,47

%SYS>s p1 = ##class(%SYS.ProcessQuery).Open("P3276") w p1.GetCPUTime()
63,47
%SYS>s p2 = ##class(%SYS.ProcessQuery).Open("P7796") w p2.GetCPUTime()
78,47
%SYS>w ##class(%SYS.ProcessQuery).GetCPUTime()
78,47

%SYS>s p1 = ##class(%SYS.ProcessQuery).Open("P3276") w p1.GetCPUTime()
78,47
%SYS>s p2 = ##class(%SYS.ProcessQuery).Open("P7796") w p2.GetCPUTime()
78,47
%SYS>w ##class(%SYS.ProcessQuery).GetCPUTime()
78,47

You can use $zu function directly with third parameter

$ZU(171,1) returns CPU time (in milliseconds) on any OS, as a string in format SYS_time,USER_time
$ZU(171,1,pid) returns total CPU time (system + user) for process pid.

However this will return CPU time -- the time CPU was actually serving the process, not the time since process was started (when process is idle, this counter does not increase). Eduard's solution would be better if you need the total time.