You want to monitor a process for CPU consumption, usually because you suspect the process is causing issues. Quite often, this process is a Windows Service.
There is no standard top.exe for Windows like there is for Linux/UNIX, so this is a little more complicated on Windows.
One solution is to use perfmon.exe to create a Counter Log for the monitored process and to save the perfmon log to a CSV. The CSV can then be monitored. As an example, let’s monitor a process named test.exe.
- Click on Start, Run, and enter “perfmon”
- Click on Performance Logs and Alerts
- Click on Counter Logs
- Right-click Counter Logs
- Click New Log Settings
- Enter a log name that makes sense, e.g., Monitor Test.exe CPU
- The Counter Log configuration dialog opens
- On the General tabl, click Add Counters..
- Click “Use local computer counters”
- Choose Process for Performance Object
- Select % Processor Time for Select counters from list
- Select Test from Select instances from list
- Click Add
- Click Close
- For Interval, choose something logical, such as 15 minutes
- Click the Log Files tab
- Choose a Log File Type of “Text File (Command delimited)”
- Choose the file destination directory in Location
- Click Ok
- Determine whether (and how) you want the log file to rotate with “End file names with..”
- Click Ok
You now have a CSV that will contain the date and CPU% for the process. An example entry:
“(PDH-CSV 4.0) (Central Standard Time)(360)”,”\LOCALHOSTProcess(test)% Processor Time”
“03/07/2011 13:13:55.759″,” ”
To get a running average of CPU%, you would run to average out the usage for a given period of time. An easier solution would be to average a certain number of rows at the end, e.g., find the sum of the last 4 rows of the CSV and divide by 4 to get the average over an hour (assuming perfmon polls the CPU once every 15 minutes).