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