Skip to content

Instantly share code, notes, and snippets.

@rf rf/convert.js
Last active May 20, 2016

What would you like to do?
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);

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-$

Extract trace from file

$ perf script > perf-script.txt

And make a flame graph

cat perf-script.txt | flamegraph --inputtype perf > perf-graph.svg

This comment has been minimized.

Copy link

commented May 1, 2015

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
You can’t perform that action at this time.