Performance Counters Pattern
public class PerformanceCounters {
static readonly string category = "MVC Folgers Seal Inspection";
public PerformanceCounter ImagesInspected;
public PerformanceCounter ImagesInspectedRate;
public PerformanceCounters() {
if (!PerformanceCounterCategory.Exists(category)) CreateCategory();
ImagesInspected = new PerformanceCounter(category, "Images Inspected", false);
ImagesInspectedRate = new PerformanceCounter(category, "Images Inspected Rate", false);
}
private void CreateCategory() {
CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
// Add ImagesInspected counter.
ccdc.Add(new CounterCreationData
( "Images Inspected"
, "The number of images inspected."
, PerformanceCounterType.NumberOfItems32
));
// Add the ImagesInspectedRate counter.
ccdc.Add(new CounterCreationData
( "Images Inspected Rate"
, "The number of images inspected per second."
, PerformanceCounterType.RateOfCountsPerSecond32
));
// Create the category.
PerformanceCounterCategory.Create
( category
, "Counters provided by the Folgers Seal Inspection machine vision application."
, ccdc
);
}
}
To use a performance counter, do something like:
pcs = new PerformanceCounters();
pcs.ImagesInspected.Increment();