Skip to content

Commit

Permalink
doc: add inspector usage example
Browse files Browse the repository at this point in the history
Add a simple example showing how to use the inspector API to access
the CPU profiler.

PR-URL: #19172
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
  • Loading branch information
ofrobots authored and MylesBorins committed Mar 20, 2018
1 parent 46b5915 commit 84acb9f
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit 84acb9f

Please sign in to comment.