@@ -53,6 +53,62 @@ added: v8.5.0
53
53
If ` name ` is not provided, removes all ` PerformanceMark ` objects from the
54
54
Performance Timeline. If ` name ` is provided, removes only the named mark.
55
55
56
+ ### ` performance.eventLoopUtilization([util1][,util2]) `
57
+ <!-- YAML
58
+ added: REPLACEME
59
+ -->
60
+
61
+ * ` util1 ` {Object} The result of a previous call to ` eventLoopUtilization() `
62
+ * ` util2 ` {Object} The result of a previous call to ` eventLoopUtilization() `
63
+ prior to ` util1 `
64
+ * Returns {Object}
65
+ * ` idle ` {number}
66
+ * ` active ` {number}
67
+ * ` utilization ` {number}
68
+
69
+ The ` eventLoopUtilization() ` method returns an object that contains the
70
+ cumulative duration of time the event loop has been both idle and active as a
71
+ high resolution milliseconds timer. The ` utilization ` value is the calculated
72
+ Event Loop Utilization (ELU). If bootstrapping has not yet finished, the
73
+ properties have the value of 0.
74
+
75
+ ` util1 ` and ` util2 ` are optional parameters.
76
+
77
+ If ` util1 ` is passed then the delta between the current call's ` active ` and
78
+ ` idle ` times are calculated and returned (similar to [ ` process.hrtime() ` ] [ ] ).
79
+ Likewise the adjusted ` utilization ` value is calculated.
80
+
81
+ If ` util1 ` and ` util2 ` are both passed then the calculation adjustments are
82
+ done between the two arguments. This is a convenience option because unlike
83
+ [ ` process.hrtime() ` ] [ ] additional work is done to calculate the ELU.
84
+
85
+ ELU is similar to CPU utilization except that it is calculated using high
86
+ precision wall-clock time. It represents the percentage of time the event loop
87
+ has spent outside the event loop's event provider (e.g. ` epoll_wait ` ). No other
88
+ CPU idle time is taken into consideration. The following is an example of how
89
+ a mostly idle process will have a high ELU.
90
+
91
+ <!-- eslint-skip -->
92
+ ``` js
93
+ ' use strict' ;
94
+ const { eventLoopUtilization } = require (' perf_hooks' ).performance ;
95
+ const { spawnSync } = require (' child_process' );
96
+
97
+ setImmediate (() => {
98
+ const elu = eventLoopUtilization ();
99
+ spawnSync (' sleep' , [' 5' ]);
100
+ console .log (eventLoopUtilization (elu).utilization );
101
+ });
102
+ ```
103
+
104
+ While the CPU is mostly idle while running this script the value of
105
+ ` utilization ` is 1. This is because the call to [ ` child_process.spawnSync() ` ] [ ]
106
+ blocks the event loop from proceeding.
107
+
108
+ Passing in a user-defined object instead of the result of a previous call to
109
+ ` eventLoopUtilization() ` will lead to undefined behavior. The return values
110
+ are not guaranteed to reflect any correct state of the event loop.
111
+
56
112
### ` performance.mark([name]) `
57
113
<!-- YAML
58
114
added: v8.5.0
@@ -163,62 +219,6 @@ obs.observe({ entryTypes: ['function'] });
163
219
wrapped ();
164
220
```
165
221
166
- ### ` performance.eventLoopUtilization([util1][,util2]) `
167
- <!-- YAML
168
- added: REPLACEME
169
- -->
170
-
171
- * ` util1 ` {Object} The result of a previous call to ` eventLoopUtilization() `
172
- * ` util2 ` {Object} The result of a previous call to ` eventLoopUtilization() `
173
- prior to ` util1 `
174
- * Returns {Object}
175
- * ` idle ` {number}
176
- * ` active ` {number}
177
- * ` utilization ` {number}
178
-
179
- The ` eventLoopUtilization() ` method returns an object that contains the
180
- cumulative duration of time the event loop has been both idle and active as a
181
- high resolution milliseconds timer. The ` utilization ` value is the calculated
182
- Event Loop Utilization (ELU). If bootstrapping has not yet finished, the
183
- properties have the value of 0.
184
-
185
- ` util1 ` and ` util2 ` are optional parameters.
186
-
187
- If ` util1 ` is passed then the delta between the current call's ` active ` and
188
- ` idle ` times are calculated and returned (similar to [ ` process.hrtime() ` ] [ ] ).
189
- Likewise the adjusted ` utilization ` value is calculated.
190
-
191
- If ` util1 ` and ` util2 ` are both passed then the calculation adjustments are
192
- done between the two arguments. This is a convenience option because unlike
193
- [ ` process.hrtime() ` ] [ ] additional work is done to calculate the ELU.
194
-
195
- ELU is similar to CPU utilization except that it is calculated using high
196
- precision wall-clock time. It represents the percentage of time the event loop
197
- has spent outside the event loop's event provider (e.g. ` epoll_wait ` ). No other
198
- CPU idle time is taken into consideration. The following is an example of how
199
- a mostly idle process will have a high ELU.
200
-
201
- <!-- eslint-skip -->
202
- ``` js
203
- ' use strict' ;
204
- const { eventLoopUtilization } = require (' perf_hooks' ).performance ;
205
- const { spawnSync } = require (' child_process' );
206
-
207
- setImmediate (() => {
208
- const elu = eventLoopUtilization ();
209
- spawnSync (' sleep' , [' 5' ]);
210
- console .log (eventLoopUtilization (elu).utilization );
211
- });
212
- ```
213
-
214
- While the CPU is mostly idle while running this script the value of
215
- ` utilization ` is 1. This is because the call to [ ` child_process.spawnSync() ` ] [ ]
216
- blocks the event loop from proceeding.
217
-
218
- Passing in a user-defined object instead of the result of a previous call to
219
- ` eventLoopUtilization() ` will lead to undefined behavior. The return values
220
- are not guaranteed to reflect any correct state of the event loop.
221
-
222
222
## Class: ` PerformanceEntry `
223
223
<!-- YAML
224
224
added: v8.5.0
@@ -234,41 +234,54 @@ added: v8.5.0
234
234
The total number of milliseconds elapsed for this entry. This value will not
235
235
be meaningful for all Performance Entry types.
236
236
237
- ### ` performanceEntry.name `
237
+ ### ` performanceEntry.entryType `
238
238
<!-- YAML
239
239
added: v8.5.0
240
240
-->
241
241
242
242
* {string}
243
243
244
- The name of the performance entry.
244
+ The type of the performance entry. It may be one of:
245
245
246
- ### ` performanceEntry.startTime `
246
+ * ` 'node' ` (Node.js only)
247
+ * ` 'mark' ` (available on the Web)
248
+ * ` 'measure' ` (available on the Web)
249
+ * ` 'gc' ` (Node.js only)
250
+ * ` 'function' ` (Node.js only)
251
+ * ` 'http2' ` (Node.js only)
252
+ * ` 'http' ` (Node.js only)
253
+
254
+ ### performanceEntry.flags
247
255
<!-- YAML
248
- added: v8.5.0
256
+ added:
257
+ - v13.9.0
258
+ - v12.17.0
249
259
-->
250
260
251
261
* {number}
252
262
253
- The high resolution millisecond timestamp marking the starting time of the
254
- Performance Entry.
263
+ _ This property is an extension by Node.js. It is not available in Web browsers._
255
264
256
- ### ` performanceEntry.entryType `
265
+ When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.flags `
266
+ property contains additional information about garbage collection operation.
267
+ The value may be one of:
268
+
269
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO `
270
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED `
271
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED `
272
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING `
273
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE `
274
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY `
275
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE `
276
+
277
+ ### ` performanceEntry.name `
257
278
<!-- YAML
258
279
added: v8.5.0
259
280
-->
260
281
261
282
* {string}
262
283
263
- The type of the performance entry. It may be one of:
264
-
265
- * ` 'node' ` (Node.js only)
266
- * ` 'mark' ` (available on the Web)
267
- * ` 'measure' ` (available on the Web)
268
- * ` 'gc' ` (Node.js only)
269
- * ` 'function' ` (Node.js only)
270
- * ` 'http2' ` (Node.js only)
271
- * ` 'http' ` (Node.js only)
284
+ The name of the performance entry.
272
285
273
286
### ` performanceEntry.kind `
274
287
<!-- YAML
@@ -288,26 +301,15 @@ The value may be one of:
288
301
* ` perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL `
289
302
* ` perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB `
290
303
291
- ### performanceEntry.flags
304
+ ### ` performanceEntry.startTime `
292
305
<!-- YAML
293
- added: v13.9 .0
306
+ added: v8.5 .0
294
307
-->
295
308
296
309
* {number}
297
310
298
- _ This property is an extension by Node.js. It is not available in Web browsers._
299
-
300
- When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.flags `
301
- property contains additional information about garbage collection operation.
302
- The value may be one of:
303
-
304
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO `
305
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED `
306
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED `
307
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING `
308
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE `
309
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY `
310
- * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE `
311
+ The high resolution millisecond timestamp marking the starting time of the
312
+ Performance Entry.
311
313
312
314
## Class: ` PerformanceNodeTiming extends PerformanceEntry `
313
315
<!-- YAML
@@ -340,6 +342,19 @@ added: v8.5.0
340
342
The high resolution millisecond timestamp at which the Node.js environment was
341
343
initialized.
342
344
345
+ ### ` performanceNodeTiming.idleTime `
346
+ <!-- YAML
347
+ added: REPLACEME
348
+ -->
349
+
350
+ * {number}
351
+
352
+ The high resolution millisecond timestamp of the amount of time the event loop
353
+ has been idle within the event loop's event provider (e.g. ` epoll_wait ` ). This
354
+ does not take CPU usage into consideration. If the event loop has not yet
355
+ started (e.g., in the first tick of the main script), the property has the
356
+ value of 0.
357
+
343
358
### ` performanceNodeTiming.loopExit `
344
359
<!-- YAML
345
360
added: v8.5.0
@@ -382,19 +397,6 @@ added: v8.5.0
382
397
The high resolution millisecond timestamp at which the V8 platform was
383
398
initialized.
384
399
385
- ### ` performanceNodeTiming.idleTime `
386
- <!-- YAML
387
- added: REPLACEME
388
- -->
389
-
390
- * {number}
391
-
392
- The high resolution millisecond timestamp of the amount of time the event loop
393
- has been idle within the event loop's event provider (e.g. ` epoll_wait ` ). This
394
- does not take CPU usage into consideration. If the event loop has not yet
395
- started (e.g., in the first tick of the main script), the property has the
396
- value of 0.
397
-
398
400
## Class: ` perf_hooks.PerformanceObserver `
399
401
400
402
### ` new PerformanceObserver(callback) `
0 commit comments