Memory.Introspect

Available on NuGet Read more

Memory.Introspect

Programmatic .gcdump and memory-graph capture for .NET — collect GC dumps, dotnet-dump process dumps, and sampling profiles from inside your own application code.

What is Memory.Introspect?

Memory.Introspect is a lightweight C# library that wraps the diagnostics functionality of dotnet-gcdump, dotnet-dump, and dotnet-trace — but exposes it as a normal in-process API. Instead of shelling out to a CLI against a PID, your application asks for its own (or another process's) memory graph, GC dump, or sampling profile and gets back a strongly-typed result.

The internals are adapted directly from the .NET diagnostics tools and connect to the target process via the official EventPipe / Diagnostics Client protocol — the same wire format the Microsoft tools use.

Project on GitHub .NET diagnostics repository PerfView (.gcdump analyser)


A first taste

using System.Diagnostics;
using Memory.Introspect;
using Microsoft.Extensions.Logging;

using var loggerFactory = LoggerFactory.Create(f => f.AddConsole());
var logger = loggerFactory.CreateLogger("Memory.Introspect");

int pid = Process.GetCurrentProcess().Id;

var introspector = MemoryIntrospector.Create(new()
{
    Logger = logger,
    Verbose = true,
});

var result = await introspector.CollectMemoryGraphAsync(pid);

if (result.Success)
{
    result.SaveToDisk($"{DateTimeOffset.UtcNow:yyyy-MM-dd-HH-mm-ss}.gcdump");
}

Open the resulting .gcdump file in Visual Studio or PerfView and you have a full snapshot of every managed object on the heap — at the exact moment your code asked for it.


Why Memory.Introspect?

Self-monitoring without external tooling

Capture diagnostics from inside the process you're investigating. No dotnet-gcdump binary on the machine, no privileged sidecar — just a NuGet reference and an await.

Automate dumps in CI and tests

Trigger a .gcdump from a flaky integration test, a soak test, or a CI memory-leak guard. Compare the heap across runs without paying for hosted profilers.

Sampling profiles, on demand

CollectSamplingProfileAsync wraps a CPU sampling session and returns the top methods — useful for "why is this 99th-percentile request slow?" investigations.

Full process dumps too

DumpAsync calls the same code path as dotnet-dump collect, producing a full process dump you can analyse in WinDbg / dotnet-dump.

Cross-platform

Works on Windows, Linux, and macOS — wherever the .NET diagnostics protocol works. The library uses no platform-specific shells.

Adapted from the official source

Internals are taken directly from dotnet/diagnostics. When the diagnostics format moves, the upstream code moves — and so does this library.


Pick your path

Get Started

Install the NuGet package and capture your first in-process .gcdump.

Core Concepts

What EventPipe is, how a .gcdump differs from a process dump, and where this library sits in the diagnostics stack.

Guides

Capture memory graphs, full process dumps, and sampling profiles — and analyse them in the right tool.

Advanced Topics

Configuration options, working with very large heaps, and remote diagnostic ports.

Source & Issues

Browse the source, file issues, and check the latest releases.


Requirements

Requirement Minimum Notes
.NET .NET 6.0+ Uses modern System.Diagnostics and Span<T> APIs.
Platform Windows / Linux / macOS Anywhere the .NET diagnostics protocol works.
Privileges Same user as the target process Capturing the current process needs no extra rights; targeting another process needs permission to open its diagnostics pipe.
Memory headroom Comparable to dotnet-gcdump The library constructs the full memory graph in-process — large heaps need the same headroom as the CLI tool.

Memory.Introspect is published under MIT, and is heavily adapted from Microsoft's dotnet-gcdump tooling.


Learn more about .NET diagnostics

© 2026 Memory.Introspect. All rights reserved.