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