- Frugal Cafe
- Posts
- FC29: Reading/parsing PerformanceCounterCategory
FC29: Reading/parsing PerformanceCounterCategory
Thousands of PerformanceCounter data in a single read
In FC03 Most PerformanceCounter usages are wrong (beehiiv.com), we discussed PerformanceCounter is a very inefficient API to use because single read actually reads data for all instances in the same category. In its replacement, PerformanceCounterCategory is suggested.
Now let’s write some real code to read and parse PerformanceCounterCategory data. Here is the data structure:
We have a dictionary of performance counter instance readings grouped by process name, and an array of counter names.
Here is reading/parsing logic:
To use the data, we simply write it to csv file:
Now we can use it to get thousands of performance counter instances:
Output:
Notice there are 6,888 instances in Process category alone. The first usage is very slow. close to 1 second here, because PerformanceCounterLib needs to initialize its category table.
Here is .NET CLR Memory performance counters in Excel (trimmed):
Two processes are having issues with high GC time, InterllicodeModelService is having large LOH heap segment. Lots of useful information.