On this page

C

SyncHeapProfileHandle

History
Stability: 1Experimental
M

syncHeapProfileHandle.getSamples

History
syncHeapProfileHandle.getSamples(): Object[]
Returns:Object[]
size:number
Estimated total allocation size in bytes, equal to objectSize * objectCount.
objectSize:number
Size of the sampled object in bytes.
objectCount:number
Estimated number of objects represented by the sample.
nodeId:number
Identifier of the allocation's node in the profile call tree.
ordinal:number
Unique, time-ordered identifier of the sample.
isLive:boolean
Whether the sampled object is still live.
sampleInterval:number
Sampling interval in bytes used when the sample was selected.

Returns 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.

M

syncHeapProfileHandle.setSampleInterval

History
syncHeapProfileHandle.setSampleInterval(sampleInterval): void
Attributes
sampleInterval:integer
Average sampling interval in bytes. Must be between 1 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();
M

syncHeapProfileHandle.stop

History
syncHeapProfileHandle.stop(): string
Returns:string

Stopping 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 (selfSize is the existing total in bytes).
  • Each sample reports objectSize, objectCount, isLive, and sampleInterval. sampleInterval records 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.

M

syncHeapProfileHandle[Symbol.dispose]

History
syncHeapProfileHandle[Symbol.dispose](): void

Stopping collecting the profile and the profile will be discarded.