CountPerTimeInterval32 может использоваться для измерения среднего количества элементов в очереди за интервал времени.Вы хотите RateOfCountsPerSecond32.
Настройка:
const string CATEGORY_NAME = "AAA - My Own Perf Counter Category";
const string CATEGORY_HELPTEXT = "My own perf counter category to study effects of using different perf counter types.";
const string COUNTER_NAME = "RateOfCountsPerSecond32";
const string COUNTER_HELPTEXT = "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.";
// This should be in an installer class and run during your application set up - do not set up and them immediately use the counter.
if (!PerformanceCounterCategory.Exists(CATEGORY_NAME))
{
var counters = new CounterCreationDataCollection();
var rateOfCounts32 = new CounterCreationData();
rateOfCounts32.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
rateOfCounts32.CounterName = COUNTER_NAME;
rateOfCounts32.CounterHelp = COUNTER_HELPTEXT;
counters.Add(rateOfCounts32);
// You could set up a multi instance category. I'm using single instance for brevity.
PerformanceCounterCategory.Create(CATEGORY_NAME, CATEGORY_HELPTEXT, PerformanceCounterCategoryType.SingleInstance, counters);
}
Использование:
public void OnSomeEvent(object sender, EventArgs e)
{
using (var counter = new PerformanceCounter(CATEGORY_NAME, COUNTER_NAME, false))
{
counter.Increment();
}
// do your stuff here...
}