Skip to content

Commit d6a8e8a

Browse files
committed
Crossbuilds now support generating profiling images
1 parent 92d750b commit d6a8e8a

8 files changed

Lines changed: 163 additions & 2 deletions

File tree

scripts/docker/build/ubuntu24/Dockerfile.cb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ RUN apt-get update && \
3232
rm -r /var/lib/apt/lists/*
3333

3434

35+
#
36+
# Install profiling tools
37+
#
38+
RUN apt-get update && \
39+
apt-get install $APT_OPTS \
40+
libgoogle-perftools-dev \
41+
google-perftools \
42+
valgrind \
43+
heaptrack \
44+
psmisc \
45+
kcachegrind \
46+
kio \
47+
libkf5iconthemes5 \
48+
libkf5parts5 \
49+
libkf5textwidgets5 \
50+
libqt5gui5 \
51+
libqt5widgets5 && \
52+
apt-get clean && \
53+
rm -r /var/lib/apt/lists/*
54+
55+
#
56+
# Install FlameGraph scripts
57+
#
58+
RUN git clone --depth 1 https://github.com/brendangregg/FlameGraph /opt/flamegraph \
59+
&& chmod +x /opt/flamegraph/*.pl /opt/flamegraph/*.sh
60+
61+
ENV PATH="/opt/flamegraph:${PATH}"
62+
3563
#
3664
# Set up NetworkRADIUS extras repository
3765
#
@@ -81,12 +109,15 @@ RUN git clone --depth 1 --no-single-branch ${source}
81109

82110
#
83111
# Install build dependencies for all branches from v4 onwards
112+
# Debian sid fails if debian/control doesn't exist due to an issue
113+
# in one of the included make files, so we create a blank file.
84114
#
85115
WORKDIR freeradius-server
86116
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); \
87117
do \
88118
git checkout $i; \
89119
if [ -e ./debian/control.in ] ; then \
120+
touch -t 202001010000 debian/control; \
90121
debian/rules debian/control ; \
91122
fi ; \
92123
mk-build-deps -irt"apt-get -o Debug::pkgProblemResolver=yes $APT_OPTS" debian/control ; \

scripts/docker/crossbuild.mk

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ DD:=$(CB_DIR)/crossbuild
2626
DOCKER_TMPL:=$(CB_DIR)/m4/Dockerfile.m4
2727

2828
# List of all the docker images (sorted for "crossbuild.info")
29-
CB_IMAGES:=$(sort $(patsubst $(DT)/%,%,$(wildcard $(DT)/*)))
29+
CB_IMAGES := $(sort $(filter-out profiling,\
30+
$(patsubst $(DT)/%/,%,$(wildcard $(DT)/*/))))
3031

3132
# Location of the .git dir (may be different for e.g. submodules)
3233
GITDIR:=$(shell perl -MCwd -e 'print Cwd::abs_path shift' $$(git rev-parse --git-dir))
@@ -40,6 +41,8 @@ endif
4041
CB_IPREFIX:=freeradius40x-build
4142
CB_CPREFIX:=fr40x-crossbuild-
4243

