---
title: "How we built an async-aware Python profiler"
description: "Datadog's Python profiler now reconstructs parent-child relationships between asyncio tasks so flame graphs show \"stacked stacks\": the logical application path rather than independent per-task stacks."
url: "https://swe.quest/articles/how-we-built-an-async-aware-python-profiler-fed39ce25f0b2b85"
canonical: "https://www.datadoghq.com/blog/engineering/async-python-profiler/"
source: "Datadog Engineering"
published: "2026-09-30"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 18
tags: ["python","performance","concurrency","observability","runtimes"]
---

# How we built an async-aware Python profiler

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2026-09-30, 18 min read, Deep dive. Original: [https://www.datadoghq.com/blog/engineering/async-python-profiler/](https://www.datadoghq.com/blog/engineering/async-python-profiler/)

## Summary

Datadog's Python profiler now reconstructs parent-child relationships between asyncio tasks so flame graphs show "stacked stacks": the logical application path rather than independent per-task stacks. It samples each thread without taking the GIL, walks coroutine frames for every task, builds a dependency tree from which task awaits which, and stitches leaf-task frames onto their awaiting parents. Tasks that outlive their creator are attributed to the creator while it runs and to the awaiter afterwards. Because per-task sampling scales with O(n\_tasks) and could push adaptive sampling down to one sample per second, the team also reworked the profiler's sampling path and cut overhead by more than 60% while improving profile fidelity.

Written by swe.quest, not by the author.

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

## Topics

- [Python](https://swe.quest/tags/python.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- Python asyncio tasks and coroutines ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- sampling profilers and flame graphs
- CPython GIL

## Keywords

asyncio, CPython, Datadog, Stack v2, Tachyon, flame graphs

## Related posts

- [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.
- [.NET Continuous Profiler: CPU and wall time profiling](https://swe.quest/articles/net-continuous-profiler-cpu-and-wall-time-profiling-5dcdacf43942cb04.md): Datadog Engineering · 2024-02-13 · Hard · 10 min read · .NET, Performance engineering, Runtimes & VMs, Observability, Linux
  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.
- [Android profiling now uses Perfetto via ProfilingManager](https://swe.quest/articles/android-profiling-now-uses-perfetto-via-profilingmanager-538acbb1b0bbfbfb.md): Sentry · 2026-11-02 · Medium · 3 min read · Mobile, Performance engineering, Observability
  Sentry Android SDK 8.51.0 switches profiling on Android 15+ (API 35+) from in-process Debug.startMethodTracing to Perfetto-based stack sampling via the system ProfilingManager API, while older devices fall back to the legacy profiler.
- [.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.
- [Strobelight: A profiling service built on open source technology](https://swe.quest/articles/strobelight-a-profiling-service-built-on-open-source-technology-6a094fead0e4b62a.md): Meta Engineering · 2025-01-21 · Medium · 12 min read · Performance engineering, Observability, Linux, Cost optimization, Compilers
  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.

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)
