Skip to content

Commit cc7ba0b

Browse files
ofrobotsMylesBorins
authored andcommitted
doc: fix/improve inspector profiler example
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 29a04b7 commit cc7ba0b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

doc/api/inspector.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protocol. Here's a simple example showing how to use the [CPU profiler][]:
145145

146146
```js
147147
const inspector = require('inspector');
148-
148+
const fs = require('fs');
149149
const session = new inspector.Session();
150150
session.connect();
151151

@@ -154,8 +154,11 @@ session.post('Profiler.enable', () => {
154154
// invoke business logic under measurement here...
155155

156156
// some time later...
157-
session.post('Profiler.stop', ({ profile }) => {
157+
session.post('Profiler.stop', (err, { profile }) => {
158158
// write profile to disk, upload, etc.
159+
if (!err) {
160+
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
161+
}
159162
});
160163
});
161164
});

0 commit comments

Comments
 (0)