doc: add inspector usage example
Add a simple example showing how to use the inspector API to access the CPU profiler. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
50b1cb39bd
commit
fbf7ff92d7
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user