How to count context switching programmatically?

Does Windows have a programmatic count of context switches for the same process? The best thing is a callback that gets called whenever the thread switches.

+3


source to share


2 answers


There is a performance counter that does your job. All you have to do is read its value. You can find a description of how to do this interactively here , but performance counters can also be used using their API.



+7


source


The problem with counting your own context switches is that you can switch contexts while counting them! Worse, your own counting code subtracts from the amount of time your own process has, so you can execute less in a single loop of context.



As On Friend (+1) says, use a performance counter instead that counts contexts at a higher level.

+2


source







All Articles