Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add inspector usage example #19172

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions doc/api/inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,34 @@ with an error. [`session.connect()`] will need to be called to be able to send
messages again. Reconnected session will lose all inspector state, such as
enabled agents or configured breakpoints.

## Example usage

### CPU Profiler

Apart from the debugger, various V8 Profilers are available through the DevTools
protocol. Here's a simple example showing how to use the [CPU profiler][]:

```js
const inspector = require('inspector');

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', ({ profile }) => {
// write profile to disk, upload, etc.
});
});
});
```


[`session.connect()`]: #inspector_session_connect
[`Debugger.paused`]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#event-paused
[`EventEmitter`]: events.html#events_class_eventemitter
[Chrome DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/v8/
[CPU Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/Profiler