Sunday, 5 June 2016

Measuring CPU performance from the CommandLine using PerfMon

In a previous post, I talked about viewing "coarse grained CPU performance" of an application using Process Explorer. It's a great way of checking "at a glance" how a process is performing CPU wise.

However, if you want to get down with the nitty-gritty details of your server's performance, you need to bring out the big guns and use the built-in perfmon utility.

I don't know why, but I always find perfmon fiddly to use. Maybe it's just me! Anyway, in this post I just wanted to describe the batch-file I use to test a server's health.

As you know, you can drive perfmon from the GUI by running the perfmon.exe command from the start menu. When you do, you will be presented with this screen:


To get started, first use the logman create command to setup the perflog. In the instance below I have named the log "ocean_airdrop_log" and assigned 2 counters to it.
logman create counter ocean_airdrop_log -c "\Processor(_Total)\% Processor Time" "\Memory\Pool Paged Bytes"  -f csv -o D:\PerfMonLogs\oceanairdrop 
The two counters I have selected are:
"\Processor(_Total)\% Processor Time"
"\Memory\Pool Paged Bytes"

I am also outputting the results to a .csv file. A .csv file is better for analyzing the output. This .csv file gets outputted to the directory "D:\PerfMonLogs" and starts each file with the name oceanairdrop.

Once you run this command, you see the log created in the perfmon window under "User Defined" collector sets.


The next command sets the sample interval for performance log. In this case I am logging every 60 seconds.
logman update ocean_airdrop_log -si 60
Next, we start the log by running the start command:
logman start ocean_airdrop_log
If you have the perfmon window open, you will see the status of the log change to running.


At this point you will see the log file created in the output directory we have specified.


At this point you can stop here and continue to run this perf log for as long as you need.

In my batch file I make a call to the timeout command. This allows you to pause a batch file for a specified period of time (it's very useful).
timeout /t 300
For example, this command waits for 5 mins (60 secs *5 = 300)


Finally, to stop the perflog from running issue this command:
logman stop ocean_airdrop_log

Full Batch Perf-Script


With that, here's the full batch script:
-- Delete the perflog if it already exists
logman delete ocean_airdrop_log

-- Create the perflog selecting the counters want to include
logman create counter ocean_airdrop_log -c "\Processor(_Total)\% Processor Time" "\Memory\Pool Paged Bytes"  -f csv -o D:\PerfMonLogs\oceanairdrop 

-- Set the sample interval time. (this is every 60 seconds)
logman update ocean_airdrop_log -si 60

-- Start the perflog
logman start ocean_airdrop_log

-- Wait for 5 mins
timeout /t 300

-- Stop the perflog
logman stop ocean_airdrop_log

-- Delete the perflog
logman delete ocean_airdrop_log

Summary


There you have it. Having the above perf-script handy that you can run ad-hoc is very useful when diagnosing server performance issues.
Contact Me:  ocean.airdrop@gmail.com

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages