Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Performance monitoring is typically directed at entire systems; for example, administrators often monitor such things as the available bytes of memory or total processor use on a computer. This kind of monitoring is extremely useful because it identifies problems, such as rapid diminution of available memory, that can have a detrimental effect on the performance of the computer itself. However, monitoring performance of the system as a whole typically does not indicate why memory is diminishing. To help answer that question, you can monitor the performance of individual processes.
Monitoring the performance of individual processes is particularly useful when you are trying to identify memory leaks. To help diagnose memory leaks in Windows 2000, you can monitor several process properties, including:
All of these key indicators of process performance can be monitored by using WMI. A list of important process properties available through the Win32_Process class is shown in Table 14.1.
Table 14.1 WMI Win32_Process Properties
Property | Description |
---|---|
ExecutablePath | Local path to the executable file. |
ExecutionState | Current status of the process. Valid values are: 0 Unknown 1 Other 2 Ready 3 Running 4 Blocked 5 Suspended Blocked 6 Suspended Ready |
KernelModeTime | Kernel mode usage, in milliseconds. |
Name | Name of the executable file responsible for the process, equivalent to the Image Name property in Task Manager. The name is hard-coded into the application itself and is not affected by changing the file name. For example, even if you rename Calc.exe, the name Calc.exe will still appear in Task Manager and in any WMI scripts that retrieve the process name. |
PageFaults | Number of page faults generated by the process. |
PageFileUsage | Amount of page file space (in kilobytes) currently used by the process. |
PeakWorkingSetSize | Maximum size of the working set (in kilobytes) used by the process since it was created. |
Priority | Scheduling priority of the process. Priorities range from 0 (lowest priority) to 31 (highest priority). |
ProcessID | Numeric identifier used to distinguish one process from another. ProcessIDs are valid from process creation time to process termination. Upon termination, that same numeric identifier can be applied to a new process. This means that you cannot use ProcessID alone to monitor a particular process. For example, an application could have a ProcessID of 7, and then fail. When a new process is started, the new process could be assigned ProcessID 7. A script that checked only for a specified ProcessID could thus be "fooled" into thinking that the original application was still running. |
QuotaNonPagedPoolUsage | Quota of nonpaged pool usage available to the process. |
QuotaPagedPoolUsage | Quota of paged pool usage available to the process. |
ThreadCount | Number of active threads associated with a process. Each process must have at least one thread. |
UserModeTime | User mode usage (in milliseconds). |
WorkingSetSize | Amount of memory (in bytes) the process needs to execute efficiently. If adequate memory is not available, "disk thrashing" occurs. (Disk thrashing refers to those times when the operating system must repeatedly access the hard disk.) |
Process performance can be monitored in several different ways, including:
Listing 14.4 contains a script that monitors process performance information. To carry out this task, the script must perform the following steps:
Listing 14.4 Monitoring Process Performance
|
|
The script shown in Listing 14.4 is designed to display process information once and then terminate. Alternatively, you might want to view process performance over time. To do this, include a For-Next loop in your script, and use the Wscript.Sleep command to pause the script for the appropriate interval. For example, the script shown in Listing 14.5 runs 10 times, displaying the current process data each time, and pauses 60 seconds (60,000 milliseconds) before retrieving updated process information.
Listing 14.5 Monitoring Process Performance Over Time
|
|
Listing 14.6 contains a script that monitors processor use by process. To carry out this task, the script must perform the following steps:
Together, KernelModeTime and UserModeTime tell you the total amount of processor time allocated to a process. To ensure that these values are added and not concatenated, use the VBScript function CSng to convert the variant data to the single data type.
Processor use times are reported in 100-nanosecond increments. (A nanosecond is one-billionth of a second; 100 nanoseconds equal one ten-millionth of a second.) This calculation results in processor use being reported in seconds.
Listing 14.6 Monitoring Processor Use by Process
|
|
Send us your feedback | « Previous | Next » |