@@ -23,7 +23,7 @@ const obs = new PerformanceObserver((items) => {
23
23
console .log (items .getEntries ()[0 ].duration );
24
24
performance .clearMarks ();
25
25
});
26
- obs .observe ({ entryTypes : [ ' measure' ] });
26
+ obs .observe ({ type : ' measure' });
27
27
performance .measure (' Start to Now' );
28
28
29
29
performance .mark (' A' );
@@ -115,23 +115,34 @@ Passing in a user-defined object instead of the result of a previous call to
115
115
` eventLoopUtilization() ` will lead to undefined behavior. The return values
116
116
are not guaranteed to reflect any correct state of the event loop.
117
117
118
- ### ` performance.mark([name]) `
118
+ ### ` performance.mark([name[, options] ]) `
119
119
<!-- YAML
120
120
added: v8.5.0
121
+ changes:
122
+ - version: REPLACEME
123
+ pr-url: https://github.com/nodejs/node/pull/37136
124
+ description: Updated to conform to the User Timing Level 3 specification.
121
125
-->
122
126
123
127
* ` name ` {string}
128
+ * ` options ` {Object}
129
+ * ` detail ` {any} Additional optional detail to include with the mark.
130
+ * ` startTime ` {number} An optional timestamp to be used as the mark time.
131
+ ** Defaults** : ` performance.now() ` .
124
132
125
133
Creates a new ` PerformanceMark ` entry in the Performance Timeline. A
126
134
` PerformanceMark ` is a subclass of ` PerformanceEntry ` whose
127
135
` performanceEntry.entryType ` is always ` 'mark' ` , and whose
128
136
` performanceEntry.duration ` is always ` 0 ` . Performance marks are used
129
137
to mark specific significant moments in the Performance Timeline.
130
138
131
- ### ` performance.measure(name[, startMark [, endMark]]) `
139
+ ### ` performance.measure(name[, startMarkOrOptions [, endMark]]) `
132
140
<!-- YAML
133
141
added: v8.5.0
134
142
changes:
143
+ - version: REPLACEME
144
+ pr-url: https://github.com/nodejs/node/pull/37136
145
+ description: Updated to conform to the User Timing Level 3 specification.
135
146
- version:
136
147
- v13.13.0
137
148
- v12.16.3
@@ -140,8 +151,15 @@ changes:
140
151
-->
141
152
142
153
* ` name ` {string}
143
- * ` startMark ` {string} Optional.
144
- * ` endMark ` {string} Optional.
154
+ * ` startMarkOrOptions ` {string|Object} Optional.
155
+ * ` detail ` {any} Additional optional detail to include with the measure.
156
+ * ` duration ` {number} Duration between start and end times.
157
+ * ` end ` {number|string} Timestamp to be used as the end time, or a string
158
+ identifying a previously recorded mark.
159
+ * ` start ` {number|string} Timestamp to be used as the start time, or a string
160
+ identifying a previously recorded mark.
161
+ * ` endMark ` {string} Optional. Must be omitted if ` startMarkOrOptions ` is an
162
+ {Object}.
145
163
146
164
Creates a new ` PerformanceMeasure ` entry in the Performance Timeline. A
147
165
` PerformanceMeasure ` is a subclass of ` PerformanceEntry ` whose
@@ -152,7 +170,7 @@ Creates a new `PerformanceMeasure` entry in the Performance Timeline. A
152
170
The ` startMark ` argument may identify any * existing* ` PerformanceMark ` in the
153
171
Performance Timeline, or * may* identify any of the timestamp properties
154
172
provided by the ` PerformanceNodeTiming ` class. If the named ` startMark ` does
155
- not exist, then ` startMark ` is set to [ ` timeOrigin ` ] [ ] by default .
173
+ not exist, an error is thrown .
156
174
157
175
The optional ` endMark ` argument must identify any * existing* ` PerformanceMark `
158
176
in the Performance Timeline or any of the timestamp properties provided by the
@@ -195,6 +213,11 @@ which the current `node` process began, measured in Unix time.
195
213
### ` performance.timerify(fn) `
196
214
<!-- YAML
197
215
added: v8.5.0
216
+ changes:
217
+ - version: REPLACEME
218
+ pr-url: https://github.com/nodejs/node/pull/37136
219
+ description: Re-implemented to use pure-JavaScript and the ability
220
+ to time async functions.
198
221
-->
199
222
200
223
* ` fn ` {Function}
@@ -227,11 +250,24 @@ obs.observe({ entryTypes: ['function'] });
227
250
wrapped ();
228
251
```
229
252
253
+ If the wrapped function returns a promise, a finally handler will be attached
254
+ to the promise and the duration will be reported once the finally handler is
255
+ invoked.
256
+
230
257
## Class: ` PerformanceEntry `
231
258
<!-- YAML
232
259
added: v8.5.0
233
260
-->
234
261
262
+ ### ` performanceEntry.details `
263
+ <!-- YAML
264
+ added: REPLACEME
265
+ -->
266
+
267
+ * {any}
268
+
269
+ Additional detail specific to the ` entryType ` .
270
+
235
271
### ` performanceEntry.duration `
236
272
<!-- YAML
237
273
added: v8.5.0
@@ -264,6 +300,11 @@ The type of the performance entry. It may be one of:
264
300
added:
265
301
- v13.9.0
266
302
- v12.17.0
303
+ changes:
304
+ - version: REPLACEME
305
+ pr-url: https://github.com/nodejs/node/pull/37136
306
+ description: Runtime deprecated. Now moved to the detail property
307
+ when entryType is 'gc'.
267
308
-->
268
309
269
310
* {number}
@@ -294,6 +335,11 @@ The name of the performance entry.
294
335
### ` performanceEntry.kind `
295
336
<!-- YAML
296
337
added: v8.5.0
338
+ changes:
339
+ - version: REPLACEME
340
+ pr-url: https://github.com/nodejs/node/pull/37136
341
+ description: Runtime deprecated. Now moved to the detail property
342
+ when entryType is 'gc'.
297
343
-->
298
344
299
345
* {number}
@@ -319,6 +365,72 @@ added: v8.5.0
319
365
The high resolution millisecond timestamp marking the starting time of the
320
366
Performance Entry.
321
367
368
+ ### Garbage Collection ('gc') Details
369
+
370
+ When ` performanceEntry.type ` is equal to ` 'gc' ` , the ` performanceEntry.details `
371
+ property will be an {Object} with two properties:
372
+
373
+ * ` kind ` {number} One of:
374
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR `
375
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR `
376
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL `
377
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB `
378
+ * ` flags ` {number} One of:
379
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO `
380
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED `
381
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED `
382
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING `
383
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE `
384
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY `
385
+ * ` perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE `
386
+
387
+ ### HTTP/2 ('http2') Details
388
+
389
+ When ` performanceEntry.type ` is equal to ` 'http2' ` , the
390
+ ` performanceEntry.details ` property will be an {Object} containing
391
+ additional performance information.
392
+
393
+ If ` performanceEntry.name ` is equal to ` Http2Stream ` , the ` details `
394
+ will contain the following properties:
395
+
396
+ * ` bytesRead ` {number} The number of ` DATA ` frame bytes received for this
397
+ ` Http2Stream ` .
398
+ * ` bytesWritten ` {number} The number of ` DATA ` frame bytes sent for this
399
+ ` Http2Stream ` .
400
+ * ` id ` {number} The identifier of the associated ` Http2Stream `
401
+ * ` timeToFirstByte ` {number} The number of milliseconds elapsed between the
402
+ ` PerformanceEntry ` ` startTime ` and the reception of the first ` DATA ` frame.
403
+ * ` timeToFirstByteSent ` {number} The number of milliseconds elapsed between
404
+ the ` PerformanceEntry ` ` startTime ` and sending of the first ` DATA ` frame.
405
+ * ` timeToFirstHeader ` {number} The number of milliseconds elapsed between the
406
+ ` PerformanceEntry ` ` startTime ` and the reception of the first header.
407
+
408
+ If ` performanceEntry.name ` is equal to ` Http2Session ` , the ` details ` will
409
+ contain the following properties:
410
+
411
+ * ` bytesRead ` {number} The number of bytes received for this ` Http2Session ` .
412
+ * ` bytesWritten ` {number} The number of bytes sent for this ` Http2Session ` .
413
+ * ` framesReceived ` {number} The number of HTTP/2 frames received by the
414
+ ` Http2Session ` .
415
+ * ` framesSent ` {number} The number of HTTP/2 frames sent by the ` Http2Session ` .
416
+ * ` maxConcurrentStreams ` {number} The maximum number of streams concurrently
417
+ open during the lifetime of the ` Http2Session ` .
418
+ * ` pingRTT ` {number} The number of milliseconds elapsed since the transmission
419
+ of a ` PING ` frame and the reception of its acknowledgment. Only present if
420
+ a ` PING ` frame has been sent on the ` Http2Session ` .
421
+ * ` streamAverageDuration ` {number} The average duration (in milliseconds) for
422
+ all ` Http2Stream ` instances.
423
+ * ` streamCount ` {number} The number of ` Http2Stream ` instances processed by
424
+ the ` Http2Session ` .
425
+ * ` type ` {string} Either ` 'server' ` or ` 'client' ` to identify the type of
426
+ ` Http2Session ` .
427
+
428
+ ### Timerify ('function') Details
429
+
430
+ When ` performanceEntry.type ` is equal to ` 'function' ` , the
431
+ ` performanceEntry.details ` property will be an {Array} listing
432
+ the input arguments to the timed function.
433
+
322
434
## Class: ` PerformanceNodeTiming `
323
435
<!-- YAML
324
436
added: v8.5.0
@@ -457,22 +569,23 @@ Disconnects the `PerformanceObserver` instance from all notifications.
457
569
### ` performanceObserver.observe(options) `
458
570
<!-- YAML
459
571
added: v8.5.0
572
+ changes:
573
+ - version: REPLACEME
574
+ pr-url: https://github.com/nodejs/node/pull/37136
575
+ description: Updated to conform to User Timing Level 3. The
576
+ buffered option has been removed.
460
577
-->
461
578
462
579
* ` options ` {Object}
580
+ * ` type ` {string} A single {PerformanceEntry} type. Must not be given
581
+ if ` entryTypes ` is already specified.
463
582
* ` entryTypes ` {string[ ] } An array of strings identifying the types of
464
- ` PerformanceEntry ` instances the observer is interested in. If not
583
+ { PerformanceEntry} instances the observer is interested in. If not
465
584
provided an error will be thrown.
466
- * ` buffered ` {boolean} If true, the notification callback will be
467
- called using ` setImmediate() ` and multiple ` PerformanceEntry ` instance
468
- notifications will be buffered internally. If ` false ` , notifications will
469
- be immediate and synchronous. ** Default:** ` false ` .
470
-
471
- Subscribes the ` PerformanceObserver ` instance to notifications of new
472
- ` PerformanceEntry ` instances identified by ` options.entryTypes ` .
473
585
474
- When ` options.buffered ` is ` false ` , the ` callback ` will be invoked once for
475
- every ` PerformanceEntry ` instance:
586
+ Subscribes the {PerformanceObserver} instance to notifications of new
587
+ {PerformanceEntry} instances identified either by ` options.entryTypes `
588
+ or ` options.type ` :
476
589
477
590
``` js
478
591
const {
@@ -483,22 +596,7 @@ const {
483
596
const obs = new PerformanceObserver ((list , observer ) => {
484
597
// Called three times synchronously. `list` contains one item.
485
598
});
486
- obs .observe ({ entryTypes: [' mark' ] });
487
-
488
- for (let n = 0 ; n < 3 ; n++ )
489
- performance .mark (` test${ n} ` );
490
- ```
491
-
492
- ``` js
493
- const {
494
- performance ,
495
- PerformanceObserver
496
- } = require (' perf_hooks' );
497
-
498
- const obs = new PerformanceObserver ((list , observer ) => {
499
- // Called once. `list` contains three items.
500
- });
501
- obs .observe ({ entryTypes: [' mark' ], buffered: true });
599
+ obs .observe ({ type: ' mark' });
502
600
503
601
for (let n = 0 ; n < 3 ; n++ )
504
602
performance .mark (` test${ n} ` );
@@ -549,7 +647,7 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
549
647
*/
550
648
observer .disconnect ();
551
649
});
552
- obs .observe ({ entryTypes : [ ' mark' ], buffered : true });
650
+ obs .observe ({ type : ' mark' });
553
651
554
652
performance .mark (' test' );
555
653
performance .mark (' meow' );
@@ -603,7 +701,7 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
603
701
console .log (perfObserverList .getEntriesByName (' test' , ' measure' )); // []
604
702
observer .disconnect ();
605
703
});
606
- obs .observe ({ entryTypes: [' mark' , ' measure' ], buffered : true });
704
+ obs .observe ({ entryTypes: [' mark' , ' measure' ] });
607
705
608
706
performance .mark (' test' );
609
707
performance .mark (' meow' );
@@ -647,7 +745,7 @@ const obs = new PerformanceObserver((perfObserverList, observer) => {
647
745
*/
648
746
observer .disconnect ();
649
747
});
650
- obs .observe ({ entryTypes : [ ' mark' ], buffered : true });
748
+ obs .observe ({ type : ' mark' });
651
749
652
750
performance .mark (' test' );
653
751
performance .mark (' meow' );
0 commit comments