perf,src: add HistogramBase and internal/histogram.js · nodejs/node@7d66cea · GitHub
Skip to content

Commit 7d66cea

Browse files
jasnelltargos
authored andcommitted
perf,src: add HistogramBase and internal/histogram.js
Separating this out from the QUIC PR to allow it to be separately reviewed. The QUIC implementation makes use of the hdr_histogram for dynamic performance monitoring. This introduces a BaseObject class that allows the internal histograms to be accessed on the JavaScript side and adds a generic Histogram class that will be used by both QUIC and perf_hooks (for the event loop delay monitoring). Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #31988 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 6e68d98 commit 7d66cea

8 files changed

Lines changed: 355 additions & 74 deletions

File tree

lib/internal/histogram.js

Lines changed: 94 additions & 0 deletions

lib/perf_hooks.js

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const {
44
ArrayIsArray,
55
Boolean,
6-
Map,
76
NumberIsSafeInteger,
87
ObjectDefineProperties,
98
ObjectDefineProperty,
@@ -52,16 +51,18 @@ const kInspect = require('internal/util').customInspectSymbol;
5251

5352
const {
5453
ERR_INVALID_CALLBACK,
55-
ERR_INVALID_ARG_VALUE,
5654
ERR_INVALID_ARG_TYPE,
5755
ERR_INVALID_OPT_VALUE,
5856
ERR_VALID_PERFORMANCE_ENTRY_TYPE,
5957
ERR_INVALID_PERFORMANCE_MARK
6058
} = require('internal/errors').codes;
6159

60+
const {
61+
Histogram,
62+
kHandle,
63+
} = require('internal/histogram');
64+
6265
const { setImmediate } = require('timers');
63-
const kHandle = Symbol('handle');
64-
const kMap = Symbol('map');
6566
const kCallback = Symbol('callback');
6667
const kTypes = Symbol('types');
6768
const kEntries = Symbol('entries');
@@ -557,47 +558,9 @@ function sortedInsert(list, entry) {
557558
list.splice(location, 0, entry);
558559
}
559560

560-
class ELDHistogram {
561-
constructor(handle) {
562-
this[kHandle] = handle;
563-
this[kMap] = new Map();
564-
}
565-
566-
reset() { this[kHandle].reset(); }
561+
class ELDHistogram extends Histogram {
567562
enable() { return this[kHandle].enable(); }
568563
disable() { return this[kHandle].disable(); }
569-
570-
get exceeds() { return this[kHandle].exceeds(); }
571-
get min() { return this[kHandle].min(); }
572-
get max() { return this[kHandle].max(); }
573-
get mean() { return this[kHandle].mean(); }
574-
get stddev() { return this[kHandle].stddev(); }
575-
percentile(percentile) {
576-
if (typeof percentile !== 'number') {
577-
throw new ERR_INVALID_ARG_TYPE('percentile', 'number', percentile);
578-
}
579-
if (percentile <= 0 || percentile > 100) {
580-
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile',
581-
percentile);
582-
}
583-
return this[kHandle].percentile(percentile);
584-
}
585-
get percentiles() {
586-
this[kMap].clear();
587-
this[kHandle].percentiles(this[kMap]);
588-
return this[kMap];
589-
}
590-
591-
[kInspect]() {
592-
return {
593-
min: this.min,
594-
max: this.max,
595-
mean: this.mean,
596-
stddev: this.stddev,
597-
percentiles: this.percentiles,
598-
exceeds: this.exceeds
599-
};
600-
}
601564
}
602565

603566
function monitorEventLoopDelay(options = {}) {

node.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
'lib/internal/fs/utils.js',
138138
'lib/internal/fs/watchers.js',
139139
'lib/internal/http.js',
140+
'lib/internal/histogram.js',
140141
'lib/internal/idna.js',
141142
'lib/internal/inspector_async_hook.js',
142143
'lib/internal/js_stream_socket.js',
@@ -529,6 +530,7 @@
529530
'src/fs_event_wrap.cc',
530531
'src/handle_wrap.cc',
531532
'src/heap_utils.cc',
533+
'src/histogram.cc',
532534
'src/js_native_api.h',
533535
'src/js_native_api_types.h',
534536
'src/js_native_api_v8.cc',

src/env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ constexpr size_t kFsStatsBufferLength =
409409
V(filehandlereadwrap_template, v8::ObjectTemplate) \
410410
V(fsreqpromise_constructor_template, v8::ObjectTemplate) \
411411
V(handle_wrap_ctor_template, v8::FunctionTemplate) \
412+
V(histogram_instance_template, v8::ObjectTemplate) \
412413
V(http2settings_constructor_template, v8::ObjectTemplate) \
413414
V(http2stream_constructor_template, v8::ObjectTemplate) \
414415
V(http2ping_constructor_template, v8::ObjectTemplate) \

src/histogram-inl.h

Lines changed: 45 additions & 25 deletions

0 commit comments

Comments
 (0)