M
v8.getHeapSnapshot
History
Added in: v11.13.0
v11.13.0
Introduced in: v4.0.0
v4.0.0
Support options to configure the heap snapshot.
v19.1.0
v8.getHeapSnapshot(options?): stream.Readable
Attributes
options:
ObjectReturns:
stream.ReadableA Readable containing the V8 heap snapshot.
Generates a snapshot of the current V8 heap and returns a Readable Stream that may be used to read the JSON serialized representation. This JSON stream format is intended to be used with tools such as Chrome DevTools. The JSON schema is undocumented and specific to the V8 engine. Therefore, the schema may change from one version of V8 to the next.
Creating a heap snapshot requires memory about twice the size of the heap at the time the snapshot is created. This results in the risk of OOM killers terminating the process.
Generating a snapshot is a synchronous operation which blocks the event loop for a duration depending on the heap size.
// Print heap snapshot to the console import { getHeapSnapshot } from 'node:v8'; import process from 'node:process'; const stream = getHeapSnapshot(); stream.pipe(process.stdout);
// Print heap snapshot to the console const v8 = require('node:v8'); const stream = v8.getHeapSnapshot(); stream.pipe(process.stdout);