From 37a4958ca34b33b293e3edda76b9bc0de3d5be58 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 11 Dec 2021 16:59:48 -0800 Subject: [PATCH] perf_hooks: multiple fixes for Histogram * The createHistogram(options) options weren't actually implemented * Add a new count property that tracks the number of samples * Adds BigInt options for relevant properties * Cleans up and expands tests * Eliminates unnecessary ELDHistogram native class * Improve/Simplify histogram transfer impl Signed-off-by: James M Snell --- doc/api/perf_hooks.md | 81 ++++++- lib/internal/histogram.js | 256 +++++++++++++++++---- lib/internal/perf/event_loop_delay.js | 41 +++- src/histogram-inl.h | 40 ++-- src/histogram.cc | 237 ++++++++++++++++++- src/histogram.h | 52 +++-- src/node_perf.cc | 67 ++---- src/node_perf.h | 17 -- test/parallel/test-perf-hooks-histogram.js | 108 ++++++--- 9 files changed, 720 insertions(+), 179 deletions(-) diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 34d2a58bd017c1..cff0e311478c5a 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -808,7 +808,7 @@ performance.mark('test'); performance.mark('meow'); ``` -## `perf_hooks.createHistogram([options])` +## `perf_hooks.createHistogram()` * `options` {Object} - * `min` {number|bigint} The minimum recordable value. Must be an integer + * `lowest` {number|bigint} The lowest discernible value. Must be an integer value greater than 0. **Default:** `1`. - * `max` {number|bigint} The maximum recordable value. Must be an integer - value greater than `min`. **Default:** `Number.MAX_SAFE_INTEGER`. + * `highest` {number|bigint} The highest recordable value. Must be an integer + value that is equal to or greater than two times `min`. + **Default:** `Number.MAX_SAFE_INTEGER`. * `figures` {number} The number of accuracy digits. Must be a number between `1` and `5`. **Default:** `3`. * Returns {RecordableHistogram} @@ -870,6 +871,26 @@ console.log(h.percentile(99)); added: v11.10.0 --> +### `histogram.count` + + + +* {number} + +The number of samples recorded by the histogram. + +### `histogram.countBigInt` + + + +* {bigint} + +The number of samples recorded by the histogram. + ### `histogram.exceeds` + +* {bigint} + +The number of times the event loop delay exceeded the maximum 1 hour event +loop delay threshold. + ### `histogram.max` + +* {bigint} + +The maximum recorded event loop delay. + ### `histogram.mean` + +* {bigint} + +The minimum recorded event loop delay. + ### `histogram.percentile(percentile)` + +* `percentile` {number} A percentile value in the range (0, 100]. +* Returns: {bigint} + +Returns the value at the given percentile. + ### `histogram.percentiles` + +* {Map} + +Returns a `Map` object detailing the accumulated percentile distribution. + ### `histogram.reset()`