- change the FormatFlags into more general StatFlags
[gem5.git] / test / stattest.cc
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <iomanip>
30 #include <iostream>
31 #include <string>
32 #include <unistd.h>
33
34 #include "base/cprintf.hh"
35 #include "base/misc.hh"
36 #include "base/statistics.hh"
37 #include "sim/host.hh"
38
39 using namespace std;
40 using namespace Statistics;
41
42 Tick curTick = 0;
43 Tick ticksPerSecond = ULL(2000000000);
44
45 Scalar<> s1;
46 Scalar<> s2;
47 Average<> s3;
48 Scalar<Counter, MainBin> s4;
49 Vector<Counter, MainBin> s5;
50 Distribution<Counter, MainBin> s6;
51 Vector<> s7;
52 AverageVector<> s8;
53 StandardDeviation<> s9;
54 AverageDeviation<> s10;
55 Scalar<Counter> s11;
56 Distribution<> s12;
57 VectorDistribution<> s13;
58 VectorStandardDeviation<> s14;
59 VectorAverageDeviation<> s15;
60 Vector2d<> s16;
61
62 Formula f1;
63 Formula f2;
64 Formula f3;
65 Formula f4;
66 Formula f5;
67 Formula f6;
68
69 MainBin bin1("bin1");
70 MainBin bin2("bin2");
71
72 double
73 testfunc()
74 {
75 return 9.8;
76 }
77
78 class TestClass {
79 public:
80 double operator()() { return 9.7; }
81 };
82
83 char *progname = "";
84
85 void
86 usage()
87 {
88 panic("incorrect usage.\n"
89 "usage:\n"
90 "\t%s [-v]\n", progname);
91 }
92
93 int
94 main(int argc, char *argv[])
95 {
96 char c;
97 progname = argv[0];
98 PrintDescriptions = false;
99 while ((c = getopt(argc, argv, "v")) != -1) {
100 cprintf("c == %c\n", c);
101 switch (c) {
102 case 'v':
103 PrintDescriptions = true;
104 break;
105 default:
106 usage();
107 }
108 }
109
110 s5.init(5);
111 s6.init(1, 100, 13);
112 s7.init(7);
113 s8.init(10);
114 s12.init(1, 100, 13);
115 s13.init(4, 0, 99, 10);
116 s14.init(9);
117 s15.init(10);
118 s16.init(2, 9);
119
120 s1
121 .name("Stat01")
122 .desc("this is statistic 1")
123 ;
124
125 s2
126 .name("Stat02")
127 .desc("this is statistic 2")
128 .prereq(s11)
129 ;
130
131 s3
132 .name("Stat03")
133 .desc("this is statistic 3")
134 .prereq(s11)
135 ;
136
137 s4
138 .name("Stat04")
139 .desc("this is statistic 4")
140 .prereq(s11)
141 ;
142
143 s5
144 .name("Stat05")
145 .desc("this is statistic 5")
146 .prereq(s11)
147 .subname(0, "foo1")
148 .subname(1, "foo2")
149 .subname(2, "foo3")
150 .subname(3, "foo4")
151 .subname(4, "foo5")
152 ;
153
154 s6
155 .name("Stat06")
156 .desc("this is statistic 6")
157 .prereq(s11)
158 ;
159
160 s7
161 .name("Stat07")
162 .desc("this is statistic 7")
163 .precision(1)
164 .flags(pdf | total)
165 .prereq(s11)
166 ;
167
168 s8
169 .name("Stat08")
170 .desc("this is statistic 8")
171 .precision(2)
172 .prereq(s11)
173 .subname(4, "blarg")
174 ;
175
176 s9
177 .name("Stat09")
178 .desc("this is statistic 9")
179 .precision(4)
180 .prereq(s11)
181 ;
182
183 s10
184 .name("Stat10")
185 .desc("this is statistic 10")
186 .prereq(s11)
187 ;
188
189 s12
190 .name("Stat12")
191 .desc("this is statistic 12")
192 ;
193
194 s13
195 .name("Stat13")
196 .desc("this is statistic 13")
197 ;
198
199 s14
200 .name("Stat14")
201 .desc("this is statistic 14")
202 ;
203
204 s15
205 .name("Stat15")
206 .desc("this is statistic 15")
207 ;
208
209 s16
210 .name("Stat16")
211 .desc("this is statistic 16")
212 .flags(total)
213 .subname(0, "sub0")
214 .subname(1, "sub1")
215 ;
216
217 f1
218 .name("Formula1")
219 .desc("this is formula 1")
220 .prereq(s11)
221 ;
222
223 f2
224 .name("Formula2")
225 .desc("this is formula 2")
226 .prereq(s11)
227 .precision(1)
228 ;
229
230 f3
231 .name("Formula3")
232 .desc("this is formula 3")
233 .prereq(s11)
234 .subname(0, "bar1")
235 .subname(1, "bar2")
236 .subname(2, "bar3")
237 .subname(3, "bar4")
238 .subname(4, "bar5")
239 ;
240
241 f4
242 .name("Formula4")
243 .desc("this is formula 4")
244 ;
245
246 f5
247 .name("Formula5")
248 .desc("this is formula 5")
249 ;
250
251 f6
252 .name("Formula6")
253 .desc("this is formula 6")
254 ;
255
256 check();
257
258 bin1.activate();
259
260 f1 = s1 + s2;
261 f2 = (-s1) / (-s2) * -s3 + ULL(100) + s4;
262 f3 = sum(s5) * s7;
263 f4 = functor(testfunc);
264 TestClass testclass;
265 f5 = functor(testclass);
266 f6 += constant(10.0);
267 f6 += s5[3];
268
269 s16[1][0] = 1;
270 s16[0][1] = 3;
271 s16[0][0] = 2;
272 s16[1][1] = 9;
273 s16[1][1] += 9;
274 s16[1][8] += 8;
275 s16[1][7] += 7;
276 s16[1][6] += 6;
277 s16[1][5] += 5;
278 s16[1][4] += 4;
279
280 s11 = 1;
281 s3 = 9;
282 s8[3] = 9;
283 s15[0].sample(1234);
284 s15[1].sample(1234);
285 s15[2].sample(1234);
286 s15[3].sample(1234);
287 s15[4].sample(1234);
288 s15[5].sample(1234);
289 s15[6].sample(1234);
290 s15[7].sample(1234);
291 s15[8].sample(1234);
292 s15[9].sample(1234);
293
294 s10.sample(1000000000);
295 curTick += ULL(1000000);
296 s10.sample(100000);
297 s10.sample(100000);
298 s10.sample(100000);
299 s10.sample(100000);
300 s10.sample(100000);
301 s10.sample(100000);
302 s10.sample(100000);
303 s10.sample(100000);
304 s10.sample(100000);
305 s10.sample(100000);
306 s10.sample(100000);
307 s10.sample(100000);
308 s10.sample(100000);
309 s13[0].sample(12);
310 s13[1].sample(29);
311 s13[2].sample(12);
312 s13[3].sample(29);
313 s13[0].sample(42);
314 s13[1].sample(29);
315 s13[2].sample(42);
316 s13[3].sample(32);
317 s13[0].sample(52);
318 s13[1].sample(49);
319 s13[2].sample(42);
320 s13[3].sample(25);
321 s13[0].sample(32);
322 s13[1].sample(49);
323 s13[2].sample(22);
324 s13[3].sample(49);
325 s13[0].sample(62);
326 s13[1].sample(99);
327 s13[2].sample(72);
328 s13[3].sample(23);
329 s13[0].sample(52);
330 s13[1].sample(78);
331 s13[2].sample(69);
332 s13[3].sample(49);
333
334 s14[0].sample(1234);
335 s14[1].sample(4134);
336 s14[4].sample(1213);
337 s14[3].sample(1124);
338 s14[2].sample(1243);
339 s14[7].sample(1244);
340 s14[4].sample(7234);
341 s14[2].sample(9234);
342 s14[3].sample(1764);
343 s14[7].sample(1564);
344 s14[3].sample(3234);
345 s14[1].sample(2234);
346 s14[5].sample(1234);
347 s14[2].sample(4334);
348 s14[2].sample(1234);
349 s14[4].sample(4334);
350 s14[6].sample(1234);
351 s14[8].sample(8734);
352 s14[1].sample(5234);
353 s14[3].sample(8234);
354 s14[7].sample(5234);
355 s14[4].sample(4434);
356 s14[3].sample(7234);
357 s14[2].sample(1934);
358 s14[1].sample(9234);
359 s14[5].sample(5634);
360 s14[3].sample(1264);
361 s14[7].sample(5223);
362 s14[0].sample(1234);
363 s14[0].sample(5434);
364 s14[3].sample(8634);
365 s14[1].sample(1234);
366
367
368 s15[0].sample(1234);
369 s15[1].sample(4134);
370 curTick += ULL(1000000);
371 s15[4].sample(1213);
372 curTick += ULL(1000000);
373 s15[3].sample(1124);
374 curTick += ULL(1000000);
375 s15[2].sample(1243);
376 curTick += ULL(1000000);
377 s15[7].sample(1244);
378 curTick += ULL(1000000);
379 s15[4].sample(7234);
380 s15[2].sample(9234);
381 s15[3].sample(1764);
382 s15[7].sample(1564);
383 s15[3].sample(3234);
384 s15[1].sample(2234);
385 curTick += ULL(1000000);
386 s15[5].sample(1234);
387 curTick += ULL(1000000);
388 s15[9].sample(4334);
389 curTick += ULL(1000000);
390 s15[2].sample(1234);
391 curTick += ULL(1000000);
392 s15[4].sample(4334);
393 s15[6].sample(1234);
394 curTick += ULL(1000000);
395 s15[8].sample(8734);
396 curTick += ULL(1000000);
397 s15[1].sample(5234);
398 curTick += ULL(1000000);
399 s15[3].sample(8234);
400 curTick += ULL(1000000);
401 s15[7].sample(5234);
402 s15[4].sample(4434);
403 s15[3].sample(7234);
404 s15[2].sample(1934);
405 s15[1].sample(9234);
406 curTick += ULL(1000000);
407 s15[5].sample(5634);
408 s15[3].sample(1264);
409 s15[7].sample(5223);
410 s15[0].sample(1234);
411 s15[0].sample(5434);
412 s15[3].sample(8634);
413 curTick += ULL(1000000);
414 s15[1].sample(1234);
415
416 s4 = curTick;
417
418 s8[3] = 99999;
419
420 s3 = 12;
421 s3++;
422 curTick += 9;
423
424 s1 = 9;
425 s1 += 9;
426 s1 -= 11;
427 s1++;
428 ++s1;
429 s1--;
430 --s1;
431
432 s2 = 9;
433
434 s5[0] += 1;
435 s5[1] += 2;
436 s5[2] += 3;
437 s5[3] += 4;
438 s5[4] += 5;
439
440 s7[0] = 10;
441 s7[1] = 20;
442 s7[2] = 30;
443 s7[3] = 40;
444 s7[4] = 50;
445 s7[5] = 60;
446 s7[6] = 70;
447
448 s6.sample(0);
449 s6.sample(1);
450 s6.sample(2);
451 s6.sample(3);
452 s6.sample(4);
453 s6.sample(5);
454 s6.sample(6);
455 s6.sample(7);
456 s6.sample(8);
457 s6.sample(9);
458
459 bin2.activate();
460 s6.sample(10);
461 s6.sample(10);
462 s6.sample(10);
463 s6.sample(10);
464 s6.sample(10);
465 s6.sample(10);
466 s6.sample(10);
467 s6.sample(10);
468 s6.sample(11);
469 s6.sample(19);
470 s6.sample(20);
471 s6.sample(20);
472 s6.sample(21);
473 s6.sample(21);
474 s6.sample(31);
475 s6.sample(98);
476 s6.sample(99);
477 s6.sample(99);
478 s6.sample(99);
479
480 s9.sample(100);
481 s9.sample(100);
482 s9.sample(100);
483 s9.sample(100);
484 s9.sample(10);
485 s9.sample(10);
486 s9.sample(10);
487 s9.sample(10);
488 s9.sample(10);
489
490 curTick += 9;
491 s4 = curTick;
492 s6.sample(100);
493 s6.sample(100);
494 s6.sample(100);
495 s6.sample(101);
496 s6.sample(102);
497
498 s12.sample(100);
499
500 bin1.activate();
501 cout << "dump 1" << endl;
502 dump(cout);
503 cout << endl << endl;
504
505 bin2.activate();
506 cout << "dump 2" << endl;
507 dump(cout);
508 cout << endl << endl;
509
510 cout << "dump 3" << endl;
511 reset();
512 dump(cout);
513 cout << endl << endl;
514
515 return 0;
516 }