Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add keyword and verbosity checks for events
Reverted the part of e8043ff regarding `IsEnabled` checks
  • Loading branch information
Koundinya Veluri committed Dec 7, 2020
commit 5785405c9d1f29be9e439ceab21e03990565ffe5
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -44,10 +43,7 @@ private static void GateThreadStart()
{
Thread.Sleep(GateThreadDelayMs);

if (ThreadPool.EnableWorkerTracking &&
PortableThreadPoolEventSource.Log.IsEnabled(
EventLevel.Verbose,
PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (ThreadPool.EnableWorkerTracking && PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkingThreadCount(
(uint)threadPoolInstance.GetAndResetHighWatermarkCountOfThreadsProcessingUserCallbacks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public unsafe void ThreadPoolWorkerThreadStart(
uint RetiredWorkerThreadCount = 0,
ushort ClrInstanceID = DefaultClrInstanceId)
{
WriteThreadEvent(50, ActiveWorkerThreadCount);
if (IsEnabled(EventLevel.Informational, Keywords.ThreadingKeyword))
{
WriteThreadEvent(50, ActiveWorkerThreadCount);
}
}

[Event(51, Level = EventLevel.Informational, Message = Messages.WorkerThread, Task = Tasks.ThreadPoolWorkerThread, Opcode = EventOpcode.Stop, Version = 0, Keywords = Keywords.ThreadingKeyword)]
Expand All @@ -117,23 +120,35 @@ public void ThreadPoolWorkerThreadStop(
uint RetiredWorkerThreadCount = 0,
ushort ClrInstanceID = DefaultClrInstanceId)
{
WriteThreadEvent(51, ActiveWorkerThreadCount);
if (IsEnabled(EventLevel.Informational, Keywords.ThreadingKeyword))
{
WriteThreadEvent(51, ActiveWorkerThreadCount);
}
}

[Event(57, Level = EventLevel.Informational, Message = Messages.WorkerThread, Task = Tasks.ThreadPoolWorkerThread, Opcode = Opcodes.Wait, Version = 0, Keywords = Keywords.ThreadingKeyword)]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ThreadPoolWorkerThreadWait(
uint ActiveWorkerThreadCount,
uint RetiredWorkerThreadCount = 0,
ushort ClrInstanceID = DefaultClrInstanceId)
{
WriteThreadEvent(57, ActiveWorkerThreadCount);
if (IsEnabled(EventLevel.Informational, Keywords.ThreadingKeyword))
{
WriteThreadEvent(57, ActiveWorkerThreadCount);
}
}

[Event(54, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentSample, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Sample, Version = 0, Keywords = Keywords.ThreadingKeyword)]
public unsafe void ThreadPoolWorkerThreadAdjustmentSample(
double Throughput,
ushort ClrInstanceID = DefaultClrInstanceId)
{
if (!IsEnabled(EventLevel.Informational, Keywords.ThreadingKeyword))
{
return;
}

EventData* data = stackalloc EventData[2];
data[0].DataPointer = (IntPtr)(&Throughput);
data[0].Size = sizeof(double);
Expand All @@ -151,6 +166,11 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment(
ThreadAdjustmentReasonMap Reason,
ushort ClrInstanceID = DefaultClrInstanceId)
{
if (!IsEnabled(EventLevel.Informational, Keywords.ThreadingKeyword))
{
return;
}

EventData* data = stackalloc EventData[4];
data[0].DataPointer = (IntPtr)(&AverageThroughput);
data[0].Size = sizeof(double);
Expand Down Expand Up @@ -181,6 +201,11 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats(
ushort NewThreadWaveMagnitude,
ushort ClrInstanceID = DefaultClrInstanceId)
{
if (!IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
return;
}

EventData* data = stackalloc EventData[11];
data[0].DataPointer = (IntPtr)(&Duration);
data[0].Size = sizeof(double);
Expand Down Expand Up @@ -247,8 +272,13 @@ private unsafe void ThreadPoolIOEnqueue(
// FrameworkEventSource's thread transfer send/receive events instead at callers.
[NonEvent]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle) =>
ThreadPoolIOEnqueue((IntPtr)registeredWaitHandle.GetHashCode(), IntPtr.Zero, registeredWaitHandle.Repeating);
public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
ThreadPoolIOEnqueue((IntPtr)registeredWaitHandle.GetHashCode(), IntPtr.Zero, registeredWaitHandle.Repeating);
}
}

[Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
private unsafe void ThreadPoolIODequeue(
Expand All @@ -273,12 +303,22 @@ private unsafe void ThreadPoolIODequeue(
// FrameworkEventSource's thread transfer send/receive events instead at callers.
[NonEvent]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ThreadPoolIODequeue(RegisteredWaitHandle registeredWaitHandle) =>
ThreadPoolIODequeue((IntPtr)registeredWaitHandle.GetHashCode(), IntPtr.Zero);
public void ThreadPoolIODequeue(RegisteredWaitHandle registeredWaitHandle)
{
if (IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword))
{
ThreadPoolIODequeue((IntPtr)registeredWaitHandle.GetHashCode(), IntPtr.Zero);
}
}

[Event(60, Level = EventLevel.Verbose, Message = Messages.WorkingThreadCount, Task = Tasks.ThreadPoolWorkingThreadCount, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.ThreadingKeyword)]
public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID = DefaultClrInstanceId)
{
if (!IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
return;
}

EventData* data = stackalloc EventData[2];
data[0].DataPointer = (IntPtr)(&Count);
data[0].Size = sizeof(uint);
Expand Down