What I would like to do is write a small program that continuously live counts the number of context switches that a specific process experiences per a sufficiently small unit of time. I have observed this functionality within the software “Process Explorer”, so I know it is definitely possible.
Unfortunately, I have very little idea of how to begin coding this and have so far been unable to find any helpful code snippets online. Thus, a small working example implementing a per process and per unit time live context switch count would be immensely helpful for me.
Here’s one way to do it – This will print the amount of context switches used by thread 0 of notepad (you can substitute any process and thread number you want in the CounterPathBuffer initialization) every second:
Most of the code is from this source: msdn.microsoft.com/en-us/library/aa371886%28v=vs.85%29.aspx. I would like to shorten the amount of time between consecutive checks on the context switches (make it less than a second). If anyone has any ideas as to how to do this, that’d be great.