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 all commits
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
60 changes: 48 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.

Node.js supports the following [Web Performance APIs][]:

* [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 is similar to [`window.performance`][] in browsers.

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

* {PerformanceNodeTiming}

_This property is an extension by Node.js. It is not available in Web browsers._

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

Expand Down Expand Up @@ -125,6 +135,8 @@ added: v8.5.0

* `fn` {Function}

_This property is an extension by Node.js. It is not available in Web browsers._

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 +204,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. It may be one of:

* `'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 +221,8 @@ added: v8.5.0

* {number}

_This property is an extension by Node.js. It is not available in Web browsers._

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 +239,8 @@ added: v13.9.0

* {number}

_This property is an extension by Node.js. It is not available in Web browsers._

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 +258,10 @@ The value may be one of:
added: v8.5.0
-->

Provides timing details for Node.js itself.
_This property is an extension by Node.js. It is not available in Web browsers._

Provides timing details for Node.js itself. The constructor of this class
is not exposed to users.

### `performanceNodeTiming.bootstrapComplete`
<!-- YAML
Expand Down Expand Up @@ -300,7 +326,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 +428,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 exposed to users.

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

_This property is an extension by Node.js. It is not available in Web browsers._

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 +506,10 @@ 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 exposed to users.

_This property is an extension by Node.js. It is not available in Web browsers._

#### `histogram.disable()`
<!-- YAML
Expand Down Expand Up @@ -651,5 +683,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