Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Datadog Engineering 9 min read Deep dive hardMaster

.NET Continuous Profiler: Under the hood

Datadog's .NET continuous profiler runs in-process as native C++ and Rust code loaded through the CLR's ICorProfilerCallback interface. This avoids TraceEvent and sidecars, which would add GC pressure, complicate deployment and prevent synchronous handling of events like allocations. Separate CPU, wall time, exception, lock contention, allocation and live-heap profilers feed samples to a shared Rust aggregator, which merges samples with identical stacks and labels into .pprof files. A native loader multiplexes the single allowed profiler callback across Datadog products, compiler-generated frame names are cleaned up for readability, and the runtime version is detected by probing which ICorProfilerInfo interface version QueryInterface returns.

Assumes: .NET CLR basicssampling profilersCOM interfaces

Related posts

  • .NET Continuous Profiler: CPU and wall time profiling

    Datadog Engineering hardMaster

    Datadog's .NET continuous profiler samples managed threads every 10 ms instead of relying on ETW, perf or enter/leave hooks, which cost too much for 24/7 production use. CPU samples are taken only from runnable threads, with CPU time read via NtQueryInformationThread or /proc. Wall time samples add extra threads tied to trace spans for Code Hotspots. Stack walking uses signal handlers plus libunwind on Linux, and on Windows uses thread suspension with DoStackSnapshot (32-bit) or RtlVirtualUnwind (64-bit), with a watcher thread and LD_PRELOAD trampolines to avoid deadlocks. Profiling the profiler showed std::ifstream reads of /proc allocating 8 KB per sample; switching to low-level C reads cut CPU and removed the allocations.

  • .NET Continuous Profiler: Memory usage

    Datadog Engineering hardMaster

    Datadog's .NET continuous profiler measures memory in three ways. It pulls per-thread CPU time for the .NET Server GC/BGC threads (available since .NET 5) to show garbage collector cost. It samples allocations via the CLR's AllocationTick event, fired every 100 KB per SOH/LOH/POH, and walks the stack on the current thread. It tracks surviving objects with weak handles through a new ICorProfilerInfo13 API added in .NET 7, patching the MethodTable slot with the ClassID so a handle can be created before the object exists. Validation showed the fixed 100 KB threshold produces unrepresentative samples, so values are not upscaled until the CLR adopts Poisson-distributed sampling thresholds like the Go and Java profilers.

  • .NET Continuous Profiler: Exception and lock contention

    Datadog Engineering hardMaster

    Datadog's .NET continuous profiler captures thrown exceptions through ICorProfilerCallback::ExceptionThrown and reads each exception's _message field by resolving System.Exception's ClassID from CoreLib metadata and computing the field offset with GetClassLayout. Lock contention durations come from CLR ContentionStart/ContentionStop events, delivered synchronously via EventPipeEventDelivered since .NET 5, with lock owner info added in .NET 8. Both event streams are subsampled with a PID-controller-based adaptive sampler: always at least one exception per type, and contentions bucketed by duration. Sampled values are then upscaled, using a count ratio for exceptions and a duration ratio for locks, since total wait time is what drives latency.

  • How we wrote a Python profiler

    Datadog Engineering mediumAdept

    Datadog built an always-on statistical profiler for Python because deterministic profilers like cProfile can add 2-3x overhead, too much for production. The design borrows from JDK Flight Recorder and splits into recorder, collectors, exporter and scheduler. A Cython-based stack collector samples every thread's stack 100 times per second and lowers its polling rate under heavy load to cap overhead. Memory and lock collectors add allocation and lock-contention data, and profiles are aggregated into compact pprof (protobuf) files uploaded every minute through the Datadog Agent.

  • Strobelight: A profiling service built on open source technology

    Meta Engineering mediumAdept

    Strobelight is Meta's fleet-wide profiling orchestrator, running 42 profilers (mostly eBPF-based, plus ad-hoc bpftrace scripts) on every production host with safeguards against PMU counter conflicts, concurrency limits and queuing. Default continuous profiling uses dynamic sampling that retunes run probability daily per service to hit target sample counts, with sample weights normalizing data for cross-host and cross-service comparison. LBR data feeds Meta's FDO pipeline (CSSPGO and BOLT), cutting CPU cycles up to 20% for top services, and one efficiency win alone saved an estimated 15,000 servers annually. Stack Schemas and thread-local Strobemeta enrich stacks with tags and request metadata, while a centralized symbolization service built on DWARF, gsym and blazesym avoids on-host debug-info parsing, relying on frame pointers in all user-space binaries.

The quest for software engineering knowledge.

Look:
Layout: