I am looking on implementing the performance analysis for the web page. I have gone through some of the tools available and found Dev tools will be helpful. Is there any REST API to trigger the profiler from node.js?
Yes, see documentation here: https://nodejs.org/api/inspector.html#inspector_cpu_profiler
const inspector = require('inspector');
const fs = require('fs');
const session = new inspector.Session();
session.connect();
session.post('Profiler.enable', () => {
session.post('Profiler.start', () => {
// Invoke business logic under measurement here...
// some time later...
session.post('Profiler.stop', (err, { profile }) => {
// Write profile to disk, upload, etc.
if (!err) {
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
}
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With