Skip to content

Commit ff45c05

Browse files
committed
Profiling build which includes common profiling tools and OS debug symbols
1 parent 4df2b46 commit ff45c05

5 files changed

Lines changed: 278 additions & 0 deletions

File tree

scripts/docker/build/ubuntu24/Dockerfile.cb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ RUN git clone --depth 1 --no-single-branch ${source}
8181

8282
#
8383
# Install build dependencies for all branches from v4 onwards
84+
# Debian sid fails if debian/control doesn't exist due to an issue
85+
# in one of the included make files, so we create a blank file.
8486
#
8587
WORKDIR freeradius-server
8688
RUN for i in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin 2>/dev/null | sed -e 's#origin/##' | egrep "^(v[4-9]*\.[0-9x]*\.x|master|${branch})$" | sort -u); \
8789
do \
8890
git checkout $i; \
8991
if [ -e ./debian/control.in ] ; then \
92+
touch -t 202001010000 debian/control; \
9093
debian/rules debian/control ; \
9194
fi ; \
9295
mk-build-deps -irt"apt-get -o Debug::pkgProblemResolver=yes $APT_OPTS" debian/control ; \
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Auto generated for ubuntu24
2+
# from scripts/docker/m4/profiling.deb.m4
3+
#
4+
# Rebuild this file with `make profiling.ubuntu24.regen`
5+
#
6+
ARG from=freeradius40x-build/ubuntu24
7+
FROM ${from}
8+
9+
#
10+
# Install profiling tools
11+
#
12+
# Valgrind/cachegrind
13+
# kcachegrind + KDE/Qt libs
14+
# gperftools
15+
# heaptrack
16+
#
17+
RUN apt-get update && \
18+
apt-get install -y $APT_OPTS \
19+
libgoogle-perftools-dev \
20+
google-perftools \
21+
valgrind \
22+
heaptrack \
23+
psmisc \
24+
kcachegrind \
25+
kio \
26+
libkf5iconthemes5 \
27+
libkf5parts5 \
28+
libkf5textwidgets5 \
29+
libqt5gui5 \
30+
libqt5widgets5 && \
31+
apt-get clean && \
32+
rm -r /var/lib/apt/lists/*
33+
34+
#
35+
# Set up Ubuntu debug symbol repository and install OS library debug symbols.
36+
# These allow profiling tools to resolve system library calls.
37+
#
38+
RUN apt-get update && \
39+
apt-get install -y $APT_OPTS ubuntu-dbgsym-keyring && \
40+
printf 'deb http://ddebs.ubuntu.com noble main restricted universe multiverse\ndeb http://ddebs.ubuntu.com noble-updates main restricted universe multiverse\n' \
41+
> /etc/apt/sources.list.d/ddebs.list && \
42+
apt-get update && \
43+
apt-get install -y $APT_OPTS \
44+
libc6-dbg \
45+
zlib1g-dbgsym \
46+
libreadline8t64-dbgsym \
47+
libssl3t64-dbgsym \
48+
libsasl2-2-dbgsym \
49+
libpam0g-dbgsym \
50+
libldap2-dbgsym \
51+
libtalloc2-dbgsym \
52+
libpcre2-8-0-dbgsym \
53+
libpcap0.8t64-dbgsym \
54+
libcurl4t64-dbgsym \
55+
libunbound8-dbgsym \
56+
libsqlite3-0-dbgsym \
57+
libpq5-dbgsym \
58+
libmariadb3-dbgsym \
59+
libgdbm6t64-dbgsym \
60+
libjson-c5-dbgsym \
61+
libbrotli1-dbgsym \
62+
libhiredis1.1.0-dbgsym \
63+
librdkafka1-dbgsym \
64+
libwbclient0-dbgsym && \
65+
apt-get clean && \
66+
rm -r /var/lib/apt/lists/*
67+
68+
ENV DEBUGINFOD_URLS="https://debuginfod.ubuntu.com"
69+
70+
#
71+
# Rebuild libkqueue from source with debug symbols.
72+
# CMAKE_BUILD_TYPE must be explicitly set to prevent
73+
# the libkqueue project from overriding the flags.
74+
# libkqueue source currently uses "-O2 -g -DNDEBUG" by default.
75+
#
76+
RUN apt-get update && \
77+
apt-get install -y $APT_OPTS --no-install-recommends cmake git && \
78+
apt-get clean && \
79+
rm -r /var/lib/apt/lists/* && \
80+
git clone --depth 1 https://github.com/mheily/libkqueue.git /tmp/libkqueue && \
81+
cd /tmp/libkqueue && \
82+
cmake -G "Unix Makefiles" \
83+
-DCMAKE_INSTALL_PREFIX=/usr \
84+
-DCMAKE_INSTALL_LIBDIR=lib \
85+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
86+
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g3 -O1 -fno-omit-frame-pointer -DNDEBUG" \
87+
. && \
88+
make && \
89+
cpack -G DEB && \
90+
dpkg -i *.deb && \
91+
cd / && rm -rf /tmp/libkqueue
92+
93+
#
94+
# Install FlameGraph
95+
#
96+
RUN git clone --depth 1 https://github.com/brendangregg/FlameGraph /opt/flamegraph \
97+
&& chmod +x /opt/flamegraph/*.pl /opt/flamegraph/*.sh
98+
99+
# Add FlameGraph to path
100+
ENV PATH="/opt/flamegraph:${PATH}"
101+
102+
#
103+
# Install Inferno for callgrind. Inferno is a Rust port of FlameGraph with broader format support
104+
#
105+
RUN apt-get update && \
106+
apt-get install -y $APT_OPTS --no-install-recommends \
107+
cargo && \
108+
cargo install inferno --version 0.11.21 --locked --root /usr/local && \
109+
apt-get clean && \
110+
rm -r /var/lib/apt/lists/*
111+
112+
EXPOSE 1812/udp 1813/udp
113+
CMD ["/bin/sh", "-c", "while true; do sleep 60; done"]

scripts/docker/crossbuild.mk

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ endif
4040
CB_IPREFIX:=freeradius40x-build
4141
CB_CPREFIX:=fr40x-crossbuild-
4242

43+
PROFILE ?= default-profiling
44+
45+
# Where profiling profiles live
46+
PROFILES_DIR:=$(CB_DIR)/profiling/profiles
47+
48+
# All available profiling profiles (one sub-directory per profile)
49+
CB_PROFILES:=$(sort $(patsubst $(PROFILES_DIR)/%,%,$(wildcard $(PROFILES_DIR)/*)))
50+
4351
#
4452
# This Makefile is included in-line, and not via the "boilermake"
4553
# wrapper. But it's still useful to use the same process for
@@ -90,6 +98,12 @@ crossbuild.help: crossbuild.info
9098
@echo " crossbuild.IMAGE.clean - stop container and tidy up"
9199
@echo " crossbuild.IMAGE.wipe - remove Docker image"
92100
@echo ""
101+
@echo "Profiling targets:"
102+
@echo " crossbuild.IMAGE.profile.regen - regenerate Dockerfile.prof using default profile ($(PROFILE))"
103+
@echo " crossbuild.IMAGE.profile.regen PROFILE=<name> - regenerate using a specific profile"
104+
@echo " crossbuild.IMAGE.profile.build - build profiling image using default profile ($(PROFILE))"
105+
@echo " crossbuild.IMAGE.profile.reset - remove profiling stamp to force rebuild"
106+
@echo ""
93107
@echo "Use 'make NOCACHE=1 ...' to disregard the Docker cache on build"
94108

95109
#
@@ -140,6 +154,20 @@ $(DD)/stamp-image.${1}:
140154
${Q}docker build $(DOCKER_BUILD_OPTS) $(DT)/${1} -f $(DT)/${1}/Dockerfile.cb -t $(CB_IPREFIX)/${1} >$(DD)/build.${1} 2>&1
141155
${Q}touch $(DD)/stamp-image.${1}
142156

157+
#
158+
# Build the profiling image
159+
#
160+
.PHONY: crossbuild.${1}.profile.build
161+
crossbuild.${1}.profile.build: $(DD)/stamp-image.${1}-profile.build
162+
163+
$(DD)/stamp-image.${1}-profile.build: $(DT)/${1}/Dockerfile.prof
164+
${Q}echo "BUILD ${1} (freeradius4-$(PROFILE)/${1}) > $(DD)/build.${1}-profile.build"
165+
${Q}docker build $(DOCKER_BUILD_OPTS) . \
166+
-f $(DT)/${1}/Dockerfile.prof \
167+
-t freeradius4-$(PROFILE)/${1} \
168+
>$(DD)/build.${1}-profile.build 2>&1
169+
${Q}touch $(DD)/stamp-image.${1}-profile.build
170+
143171
#
144172
# Start up the docker container
145173
#
@@ -249,6 +277,29 @@ $(DT)/${1}/Dockerfile.cb: $(DOCKER_TMPL) $(CB_DIR)/m4/crossbuild.deb.m4 $(CB_DIR
249277
${Q}echo REGEN ${1}
250278
${Q}m4 -I $(CB_DIR)/m4 -D D_NAME=${1} -D D_TYPE=crossbuild $$< > $$@
251279

280+
#
281+
# Regenerate Dockerfile.prof from m4 template
282+
#
283+
.PHONY: crossbuild.${1}.profile.regen
284+
crossbuild.${1}.profile.regen: $(DT)/${1}/Dockerfile.prof
285+
286+
$(DT)/${1}/Dockerfile.prof: $(DOCKER_TMPL) $(CB_DIR)/m4/profiling.deb.m4
287+
${Q}echo REGEN ${1}
288+
${Q}m4 -I $(CB_DIR)/m4 \
289+
-D D_NAME=${1} \
290+
-D D_TYPE=profiling \
291+
-D CB_IMAGE=$(CB_IPREFIX)/${1} \
292+
-D PROFILE_NAME=$(PROFILE) \
293+
$$< > $$@
294+
295+
#
296+
# Remove profiling stamp so next profile.build starts clean
297+
#
298+
.PHONY: crossbuild.${1}.profile.reset
299+
crossbuild.${1}.profile.reset:
300+
${Q}echo RESET profiling ${1}
301+
${Q}rm -f $(DD)/stamp-image.${1}-profile.build
302+
252303
#
253304
# Run the build test
254305
#

scripts/docker/m4/profiling.deb.m4

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
ARG from=CB_IMAGE
2+
FROM ${from}
3+
4+
#
5+
# Install profiling tools
6+
#
7+
# Valgrind/cachegrind
8+
# kcachegrind + KDE/Qt libs
9+
# gperftools
10+
# heaptrack
11+
#
12+
RUN apt-get update && \
13+
apt-get install -y $APT_OPTS \
14+
libgoogle-perftools-dev \
15+
google-perftools \
16+
valgrind \
17+
heaptrack \
18+
psmisc \
19+
kcachegrind \
20+
kio \
21+
libkf5iconthemes5 \
22+
libkf5parts5 \
23+
libkf5textwidgets5 \
24+
libqt5gui5 \
25+
libqt5widgets5 && \
26+
apt-get clean && \
27+
rm -r /var/lib/apt/lists/*
28+
29+
#
30+
# Set up Ubuntu debug symbol repository and install OS library debug symbols.
31+
# These allow profiling tools to resolve system library calls.
32+
#
33+
RUN apt-get update && \
34+
apt-get install -y $APT_OPTS ubuntu-dbgsym-keyring && \
35+
printf 'deb http://ddebs.ubuntu.com OS_CODENAME main restricted universe multiverse\ndeb http://ddebs.ubuntu.com OS_CODENAME-updates main restricted universe multiverse\n' \
36+
> /etc/apt/sources.list.d/ddebs.list && \
37+
apt-get update && \
38+
apt-get install -y $APT_OPTS \
39+
libc6-dbg \
40+
zlib1g-dbgsym \
41+
libreadline8t64-dbgsym \
42+
libssl3t64-dbgsym \
43+
libsasl2-2-dbgsym \
44+
libpam0g-dbgsym \
45+
libldap2-dbgsym \
46+
libtalloc2-dbgsym \
47+
libpcre2-8-0-dbgsym \
48+
libpcap0.8t64-dbgsym \
49+
libcurl4t64-dbgsym \
50+
libunbound8-dbgsym \
51+
libsqlite3-0-dbgsym \
52+
libpq5-dbgsym \
53+
libmariadb3-dbgsym \
54+
libgdbm6t64-dbgsym \
55+
libjson-c5-dbgsym \
56+
libbrotli1-dbgsym \
57+
libhiredis1.1.0-dbgsym \
58+
librdkafka1-dbgsym \
59+
libwbclient0-dbgsym && \
60+
apt-get clean && \
61+
rm -r /var/lib/apt/lists/*
62+
63+
ENV DEBUGINFOD_URLS="https://debuginfod.ubuntu.com"
64+
65+
#
66+
# Rebuild libkqueue from source with debug symbols.
67+
# CMAKE_BUILD_TYPE must be explicitly set to prevent
68+
# the libkqueue project from overriding the flags.
69+
# libkqueue source currently uses "-O2 -g -DNDEBUG" by default.
70+
#
71+
RUN apt-get update && \
72+
apt-get install -y $APT_OPTS --no-install-recommends cmake git && \
73+
apt-get clean && \
74+
rm -r /var/lib/apt/lists/* && \
75+
git clone --depth 1 https://github.com/mheily/libkqueue.git /tmp/libkqueue && \
76+
cd /tmp/libkqueue && \
77+
cmake -G "Unix Makefiles" \
78+
-DCMAKE_INSTALL_PREFIX=/usr \
79+
-DCMAKE_INSTALL_LIBDIR=lib \
80+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
81+
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g3 -O1 -fno-omit-frame-pointer -DNDEBUG" \
82+
. && \
83+
make && \
84+
cpack -G DEB && \
85+
dpkg -i *.deb && \
86+
cd / && rm -rf /tmp/libkqueue
87+
88+
#
89+
# Install FlameGraph
90+
#
91+
RUN git clone --depth 1 https://github.com/brendangregg/FlameGraph /opt/flamegraph \
92+
&& chmod +x /opt/flamegraph/*.pl /opt/flamegraph/*.sh
93+
94+
# Add FlameGraph to path
95+
ENV PATH="/opt/flamegraph:${PATH}"
96+
97+
#
98+
# Install Inferno for callgrind. Inferno is a Rust port of FlameGraph with broader format support
99+
#
100+
RUN apt-get update && \
101+
apt-get install -y $APT_OPTS --no-install-recommends \
102+
cargo && \
103+
cargo install inferno --version 0.11.21 --locked --root /usr/local && \
104+
apt-get clean && \
105+
rm -r /var/lib/apt/lists/*
106+
107+
EXPOSE 1812/udp 1813/udp
108+
CMD ["/bin/sh", "-c", "while true; do sleep 60; done"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Default server profiling "profile".
2+
3+
Future location of various scripts used to configure the server for profiling, and start profiling tools.

0 commit comments

Comments
 (0)