stats.py revision 1301
1#!/usr/bin/env python 2from __future__ import division 3import re, sys 4 5def usage(): 6 print '''\ 7Usage: %s [-E] [-F] [-d <db> ] [-g <get> ] [-h <host>] [-p] 8 [-s <system>] [-r <runs> ] [-u <username>] <command> [command args] 9''' % sys.argv[0] 10 sys.exit(1) 11 12def getopts(list, flags): 13 import getopt 14 try: 15 opts, args = getopt.getopt(list, flags) 16 except getopt.GetoptError: 17 usage() 18 19 return opts, args 20 21def printval(name, value, invert = False): 22 if invert and value != 0.0: 23 value = 1 / value 24 25 if value == (1e300*1e300): 26 return 27 28 if printval.mode == 'G': 29 print '%s: %g' % (name, value) 30 elif printval.mode != 'F' and value > 1e6: 31 print '%s: %0.5e' % (name, value) 32 else: 33 print '%s: %f' % (name, value) 34 35printval.mode = 'G' 36 37def unique(list): 38 set = {} 39 map(set.__setitem__, list, []) 40 return set.keys() 41 42def graphdata(runs, options, tag, label, value): 43 import info 44 configs = ['ste', 'hte', 'htd', 'ocm', 'occ', 'ocp' ] 45 #benchmarks = [ 'm', 's', 'nb1', 'nb2', 'nt1', 'nt2', 'w1', 'w2', 'w3', 'w4', 'ns', 'nm', 'nw1', 'nw2', 'nw3' ] 46 #benchmarks = [ 'm', 's', 'nb1', 'nb2', 'nt1', 'w1', 'w2', 'w3', 'ns', 'nm', 'w1s' ] 47 benchmarks = [ 'm', 's', 'nb1', 'nb2', 'w1', 'w2', 'w3', 'w4', 'ns', 'nm', 'nw1', 'snt' ] 48 #dmas = [ 'x', 'd', 'b' ] 49 dmas = [ 'x' ] 50 caches = [ '2', '4' ] 51 52 names = [] 53 54 bench_system = { 55 'm' : 'client', 56 's' : 'client', 57 'snt' : 'client', 58 'nb1' : 'server', 59 'nb2' : 'server', 60 'nt1' : 'server', 61 'nt2' : 'server', 62 'w1' : 'server', 63 'w2' : 'server', 64 'w3' : 'server', 65 'w4' : 'server', 66 'w1s' : 'server', 67 'w2s' : 'server', 68 'w3s' : 'server', 69 'ns' : 'natbox', 70 'nm' : 'natbox', 71 'nw1' : 'natbox', 72 'nw2' : 'natbox', 73 'nw3' : 'natbox' 74 } 75 76 for bench in benchmarks: 77 if bench_system[bench] != options.system: 78 continue 79 80 for dma in dmas: 81 for cache in caches: 82 names.append([bench, dma, cache]) 83 84 for bench,dma,cache in names: 85 base = '%s.%s.%s' % (bench, dma, cache) 86 fname = 'data/%s.%s.dat' % (tag, base) 87 f = open(fname, 'w') 88 print >>f, '#set TITLE = %s' % base 89 print >>f, '#set xlbl = Configuration' 90 print >>f, '#set ylbl = %s' % label 91 print >>f, '#set sublabels = %s' % ' '.join(configs) 92 93 for speed,freq in zip(['s', 'q'],['4GHz','10GHz']): 94 print >>f, '"%s"' % freq, 95 for conf in configs: 96 name = '%s.%s.%s.%s.%s' % (conf, bench, dma, cache, speed) 97 run = info.source.allRunNames[name] 98 info.display_run = run.run; 99 val = float(value) 100 if val == 1e300*1e300: 101 print >>f, 0.0, 102 else: 103 print >>f, "%f" % val, 104 print >>f 105 f.close() 106 107def printdata(runs, value, invert = False): 108 import info 109 for run in runs: 110 info.display_run = run.run; 111 val = float(value) 112 printval(run.name, val) 113 114class CommandException(Exception): 115 pass 116 117def commands(options, command, args): 118 if command == 'database': 119 if len(args) == 0: raise CommandException 120 121 import dbinit 122 mydb = dbinit.MyDB(options) 123 124 if args[0] == 'drop': 125 if len(args) > 2: raise CommandException 126 mydb.admin() 127 mydb.drop() 128 if len(args) == 2 and args[1] == 'init': 129 mydb.create() 130 mydb.connect() 131 mydb.populate() 132 mydb.close() 133 return 134 135 if args[0] == 'init': 136 if len(args) > 1: raise CommandException 137 mydb.admin() 138 mydb.create() 139 mydb.connect() 140 mydb.populate() 141 mydb.close() 142 return 143 144 if args[0] == 'clean': 145 if len(args) > 1: raise CommandException 146 mydb.connect() 147 mydb.clean() 148 return 149 150 raise CommandException 151 152 import db, info 153 info.source = db.Database() 154 info.source.host = options.host 155 info.source.db = options.db 156 info.source.passwd = options.passwd 157 info.source.user = options.user 158 info.source.connect() 159 info.source.update_dict(globals()) 160 161 if type(options.get) is str: 162 info.source.get = options.get 163 164 if options.runs is None: 165 runs = info.source.allRuns 166 else: 167 rx = re.compile(options.runs) 168 runs = [] 169 for run in info.source.allRuns: 170 if rx.match(run.name): 171 runs.append(run) 172 173 info.display_run = runs[0].run 174 175 if command == 'runs': 176 user = None 177 opts, args = getopts(args, '-u') 178 if len(args): 179 raise CommandException 180 for o,a in opts: 181 if o == '-u': 182 user = a 183 info.source.listRuns(user) 184 return 185 186 if command == 'stats': 187 if len(args) == 0: 188 info.source.listStats() 189 elif len(args) == 1: 190 info.source.listStats(args[0]) 191 else: 192 raise CommandException 193 194 return 195 196 if command == 'stat': 197 if len(args) != 1: 198 raise CommandException 199 200 stats = info.source.getStat(args[0]) 201 for stat in stats: 202 if options.graph: 203 graphdata(runs, options, stat.name, stat.name, stat) 204 else: 205 if options.ticks: 206 print 'only displaying sample %s' % options.ticks 207 stat.ticks = options.ticks 208 209 if options.binned: 210 print 'kernel ticks' 211 stat.bins = 'kernel' 212 printdata(runs, stat) 213 214 print 'idle ticks' 215 stat.bins = 'idle' 216 printdata(runs, stat) 217 218 print 'user ticks' 219 stat.bins = 'user' 220 printdata(runs, stat) 221 222 print 'interrupt ticks' 223 stat.bins = 'interrupt' 224 printdata(runs, stat) 225 226 print 'total ticks' 227 228 stat.bins = None 229 print stat.name 230 printdata(runs, stat) 231 return 232 233 if command == 'formula': 234 if len(args) != 1: 235 raise CommandException 236 237 stats = eval(args[0]) 238 for stat in stats: 239 if options.graph: 240 graphdata(runs, options, stat.name, stat.name, stat) 241 else: 242 if options.binned: 243 print 'kernel ticks' 244 stat.bins = 'kernel' 245 printdata(runs, stat) 246 247 print 'idle ticks' 248 stat.bins = 'idle' 249 printdata(runs, stat) 250 251 print 'user ticks' 252 stat.bins = 'user' 253 printdata(runs, stat) 254 255 print 'interrupt ticks' 256 stat.bins = 'interrupt' 257 printdata(runs, stat) 258 259 print 'total ticks' 260 261 stat.bins = None 262 print args[0] 263 printdata(runs, stat) 264 return 265 266 if command == 'bins': 267 if len(args) == 0: 268 info.source.listBins() 269 elif len(args) == 1: 270 info.source.listBins(args[0]) 271 else: 272 raise CommandException 273 274 return 275 276 if command == 'formulas': 277 if len(args) == 0: 278 info.source.listFormulas() 279 elif len(args) == 1: 280 info.source.listFormulas(args[0]) 281 else: 282 raise CommandException 283 284 return 285 286 if command == 'samples': 287 if len(args): 288 raise CommandException 289 290 info.source.listTicks(runs) 291 return 292 293 if len(args): 294 raise CommandException 295 296 system = info.source.__dict__[options.system] 297 298 if command == 'usertime': 299 import copy 300 kernel = copy.copy(system.full_cpu.numCycles) 301 kernel.bins = 'kernel' 302 303 user = copy.copy(system.full_cpu.numCycles) 304 user.bins = 'user' 305 306 if options.graph: 307 graphdata(runs, options, 'usertime', 'User Fraction', 308 user / system.full_cpu.numCycles) 309 else: 310 printdata(runs, user / system.full_cpu.numCycles) 311 return 312 313 if command == 'ticks': 314 if options.binned: 315 print 'kernel ticks' 316 system.full_cpu.numCycles.bins = 'kernel' 317 printdata(runs, system.full_cpu.numCycles) 318 319 print 'idle ticks' 320 system.full_cpu.numCycles.bins = 'idle' 321 printdata(runs, system.full_cpu.numCycles) 322 323 print 'user ticks' 324 system.full_cpu.numCycles.bins = 'user' 325 printdata(runs, system.full_cpu.numCycles) 326 327 print 'total ticks' 328 329 system.full_cpu.numCycles.bins = None 330 printdata(runs, system.full_cpu.numCycles) 331 return 332 333 if command == 'packets': 334 packets = system.tsunami.etherdev.rxPackets 335 if options.graph: 336 graphdata(runs, options, 'packets', 'Packets', packets) 337 else: 338 printdata(runs, packets) 339 return 340 341 if command == 'ppt' or command == 'tpp': 342 ppt = system.tsunami.etherdev.rxPackets / sim_ticks 343 printdata(runs, ppt, command == 'tpp') 344 return 345 346 if command == 'pps': 347 pps = system.tsunami.etherdev.rxPackets / sim_seconds 348 if options.graph: 349 graphdata(runs, options, 'pps', 'Packets/s', pps) 350 else: 351 printdata(runs, pps) 352 return 353 354 if command == 'bpt' or command == 'tpb': 355 bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 356 bpt = bytes / sim_ticks * 8 357 if options.graph: 358 graphdata(runs, options, 'bpt', 'bps / Hz', bpt) 359 else: 360 printdata(runs, bpt, command == 'tpb') 361 return 362 363 if command == 'bptb' or command == 'tpbb': 364 bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 365 366 print 'kernel stats' 367 bytes.bins = 'kernel' 368 printdata(runs, bytes / ticks) 369 370 print 'idle stats' 371 bytes.bins = 'idle' 372 printdata(runs, bytes / ticks) 373 374 print 'user stats' 375 bytes.bins = 'user' 376 printdata(runs, bytes / ticks) 377 378 return 379 380 if command == 'bytes': 381 stat = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 382 383 if options.binned: 384 print '%s kernel stats' % stat.name 385 stat.bins = 'kernel' 386 printdata(runs, stat) 387 388 print '%s idle stats' % stat.name 389 stat.bins = 'idle' 390 printdata(runs, stat) 391 392 print '%s user stats' % stat.name 393 stat.bins = 'user' 394 printdata(runs, stat) 395 396 print '%s total stats' % stat.name 397 stat.bins = None 398 399 printdata(runs, stat) 400 return 401 402 if command == 'rxbps': 403 gbps = system.tsunami.etherdev.rxBandwidth / 1e9 404 if options.graph: 405 graphdata(runs, options, 'rxbps', 'Bandwidth (Gbps)', gbps) 406 else: 407 printdata(runs, gbps) 408 return 409 410 if command == 'txbps': 411 gbps = system.tsunami.etherdev.txBandwidth / 1e9 412 if options.graph: 413 graphdata(runs, options, 'txbps', 'Bandwidth (Gbps)', gbps) 414 else: 415 printdata(runs, gbps) 416 return 417 418 if command == 'bps': 419 rxbps = system.tsunami.etherdev.rxBandwidth 420 txbps = system.tsunami.etherdev.txBandwidth 421 gbps = (rxbps + txbps) / 1e9 422 if options.graph: 423 graphdata(runs, options, 'bps', 'Bandwidth (Gbps)', gbps) 424 else: 425 printdata(runs, gbps) 426 return 427 428 if command == 'misses': 429 stat = system.L2.overall_mshr_misses 430 if options.binned: 431 print '%s kernel stats' % stat.name 432 stat.bins = 'kernel' 433 printdata(runs, stat) 434 435 print '%s idle stats' % stat.name 436 stat.bins = 'idle' 437 printdata(runs, stat) 438 439 print '%s user stats' % stat.name 440 stat.bins = 'user' 441 printdata(runs, stat) 442 443 print '%s total stats' % stat.name 444 445 stat.bins = None 446 if options.graph: 447 graphdata(runs, options, 'misses', 'Overall MSHR Misses', stat) 448 else: 449 printdata(runs, stat) 450 return 451 452 if command == 'mpkb': 453 misses = system.L2.overall_mshr_misses 454 rxbytes = system.tsunami.etherdev.rxBytes 455 txbytes = system.tsunami.etherdev.txBytes 456 457 if options.binned: 458 print 'mpkb kernel stats' 459 misses.bins = 'kernel' 460 mpkb = misses / ((rxbytes + txbytes) / 1024) 461 printdata(runs, mpkb) 462 463 print 'mpkb idle stats' 464 misses.bins = 'idle' 465 mpkb = misses / ((rxbytes + txbytes) / 1024) 466 printdata(runs, mpkb) 467 468 print 'mpkb user stats' 469 misses.bins = 'user' 470 mpkb = misses / ((rxbytes + txbytes) / 1024) 471 printdata(runs, mpkb) 472 473 print 'mpkb total stats' 474 475 mpkb = misses / ((rxbytes + txbytes) / 1024) 476 misses.bins = None 477 if options.graph: 478 graphdata(runs, options, 'mpkb', 'Misses / KB', mpkb) 479 else: 480 printdata(runs, mpkb) 481 return 482 483 if command == 'ipkb': 484 interrupts = system.full_cpu.kern.faults[4] 485 rxbytes = system.tsunami.etherdev.rxBytes 486 txbytes = system.tsunami.etherdev.txBytes 487 488 if options.binned: 489 print 'ipkb kernel stats' 490 interrupts.bins = 'kernel' 491 ipkb = interrupts / ((rxbytes + txbytes) / 1024) 492 printdata(runs, ipkb) 493 494 print 'ipkb idle stats' 495 interrupts.bins = 'idle' 496 ipkb = interrupts / ((rxbytes + txbytes) / 1024) 497 printdata(runs, ipkb) 498 499 print 'ipkb user stats' 500 interrupts.bins = 'user' 501 ipkb = interrupts / ((rxbytes + txbytes) / 1024) 502 printdata(runs, ipkb) 503 504 print 'ipkb total stats' 505 506 ipkb = interrupts / ((rxbytes + txbytes) / 1024) 507 interrupts.bins = None 508 if options.graph: 509 graphdata(runs, options, 'ipkb', 'Interrupts / KB', ipkb) 510 else: 511 printdata(runs, ipkb) 512 return 513 514 if command == 'execute': 515 printdata(runs, system.full_cpu.ISSUE__count) 516 return 517 518 if command == 'commit': 519 printdata(runs, system.full_cpu.COM__count) 520 return 521 522 if command == 'fetch': 523 printdata(runs, system.full_cpu.FETCH__count) 524 return 525 526 if command == 'bpp': 527 ed = system.tsunami.etherdev 528 bpp = (ed.rxBytes + ed.txBytes) / (ed.rxPackets + ed.txPackets) 529 if options.graph: 530 graphdata(runs, options, 'bpp', 'Bytes / Packet', bpp) 531 else: 532 printdata(runs, bpp) 533 return 534 535 if command == 'rxbpp': 536 bpp = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.rxPackets 537 if options.graph: 538 graphdata(runs, options, 'rxbpp', 'Receive Bytes / Packet', bpp) 539 else: 540 printdata(runs, bpp) 541 return 542 543 if command == 'txbpp': 544 bpp = system.tsunami.etherdev.txBytes / system.tsunami.etherdev.txPackets 545 if options.graph: 546 graphdata(runs, options, 'txbpp', 'Transmit Bytes / Packet', bpp) 547 else: 548 printdata(runs, bpp) 549 return 550 551 if command == 'rtp': 552 rtp = system.tsunami.etherdev.rxPackets / system.tsunami.etherdev.txPackets 553 if options.graph: 554 graphdata(runs, options, 'rtp', 'rxPackets / txPackets', rtp) 555 else: 556 printdata(runs, rtp) 557 return 558 559 if command == 'rtb': 560 rtb = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.txBytes 561 if options.graph: 562 graphdata(runs, options, 'rtb', 'rxBytes / txBytes', rtb) 563 else: 564 printdata(runs, rtb) 565 return 566 567 raise CommandException 568 569 570class Options: pass 571 572if __name__ == '__main__': 573 import getpass 574 575 options = Options() 576 options.host = 'zizzer.pool' 577 options.db = None 578 options.passwd = '' 579 options.user = getpass.getuser() 580 options.runs = None 581 options.system = 'client' 582 options.get = None 583 options.binned = False 584 options.graph = False 585 options.ticks = False 586 587 opts, args = getopts(sys.argv[1:], '-BEFGd:g:h:pr:s:u:T:') 588 for o,a in opts: 589 if o == '-B': 590 options.binned = True 591 if o == '-E': 592 printval.mode = 'E' 593 if o == '-F': 594 printval.mode = 'F' 595 if o == '-G': 596 options.graph = True; 597 if o == '-d': 598 options.db = a 599 if o == '-g': 600 options.get = a 601 if o == '-h': 602 options.host = a 603 if o == '-p': 604 options.passwd = getpass.getpass() 605 if o == '-r': 606 options.runs = a 607 if o == '-u': 608 options.user = a 609 if o == '-s': 610 options.system = a 611 if o == '-T': 612 options.ticks = a 613 614 if len(args) == 0: 615 usage() 616 617 command = args[0] 618 args = args[1:] 619 620 try: 621 commands(options, command, args) 622 except CommandException: 623 usage() 624