Skip to content

Commit 84acb9f

Browse files
ofrobotsMylesBorins
authored andcommitted
doc: add inspector usage example
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>
1 parent 46b5915 commit 84acb9f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/api/inspector.md

+26
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,34 @@ with an error. [`session.connect()`] will need to be called to be able to send
136136
messages again. Reconnected session will lose all inspector state, such as
137137
enabled agents or configured breakpoints.
138138

139+
## Example usage
140+
141+
### CPU Profiler
142+
143+
Apart from the debugger, various V8 Profilers are available through the DevTools
144+
protocol. Here's a simple example showing how to use the [CPU profiler][]:
145+
146+
```js
147+
const inspector = require('inspector');
148+
149+
const session = new inspector.Session();
150+
session.connect();
151+
152+
session.post('Profiler.enable', () => {
153+
session.post('Profiler.start', () => {
154+
// invoke business logic under measurement here...
155+
156+
// some time later...
157+
session.post('Profiler.stop', ({ profile }) => {
158+
// write profile to disk, upload, etc.
159+
});
160+
});
161+
});
162+
```
163+
139164

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

0 commit comments

Comments
 (0)