Open
Description
With dotnet/runtime#38129, I am introducing a feature switch to link out EventSource's implementation.
The following pattern in Task.cs is using EventSource.IsEnabled()
, which is getting stubbed out to false
.
bool etwIsEnabled = log.IsEnabled();
if (etwIsEnabled)
{
if (log.TasksSetActivityIds)
EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(this.Id), out savedActivityID);
// previousTask holds the actual "current task" we want to report in the event
if (previousTask != null)
log.TaskStarted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id);
else
log.TaskStarted(TaskScheduler.Current.Id, 0, this.Id);
}
finally
{
currentTaskSlot = previousTask;
// ETW event for Task Completed
if (etwIsEnabled)
{
// previousTask holds the actual "current task" we want to report in the event
if (previousTask != null)
log.TaskCompleted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id, IsFaulted);
else
log.TaskCompleted(TaskScheduler.Current.Id, 0, this.Id, IsFaulted);
if (log.TasksSetActivityIds)
EventSource.SetCurrentThreadActivityId(savedActivityID);
}
}
The top case can be trimmed successfully:
Code post-ILLink:
bool flag = log.IsEnabled();
!flag;
...
finally
{
currentTaskSlot = task;
if (flag)
{
if (task == null)
{
log.TaskCompleted(TaskScheduler.Current.Id, 0, this.Id, this.IsFaulted);
}
else
{
log.TaskCompleted(task.m_taskScheduler.Id, task.Id, this.Id, this.IsFaulted);
}
if (log.TasksSetActivityIds)
{
EventSource.SetCurrentThreadActivityId(guid);
}
}
}
Note that the finally calls to log.TaskCompleted
aren't being trimmed, even though flag
is always false
.