Starting a heap profile then return a SyncHeapProfileHandle object. This API supports using syntax.
import v8 from 'node:v8';
const handle = v8.startHeapProfile();
const profile = handle.stop();
console.log(profile);
With custom parameters:
import v8 from 'node:v8';
const handle = v8.startHeapProfile({
sampleInterval: 1024,
stackDepth: 8,
forceGC: true,
includeObjectsCollectedByMajorGC: true,
});
const profile = handle.stop();
console.log(profile);