Skip to content

Instantly share code, notes, and snippets.

@tjfontaine
Last active December 27, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjfontaine/7298214 to your computer and use it in GitHub Desktop.
Save tjfontaine/7298214 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var lstream = require('lstream');
var ls = new lstream();
process.stdin.pipe(ls);
var symbolTable = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
ls.on('line', function(line) {
var l = line.trim();
if (l.match(/^0x[a-f0-9]{8}/) && symbolTable[l]) {
line = line.replace(/0x[a-f0-9]{8}/, symbolTable[l]);
}
console.log(line);
});
#!/usr/sbin/dtrace -s
pid$1::umem_alloc:entry
/arg0 > 2048 && arg0 <= 4096/
{
self->cache = arg0;
}
pid$1::umem_cache_alloc:entry
/self->cache/
{
printf("\n>>>>>>>>\n");
jstack(200, 8000);
ustack(200);
printf("\n<<<<<<<<\n");
self->cache = 0;
}
var assert = require('assert');
var lstream = require('lstream');
var ls = new lstream();
process.stdin.pipe(ls);
var jstack = undefined;
var ustack = undefined;
var cur = undefined;
var symbolTable = {};
ls.on('line', function(line) {
if (line.match(/>>>>>>>>/)) {
cur = jstack = [];
ustack = [];
} else if (line.match(/<<<<<<<</)) {
ustack.forEach(function(frame, index) {
frame = frame.trim();
if (frame.match(/^0x[a-f0-9]{8}/)) {
var jframe = jstack[index].trim();
if (!symbolTable[frame]) {
symbolTable[frame] = jframe;
} else {
assert.strictEqual(symbolTable[frame], jframe);
}
}
});
jstack = undefined;
ustack = undefined;
} else if (jstack) {
if (!jstack || (jstack.length === 0 && !line.trim()))
return;
if (!line.trim()) {
cur = ustack;
} else {
cur.push(line);
}
}
});
function printit() {
console.log(JSON.stringify(symbolTable, null, ' '));
}
process.on('exit', printit);
process.on('SIGUSR2', printit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment