Skip to content

Commit 8d95012

Browse files
authored
gh-103650: Fix perf maps address format (#103651)
1 parent e8d77b0 commit 8d95012

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Lib/test/test_perf_profiler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import string
23
import subprocess
34
import sys
45
import sysconfig
@@ -70,9 +71,14 @@ def baz():
7071
perf_file = pathlib.Path(f"/tmp/perf-{process.pid}.map")
7172
self.assertTrue(perf_file.exists())
7273
perf_file_contents = perf_file.read_text()
73-
self.assertIn(f"py::foo:{script}", perf_file_contents)
74-
self.assertIn(f"py::bar:{script}", perf_file_contents)
75-
self.assertIn(f"py::baz:{script}", perf_file_contents)
74+
perf_lines = perf_file_contents.splitlines();
75+
expected_symbols = [f"py::foo:{script}", f"py::bar:{script}", f"py::baz:{script}"]
76+
for expected_symbol in expected_symbols:
77+
perf_line = next((line for line in perf_lines if expected_symbol in line), None)
78+
self.assertIsNotNone(perf_line, f"Could not find {expected_symbol} in perf file")
79+
perf_addr = perf_line.split(" ")[0]
80+
self.assertFalse(perf_addr.startswith("0x"), "Address should not be prefixed with 0x")
81+
self.assertTrue(set(perf_addr).issubset(string.hexdigits), "Address should contain only hex characters")
7682

7783
def test_trampoline_works_with_forks(self):
7884
code = """if 1:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the perf map format to remove the '0x' prefix from the addresses

Python/perf_trampoline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ perf_map_write_entry(void *state, const void *code_addr,
253253
NULL);
254254
return;
255255
}
256-
fprintf(method_file, "%p %x py::%s:%s\n", code_addr, code_size, entry,
256+
fprintf(method_file, "%" PRIxPTR " %x py::%s:%s\n", (uintptr_t) code_addr, code_size, entry,
257257
filename);
258258
fflush(method_file);
259259
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy