syncHeapProfileHandle.getSamples(): Object[]
Object[]numberobjectSize * objectCount.numbernumbernumbernumberbooleannumberReturns the currently retained allocation samples without stopping profiling or
building the full profile call tree and resolving its script metadata. The sample
fields match those in the JSON returned by stop(). Use ordinal to identify
samples across calls; array order is unspecified.
Live allocation samples are available with the default profiling options.
To also retain samples after their objects are collected, enable
includeObjectsCollectedByMajorGC or includeObjectsCollectedByMinorGC when
starting the profile. These samples have isLive set to false. The forceGC
option also applies to getSamples().
Throws ERR_HEAP_PROFILE_NOT_STARTED if this handle has been stopped or disposed.
syncHeapProfileHandle.setSampleInterval(sampleInterval): void
integer1 and Number.MAX_SAFE_INTEGER, inclusive.Updates the sampling interval for future sample scheduling without restarting
profiling or discarding existing samples. A larger interval reduces sampling
frequency. Each sample retains the sampleInterval used when it was selected.
Throws ERR_HEAP_PROFILE_NOT_STARTED if this handle has been stopped or disposed.
const v8 = require('node:v8'); const handle = v8.startHeapProfile({ sampleInterval: 1024 }); // Run the workload to profile. const samples = handle.getSamples(); handle.setSampleInterval(4096); // Continue profiling with less frequent sampling. const profile = handle.stop();
syncHeapProfileHandle.stop(): string
stringStopping collecting the profile and return the profile data.
The returned string is JSON in the Chrome DevTools sampling heap profile
format, with a head call-tree and a samples array. On top of the DevTools
fields, the following are added:
- Each node reports
selfCount, the number of sampled objects allocated by the node (selfSizeis the existing total in bytes). - Each sample reports
objectSize,objectCount,isLive, andsampleInterval.sampleIntervalrecords the sampling interval in bytes used when the sample was selected, even if the interval was subsequently changed.
The DevTools size field stays objectSize * objectCount for compatibility.
syncHeapProfileHandle[Symbol.dispose](): void
Stopping collecting the profile and the profile will be discarded.