LineTrace 0.1.3
dotnet add package LineTrace --version 0.1.3
NuGet\Install-Package LineTrace -Version 0.1.3
<PackageReference Include="LineTrace" Version="0.1.3" />
<PackageVersion Include="LineTrace" Version="0.1.3" />
<PackageReference Include="LineTrace" />
paket add LineTrace --version 0.1.3
#r "nuget: LineTrace, 0.1.3"
#:package LineTrace@0.1.3
#addin nuget:?package=LineTrace&version=0.1.3
#tool nuget:?package=LineTrace&version=0.1.3
LineTrace
LineTrace is a line-level profiler for .NET. Mark a method, run it, and get an HTML report showing the time and allocations of every call and every source line.
LineTrace is not an alternative to BenchmarkDotNet. BenchmarkDotNet is the right tool for comparing the overall performance of two methods. LineTrace answers the next question, Use BenchmarkDotNet to measure, LineTrace to improve
Quick start
dotnet new console -n LineDebugging
cd LineDebugging
dotnet add package LineTrace
Replace Program.cs:
using LineTrace;
return LineTraceRunner.Run(typeof(Cases).Assembly, args);
public class Cases
{
[LineTrace(Iterations = 1)]
public void Sum()
{
long total = 0;
for (int i = 0; i < 1_000_000; i++)
total += i % 7;
}
}
Run:
dotnet run -c Release
Open LineTrace.Artifacts/LineDebugging-report.html.
Tracing into your other projects
Projects you reference with <ProjectReference>, such as a library you cloned into the solution, are patched as well.
By default a call into them shows as one external row, at close to normal speed. Set Deep = true to trace inside
them, method by method:
[LineTrace(Iterations = 3, Deep = true)]
public void Save() { ... }
- NuGet packages are never traced inside. To trace one, clone its source and reference the project instead.
- Inside referenced projects, calls into other libraries and small methods (up to 32 bytes of IL, no loop) are not traced on their own: their time counts in the method that calls them. This keeps deep runs fast.
-p:LineTraceProjectReferenceLines=trueadds per-line hooks in referenced projects too. Expect deep runs to be many times slower; use a name filter (dotnet run -c Release -- Save) to run one case at a time.-p:LineTraceProjectReferences=falsestops patching referenced projects.
Async methods
[LineTrace] also works on methods that return Task, Task<T>, or ValueTask:
[LineTrace(Iterations = 3)]
public async Task Load()
{
var text = await File.ReadAllTextAsync("input.txt");
var words = text.Split(' ').Length;
}
- Each iteration finishes before the next one starts, because the patched method blocks until the task completes. Run it from a console app, as
LineTraceRunnerdoes. On a thread with aSynchronizationContext, such as a UI thread, it would deadlock. - Time spent waiting at an
awaitis not counted. The report shows only time spent running code. - Code after an
awaitis traced on whichever thread it resumes on. Each resume counts as another call of the method. A continuation that runs inline shows up under the call that completed it (for exampleAsyncTaskMethodBuilder.SetResult). - Only one thread is traced at a time. Work that runs in parallel, such as
Task.WhenAlloverTask.Run, is traced on just one of its threads. Work still running after the method's task completes is not traced.
Notes
[LineTrace]methods must be non-generic, take no parameters, and returnvoid,Task,Task<T>, orValueTask.async voidis not supported.- There is no warm-up: all
Iterationsare averaged, so the first (cold) run with JIT and empty caches is included. RaiseIterationsto see the warm cost dominate. dotnet run -c Release -- Sumruns only the cases whose name containsSum.- Calls into other libraries are timed as a whole and shown as
external. Referenced projects are too, unless the case setsDeep = true. - A
voidmethod is traced only on the calling thread. Other threads it starts are not traced. - Times are less reliable while other threads keep the CPU busy. In that case, compare calls and allocations rather than times.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.