Profiler

Fast and lightweight profiling library for .Net Core

Profiler

Minimalistic and fast profiling library for .NET

Build Status
NuGet version (Profiler)

Configuration

Default

Example writing traces and reports to output window like Debug.WriteLine:

var profiler = new ProfilerConfiguration()
    .CreateProfiler()

Serilog

see Profiler.Serilog

Example writing profiling traces and reports to structured events in Serilog:


var profiler = new ProfilerConfiguration()
    .UseSerilogTraceWriter(settings => settings
        .UseLogEventLevel(LogEventLevel.Verbose)
        .UseLogger(logger))
    .UseSerilogReportWriter(settings => settings
        .UseLogEventLevel(LogEventLevel.Information)
        .UseLogger(logger))
    .CreateProfiler();

Usage

Sequential

using (profiler.Section("section.one"))
{
    // delay 1 ms
}

using (profiler.Section("section.two"))
{
    // delay 1 ms
}

using (profiler.Section("section.three"))
{
    // delay 1 ms
}

// trace:
//  section.one     : 1 ms
//  section.two     : 1 ms
//  section.three   : 1 ms

// metrics:
//  section.one     : 1 ms
//  section.two     : 1 ms
//  section.three   : 1 ms

Repeating

for (int i = 0; i < 3; i++)
{
    using (profiler.Section("section.{number}", i))
    {
        // delay 1 ms
    }
}

// trace:
//  section.0           : 1 ms
//  section.1           : 1 ms
//  section.2           : 1 ms

// metrics:
//  section.{number}    : 3 ms

Childs

using (var section = profiler.Section("section"))
{
    using (section.Section("child"))
    {
        // delay 1 ms
    }

    // delay 1 ms
}

// trace:
//  section -> child        : 1 ms
//  section                 : 2 ms

// metrics:
//  section                 : 2 ms
//  section -> child        : 1 ms

Passing Childs

void Inner(ISection section, int i)
{
    using (section.Section("child.{number}", i))
    {
        // delay 1 ms
    }
}

using (var section = profiler.Section("section"))
{
    Inner(section, 0);
    Inner(section, 1);
    Inner(section, 2);

    // delay 1 ms
}

// trace:
//  section -> child.0          : 1 ms
//  section -> child.1          : 1 ms
//  section -> child.2          : 1 ms
//  section                     : 4 ms

// metrics:
//  section                     : 4 ms
//  section -> child.{number}   : 3 ms