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
@dignifiedquire Very nice. Thanks for sharing.
@arunoda The reason for nginx is because I found it was the easiest way to view the flamegraphs myself and share them with others (simple as a single URL). Instead of needing to
scp
/ftp
the file down to my box to look at it.@bjouhier Thanks for the info about the broken XML. Sorry about the
.bash_aliases
break. I used this script on fresh servers that hadn't been touched yet.