Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save despairblue/9ef98325d021d824faa0 to your computer and use it in GitHub Desktop.
Save despairblue/9ef98325d021d824faa0 to your computer and use it in GitHub Desktop.

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

perf record -i -g -e cycles:u -- ~/sources/node/node --perf-basic-prof script.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
apt-get update
apt-get -y upgrade
apt-get -y install make build-essential elfutils libelf-dev flex bison libunwind8 libunwind8-dev libaudit-dev libdw-dev binutils-dev libnuma-dev libslang2-dev asciidoc llvm-3.4 clang-3.4 subversion libc6-dev-i386 libgtk2.0-dev libperl-dev python-dev git
echo 'export CC=clang' > .bash_aliases
echo 'export CXX=clang++' >> .bash_aliases
echo 'export GYP_DEFINES="clang=1"' >> .bash_aliases
mkdir sources
cd sources
wget https://github.com/joyent/node/archive/master.tar.gz
tar xvf master.tar.gz
rm master.tar.gz
mv node-master node
cd node
./configure
make
make install
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
cd ~/sources
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.2.tar.sign
tar xvf linux-3.13.6.tar.gz
rm linux-3.13.6.tar.gz
cd linux-3.13.6/tools/perf/
make -f Makefile.perf install prefix=/usr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment