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