On this page

    M

    perf_hooks.monitorEventLoopDelay

    History
    perf_hooks.monitorEventLoopDelay(options?): ELDHistogram
    Attributes
    options:Object
    samplePerIteration?:boolean
    When true, samples are taken once per event loop iteration. Default: false.
    resolution?:number
    The sampling rate in milliseconds for interval-based sampling. Must be greater than zero. This option is ignored when samplePerIteration is true. Default: 10.
    Returns:ELDHistogram

    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));
    const { monitorEventLoopDelay } = require('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));