Search code examples
c#.netperfmon

Reading Perfmon Counters for ".NET CLR Exceptions" Category


I am trying to read perfmon counters for category ".NET CLR Exceptions". Below is code for same. What I am seeing is looks like different data being shown in Windows Perfmon counter and console application I built.

PerformanceCounterCategory netClrExceptionCat = new PerformanceCounterCategory(".NET CLR Exceptions");
foreach (PerformanceCounter counter in netClrExceptionCat.GetCounters("_Global_"))
{
    Console.WriteLine(string.Format("  Counter: {0} : Value : {1}", counter.CounterName, counter.RawValue));
}

enter image description here

I would appreciate if someone can please point me to right direction in case I am doing something wrong here.


Solution

  • Notice that the discrepancy is on the derived "per second" values. These kinds of counters are somewhat counterintuitive. The OS does not keep a standard instantaneous value for you to obtain. Keeping track of the elapsed time and performing division is done in the application consuming the counter. For example, if you query the counter with a delay of 5 seconds between calls, your application divides the difference of the counter's raw value by 5. Now, your application will not be using the exact same delay or even likely capture any of the samples at the same time. Therefore, your values will be anywhere from slightly or vastly different.