options
{Object}entryTypes
{string[]} An array of strings identifying the types ofPerformanceEntry
instances the observer is interested in. If not provided an error will be thrown.buffered
{boolean} If true, the notification callback will be called usingsetImmediate()
and multiplePerformanceEntry
instance notifications will be buffered internally. Iffalse
, notifications will be immediate and synchronous. Default:false
.
Subscribes the PerformanceObserver
instance to notifications of new
PerformanceEntry
instances identified by options.entryTypes
.
When options.buffered
is false
, the callback
will be invoked once for
every PerformanceEntry
instance:
const {
performance,
PerformanceObserver
} = require('perf_hooks');
const obs = new PerformanceObserver((list, observer) => {
// Called three times synchronously. `list` contains one item.
});
obs.observe({ entryTypes: ['mark'] });
for (let n = 0; n < 3; n++)
performance.mark(`test${n}`);
const {
performance,
PerformanceObserver
} = require('perf_hooks');
const obs = new PerformanceObserver((list, observer) => {
// Called once. `list` contains three items.
});
obs.observe({ entryTypes: ['mark'], buffered: true });
for (let n = 0; n < 3; n++)
performance.mark(`test${n}`);