Home > Mobile >  MiniProfiler .Ignore() extension method does not disable profiling
MiniProfiler .Ignore() extension method does not disable profiling

Time:02-16

I have a method with a portion of code I want to ignore from profiling when using MiniProfiler.

As from documentation, the extension method that does this is .Ignore(), that when used in a using statement should disable profiling for the duration.

Unfortunately I'm not getting the results as expected. Suppose I have this method structure:

public async Task<IActionResult> FirstMethod()
{
    using (MiniProfiler.Current.Step("FirstMethod"))
    {
        IActionResult result = this.SecondMethod();
        
        using (MiniProfiler.Current.Ignore())
        {
            Thread.Sleep(100); 
        }

        return result;
    }
}

internal virtual IActionResult SecondMethod()
{
    using (MiniProfiler.Current.CustomTiming("SQL", "QuerySecondMethod"))
    {
        // Some data logic
    }
}

What I expected is that on profiler the FirstMethod step duration and the SecondMethod custom timing would be approximately the same, since FirstMethod only calls SecondMethod and is ignoring the Thread.Sleep().

But I keep getting that FirstMethod duration is 100 milliseconds longer than SecondMethod, which makes it looks like the Ignore is not really disabling the profiler for the code inside it.

What am I doing wrong? Am I misunderstanding the documentation and purpose of the Ignore method?

CodePudding user response:

The .Ignore() method is for suppressing the code inside it, not the overall.

If you want to stop and throw away the profiler, your options are:

MiniProfiler.Current.Stop(discardResults: true);

For more details, you can check this issue in github.

  • Related