Skip to content

Commit c1347c5

Browse files
committed
Enable frame pointers by default for CPython builds
1 parent b07becb commit c1347c5

5 files changed

Lines changed: 112 additions & 17 deletions

File tree

Doc/howto/perf_profiling.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ Example, using the :mod:`sys` APIs in file :file:`example.py`:
217217
How to obtain the best results
218218
------------------------------
219219

220-
For best results, Python should be compiled with
221-
``CFLAGS="-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"`` as this allows
220+
For best results, keep frame pointers enabled. On supported GCC-compatible
221+
toolchains, CPython builds itself with ``-fno-omit-frame-pointer`` and, when
222+
available, ``-mno-omit-leaf-frame-pointer`` by default. These flags allow
222223
profilers to unwind using only the frame pointer and not on DWARF debug
223224
information. This is because as the code that is interposed to allow ``perf``
224225
support is dynamically generated it doesn't have any DWARF debugging information

Lib/test/test_frame_pointer_unwind.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ def _frame_pointers_expected(machine):
2727
)
2828

2929
if "no-omit-frame-pointer" in cflags:
30-
# For example, configure adds -fno-omit-frame-pointer if Python
31-
# has perf trampoline (PY_HAVE_PERF_TRAMPOLINE) and Python is built
32-
# in debug mode.
30+
# For example, configure adds -fno-omit-frame-pointer by default on
31+
# supported GCC-compatible builds.
3332
return True
3433
if "omit-frame-pointer" in cflags:
3534
return False
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Enable frame pointers by default for GCC-compatible CPython builds, including
2+
``-mno-omit-leaf-frame-pointer`` when the compiler supports it, so profilers
3+
and debuggers can unwind native interpreter frames more reliably.

configure

Lines changed: 91 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,19 @@ then
24902490
fi
24912491

24922492
AS_VAR_IF([ac_cv_gcc_compat], [yes], [
2493+
dnl Keep frame pointers in CPython and stdlib objects so native profilers
2494+
dnl can unwind interpreter frames and generated trampolines without DWARF.
2495+
frame_pointer_cflags=
2496+
AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer], [
2497+
frame_pointer_cflags="-fno-omit-frame-pointer"
2498+
AX_CHECK_COMPILE_FLAG([-mno-omit-leaf-frame-pointer], [
2499+
frame_pointer_cflags="$frame_pointer_cflags -mno-omit-leaf-frame-pointer"
2500+
], [], [-Werror])
2501+
], [], [-Werror])
2502+
if test -n "$frame_pointer_cflags"; then
2503+
CFLAGS_NODIST="$frame_pointer_cflags $CFLAGS_NODIST"
2504+
fi
2505+
24932506
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
24942507
24952508
PY_CHECK_CC_WARNING([enable], [extra], [if we can add -Wextra])
@@ -3748,11 +3761,6 @@ AC_MSG_RESULT([$perf_trampoline])
37483761
AS_VAR_IF([perf_trampoline], [yes], [
37493762
AC_DEFINE([PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
37503763
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline.o
3751-
3752-
dnl perf needs frame pointers for unwinding, include compiler option in debug builds
3753-
AS_VAR_IF([Py_DEBUG], [true], [
3754-
AS_VAR_APPEND([BASECFLAGS], [" -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"])
3755-
])
37563764
])
37573765
AC_SUBST([PERF_TRAMPOLINE_OBJ])
37583766

0 commit comments

Comments
 (0)