Skip to content

Commit

Permalink
pythongh-103650: Fix perf maps address format (python#103651)
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 authored and jbower-fb committed May 8, 2023
1 parent 3145c0f commit 44914e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import string
import subprocess
import sys
import sysconfig
Expand Down Expand Up @@ -70,9 +71,14 @@ def baz():
perf_file = pathlib.Path(f"/tmp/perf-{process.pid}.map")
self.assertTrue(perf_file.exists())
perf_file_contents = perf_file.read_text()
self.assertIn(f"py::foo:{script}", perf_file_contents)
self.assertIn(f"py::bar:{script}", perf_file_contents)
self.assertIn(f"py::baz:{script}", perf_file_contents)
perf_lines = perf_file_contents.splitlines();
expected_symbols = [f"py::foo:{script}", f"py::bar:{script}", f"py::baz:{script}"]
for expected_symbol in expected_symbols:
perf_line = next((line for line in perf_lines if expected_symbol in line), None)
self.assertIsNotNone(perf_line, f"Could not find {expected_symbol} in perf file")
perf_addr = perf_line.split(" ")[0]
self.assertFalse(perf_addr.startswith("0x"), "Address should not be prefixed with 0x")
self.assertTrue(set(perf_addr).issubset(string.hexdigits), "Address should contain only hex characters")

def test_trampoline_works_with_forks(self):
code = """if 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change the perf map format to remove the '0x' prefix from the addresses
2 changes: 1 addition & 1 deletion Python/perf_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ perf_map_write_entry(void *state, const void *code_addr,
NULL);
return;
}
fprintf(method_file, "%p %x py::%s:%s\n", code_addr, code_size, entry,
fprintf(method_file, "%" PRIxPTR " %x py::%s:%s\n", (uintptr_t) code_addr, code_size, entry,
filename);
fflush(method_file);
}
Expand Down

0 comments on commit 44914e0

Please sign in to comment.