Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do performance counter average timers get associated with their base?

I am adding some performance counters to my c# project and am creating a new PerformanceCounterCategory. In this category, I would like to have multiple counters/timers that track different things. I have a need to use multiple average timers and am trying to understand how the AverageBase counter gets associated with the correct AverageTimer32 counter when there are more than one in the CoutnerCreationDataCollection.

A couple of questions:
1. First, is this a correct way to do it? The samples I have found all have only one average timer.
2. And if the answer to the first question is yes, then am I correct in thinking that the first AverageBase counter added to the collection following the AverageTimer32? I did find a reference in an article to them needing to be added in order.

Here's an example of what I am trying to do:

var dataColl = new CounterCreationDataCollection
{
  new CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageTimer32,
    CounterName = "AverageTime1",
    CounterHelp = "AverageTime1_Help"
  },
  new CounterCreationData           // Does this get linked to AverageTime1 simply
                                    // because it is being added after it?
  {
    CounterType = PerformanceCounterType.AverageBase,
    CounterName = "AverageTime1Base"
  },
  new CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageTimer32,
    CounterName = "AverageTime2",
    CounterHelp = "AverageTime2_Help"
  },
  new CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageBase,
    CounterName = "AverageTime2_Base"
  },
}

PerformanceCounterCategory.Create(
                            "MyCategoryName"
                            , "My Category Help"
                            , PerformanceCounterCategoryType.SingleInstance
                            , dataColl);
like image 538
Alex Avatar asked Mar 10 '10 17:03

Alex


1 Answers

Position. The counters that require a base need to be followed immediately by the base in the definition list. So your code is correct, you have two AverageTimer32, each followed by AverageBase.

As a side note, when you'll get bored of typing the same code over and over again, you should consider Using XSLT to generate Performance Counters code.

like image 57
Remus Rusanu Avatar answered Sep 19 '22 16:09

Remus Rusanu