Recipe6.8.Viewing the Performance Statistics of a Process


Recipe 6.8. Viewing the Performance Statistics of a Process

Problem

You want to view the memory, I/O, and CPU statistics of a process. This is useful if you want to examine the resources a process is using. If you find that you are running low on memory on a particular system, it can often be attributed to a single process that has consumed a large amount. If you can terminate that process, the system should go back to a stable state.

Solution

Using a graphical user interface

  1. Open the Sysinternals Process Explorer tool (procexp.exe).

  2. Double-click the process you want to view.

  3. The Performance tab contains the process properties.

This information can also be viewed using Windows Task Manager (taskmgr.exe). After starting taskmgr.exe, click on the Processes tab. Select View Using a command-line interface

The following command displays all of the performance metrics for a process:

> pslist -x <ProcessName>

Replace <ProcessName> with the name of the process without its extension. For example:

> pslist -x iexplore

Using VBScript
' This code displays the performance stats of a process. ' ------ SCRIPT CONFIGURATION ------ intPID = 3280  ' PID of target process strComputer = "." ' ------ END CONFIGURATION --------- WScript.Echo "Process PID: " & intPID set objWMIProcess = GetObject("winmgmts:\\" & strComputer & _                       "\root\cimv2:Win32_Process.Handle='" & intPID & "'") arrProps = Array("Name", "KernelModeTime", "UserModeTime", _                  "MaximumWorkingSetSize", "MinimumWorkingSetSize", _                  "PageFaults", "PageFileUsage", "VirtualSize", _                  "WorkingSetSize", "PeakPageFileUsage", "PeakVirtualSize", _                  "PeakWorkingSetSize", "PrivatePageCount", _                  "QuotaNonPagedPoolUsage", "QuotaPagedPoolUsage", _                  "QuotaPeakNonPagedPoolUsage", "QuotaPeakPagedPoolUsage", _                  "ThreadCount") for each strProp in arrProps     WScript.Echo strProp & ": " & objWMIProcess.Properties_(strProp) next

Discussion

If you need to get serious about analyzing performance statistics for one or more processes, you should consider using Performance Monitor (perfmon.exe). With the Process performance object (click the little + icon in the System Monitor and select Process under Performance object), you can graph a variety of metrics for individual processes or all of them together using the _Total instance.

Even if you don't want to use Performance Monitor to monitor processes, the tool provides some good information about process metrics, such as Working Set. Click the Explain button when you view the Process performance object, which will cause another dialog to appear that contains additional information about what each counter means. These counters are mostly the same ones as you'll find in Task Manager, pslist, and Win32_Process.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net