سؤال

I'm using the StackExchange Miniprofiler with ASP.NET MVC 4. I'm currently trying to profile an assignment to a member variable of a class with an expensive expression that generates the value to be assigned. Miniprofiler doesn't seem to want to profile assignment statements. I've simplified my code to highlight the error:

    public ActionResult TestProfiling()
    {
        var profiler = MiniProfiler.Current;
        using (profiler.Step("Test 1"))
            Thread.Sleep(50);
        int sue;
        using (profiler.Step("Test 2"))
        {
            sue = 1;
        }
        if (sue == 1)
            sue = 2;
        using (profiler.Step("Test 3"))
        {
            Thread.Sleep(50);
            int bob;
            using (profiler.Step("Inner Test"))
            {
                bob = 1;
            }
            if (bob == 1)
                bob = 2;
        }
        return View();
    }

N.B. the if statements are simply to avoid compiler warnings.

Test 1 and Test 3 get displayed in the Miniprofiler section on the resulting page. Test 2 and Inner Test do not. However if I replace the contents of either Test 2 or Inner Test with a sleep statement they get output to the resulting page.

What is going on here? Even if I replace the simple assignment statement inside one of the non appearing tests i.e.

using (profiler.Step("Test 2"))
{
    ViewModel.ComplexData = MyAmazingService.LongRunningMethodToGenerateComplexData();
}

with a more complex one, the Test 2 step still doesn't get output to the rendered Miniprofiler section. Why isn't Miniprofiler profiling assignment statements?

Edit: code example now corresponds to text.

Edit2: After further digging around it seems that the problem isn't with assignment statements. It seems that whether something gets displayed in the output results is dependent on how long it takes to execute. i.e.

using (profiler.Step("Test 2"))
{
    sue = 1;
    Thread.Sleep(0);
}

Using the above code, Test 2 is not displayed in the Miniprofiler results.

using (profiler.Step("Test 2"))
{
    sue = 1;
    Thread.Sleep(10);
}

Using the above code Test 2 is now displayed in the Miniprofiler results.

So it seems my LongRunningCodeToGenerateComplexData turns out to be quite quick... but is it expected behaviour of Miniprofiler to not show steps that take a really small amount of time?

هل كانت مفيدة؟

المحلول 2

It seems the problem was that Miniprofiler isn't displaying results for steps where the execution time is less than 3ms.

Edit: From the Miniprofiler documentation.

TrivialDurationThresholdMilliseconds Any Timing step with a duration less than or equal to this will be hidden by default in the UI; defaults to 2.0 ms.

http://community.miniprofiler.com/permalinks/20/various-miniprofiler-settings

نصائح أخرى

Just click on "show trivial" on the bottom right of the profiler results.

this should show all actions lesser

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top