Skip to content

Instantly share code, notes, and snippets.

@sbz
Last active May 30, 2018 14:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sbz/fed2f5f441653a4e231eac9639d51339 to your computer and use it in GitHub Desktop.
Run pyflame against your python code, to profile it and generate a flamegraph (here it's against singularity-monitor)
#!/bin/bash
sudo apt-get install -y autoconf automake autotools-dev g++ pkg-config python-dev python3-dev libtool make
[ ! -f ./flamegraph.pl ] && {
curl -O https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl
}
[ ! -f /usr/local/bin/pyflame -o ! -d pyflame ] && {
git clone https://github.com/uber/pyflame.git
cd pyflame
./autogen.sh
./configure --prefix=/usr/local
make
sudo make install
}
process="singularity-monitor"
pid=`pgrep ${process%%-*}`
echo "Dump Stack Strace"
sudo /usr/local/bin/pyflame -p ${pid} -d
seconds=180
echo Launching ${seconds} seconds profiling... /usr/local/bin/pyflame -s ${seconds} -r 0.01 -p ${pid}
sudo /usr/local/bin/pyflame -s ${seconds} -r 0.01 -p ${pid} -o ${process}.prof --threads
wait $!
perl ./flamegraph.pl < ${process}.prof > ${process}.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment