perf_hooks.importHistogram(data)
data<Uint8Array> 一个之前由histogram.export()生成的 CBOR 编码直方图。- 返回:<RecordableHistogram>
从 CBOR 编码的 Uint8Array 重建直方图。返回的直方图是一个完整的 <RecordableHistogram>,包含所有桶数据、配置和 EWMA 状态。可以向其中记录新值。
🌐 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.
histogram.export() 生成的任何格式版本的数据都可以导入。详情请参见 直方图导出格式兼容性。
🌐 Data in any format version produced by histogram.export() can be
imported. See histogram export format compatibility for details.
const { createHistogram, importHistogram } = require('node:perf_hooks');
const h = createHistogram();
for (let i = 1; i <= 1000; i++) h.record(i);
// Serialize and reconstruct
const data = h.export();
const h2 = importHistogram(data);
console.log(h2.count); // 1000
console.log(h2.percentile(99)); // Same as h.percentile(99)