Developing with Windows Performance Monitor Counters

by | Aug 28, 2018 | 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.


Submit a Comment

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

Upcoming Events


28may1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Designing the Software Collaboratively


02jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Conference Room Pilots

03jun10:00 am10:30 amWhy Levridge Grain? Streamlining Sales Contracts

04jun11:00 am12:00 pmConfab With Stoneridge - Livestream - Customer Insights

04jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Dealing with Challenges Mid-Project

09jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Customizations vs Configurations and How You Manage Them

10jun10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Buyer

11jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Data Migration - Early and Often

15jun(jun 15)9:00 am16(jun 16)4:00 pmDynamics 365 Finance and Supply Chain Management Training for AX 2012 Developers

16jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Environment Management and Deployments

17jun10:00 am10:30 amWhy Levridge Grain? Best Practices for Managing Load Orders for Grain Processors

17jun12:00 pm1:00 pmMobilizing an efficient, streamlined AP department with AP Automation

17jun2:00 pm3:00 pmGuide for B2B Businesses: Tackling Supply Chain Optimization and Customer Experience Challenges

18jun11:00 am12:00 pmConfab with Stoneridge - Livestream - Enterprise Asset Management and Preventative Maintenance

18jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Testing - Definition and Activities

23jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Training for All

24jun10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Production Manager

25jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Going Live

30jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Hypercare

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!