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: fixup perf_hooks #35527

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 6 additions & 71 deletions doc/api/perf_hooks.md
Expand Up @@ -55,7 +55,9 @@ Performance Timeline. If `name` is provided, removes only the named mark.

### `performance.eventLoopUtilization([utilization1[, utilization2]])`
<!-- YAML
added: v14.10.0
added:
- v14.10.0
- v12.19.0
-->

* `utilization1` {Object} The result of a previous call to
Expand Down Expand Up @@ -222,62 +224,6 @@ obs.observe({ entryTypes: ['function'] });
wrapped();
```

### `performance.eventLoopUtilization([util1][,util2])`
<!-- YAML
added: v12.19.0
-->

* `util1` {Object} The result of a previous call to `eventLoopUtilization()`
* `util2` {Object} The result of a previous call to `eventLoopUtilization()`
prior to `util1`
* Returns {Object}
* `idle` {number}
* `active` {number}
* `utilization` {number}

The `eventLoopUtilization()` method returns an object that contains the
cumulative duration of time the event loop has been both idle and active as a
high resolution milliseconds timer. The `utilization` value is the calculated
Event Loop Utilization (ELU). If bootstrapping has not yet finished, the
properties have the value of 0.

`util1` and `util2` are optional parameters.

If `util1` is passed then the delta between the current call's `active` and
`idle` times are calculated and returned (similar to [`process.hrtime()`][]).
Likewise the adjusted `utilization` value is calculated.

If `util1` and `util2` are both passed then the calculation adjustments are
done between the two arguments. This is a convenience option because unlike
[`process.hrtime()`][] additional work is done to calculate the ELU.

ELU is similar to CPU utilization except that it is calculated using high
precision wall-clock time. It represents the percentage of time the event loop
has spent outside the event loop's event provider (e.g. `epoll_wait`). No other
CPU idle time is taken into consideration. The following is an example of how
a mostly idle process will have a high ELU.

<!-- eslint-skip -->
```js
'use strict';
const { eventLoopUtilization } = require('perf_hooks').performance;
const { spawnSync } = require('child_process');

setImmediate(() => {
const elu = eventLoopUtilization();
spawnSync('sleep', ['5']);
console.log(eventLoopUtilization(elu).utilization);
});
```

While the CPU is mostly idle while running this script the value of
`utilization` is 1. This is because the call to [`child_process.spawnSync()`][]
blocks the event loop from proceeding.

Passing in a user-defined object instead of the result of a previous call to
`eventLoopUtilization()` will lead to undefined behavior. The return values
are not guaranteed to reflect any correct state of the event loop.

## Class: `PerformanceEntry`
<!-- YAML
added: v8.5.0
Expand Down Expand Up @@ -405,7 +351,9 @@ initialized.

### `performanceNodeTiming.idleTime`
<!-- YAML
added: v14.10.0
added:
- v14.10.0
- v12.19.0
-->

* {number}
Expand Down Expand Up @@ -458,19 +406,6 @@ added: v8.5.0
The high resolution millisecond timestamp at which the V8 platform was
initialized.

### `performanceNodeTiming.idleTime`
<!-- YAML
added: v12.19.0
-->

* {number}

The high resolution millisecond timestamp of the amount of time the event loop
has been idle within the event loop's event provider (e.g. `epoll_wait`). This
does not take CPU usage into consideration. If the event loop has not yet
started (e.g., in the first tick of the main script), the property has the
value of 0.

## Class: `perf_hooks.PerformanceObserver`

### `new PerformanceObserver(callback)`
Expand Down