Skip to content

Instantly share code, notes, and snippets.

@qzaidi
Created August 4, 2012 04:21
Show Gist options
  • Save qzaidi/3254449 to your computer and use it in GitHub Desktop.
Save qzaidi/3254449 to your computer and use it in GitHub Desktop.
jsstack - pstack like tool for node.js apps
#!/usr/bin/env node
"use strict";
var debug = require('_debugger');
var c = new debug.Client();
function main() {
console.log('requesting trace');
c.reqBacktrace(function(err,trace) {
if (!err) {
trace.frames.forEach(function(frame) {
process.stderr.write(frame.text + '\n');
});
process.exit(0);
} else {
console.error(err);
process.exit(1);
}
});
}
function usage() {
var procname = process.argv[1].split('/').pop()
console.log('Usage: ' + procname + ' <pid of node process>');
process.exit(1);
}
c.on('error', function() {
console.log('[Failed]');
});
c.once('ready', function() {
console.log('[ok]');
c.reqVersion(function(err,version,state) {
console.log('v8: ' + version);
main();
});
});
if (process.argv.length < 3)
usage();
var pid = process.argv[2];
process.kill(pid,'SIGUSR1');
setTimeout(function() {
process.stdout.write('connecting ... ');
c.connect(5858);
}, 500);
@lkh5510
Copy link

lkh5510 commented Sep 9, 2019

Hello.
I want to use this code. But I don't know the _debugger module.
Is the module in npm?

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