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