From 8af8b2b6e23bf6a1a85d89ab5e6041f359044b40 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Thu, 20 Apr 2023 17:58:25 +0200 Subject: [PATCH] Fix perf maps address format --- Lib/test/test_perf_profiler.py | 12 +++++++++--- Python/perf_trampoline.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index 2b977d78d393248..188eb153c9018d5 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -1,4 +1,5 @@ import unittest +import string import subprocess import sys import sysconfig @@ -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_funcs = [f"py::foo:{script}", f"py::bar:{script}", f"py::baz:{script}"] + for expected_func in expected_funcs: + perf_line = next((line for line in perf_lines if expected_func in line), None) + self.assertIsNotNone(perf_line, f"Could not find {expected_func} 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: diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 1957ab82c339512..8bfbc0eb73146f5 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -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, "%llx %x py::%s:%s\n", code_addr, code_size, entry, filename); fflush(method_file); }