Last active
September 16, 2023 21:07
-
-
Save fcamblor/1dc5a4edc27f89636b473e30c4efa7d2 to your computer and use it in GitHub Desktop.
Async profiler on docker-alpine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM tomcat:7-jre8-alpine | |
# See https://github.com/jvm-profiling-tools/async-profiler/issues/207 | |
RUN apk update && apk add --no-cache libc6-compat perl openjdk8-dbg | |
RUN mkdir /usr/local/async-profiler/ &&\ | |
wget -O /usr/local/async-profiler/async-profiler.tar.gz https://github.com/jvm-profiling-tools/async-profiler/releases/download/v1.5/async-profiler-1.5-linux-x64.tar.gz &&\ | |
cd /usr/local/async-profiler/ &&\ | |
tar -xvzf async-profiler.tar.gz &&\ | |
rm -f /usr/local/async-profiler/async-profiler.tar.gz | |
RUN mkdir /usr/local/flame-graph/ &&\ | |
wget -O /usr/local/flame-graph/flame-graph.zip https://github.com/brendangregg/FlameGraph/archive/1b1c6deede9c33c5134c920bdb7a44cc5528e9a7.zip &&\ | |
cd /usr/local/flame-graph/ && unzip flame-graph.zip &&\ | |
cd /usr/local/flame-graph/ &&\ | |
mv FlameGraph-1b1c6deede9c33c5134c920bdb7a44cc5528e9a7/* ./ &&\ | |
rm -Rf FlameGraph-1b1c6deede9c33c5134c920bdb7a44cc5528e9a7 &&\ | |
rm -f /usr/local/flame-graph/flame-graph.zip | |
# Maybe do some specific stuff (like copy your WAR file inside /usr/local/tomcat/webapps/ROOT, or create a setenv.sh file into /usr/local/tomcat/bin/setenv.sh) | |
CMD ["sh", "-c", "cd /usr/local/tomcat/ && catalina.sh run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It will gather call stacks during 30s on your docker process instance | |
# Note that I added -e itimer option as I never succeeded to configure perf event on docker instance | |
# event through --security-opt=seccomp:unconfined docker configuration property | |
# See https://github.com/jvm-profiling-tools/async-profiler#profiling-java-in-a-container | |
# and https://github.com/jvm-profiling-tools/async-profiler#troubleshooting | |
docker exec -ti <INSTANCE_DOCKER> /usr/local/async-profiler/profiler.sh -d 30 -o collapsed -e itimer -f /tmp/collapsed.txt 1 | |
# It will transform the RAW async profiler data into a flamechart SVG file directly on your HOST machine | |
# (in /tmp/results.svg) | |
docker exec -ti <INSTANCE_DOCKER> /usr/local/flame-graph/flamegraph.pl --colors=java /tmp/collapsed.txt > /tmp/results.svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I just tried your solution in a Dockerfile relying on openjdk:8u212-jdk-alpine as the base image and as soon as I execute the
docker exec -ti $CONTAINER_NAME /usr/local/async-profiler/profiler.sh -d 30 -o collapsed -e itimer -f /tmp/collapsed.txt $PID
command the container exits with the error
Our app is using quite a lot of CPU and we would like to profile it...
Any suggestion is more than welcome! :-) Thanks!