tigerneil / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Implement process CPU kernel/user times #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Implement a method to determine the amount of time that a process has
executed in kernel/user mode.

Original issue reported on code.google.com by billiej...@gmail.com on 7 Mar 2009 at 3:15

GoogleCodeExporter commented 9 years ago
Implemented on Windows as r224.
Since this is the first time I put hands on C code a review would be needed.

Original comment by billiej...@gmail.com on 7 Mar 2009 at 3:17

GoogleCodeExporter commented 9 years ago
Implemented on Linux as r225.

Original comment by billiej...@gmail.com on 7 Mar 2009 at 1:00

GoogleCodeExporter commented 9 years ago
Implemented on FreeBSD as r238. Note that get_cpu_percent() returns results 
different
from top/ps since we are calculating it from raw data rather than using the 
kernel's
"pctcpu" value used by top/ps. Not sure if this is better or worse in the long 
run,
it may be necessary in the future to implement a platform-specific 
get_cpu_percent()
for FreeBSD to return the value from pctcpu.

Original comment by jlo...@gmail.com on 9 Mar 2009 at 3:44

GoogleCodeExporter commented 9 years ago
Well we've got a problem with this on OS X. To read this data you need 
task_for_pid()
which requires the user or application to be a member of the procmod group, or 
the
script must be run as root. 

The best we can do is raise AccessDenied appropriately but it means psutil 
simply
won't be able to get CPU (or memory) data for a process unless psutil is being
executed in a root context or at the very least, as a member of procmod group.

Original comment by jlo...@gmail.com on 13 Mar 2009 at 4:28

GoogleCodeExporter commented 9 years ago
IMO, it would make sense implementing CPU times this way by raising 
AccessDenied when
necessary, closing out this issue as fixed and opening a new one as reminder in 
case
we discover a task_for_pid() replacement.

Original comment by billiej...@gmail.com on 13 Mar 2009 at 4:58

GoogleCodeExporter commented 9 years ago
Documentation and docstrings should also be updated to reflect this behavior.

Original comment by billiej...@gmail.com on 13 Mar 2009 at 5:00

GoogleCodeExporter commented 9 years ago
I wouldn't bother opening a new issue for it, there's nothing wrong with using 
the
appropriate OS system calls so we'll just treat it as a known issue and leave 
it at that.

In r255 I've removed get_cpu_times/create_time from the __str__() method and 
wrapped
cpu times in a try/except in the Process constructor to account for this. I 
have not
yet implemented the code into the OS X module but once I do the _psutil module 
should
be ready for it at least.

Original comment by jlo...@gmail.com on 13 Mar 2009 at 5:15

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 17 Mar 2009 at 4:15

GoogleCodeExporter commented 9 years ago
Implemented on OS X as r270.
Closing out this one.

Original comment by billiej...@gmail.com on 20 Mar 2009 at 9:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r224 == revision 74261592f147
r225 == revision e7ec84bc5f8e
r238 == revision 1e121fde0c0e
r255 == revision 134cd2857e1a
r270 == revision de3eed0d4a28

Original comment by g.rodola on 2 Mar 2013 at 11:46