Node Perf Flame Graphs

Node Perf Flamegraphs

A short guide to creating CPU profile flamegraphs for a node program.

Dependencies

This requires at least node 0.11.

Also this guide is designed for Centos 7.

FlameGraph tools are required too.

Creating Flamegraphs

Start node with the --perf_basic_prof option.

NODE_ENV=dev_local node --perf_basic_prof ~/projects/baymax/smartconnect/bin/start.js 2>&1 | tee /tmp/logs/smartconnect/smartconnect.log

Get the pid of the process and capture with perf.

perf record -i -g -e cycles:u -p `ps aux | grep smartconnect | grep node | awk '{print $2}'`

Use perf script and pipe to stackcollapse-perf.pl to format the output.

perf script | ~/source/FlameGraph/stackcollapse-perf.pl > out.perf.folded

Now generate the flamegraph.

~/source/FlameGraph/flamegraph.pl --color=js out.perf.folded > out.perf.svg

The resulting svg can be viewed in a browser.