我有一个更新两个性能计数器值的 WCF 服务。第一个定义为 NumberOfItems64,第二个定义为 RateOfCountsPerSecond64。当我更新它们的值时(我每秒执行几次),perfmon 会按预期显示第一个计数器的正确值,但总是说第二个计数器的值为 0。当我调试代码时,我可以看到第二个计数器的 RawValue 属性按预期更新...
这是我创建计数器的 PowerShell 代码:
$categoryName = "My category"
$exists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
if ($exists)
{
[System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName)
}
$counters = new-object System.Diagnostics.CounterCreationDataCollection
$counter = new-object System.Diagnostics.CounterCreationData
$counter.CounterType = [System.Diagnostics.PerformanceCounterType]::NumberOfItems64
$counter.CounterName = "# ops"
$counters.Add($counter)
$counter = new-object System.Diagnostics.CounterCreationData
$counter.CounterType = [System.Diagnostics.PerformanceCounterType]::RateOfCountsPerSecond64
$counter.CounterName = "# ops/sec"
$counters.Add($counter)
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryName, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters)
这是我更新计数器值的代码:
long value = GetValue();
counter1.IncrementBy(value);
counter2.IncrementBy(value);
我在 StackOverflow 上发现了这个问题,看起来和我的很相似:RateOfCountsPerSecond32 类型的计数器总是显示 0,但它不能解决我的问题。
任何的想法 ?