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