How to use AverageTimer32 and AverageBase performance counters with System.Diagnostics.Stopwatch?

前端 未结 3 1563
北恋
北恋 2021-02-02 10:15

When I execute the following program and look at the performance counter the results don\'t make sense to me. The average value is zero and the min/max values are ~0.4 when I w

3条回答
  •  灰色年华
    2021-02-02 11:02

    Mark Seemann explained the confusing source of the problem but I would like to provide a little bit of additional information.

    If you want to set your AverageTimer32 performance counter from a TimeSpan and not a Stopwatch you can perform the following conversion:

    var performanceCounterTicks = timeSpan.Ticks*Stopwatch.Frequency/TimeSpan.TicksPerSecond;
    averageTimerCounter.IncrementBy(performanceCounterTicks);
    averageTimerCounterBase.Increment();
    

提交回复
热议问题