Skip to content

Commit 0ab529c

Browse files
author
fremag
committed
ThreadPool: display status + work items
Closes #62
1 parent cebe4f4 commit 0ab529c

15 files changed

+495
-0
lines changed

MemoDummy/MemoDummy.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Compile Include="AbstractMemoScript.cs" />
9191
<Compile Include="ComplexObject.cs" />
9292
<Compile Include="DeadLockedThreadScript.cs" />
93+
<Compile Include="ThreadPoolScript.cs" />
9394
<Compile Include="LockedThreadScript.cs" />
9495
<Compile Include="MemoDummyForm.cs">
9596
<SubType>Form</SubType>

MemoDummy/ThreadPoolScript.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.ComponentModel;
2+
using System.Threading;
3+
4+
namespace MemoDummy
5+
{
6+
public class ThreadPoolScript : AbstractMemoScript
7+
{
8+
public override string Name => "ThreadPool";
9+
public override string Description => "Queue tasks to the ThreadPool ";
10+
11+
[Category("Config")]
12+
public int MaxWorkerThreads { get; set; } = 4;
13+
[Category("Config")]
14+
public int MinWorkerThreads { get; set; } = 4;
15+
[Category("Config")]
16+
public int MinCompletionThreads { get; set; } = 4;
17+
[Category("Config")]
18+
public int MaxCompletionThreads { get; set; } = 4;
19+
[Category("Tasks")]
20+
public int NbTasks { get; set; } = 40;
21+
[Category("Tasks")]
22+
public int DurationInSeconds { get; set; } = 60;
23+
24+
public override void Run()
25+
{
26+
ThreadPool.SetMaxThreads(MaxWorkerThreads, MaxCompletionThreads);
27+
ThreadPool.SetMinThreads(MinWorkerThreads, MinCompletionThreads);
28+
29+
for (int i=0; i < NbTasks; i++)
30+
{
31+
ThreadPool.QueueUserWorkItem(CallBack, $"Task_{i}");
32+
}
33+
}
34+
35+
private void CallBack(object state)
36+
{
37+
Thread.Sleep(DurationInSeconds * 1000);
38+
}
39+
}
40+
}

MemoScope/Core/ClrDump.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using MemoScope.Core.Data;
1010
using MemoScope.Core.Bookmark;
1111
using System.Threading;
12+
using MemoScope.Modules.ThreadPool;
1213

