Skip to content

AdHocInstrumentation

Michael Powell edited this page Jan 30, 2017 · 11 revisions

Ad-Hoc Instrumentation

For simple applications, then this is probably sufficient for you.

NuGet packages

Reference MeasureIt.Castle.Interception when you want ad-hoc instrumentation.

Package References
MeasureIt.Castle.Interception
MeasureIt.Core
Castle.Core
MeasureIt.Core

Decorate your classes

Decorate your methods as such. Parameters are fine, as well as asynchronous methods.

[MeasurePerformance(
    categoryType: typeof(DefaultPerformanceCounterCategoryAdapter)
    , adapterType: typeof(TotalMemberAccessesPerformanceCounterAdapter)
    )]
public void YourMethod()
{
}

In this case, the category is identified by the DefaultPerformanceCounterCategoryAdapter category adapter and we would like to measure using the TotalMemberAccessesPerformanceCounterAdapter counter adapter.

Feel free to explore the options of the MeasurePerformanceAttribute at your convenience.

Wire up the object to be measured

Any class object will do.

class MyObject()
{
    [MeasurePerformance(...)]
    public void MyMeasuredCall()
    {
    }
}

And starting from an instance.

var myObj = new MyObject();

Then you need a measurement provider. This assumes that you have prepared a IRuntimeInstrumentationDiscoveryService and IInstrumentationDiscoveryOptions instances. Depending on the circumstance, you may want to use the IInstallerInstrumentationDiscoveryService instead to also install and/or uninstall the your categories. Under dependency injection scenarios, these should be connected for you. But under ad-hoc conditions, that preparation is up to you.

var measurementProvider = new InterceptionMeasurementProvider(
    discoveryOptions, discoveryService);

Now connect measurement to the instance and call the measured method.

var wiredObj = myObj.MeasureSingleInstance(measurementProvider);
wiredObj.MyMeasuredCall();

Happy measuring! Cheers!