On this page

C

PerformanceObserver

History
P

PerformanceObserver.supportedEntryTypes

History
Type:string[]

Get supported types.

new PerformanceObserver(callback): PerformanceObserver
Attributes

PerformanceObserver 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.

M

performanceObserver.disconnect

History
performanceObserver.disconnect(): void

Disconnects the PerformanceObserver instance from all notifications.

performanceObserver.observe(options): void
Attributes
options:Object
type:string
A single PerformanceEntry type. Must not be given if entryTypes 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 global PerformanceEntry 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}`);
M

performanceObserver.takeRecords

History
performanceObserver.takeRecords(): PerformanceEntry[]
Current list of entries stored in the performance observer, emptying it out.