Created
August 17, 2016 08:21
-
-
Save aisk/bb8e821e2cfe4213eb2223770f8facb2 to your computer and use it in GitHub Desktop.
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
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