Skip to main content

trace0

A low-overhead tracing profiler for Python, written in Rust.

trace0 hooks PEP 669 sys.monitoring, packs each event into 8 bytes in a thread-local buffer, and hands whole batches to a background thread over lock-free SPSC rings. It emits Perfetto-compatible traces — open them at https://ui.perfetto.dev.

How much does it cost?

Across 14 benchmarks from pyperformance, the suite CPython itself is judged on, run unmodified on an M4 Mac:

Median slowdown 1.19×, ranging 1.00× to 1.48×.

slowdown
telco, fannkuch, nbody, scimark 1.00–1.04× arithmetic in tight loops
json_dumps, pyflate, chaos, float, go, spectral_norm 1.12–1.25×
raytrace, hexiom, deltablue, richards 1.36–1.48× call-heavy

The spread is the story: a tracer charges per call, so what a program pays depends entirely on how many calls it makes per unit of work, not on how long it runs. Reproduce with scripts/benchmark.py suite.

Against the alternatives, on a call-dense workload — transpiling SQL with sqlglot, 10.8M events per second of work. Reproduce with scripts/benchmark.py alternatives:

wall time vs vanilla
vanilla 0.97 s
trace0 (protobuf) 1.16 s 1.20×
trace0 (json) 1.35 s 1.40×
cProfile 2.36 s 2.45×
profile 19.11 s 19.8×

trace0 adds about a seventh of cProfile's overhead and keeps every event, where cProfile only keeps per-function aggregates. That protobuf trace was 197 MB — a full timeline is not free, it is just cheaper in time than in disk. The same run as JSON is an order of magnitude larger.

For the callback in isolation, scripts/benchmark.py overhead reports the difference against the same workload untraced: ~4 ns per event at 8 threads, ~13 ns on a single thread. An event is one PY_START or PY_RETURN, so a function call is two.

Try it

No install — uvx fetches the wheel, traces your script, and leaves nothing behind:

uvx trace0 run --output trace.pb your_script.py

Drop trace.pb onto https://ui.perfetto.dev and you have a flame chart.

The traced script runs inside the tracer's environment, so name what it imports with --with, and the interpreter with --python:

uvx --with httpx --python 3.13t trace0 run --output trace.pb your_script.py

Free-threaded builds (3.13t, 3.14t) are a first-class target — every thread is traced, not just the calling one.

-m runs a library module, exactly as python -m does; everything after the module name belongs to it:

uvx --with uvicorn trace0 run --output trace.pb -m uvicorn app:app --port 8000

A server traced from launch spends most of its trace importing. To trace only the part you care about, wrap it with the Tracer API below instead.

Install

Install it for the Tracer API, which also puts the same CLI on your project's path. Requires Python 3.13+.

uv add trace0
from trace0 import Tracer

with Tracer("trace.pb"):
    your_workload()

Output is Perfetto protobuf by default. --format json, or Tracer(..., format="json"), writes Chrome Trace Event instead — larger and slower to write, but human-readable and diffable.

Child processes

Children are traced too, whether they arrive by fork or by exec, so multiprocessing, subprocess and worker-based servers all show up. They write into the same file as they run, so there is nothing to merge afterwards:

trace0 run --output trace.pb -m uvicorn app:app --workers 4

leaves one trace.pb holding every worker, on a track of its own. Each process buffers whole packets and commits them under a lock, so two processes writing at once never splice into each other, and each namespaces its packet sequences by pid so Perfetto keeps them apart.

JSON traces use the Chrome JSON Array Format for the same reason — entries follow one another with a trailing comma and no closing bracket. That is what lets several processes append to one array, and it means a process killed mid-run still leaves everything up to its last whole entry.

Status

Early. The tracer works end to end and is covered by tests, but the API is not yet stable and wheels are not yet built for every platform.

Developing

The benchmarks behind every number above live in one script:

uv run scripts/benchmark.py --help

prek runs the CI checks before a commit lands — formatting and clippy on commit, both test suites on push:

uv tool install prek && prek install --hook-type pre-commit --hook-type pre-push

Layout

Rust lives under crates/, Python under python/.

crate role
trace0-core clock, event model, event queue, exporter contract
trace0-json Chrome Trace Event output
trace0-proto Perfetto protobuf output
trace0-py the sys.monitoring callbacks and the _core extension

Only trace0-py links against CPython, and it is the one crate with no tests: a cdylib built with extension-module leaves the interpreter's symbols undefined, so it cannot link outside maturin. Everything worth testing lives in the other three, which cargo test runs directly.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trace0-0.1.9.tar.gz (44.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

