stattest.cc revision 8229:78bf55f23338
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" 37#include "base/cprintf.hh" 38#include "base/misc.hh" 39#include "base/statistics.hh" 40#include "base/types.hh" 41#include "sim/core.hh" 42#include "sim/stat_control.hh" 43 44using namespace std; 45using namespace Stats; 46 47double 48testfunc() 49{ 50 return 9.8; 51} 52 53class TestClass { 54 public: 55 double operator()() { return 9.7; } 56}; 57 58const char *progname = ""; 59 60void 61usage() 62{ 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 119 Scalar s1; 120 Scalar s2; 121 Average s3; 122 Scalar s4; 123 Vector s5; 124 Distribution s6; 125 Vector s7; 126 AverageVector s8; 127 StandardDeviation s9; 128 AverageDeviation s10; 129 Scalar s11; 130 Distribution s12; 131 VectorDistribution s13; 132 VectorStandardDeviation s14; 133 VectorAverageDeviation s15; 134 Vector2d s16; 135 Value s17; 136 Value s18; 137 Histogram h01; 138 Histogram h02; 139 Histogram h03; 140 Histogram h04; 141 Histogram h05; 142 Histogram h06; 143 Histogram h07; 144 Histogram h08; 145 Histogram h09; 146 Histogram h10; 147 Histogram h11; 148 Histogram h12; 149 150 Formula f1; 151 Formula f2; 152 Formula f3; 153 Formula f4; 154 Formula f5; 155 156 cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar)); 157 cprintf("sizeof(Vector) = %d\n", sizeof(Vector)); 158 cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution)); 159 160 s1 161 .name("Stat01") 162 .desc("this is statistic 1") 163 ; 164 165 s2 166 .name("Stat02") 167 .desc("this is statistic 2") 168 .prereq(s11) 169 ; 170 171 s3 172 .name("Stat03") 173 .desc("this is statistic 3") 174 .prereq(f5) 175 ; 176 177 s4 178 .name("Stat04") 179 .desc("this is statistic 4") 180 .prereq(s11) 181 ; 182 183 s5 184 .init(5) 185 .name("Stat05") 186 .desc("this is statistic 5") 187 .prereq(s11) 188 .subname(0, "foo1") 189 .subname(1, "foo2") 190 .subname(2, "foo3") 191 .subname(3, "foo4") 192 .subname(4, "foo5") 193 ; 194 195 s6 196 .init(1, 100, 13) 197 .name("Stat06") 198 .desc("this is statistic 6") 199 .prereq(s11) 200 ; 201 202 s7 203 .init(7) 204 .name("Stat07") 205 .desc("this is statistic 7") 206 .precision(1) 207 .flags(pdf | total) 208 .prereq(s11) 209 ; 210 211 s8 212 .init(10) 213 .name("Stat08") 214 .desc("this is statistic 8") 215 .precision(2) 216 .prereq(s11) 217 .subname(4, "blarg") 218 ; 219 220 s9 221 .name("Stat09") 222 .desc("this is statistic 9") 223 .precision(4) 224 .prereq(s11) 225 ; 226 227 s10 228 .name("Stat10") 229 .desc("this is statistic 10") 230 .prereq(s11) 231 ; 232 233 s12 234 .init(1, 100, 13) 235 .name("Stat12") 236 .desc("this is statistic 12") 237 ; 238 239 s13 240 .init(4, 0, 99, 10) 241 .name("Stat13") 242 .desc("this is statistic 13") 243 ; 244 245 s14 246 .init(9) 247 .name("Stat14") 248 .desc("this is statistic 14") 249 ; 250 251 s15 252 .init(10) 253 .name("Stat15") 254 .desc("this is statistic 15") 255 ; 256 257 s16 258 .init(2, 9) 259 .name("Stat16") 260 .desc("this is statistic 16") 261 .flags(total) 262 .subname(0, "sub0") 263 .subname(1, "sub1") 264 .ysubname(0, "y0") 265 .ysubname(1, "y1") 266 ; 267 268 s17 269 .functor(testfunc) 270 .name("Stat17") 271 .desc("this is stat 17") 272 ; 273 274 TestClass testclass; 275 s18 276 .functor(testclass) 277 .name("Stat18") 278 .desc("this is stat 18") 279 ; 280 281 h01 282 .init(11) 283 .name("Histogram01") 284 .desc("this is histogram 1") 285 ; 286 287 h02 288 .init(10) 289 .name("Histogram02") 290 .desc("this is histogram 2") 291 ; 292 293 h03 294 .init(11) 295 .name("Histogram03") 296 .desc("this is histogram 3") 297 ; 298 299 h04 300 .init(10) 301 .name("Histogram04") 302 .desc("this is histogram 4") 303 ; 304 305 h05 306 .init(11) 307 .name("Histogram05") 308 .desc("this is histogram 5") 309 ; 310 311 h06 312 .init(10) 313 .name("Histogram06") 314 .desc("this is histogram 6") 315 ; 316 317 h07 318 .init(11) 319 .name("Histogram07") 320 .desc("this is histogram 7") 321 ; 322 323 h08 324 .init(10) 325 .name("Histogram08") 326 .desc("this is histogram 8") 327 ; 328 329 h09 330 .init(11) 331 .name("Histogram09") 332 .desc("this is histogram 9") 333 ; 334 335 h10 336 .init(10) 337 .name("Histogram10") 338 .desc("this is histogram 10") 339 ; 340 341 h11 342 .init(11) 343 .name("Histogram11") 344 .desc("this is histogram 11") 345 ; 346 347 h12 348 .init(10) 349 .name("Histogram12") 350 .desc("this is histogram 12") 351 ; 352 353 f1 354 .name("Formula1") 355 .desc("this is formula 1") 356 .prereq(s11) 357 ; 358 359 f2 360 .name("Formula2") 361 .desc("this is formula 2") 362 .prereq(s11) 363 .precision(1) 364 ; 365 366 f3 367 .name("Formula3") 368 .desc("this is formula 3") 369 .prereq(s11) 370 .subname(0, "bar1") 371 .subname(1, "bar2") 372 .subname(2, "bar3") 373 .subname(3, "bar4") 374 .subname(4, "bar5") 375 ; 376 377 f4 378 .name("Formula4") 379 .desc("this is formula 4") 380 ; 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 390 enable(); 391 reset(); 392 393 s16[1][0] = 1; 394 s16[0][1] = 3; 395 s16[0][0] = 2; 396 s16[1][1] = 9; 397 s16[1][1] += 9; 398 s16[1][8] += 8; 399 s16[1][7] += 7; 400 s16[1][6] += 6; 401 s16[1][5] += 5; 402 s16[1][4] += 4; 403 404 s11 = 1; 405 s3 = 9; 406 s8[3] = 9; 407 s15[0].sample(1234); 408 s15[1].sample(1234); 409 s15[2].sample(1234); 410 s15[3].sample(1234); 411 s15[4].sample(1234); 412 s15[5].sample(1234); 413 s15[6].sample(1234); 414 s15[7].sample(1234); 415 s15[8].sample(1234); 416 s15[9].sample(1234); 417 418 s10.sample(1000000000); 419 curTick(curTick() + ULL(1000000)); 420 s10.sample(100000); 421 s10.sample(100000); 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 s13[0].sample(12); 434 s13[1].sample(29); 435 s13[2].sample(12); 436 s13[3].sample(29); 437 s13[0].sample(42); 438 s13[1].sample(29); 439 s13[2].sample(42); 440 s13[3].sample(32); 441 s13[0].sample(52); 442 s13[1].sample(49); 443 s13[2].sample(42); 444 s13[3].sample(25); 445 s13[0].sample(32); 446 s13[1].sample(49); 447 s13[2].sample(22); 448 s13[3].sample(49); 449 s13[0].sample(62); 450 s13[1].sample(99); 451 s13[2].sample(72); 452 s13[3].sample(23); 453 s13[0].sample(52); 454 s13[1].sample(78); 455 s13[2].sample(69); 456 s13[3].sample(49); 457 458 s14[0].sample(1234); 459 s14[1].sample(4134); 460 s14[4].sample(1213); 461 s14[3].sample(1124); 462 s14[2].sample(1243); 463 s14[7].sample(1244); 464 s14[4].sample(7234); 465 s14[2].sample(9234); 466 s14[3].sample(1764); 467 s14[7].sample(1564); 468 s14[3].sample(3234); 469 s14[1].sample(2234); 470 s14[5].sample(1234); 471 s14[2].sample(4334); 472 s14[2].sample(1234); 473 s14[4].sample(4334); 474 s14[6].sample(1234); 475 s14[8].sample(8734); 476 s14[1].sample(5234); 477 s14[3].sample(8234); 478 s14[7].sample(5234); 479 s14[4].sample(4434); 480 s14[3].sample(7234); 481 s14[2].sample(1934); 482 s14[1].sample(9234); 483 s14[5].sample(5634); 484 s14[3].sample(1264); 485 s14[7].sample(5223); 486 s14[0].sample(1234); 487 s14[0].sample(5434); 488 s14[3].sample(8634); 489 s14[1].sample(1234); 490 491 492 s15[0].sample(1234); 493 s15[1].sample(4134); 494 curTick(curTick() + ULL(1000000)); 495 s15[4].sample(1213); 496 curTick(curTick() + ULL(1000000)); 497 s15[3].sample(1124); 498 curTick(curTick() + ULL(1000000)); 499 s15[2].sample(1243); 500 curTick(curTick() + ULL(1000000)); 501 s15[7].sample(1244); 502 curTick(curTick() + ULL(1000000)); 503 s15[4].sample(7234); 504 s15[2].sample(9234); 505 s15[3].sample(1764); 506 s15[7].sample(1564); 507 s15[3].sample(3234); 508 s15[1].sample(2234); 509 curTick(curTick() + ULL(1000000)); 510 s15[5].sample(1234); 511 curTick(curTick() + ULL(1000000)); 512 s15[9].sample(4334); 513 curTick(curTick() + ULL(1000000)); 514 s15[2].sample(1234); 515 curTick(curTick() + ULL(1000000)); 516 s15[4].sample(4334); 517 s15[6].sample(1234); 518 curTick(curTick() + ULL(1000000)); 519 s15[8].sample(8734); 520 curTick(curTick() + ULL(1000000)); 521 s15[1].sample(5234); 522 curTick(curTick() + ULL(1000000)); 523 s15[3].sample(8234); 524 curTick(curTick() + ULL(1000000)); 525 s15[7].sample(5234); 526 s15[4].sample(4434); 527 s15[3].sample(7234); 528 s15[2].sample(1934); 529 s15[1].sample(9234); 530 curTick(curTick() + ULL(1000000)); 531 s15[5].sample(5634); 532 s15[3].sample(1264); 533 s15[7].sample(5223); 534 s15[0].sample(1234); 535 s15[0].sample(5434); 536 s15[3].sample(8634); 537 curTick(curTick() + ULL(1000000)); 538 s15[1].sample(1234); 539 540 s4 = curTick(); 541 542 s8[3] = 99999; 543 544 s3 = 12; 545 s3++; 546 curTick(curTick() + 9); 547 548 s1 = 9; 549 s1 += 9; 550 s1 -= 11; 551 s1++; 552 ++s1; 553 s1--; 554 --s1; 555 556 s2 = 9; 557 558 s5[0] += 1; 559 s5[1] += 2; 560 s5[2] += 3; 561 s5[3] += 4; 562 s5[4] += 5; 563 564 s7[0] = 10; 565 s7[1] = 20; 566 s7[2] = 30; 567 s7[3] = 40; 568 s7[4] = 50; 569 s7[5] = 60; 570 s7[6] = 70; 571 572 s6.sample(0); 573 s6.sample(1); 574 s6.sample(2); 575 s6.sample(3); 576 s6.sample(4); 577 s6.sample(5); 578 s6.sample(6); 579 s6.sample(7); 580 s6.sample(8); 581 s6.sample(9); 582 583 s6.sample(10); 584 s6.sample(10); 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(11); 592 s6.sample(19); 593 s6.sample(20); 594 s6.sample(20); 595 s6.sample(21); 596 s6.sample(21); 597 s6.sample(31); 598 s6.sample(98); 599 s6.sample(99); 600 s6.sample(99); 601 s6.sample(99); 602 603 s7[0] = 700; 604 s7[1] = 600; 605 s7[2] = 500; 606 s7[3] = 400; 607 s7[4] = 300; 608 s7[5] = 200; 609 s7[6] = 100; 610 611 s9.sample(100); 612 s9.sample(100); 613 s9.sample(100); 614 s9.sample(100); 615 s9.sample(10); 616 s9.sample(10); 617 s9.sample(10); 618 s9.sample(10); 619 s9.sample(10); 620 621 curTick(curTick() + 9); 622 s4 = curTick(); 623 s6.sample(100); 624 s6.sample(100); 625 s6.sample(100); 626 s6.sample(101); 627 s6.sample(102); 628 629 s12.sample(100); 630 for (int i = 0; i < 100; i++) { 631 h01.sample(i); 632 h02.sample(i); 633 } 634 635 for (int i = -100; i < 100; i++) { 636 h03.sample(i); 637 h04.sample(i); 638 } 639 640 for (int i = -100; i < 1000; i++) { 641 h05.sample(i); 642 h06.sample(i); 643 } 644 645 for (int i = 100; i >= -1000; i--) { 646 h07.sample(i); 647 h08.sample(i); 648 } 649 650 for (int i = 0; i <= 1023; i++) { 651 h09.sample(i); 652 h10.sample(i); 653 } 654 655 for (int i = -1024; i <= 1023; i++) { 656 h11.sample(i); 657 h12.sample(i); 658 } 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; 678} 679