PFZheng / psutil

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

Process number of context switches #302

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Proposal
Add the possibility to determine the number of context switches executed by a 
given process:
http://www.linfo.org/context_switch.html
http://en.wikipedia.org/wiki/Context_switch
What a user might typically want to do with them is to monitor a process and 
figure out the increase rate of ctx switches every second.

On what platforms would this be available?
All

Proposed API
>>> p = psutil.Process(pid)
>>> p.get_num_ctx_switches()
ctxs(voluntary=9123, involuntary=1238)
>>>

The voluntary/involuntary distinction should exist in the UNIX world only.
On Windows we can fill 'voluntary' and leave 'involuntary' to 0.

Are there existent implementations we can use as an example?
On Windows this can be determined by using SYSTEM_PROCESS_INFORMATION struct:
http://alax.info/blog/1182
On Linux we read /prof as always.
Still haven't looked into BSD/OSX but it's very likely they are exposed.

Original issue reported on code.google.com by g.rodola on 11 Jul 2012 at 3:10

GoogleCodeExporter commented 9 years ago
Fixed in r1438 (Linux), r1439 (BSD), r1440 (OSX), r1441 (Windows).
'involuntary' field is set to 0 on OSX and Windows.

Original comment by g.rodola on 12 Jul 2012 at 5:03

GoogleCodeExporter commented 9 years ago
Fixed in version 0.6.0, released just now.

Original comment by g.rodola on 13 Aug 2012 at 4:25

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r1438 == revision baacf9660220

Original comment by g.rodola on 2 Mar 2013 at 12:10