From c80fc80e671bf771252dac81b1382e717cf7216c 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 * Adds add(other) method for RecordableHistogram * Cleans up and expands tests * Eliminates unnecessary ELDHistogram native class * Improve/Simplify histogram transfer impl Signed-off-by: James M Snell perf_hooks: simplify Histogram constructor options Signed-off-by: James M Snell --- doc/api/perf_hooks.md | 91 ++++++- lib/internal/histogram.js | 267 ++++++++++++++++--- lib/internal/perf/event_loop_delay.js | 41 ++- src/histogram-inl.h | 49 ++-- src/histogram.cc | 282 +++++++++++++++++++-- src/histogram.h | 83 +++--- src/node_perf.cc | 69 ++--- src/node_perf.h | 17 -- test/parallel/test-perf-hooks-histogram.js | 133 ++++++++-- 9 files changed, 820 insertions(+), 212 deletions(-) diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 34d2a58bd017c1..083ce94c856e3d 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()` +### `histogram.add(other)` + + + +* `other` {RecordableHistogram} + +Adds the values from `other` to this histogram. + ### `histogram.record(val)`