3

We are attempting to profile the performance of some WCF web services, which heavily make use of async/await.

I found that for Visual Studio's 2012 instrumentation profiling mode, the times spent awaiting for other async methods is not accumulated into its inclusive duration. Technically I guess that makes sense if the thread is in fact no longer stuck in the method execution. But that practically means it is difficult to drill down the actual methods that are slow.

For example below, the demonstration main method TestConcurrencyProfiling() is appearing to the profiler as very fast, when in reality was bogged down awaiting all the child tasks, which themselves are reportedly fast but bogged down awaiting.

I am sure there should be some way I am not realising to capture the real start-end timings of such methods?

  public async Task<string> TestConcurrencyProfiling()
  {
        var numberTasks = new List<Task<int>>();
        var rnd = new Random();
        var counter = 0;

        while (counter < 5)
        {
              numberTasks.Add(this.DelayRandomNumber(rnd));
              counter++;
        }

        await Task.WhenAll(numberTasks);

        string result = string.Empty;
        foreach (var task in numberTasks)
        {
              result += task.Result.ToString() + ";";
        }

        return result;
  }

  private async Task<int> DelayRandomNumber(Random rnd)
  {
        var delay = rnd.Next(1, 4) * 1000;
        await Task.Delay(delay);
        return delay;
  }
icelava
  • 9,787
  • 7
  • 52
  • 74
  • 1
    `async` tooling is still catching up. There *may* be a way to find this data, but I wouldn't necessarily expect that there *is* a way. The Microsoft team is most likely suited to answer this question, and they don't hang on SO; ask on the [MSDN forums](http://social.msdn.microsoft.com/Forums/en-US/home?forum=parallelextensions) instead. – Stephen Cleary Feb 20 '14 at 14:29
  • Wow really? The profiler can't accumulate the awaitables within the caller method? :-( – icelava Feb 20 '14 at 14:37
  • 1
    This has been given the glorious name "CPU Profiling", which means the profiler sleeps whenever the thread is blocked. [*I use this method.*](http://stackoverflow.com/a/378024/23771) – Mike Dunlavey Feb 20 '14 at 15:46

1 Answers1

1

From what I've seen so far, only Red Gate's ANTS profile supports this type of "wall clock" timing.

http://documentation.red-gate.com/display/APP8/Async+in+the+call+tree

icelava
  • 9,787
  • 7
  • 52
  • 74
  • OHH yes!! I had heard about redgate profiling being to able to measure that. Thanks for the reminder. – GPGVM Jan 20 '15 at 19:18