Ejemplo n.º 1
0
            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));
            }
Ejemplo n.º 2
0
            private static Action OutputCorrelationEtwEvent(Action continuation)
            {
                int  continuationId = Task.NewId();
                Task currentTask    = Task.InternalCurrent;

                // fire the correlation ETW event
                TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);

                return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation, continuationIdTask) =>
                {
                    var etwLog = TplEtwProvider.Log;
                    etwLog.TaskWaitContinuationStarted(((Task <int>)continuationIdTask).Result);

                    // ETW event for Task Wait End.
                    Guid prevActivityId = new Guid();
                    // Ensure the continuation runs under the correlated activity ID generated above
                    if (etwLog.TasksSetActivityIds)
                    {
                        EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(((Task <int>)continuationIdTask).Result), out prevActivityId);
                    }

                    // Invoke the original continuation provided to OnCompleted.
                    innerContinuation();
                    // Restore activity ID

                    if (etwLog.TasksSetActivityIds)
                    {
                        EventSource.SetCurrentThreadActivityId(prevActivityId);
                    }

                    etwLog.TaskWaitContinuationComplete(((Task <int>)continuationIdTask).Result);
                }, Task.FromResult(continuationId))); // pass the ID in a task to avoid a closure
            }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        // 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));
        }
Ejemplo n.º 5
0
            private static Action OutputCorrelationEtwEvent(Action continuation)
            {
                int  continuationId = Task.NewId();
                Task currentTask    = Task.InternalCurrent;

                // fire the correlation ETW event
                TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);

                return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, () =>
                {
                    // ETW event for Task Wait End.
                    Guid prevActivityId = new Guid();
                    // Ensure the continuation runs under the correlated activity ID generated above
                    EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out prevActivityId);
                    // Invoke the original continuation provided to OnCompleted.
                    continuation();
                    // Restore activity ID
                    EventSource.SetCurrentThreadActivityId(prevActivityId);
                }));
            }
Ejemplo n.º 6
0
            // 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));
            }
Ejemplo n.º 7
0
        /// <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)
        {
            Contract.Requires(task != null, "Need a task to wait on");
            Contract.Requires(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), System.Threading.Thread.GetDomainID());
            }

            // 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, () =>
            {
                if (Task.s_asyncDebuggingEnabled)
                {
                    Task.RemoveFromActiveTasks(task.Id);
                }

                // ETW event for Task Wait End.
                Guid prevActivityId = new Guid();
                bool bEtwLogEnabled = etwLog.IsEnabled();
                if (bEtwLogEnabled)
                {
                    var currentTaskAtEnd = Task.InternalCurrent;
                    etwLog.TaskWaitEnd(
                        (currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler.Id : TaskScheduler.Default.Id),
                        (currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0),
                        task.Id);

                    // Ensure the continuation runs under the activity ID of the task that completed for the
                    // case the antecendent is a promise (in the other cases this is already the case).
                    if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
                    {
                        EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out prevActivityId);
                    }
                }
                // Invoke the original continuation provided to OnCompleted.
                continuation();

                if (bEtwLogEnabled)
                {
                    etwLog.TaskWaitContinuationComplete(task.Id);
                    if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
                    {
                        EventSource.SetCurrentThreadActivityId(prevActivityId);
                    }
                }
            }));
        }