expose API for writing perf map files · Issue #103295 · python/cpython (original) (raw)
#96123 added support for CPython to write /tmp/perf-<pid>.map
files, associating instruction address ranges with a human-readable frame name for the Linux perf
profiler.
Two external Python JIT compilers, Cinder and Pyston, both also independently write to perf map files.
Since perf map files are one-per-process, multiple separate libraries trying to write perf map entries independently can lead to file corruption from simultaneous writes.
It's unlikely for both Cinder and Pyston JITs to be used in the same process, but it's quite reasonable to use one of these JITs along with CPython's native perf trampoline support.
In order for this to be safe, CPython should expose a thread-safe API for writing perf map entries that all these clients can use.
(We've backported the 3.12 perf trampolines feature to Cinder 3.10 and experimented with using it, and we've seen this write corruption problem occur in practice; it's not just a theoretical risk we identified.)
cc @pablogsal , @kmod