]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-150723: Fix perf jitdump files on macOS (GH-150728) (#150832)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 3 Jun 2026 00:41:24 +0000 (02:41 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Jun 2026 00:41:24 +0000 (00:41 +0000)
commit53e7f2400a74fc81b741371aaedec7e7b43e6a1b
tree1494bd1d92f3d8e4c94c833d2b1198bc9b00e209
parent1c2daa08fb8b802e6057378d78e8e2b38b14abdb
[3.15] gh-150723: Fix perf jitdump files on macOS (GH-150728) (#150832)

gh-150723: Fix perf jitdump files on macOS (GH-150728)

The perf jitdump format defines the thread id field of the JR_CODE_LOAD
record as a 32-bit value, but on macOS it was declared as a uint64_t
(since pthread_threadid_np() returns a uint64_t). Those extra 8 bytes
plus alignment padding shifted every following field, so parsers reading
the file by the spec misread code_size as the code address and failed to
resolve any Python frames.

Declare thread_id as uint32_t on all platforms and truncate the macOS
thread id when writing the record. The value is only informational.
Symbols are resolved by address, and not thread ids so truncation is
safe here.

* Use mach_absolute_time for macOS jitdump timestamps

On macOS the jitdump file is consumed by profilers such as samply, which
timestamp their samples using mach_absolute_time(). The jitdump events were
stamped with clock_gettime(CLOCK_MONOTONIC), a different clock domain that
keeps advancing while the system is asleep, so the JIT code mappings could be
off by days relative to the samples and no Python frame would resolve. Stamp
jitdump events with mach_absolute_time() on macOS so they share the sampler's
clock domain. Linux continues to use CLOCK_MONOTONIC to stay aligned with perf.

Exercise the -Xperf_jit (jitdump) backend through samply and assert that
Python frames resolve, exercising the binary jitdump path end to end.
Skipped when samply is not installed.
(cherry picked from commit 494f2e3c92cc1b7774cca16fca5c7d1ff18c0de2)

Co-authored-by: Nazım Can Altınova <canaltinova@gmail.com>
Lib/test/test_samply_profiler.py
Misc/NEWS.d/next/Core_and_Builtins/2026-06-01-19-21-01.gh-issue-150723.Hb3JDG.rst [new file with mode: 0644]
Misc/NEWS.d/next/Core_and_Builtins/2026-06-01-19-24-12.gh-issue-150723.WlcL_-.rst [new file with mode: 0644]
Python/perf_jit_trampoline.c