1 package net.obsearch.stats;
2
3 import hep.aida.bin.StaticBin1D;
4
5 import java.util.HashMap;
6 import java.util.Map.Entry;
7
8 import net.obsearch.index.utils.IntegerHolder;
9 import net.obsearch.index.utils.StatsUtil;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class Statistics {
36
37
38
39
40 private HashMap<String, IntegerHolder> extra = new HashMap<String, IntegerHolder>();
41
42
43
44
45
46 private HashMap<String, StaticBin1D> extraStats = new HashMap<String, StaticBin1D>();
47
48
49
50
51
52 private HashMap<String, Object> extraObjects = new HashMap();
53
54
55
56
57 private long distanceCount = 0;
58
59
60
61 private long smapCount = 0;
62
63
64
65
66 private long diskAccessCount = 0;
67
68
69
70
71 private long queryCount = 0;
72
73
74
75
76 private long dataRead = 0;
77
78
79
80
81 private long bucketsRead = 0;
82
83
84
85
86
87
88
89 public void incBucketsRead(long x){
90 bucketsRead += x;
91 }
92
93
94
95
96 public void incBucketsRead(){
97 bucketsRead++;
98 }
99
100
101
102
103
104 public void incExtra(String key){
105 incExtra(key, 1);
106 }
107
108
109
110
111
112 public void incExtra(String key, int value){
113 IntegerHolder i = extra.get(key);
114 if(i == null){
115 i = new IntegerHolder(0);
116 extra.put(key, i);
117 }
118 i.add(value);
119 }
120
121
122
123
124
125 public void setExtra(String key, int value){
126 IntegerHolder i = extra.get(key);
127 if(i == null){
128 i = new IntegerHolder(0);
129 extra.put(key, i);
130 }
131 i.setValue(value);
132 }
133
134
135
136
137
138 public int getExtra(String key){
139 IntegerHolder i = extra.get(key);
140 if(i == null){
141 return 0;
142 }
143 return i.getValue();
144 }
145
146
147
148
149 public void incDistanceCount(long distance) {
150 distanceCount+= distance;
151 }
152
153
154
155
156 public void incDistanceCount() {
157 distanceCount++;
158 }
159
160
161
162
163 public void incSmapCount() {
164 smapCount++;
165 }
166
167
168
169
170
171 public void incSmapCount(long count) {
172 smapCount += count;
173 }
174
175
176
177
178 public void incDiskAccessCount() {
179 diskAccessCount++;
180 }
181
182
183
184
185 public void incQueryCount() {
186 queryCount++;
187 }
188
189
190
191
192
193 public void incDataRead(long dataRead) {
194 this.dataRead += dataRead;
195 }
196
197
198
199
200
201 public long getDistanceCount() {
202 return distanceCount;
203 }
204
205
206
207
208 public void setDistanceCount(long distanceCount) {
209 this.distanceCount = distanceCount;
210 }
211
212
213
214
215 public long getSmapCount() {
216 return smapCount;
217 }
218
219
220
221
222 public void setSmapCount(long smapCount) {
223 this.smapCount = smapCount;
224 }
225
226
227
228
229 public long getDiskAccessCount() {
230 return diskAccessCount;
231 }
232
233
234
235
236 public void setDiskAccessCount(long diskAccessCount) {
237 this.diskAccessCount = diskAccessCount;
238 }
239
240
241
242
243 public long getQueryCount() {
244 return queryCount;
245 }
246
247
248
249
250 public void setQueryCount(long queryCount) {
251 this.queryCount = queryCount;
252 }
253
254
255
256
257 public long getDataRead() {
258 return dataRead;
259 }
260
261
262
263
264 public void setDataRead(long dataRead) {
265 this.dataRead = dataRead;
266 }
267
268
269
270
271 public void resetStats(){
272 distanceCount = 0;
273 smapCount = 0;
274 diskAccessCount = 0;
275 queryCount = 0;
276 dataRead = 0;
277 this.bucketsRead = 0;
278 extra = new HashMap<String, IntegerHolder>();
279 extraObjects = new HashMap();
280 extraStats = new HashMap<String, StaticBin1D>();
281 }
282
283
284
285
286
287
288 public void putStats(String name, StaticBin1D stats){
289 this.extraStats.put(name, stats);
290 }
291
292 public StaticBin1D getStats(String name){
293 StaticBin1D r = extraStats.get(name);
294 if(r != null){
295 return r;
296 }else{
297 return new StaticBin1D();
298 }
299 }
300
301
302
303
304
305
306
307
308
309 public void addExtraStats(String name, double value){
310 StaticBin1D s = extraStats.get(name);
311 if(s == null){
312 s = new StaticBin1D();
313 extraStats.put(name, s);
314 }
315 s.add(value);
316 }
317
318
319
320
321
322
323 public void putObjects(String name, Object stats){
324 this.extraObjects.put(name, stats);
325 }
326
327 public String toStringSummary(){
328 return "Distances: " + distanceCount +
329 " Pivot vector count: " + smapCount +
330 " Disk access count: " + diskAccessCount +
331 " Query count: " + queryCount +
332 " Data read: " + dataRead +
333 " Buckets Read: " + this.bucketsRead + " extra: " + extra;
334 }
335
336
337
338 public long getBucketsRead() {
339 return bucketsRead;
340 }
341
342 public String toString(){
343 StringBuilder res = new StringBuilder( toStringSummary() );
344 for(Entry<String, StaticBin1D> e : extraStats.entrySet()){
345 res.append(StatsUtil.prettyPrintStats(e.getKey(), e.getValue()));
346 }
347 for(Entry<String, Object> e : extraObjects.entrySet()){
348 res.append(e.getKey());
349 res.append("\n");
350 res.append(e.getValue());
351 }
352 return res.toString();
353 }
354
355
356 }