Skip to content

Commit 2d44ba6

Browse files
author
fremag
committed
Disposables: find instances with IDisposable interface
Closes #71
1 parent 93c3ae6 commit 2d44ba6

12 files changed

+395
-1
lines changed

MemoScope/Icons/Large/recycle_bag.png

1.83 KB
Loading

MemoScope/Icons/Small/recycle_bag.png

726 Bytes
Loading

MemoScope/MemoScope.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@
230230
</Compile>
231231
<Compile Include="Modules\Delegates\DelegatesAnalysis.cs" />
232232
<Compile Include="Modules\Delegates\Types\DelegateTypesCommand.cs" />
233+
<Compile Include="Modules\Disposables\DisposableAnalysis.cs" />
234+
<Compile Include="Modules\Disposables\DisposableTypeInformation.cs" />
235+
<Compile Include="Modules\Disposables\DisposableTypesCommand.cs" />
236+
<Compile Include="Modules\Disposables\DisposableTypesModule.cs">
237+
<SubType>UserControl</SubType>
238+
</Compile>
239+
<Compile Include="Modules\Disposables\DisposableTypesModule.Designer.cs">
240+
<DependentUpon>DisposableTypesModule.cs</DependentUpon>
241+
</Compile>
233242
<Compile Include="Modules\DumpDiff\DiffColumn.cs">
234243
<SubType>Component</SubType>
235244
</Compile>
@@ -516,6 +525,9 @@
516525
<EmbeddedResource Include="Modules\Delegates\Types\DelegateTypesModule.resx">
517526
<DependentUpon>DelegateTypesModule.cs</DependentUpon>
518527
</EmbeddedResource>
528+
<EmbeddedResource Include="Modules\Disposables\DisposableTypesModule.resx">
529+
<DependentUpon>DisposableTypesModule.cs</DependentUpon>
530+
</EmbeddedResource>
519531
<EmbeddedResource Include="Modules\Explorer\ExplorerModule.resx">
520532
<DependentUpon>ExplorerModule.cs</DependentUpon>
521533
</EmbeddedResource>
@@ -647,6 +659,7 @@
647659
<Content Include="Icons\Large\plugin_link.png" />
648660
<Content Include="Icons\Large\processor.png" />
649661
<Content Include="Icons\Large\recommended_summart_table.png" />
662+
<Content Include="Icons\Large\recycle_bag.png" />
650663
<Content Include="Icons\Large\red_line.png" />
651664
<Content Include="Icons\Large\save_data.png" />
652665
<Content Include="Icons\Large\scroll_pane_list.png" />
@@ -760,6 +773,7 @@
760773
<Content Include="Icons\Small\plugin_link.png" />
761774
<Content Include="Icons\Small\processor.png" />
762775
<Content Include="Icons\Small\recommended_summart_table.png" />
776+
<Content Include="Icons\Small\recycle_bag.png" />
763777
<Content Include="Icons\Small\red_line.png" />
764778
<Content Include="Icons\Small\save_data.png" />
765779
<Content Include="Icons\Small\scroll_pane_list.png" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Generic;
2+
using MemoScope.Core;
3+
using System.Linq;
4+
5+
namespace MemoScope.Modules.Disposables
6+
{
7+
public static class DisposableAnalysis
8+
{
9+
internal static List<DisposableTypeInformation> GetDisposableTypeInformations(ClrDump clrDump)
10+
{
11+
List<DisposableTypeInformation> result = new List<DisposableTypeInformation>();
12+
var stats = clrDump.GetTypeStats().ToDictionary(stat => stat.TypeName);
13+
14+
foreach (var type in clrDump.AllTypes)
15+
{
16+
foreach(var interf in type.Interfaces)
17+
{
18+
if( interf.Name == typeof(System.IDisposable).FullName)
19+
{
20+
ClrTypeStats stat;
21+
if (stats.TryGetValue(type.Name, out stat))
22+
{
23+
result.Add(new DisposableTypeInformation(stat.Type, stat.NbInstances));
24+
}
25+
}
26+
}
27+
}
28+
return result;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using MemoScope.Core.Data;
2+
using BrightIdeasSoftware;
3+
using WinFwk.UITools;
4+
using Microsoft.Diagnostics.Runtime;
5+
6+
namespace MemoScope.Modules.Disposables
7+
{
8+
public class DisposableTypeInformation : ITypeNameData
9+
{
10+
private ClrType type;
11+
private long nbInstances;
12+
13+
public DisposableTypeInformation(ClrType type, long nbInstances)
14+
{
15+
ClrType = type;
16+
TypeName = ClrType.Name;
17+
Count = nbInstances;
18+
}
19+
20+
public ClrType ClrType { get; private set; }
21+
22+
[OLVColumn]
23+
public string TypeName { get; }
24+
[IntColumn]
25+
public long Count { get; }
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using MemoScope.Core;
2+
using System.Windows.Forms;
3+
using WinFwk.UICommands;
4+
using WinFwk.UIModules;
5+
6+
namespace MemoScope.Modules.Disposables
7+
{
8+
public class DisposablesCommand : AbstractTypedUICommand<ClrDump>
9+
{
10+
public DisposablesCommand() : base("Disposable Types", "Display Disposable Types (inherinting MultiCastDelegate tpe)", "Analysis", Properties.Resources.recycle_bag, Keys.Control | Keys.Shift | Keys.B)
11+
{
12+
13+
}
14+
15+
protected override void HandleData(ClrDump clrDump)
16+
{
17+
UIModuleFactory.CreateModule<DisposableTypesModule>(module => { module.UIModuleParent = selectedModule; module.Setup(clrDump); }, module => DockModule(module));
18+
}
19+
}
20+
}

MemoScope/Modules/Disposables/DisposableTypesModule.Designer.cs

+84
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using MemoScope.Core;
2+
using MemoScope.Core.Helpers;
3+
using WinFwk.UICommands;
4+
using MemoScope.Core.Data;
5+
using System.Collections.Generic;
6+
using System.Windows.Forms;
7+
using MemoScope.Modules.Instances;
8+
9+
namespace MemoScope.Modules.Disposables
10+
{
11+
public partial class DisposableTypesModule : UIClrDumpModule, UIDataProvider<ClrDumpType>
12+
{
13+
List<DisposableTypeInformation> disposableInformations;
14+
15+
public DisposableTypesModule()
16+
{
17+
InitializeComponent();
18+
}
19+
20+
public void Setup(ClrDump clrDump)
21+
{
22+
ClrDump = clrDump;
23+
Icon = Properties.Resources.macro_show_all_actions_small;
24+
Name = $"#{clrDump.Id} - Disposable Types";
25+
26+
dlvDisposableTypes.InitColumns<DisposableTypeInformation>();
27+
dlvDisposableTypes.SetUpTypeColumn<DisposableTypeInformation>(this);
28+
dlvDisposableTypes.SetTypeNameFilter<DisposableTypeInformation>(regexFilterControl);
29+
}
30+
31+
public override void Init()
32+
{
33+
disposableInformations = DisposableAnalysis.GetDisposableTypeInformations(ClrDump);
34+
}
35+
36+
public override void PostInit()
37+
{
38+
Summary = $"{disposableInformations.Count:###,###,###,##0} Disposable Types";
39+
dlvDisposableTypes.Objects = disposableInformations;
40+
dlvDisposableTypes.Sort(nameof(DisposableTypeInformation.Count), SortOrder.Descending);
41+
}
42+
43+
public ClrDumpType Data
44+
{
45+
get
46+
{
47+
var delegateInformation = dlvDisposableTypes.SelectedObject<DisposableTypeInformation>();
48+
if (delegateInformation != null)
49+
{
50+
return new ClrDumpType(ClrDump, delegateInformation.ClrType);
51+
}
52+
return null;
53+
}
54+
}
55+
56+
private void dlvDelegates_CellClick(object sender, BrightIdeasSoftware.CellClickEventArgs e)
57+
{
58+
if (e.ClickCount != 2)
59+
{
60+
return;
61+
}
62+
63+
var selectedDelegateType = Data;
64+
if(selectedDelegateType == null)
65+
{
66+
return;
67+
}
68+
69+
TypeInstancesModule.Create(selectedDelegateType, this, mod => RequestDockModule(mod));
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)