Question

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;
  }
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top