From 5b0aaddf4f4e887cad27aee3ca99a0c698693c5a Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Wed, 15 Jan 2025 14:24:46 +0200 Subject: [PATCH] Compile with `no-omit-frame-pointer` This adds support for profiling Python 3.12 and newer using Linux `perf` command. * https://docs.python.org/3.12/howto/perf_profiling.html Co-authored-by: Tianon Gravi --- 3.12/alpine3.20/Dockerfile | 4 ++++ 3.12/alpine3.21/Dockerfile | 4 ++++ 3.12/bookworm/Dockerfile | 4 ++++ 3.12/bullseye/Dockerfile | 4 ++++ 3.12/slim-bookworm/Dockerfile | 4 ++++ 3.12/slim-bullseye/Dockerfile | 4 ++++ 3.13/alpine3.20/Dockerfile | 4 ++++ 3.13/alpine3.21/Dockerfile | 4 ++++ 3.13/bookworm/Dockerfile | 4 ++++ 3.13/bullseye/Dockerfile | 4 ++++ 3.13/slim-bookworm/Dockerfile | 4 ++++ 3.13/slim-bullseye/Dockerfile | 4 ++++ 3.14-rc/alpine3.20/Dockerfile | 4 ++++ 3.14-rc/alpine3.21/Dockerfile | 4 ++++ 3.14-rc/bookworm/Dockerfile | 4 ++++ 3.14-rc/bullseye/Dockerfile | 4 ++++ 3.14-rc/slim-bookworm/Dockerfile | 4 ++++ 3.14-rc/slim-bullseye/Dockerfile | 4 ++++ Dockerfile-linux.template | 9 +++++++++ 19 files changed, 81 insertions(+) diff --git a/3.12/alpine3.20/Dockerfile b/3.12/alpine3.20/Dockerfile index 734c041f7..738425f86 100644 --- a/3.12/alpine3.20/Dockerfile +++ b/3.12/alpine3.20/Dockerfile @@ -84,6 +84,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.12/alpine3.21/Dockerfile b/3.12/alpine3.21/Dockerfile index 4bc600f39..ecfa2e5a5 100644 --- a/3.12/alpine3.21/Dockerfile +++ b/3.12/alpine3.21/Dockerfile @@ -84,6 +84,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.12/bookworm/Dockerfile b/3.12/bookworm/Dockerfile index 1582f2c25..03a567730 100644 --- a/3.12/bookworm/Dockerfile +++ b/3.12/bookworm/Dockerfile @@ -56,6 +56,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.12/bullseye/Dockerfile b/3.12/bullseye/Dockerfile index 4c29d1c8a..c50e64a9f 100644 --- a/3.12/bullseye/Dockerfile +++ b/3.12/bullseye/Dockerfile @@ -56,6 +56,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.12/slim-bookworm/Dockerfile b/3.12/slim-bookworm/Dockerfile index d5510b6f5..f2f30c0e5 100644 --- a/3.12/slim-bookworm/Dockerfile +++ b/3.12/slim-bookworm/Dockerfile @@ -82,6 +82,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.12/slim-bullseye/Dockerfile b/3.12/slim-bullseye/Dockerfile index 1b0527ac7..cfc48bc80 100644 --- a/3.12/slim-bullseye/Dockerfile +++ b/3.12/slim-bullseye/Dockerfile @@ -82,6 +82,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/alpine3.20/Dockerfile b/3.13/alpine3.20/Dockerfile index a3400bc7e..478217810 100644 --- a/3.13/alpine3.20/Dockerfile +++ b/3.13/alpine3.20/Dockerfile @@ -79,6 +79,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/alpine3.21/Dockerfile b/3.13/alpine3.21/Dockerfile index 47fda0dbc..2fb507f5d 100644 --- a/3.13/alpine3.21/Dockerfile +++ b/3.13/alpine3.21/Dockerfile @@ -79,6 +79,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/bookworm/Dockerfile b/3.13/bookworm/Dockerfile index 7c1086995..96f63897b 100644 --- a/3.13/bookworm/Dockerfile +++ b/3.13/bookworm/Dockerfile @@ -51,6 +51,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/bullseye/Dockerfile b/3.13/bullseye/Dockerfile index 88fbc5fdd..d1a2581df 100644 --- a/3.13/bullseye/Dockerfile +++ b/3.13/bullseye/Dockerfile @@ -51,6 +51,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/slim-bookworm/Dockerfile b/3.13/slim-bookworm/Dockerfile index bba18e9ab..daba872d5 100644 --- a/3.13/slim-bookworm/Dockerfile +++ b/3.13/slim-bookworm/Dockerfile @@ -77,6 +77,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.13/slim-bullseye/Dockerfile b/3.13/slim-bullseye/Dockerfile index 1afd61621..d3a069c21 100644 --- a/3.13/slim-bullseye/Dockerfile +++ b/3.13/slim-bullseye/Dockerfile @@ -77,6 +77,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/alpine3.20/Dockerfile b/3.14-rc/alpine3.20/Dockerfile index e8d8627cb..9ecd7ccc7 100644 --- a/3.14-rc/alpine3.20/Dockerfile +++ b/3.14-rc/alpine3.20/Dockerfile @@ -72,6 +72,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/alpine3.21/Dockerfile b/3.14-rc/alpine3.21/Dockerfile index 0f2357e03..aef70890e 100644 --- a/3.14-rc/alpine3.21/Dockerfile +++ b/3.14-rc/alpine3.21/Dockerfile @@ -72,6 +72,10 @@ RUN set -eux; \ # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/bookworm/Dockerfile b/3.14-rc/bookworm/Dockerfile index a5daf968a..87bcfdb5c 100644 --- a/3.14-rc/bookworm/Dockerfile +++ b/3.14-rc/bookworm/Dockerfile @@ -44,6 +44,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/bullseye/Dockerfile b/3.14-rc/bullseye/Dockerfile index b869fcfa7..503461b33 100644 --- a/3.14-rc/bullseye/Dockerfile +++ b/3.14-rc/bullseye/Dockerfile @@ -44,6 +44,10 @@ RUN set -eux; \ nproc="$(nproc)"; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/slim-bookworm/Dockerfile b/3.14-rc/slim-bookworm/Dockerfile index 3d51543d6..74ad70f0a 100644 --- a/3.14-rc/slim-bookworm/Dockerfile +++ b/3.14-rc/slim-bookworm/Dockerfile @@ -70,6 +70,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/3.14-rc/slim-bullseye/Dockerfile b/3.14-rc/slim-bullseye/Dockerfile index afc7b3fd4..d449c281c 100644 --- a/3.14-rc/slim-bullseye/Dockerfile +++ b/3.14-rc/slim-bullseye/Dockerfile @@ -70,6 +70,10 @@ RUN set -eux; \ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \ diff --git a/Dockerfile-linux.template b/Dockerfile-linux.template index ecb9c5416..f3ccb5beb 100644 --- a/Dockerfile-linux.template +++ b/Dockerfile-linux.template @@ -198,6 +198,15 @@ RUN set -eux; \ {{ if is_slim or is_alpine then ( -}} LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \ {{ ) else "" end -}} +{{ + # Enabling frame-pointers only makes sense for Python 3.12 and newer as those have perf profiler support + if rcVersion | IN("3.9", "3.10", "3.11") then "" else ( +-}} +# https://docs.python.org/3.12/howto/perf_profiling.html +# But don't enable frame-pointers on 32bit x86 due to performance drop. +# https://github.com/docker-library/python/pull/1000#issuecomment-2597021615 + test "$gnuArch" != 'i686-linux-gnu' && EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"; \ +{{ ) end -}} make -j "$nproc" \ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ "LDFLAGS=${LDFLAGS:-}" \