Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Forked from rf/convert.js
Last active August 29, 2015 14:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alessioalex/c7d6ce69974576c130ef to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment