Analyzing Processor Activity
After observing the threads that use the greatest amount of processor time, monitor the dispatch states of the threads. This tells you which threads are running and which threads are ready. Most important, monitoring thread states on your system can help you identify which threads are piling up in the queue and which threads are actively running at various times.
The Thread\Thread State counter provided by System Monitor reports the current execution state (also known as dispatch state) of a thread. System Monitor reports thread state as a numeric value from 0 through 7, corresponding to whether the thread is ready, running, terminated, and so on.
Table 29.3 lists the typical thread states.
Table 29.3 Typical Thread States
Thread State |
Description |
Comments |
---|---|---|
0 |
Initialized |
|
1 |
Ready |
The thread is prepared to run on the next available processor. |
2 |
Running |
|
3 |
Standby |
The thread is about to use the processor. |
4 |
Terminated |
|
5 |
Waiting |
The thread is not ready to run, typically because another operation (for example, involving I/O) must finish before the thread can run. |
6 |
Transition |
The thread is not ready to run because it is waiting for a resource (such as code being paged in from disk). |
7 |
Unknown |
The thread is in an unknown state. |
To determine which threads are contending for the processor, track the states of all threads in the system by using System Monitor. Figure 29.15 shows a histogram. The vertical maximum for the chart is set to 10 to make it easier to see the values; an alternative for easier viewing is to display the thread-state values in a report view.
Figure 29.15 Display of Thread States
Notice that the preceding figure plots a thread of the MMC process with the steady value of 2 for running. This is the thread of the System Monitor snap-in that is collecting the data that you are monitoring. As long as System Monitor is running, one of its threads shows as running. Other threads state values alternate between 1 for ready and 5 for waiting.
Plotting thread-state data in a chart rather than a histogram might make it easier to view the switching of thread states. Note in Figure 29.16 how a processs thread moves from the waiting state (plotted on the chart at 5) to the ready state (plotted on the chart at 1).
Figure 29.16 Changing Thread States
To find out how long each thread remains in a particular state, define log settings with a tab-separated (TSV) or comma-separated (CSV) file format and include Thread\ Thread State. When the log is completed, import the file into Microsoft Excel. A sample log is shown in Figure 29.17.
Figure 29.17 Sample Log Output Viewed in Microsoft Excel
By looking at log output, you can get an idea of the length of time that a thread remains in a state by determining the number of seconds that elapsed until the threads state changed. However, it is important to note that, because sampling omits some data, you might not see all the state changes that occur.
In addition, the Thread\Thread Wait State counter and Perfmon4.exe on the Windows 2000 Resource Kit companion CD give you information about why a thread is in a waiting state.
The value reported for Thread Wait Reason is a code. The Counters Help file on the Windows 2000 Resource Kit companion CD provides descriptions for these codes.