{
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);
+ }
}
}
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
{
HandleException(exn);
}
- if (loggingOn)
- TplEventSource.Log.TraceSynchronousWorkEnd(CausalitySynchronousWork.Execution);
+ if (etwIsEnabled)
+ log.TraceSynchronousWorkEnd(CausalitySynchronousWork.Execution);
Finish(true);
}
{
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 &&
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);
}
}
if (forceContinuationsAsync)
{
continuations[i] = null;
- log?.RunningContinuationList(Id, i, currentContinuation);
+ if (etwIsEnabled)
+ log.RunningContinuationList(Id, i, currentContinuation);
switch (currentContinuation)
{
case IAsyncStateMachineBox stateMachineBox:
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)
{
// 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);
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));
}
}
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);
}
finally
{
- if (log.TasksSetActivityIds && m_continuationId != 0)
+ if (log.IsEnabled() && log.TasksSetActivityIds && m_continuationId != 0)
{
System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(savedActivityId);
}