dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.19k stars 355 forks source link

Improve name2ee output #4993

Open kevingosse opened 1 month ago

kevingosse commented 1 month ago

Background and Motivation

!name2ee is a great way to locate a type definition without having to browse the heap to find an instance. However, it requires the name of the assembly which is sometimes hard to remember. Because of that, I often use !name2ee *!TypeName. It works great but it shows all the assemblies, so it's hard to find the actual type in the output.

0:036> !name2ee *!Datadog.Trace.Tracer
Module:      00007ffe65744000
Assembly:    System.Private.CoreLib.dll
--------------------------------------
Module:      00007ffe6592c158
Assembly:    Universal.Server.dll
--------------------------------------
Module:      00007ffe659b7570
Assembly:    System.Runtime.dll
--------------------------------------
Module:      00007ffe659e0dc0
Assembly:    Microsoft.Extensions.Hosting.Abstractions.dll
--------------------------------------
Module:      00007ffe65a4fae0
Assembly:    Serilog.dll
--------------------------------------
Module:      00007ffe65a75238
Assembly:    System.Threading.dll
--------------------------------------
Module:      00007ffe65a7c948
Assembly:    Datadog.Trace.ClrProfiler.Managed.Loader.dll
--------------------------------------
Module:      00007ffe65a94688
Assembly:    System.Runtime.Loader.dll
--------------------------------------
Module:      00007ffe65a94e08
Assembly:    System.Runtime.Extensions.dll
--------------------------------------
Module:      00007ffe65a95f08
Assembly:    System.Collections.dll
--------------------------------------
Module:      00007ffe65a97dd8
Assembly:    System.IO.FileSystem.dll
--------------------------------------
Module:      00007ffe65b10500
Assembly:    System.Diagnostics.Process.dll
--------------------------------------
Module:      00007ffe65b10ec8
Assembly:    System.ComponentModel.Primitives.dll
--------------------------------------
Module:      00007ffe65b170a8
Assembly:    System.Runtime.InteropServices.dll
--------------------------------------
Module:      00007ffe65b187b8
Assembly:    System.Memory.dll
--------------------------------------
Module:      00007ffe65b411b8
Assembly:    System.Text.Encoding.Extensions.dll
--------------------------------------
Module:      00007ffe65bc8a98
Assembly:    Datadog.Trace.dll
Token:       000000000200005A
MethodTable: 00007ffe65ff0bf0
EEClass:     00007ffe65fd74f0
Name:        Datadog.Trace.Tracer
--------------------------------------
Module:      00007ffe65ce2a98
Assembly:    System.Collections.Concurrent.dll
--------------------------------------
Module:      00007ffe65cedb20
Assembly:    System.Linq.Expressions.dll
--------------------------------------
Module:      00007ffe65d56980
Assembly:    System.Linq.dll
--------------------------------------
Module:      00007ffe65daf030
Assembly:    System.Runtime.InteropServices.RuntimeInformation.dll
--------------------------------------
Module:      00007ffe65dd8a80
Assembly:    System.Text.RegularExpressions.dll
--------------------------------------
Module:      00007ffe65e4b9b0
Assembly:    System.Private.Uri.dll
--------------------------------------
Module:      00007ffe65ee8ab8
Assembly:    System.Reflection.Emit.Lightweight.dll
--------------------------------------
Module:      00007ffe65eea200
Assembly:    System.Reflection.Emit.ILGeneration.dll
--------------------------------------
Module:      00007ffe65f2e5e8
Assembly:    System.Reflection.Primitives.dll
--------------------------------------
Module:      00007ffe65f55ef8
Assembly:    System.Console.dll
--------------------------------------
Module:      00007ffe65ff3208
Assembly:    System.Diagnostics.DiagnosticSource.dll
--------------------------------------
Module:      00007ffe6604c3e0
Assembly:    Microsoft.AspNetCore.Mvc.Core.dll
--------------------------------------
Module:      00007ffe6604eb98
Assembly:    Microsoft.AspNetCore.Razor.Runtime.dll
--------------------------------------
Module:      00007ffe6604f438
Assembly:    Microsoft.AspNetCore.Mvc.RazorPages.dll
--------------------------------------
Module:      00007ffe66090840
Assembly:    Microsoft.AspNetCore.Mvc.Razor.dll
--------------------------------------
Module:      00007ffe66091be8
Assembly:    Microsoft.AspNetCore.Razor.dll
--------------------------------------
Module:      00007ffe660927b8
Assembly:    Microsoft.AspNetCore.Mvc.ViewFeatures.dll
--------------------------------------
Module:      00007ffe66117578
Assembly:    System.IO.MemoryMappedFiles.dll
--------------------------------------
Module:      00007ffe6611b948
Assembly:    System.ComponentModel.TypeConverter.dll
--------------------------------------
Module:      00007ffe6611ce50
Assembly:    System.ObjectModel.dll
--------------------------------------
Module:      00007ffe6614cde0
Assembly:    System.Runtime.Numerics.dll
--------------------------------------
Module:      00007ffe661d8ba8
Assembly:    System.Collections.Specialized.dll
--------------------------------------
Module:      00007ffe6624b750
Assembly:    System.IO.Pipes.dll
--------------------------------------
Module:      00007ffe6624c558
Assembly:    System.Net.Http.dll
--------------------------------------
Module:      00007ffe66270380
Assembly:    System.Net.Primitives.dll
--------------------------------------
Module:      00007ffe66271228
Assembly:    System.Diagnostics.Tracing.dll
--------------------------------------
Module:      00007ffe6627cc68
Assembly:    System.Net.Security.dll
--------------------------------------
Module:      00007ffe6627df58
Assembly:    System.Security.Cryptography.dll
--------------------------------------
Module:      00007ffe662fad48
Assembly:    Microsoft.Win32.Primitives.dll
--------------------------------------
Module:      00007ffe66320a10
Assembly:    System.Threading.Thread.dll
--------------------------------------
Module:      00007ffe66471e28
Assembly:    System.Net.Sockets.dll
--------------------------------------
Module:      00007ffe6647cae0
Assembly:    System.Threading.Overlapped.dll
--------------------------------------
...

Proposed Feature

I assume it's possible to update the output of !name2ee (it's unlikely to be used in scripting). If so, it would be nice if it only showed the detailed output for the successful result, and a summary for the other ones:

0:036> !name2ee *!Datadog.Trace.Tracer

--------------------------------------
Module:      00007ffe65bc8a98
Assembly:    Datadog.Trace.dll
Token:       000000000200005A
MethodTable: 00007ffe65ff0bf0
EEClass:     00007ffe65fd74f0
Name:        Datadog.Trace.Tracer
--------------------------------------
Module:      00007ffe6ad26040
Assembly:    Datadog.Trace.dll
Token:       000000000200006C
MethodTable: <not loaded yet>
EEClass:     <not loaded yet>
Name:        Datadog.Trace.Tracer
--------------------------------------

Also inspected System.Private.CoreLib.dll, System.Runtime.dll, Microsoft.Extensions.Hosting.Abstractions.dll, and 36 other assemblies.

Showing a sample of the inspected assemblies can be nice to validate that the syntax of the wildcard is correct, but honestly I'm not sure it's that useful. Maybe we could just show the total number of assemblies.

If the output of !name2ee can't be touched, then we could add a -quiet option to switch to the less-verbose output.