Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: clarify about the Node.js-only extensions in perf_hooks #33199

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 55 additions & 12 deletions doc/api/perf_hooks.md
@@ -1,13 +1,18 @@
# Performance Timing API
# Performance Measurement APIs

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

> Stability: 2 - Stable

The Performance Timing API provides an implementation of the
[W3C Performance Timeline][] specification. The purpose of the API
is to support collection of high resolution performance metrics.
This is the same Performance API as implemented in modern Web browsers.
This module provides an implementation of a subset of the W3C
[Web Performance APIs][] as well as additional APIs for
Node.js-specific performance measurements.

Currently, Node.js supports the following [Web Performance APIs][]:
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

* [High Resolution Time][]
* [Performance Timeline][]
* [User Timing][]

```js
const { PerformanceObserver, performance } = require('perf_hooks');
Expand All @@ -28,11 +33,14 @@ doSomeLongRunningProcess(() => {
});
```

## Class: `Performance`
## `perf_hooks.performance`
<!-- YAML
added: v8.5.0
-->

An object that can be used to collect performance metrics from the current
Node.js instance. It's similar to [`window.performance`][] in browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

### `performance.clearMarks([name])`
<!-- YAML
added: v8.5.0
Expand Down Expand Up @@ -95,6 +103,9 @@ added: v8.5.0

* {PerformanceNodeTiming}

> Note: This property is an extension by Node.js. It's not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

An instance of the `PerformanceNodeTiming` class that provides performance
metrics for specific Node.js operational milestones.

Expand Down Expand Up @@ -125,6 +136,9 @@ added: v8.5.0

* `fn` {Function}

> Note: This property is an extension by Node.js. It's not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

Wraps a function within a new function that measures the running time of the
wrapped function. A `PerformanceObserver` must be subscribed to the `'function'`
event type in order for the timing details to be accessed.
Expand Down Expand Up @@ -192,8 +206,15 @@ added: v8.5.0

* {string}

The type of the performance entry. Currently it may be one of: `'node'`,
`'mark'`, `'measure'`, `'gc'`, `'function'`, `'http2'` or `'http'`.
The type of the performance entry. Currently it may be one of:
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

* `'node'` (Node.js only)
* `'mark'` (available on the Web)
* `'measure'` (available on the Web)
* `'gc'` (Node.js only)
* `'function'` (Node.js only)
* `'http2'` (Node.js only)
* `'http'` (Node.js only)

### `performanceEntry.kind`
<!-- YAML
Expand All @@ -202,6 +223,9 @@ added: v8.5.0

* {number}

> Note: This property is an extension by Node.js. It is not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

When `performanceEntry.entryType` is equal to `'gc'`, the `performance.kind`
property identifies the type of garbage collection operation that occurred.
The value may be one of:
Expand All @@ -218,6 +242,9 @@ added: v13.9.0

* {number}

> Note: This property is an extension by Node.js. It is not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

When `performanceEntry.entryType` is equal to `'gc'`, the `performance.flags`
property contains additional information about garbage collection operation.
The value may be one of:
Expand All @@ -235,7 +262,11 @@ The value may be one of:
added: v8.5.0
-->

Provides timing details for Node.js itself.
> Note: This class is an extension by Node.js. It's not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

Provides timing details for Node.js itself. The constructor of this class
is not directly exposed to users.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

### `performanceNodeTiming.bootstrapComplete`
<!-- YAML
Expand Down Expand Up @@ -300,7 +331,7 @@ added: v8.5.0
The high resolution millisecond timestamp at which the V8 platform was
initialized.

## Class: `PerformanceObserver`
## Class: `perf_hooks.PerformanceObserver`

### `new PerformanceObserver(callback)`
<!-- YAML
Expand Down Expand Up @@ -402,6 +433,7 @@ added: v8.5.0

The `PerformanceObserverEntryList` class is used to provide access to the
`PerformanceEntry` instances passed to a `PerformanceObserver`.
The constructor of this class is not directly exposed to users.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

### `performanceObserverEntryList.getEntries()`
<!-- YAML
Expand Down Expand Up @@ -449,6 +481,9 @@ added: v11.10.0
than zero. **Default:** `10`.
* Returns: {Histogram}

> Note: This property is an extension by Node.js. It's not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

Creates a `Histogram` object that samples and reports the event loop delay
over time. The delays will be reported in nanoseconds.

Expand Down Expand Up @@ -477,7 +512,11 @@ console.log(h.percentile(99));
<!-- YAML
added: v11.10.0
-->
Tracks the event loop delay at a given sampling rate.
Tracks the event loop delay at a given sampling rate. The constructor of
this class not directly exposed to users.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

> Note: This class is an extension by Node.js. It's not available in Web
> browsers.
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

#### `histogram.disable()`
<!-- YAML
Expand Down Expand Up @@ -651,5 +690,9 @@ require('some-module');

[`'exit'`]: process.html#process_event_exit
[`timeOrigin`]: https://w3c.github.io/hr-time/#dom-performance-timeorigin
[`window.performance`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
[Async Hooks]: async_hooks.html
[W3C Performance Timeline]: https://w3c.github.io/performance-timeline/
[High Resolution Time]: https://www.w3.org/TR/hr-time-2
[Performance Timeline]: https://w3c.github.io/performance-timeline/
[Web Performance APIs]: https://w3c.github.io/perf-timing-primer/
[User Timing]: https://www.w3.org/TR/user-timing/
2 changes: 1 addition & 1 deletion tools/doc/type-parser.js
Expand Up @@ -125,7 +125,7 @@ const customTypesMap = {
'PerformanceNodeTiming':
'perf_hooks.html#perf_hooks_class_performancenodetiming_extends_performanceentry', // eslint-disable-line max-len
'PerformanceObserver':
'perf_hooks.html#perf_hooks_class_performanceobserver',
'perf_hooks.html#perf_hooks_class_perf_hooks_performanceobserver',
'PerformanceObserverEntryList':
'perf_hooks.html#perf_hooks_class_performanceobserverentrylist',

Expand Down