AdHocInstrumentation - mwpowellhtx/MeasureIt GitHub Wiki
For simple applications, then this is probably sufficient for you.
Reference MeasureIt.Castle.Interception
when you want ad-hoc instrumentation.
Package | References |
---|---|
MeasureIt.Castle.Interception |
MeasureIt.Core |
MeasureIt.Core |
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.
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!