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?