44+
PROFILE ?= profiling1
45+
4346
#
4447
# This Makefile is included in-line, and not via the "boilermake"
4548
# wrapper. But it's still useful to use the same process for
@@ -90,6 +93,23 @@ crossbuild.help: crossbuild.info
9093
@echo " crossbuild.IMAGE.clean - stop container and tidy up"
9194
@echo " crossbuild.IMAGE.wipe - remove Docker image"
9295
@echo ""
96+
@echo "Profiling targets:"
97+
@echo " crossbuild.IMAGE.profregen - regenerate Dockerfile.prof using default profile ($(PROFILE))"
98+
@echo " crossbuild.IMAGE.profregen PROFILE=<name> - regenerate using a specific profile"
99+
@echo " crossbuild.IMAGE.profbuild - build profiling image using default profile ($(PROFILE))"
100+
@echo " crossbuild.IMAGE.profbuild PROFILE=<name> - build using a specific profile"
101+
@echo ""
102+
@echo "Available profiling profiles (scripts/docker/profiling/profiles/):"
103+
@echo " valgrind-callgrind - callgrind call graph and instruction profiling"
104+
@echo " valgrind-massif - FUTURE: massif heap memory profiling"
105+
@echo " gperftools-cpu - FUTURE: gperftools CPU profiling"
106+
@echo ""
107+
@echo "Profiling examples:"
108+
@echo " make crossbuild.ubuntu24.profregen"
109+
@echo " make crossbuild.ubuntu24.profregen PROFILE=valgrind-callgrind"
110+
@echo " make crossbuild.ubuntu24.profbuild"
111+
@echo " make crossbuild.ubuntu24.profbuild PROFILE=gperftools-cpu"
112+
@echo ""
93113
@echo "Use 'make NOCACHE=1 ...' to disregard the Docker cache on build"
94114

95115
#
@@ -140,6 +160,20 @@ $(DD)/stamp-image.${1}:
140160
${Q}docker build $(DOCKER_BUILD_OPTS) $(DT)/${1} -f $(DT)/${1}/Dockerfile.cb -t $(CB_IPREFIX)/${1} >$(DD)/build.${1} 2>&1
141161
${Q}touch $(DD)/stamp-image.${1}
142162

