1

In version 1.9 of the mini profiler I found a way to get the SQL timings of asynchronous DB calls into the profiler results. Basically, I added a ContinueWith to my async task and then added all the SQL timings to the step that initiated the async action:

foreach (var sqlTiming in completedResult.SqlTimings)
{
    currentStep.AddSqlTiming(sqlTiming);
}

However, this no longer works in 2.0.2 - those SQL timings just disappear. There appears to be a new method that does exactly what I want (source, line 487):

/// <summary>
/// Adds <paramref name="externalProfiler"/>'s <see cref="Timing"/> hierarchy to this profiler's current Timing step,
/// allowing other threads, remote calls, etc. to be profiled and joined into this profiling session.
/// </summary>
public static void AddProfilerResults(this MiniProfiler profiler, MiniProfiler externalProfiler)
{
    ...

So it looks as if this is what I should do now:

MiniProfiler.Current.AddProfilerResults(profilerFromAsyncTask);

But, while that doesn't throw an error, it doesn't seem to add anything at all to the results. I can get the steps to appear in the step with:

currentStep.AddChild(profilerFromAsyncTask.Root)

However that still discards the SQL timings and results in negative times for the step that starts the async task.

Is there something I need to do to get the results from AddProfilerResults to appear with the SQL timings?

Community
  • 1
  • 1
Keith
  • 150,284
  • 78
  • 298
  • 434

1 Answers1

1

Async is not currently an actively supported or tested scenario for mini-profiler. Until there is a supported mechanism to do that, I'm loathe to dig in to find a way to hack it in, only for that hack to evaporate with the next change. Long term, async is something we should handle - it just hasn't been a requirement so far.

I suspect your best option would be to create a suggestion on the project site (or add a comment on an existing suggestion). Or perhaps even better: figure out a mechanism to do it (that works without breaking anything or being risky) and submit a change-set.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Cheers for the swift response :-) Frustrating when I had a way to do it in 1.9 though. What's `AddProfilerResults` for then? Is it a stub for something unfinished? It appears to add the root of the async profiler to the current head, which I think means that the results should appear under whatever step was underway when the async task finished. Any idea the way I was doing it in 1.9 (with `AddSqlTiming`) doesn't work any more? That method just adds the SQL timing to the list for the current step, so I can't figure out what's changed in 2.0.2 to hide those timings. – Keith Jul 17 '12 at 10:52
  • @Keith I'll be honest: I haven't opened up the code to investigate. All I know (without looking) is: that isn't a supported scenario, and hasn't been designed for. – Marc Gravell Jul 17 '12 at 11:41
  • Cheers anyway. Further digging of the code shows that the problem is actually in `ProfiledDbCommand.ExecuteDbDataReader` - in 1.9 it checks for `_profiler == null` but in 2.0.2 it adds `|| !_profiler.IsActive` - that `IsActive` property is false, so I figure I just need to find out whatever sets that to true. – Keith Jul 17 '12 at 12:41
  • Ok, that `IsActive` check was added as part of the EF support (https://github.com/SamSaffron/MiniProfiler/pull/6/files) - it looks like my best bet is to implement my own implementation of `BaseProfilerProvider` that supports the threads with their own results. – Keith Jul 17 '12 at 14:16