Skip to content

Commit b8c8889

Browse files
joyeecheungtargos
authored andcommitted
doc: clarify about the Node.js-only extensions in perf_hooks
- Add clarifications for Node.js-only extensions - Explain the Web Performance APIs implemented in Node.js and clarify that perf_hooks also include other non-Web APIs. - Prefix exposed interfaces with `perf_hooks.` to distinguish them from internal classes. PR-URL: #33199 Refs: #28635 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d1efdb2 commit b8c8889

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

doc/api/perf_hooks.md

+48-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# Performance Timing API
1+
# Performance Measurement APIs
22

33
<!--introduced_in=v8.5.0-->
44

55
> Stability: 2 - Stable
66
7-
The Performance Timing API provides an implementation of the
8-
[W3C Performance Timeline][] specification. The purpose of the API
9-
is to support collection of high resolution performance metrics.
10-
This is the same Performance API as implemented in modern Web browsers.
7+
This module provides an implementation of a subset of the W3C
8+
[Web Performance APIs][] as well as additional APIs for
9+
Node.js-specific performance measurements.
10+
11+
Node.js supports the following [Web Performance APIs][]:
12+
13+
* [High Resolution Time][]
14+
* [Performance Timeline][]
15+
* [User Timing][]
1116

1217
```js
1318
const { PerformanceObserver, performance } = require('perf_hooks');
@@ -28,11 +33,14 @@ doSomeLongRunningProcess(() => {
2833
});
2934
```
3035

31-
## Class: `Performance`
36+
## `perf_hooks.performance`
3237
<!-- YAML
3338
added: v8.5.0
3439
-->
3540

41+
An object that can be used to collect performance metrics from the current
42+
Node.js instance. It is similar to [`window.performance`][] in browsers.
43+
3644
### `performance.clearMarks([name])`
3745
<!-- YAML
3846
added: v8.5.0
@@ -93,6 +101,8 @@ added: v8.5.0
93101

94102
* {PerformanceNodeTiming}
95103

104+
_This property is an extension by Node.js. It is not available in Web browsers._
105+
96106
An instance of the `PerformanceNodeTiming` class that provides performance
97107
metrics for specific Node.js operational milestones.
98108

@@ -123,6 +133,8 @@ added: v8.5.0
123133

124134
* `fn` {Function}
125135

136+
_This property is an extension by Node.js. It is not available in Web browsers._
137+
126138
Wraps a function within a new function that measures the running time of the
127139
wrapped function. A `PerformanceObserver` must be subscribed to the `'function'`
128140
event type in order for the timing details to be accessed.
@@ -190,8 +202,15 @@ added: v8.5.0
190202

191203
* {string}
192204

193-
The type of the performance entry. Currently it may be one of: `'node'`,
194-
`'mark'`, `'measure'`, `'gc'`, `'function'`, `'http2'` or `'http'`.
205+
The type of the performance entry. It may be one of:
206+
207+
* `'node'` (Node.js only)
208+
* `'mark'` (available on the Web)
209+
* `'measure'` (available on the Web)
210+
* `'gc'` (Node.js only)
211+
* `'function'` (Node.js only)
212+
* `'http2'` (Node.js only)
213+
* `'http'` (Node.js only)
195214

196215
### `performanceEntry.kind`
197216
<!-- YAML
@@ -200,6 +219,8 @@ added: v8.5.0
200219

201220
* {number}
202221

222+
_This property is an extension by Node.js. It is not available in Web browsers._
223+
203224
When `performanceEntry.entryType` is equal to `'gc'`, the `performance.kind`
204225
property identifies the type of garbage collection operation that occurred.
205226
The value may be one of:
@@ -216,6 +237,8 @@ added: v13.9.0
216237

217238
* {number}
218239

240+
_This property is an extension by Node.js. It is not available in Web browsers._
241+
219242
When `performanceEntry.entryType` is equal to `'gc'`, the `performance.flags`
220243
property contains additional information about garbage collection operation.
221244
The value may be one of:
@@ -233,7 +256,10 @@ The value may be one of:
233256
added: v8.5.0
234257
-->
235258

236-
Provides timing details for Node.js itself.
259+
_This property is an extension by Node.js. It is not available in Web browsers._
260+
261+
Provides timing details for Node.js itself. The constructor of this class
262+
is not exposed to users.
237263

238264
### `performanceNodeTiming.bootstrapComplete`
239265
<!-- YAML
@@ -298,7 +324,7 @@ added: v8.5.0
298324
The high resolution millisecond timestamp at which the V8 platform was
299325
initialized.
300326

301-
## Class: `PerformanceObserver`
327+
## Class: `perf_hooks.PerformanceObserver`
302328

303329
### `new PerformanceObserver(callback)`
304330
<!-- YAML
@@ -400,6 +426,7 @@ added: v8.5.0
400426

401427
The `PerformanceObserverEntryList` class is used to provide access to the
402428
`PerformanceEntry` instances passed to a `PerformanceObserver`.
429+
The constructor of this class is not exposed to users.
403430

404431
### `performanceObserverEntryList.getEntries()`
405432
<!-- YAML
@@ -447,6 +474,8 @@ added: v11.10.0
447474
than zero. **Default:** `10`.
448475
* Returns: {Histogram}
449476

477+
_This property is an extension by Node.js. It is not available in Web browsers._
478+
450479
Creates a `Histogram` object that samples and reports the event loop delay
451480
over time. The delays will be reported in nanoseconds.
452481

@@ -475,7 +504,10 @@ console.log(h.percentile(99));
475504
<!-- YAML
476505
added: v11.10.0
477506
-->
478-
Tracks the event loop delay at a given sampling rate.
507+
Tracks the event loop delay at a given sampling rate. The constructor of
508+
this class not exposed to users.
509+
510+
_This property is an extension by Node.js. It is not available in Web browsers._
479511

480512
#### `histogram.disable()`
481513
<!-- YAML
@@ -649,5 +681,9 @@ require('some-module');
649681

650682
[`'exit'`]: process.html#process_event_exit
651683
[`timeOrigin`]: https://w3c.github.io/hr-time/#dom-performance-timeorigin
684+
[`window.performance`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
652685
[Async Hooks]: async_hooks.html
653-
[W3C Performance Timeline]: https://w3c.github.io/performance-timeline/
686+
[High Resolution Time]: https://www.w3.org/TR/hr-time-2
687+
[Performance Timeline]: https://w3c.github.io/performance-timeline/
688+
[Web Performance APIs]: https://w3c.github.io/perf-timing-primer/
689+
[User Timing]: https://www.w3.org/TR/user-timing/

tools/doc/type-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const customTypesMap = {
126126
'PerformanceNodeTiming':
127127
'perf_hooks.html#perf_hooks_class_performancenodetiming_extends_performanceentry', // eslint-disable-line max-len
128128
'PerformanceObserver':
129-
'perf_hooks.html#perf_hooks_class_performanceobserver',
129+
'perf_hooks.html#perf_hooks_class_perf_hooks_performanceobserver',
130130
'PerformanceObserverEntryList':
131131
'perf_hooks.html#perf_hooks_class_performanceobserverentrylist',
132132

0 commit comments

Comments
 (0)