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