Created
July 28, 2018 12:30
-
-
Save tankala/be5d569bb4ef4fe0724be01f21819c31 to your computer and use it in GitHub Desktop.
CPU profiling using v8-profiler
This file contains hidden or 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
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