Skip to content

Commit a3f0887

Browse files
kovanclaude
andcommitted
doc: fix perf_hooks documentation gaps and inaccuracies
- Fix introductory ESM example that references undefined `doSomeLongRunningProcess` and prematurely clears marks - Add missing PerformanceResourceTiming properties: initiatorType, nextHopProtocol, responseStart, deliveryType, responseStatus - Correct PerformanceMark/PerformanceMeasure version metadata from v18.2.0/v16.17.0 to v16.0.0 (introduced in PR #37136) - Fix histogram.exceeds description: it counts values exceeding the histogram's configured `highest` value, not a "1 hour" threshold - Generalize Histogram property descriptions (min, max, mean, stddev) to not reference "event loop delay" since Histogram is a generic class Fixes: #40558 Fixes: #40096 Fixes: #40723 Fixes: #55792 Fixes: #55793 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9ff27fd commit a3f0887

File tree

1 file changed

+97
-23
lines changed

1 file changed

+97
-23
lines changed

doc/api/perf_hooks.md

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ import { performance, PerformanceObserver } from 'node:perf_hooks';
2222

2323
const obs = new PerformanceObserver((items) => {
2424
console.log(items.getEntries()[0].duration);
25-
performance.clearMarks();
2625
});
2726
obs.observe({ type: 'measure' });
2827
performance.measure('Start to Now');
2928

3029
performance.mark('A');
31-
doSomeLongRunningProcess(() => {
32-
performance.measure('A to Now', 'A');
30+
await new Promise((r) => setTimeout(r, 5000));
31+
performance.measure('A to Now', 'A');
3332

34-
performance.mark('B');
35-
performance.measure('A to B', 'A', 'B');
36-
});
33+
performance.mark('B');
34+
performance.measure('A to B', 'A', 'B');
3735
```
3836

3937
```cjs
@@ -511,9 +509,7 @@ Performance Entry.
511509
## Class: `PerformanceMark`
512510

513511
<!-- YAML
514-
added:
515-
- v18.2.0
516-
- v16.17.0
512+
added: v16.0.0
517513
-->
518514

519515
* Extends: {PerformanceEntry}
@@ -538,9 +534,7 @@ Additional detail specified when creating with `Performance.mark()` method.
538534
## Class: `PerformanceMeasure`
539535

540536
<!-- YAML
541-
added:
542-
- v18.2.0
543-
- v16.17.0
537+
added: v16.7.0
544538
-->
545539

546540
* Extends: {PerformanceEntry}
@@ -906,6 +900,24 @@ resources.
906900

907901
The constructor of this class is not exposed to users directly.
908902

903+
### `performanceResourceTiming.initiatorType`
904+
905+
<!-- YAML
906+
added:
907+
- v18.6.0
908+
- v16.17.0
909+
changes:
910+
- version: v19.0.0
911+
pr-url: https://github.com/nodejs/node/pull/44483
912+
description: This property getter must be called with the
913+
`PerformanceResourceTiming` object as the receiver.
914+
-->
915+
916+
* Type: {string}
917+
918+
The string that represents the type of resource that initiated the
919+
performance entry, such as `'fetch'`.
920+
909921
### `performanceResourceTiming.workerStart`
910922

911923
<!-- YAML
@@ -1071,6 +1083,27 @@ changes:
10711083
The high resolution millisecond timestamp representing the time immediately
10721084
before Node.js starts the handshake process to secure the current connection.
10731085

1086+
### `performanceResourceTiming.nextHopProtocol`
1087+
1088+
<!-- YAML
1089+
added:
1090+
- v18.2.0
1091+
- v16.17.0
1092+
changes:
1093+
- version: v19.0.0
1094+
pr-url: https://github.com/nodejs/node/pull/44483
1095+
description: This property getter must be called with the
1096+
`PerformanceResourceTiming` object as the receiver.
1097+
-->
1098+
1099+
* Type: {string}
1100+
1101+
A string representing the network protocol used to fetch the resource, as
1102+
identified by the [ALPN Protocol ID][]. When a proxy is used, if a tunnel
1103+
connection is established, this returns the ALPN Protocol ID of the tunneled
1104+
protocol. Otherwise, this returns the ALPN Protocol ID of the first hop to
1105+
the proxy.
1106+
10741107
### `performanceResourceTiming.requestStart`
10751108

10761109
<!-- YAML
@@ -1087,7 +1120,25 @@ changes:
10871120
* Type: {number}
10881121

10891122
The high resolution millisecond timestamp representing the time immediately
1090-
before Node.js receives the first byte of the response from the server.
1123+
before Node.js starts requesting the resource from the server.
1124+
1125+
### `performanceResourceTiming.responseStart`
1126+
1127+
<!-- YAML
1128+
added:
1129+
- v18.2.0
1130+
- v16.17.0
1131+
changes:
1132+
- version: v19.0.0
1133+
pr-url: https://github.com/nodejs/node/pull/44483
1134+
description: This property getter must be called with the
1135+
`PerformanceResourceTiming` object as the receiver.
1136+
-->
1137+
1138+
* Type: {number}
1139+
1140+
The high resolution millisecond timestamp representing the time immediately
1141+
after Node.js receives the first byte of the response from the server.
10911142

10921143
### `performanceResourceTiming.responseEnd`
10931144

@@ -1164,6 +1215,28 @@ A number representing the size (in octets) received from the fetch
11641215
(HTTP or cache), of the message body, after removing any applied
11651216
content-codings.
11661217

1218+
### `performanceResourceTiming.deliveryType`
1219+
1220+
<!-- YAML
1221+
added: v22.2.0
1222+
-->
1223+
1224+
* Type: {string}
1225+
1226+
A string representing how the resource was delivered. For example,
1227+
resources delivered from the cache will return `'cache'`.
1228+
1229+
### `performanceResourceTiming.responseStatus`
1230+
1231+
<!-- YAML
1232+
added: v22.2.0
1233+
-->
1234+
1235+
* Type: {number}
1236+
1237+
A number representing the HTTP response status code returned when
1238+
fetching the resource.
1239+
11671240
### `performanceResourceTiming.toJSON()`
11681241

11691242
<!-- YAML
@@ -1864,8 +1937,8 @@ added: v11.10.0
18641937

18651938
* Type: {number}
18661939

1867-
The number of times the event loop delay exceeded the maximum 1 hour event
1868-
loop delay threshold.
1940+
The number of times the recorded value exceeded the `highest` recordable
1941+
value of the histogram.
18691942

18701943
### `histogram.exceedsBigInt`
18711944

@@ -1877,8 +1950,8 @@ added:
18771950

18781951
* Type: {bigint}
18791952

1880-
The number of times the event loop delay exceeded the maximum 1 hour event
1881-
loop delay threshold.
1953+
The number of times the recorded value exceeded the `highest` recordable
1954+
value of the histogram.
18821955

18831956
### `histogram.max`
18841957

@@ -1888,7 +1961,7 @@ added: v11.10.0
18881961

18891962
* Type: {number}
18901963

1891-
The maximum recorded event loop delay.
1964+
The maximum recorded value.
18921965

18931966
### `histogram.maxBigInt`
18941967

@@ -1900,7 +1973,7 @@ added:
19001973

19011974
* Type: {bigint}
19021975

1903-
The maximum recorded event loop delay.
1976+
The maximum recorded value.
19041977

19051978
### `histogram.mean`
19061979

@@ -1910,7 +1983,7 @@ added: v11.10.0
19101983

19111984
* Type: {number}
19121985

1913-
The mean of the recorded event loop delays.
1986+
The mean of the recorded values.
19141987

19151988
### `histogram.min`
19161989

@@ -1920,7 +1993,7 @@ added: v11.10.0
19201993

19211994
* Type: {number}
19221995

1923-
The minimum recorded event loop delay.
1996+
The minimum recorded value.
19241997

19251998
### `histogram.minBigInt`
19261999

@@ -1932,7 +2005,7 @@ added:
19322005

19332006
* Type: {bigint}
19342007

1935-
The minimum recorded event loop delay.
2008+
The minimum recorded value.
19362009

19372010
### `histogram.percentile(percentile)`
19382011

@@ -1996,7 +2069,7 @@ added: v11.10.0
19962069

19972070
* Type: {number}
19982071

1999-
The standard deviation of the recorded event loop delays.
2072+
The standard deviation of the recorded values.
20002073

20012074
## Class: `IntervalHistogram extends Histogram`
20022075

@@ -2348,6 +2421,7 @@ dns.lookup('localhost', () => {});
23482421
dns.promises.resolve('localhost');
23492422
```
23502423

2424+
[ALPN Protocol ID]: https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids
23512425
[Async Hooks]: async_hooks.md
23522426
[Fetch Response Body Info]: https://fetch.spec.whatwg.org/#response-body-info
23532427
[Fetch Timing Info]: https://fetch.spec.whatwg.org/#fetch-timing-info

0 commit comments

Comments
 (0)