@@ -154,10 +154,12 @@ to the run-time events.
154
154
155
155
## Example usage
156
156
157
+ Apart from the debugger, various V8 Profilers are available through the DevTools
158
+ protocol.
159
+
157
160
### CPU Profiler
158
161
159
- Apart from the debugger, various V8 Profilers are available through the DevTools
160
- protocol. Here's a simple example showing how to use the [ CPU profiler] [ ] :
162
+ Here's an example showing how to use the [ CPU Profiler] [ ] :
161
163
162
164
``` js
163
165
const inspector = require (' inspector' );
@@ -180,8 +182,33 @@ session.post('Profiler.enable', () => {
180
182
});
181
183
```
182
184
185
+ ### Heap Profiler
186
+
187
+ Here's an example showing how to use the [ Heap Profiler] [ ] :
188
+
189
+ ``` js
190
+ const inspector = require (' inspector' );
191
+ const fs = require (' fs' );
192
+ const session = new inspector.Session ();
193
+
194
+ const fd = fs .openSync (' profile.heapsnapshot' , ' w' );
195
+
196
+ session .connect ();
197
+
198
+ session .on (' HeapProfiler.addHeapSnapshotChunk' , (m ) => {
199
+ fs .writeSync (fd, m .params .chunk );
200
+ });
201
+
202
+ session .post (' HeapProfiler.takeHeapSnapshot' , null , (err , r ) => {
203
+ console .log (' Runtime.takeHeapSnapshot done:' , err, r);
204
+ session .disconnect ();
205
+ fs .closeSync (fd);
206
+ });
207
+ ```
208
+
183
209
[ `'Debugger.paused'` ] : https://chromedevtools.github.io/devtools-protocol/v8/Debugger#event-paused
184
210
[ `EventEmitter` ] : events.html#events_class_eventemitter
185
211
[ `session.connect()` ] : #inspector_session_connect
186
212
[ CPU Profiler ] : https://chromedevtools.github.io/devtools-protocol/v8/Profiler
187
213
[ Chrome DevTools Protocol Viewer ] : https://chromedevtools.github.io/devtools-protocol/v8/
214
+ [ Heap Profiler ] : https://chromedevtools.github.io/devtools-protocol/v8/HeapProfiler
0 commit comments