1314
namespace MemoScope.Core
1415
{
@@ -33,6 +34,8 @@ public class ClrDump
3334
public IEnumerable<ClrRoot> ClrRoots => Runtime.GetHeap().EnumerateRoots();
3435
public List<BlockingObject> BlockingObjects => Runtime.GetHeap().EnumerateBlockingObjects().ToList();
3536
public IList<ClrThread> Threads => Runtime.Threads;
37+
public ClrThreadPool ThreadPool => Runtime.GetThreadPool();
38+
3639

3740
public Dictionary<int, ThreadProperty> ThreadProperties
3841
{
1.63 KB
Loading
701 Bytes
Loading

MemoScope/MemoScope.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@
215215
<Compile Include="Modules\Stack\StackModule.Designer.cs">
216216
<DependentUpon>StackModule.cs</DependentUpon>
217217
</Compile>
218+
<Compile Include="Modules\ThreadPool\ManagedWorkItemInformation.cs" />
219+
<Compile Include="Modules\ThreadPool\NativeWorkItemInformation.cs" />
220+
<Compile Include="Modules\ThreadPool\ThreadPoolCommand.cs" />
221+
<Compile Include="Modules\ThreadPool\ThreadPoolInformation.cs" />
222+
<Compile Include="Modules\ThreadPool\ThreadPoolModule.cs">
223+
<SubType>UserControl</SubType>
224+
</Compile>
225+
<Compile Include="Modules\ThreadPool\ThreadPoolModule.Designer.cs">
226+
<DependentUpon>ThreadPoolModule.cs</DependentUpon>
227+
</Compile>
218228
<Compile Include="Modules\Threads\ThreadsCommand.cs" />
219229
<Compile Include="Modules\Threads\ThreadsInformation.cs" />
220230
<Compile Include="Modules\Threads\ThreadsModule.cs">
@@ -434,6 +444,9 @@
434444
<EmbeddedResource Include="Modules\Stack\StackModule.resx">
435445
<DependentUpon>StackModule.cs</DependentUpon>
436446
</EmbeddedResource>
447+
<EmbeddedResource Include="Modules\ThreadPool\ThreadPoolModule.resx">
448+
<DependentUpon>ThreadPoolModule.cs</DependentUpon>
449+
</EmbeddedResource>
437450
<EmbeddedResource Include="Modules\Threads\ThreadsModule.resx">
438451
<DependentUpon>ThreadsModule.cs</DependentUpon>
439452
</EmbeddedResource>
@@ -521,6 +534,7 @@
521534
<Content Include="Icons\Large\blueprint.png" />
522535
<Content Include="Icons\Large\bow.png" />
523536
<Content Include="Icons\Large\broom.png" />
537+
<Content Include="Icons\Large\candlestickchart.png" />
524538
<Content Include="Icons\Large\class_module.png" />
525539
<Content Include="Icons\Large\ddr_memory.png" />
526540
<Content Include="Icons\Large\elements.png" />
@@ -610,6 +624,7 @@
610624
<Content Include="Icons\Small\borders_accent.png" />
611625
<Content Include="Icons\Small\broom.png" />
612626
<Content Include="Icons\Small\cancel.png" />
627+
<Content Include="Icons\Small\candlestickchart.png" />
613628
<Content Include="Icons\Small\class_module.png" />
614629
<Content Include="Icons\Small\clock_go.png" />
615630
<Content Include="Icons\Small\clock_stop.png" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using BrightIdeasSoftware;
2+
using Microsoft.Diagnostics.Runtime;
3+
4+
namespace MemoScope.Modules.ThreadPool
5+
{
6+
public class ManagedWorkItemInformation
7+
{
8+
private ManagedWorkItem workItem;
9+
10+
public ManagedWorkItemInformation(ManagedWorkItem workItem)
11+
{
12+
this.workItem = workItem;
13+
}
14+
15+
[OLVColumn]
16+
public ulong Object => workItem.Object;
17+
[OLVColumn]
18+
public string Type => workItem.Type.Name;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using BrightIdeasSoftware;
2+
using Microsoft.Diagnostics.Runtime;
3+
4+
namespace MemoScope.Modules.ThreadPool
5+
{
6+
public class NativeWorkItemInformation
7+
{
8+
private NativeWorkItem workItem;
9+
10+
public NativeWorkItemInformation(NativeWorkItem workItem)
11+
{
12+
this.workItem = workItem;
13+
}
14+
15+
[OLVColumn]
16+
public WorkItemKind Kind => workItem.Kind;
17+
[OLVColumn]
18+
public ulong Data=> workItem.Data;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using MemoScope.Core;
2+
using WinFwk.UICommands;
3+
using WinFwk.UIModules;
4+
5+
namespace MemoScope.Modules.ThreadPool
6+
{
7+
public class ThreadPoolCommand : AbstractTypedUICommand<ClrDump>
8+
{
9+
public ThreadPoolCommand() : base("Thread Pool", "Display Thread Pool Information", "Threads", Properties.Resources.candlestickchart)
10+
{
11+
12+
}
13+
14+
protected override void HandleData(ClrDump clrDump)
15+
{
16+
UIModuleFactory.CreateModule<ThreadPoolModule>(module => { module.UIModuleParent = selectedModule; module.Setup(clrDump); }, module => DockModule(module));
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using MemoScope.Core;
2+
using Microsoft.Diagnostics.Runtime;
3+
4+
namespace MemoScope.Modules.ThreadPool
5+
{
6+
public class ThreadPoolInformation
7+
{
8+
public ClrDump ClrDump { get; }
9+
public ClrThreadPool ThreadPool { get; }
10+
11+
public ThreadPoolInformation(ClrDump clrDump, ClrThreadPool threadPool)
12+
{
13+
ClrDump = clrDump;
14+
ThreadPool = threadPool;
15+
}
16+
17+
public int CpuUtilization => ThreadPool.CpuUtilization;
18+
public int FreeCompletionPortCount => ThreadPool.FreeCompletionPortCount;
19+
public int IdleThreads => ThreadPool.IdleThreads;
20+
public int MaxCompletionPorts => ThreadPool.MaxCompletionPorts;
21+
public int MaxFreeCompletionPorts => ThreadPool.MaxFreeCompletionPorts;
22+
public int MaxThreads => ThreadPool.MaxThreads;
23+
public int MinCompletionPorts => ThreadPool.MinCompletionPorts;
24+
public int MinThreads => ThreadPool.MinThreads;
25+
public int RunningThreads => ThreadPool.RunningThreads;
26+
public int TotalThreads => ThreadPool.TotalThreads;
27+
}
28+
}

MemoScope/Modules/ThreadPool/ThreadPoolModule.Designer.cs

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)