Created
August 4, 2012 04:21
-
-
Save qzaidi/3254449 to your computer and use it in GitHub Desktop.
jsstack - pstack like tool for node.js apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello.
I want to use this code. But I don't know the
_debugger
module.Is the module in npm?