Enable ETW/EventSource logging of task IDs for boxed state machines (dotnet/coreclr...
authorDel Myers <delmyers@microsoft.com>
Wed, 16 Oct 2019 01:12:56 +0000 (18:12 -0700)
committerStephen Toub <stoub@microsoft.com>
Wed, 16 Oct 2019 01:12:56 +0000 (21:12 -0400)
* Wrap MoveNext Action for TPL event tracing

Wraps the MoveNext action of the AsyncStateMachineBox in a
continuation wrapper when async causality tracing is on so that the
TPL event source can find the task that is associated with a
continuation. Does not wrap otherwise.

* Clarifying comment

* removing trailing whitespace

* code review feedback.

Makes AsyncMethodBuilderCore.TryFindContinuationTask check to
whether the target of a continuation is itself a task, as a fall-back
to checking to see if the continuation is a ContinuationWrapper

* Got rid of unnecessary null checks

Commit migrated from https://github.com/dotnet/coreclr/commit/faf20708867611e0ba134005f5b93b6eb575c160

src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs

index b71fa15..214ee72 100644 (file)
@@ -123,7 +123,9 @@ namespace System.Runtime.CompilerServices
         }
 
         internal static Task? TryGetContinuationTask(Action continuation) =>
-            (continuation?.Target as ContinuationWrapper)?._innerTask;
+            (continuation.Target is ContinuationWrapper wrapper) ?
+                wrapper._innerTask :           // A wrapped continuation, created by an awaiter
+                continuation.Target as Task;   // The continuation targets a task directly, such as with AsyncStateMachineBox
 
         /// <summary>
         /// Logically we pass just an Action (delegate) to a task for its action to 'ContinueWith' when it completes.