Most developers are somehow familiar with Performance Monitor (often called PerfMon). Perfmon is a built-in windows tool that allows you to measure system performance (hardware, software services and applications) and help to determine the cause of performance problems.
I used it sporadically for many years but I never spend some time to explore the tool in-depth. Turns out that there are some unknown features that are quite useful and can be really handy during performance investigations and dealing with support issues.
Let me share some with you.
Sampling frequency and duration
By default, Perfmon is sampling every seconds with a duration of 100 seconds. This duration is often too short for any meaningful investigation problem so it’s important to change it with a more appropriate value.
To do it, right-click on Performance Monitor, click Properties and then set the graph elements properties.
Copy and Paste performance counters
It is possible to save performance counter settings into a file and later copy and paste them. This is well documented in Performance Monitor Tips and Tricks with John Rodriguez.
Sadly, at the time of writing, this behavior appears to be broken in Windows 10.
Record your performance analysis using Data Collector Sets
At work, on the SQL Monitor project, sometimes I had to deal with some customers having a performance problem. They often send screenshots of Perfmon after running it for few minutes on their system. Sometimes this is enough but it is usually more useful to actually get the full data.
Most people don’t know that you can actually record your performance analysis into a log file and send that file to anyone to open with PerfMon. Data Collector Sets are the way to do it.
You start creating a new Data Collector Set.
Give it a name, select Create Manually (Advanced) and click Next.
Select Create data logs, check Performance Counters and then click Next.
Add all the performance counters you want to monitor.
Finally, specify the root directory where the logs will be saved and click Finish.
You can open the properties to further customize it.
You can configure it to run automatically on a particular schedule, add a stop condition and add even tasks to run when the collection stops that might copy the results into a centralized shared folder or upload it somewhere. It is quite flexible. I invite you to explore all the options in the various tabs.
You can manually start the collection at any time. Right click on your custom collector and then click Start. Similarly, you can stop it clicking Stop.
After the analysis is completed, you can copy the folder and send it to the support team or whoever need to analyze your data on an another machine.
Loading performance analysis data from log files
These are the steps to analyze a performance counter log that someone provided you:
- Click on the Performance Monitor node
- Click on the data collector set icon in the toolbar or use the CTRL + L shortcut
- In the Data source section, select Log files and click Add
- Add as many log files as you want
The result is an empty screen. This is a bit confusing. By default, the tool does not add any counters. You need to explicitly add the counters you are interested in using the green Plus icon in the toolbar.
You will only be able to select, the counters that has being collected in the log file.
You can now explore the data as you like and do your performance investigation.
Performance Monitor is a low-level tool that is available in any version of Windows. Even if you can find more high level commercial performance analysis tools, I think it is important to learn how to use the out-of-the-box tools available on Windows. This post wanted to show you some of the useful features that this tool can provides you, features that sometimes are not as intuitive as you expect and are often unknown to many windows users and developers. I personally think that the ability to save a performance session and open it at a later time is extremely useful and I didn’t know it was possible till now. Hope you find it useful too.
There is certainly more to explore, but that is something for future posts.
Thank you very much for your write-up. I would you like to ask you a question. I’m building a windows service application with C# and I want to learn this service performance through use PerfMon. Is it possible or not ?
Also how can I make it ?
You are welcome. If you are using WCF to implement your service you can use various perfmon counters as described here https://msdn.microsoft.com/en-us/library/ms735098(v=vs.110).aspx. Otherwise you need to create your custom performance counters that is relatively easy to do https://msdn.microsoft.com/en-us/library/ms735098(v=vs.110).aspx For general information about performance of services you can also consider using Process Explorer from sysinternals https://technet.microsoft.com/en-us/sysinternals/processexplorer.aspx?f=255&MSPPError=-2147217396