diff --git a/doc/api/inspector.md b/doc/api/inspector.md index c801510b7563f2..9dafdb7e1b3d6c 100644 --- a/doc/api/inspector.md +++ b/doc/api/inspector.md @@ -145,7 +145,7 @@ protocol. Here's a simple example showing how to use the [CPU profiler][]: ```js const inspector = require('inspector'); - +const fs = require('fs'); const session = new inspector.Session(); session.connect(); @@ -154,8 +154,11 @@ session.post('Profiler.enable', () => { // invoke business logic under measurement here... // some time later... - session.post('Profiler.stop', ({ profile }) => { + session.post('Profiler.stop', (err, { profile }) => { // write profile to disk, upload, etc. + if (!err) { + fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile)); + } }); }); });