trace0-0.1.9-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (645.8 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

trace0-0.1.9-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (631.0 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

trace0-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl (578.8 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

trace0-0.1.9-cp314-cp314t-macosx_10_12_x86_64.whl (592.2 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

trace0-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (646.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

trace0-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (633.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

trace0-0.1.9-cp314-cp314-macosx_11_0_arm64.whl (579.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

trace0-0.1.9-cp314-cp314-macosx_10_12_x86_64.whl (593.4 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

trace0-0.1.9-cp313-cp313t-macosx_11_0_arm64.whl (577.1 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

trace0-0.1.9-cp313-cp313t-macosx_10_12_x86_64.whl (592.1 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

trace0-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (646.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

trace0-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (632.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

trace0-0.1.9-cp313-cp313-macosx_11_0_arm64.whl (579.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

trace0-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl (592.7 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file trace0-0.1.9.tar.gz.

File metadata

  • Download URL: trace0-0.1.9.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for trace0-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c125da20c67cb4dc86c884c82c59427333f667a735811c460f3194ddd7b172ae
MD5 c8b6a7a7fad291835cd455055d50d983
BLAKE2b-256 1f72795634b9a98757a409b790441354c7f9ee764aa85ba0832ca2780e234940

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9.tar.gz:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06b960d2bd9d46be1969eaf779cd64d0c622da707226f7abe0514156ab48c016
MD5 fe5aec438ef0c4c2937157587a96ee6a
BLAKE2b-256 22202a71fe24664630d967b4a17ddc4d0a1d8a3a52ada7ed745a6982d96fcbc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 926d2dc22d5e8ce37a53e345a9f3eea72389c7cd564e60dec9ba921ecc1563e8
MD5 fa94cdd67722090cb128642f5c27ec2e
BLAKE2b-256 0fc290e5d76b345719a5ca6da6c189c1509c02b381cf103475fc0580b6b882c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1f3ea573cd9892f560eea2c33289e67e00cbd624463522f20cbee04f6747c4f
MD5 e5715bb60a506bbdedafc8a93436bfa7
BLAKE2b-256 049c1683669674650586f1522f33aa2e9bbd99785d7e4bf4e77c6c7da1c69a00

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 36bd4595703264a05c502f5d1248a0083ff3a47c77488305928be7898afec6d3
MD5 8608092fbdeb3ac29142bbac36e0614f
BLAKE2b-256 e86914f2026a2e187934ec9537590ff81b6055995c86a71c9df3f07a7e243013

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314t-macosx_10_12_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 863b70150070e19c28bba71881eb74997be567f121cf9aba3cf11e4e61a9f78f
MD5 d46e53901b99f58b4146bef83b4aaf81
BLAKE2b-256 47044dc55865918cf69368a97350b23446a17027d83dd2560fb6a79cf49365a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 928b187708165b1dbe9a1d7258c5fd22bffa594e3c1020a5c54091afc68b3da7
MD5 798666980708bea8eed7c94b52a59679
BLAKE2b-256 616e6998c137f954108ffbc6bdde0c97c3af679cddf4d654f3105c63f2c637a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1842693089a6c2983f65776531b13554b914e8bd9a859a75fdf59c1f5d51f978
MD5 2e1970c411bbbbb79677b7de9bbcb6e1
BLAKE2b-256 9c944158b217f505b8dfa1cc8aa4c96d68a39f970e4a49cba1dd62a34bca99f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3cc171aad37264ab0918c343a52504f284f7b9443d1691337e75932e4db4115c
MD5 55dd8662a7c466d713bb6027d267fd47
BLAKE2b-256 18267f01e15b095a92656382259d340f6fdfa3b9b172c98f2e7aed2c53ca0312

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59c40084719002fff843e2fd88098a69f03a3c6d97e0e875c66879f39b0328ad
MD5 82dabfb13c767f4f75454034d40db2c8
BLAKE2b-256 da190bf3e6159f99fb177a040cfacdcce2ecad4bd0e098676154f280f1e5b518

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313t-macosx_11_0_arm64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 de44defc0c1a48b069cd42308262606f3c217ac165088e100489e6307fb5a683
MD5 fdfeedfab0ee56f0a921095eff0e7ff5
BLAKE2b-256 8e5978cbb478b97797aae94b85db58bdea5bb7a716bf75818372bd55bfea9d30

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313t-macosx_10_12_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5249f199bf012e54a99628d23d1110a2dca735dfeaca43887b3dbff1ff09b915
MD5 048e489670d773fcf6a74ba23954ba89
BLAKE2b-256 9018a5449f90a29bdbd02f8a8b245300bb2ce4d52e699f17cfd74fd9578aa07d

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f0316e5bb4c312eec7f17d8a553981bbfbdc8728cb1d0c27ddf328c3cc26721
MD5 a0a23f14a4116dc221e217d4197450d8
BLAKE2b-256 68dbdcf34fc3e87a5406669a312e256bf10631cc58588be2f16825423c7a12ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb75b3f5ccdc634ba0385809e0a44f67ae154077dbeab14c8627dbe9ed2f53ea
MD5 1642b4e61df971cbcb1750e160f3aaa0
BLAKE2b-256 678b26172a39b272d4a3ef4edd7a0da23f025cdaac737481bfecee66de919347

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace0-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 30a7c1cd5a3c6b57363a6688ade02b589bcca92105c11dff22d47c1f1acbadac
MD5 322b6782b48b7074377d3b039a016b71
BLAKE2b-256 3b1dfb37df27a0db60ff08842677d6b5d634ce70d28eec506f6ded33dd7257a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release.yml on soof-golan/trace0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page