Windows – How to measure context switching overhead on windows

windows

Is it possible to check how much cpu time context switching is taking on windows, or better yet, an .net process?

Best Answer

Performance Monitor can be used to see the % processor time and # of context switches. The context switch counts are available in either:

  • System\Context Switches/sec counter reports system wide context switches.
  • Thread(_Total)\Context Switches/sec counter reports the total number of context switches generated per second by all threads

Context switch overhead is low but if you see a much higher number at the same time as % processor time spikes then you can start troubleshooting what is occurring at that time. Other counters can help with narrowing down what the problem might be - for example Processor Queue Length.

Ref: TechNet Monitoring Context Switches

As well from another article on Context Switches:

You can determine whether context switching is excessive by comparing it with the value of Processor\% Privileged Time. If this counter is at 40 percent or more and the context-switching rate is high, then you can investigate the cause for high rates of context switches.