private static Action OutputCorrelationEtwEvent(Action continuation) { int continuationId = Task.NewId(); Task internalCurrent = Task.InternalCurrent; TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, internalCurrent != null ? internalCurrent.Id : 0, continuationId); return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (Action)(() => { TplEtwProvider tplEtwProvider = TplEtwProvider.Log; int TaskID1 = continuationId; tplEtwProvider.TaskWaitContinuationStarted(TaskID1); Guid oldActivityThatWillContinue = new Guid(); if (tplEtwProvider.TasksSetActivityIds) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out oldActivityThatWillContinue); } continuation(); if (tplEtwProvider.TasksSetActivityIds) { EventSource.SetCurrentThreadActivityId(oldActivityThatWillContinue); } int TaskID2 = continuationId; tplEtwProvider.TaskWaitContinuationComplete(TaskID2); }), (Task)null)); }
private static Action OutputWaitEtwEvents(Task task, Action continuation) { if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEtwProvider etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { Task internalCurrent = Task.InternalCurrent; Task continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin(internalCurrent != null ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, internalCurrent != null ? internalCurrent.Id : 0, task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, continuationTask != null ? continuationTask.Id : 0, Thread.GetDomainID()); } return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (Action)(() => { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(task.Id); } Guid oldActivityThatWillContinue = new Guid(); int num = etwLog.IsEnabled() ? 1 : 0; if (num != 0) { Task internalCurrent = Task.InternalCurrent; etwLog.TaskWaitEnd(internalCurrent != null ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, internalCurrent != null ? internalCurrent.Id : 0, task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out oldActivityThatWillContinue); } } continuation(); if (num == 0) { return; } etwLog.TaskWaitContinuationComplete(task.Id); if (!etwLog.TasksSetActivityIds || (task.Options & (TaskCreationOptions)1024) == TaskCreationOptions.None) { return; } EventSource.SetCurrentThreadActivityId(oldActivityThatWillContinue); }), (Task)null)); }
// Token: 0x06005D28 RID: 23848 RVA: 0x00146878 File Offset: 0x00144A78 private static Action OutputWaitEtwEvents(Task task, Action continuation) { if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEtwProvider etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { Task internalCurrent = Task.InternalCurrent; Task task2 = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin((internalCurrent != null) ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, (internalCurrent != null) ? internalCurrent.Id : 0, task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, (task2 != null) ? task2.Id : 0, Thread.GetDomainID()); } return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(task.Id); } Guid currentThreadActivityId = default(Guid); bool flag = etwLog.IsEnabled(); if (flag) { Task internalCurrent2 = Task.InternalCurrent; etwLog.TaskWaitEnd((internalCurrent2 != null) ? internalCurrent2.m_taskScheduler.Id : TaskScheduler.Default.Id, (internalCurrent2 != null) ? internalCurrent2.Id : 0, task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out currentThreadActivityId); } } continuation(); if (flag) { etwLog.TaskWaitContinuationComplete(task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(currentThreadActivityId); } } }, null)); }
// Token: 0x06006FE1 RID: 28641 RVA: 0x0018064C File Offset: 0x0017E84C private static Action OutputCorrelationEtwEvent(Action continuation) { int continuationId = Task.NewId(); Task internalCurrent = Task.InternalCurrent; TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (internalCurrent != null) ? internalCurrent.Id : 0, continuationId); return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate { TplEtwProvider log = TplEtwProvider.Log; log.TaskWaitContinuationStarted(continuationId); Guid currentThreadActivityId = default(Guid); if (log.TasksSetActivityIds) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out currentThreadActivityId); } continuation(); if (log.TasksSetActivityIds) { EventSource.SetCurrentThreadActivityId(currentThreadActivityId); } log.TaskWaitContinuationComplete(continuationId); }, null)); }
/// <summary> /// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event. /// </summary> /// <param name="task">The task being awaited.</param> /// <param name="continuation">The action to invoke when the await operation completes.</param> /// <returns>The action to use as the actual continuation.</returns> private static Action OutputWaitEtwEvents(Task task, Action continuation) { Debug.Assert(task != null, "Need a task to wait on"); Debug.Assert(continuation != null, "Need a continuation to invoke when the wait completes"); if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } var etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { // ETW event for Task Wait Begin var currentTaskAtBegin = Task.InternalCurrent; // If this task's continuation is another task, get it. var continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin( (currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler.Id : TaskScheduler.Default.Id), (currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0), task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, (continuationTask != null ? continuationTask.Id : 0)); } // Create a continuation action that outputs the end event and then invokes the user // provided delegate. This incurs the allocations for the closure/delegate, but only if the event // is enabled, and in doing so it allows us to pass the awaited task's information into the end event // in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter // just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred). return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation, innerTask) => { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(innerTask); } TplEtwProvider innerEtwLog = TplEtwProvider.Log; // ETW event for Task Wait End. Guid prevActivityId = new Guid(); bool bEtwLogEnabled = innerEtwLog.IsEnabled(); if (bEtwLogEnabled) { var currentTaskAtEnd = Task.InternalCurrent; innerEtwLog.TaskWaitEnd( (currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler.Id : TaskScheduler.Default.Id), (currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0), innerTask.Id); // Ensure the continuation runs under the activity ID of the task that completed for the // case the antecedent is a promise (in the other cases this is already the case). if (innerEtwLog.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(innerTask.Id), out prevActivityId); } } // Invoke the original continuation provided to OnCompleted. innerContinuation(); if (bEtwLogEnabled) { innerEtwLog.TaskWaitContinuationComplete(innerTask.Id); if (innerEtwLog.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0) { EventSource.SetCurrentThreadActivityId(prevActivityId); } } }, task)); }