未验证 提交 ea75ac63 编写于 作者: M Marek Safar 提交者: GitHub

Cleanup more EventSource calls in SPC to work better with illinker (#40539)

Co-authored-by: NKoundinya Veluri <kouvel@users.noreply.github.com>
上级 f353158c
......@@ -839,10 +839,13 @@ internal void FireTaskScheduledIfNeeded(TaskScheduler ts)
{
m_stateFlags |= Task.TASK_STATE_TASKSCHEDULED_WAS_FIRED;
Task? currentTask = Task.InternalCurrent;
Task? parentTask = m_contingentProperties?.m_parent;
TplEventSource.Log.TaskScheduled(ts.Id, currentTask == null ? 0 : currentTask.Id,
this.Id, parentTask == null ? 0 : parentTask.Id, (int)this.Options);
if (TplEventSource.Log.IsEnabled())
{
Task? currentTask = Task.InternalCurrent;
Task? parentTask = m_contingentProperties?.m_parent;
TplEventSource.Log.TaskScheduled(ts.Id, currentTask == null ? 0 : currentTask.Id,
this.Id, parentTask == null ? 0 : parentTask.Id, (int)this.Options);
}
}
}
......@@ -2288,11 +2291,9 @@ private void ExecuteWithThreadLocal(ref Task? currentTaskSlot, Thread? threadPoo
log.TaskStarted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id);
else
log.TaskStarted(TaskScheduler.Current.Id, 0, this.Id);
}
bool loggingOn = TplEventSource.Log.IsEnabled();
if (loggingOn)
TplEventSource.Log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.Execution);
log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.Execution);
}
try
{
......@@ -2327,8 +2328,8 @@ private void ExecuteWithThreadLocal(ref Task? currentTaskSlot, Thread? threadPoo
HandleException(exn);
}
if (loggingOn)
TplEventSource.Log.TraceSynchronousWorkEnd(CausalitySynchronousWork.Execution);
if (etwIsEnabled)
log.TraceSynchronousWorkEnd(CausalitySynchronousWork.Execution);
Finish(true);
}
......@@ -3199,14 +3200,10 @@ internal void FinishContinuations()
{
Debug.Assert(continuationObject != null);
TplEventSource? log = TplEventSource.Log;
if (!log.IsEnabled())
{
log = null;
}
if (TplEventSource.Log.IsEnabled())
TplEventSource.Log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.CompletionNotification);
TplEventSource log = TplEventSource.Log;
bool etwIsEnabled = log.IsEnabled();
if (etwIsEnabled)
log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.CompletionNotification);
bool canInlineContinuations =
(m_stateFlags & (int)TaskCreationOptions.RunContinuationsAsynchronously) == 0 &&
......@@ -3279,7 +3276,8 @@ internal void FinishContinuations()
if ((stc.m_options & TaskContinuationOptions.ExecuteSynchronously) == 0)
{
continuations[i] = null; // so that we can skip this later
log?.RunningContinuationList(Id, i, stc);
if (etwIsEnabled)
log.RunningContinuationList(Id, i, stc);
stc.Run(this, canInlineContinuationTask: false);
}
}
......@@ -3288,7 +3286,8 @@ internal void FinishContinuations()
if (forceContinuationsAsync)
{
continuations[i] = null;
log?.RunningContinuationList(Id, i, currentContinuation);
if (etwIsEnabled)
log.RunningContinuationList(Id, i, currentContinuation);
switch (currentContinuation)
{
case IAsyncStateMachineBox stateMachineBox:
......@@ -3319,7 +3318,8 @@ internal void FinishContinuations()
continue;
}
continuations[i] = null; // to enable free'ing up memory earlier
log?.RunningContinuationList(Id, i, currentContinuation);
if (etwIsEnabled)
log.RunningContinuationList(Id, i, currentContinuation);
switch (currentContinuation)
{
......
......@@ -311,7 +311,7 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask)
// If the task was cancel before running (e.g a ContinueWhenAll with a cancelled caancelation token)
// we will still flow it to ScheduleAndStart() were it will check the status before running
// We check here to avoid faulty logs that contain a join event to an operation that was already set as completed.
if (!continuationTask.IsCanceled && TplEventSource.Log.IsEnabled())
if (TplEventSource.Log.IsEnabled() && !continuationTask.IsCanceled)
{
// Log now that we are sure that this continuation is being ran
TplEventSource.Log.TraceOperationRelation(continuationTask.Id, CausalityRelation.AssignDelegate);
......@@ -419,7 +419,7 @@ private static void PostAction(object? state)
var c = (SynchronizationContextAwaitTaskContinuation)state;
TplEventSource log = TplEventSource.Log;
if (log.TasksSetActivityIds && c.m_continuationId != 0)
if (log.IsEnabled() && log.TasksSetActivityIds && c.m_continuationId != 0)
{
c.m_syncContext.Post(s_postCallback, GetActionLogDelegate(c.m_continuationId, c.m_action));
}
......@@ -629,7 +629,7 @@ void IThreadPoolWorkItem.Execute()
}
Guid savedActivityId = default;
if (log.TasksSetActivityIds && m_continuationId != 0)
if (log.IsEnabled() && log.TasksSetActivityIds && m_continuationId != 0)
{
Guid activityId = TplEventSource.CreateGuidForTaskID(m_continuationId);
System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(activityId, out savedActivityId);
......@@ -656,7 +656,7 @@ void IThreadPoolWorkItem.Execute()
}
finally
{
if (log.TasksSetActivityIds && m_continuationId != 0)
if (log.IsEnabled() && log.TasksSetActivityIds && m_continuationId != 0)
{
System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(savedActivityId);
}
......
......@@ -450,7 +450,7 @@ public void Enqueue(object callback, bool forceGlobal)
{
Debug.Assert((callback is IThreadPoolWorkItem) ^ (callback is Task));
if (loggingEnabled)
if (loggingEnabled && FrameworkEventSource.Log.IsEnabled())
System.Diagnostics.Tracing.FrameworkEventSource.Log.ThreadPoolEnqueueWorkObject(callback);
ThreadPoolWorkQueueThreadLocals? tl = null;
......@@ -595,7 +595,7 @@ internal static bool Dispatch()
return true;
}
if (workQueue.loggingEnabled)
if (workQueue.loggingEnabled && FrameworkEventSource.Log.IsEnabled())
System.Diagnostics.Tracing.FrameworkEventSource.Log.ThreadPoolDequeueWorkObject(workItem);
//
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册