Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion doc/api/perf_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,11 @@ console.log(snapshot.percentile(99));

<!-- YAML
added: v26.9.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/66098
description: Format version 2 is supported. Unknown keys in version 2
data are ignored.
-->

* `data` {Uint8Array} A CBOR-encoded histogram previously produced by
Expand All @@ -1787,6 +1792,9 @@ Reconstructs a histogram from a CBOR-encoded `Uint8Array`. The returned
histogram is a full {RecordableHistogram} with all bucket data, configuration,
and EWMA state restored. New values can be recorded into it.

Data in any format version produced by [`histogram.export()`][] can be
imported. See [histogram export format compatibility][] for details.

```js
const { createHistogram, importHistogram } = require('node:perf_hooks');

Expand Down Expand Up @@ -2180,6 +2188,10 @@ loop delay threshold.

<!-- YAML
added: v26.9.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/66098
description: The output uses format version 2.
-->

* Returns: {Uint8Array}
Expand All @@ -2198,7 +2210,7 @@ The CBOR payload is a map with integer keys:

| Key | Type | Field |
| --- | ------- | --------------------------------------------- |
| 0 | uint | Format version (currently 1) |
| 0 | uint | Format version (currently 2) |
| 1 | uint | Lowest discernible value |
| 2 | uint | Highest trackable value |
| 3 | uint | Significant figures |
Expand All @@ -2213,6 +2225,23 @@ The CBOR payload is a map with integer keys:

Any standard CBOR decoder can parse the output.

#### Histogram export format compatibility

[`perf_hooks.importHistogram()`][] accepts every format version that
`histogram.export()` has produced:

* Version 1 was produced by Node.js v26.9.0. Data with a version 1 key, or
without a version key, is imported with the original semantics: keys
that are not listed above are rejected.
* Version 2 has the same layout as version 1. Keys that are not recognized
are ignored, so later versions of Node.js can add fields to version 2
data without changing the version, and the data remains importable.

Data with any other version is rejected.

When the total count, min, or max value is absent, it is derived from the
bucket counts. A total count that is present must match the bucket counts.

### `histogram.ewmaMean`

<!-- YAML
Expand Down Expand Up @@ -3267,3 +3296,4 @@ dns.promises.resolve('localhost');
[`timeOrigin`]: https://w3c.github.io/hr-time/#dom-performance-timeorigin
[`window.performance.toJSON`]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON
[`window.performance`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
[histogram export format compatibility]: #histogram-export-format-compatibility
Loading
Loading