Question
· Aug 15, 2018

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.

Discussion (6)2
Log in or sign up to continue

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.