Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -3199,14 +3200,10 @@ private void RunContinuations(object continuationObject) // separated out of Fin
{
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 &&
Expand Down Expand Up @@ -3279,7 +3276,8 @@ private void RunContinuations(object continuationObject) // separated out of Fin
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);
}
}
Expand All @@ -3288,7 +3286,8 @@ private void RunContinuations(object continuationObject) // separated out of Fin
if (forceContinuationsAsync)
{
continuations[i] = null;
log?.RunningContinuationList(Id, i, currentContinuation);
if (etwIsEnabled)
log.RunningContinuationList(Id, i, currentContinuation);
switch (currentContinuation)
{
case IAsyncStateMachineBox stateMachineBox:
Expand Down Expand Up @@ -3319,7 +3318,8 @@ private void RunContinuations(object continuationObject) // separated out of Fin
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the linker not handle something && false should just be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, it just didn't look right to me to do the call and then scrap it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think I understand, to do what call? This was checking a property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep but why to check the property if it's needed only when tracing is enabled. I don't feel strongly about this and could revert to the original logic event though continuationTask.IsCanceled is probably most of time false

{
// Log now that we are sure that this continuation is being ran
TplEventSource.Log.TraceOperationRelation(continuationTask.Id, CausalityRelation.AssignDelegate);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,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;
Expand Down Expand Up @@ -594,7 +594,7 @@ internal static bool Dispatch()
return true;
}

if (workQueue.loggingEnabled)
if (workQueue.loggingEnabled && FrameworkEventSource.Log.IsEnabled())
System.Diagnostics.Tracing.FrameworkEventSource.Log.ThreadPoolDequeueWorkObject(workItem);

//
Expand Down