1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | /*
|
---|
4 | * This is a TypeScript port of the original Java version, which was written by
|
---|
5 | * Gil Tene as described in
|
---|
6 | * https://github.com/HdrHistogram/HdrHistogram
|
---|
7 | * and released to the public domain, as explained at
|
---|
8 | * http://creativecommons.org/publicdomain/zero/1.0/
|
---|
9 | */
|
---|
10 | const JsHistogram_1 = require("./JsHistogram");
|
---|
11 | const PackedArray_1 = require("./packedarray/PackedArray");
|
---|
12 | /**
|
---|
13 | * <h3>A High Dynamic Range (HDR) Histogram that uses a packed internal representation</h3>
|
---|
14 | * <p>
|
---|
15 | * {@link PackedHistogram} supports the recording and analyzing sampled data value counts across a configurable
|
---|
16 | * integer value range with configurable value precision within the range. Value precision is expressed as the
|
---|
17 | * number of significant digits in the value recording, and provides control over value quantization behavior
|
---|
18 | * across the value range and the subsequent value resolution at any given level.
|
---|
19 | * <p>
|
---|
20 | * {@link PackedHistogram} tracks value counts in a packed internal representation optimized
|
---|
21 | * for typical histogram recoded values are sparse in the value range and tend to be incremented in small unit counts.
|
---|
22 | * This packed representation tends to require significantly smaller amounts of stoarge when compared to unpacked
|
---|
23 | * representations, but can incur additional recording cost due to resizing and repacking operations that may
|
---|
24 | * occur as previously unrecorded values are encountered.
|
---|
25 | * <p>
|
---|
26 | * For example, a {@link PackedHistogram} could be configured to track the counts of observed integer values between 0 and
|
---|
27 | * 3,600,000,000,000 while maintaining a value precision of 3 significant digits across that range. Value quantization
|
---|
28 | * within the range will thus be no larger than 1/1,000th (or 0.1%) of any value. This example Histogram could
|
---|
29 | * be used to track and analyze the counts of observed response times ranging between 1 nanosecond and 1 hour
|
---|
30 | * in magnitude, while maintaining a value resolution of 1 microsecond up to 1 millisecond, a resolution of
|
---|
31 | * 1 millisecond (or better) up to one second, and a resolution of 1 second (or better) up to 1,000 seconds. At its
|
---|
32 | * maximum tracked value (1 hour), it would still maintain a resolution of 3.6 seconds (or better).
|
---|
33 | * <p>
|
---|
34 | * Auto-resizing: When constructed with no specified value range range (or when auto-resize is turned on with {@link
|
---|
35 | * Histogram#setAutoResize}) a {@link PackedHistogram} will auto-resize its dynamic range to include recorded values as
|
---|
36 | * they are encountered. Note that recording calls that cause auto-resizing may take longer to execute, as resizing
|
---|
37 | * incurs allocation and copying of internal data structures.
|
---|
38 | * <p>
|
---|
39 | */
|
---|
40 | class PackedHistogram extends JsHistogram_1.default {
|
---|
41 | constructor(lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits) {
|
---|
42 | super(lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits);
|
---|
43 | this._totalCount = 0;
|
---|
44 | this.packedCounts = new PackedArray_1.PackedArray(this.countsArrayLength);
|
---|
45 | }
|
---|
46 | clearCounts() {
|
---|
47 | this.packedCounts.clear();
|
---|
48 | }
|
---|
49 | incrementCountAtIndex(index) {
|
---|
50 | this.packedCounts.increment(index);
|
---|
51 | }
|
---|
52 | addToCountAtIndex(index, value) {
|
---|
53 | this.packedCounts.add(index, value);
|
---|
54 | }
|
---|
55 | setCountAtIndex(index, value) {
|
---|
56 | this.packedCounts.set(index, value);
|
---|
57 | }
|
---|
58 | resize(newHighestTrackableValue) {
|
---|
59 | this.establishSize(newHighestTrackableValue);
|
---|
60 | this.packedCounts.setVirtualLength(this.countsArrayLength);
|
---|
61 | }
|
---|
62 | getCountAtIndex(index) {
|
---|
63 | return this.packedCounts.get(index);
|
---|
64 | }
|
---|
65 | _getEstimatedFootprintInBytes() {
|
---|
66 | return 192 + 8 * this.packedCounts.getPhysicalLength();
|
---|
67 | }
|
---|
68 | copyCorrectedForCoordinatedOmission(expectedIntervalBetweenValueSamples) {
|
---|
69 | const copy = new PackedHistogram(this.lowestDiscernibleValue, this.highestTrackableValue, this.numberOfSignificantValueDigits);
|
---|
70 | copy.addWhileCorrectingForCoordinatedOmission(this, expectedIntervalBetweenValueSamples);
|
---|
71 | return copy;
|
---|
72 | }
|
---|
73 | toString() {
|
---|
74 | return `PackedHistogram ${JSON.stringify(this, null, 2)}`;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | exports.default = PackedHistogram;
|
---|
78 | //# sourceMappingURL=PackedHistogram.js.map |
---|