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

隐身守侯 提交于 2020-01-01 07:35:48

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/2418998/how-do-performance-counter-average-timers-get-associated-with-their-base

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!