---
title: ".NET Continuous Profiler: CPU and wall time profiling"
description: "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."
url: "https://swe.quest/articles/net-continuous-profiler-cpu-and-wall-time-profiling-5dcdacf43942cb04"
canonical: "https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-2/"
source: "Datadog Engineering"
published: "2024-02-13"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 10
tags: ["dotnet","performance","runtimes","observability","linux"]
---

# .NET Continuous Profiler: CPU and wall time profiling

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2024-02-13, 10 min read, Deep dive. Original: [https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-2/](https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-2/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [.NET](https://swe.quest/tags/dotnet.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)

## Prerequisites

- .NET CLR basics ([easy posts on .NET](https://swe.quest/tags/dotnet.md?difficulty=easy))
- sampling profilers
- Unix signals
- stack unwinding

## Keywords

Datadog .NET Profiler, ICorProfilerCallback, libunwind, DoStackSnapshot, RtlVirtualUnwind, Code Hotspots, LD\_PRELOAD

## Related posts

- [.NET Continuous Profiler: Memory usage](https://swe.quest/articles/net-continuous-profiler-memory-usage-51d84deba820efcb.md): Datadog Engineering · 2024-05-20 · Hard · 9 min read · .NET, Memory management, Observability, Performance engineering, Runtimes & VMs
  Datadog's .NET continuous profiler measures memory in three ways.
- [.NET Continuous Profiler: Under the hood](https://swe.quest/articles/net-continuous-profiler-under-the-hood-46b61cbffdef64a4.md): Datadog Engineering · 2024-01-09 · Hard · 9 min read · .NET, Performance engineering, Observability, Runtimes & VMs
  Datadog's .NET continuous profiler runs in-process as native C++ and Rust code loaded through the CLR's ICorProfilerCallback interface.
- [.NET Continuous Profiler: Exception and lock contention](https://swe.quest/articles/net-continuous-profiler-exception-and-lock-contention-93247ad1a6e667eb.md): Datadog Engineering · 2024-04-04 · Hard · 8 min read · .NET, Performance engineering, Observability, Concurrency, Runtimes & VMs
  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.
- [How we wrote a Python profiler](https://swe.quest/articles/how-we-wrote-a-python-profiler-397d52e3f1db71ec.md): Datadog Engineering · 2020-10-07 · Medium · 7 min read · Python, Performance engineering, Observability
  Datadog built an always-on statistical profiler for Python because deterministic profilers like cProfile can add 2-3x overhead, too much for production.
- [Unbiased Java CPU profiling with JFR in JDK 25](https://swe.quest/articles/unbiased-java-cpu-profiling-with-jfr-in-jdk-25-9bdec8ca98b4801c.md): Datadog Engineering · 2026-07-22 · Medium · 10 min read · Java & JVM, Performance engineering, Observability, Runtimes & VMs
  JDK 25 adds an experimental JFR CPU-time sampling event (CPUTimeSample) that gives unbiased CPU profiles without relying on the unsupported HotSpot AsyncGetCallTrace API.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
