source: trip-planner-front/node_modules/hdr-histogram-js/src/Histogram.ts@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 10.2 KB
Line 
1import { keepSignificantDigits } from "./formatters";
2
3export const NO_TAG = "NO TAG";
4
5export type BitBucketSize = 8 | 16 | 32 | 64 | "packed";
6
7export interface HistogramSummary {
8 p50: number;
9 p75: number;
10 p90: number;
11 p97_5: number;
12 p99: number;
13 p99_9: number;
14 p99_99: number;
15 p99_999: number;
16 max: number;
17 totalCount: number;
18}
19
20export default interface Histogram {
21 /**
22 * Flag to enable automatic resizing of the underlying array
23 */
24 autoResize: boolean;
25
26 /**
27 * The current highest trackable value. May change if autoresize flag is set to true
28 */
29 readonly highestTrackableValue: number;
30
31 /**
32 * Total count of all recorded values in the histogram
33 */
34 readonly totalCount: number;
35
36 /**
37 * The computed standard deviation of all recorded values in the histogram
38 */
39 readonly stdDeviation: number;
40
41 /**
42 * The computed mean value of all recorded values in the histogram
43 */
44 readonly mean: number;
45
46 /**
47 * Main percentiles, max value and total number of recorded values
48 */
49 readonly summary: HistogramSummary;
50
51 /**
52 * A (conservatively high) estimate of the Histogram's total footprint in bytes
53 */
54 readonly estimatedFootprintInBytes: number;
55
56 readonly maxValue: number;
57
58 readonly minNonZeroValue: number;
59
60 readonly numberOfSignificantValueDigits: number;
61
62 startTimeStampMsec: number;
63 endTimeStampMsec: number;
64 tag: string;
65
66 /**
67 * Record a value in the histogram
68 *
69 * @param value The value to be recorded
70 * @throws may throw Error if value is exceeds highestTrackableValue
71 */
72 recordValue(value: number): void;
73
74 /**
75 * Record a value in the histogram (adding to the value's current count)
76 *
77 * @param value The value to be recorded
78 * @param count The number of occurrences of this value to record
79 * @throws ArrayIndexOutOfBoundsException (may throw) if value is exceeds highestTrackableValue
80 */
81 recordValueWithCount(value: number, count: number): void;
82
83 /**
84 * Get the value at a given percentile.
85 * When the given percentile is &gt; 0.0, the value returned is the value that the given
86 * percentage of the overall recorded value entries in the histogram are either smaller than
87 * or equivalent to. When the given percentile is 0.0, the value returned is the value that all value
88 * entries in the histogram are either larger than or equivalent to.
89 * <p>
90 * Note that two values are "equivalent" in this statement if
91 * {@link org.HdrHistogram.JsHistogram#valuesAreEquivalent} would return true.
92 *
93 * @param percentile The percentile for which to return the associated value
94 * @return The value that the given percentage of the overall recorded value entries in the
95 * histogram are either smaller than or equivalent to. When the percentile is 0.0, returns the
96 * value that all value entries in the histogram are either larger than or equivalent to.
97 */
98 getValueAtPercentile(percentile: number): number;
99
100 /**
101 * Produce textual representation of the value distribution of histogram data by percentile. The distribution is
102 * output with exponentially increasing resolution, with each exponentially decreasing half-distance containing
103 * <i>dumpTicksPerHalf</i> percentile reporting tick points.
104 *
105 * @param printStream Stream into which the distribution will be output
106 * <p>
107 * @param percentileTicksPerHalfDistance The number of reporting points per exponentially decreasing half-distance
108 * <p>
109 * @param outputValueUnitScalingRatio The scaling factor by which to divide histogram recorded values units in
110 * output
111 * @param useCsvFormat Output in CSV format if true. Otherwise use plain text form.
112 */
113 outputPercentileDistribution(
114 percentileTicksPerHalfDistance?: number,
115 outputValueUnitScalingRatio?: number,
116 useCsvFormat?: false
117 ): string;
118
119 toJSON(): HistogramSummary;
120
121 /**
122 * Record a value in the histogram.
123 * <p>
124 * To compensate for the loss of sampled values when a recorded value is larger than the expected
125 * interval between value samples, Histogram will auto-generate an additional series of decreasingly-smaller
126 * (down to the expectedIntervalBetweenValueSamples) value records.
127 * <p>
128 * Note: This is a at-recording correction method, as opposed to the post-recording correction method provided
129 * by {@link #copyCorrectedForCoordinatedOmission(long)}.
130 * The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct
131 * for the same coordinated omission issue.
132 * <p>
133 * See notes in the description of the Histogram calls for an illustration of why this corrective behavior is
134 * important.
135 *
136 * @param value The value to record
137 * @param expectedIntervalBetweenValueSamples If expectedIntervalBetweenValueSamples is larger than 0, add
138 * auto-generated value records as appropriate if value is larger
139 * than expectedIntervalBetweenValueSamples
140 * @throws ArrayIndexOutOfBoundsException (may throw) if value is exceeds highestTrackableValue
141 */
142 recordValueWithExpectedInterval(
143 value: number,
144 expectedIntervalBetweenValueSamples: number
145 ): void;
146
147 /**
148 * Add the contents of another histogram to this one, while correcting the incoming data for coordinated omission.
149 * <p>
150 * To compensate for the loss of sampled values when a recorded value is larger than the expected
151 * interval between value samples, the values added will include an auto-generated additional series of
152 * decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records for each count found
153 * in the current histogram that is larger than the expectedIntervalBetweenValueSamples.
154 *
155 * Note: This is a post-recording correction method, as opposed to the at-recording correction method provided
156 * by {@link #recordValueWithExpectedInterval(long, long) recordValueWithExpectedInterval}. The two
157 * methods are mutually exclusive, and only one of the two should be be used on a given data set to correct
158 * for the same coordinated omission issue.
159 * by
160 * <p>
161 * See notes in the description of the Histogram calls for an illustration of why this corrective behavior is
162 * important.
163 *
164 * @param otherHistogram The other histogram. highestTrackableValue and largestValueWithSingleUnitResolution must match.
165 * @param expectedIntervalBetweenValueSamples If expectedIntervalBetweenValueSamples is larger than 0, add
166 * auto-generated value records as appropriate if value is larger
167 * than expectedIntervalBetweenValueSamples
168 * @throws ArrayIndexOutOfBoundsException (may throw) if values exceed highestTrackableValue
169 */
170 addWhileCorrectingForCoordinatedOmission(
171 otherHistogram: Histogram,
172 expectedIntervalBetweenValueSamples: number
173 ): void;
174
175 /**
176 * Get a copy of this histogram, corrected for coordinated omission.
177 * <p>
178 * To compensate for the loss of sampled values when a recorded value is larger than the expected
179 * interval between value samples, the new histogram will include an auto-generated additional series of
180 * decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records for each count found
181 * in the current histogram that is larger than the expectedIntervalBetweenValueSamples.
182 *
183 * Note: This is a post-correction method, as opposed to the at-recording correction method provided
184 * by {@link #recordValueWithExpectedInterval(long, long) recordValueWithExpectedInterval}. The two
185 * methods are mutually exclusive, and only one of the two should be be used on a given data set to correct
186 * for the same coordinated omission issue.
187 * by
188 * <p>
189 * See notes in the description of the Histogram calls for an illustration of why this corrective behavior is
190 * important.
191 *
192 * @param expectedIntervalBetweenValueSamples If expectedIntervalBetweenValueSamples is larger than 0, add
193 * auto-generated value records as appropriate if value is larger
194 * than expectedIntervalBetweenValueSamples
195 * @return a copy of this histogram, corrected for coordinated omission.
196 */
197 copyCorrectedForCoordinatedOmission(
198 expectedIntervalBetweenValueSamples: number
199 ): Histogram;
200
201 /**
202 * Add the contents of another histogram to this one.
203 * <p>
204 * As part of adding the contents, the start/end timestamp range of this histogram will be
205 * extended to include the start/end timestamp range of the other histogram.
206 *
207 * @param otherHistogram The other histogram.
208 * @throws (may throw) if values in fromHistogram's are
209 * higher than highestTrackableValue.
210 */
211 add(otherHistogram: Histogram): void;
212
213 /**
214 * Subtract the contents of another histogram from this one.
215 * <p>
216 * The start/end timestamps of this histogram will remain unchanged.
217 *
218 * @param otherHistogram The other histogram.
219 * @throws ArrayIndexOutOfBoundsException (may throw) if values in otherHistogram's are higher than highestTrackableValue.
220 *
221 */
222 subtract(otherHistogram: Histogram): void;
223
224 reset(): void;
225
226 /**
227 * Clean up memory associated to this histogram. Useful for WebAssembly implementations
228 */
229 destroy(): void;
230}
231
232export interface HistogramConstructor {
233 new (
234 lowestDiscernibleValue: number,
235 highestTrackableValue: number,
236 numberOfSignificantValueDigits: number
237 ): Histogram;
238}
239
240export const toSummary = (histogram: Histogram): HistogramSummary => {
241 const { totalCount, maxValue, numberOfSignificantValueDigits } = histogram;
242 const round = keepSignificantDigits(numberOfSignificantValueDigits);
243 return {
244 p50: round(histogram.getValueAtPercentile(50)),
245 p75: round(histogram.getValueAtPercentile(75)),
246 p90: round(histogram.getValueAtPercentile(90)),
247 p97_5: round(histogram.getValueAtPercentile(97.5)),
248 p99: round(histogram.getValueAtPercentile(99)),
249 p99_9: round(histogram.getValueAtPercentile(99.9)),
250 p99_99: round(histogram.getValueAtPercentile(99.99)),
251 p99_999: round(histogram.getValueAtPercentile(99.999)),
252 max: maxValue,
253 totalCount,
254 };
255};
Note: See TracBrowser for help on using the repository browser.