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