The DeadCode tool now successfully uses the Microsoft.Diagnostics.Tracing.TraceEvent library to extract JIT compilation events from .nettrace files, providing deterministic method tracking.
-
JIT Event Capture: Using
--providers "Microsoft-Windows-DotNETRuntime:0x4C14FCCBD:5"captures JIT compilation events (MethodJittingStarted, MethodLoadVerbose). -
TraceEvent Library Integration: The tool uses
EventPipeEventSourceto parse .nettrace files and extract JIT events directly:
using var source = new EventPipeEventSource(traceFilePath);
var clrParser = new ClrTraceEventParser(source);
clrParser.MethodJittingStarted += (data) => {
// Extract method: data.MethodNamespace, data.MethodName, data.MethodSignature
};- Accurate Results: The tool correctly identifies which methods were JIT-compiled (and thus executed) during runtime. It filters application methods from framework methods to focus on user code.
The tool cannot detect methods called through reflection or dynamic invocation, as these don't go through normal JIT compilation.
Methods triggered by external events (webhooks, scheduled tasks, message handlers) may not be exercised during profiling scenarios.
Methods that are only called under specific conditions may be missed if those conditions aren't met during profiling.
Abstract methods and interface definitions show as having no source location since they have no implementation body.
Consider using code coverage tools for comprehensive analysis:
dotnet test --collect:"XPlat Code Coverage"Code coverage data can complement JIT trace analysis for test-driven scenarios.
Add method tracking directly in the application:
[EventSource(Name = "MyApp-MethodTracker")]
public sealed class MethodTracker : EventSource
{
[Event(1)]
public void MethodEntry(string methodName) => WriteEvent(1, methodName);
}Implement custom instrumentation using:
- Assembly weaving (e.g., with Fody)
- .NET Profiling APIs
- Runtime hooks
Instrument production code to log method usage over time.
For unit testing purposes, the tool also accepts .txt trace files with a simple format:
Method Enter: Namespace.Class.Method(Parameters)
This allows testing the analysis pipeline without generating real .nettrace files, making unit tests fast and deterministic.
- Enhanced integration with code coverage tools (coverlet)
- Custom profiler using .NET Profiling APIs for deeper analysis
- Production telemetry data support for real-world usage patterns
- Assembly instrumentation options for comprehensive tracking