v8.startHeapProfile([options])


  • options <Object>
    • sampleInterval <number> 平均采样间隔(以字节为单位)。 默认值: 524288(512 KiB)。
    • stackDepth <integer> 样本的最大堆栈深度。 默认值: 16
    • forceGC <boolean> 在进行性能分析前强制进行垃圾回收。 默认值: false
    • includeObjectsCollectedByMajorGC <boolean> 包含主要 GC 收集的对象。默认值: false
    • includeObjectsCollectedByMinorGC <boolean> 包含由次级 GC 收集的对象。默认值: false
  • 返回:SyncHeapProfileHandle

启动堆分析然后返回一个 SyncHeapProfileHandle 对象。 此 API 支持 using 语法。

🌐 Starting a heap profile then return a SyncHeapProfileHandle object. This API supports using syntax.

const v8 = require('node:v8');

const handle = v8.startHeapProfile();
const profile = handle.stop();
console.log(profile);import v8 from 'node:v8';

const handle = v8.startHeapProfile();
const profile = handle.stop();
console.log(profile);

使用自定义参数:

🌐 With custom parameters:

const v8 = require('node:v8');

const handle = v8.startHeapProfile({
  sampleInterval: 1024,
  stackDepth: 8,
  forceGC: true,
  includeObjectsCollectedByMajorGC: true,
});
const profile = handle.stop();
console.log(profile);import v8 from 'node:v8';

const handle = v8.startHeapProfile({
  sampleInterval: 1024,
  stackDepth: 8,
  forceGC: true,
  includeObjectsCollectedByMajorGC: true,
});
const profile = handle.stop();
console.log(profile);