如何性能计数器平均计时器得到与他们的基地相关联?他们的、计时器、相关联、计数器

2023-09-03 05:46:26 作者:本是薄凉之人却恋妳成痴

我加入了一些性能计数器,我的C#项目,并正在创建一个新的PerformanceCounterCategory。在这一类别中,我想有多个计数器/追踪不同的东西定时器。我有一个需要使用多个平均定时器和想了解如何AverageBase柜台获取与当有多个在CoutnerCreationDataCollection正确AverageTimer32计数器相关。

几个问题:  1.首先,这是做一个正确的方法是什么?我发现所有样本都只有一个平均的定时器。  2.如果回答的第一个问题是肯定的,那么我是正确的思维,第一AverageBase计数器添加到下面的AverageTimer32集合?我发现在一篇​​文章中他们需要为了加入一个参考。

下面是什么,我试图做一个例子:

  VAR Datacoll中=新CounterCreationDataCollection
{
  新CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageTimer32,
    CounterName =AverageTime1
    CounterHelp =AverageTime1_Help
  },
  新CounterCreationData //这是否获取链接到AverageTime1简单
                                    //因为它是后添加?
  {
    CounterType = PerformanceCounterType.AverageBase,
    CounterName =AverageTime1Base
  },
  新CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageTimer32,
    CounterName =AverageTime2
    CounterHelp =AverageTime2_Help
  },
  新CounterCreationData
  {
    CounterType = PerformanceCounterType.AverageBase,
    CounterName =AverageTime2_Base
  },
}

PerformanceCounterCategory.Create(
                            MyCategoryName
                            ,我的类别帮助
                            ,PerformanceCounterCategoryType.SingleInstance
                            ,Datacoll中);
 

解决方案

位置。需要碱的计数器必须紧接着所述基座在所述定义列表。所以,你的code是正确的,你有两个AverageTimer32,每个随后AverageBase。

作为一个方面说明,当你厌倦了一遍又一遍键入相同的code,你应该考虑的使用XSLT生成性能计数器code 。

计时器 计数器 计时器 计数器 计时器 计数器

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

解决方案

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.