performanceObserver.observe(options)
-
options
<Object>-
type
<string> 单个 <PerformanceEntry> 类型。如果已经指定了entryTypes
,则不能给出。¥
type
<string> A single <PerformanceEntry> type. Must not be given ifentryTypes
is 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 globalPerformanceEntry
buffered entries. If false, onlyPerformanceEntry
s 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
:
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}`);