当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js perf_hooks.PerformanceObserver.observe(options)用法及代码示例


performanceObserver.observe(options)

历史
版本变化
v16.7.0

更新以符合性能时间线级别 2。已添加回缓冲选项。

v16.0.0

更新以符合用户时序级别 3。缓冲选项已被删除。

v8.5.0

添加于:v8.5.0


参数
  • options <Object>
    • type <string> 单个 <PerformanceEntry> 类型。如果已指定entryTypes,则不得提供。
    • entryTypes <string[]> 标识观察者感兴趣的 <PerformanceEntry> 实例类型的字符串数组。如果未提供,将引发错误。
    • buffered <boolean> 如果为真,则使用列表全局 PerformanceEntry 缓冲条目调用观察者回调。如果为 false,则仅将在时间点之后创建的 PerformanceEntry 发送到观察者回调。 默认: false

<PerformanceObserver> 实例订阅由 options.entryTypesoptions.type 标识的新 <PerformanceEntry> 实例的通知:

const {
  performance,
  PerformanceObserver
} = require('node:perf_hooks');

const obs = new PerformanceObserver((list, observer) => {
  // Called once asynchronously. `list` contains three items.
});
obs.observe({ type: 'mark' });

for (let n = 0; n < 3; n++)
  performance.mark(`test${n}`);

相关用法


注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 perf_hooks.PerformanceObserver.observe(options)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。