0

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?

4

2 回答 2

2

只需单击探查器结果右下角的“显示琐碎”。

这应该显示所有动作较小

于 2013-12-17T09:05:37.297 回答
0

问题似乎是 Miniprofiler 没有显示执行时间小于 3 毫秒的步骤的结果。

编辑:来自 Miniprofiler 文档。

TrivialDurationThresholdMilliseconds 任何持续时间小于或等于此值的计时步骤将默认隐藏在 UI 中;默认为 2.0 毫秒。

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

于 2013-08-15T08:42:51.227 回答