我正在向我的 c# 项目添加一些性能计数器,并正在创建一个新的 PerformanceCounterCategory。在这个类别中,我希望有多个计数器/计时器来跟踪不同的事情。我需要使用多个平均计时器,并试图了解当 CoutnerCreationDataCollection 中有多个平均计时器时,AverageBase 计数器如何与正确的 AverageTimer32 计数器相关联。
几个问题:
1. 首先,这是正确的做法吗?我发现的样本都只有一个平均计时器。
2. 如果第一个问题的答案是肯定的,那么我认为在 AverageTimer32 之后添加到集合中的第一个 AverageBase 计数器是否正确?我确实在一篇文章中找到了需要按顺序添加它们的参考。
这是我正在尝试做的一个例子:
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);