v8.setFlagsFromString(flags)
flags
<string>
v8.setFlagsFromString()
方法可用于以编程方式设置 V8 命令行标志。此方法需谨慎使用。在 VM 启动后更改设置可能会导致不可预测的行为,包括崩溃和数据丢失;或者它可能什么都不做。
¥The v8.setFlagsFromString()
method can be used to programmatically set
V8 command-line flags. This method should be used with care. Changing settings
after the VM has started may result in unpredictable behavior, including
crashes and data loss; or it may simply do nothing.
可以通过运行 node --v8-options
来确定 Node.js 版本可用的 V8 选项。
¥The V8 options available for a version of Node.js may be determined by running
node --v8-options
.
用法:
¥Usage:
// Print GC events to stdout for one minute.
const v8 = require('node:v8');
v8.setFlagsFromString('--trace_gc');
setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);