| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 46b5915 commit 84acb9f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,8 +136,34 @@ with an error. [`session.connect()`] will need to be called to be able to send | |||
| 136 | 136 | messages again. Reconnected session will lose all inspector state, such as | |
| 137 | 137 | enabled agents or configured breakpoints. | |
| 138 | 138 | ||
| 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 | + | ||
| 139 | 164 | ||
| 140 | 165 | [`session.connect()`]: #inspector_session_connect | |
| 141 | 166 | [`Debugger.paused`]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#event-paused | |
| 142 | 167 | [`EventEmitter`]: events.html#events_class_eventemitter | |
| 143 | 168 | [Chrome DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/v8/ | |
| 169 | + [CPU Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/Profiler | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments