LineTrace 0.1.3

dotnet add package LineTrace --version 0.1.3
                    
NuGet\Install-Package LineTrace -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LineTrace" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LineTrace" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="LineTrace" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LineTrace --version 0.1.3
                    
#r "nuget: LineTrace, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LineTrace@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LineTrace&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=LineTrace&version=0.1.3
                    
Install as a Cake Tool

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=true adds 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=false stops 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 LineTraceRunner does. On a thread with a SynchronizationContext, such as a UI thread, it would deadlock.
  • Time spent waiting at an await is not counted. The report shows only time spent running code.
  • Code after an await is 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 example AsyncTaskMethodBuilder.SetResult).
  • Only one thread is traced at a time. Work that runs in parallel, such as Task.WhenAll over Task.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 return void, Task, Task<T>, or ValueTask. async void is not supported.
  • There is no warm-up: all Iterations are averaged, so the first (cold) run with JIT and empty caches is included. Raise Iterations to see the warm cost dominate.
  • dotnet run -c Release -- Sum runs only the cases whose name contains Sum.
  • Calls into other libraries are timed as a whole and shown as external. Referenced projects are too, unless the case sets Deep = true.
  • A void method 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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
0.1.3 50 11/29/2026
0.1.1 109 10/1/2026
0.1.0 86 10/1/2026