Skip to content

Commit df300e1

Browse files
pablogsalmarkshannonhugovk
authored
Apply suggestions from code review
Co-authored-by: Mark Shannon <Mark.Shannon@arm.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 42dcac9 commit df300e1

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

peps/pep-0831.rst

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This PEP proposes two things:
2929
with frame pointers by default.** This PEP recommends that *every* compiled
3030
component that participates in the Python call stack (C extensions, Rust
3131
extensions, embedding applications, and native libraries) should enable
32-
frame pointers. A frame-pointer chain is only as complete as its weakest
32+
frame pointers. A frame-pointer chain is only as strong as its weakest
3333
link: a single library without frame pointers breaks profiling, debugging,
3434
and tracing for the entire process.
3535

@@ -101,8 +101,8 @@ the entire call stack::
101101
Stack unwinding is the process of walking this chain to reconstruct the call
102102
stack. Profilers do it to find out where the program is spending time;
103103
debuggers do it to show backtraces; crash handlers do it to produce useful
104-
error reports. With frame pointers, unwinding is a simple pointer chase: read
105-
``%rbp``, follow the link, repeat. It takes microseconds and requires no
104+
error reports. With frame pointers, unwinding is a simply following pointers: read
105+
``%rbp``, follow the link, repeat. It is very fast and requires no
106106
external data.
107107

108108
At optimisation levels ``-O1`` and above, GCC and Clang omit frame pointers by
@@ -322,15 +322,14 @@ BPF programs for production monitoring), frame pointers are the only viable
322322
unwinding mechanism because they are the only mechanism the kernel's built-in
323323
helpers support.
324324

325-
CPython's own documentation already states the recommended fix::
325+
:ref:`CPython's own documentation <python:perf_profiling>`__ already states the
326+
recommended fix:
326327

327328
For best results, Python should be compiled with
328-
CFLAGS='-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer'
329+
``CFLAGS="-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"``
329330
as this allows profilers to unwind using only the frame pointer
330331
and not on DWARF debug information.
331332

332-
-- docs.python.org/3/howto/perf_profiling.html
333-
334333
Production profiling tools echo this guidance. Grafana Pyroscope's
335334
troubleshooting documentation states: "If your profiles show many shallow stack
336335
traces, typically 1-2 frames deep, your binary might have been compiled without
@@ -359,16 +358,14 @@ Distributions Are Waiting for Upstream
359358

360359
Fedora 38 [#fedora38]_, Ubuntu 24.04 LTS [#ubuntu2404]_, and Arch Linux have
361360
all rebuilt their entire package trees with ``-fno-omit-frame-pointer
362-
-mno-omit-leaf-frame-pointer``. However, Ubuntu 24.04 LTS explicitly exempted
363-
CPython::
361+
-mno-omit-leaf-frame-pointer``. However, Ubuntu 24.04 LTS
362+
`explicitly exempted CPython
363+
<https://ubuntu.com/blog/ubuntu-performance-engineering-with-frame-pointers-by-default>`__:
364364

365365
In cases where the impact is high (such as the Python
366366
interpreter), we'll continue to omit frame pointers until
367367
this is addressed.
368368

369-
-- ubuntu.com/blog/ubuntu-performance-engineering-with-
370-
frame-pointers-by-default
371-
372369
The result is a circular dependency: the runtime most in need of frame pointers
373370
for profiling is the one that major distributions leave without them, pending
374371
an upstream fix. Red Hat Enterprise Linux and CentOS Stream also disable frame
@@ -395,7 +392,7 @@ The need for a continuous chain is precisely why the flags must propagate to
395392
extension builds. If only the interpreter has frame pointers but extensions do
396393
not, the chain is still broken at every C extension boundary. By adding the
397394
flags to ``CFLAGS`` as reported by ``sysconfig``, extension builds that consume
398-
CPython's compiler flags (for example via ``pip install``, ``setuptools``, or
395+
CPython's compiler flags (for example via ``pip install``, Setuptools, or
399396
``python setup.py build``) will inherit frame pointers by default. Extensions
400397
and libraries with independent build systems still need to enable the same
401398
flags themselves for the frame-pointer chain to remain continuous.
@@ -517,7 +514,7 @@ Ecosystem Impact
517514

518515
Because the flags are in ``CFLAGS``, they propagate automatically to consumers
519516
that build against CPython's reported compiler flags, such as C extensions
520-
built via ``pip``, ``setuptools``, or direct ``sysconfig`` queries. Those
517+
built via pip, Setuptools, or direct ``sysconfig`` queries. Those
521518
consumers need take no additional action to benefit from this change.
522519

523520
Not all compiled code in the Python ecosystem inherits CPython's ``CFLAGS``.

0 commit comments

Comments
 (0)