Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a -stat option to the !threadpool command to display a DumpHeap-style summary of queued work items grouped by type. The implementation refactors the existing DumpWorkItems() method to extract an EnumerateAllWorkItems() method that yields work items, which can then be consumed either by the original display logic or by the new stats display via DumpHeapService.PrintHeap().
Changes:
- Added
-statoption to display statistical summary of thread pool work items - Refactored work item enumeration into a reusable
EnumerateAllWorkItems()method - Added test coverage for the new
-statoption
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Microsoft.Diagnostics.ExtensionCommands/ThreadPoolCommand.cs | Adds -stat option, DumpHeapService import, refactors work item enumeration, and updates help text |
| src/tests/SOS.UnitTests/Scripts/OtherCommands.script | Adds test coverage for !threadpool -stat command |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Microsoft.Diagnostics.ExtensionCommands/ThreadPoolCommand.cs
Outdated
Show resolved
Hide resolved
Adds a -stat flag to the threadpool command that produces a DumpHeap-style summary of queued work items grouped by type (MT, Count, TotalSize, Class Name). Delegates to DumpHeapService.PrintHeap with statsOnly: true. Refactors work item enumeration into EnumerateAllWorkItemsWithPriority() that returns (ClrObject, bool IsHighPri) tuples, preserving the high-priority distinction for -wi output. EnumerateAllWorkItems() wraps it for -stat. Adds mutual exclusivity check: -wi and -stat cannot be specified together. Prints 'No queued work items.' when -stat finds nothing. Fixes dotnet#531 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Manually tested with: using System.Diagnostics;
// Saturate the thread pool so subsequent items stay queued.
ManualResetEventSlim blocker = new(false);
int satCount = Environment.ProcessorCount * 2;
for (int i = 0; i < satCount; i++)
ThreadPool.QueueUserWorkItem(_ => blocker.Wait());
// Let saturation threads start.
Thread.Sleep(1000);
// Queue diverse work items that will remain in the queue.
for (int i = 0; i < 20; i++)
ThreadPool.QueueUserWorkItem(_ => blocker.Wait());
for (int i = 0; i < 10; i++)
Task.Run(() => blocker.Wait());
Thread.Sleep(500);
Console.WriteLine("Work items queued. Break here.");
Debugger.Break();
// Clean up.
blocker.Set();
Thread.Sleep(200);Result: I can add this test to SOS's test matrix if requested, but these kind of threadpool tests are sometimes flakey and hard to maintain due to changes in how async/threadpool changes over time. Happy to do so if requested though. We already have good coverage of the |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Quick fix to add David's requested -stat to threadpool. The formatting code already exists in DumpHeapService, we just turn the print into an enumeration and either dump the stats or the raw work items.
Fixes #531