Skip to content
ikopylov edited this page Dec 24, 2014 · 3 revisions

##Steps:

  • add reference to performance counters library;
  • define category with required counters:
internal class TestSingleInstance: SingleInstanceCategoryWrapper
{
    public TestSingleInstance() : base("SingleInstance", "For tests") { }

    [Counter("Test NumberOfItemsCounter")]
    public NumberOfItemsCounter Count { get; private set; }
}
  • define your counters container (if you need a singleton):
internal class PerfCounters: Qoollo.PerformanceCounters.PerfCountersContainer
{
    private static TestSingleInstance _singleInstance = CreateNullCategoryWrapper<TestSingleInstance>();
    public static TestSingleInstance TestSingle { get { return _singleInstance; } }

    public static void Init(CategoryWrapper parent)
    {
        _singleInstance = parent.CreateSubCategory<TestSingleInstance>();
    }
}
  • create counters factory on application start-up and initialize you PerfCounters container:
var counterFactory = new WinCounterFactory();
// or load from App.config:
// var counterFactory = PerfCountersInstantiationFactory.CreateCounterFactoryFromAppConfig("PerfCountersConfigurationSection");

PerfCounters.Init(counterFactory.CreateRootWrapper());
counterFactory.InitAll();
  • use counters anywhere you want:
PerfCounters.TestSingle.Count.Increment();
  • don't forget to dispose counters factory when application is closing:
counterFactory.Dispose();
Clone this wiki locally