Skip to content

Commit

Permalink
Make PortableThreadPool to check events correctly before firing them (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhang authored Dec 7, 2020
1 parent 08ad834 commit 83d19de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 @@ -169,7 +170,7 @@ public HillClimbing()
// Add the current thread count and throughput sample to our history
//
double throughput = numCompletions / sampleDurationSeconds;
if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentSample(throughput);
}
Expand Down Expand Up @@ -343,7 +344,7 @@ public HillClimbing()
// Record these numbers for posterity
//

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

_logSize++;

if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadAdjustmentAdjustment(
throughput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 @@ -36,7 +37,7 @@ internal partial class PortableThreadPool
/// <param name="handle">A description of the requested registration.</param>
internal void RegisterWaitHandle(RegisteredWaitHandle handle)
{
if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolIOEnqueue(handle);
}
Expand Down Expand Up @@ -75,7 +76,7 @@ internal void RegisterWaitHandle(RegisteredWaitHandle handle)

internal static void CompleteWait(RegisteredWaitHandle handle, bool timedOut)
{
if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Verbose, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolIODequeue(handle);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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 @@ -20,7 +22,7 @@ private static class WorkerThread
AppContextConfigHelper.GetInt32Config("System.Threading.ThreadPool.UnfairSemaphoreSpinLimit", 70, false),
onWait: () =>
{
if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadWait(
(uint)ThreadPoolInstance._separated.counts.VolatileRead().NumExistingThreads);
Expand All @@ -33,7 +35,7 @@ private static void WorkerThreadStart()

PortableThreadPool threadPoolInstance = ThreadPoolInstance;

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

if (PortableThreadPoolEventSource.Log.IsEnabled())
if (PortableThreadPoolEventSource.Log.IsEnabled(EventLevel.Informational, PortableThreadPoolEventSource.Keywords.ThreadingKeyword))
{
PortableThreadPoolEventSource.Log.ThreadPoolWorkerThreadStop((uint)newNumExistingThreads);
}
Expand Down

0 comments on commit 83d19de

Please sign in to comment.