performanceObserver.observe(options)
版本历史
| 版本 | 变更 |
|---|---|
| v16.7.0 | 已更新以符合性能时间轴级别 2。缓冲选项已被添加回来。 |
| v16.0.0 | 已更新以符合用户计时级别 3。已删除缓冲选项。 |
| v8.5.0 | 新增于: v8.5.0 |
-
options<Object>-
type<string> 单个 <PerformanceEntry> 类型。如果已经指定了entryTypes,则不能给出。\
type<string> A single <PerformanceEntry> type. Must not be given ifentryTypesis already specified. -
entryTypes<string[]> 标识监视器感兴趣的 <PerformanceEntry> 实例类型的字符串数组。如果未提供,将抛出错误。\
entryTypes<string[]> An array of strings identifying the types of <PerformanceEntry> instances the observer is interested in. If not provided an error will be thrown. -
buffered<boolean> 如果为 true,则使用列表全局PerformanceEntry缓冲条目调用监视器回调。如果为 false,则只有在该时间点之后创建的PerformanceEntry被发送到监视器回调。默认值:false。\
buffered<boolean> If true, the observer callback is called with a list globalPerformanceEntrybuffered entries. If false, onlyPerformanceEntrys created after the time point are sent to the observer callback. Default:false.
-
为 <PerformanceObserver> 实例订阅由 options.entryTypes 或 options.type 标识的新 <PerformanceEntry> 实例的通知:
\Subscribes the <PerformanceObserver> instance to notifications of new
<PerformanceEntry> instances identified either by options.entryTypes
or options.type:
import { performance, PerformanceObserver } from '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}`);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}`);