| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 76c22f8 commit 5ad9929
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + common.skipIfInspectorDisabled(); | ||
| 5 | + | ||
| 6 | + // Test that example code in doc/api/inspector.md continues to work with the V8 | ||
| 7 | + // experimental API. | ||
| 8 | + | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + const inspector = require('inspector'); | ||
| 11 | + const session = new inspector.Session(); | ||
| 12 | + | ||
| 13 | + session.connect(); | ||
| 14 | + | ||
| 15 | + const chunks = []; | ||
| 16 | + | ||
| 17 | + session.on('HeapProfiler.addHeapSnapshotChunk', (m) => { | ||
| 18 | + chunks.push(m.params.chunk); | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + session.post('HeapProfiler.takeHeapSnapshot', null, common.mustCall((e, r) => { | ||
| 22 | + assert.ifError(e); | ||
| 23 | + assert.deepStrictEqual(r, {}); | ||
| 24 | + session.disconnect(); | ||
| 25 | + | ||
| 26 | + const profile = JSON.parse(chunks.join('')); | ||
| 27 | + assert(profile.snapshot.meta); | ||
| 28 | + assert(profile.snapshot.node_count > 0); | ||
| 29 | + assert(profile.snapshot.edge_count > 0); | ||
| 30 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments