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/bench_pyperformance.py.

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

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/bench_producer.py 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.

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.8.tar.gz (46.7 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.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (645.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

trace0-0.1.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (630.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

trace0-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl (579.0 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

trace0-0.1.8-cp314-cp314t-macosx_10_12_x86_64.whl (592.4 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

trace0-0.1.8-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.8-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (633.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

trace0-0.1.8-cp314-cp314-macosx_10_12_x86_64.whl (593.5 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

trace0-0.1.8-cp313-cp313t-macosx_11_0_arm64.whl (577.3 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

trace0-0.1.8-cp313-cp313t-macosx_10_12_x86_64.whl (592.2 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

trace0-0.1.8-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.8-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.8-cp313-cp313-macosx_11_0_arm64.whl (579.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

trace0-0.1.8-cp313-cp313-macosx_10_12_x86_64.whl (592.9 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: trace0-0.1.8.tar.gz
  • Upload date:
  • Size: 46.7 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.8.tar.gz
Algorithm Hash digest
SHA256 15391c14276dd4cd2da1c9e8e838603000e4c0f7355d78739e7db8045fad53cd
MD5 33b5da2ba55725c3604c6d074a29074d
BLAKE2b-256 386c8bd194332fac9d77399fa28ee5b1b2ada4e0ed02d1e27cfa90193b98df8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8.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.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e2dfbd646e0d33426bb3ed91585cf3f94b37b2b5f8b0ba5f5780311b8b8ef23
MD5 eaf07fbcaffe11099a02bd45768f7e8c
BLAKE2b-256 343e2b3a172c812cb036cff797748f81dccb35860d24a448da73a8c35865d8bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 23b4933c92249ed9402e809f7528b08b7bd686158716e69f0d776d848775f1b1
MD5 9072c21eb63ca98be2fad59ea6bedd08
BLAKE2b-256 7e3e5ffc65372122e5e010ab90524b74e76cfcd6cf29c54ff52cee580d665bc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4e65a8567a0af86eeb56334499a06d2bbaa26e02c04362eaced7217928ca2f7
MD5 5794bf3f5c405300aa8bf8d5f2c097d4
BLAKE2b-256 e9ab3ba6c472daaad2a0fa2a3919dd79d00c9f8864f30b351a4bd2d836a89533

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 90355bb0dd3a7224d4c3123dc60b94e2986e458ef7164ace0090706677c9e560
MD5 c4ae597bd74ad0bbc87097aafda44dda
BLAKE2b-256 94c3b7cbdb613f228a0d6521b749453320e8c5074bbb30ec6993eb9636b73bc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d392543103e33435c16de7c31d638c3d2997b84ea2587e751ae756eabfb8a16
MD5 f81060666023a9ca8dfe579784994787
BLAKE2b-256 b32b62b7d5163a29ae61e575e0734a8188d614fbb825b715b85e17fb4d7f4648

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1e24f8515ca5eef79815a87ce6bea9a67dc35058babc5b734a53f5c3404ebcb
MD5 e6574e60b1abde3d5067b35af55364b6
BLAKE2b-256 0acddef871ee433e02b84a4ac8862adf1f985f650e33a2da97e92a67c476016c

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58b3b63e20b849805e7b6ee87c7c218f3354846df2d9ede8b74dc1afb565d974
MD5 1a80c73a32e66af77f88572e72b68343
BLAKE2b-256 3109f502c46a2614bdd812d64e5ebacb8817c63a88e588c7421d0f645367ef42

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2e161292ce7166667091313b2dd6c3238e203473483206b988619848e85f0894
MD5 226c84b50e8f8b2e4c18caef69931cab
BLAKE2b-256 ef85c69513d8bfb6d1b5e50213ab5385015e2ba6e9f488655bd65309c916bc75

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98ca7554a04f009fe2fac5e0179434b521cb0f248f024a61a30b3ecada11a29a
MD5 b4e912f7049d1edfdbd74e5e1f710b7a
BLAKE2b-256 68aeb99eaab533525a1ff0b3d8cf7c07d39d0db2552cf0f3d83b4fb8b84727a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1e0deac27a5c49cc735abf91b388314ee63f1222af83b8f1dd0fa08635939588
MD5 abbc23133566d75f495e33a9a44fdf40
BLAKE2b-256 9b242df124afdd97d33da279dd85c1bb4c670fca630caef06d4b832f6340e830

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 918a842276b06b0bcb39dfe8fd6a2e147230721e72f4adb448ffd25fc04bc605
MD5 aa50e2f2f0ddd724aae199178941361d
BLAKE2b-256 814da79b2a1bfc8ac638a536a8d27f989fdde7df5410e4a818392e8c957a1907

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a41630afcbd9d34029fc2661176a15ccf659da93b45f085c8eeaab15c8da66b
MD5 0877922a94e716f274548db958520338
BLAKE2b-256 a4c8c72f04e92119f0b30b3a42129d231eb01977651a6808a8fb8515b5e94398

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b6bec6539a00b455e19da4b306cf2580c4228c06af8522a83bcd01144ae2817
MD5 685306096635a602ff1f96f0f4057bd4
BLAKE2b-256 89b8ac17de3baf6350a9da8c68717d3f87138a60c10346674323254c60c7fbe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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.8-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for trace0-0.1.8-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3f4a047d398eac8be6baaaf511e3966c5afdece0a3768c89946d2ce01a8981c1
MD5 043d320f68295e73eec520b271328ff4
BLAKE2b-256 5ecdf92ebf4d3980a940659591d2260b9c725548962ce78ec59e9c5b6f068da9

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace0-0.1.8-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