gem5  v20.0.0.3
stattest.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 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 "pybind11/pybind11.h"
30 
31 #include <iomanip>
32 #include <iostream>
33 #include <string>
34 
35 #include "base/cprintf.hh"
36 #include "base/logging.hh"
37 #include "base/statistics.hh"
38 #include "base/types.hh"
39 #include "sim/core.hh"
40 #include "sim/init.hh"
41 #include "sim/stat_control.hh"
42 
43 namespace py = pybind11;
44 
45 // override the default main() code for this unittest
46 const char *m5MainCommands[] = {
47  "import m5.stattestmain",
48  "m5.stattestmain.main()",
49  0 // sentinel is required
50 };
51 
52 using namespace std;
53 using namespace Stats;
54 
55 double testfunc();
56 struct StatTest;
58 
59 
60 double
62 {
63  return 9.8;
64 }
65 
66 class TestClass {
67  public:
68  double operator()() { return 9.7; }
69 };
70 
71 struct StatTest
72 {
104 
107 
114 
115  void run();
116  void init();
117 };
118 
119 StatTest &
121 {
122  static StatTest st;
123  return st;
124 }
125 
126 void
128 {
129  EventQueue *q = getEventQueue(0);
130  curEventQueue(q);
131 
132  cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar));
133  cprintf("sizeof(Vector) = %d\n", sizeof(Vector));
134  cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution));
135 
136  s1
137  .name("Stat01")
138  .desc("this is statistic 1")
139  ;
140 
141  s2
142  .name("Stat02")
143  .desc("this is statistic 2")
144  .prereq(s11)
145  ;
146 
147  s3
148  .name("Stat03")
149  .desc("this is statistic 3")
150  .prereq(f5)
151  ;
152 
153  s4
154  .name("Stat04")
155  .desc("this is statistic 4")
156  .prereq(s11)
157  ;
158 
159  s5
160  .init(5)
161  .name("Stat05")
162  .desc("this is statistic 5")
163  .prereq(s11)
164  .subname(0, "foo1")
165  .subname(1, "foo2")
166  .subname(2, "foo3")
167  .subname(3, "foo4")
168  .subname(4, "foo5")
169  ;
170 
171  s6
172  .init(1, 100, 13)
173  .name("Stat06")
174  .desc("this is statistic 6")
175  .prereq(s11)
176  ;
177 
178  s7
179  .init(7)
180  .name("Stat07")
181  .desc("this is statistic 7")
182  .precision(1)
183  .flags(pdf | total)
184  .prereq(s11)
185  ;
186 
187  s8
188  .init(10)
189  .name("Stat08")
190  .desc("this is statistic 8")
191  .precision(2)
192  .prereq(s11)
193  .subname(4, "blarg")
194  ;
195 
196  s9
197  .name("Stat09")
198  .desc("this is statistic 9")
199  .precision(4)
200  .prereq(s11)
201  ;
202 
203  s10
204  .name("Stat10")
205  .desc("this is statistic 10")
206  .prereq(s11)
207  ;
208 
209  s12
210  .init(1, 100, 13)
211  .name("Stat12")
212  .desc("this is statistic 12")
213  ;
214 
215  s13
216  .init(4, 0, 99, 10)
217  .name("Stat13")
218  .desc("this is statistic 13")
219  ;
220 
221  s14
222  .init(9)
223  .name("Stat14")
224  .desc("this is statistic 14")
225  ;
226 
227  s15
228  .init(10)
229  .name("Stat15")
230  .desc("this is statistic 15")
231  ;
232 
233  s16
234  .init(2, 9)
235  .name("Stat16")
236  .desc("this is statistic 16")
237  .flags(total)
238  .subname(0, "sub0")
239  .subname(1, "sub1")
240  .ysubname(0, "y0")
241  .ysubname(1, "y1")
242  ;
243 
244  s17
245  .functor(testfunc)
246  .name("Stat17")
247  .desc("this is stat 17")
248  ;
249 
250  TestClass testclass;
251  s18
252  .functor(testclass)
253  .name("Stat18")
254  .desc("this is stat 18")
255  ;
256 
257  h01
258  .init(11)
259  .name("Histogram01")
260  .desc("this is histogram 1")
261  ;
262 
263  h02
264  .init(10)
265  .name("Histogram02")
266  .desc("this is histogram 2")
267  ;
268 
269  h03
270  .init(11)
271  .name("Histogram03")
272  .desc("this is histogram 3")
273  ;
274 
275  h04
276  .init(10)
277  .name("Histogram04")
278  .desc("this is histogram 4")
279  ;
280 
281  h05
282  .init(11)
283  .name("Histogram05")
284  .desc("this is histogram 5")
285  ;
286 
287  h06
288  .init(10)
289  .name("Histogram06")
290  .desc("this is histogram 6")
291  ;
292 
293  h07
294  .init(11)
295  .name("Histogram07")
296  .desc("this is histogram 7")
297  ;
298 
299  h08
300  .init(10)
301  .name("Histogram08")
302  .desc("this is histogram 8")
303  ;
304 
305  h09
306  .init(11)
307  .name("Histogram09")
308  .desc("this is histogram 9")
309  ;
310 
311  h10
312  .init(10)
313  .name("Histogram10")
314  .desc("this is histogram 10")
315  ;
316 
317  h11
318  .init(11)
319  .name("Histogram11")
320  .desc("this is histogram 11")
321  ;
322 
323  h12
324  .init(10)
325  .name("Histogram12")
326  .desc("this is histogram 12")
327  ;
328 
329  sh1
330  .init(0)
331  .name("SparseHistogram1")
332  .desc("this is sparse histogram 1")
333  ;
334 
335  f1
336  .name("Formula1")
337  .desc("this is formula 1")
338  .prereq(s11)
339  ;
340 
341  f2
342  .name("Formula2")
343  .desc("this is formula 2")
344  .prereq(s11)
345  .precision(1)
346  ;
347 
348  f3
349  .name("Formula3")
350  .desc("this is formula 3")
351  .prereq(s11)
352  .subname(0, "bar1")
353  .subname(1, "bar2")
354  .subname(2, "bar3")
355  .subname(3, "bar4")
356  .subname(4, "bar5")
357  ;
358 
359  f4
360  .name("Formula4")
361  .desc("this is formula 4")
362  ;
363 
364  s19
365  .init(2)
366  .name("Stat19")
367  .desc("this is statistic 19 for vector op testing")
368  .flags(total | nozero | nonan)
369  ;
370  s20
371  .init(2)
372  .name("Stat20")
373  .desc("this is statistic 20 for vector op testing")
374  .flags(total | nozero | nonan)
375  ;
376 
377  f6
378  .name("vector_op_test_formula")
379  .desc("The total stat should equal 1")
380  .flags(total |nozero |nonan)
381  ;
382 
383  f1 = s1 + s2;
384  f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
385  f3 = sum(s5) * s7;
386  f4 += constant(10.0);
387  f4 += s5[3];
388  f5 = constant(1);
389  f6 = s19/s20;
390 }
391 
392 void
394 {
395  s16[1][0] = 1;
396  s16[0][1] = 3;
397  s16[0][0] = 2;
398  s16[1][1] = 9;
399  s16[1][1] += 9;
400  s16[1][8] += 8;
401  s16[1][7] += 7;
402  s16[1][6] += 6;
403  s16[1][5] += 5;
404  s16[1][4] += 4;
405 
406  s11 = 1;
407  s3 = 9;
408  s8[3] = 9;
409  s15[0].sample(1234);
410  s15[1].sample(1234);
411  s15[2].sample(1234);
412  s15[3].sample(1234);
413  s15[4].sample(1234);
414  s15[5].sample(1234);
415  s15[6].sample(1234);
416  s15[7].sample(1234);
417  s15[8].sample(1234);
418  s15[9].sample(1234);
419 
420  s10.sample(1000000000);
421  curEventQueue()->setCurTick(curTick() + ULL(1000000));
422  s10.sample(100000);
423  s10.sample(100000);
424  s10.sample(100000);
425  s10.sample(100000);
426  s10.sample(100000);
427  s10.sample(100000);
428  s10.sample(100000);
429  s10.sample(100000);
430  s10.sample(100000);
431  s10.sample(100000);
432  s10.sample(100000);
433  s10.sample(100000);
434  s10.sample(100000);
435  s13[0].sample(12);
436  s13[1].sample(29);
437  s13[2].sample(12);
438  s13[3].sample(29);
439  s13[0].sample(42);
440  s13[1].sample(29);
441  s13[2].sample(42);
442  s13[3].sample(32);
443  s13[0].sample(52);
444  s13[1].sample(49);
445  s13[2].sample(42);
446  s13[3].sample(25);
447  s13[0].sample(32);
448  s13[1].sample(49);
449  s13[2].sample(22);
450  s13[3].sample(49);
451  s13[0].sample(62);
452  s13[1].sample(99);
453  s13[2].sample(72);
454  s13[3].sample(23);
455  s13[0].sample(52);
456  s13[1].sample(78);
457  s13[2].sample(69);
458  s13[3].sample(49);
459 
460  s14[0].sample(1234);
461  s14[1].sample(4134);
462  s14[4].sample(1213);
463  s14[3].sample(1124);
464  s14[2].sample(1243);
465  s14[7].sample(1244);
466  s14[4].sample(7234);
467  s14[2].sample(9234);
468  s14[3].sample(1764);
469  s14[7].sample(1564);
470  s14[3].sample(3234);
471  s14[1].sample(2234);
472  s14[5].sample(1234);
473  s14[2].sample(4334);
474  s14[2].sample(1234);
475  s14[4].sample(4334);
476  s14[6].sample(1234);
477  s14[8].sample(8734);
478  s14[1].sample(5234);
479  s14[3].sample(8234);
480  s14[7].sample(5234);
481  s14[4].sample(4434);
482  s14[3].sample(7234);
483  s14[2].sample(1934);
484  s14[1].sample(9234);
485  s14[5].sample(5634);
486  s14[3].sample(1264);
487  s14[7].sample(5223);
488  s14[0].sample(1234);
489  s14[0].sample(5434);
490  s14[3].sample(8634);
491  s14[1].sample(1234);
492 
493 
494  s15[0].sample(1234);
495  s15[1].sample(4134);
496  curEventQueue()->setCurTick(curTick() + ULL(1000000));
497  s15[4].sample(1213);
498  curEventQueue()->setCurTick(curTick() + ULL(1000000));
499  s15[3].sample(1124);
500  curEventQueue()->setCurTick(curTick() + ULL(1000000));
501  s15[2].sample(1243);
502  curEventQueue()->setCurTick(curTick() + ULL(1000000));
503  s15[7].sample(1244);
504  curEventQueue()->setCurTick(curTick() + ULL(1000000));
505  s15[4].sample(7234);
506  s15[2].sample(9234);
507  s15[3].sample(1764);
508  s15[7].sample(1564);
509  s15[3].sample(3234);
510  s15[1].sample(2234);
511  curEventQueue()->setCurTick(curTick() + ULL(1000000));
512  s15[5].sample(1234);
513  curEventQueue()->setCurTick(curTick() + ULL(1000000));
514  s15[9].sample(4334);
515  curEventQueue()->setCurTick(curTick() + ULL(1000000));
516  s15[2].sample(1234);
517  curEventQueue()->setCurTick(curTick() + ULL(1000000));
518  s15[4].sample(4334);
519  s15[6].sample(1234);
520  curEventQueue()->setCurTick(curTick() + ULL(1000000));
521  s15[8].sample(8734);
522  curEventQueue()->setCurTick(curTick() + ULL(1000000));
523  s15[1].sample(5234);
524  curEventQueue()->setCurTick(curTick() + ULL(1000000));
525  s15[3].sample(8234);
526  curEventQueue()->setCurTick(curTick() + ULL(1000000));
527  s15[7].sample(5234);
528  s15[4].sample(4434);
529  s15[3].sample(7234);
530  s15[2].sample(1934);
531  s15[1].sample(9234);
532  curEventQueue()->setCurTick(curTick() + ULL(1000000));
533  s15[5].sample(5634);
534  s15[3].sample(1264);
535  s15[7].sample(5223);
536  s15[0].sample(1234);
537  s15[0].sample(5434);
538  s15[3].sample(8634);
539  curEventQueue()->setCurTick(curTick() + ULL(1000000));
540  s15[1].sample(1234);
541 
542  s4 = curTick();
543 
544  s8[3] = 99999;
545 
546  s3 = 12;
547  s3++;
548  curEventQueue()->setCurTick(curTick() + 9);
549 
550  s1 = 9;
551  s1 += 9;
552  s1 -= 11;
553  s1++;
554  ++s1;
555  s1--;
556  --s1;
557 
558  s2 = 9;
559 
560  s5[0] += 1;
561  s5[1] += 2;
562  s5[2] += 3;
563  s5[3] += 4;
564  s5[4] += 5;
565 
566  s7[0] = 10;
567  s7[1] = 20;
568  s7[2] = 30;
569  s7[3] = 40;
570  s7[4] = 50;
571  s7[5] = 60;
572  s7[6] = 70;
573 
574  s6.sample(0);
575  s6.sample(1);
576  s6.sample(2);
577  s6.sample(3);
578  s6.sample(4);
579  s6.sample(5);
580  s6.sample(6);
581  s6.sample(7);
582  s6.sample(8);
583  s6.sample(9);
584 
585  s6.sample(10);
586  s6.sample(10);
587  s6.sample(10);
588  s6.sample(10);
589  s6.sample(10);
590  s6.sample(10);
591  s6.sample(10);
592  s6.sample(10);
593  s6.sample(11);
594  s6.sample(19);
595  s6.sample(20);
596  s6.sample(20);
597  s6.sample(21);
598  s6.sample(21);
599  s6.sample(31);
600  s6.sample(98);
601  s6.sample(99);
602  s6.sample(99);
603  s6.sample(99);
604 
605  s7[0] = 700;
606  s7[1] = 600;
607  s7[2] = 500;
608  s7[3] = 400;
609  s7[4] = 300;
610  s7[5] = 200;
611  s7[6] = 100;
612 
613  s9.sample(100);
614  s9.sample(100);
615  s9.sample(100);
616  s9.sample(100);
617  s9.sample(10);
618  s9.sample(10);
619  s9.sample(10);
620  s9.sample(10);
621  s9.sample(10);
622 
623  curEventQueue()->setCurTick(curTick() + 9);
624  s4 = curTick();
625  s6.sample(100);
626  s6.sample(100);
627  s6.sample(100);
628  s6.sample(101);
629  s6.sample(102);
630 
631  s12.sample(100);
632  for (int i = 0; i < 100; i++) {
633  h01.sample(i);
634  h02.sample(i);
635  }
636 
637  for (int i = -100; i < 100; i++) {
638  h03.sample(i);
639  h04.sample(i);
640  }
641 
642  for (int i = -100; i < 1000; i++) {
643  h05.sample(i);
644  h06.sample(i);
645  }
646 
647  for (int i = 100; i >= -1000; i--) {
648  h07.sample(i);
649  h08.sample(i);
650  }
651 
652  for (int i = 0; i <= 1023; i++) {
653  h09.sample(i);
654  h10.sample(i);
655  }
656 
657  for (int i = -1024; i <= 1023; i++) {
658  h11.sample(i);
659  h12.sample(i);
660  }
661 
662  for (int i = 0; i < 1000; i++) {
663  sh1.sample(random() % 10000);
664  }
665 
666  s19[0] = 1;
667  s19[1] = 100000;
668  s20[0] = 100000;
669  s20[1] = 1;
670 
671 }
672 
673 static void
674 stattest_init_pybind(py::module &m_internal)
675 {
676  py::module m = m_internal.def_submodule("stattest");
677 
678  m
679  .def("stattest_init", []() { __stattest().init(); })
680  .def("stattest_run", []() { __stattest().run(); })
681  ;
682 }
683 
684 static EmbeddedPyBind embed_("stattest", stattest_init_pybind);
Scalar s11
Definition: stattest.cc:83
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:51
Vector s19
Definition: stattest.cc:105
VectorAverageDeviation s15
Definition: stattest.cc:87
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
Definition: eventq.cc:60
Bitfield< 7 > i
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2521
Bitfield< 0 > m
Histogram h02
Definition: stattest.cc:92
Distribution s12
Definition: stattest.cc:84
const FlagsType nonan
Don&#39;t print if this is NAN.
Definition: info.hh:59
Scalar s1
Definition: stattest.cc:73
void setCurTick(Tick newVal)
Definition: eventq.hh:771
Scalar s4
Definition: stattest.cc:76
Vector2d s16
Definition: stattest.cc:88
Histogram h08
Definition: stattest.cc:98
Value s17
Definition: stattest.cc:89
Vector s20
Definition: stattest.cc:106
A vector of scalar stats.
Definition: statistics.hh:2547
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
A vector of distributions.
Definition: statistics.hh:2695
const char * m5MainCommands[]
Definition: stattest.cc:46
Vector s5
Definition: stattest.cc:77
Value s18
Definition: stattest.cc:90
Declaration of Statistics objects.
double operator()()
Definition: stattest.cc:68
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2505
This is a vector of AverageDeviation stats.
Definition: statistics.hh:2760
Calculates the mean and variance of all the samples.
Definition: statistics.hh:2655
Formula f3
Definition: stattest.cc:110
Formula f2
Definition: stattest.cc:109
Scalar s2
Definition: stattest.cc:74
Distribution s6
Definition: stattest.cc:78
VectorDistribution s13
Definition: stattest.cc:85
Histogram h09
Definition: stattest.cc:99
static void stattest_init_pybind(py::module &m_internal)
Definition: stattest.cc:674
Tick curTick()
The current simulated tick.
Definition: core.hh:44
AverageDeviation s10
Definition: stattest.cc:82
Bitfield< 18 > sum
Definition: registers.hh:610
Queue of events sorted in time order.
Definition: eventq.hh:613
Histogram h06
Definition: stattest.cc:96
Vector s7
Definition: stattest.cc:79
Histogram h04
Definition: stattest.cc:94
void run()
Definition: stattest.cc:393
Bitfield< 27 > q
A simple distribution stat.
Definition: statistics.hh:2589
static EmbeddedPyBind embed_("stattest", stattest_init_pybind)
EventQueue * curEventQueue()
Definition: eventq.hh:82
Histogram h05
Definition: stattest.cc:95
A simple histogram stat.
Definition: statistics.hh:2626
Temp constant(T val)
Definition: statistics.hh:3329
StandardDeviation s9
Definition: stattest.cc:81
Formula f6
Definition: stattest.cc:113
Calculates the per tick mean and variance of the samples.
Definition: statistics.hh:2675
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
VectorStandardDeviation s14
Definition: stattest.cc:86
#define ULL(N)
uint64_t constant
Definition: types.hh:48
Histogram h07
Definition: stattest.cc:97
Bitfield< 29, 28 > sh1
Histogram h10
Definition: stattest.cc:100
void init()
Definition: stattest.cc:127
Histogram h03
Definition: stattest.cc:93
const FlagsType total
Print the total.
Definition: info.hh:49
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3009
Average s3
Definition: stattest.cc:75
Formula f5
Definition: stattest.cc:112
Histogram h12
Definition: stattest.cc:102
Formula f4
Definition: stattest.cc:111
Histogram h01
Definition: stattest.cc:91
Bitfield< 31, 28 > st
double testfunc()
Definition: stattest.cc:61
Histogram h11
Definition: stattest.cc:101
AverageVector s8
Definition: stattest.cc:80
SparseHistogram sh1
Definition: stattest.cc:103
A vector of Average stats.
Definition: statistics.hh:2561
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2575
This is a vector of StandardDeviation stats.
Definition: statistics.hh:2730
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:57
StatTest & __stattest()
Definition: stattest.cc:120
Formula f1
Definition: stattest.cc:108
const FlagsType init
This Stat is Initialized.
Definition: info.hh:45
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152

Generated on Fri Jul 3 2020 15:53:08 for gem5 by doxygen 1.8.13