v8.setHeapProfileNearHeapLimit(limit)


稳定性: 1 - 实验性

当 V8 接近堆限制时,会将活动采样堆配置文件写成 .heapprofile 文件,最多写入 limit 次。文件会写到 --diagnostic-dir 配置的目录(如果未设置该选项,则写到当前工作目录),使用 Heap.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.heapprofile 命名规则。

🌐 Writes the active sampling heap profile as a .heapprofile file when V8 is near the heap limit, up to limit times. Files are written to the directory configured by --diagnostic-dir (or to the current working directory if the option is unset), using the Heap.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.heapprofile naming convention.

在这个 API 可以捕获配置文件之前,必须先调用 v8.startHeapProfile()。如果当 V8 达到堆限制时没有正在进行的采样堆配置文件,回调将被卸载,V8 会继续其正常的内存不足处理行为。

这个 API 可以和 v8.setHeapSnapshotNearHeapLimit() 一起使用。 每个 API 都有自己的 limit。

🌐 This API can be used together with v8.setHeapSnapshotNearHeapLimit(). Each API maintains its own limit.

写入是尽力而为的。生成采样调用树可能会分配 V8 和本地内存,所以如果进程可用内存不足,分析可能无法完成。序列化的分析是由本地代码写入的,JavaScript 无法直接访问。

🌐 Writing is best-effort. Materializing the sampled call tree can allocate V8 and native memory, so the profile might not be completed if the process has insufficient memory available. The serialized profile is written by native code and is not exposed to JavaScript.

多次调用 setHeapProfileNearHeapLimit() 不会有任何效果。limit 必须是正整数。

🌐 Calling setHeapProfileNearHeapLimit() more than once is a no-op. limit must be a positive integer.