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

Update portable thread pool event enablement checks #45681

Merged
merged 2 commits into from
Dec 7, 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 @@ -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 @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.Tracing;

namespace System.Threading
{
Expand Down Expand Up @@ -170,7 +169,7 @@ public HillClimbing()
// Add the current thread count and throughput sample to our history
//
double throughput = numCompletions / sampleDurationSeconds;
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentSample(throughput);
}
Expand Down Expand Up @@ -344,7 +343,7 @@ public HillClimbing()
// Record these numbers for posterity
//

if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentStats(sampleDurationSeconds, throughput, threadWaveComponent.Real, throughputWaveComponent.Real,
throughputErrorEstimate, _averageThroughputNoise, ratio.Real, confidence, _currentControlSetting, (ushort)newThreadWaveMagnitude);
Expand Down Expand Up @@ -405,7 +404,7 @@ private void LogTransition(int newThreadCount, double throughput, StateOrTransit

_logSize++;

if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentAdjustment(
throughput,
Expand Down
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 Microsoft.Win32.SafeHandles;

namespace System.Threading
Expand Down Expand Up @@ -37,7 +36,7 @@ internal partial class PortableThreadPool
/// <param name="handle">A description of the requested registration.</param>
internal void RegisterWaitHandle(RegisteredWaitHandle handle)
{
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolIOEnqueue(handle);
}
Expand Down Expand Up @@ -76,7 +75,7 @@ internal void RegisterWaitHandle(RegisteredWaitHandle handle)

internal static void CompleteWait(RegisteredWaitHandle handle, bool timedOut)
{
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolIODequeue(handle);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.Tracing;

namespace System.Threading
{
internal partial class PortableThreadPool
Expand All @@ -22,7 +20,7 @@ private static class WorkerThread
AppContextConfigHelper.GetInt32Config("System.Threading.ThreadPool.UnfairSemaphoreSpinLimit", 70, false),
onWait: () =>
{
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadWait(
(uint)ThreadPoolInstance._separated.counts.VolatileRead().NumExistingThreads);
Expand All @@ -35,7 +33,7 @@ private static void WorkerThreadStart()

PortableThreadPool threadPoolInstance = ThreadPoolInstance;

if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadStart(
(uint)threadPoolInstance._separated.counts.VolatileRead().NumExistingThreads);
Expand Down Expand Up @@ -107,7 +105,7 @@ private static void WorkerThreadStart()
{
HillClimbing.ThreadPoolHillClimber.ForceChange(newNumThreadsGoal, HillClimbing.StateOrTransition.ThreadTimedOut);

if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
if (PortableThreadPoolEventSource.Log.IsEnabled())
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadStop((uint)newNumExistingThreads);
}
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