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.10.tar.gz (45.3 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.10-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.10-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (630.7 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.14tmacOS 11.0+ ARM64

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

Uploaded CPython 3.14tmacOS 10.12+ x86-64

trace0-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (646.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

trace0-0.1.10-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (633.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

trace0-0.1.10-cp314-cp314-macosx_11_0_arm64.whl (579.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

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

Uploaded CPython 3.13tmacOS 11.0+ ARM64

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

Uploaded CPython 3.13tmacOS 10.12+ x86-64

trace0-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (646.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

trace0-0.1.10-cp313-cp313-macosx_10_12_x86_64.whl (592.8 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: trace0-0.1.10.tar.gz
  • Upload date:
  • Size: 45.3 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.10.tar.gz
Algorithm Hash digest
SHA256 839c543da2b650ba3bd071584ab556b5b4bc7a3ee1ae11693e913fcf3d728d07
MD5 d8be08fde6d9bf5da152eb018f733ba0
BLAKE2b-256 4649263112b6ef8729b32471cfad06ca04c0c0375d0fc5a9820d013f03ecf241

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5403f4b6ddf4fea4dbde06196af5bd93b5abf5fb2ed0c0a3925842f88b5fb304
MD5 6729015b17e872e56f301c09e91e366c
BLAKE2b-256 c637cc6f14cdb339bb3e6666722a1162048d8498efcae78784d167084b667ed3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1861f583766d93e6392b686f9a1551ae987a0e7ae29806274b20218f9c03018f
MD5 422e23192277ae866abda31b5f30f6a3
BLAKE2b-256 122b12f11395794ebf78523dd3d35774b52aa3b078e910ca63e3562ac08c197d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c23e520b2c664c20c95bd0fceeb4062e6f14f2f7a555cd1f83b8c3c4e8e726cb
MD5 bd8af338de25ad1ce09a55d1f7a70a91
BLAKE2b-256 b7a0bf52b3227457c232148cd9f49792466b1add7db166277db13f69be9a1448

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6abe6300b610918c34ef224b1e3cc14758c0c64cf9f3cc779a567d7b519e998b
MD5 021d5748f097a620b97ff8955ab4f54a
BLAKE2b-256 00db1c41fd81bbcd3f162d3a2bc1dfc05c6d42e91e7fc666fcf105267fa1086a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e3edd74e68906e43cee612c64d3d00ce16e903d25759f7a243231c872dc10cf
MD5 ffdc05ecb446bb5d063a3e13861fc0a0
BLAKE2b-256 8578c1fb260d3cf629c6dcc0c98814a710ac6a2c5be809ef042d0b989fc2b183

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 27d4b741eb8ced5d849051d19bb70a87cbc4e2fc609fb97a43ff746fd4754720
MD5 1f1c0de35818061fb4f8086248907dc7
BLAKE2b-256 4e371da68fdb460f5b6820be40b35cbbd61eaa6639d8672cc146975e3dd9e569

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26997e11e02ecf32052b4f633eaae8b9dceecc6dd45dfd3a4efbd30c9f5ca4c7
MD5 b53f6d1a3e741fc59e6d97eab10476d6
BLAKE2b-256 8aeeeaa426f57f91aac098b38baa7ab715b296897032664bf27e63d1d77d4353

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 405d4323f035de8c3767666adef292d4859a54b1604e1df39ad82985dd93e7a1
MD5 1686849de0c721c1641dcea3cabbc823
BLAKE2b-256 a834067c7658d31d4e03a267bd5f81244c544e1e816cbed950467320b2d449b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f35c4faf70bedf86beabe7e8148971466c74446088b789f0a90102f43f22307
MD5 a0540dd4d0bfee30c1ec81689f1e17f1
BLAKE2b-256 6712672aa8cbe3c9a9b05aaf14c92f613ea08a6fb6aeb93ddf8503c47f7754cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4edf21602af7d5cd2215e380f995f2a711cdce5b5dd6c7443b6ebdad44101ab2
MD5 d9910ad4603bdd2e911ad0d6f67db0af
BLAKE2b-256 55b6dfad76d39dc54debbc27445baadbe57254099830badf5d1e9f16f00da53e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25b6bffae448ef2095dae340538a31e514105d2def3f731db130c13f0354da32
MD5 3b0b6bcafc5a0a587fc7614edb5f8955
BLAKE2b-256 7f7c892bf8e577a234886185dfa6c22726cbe6a064acf7bc1563157ae98727e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4622efc6bd8fc1fa035ed3646ebba9dabc93124f4812b787c4df9184d9c059d3
MD5 f59ea464cfebace1b354d74a8e292092
BLAKE2b-256 8b106402a17a7147c67204b9fb5d9c24dd4bf451b51b4ce3e9df07cb939a8c41

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c365397bd817306b8c30bfcee491413cd846fa7f5082179c33c6ffdaebd23c08
MD5 ebe5739dc7f4ab325616f2b1becf28a0
BLAKE2b-256 b1eea20deb6db566406335b1a01fa9620049321104d6cf76ce35cb102f3a8b71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for trace0-0.1.10-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8484563130b275396613cfb509b355b8f38eb39e68550fbfe6e1f90f3f9344a9
MD5 a118eadecd035c886c86c8cac248c98c
BLAKE2b-256 bf4b990f47a9d0320282e92957183f8ca92f8e9680dfea7dcda3348381227d72

See more details on using hashes here.

Provenance

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