Skip to content

Instantly share code, notes, and snippets.

@aisk
Created August 17, 2016 08:21
Show Gist options
  • Save aisk/bb8e821e2cfe4213eb2223770f8facb2 to your computer and use it in GitHub Desktop.
Save aisk/bb8e821e2cfe4213eb2223770f8facb2 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var router = require('express').Router();
var heapdump = require('heapdump');
var AV = require('leanengine');
router.post('/snapshot', function(req, res, next) {
var name = 'dump_' + Date.now() + '.heapsnapshot';
heapdump.writeSnapshot('/tmp/' + name, function(err, filename) {
if(err) {
return next(err);
}
fs.readFile(filename, function(err, data) {
if(err) {
return next(err);
}
var theFile = new AV.File(name, {base64: data.toString('base64')});
theFile.save().then(function(theFile){
res.send('dump written to _File, name: ' + name);
}, function(err) {
if(err) {
return next(err);
}
});
});
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment