我正在爲我的c#項目添加一些性能計數器,並且正在創建一個新的PerformanceCounterCategory。在這個類別中,我想要有多個跟蹤不同事物的計數器/定時器。我需要使用多個平均計時器,並試圖瞭解在CoutnerCreationDataCollection中有多個計數器時,AverageBase計數器如何與正確的AverageTimer32計數器關聯。性能計數器平均計時器如何與其基數關聯?
幾個問題:
1.首先,這是做一個正確的方法是什麼?我發現的樣本都只有一個平均計時器。
2.如果第一個問題的答案是肯定的,那麼我是否認爲第一個AverageBase計數器添加到AverageTimer32之後的集合中?我確實在文章中找到了需要按順序添加的參考。
這裏是什麼,我試圖做一個例子:
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);