Skip to content

Instantly share code, notes, and snippets.

@tankala
Created July 28, 2018 12:30
Show Gist options
  • Save tankala/be5d569bb4ef4fe0724be01f21819c31 to your computer and use it in GitHub Desktop.
Save tankala/be5d569bb4ef4fe0724be01f21819c31 to your computer and use it in GitHub Desktop.
CPU profiling using v8-profiler
app.get('/doCPUProfiling/profileId/:profileId/durationInSec/:durationInSec', function (req, res) {
let profileId = req.params['profileId'];
let durationInMilliSec = req.params['durationInSec'] * 1000;
// Start profiling
profiler.startProfiling(profileId);
setTimeout(function () {
stopProfiling(profileId);
}, durationInMilliSec);
res.json({});
});
var stopProfiling = function(profileId) {
let profile = profiler.stopProfiling(profileId);
fs.writeFile(__dirname + '/' + profileId + '.cpuprofile', JSON.stringify(profile), function () {
console.log('Profiler data written');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment