Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

waxtell/Aop.Profiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aop.Profiler

Aspect Oriented Performance Profiler. Supports synchronous and asynchronous actions and functions.

Build status NuGet Badge Coverage Status

Explicit Parameter Matching

[Fact]
public void MethodNameMatchesInvokedMethod()
{
    var eventCount = 0;
    object methodName = null;

    var proxy = new PerMethodAdapter<IForTestingPurposes>
                    (
                        Process.Lean(EventProcessor)
                    )
                    .Profile(x => x.MethodCall(0,"zero"), CaptureOptions.MethodName)
                    .Adapt(new ForTestingPurposes());


    proxy.MethodCall(0, "zero");

    Assert.Equal(1, eventCount);
    Assert.Equal(nameof(ForTestingPurposes.MethodCall), methodName);

    void EventProcessor(IDictionary<string, object> @event)
    {
        eventCount++;
        methodName = @event[nameof(CaptureOptions.MethodName)];
    }
}

Fuzzy Parameter Matching

[Fact]
public void SerializedResultMatchesFuzzyInvokedMethodResult()
{
    var eventCount = 0;
    object serializedResult = null;

    var proxy = new PerMethodAdapter<IForTestingPurposes>
                    (
                        Process.Lean(EventProcessor)
                    )
                    .Profile(x => x.MethodCall(It.IsAny<int>(), It.IsAny<string>()), CaptureOptions.SerializedResult)
                    .Adapt(new ForTestingPurposes());

    var result = proxy.MethodCall(7, "eight");

    Assert.Equal(1, eventCount);
    Assert.Equal(result, JsonConvert.DeserializeObject((string)serializedResult));

    void EventProcessor(IDictionary<string, object> @event)
    {
        eventCount++;
        serializedResult = @event[nameof(CaptureOptions.SerializedResult)];
    }
}

Per Instance (All actions/methods profiled)

[Fact]
public async Task DefaultOptionsYieldExpectedDictionarySize()
{
    var eventCount = 0;
    var itemCount = 0;

    var proxy = new PerInstanceAdapter<IForTestingPurposes>
                    (
                        Process.Lean(EventProcessor)
                    )
                    .Adapt(new ForTestingPurposes());

    await proxy.AsyncAction(0, "zero");

    Thread.Sleep(1000);

    Assert.Equal(1, eventCount);
    Assert.Equal(BitFunctions.CountSet((int) CaptureOptions.Default), itemCount);

    void EventProcessor(IDictionary<string, object> @event)
    {
        eventCount++;
        itemCount = @event.Count;
    }
}