Detecting context switching

The Performance Monitoring program (perfmon.exe) is useful in determining how many context switches are occurring per second. In Windows 2000 the Performance Monitoring program is located in the Administrative Tools group under Programs in the Start menu. Figure 1.4 shows the impact of executing the program in listing 1.9.

The four "bumps" in the graph occurred during the time between when Created x Workers was written to the console and when Stopped x Workers was written to the console. Not surprisingly, the execution of zero workers did not produce a bump.

Figure 1.4 Performance Monitor during listing 1.9. The "bumps" correspond to the time between Created and Stopped.

Figure 1.5

The Add Counter dialog box used to add Context Switches / sec to a Performance Monitor graph

Measuring the number of context switches that occur per second is a good way of troubleshooting an application. Figure 1.5 shows how to add the measure to Performance Monitor.

The OS determines when a context switch occurs. A thread can give the scheduler a hint that it has finished performing its operations, but it's up to the scheduler to determine if it will perform the context switch.

For more information on context switches, time slices, and thread scheduling, consult any book that covers the Windows platform.

0 0

Post a comment

  • Receive news updates via email from this site