Skip to content
Merged
Prev Previous commit
Update ThreadCount and expose HasLegacyData
  • Loading branch information
eduardo-vp committed Sep 28, 2023
commit 078707b890246c1bdc1d1f37e781c53816c7613d
11 changes: 6 additions & 5 deletions src/Microsoft.Diagnostics.Runtime/ClrThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ public sealed class ClrThreadPool : IClrThreadPool
/// </summary>
public int ActiveWorkerThreads { get; }

public int ThreadCount { get; }
public int WindowsThreadPoolThreadCount { get; }
public int TotalCompletionPorts { get; }
public int FreeCompletionPorts { get; }
public int MaxFreeCompletionPorts { get; }
public int CompletionPortCurrentLimit { get; }
public int MinCompletionPorts { get; }
public int MaxCompletionPorts { get; }
public bool HasLegacyData { get; }

/// <summary>
/// The number of retired worker threads.
Expand All @@ -85,7 +86,7 @@ internal ClrThreadPool(ClrRuntime runtime, IClrThreadPoolHelpers? helpers)
_legacyData = helpers;

ThreadPoolData tpData = default;
bool hasLegacyData = _legacyData is not null && _legacyData.GetLegacyThreadPoolData(out tpData);
HasLegacyData = _legacyData is not null && _legacyData.GetLegacyThreadPoolData(out tpData);

ClrAppDomain domain = GetDomain();

Expand All @@ -98,12 +99,12 @@ internal ClrThreadPool(ClrRuntime runtime, IClrThreadPoolHelpers? helpers)
UsingPortableThreadPool = usingPortableThreadPool;
UsingWindowsThreadPool = usingWindowsThreadPool;

Initialized = UsingPortableThreadPool || UsingWindowsThreadPool || hasLegacyData;
Initialized = UsingPortableThreadPool || UsingWindowsThreadPool || HasLegacyData;

if (UsingWindowsThreadPool)
{
ClrStaticField threadCountField = windowsThreadPoolType!.GetStaticFieldByName("s_threadCount")!;
ThreadCount = threadCountField.Read<int>(domain);
WindowsThreadPoolThreadCount = threadCountField.Read<int>(domain);
}
else if (UsingPortableThreadPool)
{
Expand All @@ -122,7 +123,7 @@ internal ClrThreadPool(ClrRuntime runtime, IClrThreadPoolHelpers? helpers)

RetiredWorkerThreads = 0;
}
else if (hasLegacyData)
else if (HasLegacyData)
{
CpuUtilization = tpData.CpuUtilization;
MinThreads = tpData.MinLimitTotalWorkerThreads;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public interface IClrThreadPool
/// </summary>
int ActiveWorkerThreads { get; }

int ThreadCount { get; }
int WindowsThreadPoolThreadCount { get; }
int TotalCompletionPorts { get; }
int FreeCompletionPorts { get; }
int MaxFreeCompletionPorts { get; }
int CompletionPortCurrentLimit { get; }
int MinCompletionPorts { get; }
int MaxCompletionPorts { get; }
bool HasLegacyData { get; }

/// <summary>
/// The number of retired worker threads.
Expand Down