function
perf_hooks.monitorEventLoopDelay
This property is an extension by Node.js. It is not available in Web browsers.
Creates a histogram object that samples and reports the event loop delay over time. The delays will be reported in nanoseconds.
By default, the histogram is updated by a timer using the configured resolution. When samplePerIteration is true, samples are taken once per event loop iteration using uv_prepare_t and uv_check_t hooks. In that mode, the histogram does not keep the loop alive or force additional iterations when the application is idle. The two sampling modes produce significantly different results and should not be compared directly.
import { monitorEventLoopDelay } from 'node:perf_hooks';
const h = monitorEventLoopDelay({ resolution: 20 });
h.enable();
// Do something.
h.disable();
console.log(h.min);
console.log(h.max);
console.log(h.mean);
console.log(h.stddev);
console.log(h.percentiles);
console.log(h.percentile(50));
console.log(h.percentile(99));Referenced types
interface EventLoopMonitorOptions
- resolution?: number
The sampling rate in milliseconds for interval-based sampling. Must be greater than zero. This option is ignored when
samplePerIterationistrue. Default:10. - samplePerIteration?: boolean
When
true, samples are taken once per event loop iteration. Default:false.
interface ELDHistogram
A Histogram that records event loop delay, returned by perf_hooks.monitorEventLoopDelay().
- readonly exceeds: number
The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.
- readonly exceedsBigInt: bigint
The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.
- readonly percentiles: Map<number, number>
Returns a
Mapobject detailing the accumulated percentile distribution. - readonly percentilesBigInt: Map<bigint, bigint>
Returns a
Mapobject detailing the accumulated percentile distribution. Disables event loop delay sampling when the histogram is disposed.
const { monitorEventLoopDelay } = require('node:perf_hooks'); { using hist = monitorEventLoopDelay({ resolution: 20 }); hist.enable(); // The histogram will be disabled when the block is exited. }Disables event loop delay sampling. Returns
trueif sampling was stopped,falseif it was already stopped.Enables event loop delay sampling. Returns
trueif sampling was started,falseif it was already started.- @param percentile
A percentile value in the range (0, 100].
- @param percentile
A percentile value in the range (0, 100].
Resets the collected histogram data.