You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js启用node.perf追踪类别未生成perf_hooks性能API事件

Node.js node.perf 追踪类别无对应事件生成问题

根据Node.js追踪文档,配置node.perf追踪类别应该会触发perf_hooks::performance API相关的追踪事件,但实际测试后并未生成任何此类事件。

重现细节

执行脚本时使用以下命令:

node --trace-event-categories node,node.async_hooks,node.perf --trace-event-file-pattern 'trace_${pid}-${rotation}.json' foo.js

命令执行后生成了追踪文件,但文件中完全找不到"cat"字段为node.perf的事件。

测试代码

// foo.js
const trace_events = require("node:trace_events");
const { performance, createHistogram } = require("perf_hooks");

const tracing = trace_events.createTracing({ categories: ["node.async_hooks", "node.perf"] });
tracing.enable();

console.log(trace_events.getEnabledCategories());

const sleep = (ms) => new Promise((res) => setTimeout(res, ms));

async function slowMark() {
  performance.mark("started");
  await sleep(50);
  performance.mark("ended");
  performance.measure("work", "started", "ended"); // 预期此处生成追踪事件
}

async function slowWork() {
  console.log("slow start");
  await sleep(500);
  console.log("slow finish");
}

async function main() {
  await slowMark();
  await performance.timerify(slowWork)(); // 预期此处生成追踪事件
  tracing.disable();
}

main();

疑问

是否我对文档内容存在误解?

参考资料

  • Node.js 追踪文档
  • Node.js 性能API文档
  • 示例追踪文件

内容的提问来源于stack exchange,提问作者cdaringe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 17:23:20