To monitor my dotnet core application I'm using .NET clr profiling api to get method level trace and calculate the time taken by any method to complete its execution. I'm unable to get the time taken by async methods.
public ActionResult<IEnumerable<string>> Get()
{
Ok(RunQueryAsync().Result);
return new string[] { "value1", "value2" };
}
public async Task<String> RunQueryAsync()
{
// in the PostDataAsyncWithHeader I'm making async api request using HttpClient
await PostDataAsyncWithHeader();
}
catch (Exception ex)
{
//display error message
return "Exception: " + ex.Message;
}
}
In the above code I'm making an api request from the method PostDataAsyncWithHeader() which almost takes 5 seconds to complete. But when I use the clr profiling Enter and exit hooks to calculate the time, Get() method shows around 5 seconds but RunQueryAsync() and PostDataAsyncWithHeader() methods show 0ms. But the actual time is taken by the method PostDataAsyncWithHeader().
I want to find the exact time taken by the PostDataAsyncWithHeader() method. Please suggest me how I can achieve it.