Skip to content

Instantly share code, notes, and snippets.

@rf
Last active May 20, 2016 18:15
Show Gist options
  • Save rf/8d030998b36b33301c18 to your computer and use it in GitHub Desktop.
Save rf/8d030998b36b33301c18 to your computer and use it in GitHub Desktop.
Symbolicate linux perf output of a node program using the v8 log
var fs = require('fs');
var infile = process.argv[2];
if (!infile) return console.log("need infile");
var data = fs.readFileSync(infile, 'utf8').split('\n');
var outlines = [];
data.forEach(function(item) {
var parts = item.split(',');
if (parts.length < 5) return;
if (parts[0] != 'code-creation') return;
var length = parseInt(parts[3], 10).toString(16);
var type = parts[1];
var start = parts[2].slice(2);
var name = parts[4].slice(1, -1);
outlines.push(start + " " + length + " " + type + ":" + name);
});
console.log(outlines.join('\n'));

Use the v8 log to symbolicate linux perf output without having to upgrade yo node. This works with node v0.10. v0.11 has a slightly different v8 log file format so it won't quite work but a similar technique would work.

Run node like this

$ node --logfile="/tmp/node-%p.log" --nocompact_code_space --log_code program.js

Get some perf samples

$ perf record -e cycles:u -g -p $PID

Then convert the v8 log file to a perf map

$ node convert.js /tmp/node-$PID.log > /tmp/perf-$PID.map

Extract trace from perf.data file

$ perf script > perf-script.txt

And make a flame graph

cat perf-script.txt | flamegraph --inputtype perf > perf-graph.svg
@Redsandro
Copy link

The process works, but my flame graphs basically show two horizontal bars. Doesn't seem like anything of value is captured. Does this still work with node 0.10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment