Written by

DBA at WebMais Sistemas
Question Lucas Fernandes · 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.

Comments

Sergei Shutov · Aug 15, 2018

Did you check GetCPUTime() method of that class?

0
Lucas Fernandes  Aug 16, 2018 to Sergei Shutov

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

0
Sergei Shutov  Aug 16, 2018 to Lucas Fernandes

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.

0
Lucas Fernandes  Aug 17, 2018 to Sergei Shutov

Nice! I was looking for something like that.

0
Eduard Lebedyuk · Aug 16, 2018

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.

0