163+
#
164+
# Build the profiling image
165+
#
166+
.PHONY: crossbuild.${1}.profbuild
167+
crossbuild.${1}.profbuild: $(DD)/stamp-image.${1}-profbuild
168+
169+
$(DD)/stamp-image.${1}-profbuild: $(DT)/${1}/Dockerfile.prof
170+
${Q}echo "BUILD ${1} ($(CB_IPREFIX)/${1}-prof) > $(DD)/build.${1}-profbuild"
171+
${Q}docker build $(DOCKER_BUILD_OPTS) . \
172+
-f $(DT)/${1}/Dockerfile.prof \
173+
-t $(CB_IPREFIX)/${1}-prof \
174+
>$(DD)/build.${1}-profbuild 2>&1
175+
${Q}touch $(DD)/stamp-image.${1}-profbuild
176+
143177
#
144178
# Start up the docker container
145179
#
@@ -249,6 +283,21 @@ $(DT)/${1}/Dockerfile.cb: $(DOCKER_TMPL) $(CB_DIR)/m4/crossbuild.deb.m4 $(CB_DIR
249283
${Q}echo REGEN ${1}
250284
${Q}m4 -I $(CB_DIR)/m4 -D D_NAME=${1} -D D_TYPE=crossbuild $$< > $$@
251285

286+
#
287+
# Regenerate Dockerfile.prof from m4 template
288+
#
289+
.PHONY: crossbuild.${1}.profregen
290+
crossbuild.${1}.profregen: $(DT)/${1}/Dockerfile.prof
291+
292+
$(DT)/${1}/Dockerfile.prof: $(DOCKER_TMPL) $(CB_DIR)/m4/profiling.deb.m4 $(CB_DIR)/m4/profiling.rpm.m4
293+
${Q}echo REGEN ${1}
294+
${Q}m4 -I $(CB_DIR)/m4 \
295+
-D D_NAME=${1} \
296+
-D D_TYPE=profiling \
297+
-D CB_IMAGE=$(CB_IPREFIX)/${1} \
298+
-D PROFILE_NAME=$(PROFILE) \
299+
$$< > $$@
300+
252301
#
253302
# Run the build test
254303
#

scripts/docker/docker.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DT:=$(CB_DIR)/build
2222
DOCKER_TMPL:=$(CB_DIR)/m4/Dockerfile.m4
2323

2424
# List of all the docker images (sorted for "docker.info")
25-
IMAGES:=$(sort $(patsubst $(DT)/%,%,$(wildcard $(DT)/*)))
25+
IMAGES:=$(sort $(filter-out profiling,$(patsubst $(DT)/%,%,$(wildcard $(DT)/*))))
2626

2727
# Don't use the Docker cache if asked
2828
ifneq "$(NOCACHE)" ""

scripts/docker/m4/crossbuild.deb.m4

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ RUN apt-get update && \
2727
rm -r /var/lib/apt/lists/*
2828

2929

30+
#
31+
# Install profiling tools
32+
#
33+
RUN apt-get update && \
34+
apt-get install $APT_OPTS \
35+
libgoogle-perftools-dev \
36+
google-perftools \
37+
valgrind \
38+
heaptrack \
39+
psmisc \
40+
kcachegrind \
41+
kio \
42+
libkf5iconthemes5 \
43+
libkf5parts5 \
44+
libkf5textwidgets5 \
45+
libqt5gui5 \
46+
libqt5widgets5 && \
47+
apt-get clean && \
48+
rm -r /var/lib/apt/lists/*
49+
50+
#
51+
# Install FlameGraph scripts
52+
#
53+
RUN git clone --depth 1 https://github.com/brendangregg/FlameGraph /opt/flamegraph \
54+
&& chmod +x /opt/flamegraph/*.pl /opt/flamegraph/*.sh
55+
56+
ENV PATH="/opt/flamegraph:${PATH}"
57+
3058
#
3159
# Set up NetworkRADIUS extras repository
3260
#

scripts/docker/m4/profiling.deb.m4

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG from=CB_IMAGE
2+
FROM ${from}
3+
4+
# Copy profiling profile scripts into the container
5+
COPY scripts/docker/profiling/profiles/PROFILE_NAME /profiling
6+
7+
RUN /profiling/configure.sh
8+
RUN make
9+
RUN make install
10+
11+
# Make sure freeradius can also be used to run server
12+
RUN ln -s /usr/local/sbin/radiusd /usr/local/sbin/freeradius
13+
14+
WORKDIR /
15+
COPY scripts/docker/etc/docker-entrypoint.sh.PKG_TYPE docker-entrypoint.sh
16+
RUN chmod +x docker-entrypoint.sh
17+
18+
EXPOSE 1812/udp 1813/udp
19+
ENTRYPOINT ["/docker-entrypoint.sh"]
20+
CMD ["/profiling/start.sh"]

scripts/docker/m4/profiling.rpm.m4

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG from=CB_IMAGE
2+
FROM ${from}
3+
4+
# Copy profiling profile scripts into the container
5+
COPY scripts/docker/profiling/profiles/PROFILE_NAME /profiling
6+
7+
RUN /profiling/configure.sh
8+
RUN make
9+
RUN make install
10+
11+
# Make sure freeradius can also be used to run server
12+
RUN ln -s /usr/local/sbin/radiusd /usr/local/sbin/freeradius
13+
14+
WORKDIR /
15+
COPY scripts/docker/etc/docker-entrypoint.sh.PKG_TYPE docker-entrypoint.sh
16+
RUN chmod +x docker-entrypoint.sh
17+
18+
EXPOSE 1812/udp 1813/udp
19+
ENTRYPOINT ["/docker-entrypoint.sh"]
20+
CMD ["/profiling/start.sh"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
./configure \
3+
--enable-developer \
4+
--disable-verify-ptr \
5+
--sysconfdir=/etc \
6+
CFLAGS="-g3 -O1 -fno-omit-frame-pointer" \
7+
LDFLAGS="-fno-omit-frame-pointer"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
exec valgrind \
3+
--tool=callgrind \
4+
--callgrind-out-file=/etc/prof-results/callgrind.out.%p \
5+
--collect-jumps=yes \
6+
freeradius -f -l stdout -S resources.talloc_skip_cleanup=yes

0 commit comments

Comments
 (0)