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