Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschenkelman/f6c323e904623ea9b8ea6b8f75e243ee to your computer and use it in GitHub Desktop.
Save dschenkelman/f6c323e904623ea9b8ea6b8f75e243ee to your computer and use it in GitHub Desktop.
Quick steps of how to create a flame graph using perf

The prep-script.sh will setup the latest Node and install the latest perf version on your Linux box.

When you want to generate the flame graph, run the following (folder locations taken from install script):

sudo sysctl kernel.kptr_restrict=0
# May also have to do the following:
# (additional reading http://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar )
sudo sysctl kernel.perf_event_paranoid=0

perf record -i -g -e cycles:u -- node --perf-basic-prof index.js

perf script | egrep -v "( __libc_start| LazyCompile | v8::internal::| Builtin:| Stub:| LoadIC:|\[unknown\]| LoadPolymorphicIC:)" | sed 's/ LazyCompile:[*~]\?/ /' | ~/sources/FlameGraph/stackcollapse-perf.pl > out.perf-folded

~/sources/FlameGraph/flamegraph.pl out.perf-folded > node-flame.svg

The data munging is to help expose the most important bits. There is still some play that I'm working with, but right now it seems to be working.

Alternatives:

perf script | egrep -v "( __libc_start|node::Start\(| LazyCompile | Builtin:| Stub:| LoadIC:|\[unknown\]| LoadPolymorphicIC:)" | ../FlameGraph/stackcollapse-perf.pl | grep "uv_run" > out.perf-folded

perf script | egrep -v "( __libc_start|node::Start\(| LazyCompile | v8::internal::| Builtin:| Stub:| LoadIC:|\[unknown\]| LoadPolymorphicIC:)" | ../FlameGraph/stackcollapse-perf.pl | grep "uv_run" > out.perf-folded
#!/bin/bash
sh /etc/lsb-release
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -
apt-add-repository "deb http://llvm.org/apt/${DISTRIB_CODENAME}/ llvm-toolchain-${DISTRIB_CODENAME} main"
apt-get update
apt-get -y upgrade
apt-get -y install make build-essential linux-tools-common elfutils libelf-dev flex bison libunwind8 libunwind8-dev libaudit-dev libdw-dev binutils-dev libnuma-dev libslang2-dev asciidoc llvm-3.6 clang-3.6 lldb-3.6 libllvm3.6 subversion libc6-dev-i386 libgtk2.0-dev libperl-dev python-dev git tmux nginx gdb apache2-utils
ln -s /usr/bin/clang-3.6 /usr/bin/clang
ln -s /usr/bin/clang++-3.6 /usr/bin/clang++
ln -s /usr/bin/lldb-3.6 /usr/bin/lldb
echo 'export CC=clang' > ~/.bash_aliases
echo 'export CXX=clang++' >> ~/.bash_aliases
echo 'export GYP_DEFINES="clang=1"' >> ~/.bash_aliases
. ~/.bash_aliases
chmod 777 /usr/share/nginx/html
ln -s /usr/share/nginx/html www
mkdir sources
cd ~/sources
wget https://github.com/brendangregg/FlameGraph/archive/master.tar.gz
tar xvf master.tar.gz
rm master.tar.gz
mv FlameGraph-master FlameGraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment