1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.grinder.statistics;
25
26 import static java.util.Arrays.asList;
27
28 import java.io.Serializable;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 public final class StatisticsIndexMap implements Serializable {
64
65 private static final long serialVersionUID = 1;
66
67 private final Map<String, DoubleIndex> m_doubleMap =
68 new HashMap<String, DoubleIndex>();
69 private final Map<String, LongIndex> m_longMap =
70 new HashMap<String, LongIndex>();
71 private final Map<String, LongIndex> m_transientLongMap =
72 new HashMap<String, LongIndex>();
73 private final Map<String, DoubleSampleIndex> m_doubleSampleMap =
74 new HashMap<String, DoubleSampleIndex>();
75 private final Map<String, LongSampleIndex> m_longSampleMap =
76 new HashMap<String, LongSampleIndex>();
77
78
79
80 private final int m_numberOfDoubles;
81 private final int m_numberOfLongs;
82
83
84
85
86
87 public static final String HTTP_PLUGIN_RESPONSE_STATUS_KEY =
88 "httpplugin.responseStatus";
89
90
91
92
93
94 public static final String HTTP_PLUGIN_RESPONSE_LENGTH_KEY =
95 "httpplugin.responseLength";
96
97
98
99
100
101 public static final String HTTP_PLUGIN_RESPONSE_ERRORS_KEY =
102 "httpplugin.responseErrors";
103
104
105
106
107
108 public static final String HTTP_PLUGIN_DNS_TIME_KEY =
109 "httpplugin.dnsTime";
110
111
112
113
114
115 public static final String HTTP_PLUGIN_CONNECT_TIME_KEY =
116 "httpplugin.connectTime";
117
118
119
120
121
122 public static final String HTTP_PLUGIN_FIRST_BYTE_TIME_KEY =
123 "httpplugin.firstByteTime";
124
125
126
127
128
129 public static final String HTTP_PLUGIN_CONNECTIONS_ESTABLISHED =
130 "httpplugin.connectionsEstablished";
131
132
133
134
135 StatisticsIndexMap() {
136
137
138
139 this(asList("errors",
140 "untimedTests",
141 HTTP_PLUGIN_RESPONSE_STATUS_KEY,
142 HTTP_PLUGIN_RESPONSE_LENGTH_KEY,
143 HTTP_PLUGIN_RESPONSE_ERRORS_KEY,
144 HTTP_PLUGIN_DNS_TIME_KEY,
145 HTTP_PLUGIN_CONNECT_TIME_KEY,
146 HTTP_PLUGIN_FIRST_BYTE_TIME_KEY,
147 HTTP_PLUGIN_CONNECTIONS_ESTABLISHED,
148 "userLong0",
149 "userLong1",
150 "userLong2",
151 "userLong3",
152 "userLong4"),
153 asList("peakTPS",
154 "userDouble0",
155 "userDouble1",
156 "userDouble2",
157 "userDouble3",
158 "userDouble4"),
159 asList("period"),
160 asList("timedTests"));
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175 StatisticsIndexMap(List<String> longNames,
176 List<String> doubleNames,
177 List<String> transientLongNames,
178 List<String> longSampleNames) {
179 int nextLongIndex = 0;
180 int nextTransientLongIndex = 0;
181
182 for (String longName : longNames) {
183 m_longMap.put(longName, new LongIndex(nextLongIndex++));
184 }
185
186 int nextDoubleIndex = 0;
187
188 for (String doubleName : doubleNames) {
189 m_doubleMap.put(doubleName, new DoubleIndex(nextDoubleIndex++));
190 }
191
192 for (String longSampleName : longSampleNames) {
193 createLongSampleIndex(longSampleName,
194 new LongIndex(nextLongIndex++),
195 new LongIndex(nextLongIndex++),
196 new DoubleIndex(nextDoubleIndex++));
197 }
198
199 for (String transientLongName : transientLongNames) {
200 m_transientLongMap.put(transientLongName,
201 new LongIndex(nextTransientLongIndex++, true));
202 }
203
204 m_numberOfDoubles = nextDoubleIndex;
205 m_numberOfLongs = nextLongIndex;
206 }
207
208 int getNumberOfDoubles() {
209 return m_numberOfDoubles;
210 }
211
212 int getNumberOfLongs() {
213 return m_numberOfLongs;
214 }
215
216 int getNumberOfTransientLongs() {
217 return m_transientLongMap.size();
218 }
219
220 Collection<DoubleSampleIndex> getDoubleSampleIndicies() {
221 return m_doubleSampleMap.values();
222 }
223
224 Collection<LongSampleIndex> getLongSampleIndicies() {
225 return m_longSampleMap.values();
226 }
227
228
229
230
231
232
233
234
235 public DoubleIndex getDoubleIndex(String statisticName) {
236 return m_doubleMap.get(statisticName);
237 }
238
239
240
241
242
243
244
245
246 public LongIndex getLongIndex(String statisticName) {
247 final LongIndex nonTransient = m_longMap.get(statisticName);
248
249 if (nonTransient != null) {
250 return nonTransient;
251 }
252 else {
253 return m_transientLongMap.get(statisticName);
254 }
255 }
256
257
258
259
260
261
262
263
264 public DoubleSampleIndex getDoubleSampleIndex(String statisticName) {
265 return m_doubleSampleMap.get(statisticName);
266 }
267
268
269
270
271
272
273
274
275 public LongSampleIndex getLongSampleIndex(String statisticName) {
276 return m_longSampleMap.get(statisticName);
277 }
278
279
280
281
282
283
284
285
286
287
288
289
290
291 private LongSampleIndex createLongSampleIndex(String statisticName,
292 LongIndex sumIndex,
293 LongIndex countIndex,
294 DoubleIndex varianceIndex) {
295 final LongSampleIndex result =
296 new LongSampleIndex(sumIndex, countIndex, varianceIndex);
297
298 m_longSampleMap.put(statisticName, result);
299
300 return result;
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317 DoubleSampleIndex createDoubleSampleIndex(String statisticName,
318 DoubleIndex sumIndex,
319 LongIndex countIndex,
320 DoubleIndex varianceIndex) {
321 final DoubleSampleIndex result =
322 new DoubleSampleIndex(sumIndex, countIndex, varianceIndex);
323
324 m_doubleSampleMap.put(statisticName, result);
325
326 return result;
327 }
328
329
330
331
332
333
334 void removeDoubleSampleIndex(String statisticName) {
335 m_doubleSampleMap.remove(statisticName);
336 }
337
338
339
340
341
342
343
344
345
346
347 abstract static class AbstractSimpleIndex {
348
349 private final int m_value;
350 private final boolean m_transient;
351
352 protected AbstractSimpleIndex(int i, boolean isTransient) {
353 m_value = i;
354 m_transient = isTransient;
355 }
356
357 public final int getValue() {
358 return m_value;
359 }
360
361 public boolean isTransient() {
362 return m_transient;
363 }
364 }
365
366
367
368
369 public static final class DoubleIndex extends AbstractSimpleIndex {
370 private DoubleIndex(int i) {
371 super(i, false);
372 }
373 }
374
375
376
377
378 public static final class LongIndex extends AbstractSimpleIndex {
379 private LongIndex(int i) {
380 this(i, false);
381 }
382
383 private LongIndex(int i, boolean isTransient) {
384 super(i, isTransient);
385 }
386 }
387
388
389
390
391 static class SampleIndex {
392 private final LongIndex m_countIndex;
393 private final DoubleIndex m_varianceIndex;
394
395 protected SampleIndex(LongIndex countIndex, DoubleIndex varianceIndex) {
396 m_countIndex = countIndex;
397 m_varianceIndex = varianceIndex;
398 }
399
400
401
402
403
404
405
406
407
408
409 final LongIndex getCountIndex() {
410 return m_countIndex;
411 }
412
413
414
415
416
417
418
419
420
421
422 final DoubleIndex getVarianceIndex() {
423 return m_varianceIndex;
424 }
425 }
426
427
428
429
430
431 public static final class DoubleSampleIndex extends SampleIndex {
432 private final DoubleIndex m_sumIndex;
433
434 private DoubleSampleIndex(DoubleIndex sumIndex,
435 LongIndex countIndex,
436 DoubleIndex varianceIndex) {
437 super(countIndex, varianceIndex);
438 m_sumIndex = sumIndex;
439 }
440
441
442
443
444
445
446
447
448
449
450 DoubleIndex getSumIndex() {
451 return m_sumIndex;
452 }
453 }
454
455
456
457
458
459 public static final class LongSampleIndex extends SampleIndex {
460 private final LongIndex m_sumIndex;
461
462 private LongSampleIndex(LongIndex sumIndex,
463 LongIndex countIndex,
464 DoubleIndex varianceIndex) {
465 super(countIndex, varianceIndex);
466 m_sumIndex = sumIndex;
467 }
468
469
470
471
472
473
474
475
476
477
478 LongIndex getSumIndex() {
479 return m_sumIndex;
480 }
481 }
482 }