Node Perf Flame Graphs

Node Perf Flamegraphs

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


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 to format the output.

perf script | ~/source/FlameGraph/ > out.perf.folded

Now generate the flamegraph.

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

The resulting svg can be viewed in a browser.