performanceObserver.observe(options)
options
<Object>type
<string> 单个 <PerformanceEntry> 类型。 如果已经指定了entryTypes
,则不能给出。entryTypes
<string[]> 标识观察者感兴趣的 <PerformanceEntry> 实例类型的字符串数组。 如果未提供,将抛出错误。buffered
<boolean> 如果为 true,则使用列表全局PerformanceEntry
缓冲条目调用观察者回调。 如果为false,则只有在时间点之后创建的PerformanceEntry
被发送到观察者回调。 默认值:false
。
为 <PerformanceObserver> 实例订阅由 options.entryTypes
或 options.type
标识的新 <PerformanceEntry> 实例的通知:
const {
performance,
PerformanceObserver,
} = require('node:perf_hooks');
const obs = new PerformanceObserver((list, observer) => {
// 异步调用一次。`list` 包含三个条目。
});
obs.observe({ type: 'mark' });
for (let n = 0; n < 3; n++)
performance.mark(`test${n}`);
options
<Object>type
<string> A single <PerformanceEntry> type. Must not be given ifentryTypes
is already specified.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> If true, the observer callback is called with a list globalPerformanceEntry
buffered entries. If false, onlyPerformanceEntry
s created after the time point are sent to the observer callback. Default:false
.
Subscribes the <PerformanceObserver> instance to notifications of new
<PerformanceEntry> instances identified either by options.entryTypes
or options.type
:
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}`);