Developing with Windows Performance Monitor Counters

By Dalton Roll | August 28, 2018

Microsoft’s preferred tool to measure the performance of Windows systems is the Performance Monitor. It provides an analysis chart view with metrics for the Last, Average, Minimum and Maximum values of the performance counters from an imported performance Binary Log File (.blg).

The Performance Monitor is a nice tool to view one file at a time, but sometimes it can become time consuming and limited. However, there is good news. Windows Performance monitor counters can be extracted and developed by software to provide automation and customization.

PowerShell

PowerShell is a Microsoft task-based command-line shell and scripting language, and it can be used to parse performance counter instances into objects imported from performance files. Also, it is able to convert Binary Log Files (.blg) into a few other formats, such as Comma Separate Values (.csv) for easier viewing or another software compatibility.

The following is an example from Microsoft of using PowerShell to select data from a performance file and export it to a new file:

Developing with Windows

Click here for more information from Microsoft on Import-Counter.

The Problem with PowerShell

When importing and parsing performance counter instances into objects, it is possible to access the value of each one. Therefore, it is easy enough to calculate straightforward metrics for a data set including Last, Minimum, and Maximum. The not so straightforward metric to calculate is average.

When calculating the average of performance counters, it is important to consider the cardinality of the data. It is even more important when calculating against counters whose values are already an average, such as, the Avg. Disk sec/Read counter. Hence, the above two reasons are why it is confusing to calculate the averages of performance counters. The standard formula for average: total sum/number of items – will not be the correct representation of values from the Performance Monitor. Microsoft recommends developers to use PdhComputeCounterStatistics to correctly calculate averages from performance counter data.

Note: Along with PowerShell, if a user tries to calculate averages after converting a performance file to CSV, it will be incorrect as well.

PdhComputeCounterStatistics (C++)

PdhComputeCounterStatistics is a part of the Windows application programming interface. It can be accessed and used when developing a Microsoft C++ project. It is Microsoft’s recommendation when calculating averages for performance counter data.

To dig in a little further for developers, the PdhComputeCounterStatistic is a C++ function that computes statistics for a certain performance counter from an array of raw values. It then returns a structure that holds the counter statistics – Last, Average, Minimum, Maximum.

The following is the documented syntax from Microsoft for the PdhComputeCounterStatsitcs function.

Developing with Windows

If you want to learn more about Developing with Windows Performance Counters, Click here for more information about these functions, or hit the contact us form below to talk with us.


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!