Skip to content

Commit

Permalink
doc: fix/improve inspector profiler example
Browse files Browse the repository at this point in the history
The first parameter to the callback is `err`. Fix that. Expand example
to demonstrate an actual write to disk.

PR-URL: #19379
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
ofrobots committed Mar 20, 2018
1 parent c1695d8 commit 2725acf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions doc/api/inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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));
}
});
});
});
Expand Down

0 comments on commit 2725acf

Please sign in to comment.