string[]Get supported types.
new PerformanceObserver(callback): PerformanceObserver
FunctionPerformanceObserverPerformanceObserver objects provide notifications when new
PerformanceEntry instances have been added to the Performance Timeline.
import { performance, PerformanceObserver } from 'node:perf_hooks'; const obs = new PerformanceObserver((list, observer) => { console.log(list.getEntries()); performance.clearMarks(); performance.clearMeasures(); observer.disconnect(); }); obs.observe({ entryTypes: ['mark'], buffered: true }); performance.mark('test');
const { performance, PerformanceObserver, } = require('node:perf_hooks'); const obs = new PerformanceObserver((list, observer) => { console.log(list.getEntries()); performance.clearMarks(); performance.clearMeasures(); observer.disconnect(); }); obs.observe({ entryTypes: ['mark'], buffered: true }); performance.mark('test');
Because PerformanceObserver instances introduce their own additional
performance overhead, instances should not be left subscribed to notifications
indefinitely. Users should disconnect observers as soon as they are no
longer needed.
The callback is invoked when a PerformanceObserver is
notified about new PerformanceEntry instances. The callback receives a
PerformanceObserverEntryList instance and a reference to the
PerformanceObserver.
performanceObserver.disconnect(): void
Disconnects the PerformanceObserver instance from all notifications.
performanceObserver.observe(options): void
ObjectstringPerformanceEntry type. Must not be given
if entryTypes is already specified.string[]PerformanceEntry instances the observer is interested in. If not
provided an error will be thrown.booleanPerformanceEntry buffered entries. If false, only
PerformanceEntrys 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:
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}`);
performanceObserver.takeRecords(): PerformanceEntry[]
PerformanceEntry[]