Skip to content

dushouke/MiniProfiler.Fody

Repository files navigation

MiniProfiler.Fody

Injects Miniprofiler into your code use Fody.

The nuget package NuGet Status

https://nuget.org/packages/MiniProfiler.Fody/

PM> Install-Package MiniProfiler.Fody

Your Code

namespace MyNamespace
{
    public class MyClass
    {
        public void MyMethod()
        {
            Console.WriteLine("Hello");
        }
    }
}

What gets compiled with MiniProfiler.Fody

namespace MyNamespace
{
    public class MyClass
    {
        public void MyMethod()
        {
            IDisposable disposable = MiniProfiler.Current.Step("MyNamespace.MyClass.MyMethod()");
            try
            {
                Console.WriteLine("Hello");
            }
            finally
            {
               if(disposable != null)
               {
                   disposable.Dispose();
               }
            }
        }
    }
}

Inject Configuration

The idea and most of the code copy form tracer 😁, so configuration of control injection is similar, you can see about configuration detail here

Use FodyWeaver.xml configuration

<?xml version="1.0" encoding="utf-8"?>
<Weavers>
    <MiniProfiler profilerConstructors="false" profilerProperties="false">
        <ProfilerOn namespace="Root+*" class="public" method="public" />
        <NoProfiler namespace="Root.Generated" /> 
    </MiniProfiler>
</Weavers>

Use Attribute

ProfilerOnAttribute

namespace MyNamespace
{
    public class MyClass
    {
        [ProfilerOn]
        public void MyMethod()
        {
            Console.WriteLine("Hello");
        }
    }
}

NoProfilerAttribute

namespace MyNamespace
{
    [NoProfiler]
    public class MyClass
    {
        public void MyMethod()
        {
            Console.WriteLine("Hello");
        }
    }
}

The ProfilerOnAttribute & NoProfilerAttribute source code

using System;
// ReSharper disable once CheckNamespace
namespace ProfilerAttributes
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
    public class ProfilerOnAttribute : Attribute
    {
        public ProfilerTarget Target { get; set; }

        public ProfilerOnAttribute()
        {
        }

        public ProfilerOnAttribute(ProfilerTarget profilerTarget)
        {
            Target = profilerTarget;
        }
    }

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
    public class NoProfilerAttribute : Attribute
    {
    }

    public enum ProfilerTarget
    {
        Public,
        Internal,
        Protected,
        Private
    }
}

About

Injects Miniprofiler into your code use Fody

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published