Scripting Perfmon


Scripting Perfmon


We have a test team in India that I would like to run some load and performance testing. They have access to the required test server and load tools but limited experience using tools such as perfmon.


I have previously only used Perfmon to take a real-time view of performance counters, or used the ui to configure logging to a data file for later evaluation. In this particular case I didn't have access to the test server to enable me to manually configure the logging, and I know that trying to walk someone through this on the phone would be painful. After a little searching the web I discovered that it's possible to script the perfmon counter logging - exactly what I needed!


I started by creating a config file containing the counters that I wished to monitor. I called this baseling.cfg . It simply contains a unique line for each counter to be logged, as follows:


"\Memory\Available MBytes"

"\Memory\Pool Nonpaged Bytes"

"\Memory\Pool Paged Bytes"

"\PhysicalDisk(*)\Current Disk Queue Length"

"\PhysicalDisk(*)\Disk Reads/sec"

"\PhysicalDisk(*)\Disk Reads Bytes/sec"

"\PhysicalDisk(*)\Disk Writes/sec"

"\PhysicalDisk(*)\Disk Writes Bytes/sec"

"\Process(*)\% Processor Time"

"\Process(*)\Private Bytes

"\Process(*)\Virtual Bytes"


I then created a batch file containing the required command line to setup the data capture. I called the file create_data_collector.bat, it contains the following:


logman create counter BASELINE -f bincirc -max 200 -si 00:00:05 --v -o "c:\perfmon\serverbaseline" -cf "c:\perfmon\baseline.config"


To find out what the various parameters mean and other options available just run a quick google for 'logman'. In my particular case:


  •  I am creating a data collector called 'BASELINE', logging to file up to a max size of 200mb
  • The file is binary circular file, meaning that once it reaches maximum size it will begin overwriting the oldest records within the file
  •  The log is to be updated every 5 seconds
  • The file will be output to the folder c:\perfmon\serverbaseline
  • Counters to include in the log are contained within the previously mentioned configuration file: "c:\perfmon\baseline.config"


On first running the batch file locally (to test it) I received a message telling me that the data capture vehicle couldn't be created because of a permissions issue. I adjusted the permissions to the logging folder "c:\perfmon\serverbaseline" and all was good.


All that remained was to script to start the data collection. For this I created the batch file start_collector.bat, containing the following single line:


  • logman.exe start baseline


A few minutes after starting the logging I could see the log file beginning to grow. Great, I thought! I went back to the perfmon ui, clicked the 'view log data' button (looks like a db drum) and selected my new and continually growing log file. It didn't complain, and the current data view was cleared - but where was the historic data that should be been logged? I opened the log file in notepad - just binary data. I wanted to check that it was logging the data I expected so I deleted the BASELINE data collector, then re-created, choosing to log to text file, rather than binary. I then started logging, gave it a few minutes and opened the newly logged data in notepad. It appeared just as I expected, with column headers for my counters and lots of data for each subsequent row.


Great - I was logging the data but couldn't get it to appear in the perfmon graph! Then it struck me, in addition to choosing the data file as the data source for the perfmon graph I needed to add the counters to the graph. I hit the add button on the toolbar (+ symbol) and was presented with a dialog offering a limited set of counters - just the ones I'd specified in the baseline.cfg file. After selecting the counters, my historic data was displayed in the graph. Such a result called for celebratory cup of tea!




I've now also started working on a script to run a SQL profiler trace. My initial results were disappointing, the trace file was generated but my filters were not applied.


I had used the profiler UI to generate the script: file\export\script trace definition. Unfortunately, it seems that there's a bug in SQL 2005 which means that the script generated by this option will OR each of your filters. For details see


Print | posted on Wednesday, July 8, 2009 3:17 PM


# re: Scripting Perfmon

left by Matt Nolan at 1/5/2010 5:34 AM Gravatar
Wow thanks, this was really helpful and exactly what I was after. Cheers

# re: Scripting Perfmon

left by Kotsumo at 1/27/2010 6:36 PM Gravatar
Thank you. You were first in google, and this will really help us collect data without worrying about having IT do things wrong

# re: Scripting Perfmon

left by Ladislav at 2/3/2010 9:30 PM Gravatar
Thank you, this is really great place to get ideas about the automatic performance data collection possibilities.

# re: Scripting Perfmon

left by used backhoe loader at 2/21/2010 8:50 AM Gravatar
Google told they will include website load speed into ranking algoritm. so this should help.

# re: Scripting Perfmon

left by shopping cart reviews at 5/25/2010 5:24 AM Gravatar
It is already included. Speed is important factor

# re: Scripting Perfmon

left by orchid delivery at 9/26/2010 10:26 PM Gravatar
nice tutorial, thanks

# re: Scripting Perfmon

left by Poker training at 1/3/2011 1:50 AM Gravatar
nice, it works

# re: Scripting Perfmon

left by deta at 1/14/2011 9:12 PM Gravatar
Thanks for the tutorial. Well done!

# re: Scripting Perfmon

left by Razikh at 4/25/2011 1:48 AM Gravatar
Thanks for the writeup! It did help me get started with perfmon scripting :)

# re: Scripting Perfmon

left by Luiz Break at 6/6/2012 11:17 AM Gravatar
Thanks for this great article... it was saving me some much time in research. I am definitely using your technique. Cheers

# re: Scripting Perfmon

left by Arnab at 7/23/2012 8:51 AM Gravatar
nice article...

# re: Scripting Perfmon

left by Pirate at 7/27/2012 5:54 PM Gravatar
thanks... :)

# re: Scripting Perfmon

left by Pachiappan at 5/2/2014 1:57 PM Gravatar
Thanks Rob,
Its very helpful for beginner like me.

# re: Scripting Perfmon

left by Tim at 6/3/2014 9:58 PM Gravatar
Nice write up. What permissions did you have to alter so that you could run the script?

# re: Scripting Perfmon

left by natalie at 12/30/2014 1:27 PM Gravatar
change create_data_collector.bat to:
logman create counter BASELINE -f csv -max 200 -si 00:00:05 --v -o "%LOCALAPPDATA%\Velocity\perfmon\serverbaseline" -cf "c:\perfmon\baseline.cfg"

# re: Scripting Perfmon

left by David at 4/24/2015 3:53 PM Gravatar
I discovered that for counters that contained a % sign I had to enter a double percent sign %% into the file to escape the character. If you do a logman query BASELINE you can see what counters the system thinks you are wanting so check those carefully. The target system is XP-64. I assume the same would apply for other windows systems.
Post A Comment