Developing with Windows Performance Monitor Counters

by | Updated March 28, 2019 | Development, Dynamics 365 for Finance and Operations

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 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.

Related Posts

  • I've been thoroughly enjoying my new Windows 8 phone, and I wanted to take a minute to share some good resources I've found on these phones.  First, this comparison chart…

  • With the announcement of the release of Microsoft Dynamics AX 2012 R2, Microsoft released an updated system requirements document for AX 2012:  Windows 2012 Server is now supported, but…

  • Today's the big day for Microsoft as Windows 8 is launching.  Many of my Facebook friends have taken pictures of their new Windows Surface machines - I think they have…


Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


06oct10:00 am10:30 amPreview of D365 Business Central Fall Release Features and Functionality

06oct12:00 pm12:30 pmInsider's Guide to New Features Available in the Fall Release of D365 Finance and Supply Chain

07oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Technical

13oct12:00 pm12:30 pmWave 2 Release – What’s Coming for Dynamics 365 Sales and Customer Service

21oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Functional

26oct(oct 26)9:00 am28(oct 28)5:00 pmStoneridge Connect Leadership and Community Conference


04nov11:00 am12:00 pmConfab LIVE with Stoneridge - Challenging the Development Paradigm

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!