Skip to content

Commit 32f8c99

Browse files
authored
Merge pull request python#37 from tiran/perf-test
2 parents 96dbc44 + 5370e61 commit 32f8c99

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

Lib/test/test_perf_profiler.py

+20-25
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,35 @@
77
from test import support
88
from test.support.script_helper import make_script
99
from test.support.os_helper import temp_dir
10-
from test.support import check_sanitizer
1110

1211

13-
def get_perf_version():
14-
try:
15-
cmd = ["perf", "version"]
16-
proc = subprocess.run(
17-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
18-
)
19-
except (subprocess.SubprocessError, OSError):
20-
raise unittest.SkipTest("Couldn't find perf on the path")
21-
22-
version = proc.stdout
23-
24-
match = re.search(r"^perf version\s+(.*)", version)
25-
if match is None:
26-
raise Exception("unable to parse perf version: %r" % version)
27-
return (version, match.group(1))
28-
2912
if not support.has_subprocess_support:
3013
raise unittest.SkipTest("test module requires subprocess")
3114

32-
33-
_, version = get_perf_version()
34-
35-
if not version:
36-
raise unittest.SkipTest("Could not find valid perf tool")
37-
38-
if "no-omit-frame-pointer" not in sysconfig.get_config_var("CFLAGS"):
15+
if "no-omit-frame-pointer" not in sysconfig.get_config_var("PY_CORE_CFLAGS"):
3916
raise unittest.SkipTest("Unwinding without frame pointer is unreliable")
4017

41-
if check_sanitizer(address=True, memory=True, ub=True):
18+
if support.check_sanitizer(address=True, memory=True, ub=True):
4219
raise unittest.SkipTest("Perf unwinding doesn't work with sanitizers")
4320

21+
def check_perf_command():
22+
try:
23+
cmd = ["perf", "--help"]
24+
stdout = subprocess.check_output(
25+
cmd, universal_newlines=True
26+
)
27+
except (subprocess.SubprocessError, OSError):
28+
raise unittest.SkipTest("Couldn't find perf on the path")
29+
30+
# perf version does not return a version number on Fedora. Use presence
31+
# of "perf.data" in help as indicator that it's perf from Linux tools.
32+
if "perf.data" not in stdout:
33+
raise unittest.SkipTest(
34+
"perf command does not look like Linux tool perf"
35+
)
36+
37+
check_perf_command()
38+
4439

4540
def run_perf(cwd, *args, **env_vars):
4641
if env_vars:

configure

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+5
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,11 @@ AC_MSG_RESULT([$perf_trampoline])
34383438
AS_VAR_IF([perf_trampoline], [yes], [
34393439
AC_DEFINE([_PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
34403440
PERF_TRAMPOLINE_OBJ=Objects/asm_trampoline.o
3441+
3442+
dnl perf needs frame pointers for unwinding, include compiler option in debug builds
3443+
AS_VAR_IF([Py_DEBUG], [true], [
3444+
AS_VAR_APPEND([BASECFLAGS], [" -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"])
3445+
])
34413446
])
34423447
AC_SUBST([PERF_TRAMPOLINE_OBJ])
34433448

0 commit comments

Comments
 (0)