Skip to content

Process number of context switches #302

Closed
@giampaolo

Description

From g.rodola on July 11, 2012 17:10:37

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: http://code.google.com/p/psutil/issues/detail?id=302

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions