Skip to content

Add basic profiling support for CPython 3.14 free-threaded builds#860

Open
honglei wants to merge 1 commit into
benfred:masterfrom
honglei:codex/cpython314t-basic-profiling
Open

Add basic profiling support for CPython 3.14 free-threaded builds#860
honglei wants to merge 1 commit into
benfred:masterfrom
honglei:codex/cpython314t-basic-profiling

Conversation

@honglei

@honglei honglei commented Jul 4, 2026

Copy link
Copy Markdown

Summary

This PR adds basic stack sampling support for CPython 3.14 free-threaded builds.

It is intentionally scoped as the first step for #711:

  • recognize libpython3.14t shared libraries
  • detect CPython 3.14 free-threaded builds through _PyRuntime.debug_offsets.free_threaded
  • add a minimal CPython 3.14t interpreter layout for stack walking, code object names, filenames, and line numbers
  • route CPython 3.14t stack sampling through that layout
  • skip thread-name lookup for free-threaded builds for now
  • return a clear unsupported error for --gil on free-threaded Python builds

Out of scope for this PR:

  • CPython 3.13t support
  • locals
  • thread names
  • native stack unwinding
  • memory profiling
  • core dump support
  • subinterpreter coverage

Related to #711.

Validation

  • cargo fmt --check
  • CARGO_HOME=/home/honglei/bwh/.cargo-py-spy cargo test --lib
    • 14 passed
  • CARGO_HOME=/home/honglei/bwh/.cargo-py-spy cargo test --release
    • lib tests: 14 passed
    • main tests: 15 passed
    • integration tests: 12 passed
    • doc tests: 1 passed
  • Remote Linux x86_64, CPython 3.14t (/opt/python314t/bin/python3):
    • cargo +stable build --release
    • cargo +stable test --lib
    • py-spy record -f raw -d 60 -- /opt/python314t/bin/python3 busy_314t.py
    • result: Samples: 5999 Errors: 0
    • raw output contains busy_loop
    • py-spy dump -p <pid> contains busy_loop
    • py-spy record --gil ... fails with --gil is not supported for free-threaded Python builds
  • Remote Linux x86_64 ordinary-GIL regression checks:
    • CPython 3.14: 60s record -f raw, Samples: 5999 Errors: 0
    • CPython 3.13: 60s record -f raw, Samples: 5999 Errors: 0
    • CPython 3.12: 60s record -f raw, Samples: 5999 Errors: 0

AI assistance disclosure

This PR was prepared with assistance from Codex / GPT-5.5. The implementation and the validation results above were checked with local and remote test runs before submission.

Add detection for CPython 3.14 free-threaded builds and route stack sampling through a minimal 3.14t interpreter layout.

Keep the first slice deliberately narrow: basic stack walking, code names, filenames, and line numbers. Thread names, locals, native stacks, memory profiling, core dumps, subinterpreters, and 3.13t support remain out of scope.

Reject --gil explicitly on free-threaded builds because there is no single GIL owner to report.

Assisted-by: Codex / GPT-5.5

Refs: benfred#711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant