Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2019-03-07 19:48:54 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-03-11 08:19:11 +0300
commita445244a0c7e25e9b3dcfa48f622ce51f5815dcd (patch)
tree3ed8e0c64f0ac1859867e0ba13589d16d4a4e459 /doc/api/inspector.md
parent8d669bbeb1ed77e9cdc679f75d9e8529f5764087 (diff)
doc: add inspector API example for heapdump
PR-URL: https://github.com/nodejs/node/pull/26498 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/inspector.md')
-rw-r--r--doc/api/inspector.md31
1 files changed, 29 insertions, 2 deletions
diff --git a/doc/api/inspector.md b/doc/api/inspector.md
index f32f6c3032b..63d2a702724 100644
--- a/doc/api/inspector.md
+++ b/doc/api/inspector.md
@@ -154,10 +154,12 @@ to the run-time events.
## Example usage
+Apart from the debugger, various V8 Profilers are available through the DevTools
+protocol.
+
### 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][]:
+Here's an example showing how to use the [CPU Profiler][]:
```js
const inspector = require('inspector');
@@ -180,8 +182,33 @@ session.post('Profiler.enable', () => {
});
```
+### Heap Profiler
+
+Here's an example showing how to use the [Heap Profiler][]:
+
+```js
+const inspector = require('inspector');
+const fs = require('fs');
+const session = new inspector.Session();
+
+const fd = fs.openSync('profile.heapsnapshot', 'w');
+
+session.connect();
+
+session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
+ fs.writeSync(fd, m.params.chunk);
+});
+
+session.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {
+ console.log('Runtime.takeHeapSnapshot done:', err, r);
+ session.disconnect();
+ fs.closeSync(fd);
+});
+```
+
[`'Debugger.paused'`]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger#event-paused
[`EventEmitter`]: events.html#events_class_eventemitter
[`session.connect()`]: #inspector_session_connect
[CPU Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/Profiler
[Chrome DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/v8/
+[Heap Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/HeapProfiler