Skip to content

Commit 4f391f7

Browse files
committed
Added perf & flame-graph
1 parent 235e066 commit 4f391f7

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

base.Dockerfile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ FROM ${OS}:${TAG} as base
66
# Install required packages
77
ARG CLANG_VER=12
88
ARG GCC_VER=11
9-
RUN apt update
109
RUN export DEBIAN_FRONTEND=noninteractive \
11-
&& apt install -y git htop sudo curl wget net-tools jq \
10+
&& apt update && apt install -y git htop sudo curl wget net-tools jq locales\
1211
build-essential cmake ninja-build valgrind gdb rr doxygen \
1312
clang-${CLANG_VER} clang-tidy-${CLANG_VER} clang-format-${CLANG_VER} clang-tools-${CLANG_VER} \
1413
gcc-${GCC_VER} g++-${GCC_VER} \
15-
python3 python3-pip
14+
python3 python3-pip \
15+
libbabeltrace-ctf-dev systemtap-sdt-dev libslang2-dev libelf-dev libunwind-dev libdw-dev libiberty-dev
1616

1717
# Set selected clang version as default
1818
RUN ln -s /usr/bin/clang-${CLANG_VER} /usr/bin/clang \
@@ -31,6 +31,15 @@ COPY scripts/setup.sh /tmp
3131
RUN /tmp/setup.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "true" \
3232
&& rm -f /tmp/setup.sh
3333
#################################################################################################
34+
FROM base as perf-builder
35+
36+
RUN export DEBIAN_FRONTEND=noninteractive \
37+
&& apt install -y --no-install-recommends gcc-8 g++-8 flex bison
38+
RUN export CC=gcc-8 && export CXX=g++-8 \
39+
&& git clone --branch linux-msft-wsl-5.10.y --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git /tmp/wsl2-kernel \
40+
&& cd /tmp/wsl2-kernel/tools/perf && make
41+
42+
#################################################################################################
3443
FROM base as codechecker-builder
3544

3645
RUN export DEBIAN_FRONTEND=noninteractive \
@@ -46,15 +55,24 @@ RUN cd /codechecker \
4655

4756
#################################################################################################
4857
FROM base
58+
# Setup perf
59+
COPY --from=perf-builder /tmp/wsl2-kernel/tools/perf/perf /usr/local/bin
4960

5061
# Setup CodeChecker
5162
COPY --from=codechecker-builder /codechecker/build/CodeChecker /opt/codechecker
5263
COPY --from=codechecker-builder /codechecker/analyzer/requirements.txt /opt/codechecker
5364
RUN pip3 install -r /opt/codechecker/requirements.txt \
5465
&& ln -s /opt/codechecker/bin/CodeChecker /usr/bin/CodeChecker
5566

67+
# Setup flame-graph
68+
RUN git clone --depth=1 https://github.com/brendangregg/FlameGraph /opt/flame-graph
69+
5670
# Setup cmake utils
5771
COPY scripts/.CodeCheckerIgnore scripts/utils.cmake /opt/cmake-utils/
5872

73+
#Setup profiling script
74+
COPY scripts/cpu-profile.sh /opt
75+
RUN ln -s /opt/cpu-profile.sh /usr/bin/cpu-profile
76+
5977
# Cleanup
6078
RUN export DEBIAN_FRONTEND=noninteractive && apt autoremove -y

devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dockerfile": "Dockerfile"
55
},
66
// The extra security opthion is for advanced debugging and analysis an should be used only in development
7-
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--rm"],
7+
"runArgs": [ "--cap-add=SYS_ADMIN", "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--rm"],
88

99
// Set *default* container specific settings.json values on container create.
1010
"settings": {},

scripts/cpu-profile.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# TODO: There is a room for improvant and validation
6+
if [ "$#" -ne 2 ]; then
7+
echo "Usage: cpu-profile <command> <output_path>"
8+
exit 1
9+
fi
10+
11+
12+
perf record -g -F max -o /tmp/perf.data $1
13+
perf script -i /tmp/perf.data > /tmp/perf.script
14+
/opt/flame-graph/stackcollapse-perf.pl /tmp/perf.script | /opt/flame-graph/flamegraph.pl > $2/perf.svg

scripts/setup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}"
7171
EXISTING_NON_ROOT_USER="${USERNAME}"
7272
fi
7373

74+
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
75+
# Common need for both applications and things like the agnoster ZSH theme.
76+
if ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then
77+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
78+
locale-gen
79+
fi
80+
7481
# ** Shell customization section **
7582
if [ "${USERNAME}" = "root" ]; then
7683
USER_RC_PATH="/root"

scripts/utils.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ add_custom_target(
66

77
add_custom_target(
88
tidy-fix
9-
# The double run-clang-tidy is because when -fix is applied the fixed error are still shown
10-
COMMAND run-clang-tidy -p build/ -fix -quiet && run-clang-tidy -p build/
9+
COMMAND run-clang-tidy -p build/ -fix -quiet
1110
WORKING_DIRECTORY ..
1211
)
1312

0 commit comments

Comments
 (0)