mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib: refactor to use more primordials in internal/histogram.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/36455 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
083abe20b9
commit
1623aff55c
@ -5,7 +5,7 @@ const {
|
||||
} = require('internal/util');
|
||||
|
||||
const { format } = require('util');
|
||||
const { Map, Symbol } = primordials;
|
||||
const { SafeMap, Symbol } = primordials;
|
||||
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
@ -19,11 +19,10 @@ const kHandle = Symbol('kHandle');
|
||||
// record various metrics. This Histogram class provides a
|
||||
// generally read-only view of the internal histogram.
|
||||
class Histogram {
|
||||
#handle = undefined;
|
||||
#map = new Map();
|
||||
#map = new SafeMap();
|
||||
|
||||
constructor(internal) {
|
||||
this.#handle = internal;
|
||||
this[kHandle] = internal;
|
||||
}
|
||||
|
||||
[kInspect]() {
|
||||
@ -39,23 +38,23 @@ class Histogram {
|
||||
}
|
||||
|
||||
get min() {
|
||||
return this.#handle ? this.#handle.min() : undefined;
|
||||
return this[kHandle]?.min();
|
||||
}
|
||||
|
||||
get max() {
|
||||
return this.#handle ? this.#handle.max() : undefined;
|
||||
return this[kHandle]?.max();
|
||||
}
|
||||
|
||||
get mean() {
|
||||
return this.#handle ? this.#handle.mean() : undefined;
|
||||
return this[kHandle]?.mean();
|
||||
}
|
||||
|
||||
get exceeds() {
|
||||
return this.#handle ? this.#handle.exceeds() : undefined;
|
||||
return this[kHandle]?.exceeds();
|
||||
}
|
||||
|
||||
get stddev() {
|
||||
return this.#handle ? this.#handle.stddev() : undefined;
|
||||
return this[kHandle]?.stddev();
|
||||
}
|
||||
|
||||
percentile(percentile) {
|
||||
@ -65,26 +64,22 @@ class Histogram {
|
||||
if (percentile <= 0 || percentile > 100)
|
||||
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile', percentile);
|
||||
|
||||
return this.#handle ? this.#handle.percentile(percentile) : undefined;
|
||||
return this[kHandle]?.percentile(percentile);
|
||||
}
|
||||
|
||||
get percentiles() {
|
||||
this.#map.clear();
|
||||
if (this.#handle)
|
||||
this.#handle.percentiles(this.#map);
|
||||
this[kHandle]?.percentiles(this.#map);
|
||||
return this.#map;
|
||||
}
|
||||
|
||||
reset() {
|
||||
if (this.#handle)
|
||||
this.#handle.reset();
|
||||
this[kHandle]?.reset();
|
||||
}
|
||||
|
||||
[kDestroy]() {
|
||||
this.#handle = undefined;
|
||||
this[kHandle] = undefined;
|
||||
}
|
||||
|
||||
get [kHandle]() { return this.#handle; }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user