d0b6916bb5ec4b00a80825113b87508dcb8e8cfa
[gem5.git] / test / stattest.cc
1 /*
2 * Copyright (c) 2003-2004 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 <fstream>
32 #include <string>
33 #include <unistd.h>
34
35 #include "base/cprintf.hh"
36 #include "base/misc.hh"
37 #include "base/statistics.hh"
38 #include "base/stats/text.hh"
39 #include "base/stats/python.hh"
40 #include "base/stats/mysql.hh"
41 #include "sim/host.hh"
42
43 using namespace std;
44 using namespace Stats;
45
46 Tick curTick = 0;
47 Tick ticksPerSecond = ULL(2000000000);
48
49 Scalar<> s1;
50 Scalar<> s2;
51 Average<> s3;
52 Scalar<MainBin> s4;
53 Vector<MainBin> s5;
54 Distribution<MainBin> s6;
55 Vector<MainBin> s7;
56 AverageVector<> s8;
57 StandardDeviation<> s9;
58 AverageDeviation<> s10;
59 Scalar<> s11;
60 Distribution<> s12;
61 VectorDistribution<> s13;
62 VectorStandardDeviation<> s14;
63 VectorAverageDeviation<> s15;
64 Vector2d<> s16;
65
66 Formula f1;
67 Formula f2;
68 Formula f3;
69 Value f4;
70 Value f5;
71 Formula f6;
72 Formula f7;
73
74 MainBin bin1("bin1");
75 MainBin bin2("bin2");
76
77 ostream *outputStream = &cout;
78
79 double
80 testfunc()
81 {
82 return 9.8;
83 }
84
85 class TestClass {
86 public:
87 double operator()() { return 9.7; }
88 };
89
90 char *progname = "";
91
92 void
93 usage()
94 {
95 panic("incorrect usage.\n"
96 "usage:\n"
97 "\t%s [-p <python file>] [-t [-c] [-d]]\n", progname);
98 }
99
100 int
101 main(int argc, char *argv[])
102 {
103 bool descriptions = false;
104 bool compat = false;
105 bool text = false;
106 string pyfile;
107 string mysql_name;
108 string mysql_host;
109 string mysql_user = "binkertn";
110 string mysql_passwd;
111
112 char c;
113 progname = argv[0];
114 while ((c = getopt(argc, argv, "cdh:P:p:s:tu:")) != -1) {
115 switch (c) {
116 case 'c':
117 compat = true;
118 break;
119 case 'd':
120 descriptions = true;
121 break;
122 case 'h':
123 mysql_host = optarg;
124 break;
125 case 'P':
126 mysql_passwd = optarg;
127 break;
128 case 'p':
129 pyfile = optarg;
130 break;
131 case 's':
132 mysql_name = optarg;
133 break;
134 case 't':
135 text = true;
136 break;
137 case 'u':
138 mysql_user = optarg;
139 break;
140 default:
141 usage();
142 }
143 }
144
145 if (!text && (compat || descriptions))
146 usage();
147
148 s5.init(5);
149 s6.init(1, 100, 13);
150 s7.init(7);
151 s8.init(10);
152 s12.init(1, 100, 13);
153 s13.init(4, 0, 99, 10);
154 s14.init(9);
155 s15.init(10);
156 s16.init(2, 9);
157
158 s1
159 .name("Stat01")
160 .desc("this is statistic 1")
161 ;
162
163 s2
164 .name("Stat02")
165 .desc("this is statistic 2")
166 .prereq(s11)
167 ;
168
169 s3
170 .name("Stat03")
171 .desc("this is statistic 3")
172 .prereq(f7)
173 ;
174
175 s4
176 .name("Stat04")
177 .desc("this is statistic 4")
178 .prereq(s11)
179 ;
180
181 s5
182 .name("Stat05")
183 .desc("this is statistic 5")
184 .prereq(s11)
185 .subname(0, "foo1")
186 .subname(1, "foo2")
187 .subname(2, "foo3")
188 .subname(3, "foo4")
189 .subname(4, "foo5")
190 ;
191
192 s6
193 .name("Stat06")
194 .desc("this is statistic 6")
195 .prereq(s11)
196 ;
197
198 s7
199 .name("Stat07")
200 .desc("this is statistic 7")
201 .precision(1)
202 .flags(pdf | total)
203 .prereq(s11)
204 ;
205
206 s8
207 .name("Stat08")
208 .desc("this is statistic 8")
209 .precision(2)
210 .prereq(s11)
211 .subname(4, "blarg")
212 ;
213
214 s9
215 .name("Stat09")
216 .desc("this is statistic 9")
217 .precision(4)
218 .prereq(s11)
219 ;
220
221 s10
222 .name("Stat10")
223 .desc("this is statistic 10")
224 .prereq(s11)
225 ;
226
227 s12
228 .name("Stat12")
229 .desc("this is statistic 12")
230 ;
231
232 s13
233 .name("Stat13")
234 .desc("this is statistic 13")
235 ;
236
237 s14
238 .name("Stat14")
239 .desc("this is statistic 14")
240 ;
241
242 s15
243 .name("Stat15")
244 .desc("this is statistic 15")
245 ;
246
247 s16
248 .name("Stat16")
249 .desc("this is statistic 16")
250 .flags(total)
251 .subname(0, "sub0")
252 .subname(1, "sub1")
253 .ysubname(0, "y0")
254 .ysubname(1, "y1")
255 ;
256
257 f1
258 .name("Formula1")
259 .desc("this is formula 1")
260 .prereq(s11)
261 ;
262
263 f2
264 .name("Formula2")
265 .desc("this is formula 2")
266 .prereq(s11)
267 .precision(1)
268 ;
269
270 f3
271 .name("Formula3")
272 .desc("this is formula 3")
273 .prereq(s11)
274 .subname(0, "bar1")
275 .subname(1, "bar2")
276 .subname(2, "bar3")
277 .subname(3, "bar4")
278 .subname(4, "bar5")
279 ;
280
281 f4
282 .functor(testfunc)
283 .name("Formula4")
284 .desc("this is formula 4")
285 ;
286
287 TestClass testclass;
288 f5
289 .functor(testclass)
290 .name("Formula5")
291 .desc("this is formula 5")
292 ;
293
294 f6
295 .name("Formula6")
296 .desc("this is formula 6")
297 ;
298
299 f1 = s1 + s2;
300 f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
301 f3 = sum(s5) * s7;
302 f6 += constant(10.0);
303 f6 += s5[3];
304 f7 = constant(1);
305
306 check();
307 reset();
308
309 bin1.activate();
310
311 s16[1][0] = 1;
312 s16[0][1] = 3;
313 s16[0][0] = 2;
314 s16[1][1] = 9;
315 s16[1][1] += 9;
316 s16[1][8] += 8;
317 s16[1][7] += 7;
318 s16[1][6] += 6;
319 s16[1][5] += 5;
320 s16[1][4] += 4;
321
322 s11 = 1;
323 s3 = 9;
324 s8[3] = 9;
325 s15[0].sample(1234);
326 s15[1].sample(1234);
327 s15[2].sample(1234);
328 s15[3].sample(1234);
329 s15[4].sample(1234);
330 s15[5].sample(1234);
331 s15[6].sample(1234);
332 s15[7].sample(1234);
333 s15[8].sample(1234);
334 s15[9].sample(1234);
335
336 s10.sample(1000000000);
337 curTick += ULL(1000000);
338 s10.sample(100000);
339 s10.sample(100000);
340 s10.sample(100000);
341 s10.sample(100000);
342 s10.sample(100000);
343 s10.sample(100000);
344 s10.sample(100000);
345 s10.sample(100000);
346 s10.sample(100000);
347 s10.sample(100000);
348 s10.sample(100000);
349 s10.sample(100000);
350 s10.sample(100000);
351 s13[0].sample(12);
352 s13[1].sample(29);
353 s13[2].sample(12);
354 s13[3].sample(29);
355 s13[0].sample(42);
356 s13[1].sample(29);
357 s13[2].sample(42);
358 s13[3].sample(32);
359 s13[0].sample(52);
360 s13[1].sample(49);
361 s13[2].sample(42);
362 s13[3].sample(25);
363 s13[0].sample(32);
364 s13[1].sample(49);
365 s13[2].sample(22);
366 s13[3].sample(49);
367 s13[0].sample(62);
368 s13[1].sample(99);
369 s13[2].sample(72);
370 s13[3].sample(23);
371 s13[0].sample(52);
372 s13[1].sample(78);
373 s13[2].sample(69);
374 s13[3].sample(49);
375
376 s14[0].sample(1234);
377 s14[1].sample(4134);
378 s14[4].sample(1213);
379 s14[3].sample(1124);
380 s14[2].sample(1243);
381 s14[7].sample(1244);
382 s14[4].sample(7234);
383 s14[2].sample(9234);
384 s14[3].sample(1764);
385 s14[7].sample(1564);
386 s14[3].sample(3234);
387 s14[1].sample(2234);
388 s14[5].sample(1234);
389 s14[2].sample(4334);
390 s14[2].sample(1234);
391 s14[4].sample(4334);
392 s14[6].sample(1234);
393 s14[8].sample(8734);
394 s14[1].sample(5234);
395 s14[3].sample(8234);
396 s14[7].sample(5234);
397 s14[4].sample(4434);
398 s14[3].sample(7234);
399 s14[2].sample(1934);
400 s14[1].sample(9234);
401 s14[5].sample(5634);
402 s14[3].sample(1264);
403 s14[7].sample(5223);
404 s14[0].sample(1234);
405 s14[0].sample(5434);
406 s14[3].sample(8634);
407 s14[1].sample(1234);
408
409
410 s15[0].sample(1234);
411 s15[1].sample(4134);
412 curTick += ULL(1000000);
413 s15[4].sample(1213);
414 curTick += ULL(1000000);
415 s15[3].sample(1124);
416 curTick += ULL(1000000);
417 s15[2].sample(1243);
418 curTick += ULL(1000000);
419 s15[7].sample(1244);
420 curTick += ULL(1000000);
421 s15[4].sample(7234);
422 s15[2].sample(9234);
423 s15[3].sample(1764);
424 s15[7].sample(1564);
425 s15[3].sample(3234);
426 s15[1].sample(2234);
427 curTick += ULL(1000000);
428 s15[5].sample(1234);
429 curTick += ULL(1000000);
430 s15[9].sample(4334);
431 curTick += ULL(1000000);
432 s15[2].sample(1234);
433 curTick += ULL(1000000);
434 s15[4].sample(4334);
435 s15[6].sample(1234);
436 curTick += ULL(1000000);
437 s15[8].sample(8734);
438 curTick += ULL(1000000);
439 s15[1].sample(5234);
440 curTick += ULL(1000000);
441 s15[3].sample(8234);
442 curTick += ULL(1000000);
443 s15[7].sample(5234);
444 s15[4].sample(4434);
445 s15[3].sample(7234);
446 s15[2].sample(1934);
447 s15[1].sample(9234);
448 curTick += ULL(1000000);
449 s15[5].sample(5634);
450 s15[3].sample(1264);
451 s15[7].sample(5223);
452 s15[0].sample(1234);
453 s15[0].sample(5434);
454 s15[3].sample(8634);
455 curTick += ULL(1000000);
456 s15[1].sample(1234);
457
458 s4 = curTick;
459
460 s8[3] = 99999;
461
462 s3 = 12;
463 s3++;
464 curTick += 9;
465
466 s1 = 9;
467 s1 += 9;
468 s1 -= 11;
469 s1++;
470 ++s1;
471 s1--;
472 --s1;
473
474 s2 = 9;
475
476 s5[0] += 1;
477 s5[1] += 2;
478 s5[2] += 3;
479 s5[3] += 4;
480 s5[4] += 5;
481
482 s7[0] = 10;
483 s7[1] = 20;
484 s7[2] = 30;
485 s7[3] = 40;
486 s7[4] = 50;
487 s7[5] = 60;
488 s7[6] = 70;
489
490 s6.sample(0);
491 s6.sample(1);
492 s6.sample(2);
493 s6.sample(3);
494 s6.sample(4);
495 s6.sample(5);
496 s6.sample(6);
497 s6.sample(7);
498 s6.sample(8);
499 s6.sample(9);
500
501 bin2.activate();
502 s6.sample(10);
503 s6.sample(10);
504 s6.sample(10);
505 s6.sample(10);
506 s6.sample(10);
507 s6.sample(10);
508 s6.sample(10);
509 s6.sample(10);
510 s6.sample(11);
511 s6.sample(19);
512 s6.sample(20);
513 s6.sample(20);
514 s6.sample(21);
515 s6.sample(21);
516 s6.sample(31);
517 s6.sample(98);
518 s6.sample(99);
519 s6.sample(99);
520 s6.sample(99);
521
522 s7[0] = 700;
523 s7[1] = 600;
524 s7[2] = 500;
525 s7[3] = 400;
526 s7[4] = 300;
527 s7[5] = 200;
528 s7[6] = 100;
529
530 s9.sample(100);
531 s9.sample(100);
532 s9.sample(100);
533 s9.sample(100);
534 s9.sample(10);
535 s9.sample(10);
536 s9.sample(10);
537 s9.sample(10);
538 s9.sample(10);
539
540 curTick += 9;
541 s4 = curTick;
542 s6.sample(100);
543 s6.sample(100);
544 s6.sample(100);
545 s6.sample(101);
546 s6.sample(102);
547
548 s12.sample(100);
549
550 if (text) {
551 Text out(cout);
552 out.descriptions = descriptions;
553 out.compat = compat;
554 out();
555 }
556
557 if (!pyfile.empty()) {
558 Python out(pyfile);
559 out();
560 }
561
562 if (!mysql_name.empty()) {
563 MySql out;
564 out.connect(mysql_host, mysql_user, mysql_passwd, "m5stats",
565 mysql_name, "test");
566 out();
567 }
568
569 return 0;
570 }