eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time. It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait). No other CPU idle time is taken into consideration.
interface
perf_hooks.Performance
interface Performance
- readonly nodeTiming: PerformanceNodeTiming
This property is an extension by Node.js. It is not available in Web browsers.
An instance of the
PerformanceNodeTiming
class that provides performance metrics for specific Node.js operational milestones. - readonly timeOrigin: number
The
timeOrigin
specifies the high resolution millisecond timestamp at which the currentnode
process began, measured in Unix time. - name?: string): void;
If
name
is not provided, removes allPerformanceMark
objects from the Performance Timeline. Ifname
is provided, removes only the named mark. - name?: string): void;
If
name
is not provided, removes allPerformanceMeasure
objects from the Performance Timeline. Ifname
is provided, removes only the named measure. - name?: string): void;
If
name
is not provided, removes allPerformanceResourceTiming
objects from the Resource Timeline. Ifname
is provided, removes only the named resource. Returns a list of
PerformanceEntry
objects in chronological order with respect toperformanceEntry.startTime
. If you are only interested in performance entries of certain types or that have certain names, seeperformance.getEntriesByType()
andperformance.getEntriesByName()
.- name: string,
Returns a list of
PerformanceEntry
objects in chronological order with respect toperformanceEntry.startTime
whoseperformanceEntry.name
is equal toname
, and optionally, whoseperformanceEntry.entryType
is equal totype
. Returns a list of
PerformanceEntry
objects in chronological order with respect toperformanceEntry.startTime
whoseperformanceEntry.entryType
is equal totype
.- mark(name: string,
Creates a new
PerformanceMark
entry in the Performance Timeline. APerformanceMark
is a subclass ofPerformanceEntry
whoseperformanceEntry.entryType
is always'mark'
, and whoseperformanceEntry.duration
is always0
. Performance marks are used to mark specific significant moments in the Performance Timeline.The created
PerformanceMark
entry is put in the global Performance Timeline and can be queried withperformance.getEntries
,performance.getEntriesByName
, andperformance.getEntriesByType
. When the observation is performed, the entries should be cleared from the global Performance Timeline manually withperformance.clearMarks
. - timingInfo: object,requestedUrl: string,initiatorType: string,global: object,cacheMode: '' | 'local',bodyInfo: object,responseStatus: number,deliveryType?: string
Creates a new
PerformanceResourceTiming
entry in the Resource Timeline. APerformanceResourceTiming
is a subclass ofPerformanceEntry
whoseperformanceEntry.entryType
is always'resource'
. Performance resources are used to mark moments in the Resource Timeline.@param timingInfo@param requestedUrlThe resource url
@param initiatorTypeThe initiator name, e.g: 'fetch'
@param cacheModeThe cache mode must be an empty string ('') or 'local'
@param bodyInfo@param responseStatusThe response's status code
@param deliveryTypeThe delivery type. Default: ''.
- name: string,startMark?: string,endMark?: string
Creates a new PerformanceMeasure entry in the Performance Timeline. A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure', and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist, then startMark is set to timeOrigin by default.
The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
@returnsThe PerformanceMeasure entry that was created
Returns the current high resolution millisecond timestamp, where 0 represents the start of the current
node
process.- maxSize: number): void;
Sets the global performance resource timing buffer size to the specified number of "resource" type performance entry objects.
By default the max buffer size is set to 250.
- fn: T,): T;
This property is an extension by Node.js. It is not available in Web browsers.
Wraps a function within a new function that measures the running time of the wrapped function. A
PerformanceObserver
must be subscribed to the'function'
event type in order for the timing details to be accessed.import { performance, PerformanceObserver, } from 'node:perf_hooks'; function someFunction() { console.log('hello world'); } const wrapped = performance.timerify(someFunction); const obs = new PerformanceObserver((list) => { console.log(list.getEntries()[0].duration); performance.clearMarks(); performance.clearMeasures(); obs.disconnect(); }); obs.observe({ entryTypes: ['function'] }); // A performance timeline entry will be created wrapped();
If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported once the finally handler is invoked.
An object which is JSON representation of the performance object. It is similar to
window.performance.toJSON
in browsers.