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 -- ~/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
taken from https://yunong.io/2015/11/23/generating-node-js-flame-graphs/
$ uname -a
Linux demo 3.2.0-74-virtual #109-Ubuntu SMP Tue Dec 9 17:04:48 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ node --version
v5.0.0
$ node --perf-basic-prof-only-functions demo.js&
$ sudo perf record -F 99 -p pgrep -n node -g -- sleep 30
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.531 MB perf.data (~23181 samples) ]
$ ls /tmp/*.map
/tmp/perf-13083.map
$ sudo chown root /tmp/perf-13083.map
$ sudo perf script > nodestacks
$ git clone --depth 1 http://github.com/brendangregg/FlameGraph
$ cd FlameGraph
$ ./stackcollapse-perf.pl < ../nodestacks | ./flamegraph.pl --colors js > ../node-flamegraph.svg