Created
August 24, 2020 01:59
-
-
Save russcam/12a2f83e123d055dfa6520e95c130819 to your computer and use it in GitHub Desktop.
Get Threadpool, worker and IOCP thread statistics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Threading; | |
public static class ThreadpoolStats | |
{ | |
public static string GetThreadPoolStats() | |
{ | |
ThreadPool.GetMaxThreads(out int maxWorkerThreads, out int maxIoThreads); | |
ThreadPool.GetAvailableThreads(out int freeWorkerThreads, out int freeIoThreads); | |
ThreadPool.GetMinThreads(out int minWorkerThreads, out int minIoThreads); | |
int busyIoThreads = maxIoThreads - freeIoThreads; | |
int busyWorkerThreads = maxWorkerThreads - freeWorkerThreads; | |
var builder = new StringBuilder() | |
.AppendLine("Threadpool Statistics:") | |
.AppendLine($" Thread Count: {ThreadPool.ThreadCount}") | |
.AppendLine($" Pending WorkItem Count: {ThreadPool.PendingWorkItemCount}") | |
.AppendLine($" Completed WorkItem Count: {ThreadPool.CompletedWorkItemCount}") | |
.AppendLine(" IOCP threads:") | |
.AppendLine($" Busy: {busyIoThreads}") | |
.AppendLine($" Free: {freeIoThreads}") | |
.AppendLine($" Min: {minIoThreads}") | |
.AppendLine($" Max: {maxIoThreads}") | |
.AppendLine(" Worker threads:") | |
.AppendLine($" Busy: {busyWorkerThreads}") | |
.AppendLine($" Free: {freeWorkerThreads}") | |
.AppendLine($" Min: {minWorkerThreads}") | |
.AppendLine($" Max: {maxWorkerThreads}"); | |
return builder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment