stats.py revision 1162
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, tag, label, value): 43 import info 44 configs = ['stx', 'ste', 'hte', 'htd', 'ocm', 'occ', 'ocp' ] 45 benchmarks = [ 'm', 's' ] 46 dmas = [ 'X', 'D' ] 47 caches = [ '2', '4' ] 48 checkpoints = [ '1' ] 49 50 names = [] 51 for bench in benchmarks: 52 for dma in dmas: 53 for cache in caches: 54 for cpt in checkpoints: 55 names.append([bench, dma, cache, cpt]) 56 57 for bench,dma,cache,cpt in names: 58 base = '%s.%s.%s.%s' % (bench, dma, cache, cpt) 59 fname = '/n/ziff/z/binkertn/graph/test2/data/%s.%s.dat' % (tag, base) 60 f = open(fname, 'w') 61 print >>f, '#set TITLE = %s' % base 62 print >>f, '#set xlbl = Configuration' 63 print >>f, '#set ylbl = %s' % label 64 print >>f, '#set sublabels = %s' % ' '.join(configs) 65 66 for speed,freq in zip(['s', 'q'],['4GHz','10GHz']): 67 print >>f, '"%s"' % freq, 68 for conf in configs: 69 name = '%s.%s.%s.%s.%s.%s' % (conf, bench, dma, speed, cache, 70 cpt) 71 run = info.source.allRunNames[name] 72 info.display_run = run.run; 73 val = float(value) 74 if val == 1e300*1e300: 75 print >>f, 0.0, 76 else: 77 print >>f, "%f" % val, 78 print >>f 79 f.close() 80 81def printdata(runs, value, invert = False): 82 import info 83 for run in runs: 84 info.display_run = run.run; 85 val = float(value) 86 printval(run.name, val) 87 88class CommandException(Exception): 89 pass 90 91def commands(options, command, args): 92 if command == 'database': 93 if len(args) == 0: raise CommandException 94 95 import dbinit 96 mydb = dbinit.MyDB(options) 97 98 if args[0] == 'drop': 99 if len(args) > 2: raise CommandException 100 mydb.admin() 101 mydb.drop() 102 if len(args) == 2 and args[1] == 'init': 103 mydb.create() 104 mydb.connect() 105 mydb.populate() 106 mydb.close() 107 return 108 109 if args[0] == 'init': 110 if len(args) > 1: raise CommandException 111 mydb.admin() 112 mydb.create() 113 mydb.connect() 114 mydb.populate() 115 mydb.close() 116 return 117 118 if args[0] == 'clean': 119 if len(args) > 1: raise CommandException 120 mydb.connect() 121 mydb.clean() 122 return 123 124 raise CommandException 125 126 import db, info 127 info.source = db.Database() 128 info.source.host = options.host 129 info.source.db = options.db 130 info.source.passwd = options.passwd 131 info.source.user = options.user 132 info.source.connect() 133 info.source.update_dict(globals()) 134 135 system = info.source.__dict__[options.system] 136 137 if type(options.get) is str: 138 info.source.get = options.get 139 140 if options.runs is None: 141 runs = info.source.allRuns 142 else: 143 rx = re.compile(options.runs) 144 runs = [] 145 for run in info.source.allRuns: 146 if rx.match(run.name): 147 runs.append(run) 148 149 info.display_run = runs[0].run 150 151 if command == 'runs': 152 user = None 153 opts, args = getopts(args, '-u') 154 if len(args): 155 raise CommandException 156 for o,a in opts: 157 if o == '-u': 158 user = a 159 info.source.listRuns(user) 160 return 161 162 if command == 'stats': 163 if len(args) == 0: 164 info.source.listStats() 165 elif len(args) == 1: 166 info.source.listStats(args[0]) 167 else: 168 raise CommandException 169 170 return 171 172 if command == 'stat': 173 if len(args) != 1: 174 raise CommandException 175 176 stats = info.source.getStat(args[0]) 177 for stat in stats: 178 if options.graph: 179 graphdata(runs, stat.name, stat.name, stat) 180 else: 181 print stat.name 182 printdata(runs, stat) 183 return 184 185 if command == 'bins': 186 if len(args) == 0: 187 info.source.listBins() 188 elif len(args) == 1: 189 info.source.listBins(args[0]) 190 else: 191 raise CommandException 192 193 return 194 195 if command == 'formulas': 196 if len(args) == 0: 197 info.source.listFormulas() 198 elif len(args) == 1: 199 info.source.listFormulas(args[0]) 200 else: 201 raise CommandException 202 203 return 204 205 if command == 'samples': 206 if len(args): 207 raise CommandException 208 209 info.source.listTicks(runs) 210 return 211 212 if len(args): 213 raise CommandException 214 215 if command == 'usertime': 216 import copy 217 kernel = copy.copy(system.full_cpu.numCycles) 218 kernel.bins = 'kernel' 219 220 user = copy.copy(system.full_cpu.numCycles) 221 user.bins = 'user' 222 223 if options.graph: 224 graphdata(runs, 'usertime', 'User Fraction', 225 user / system.full_cpu.numCycles) 226 else: 227 printdata(runs, user / system.full_cpu.numCycles) 228 return 229 230 if command == 'ticks': 231 if options.binned: 232 print 'kernel ticks' 233 system.full_cpu.numCycles.bins = 'kernel' 234 printdata(runs, system.full_cpu.numCycles) 235 236 print 'idle ticks' 237 system.full_cpu.numCycles.bins = 'idle' 238 printdata(runs, system.full_cpu.numCycles) 239 240 print 'user ticks' 241 system.full_cpu.numCycles.bins = 'user' 242 printdata(runs, system.full_cpu.numCycles) 243 244 print 'total ticks' 245 246 system.full_cpu.numCycles.bins = None 247 printdata(runs, system.full_cpu.numCycles) 248 return 249 250 if command == 'packets': 251 packets = system.tsunami.etherdev.rxPackets 252 if options.graph: 253 graphdata(runs, 'packets', 'Packets', packets) 254 else: 255 printdata(runs, packets) 256 return 257 258 if command == 'ppt' or command == 'tpp': 259 ppt = system.tsunami.etherdev.rxPackets / sim_ticks 260 printdata(runs, ppt, command == 'tpp') 261 return 262 263 if command == 'pps': 264 pps = system.tsunami.etherdev.rxPackets / sim_seconds 265 if options.graph: 266 graphdata(runs, 'pps', 'Packets/s', pps) 267 else: 268 printdata(runs, pps) 269 return 270 271 if command == 'bpt' or command == 'tpb': 272 bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 273 bpt = bytes / sim_ticks * 8 274 if options.graph: 275 graphdata(runs, 'bpt', 'bps / Hz', bpt) 276 else: 277 printdata(runs, bpt, command == 'tpb') 278 return 279 280 if command == 'bptb' or command == 'tpbb': 281 bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 282 283 print 'kernel stats' 284 bytes.bins = 'kernel' 285 printdata(runs, bytes / ticks) 286 287 print 'idle stats' 288 bytes.bins = 'idle' 289 printdata(runs, bytes / ticks) 290 291 print 'user stats' 292 bytes.bins = 'user' 293 printdata(runs, bytes / ticks) 294 295 return 296 297 if command == 'bytes': 298 stat = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes 299 300 if options.binned: 301 print '%s kernel stats' % stat.name 302 stat.bins = 'kernel' 303 printdata(runs, stat) 304 305 print '%s idle stats' % stat.name 306 stat.bins = 'idle' 307 printdata(runs, stat) 308 309 print '%s user stats' % stat.name 310 stat.bins = 'user' 311 printdata(runs, stat) 312 313 print '%s total stats' % stat.name 314 stat.bins = None 315 316 printdata(runs, stat) 317 return 318 319 if command == 'rxbps': 320 gbps = system.tsunami.etherdev.rxBandwidth / 1e9 321 if options.graph: 322 graphdata(runs, 'rxbps', 'Bandwidth (Gbps)', gbps) 323 else: 324 printdata(runs, gbps) 325 return 326 327 if command == 'txbps': 328 gbps = system.tsunami.etherdev.txBandwidth / 1e9 329 if options.graph: 330 graphdata(runs, 'txbps', 'Bandwidth (Gbps)', gbps) 331 else: 332 printdata(runs, gbps) 333 return 334 335 if command == 'bps': 336 rxbps = system.tsunami.etherdev.rxBandwidth 337 txbps = system.tsunami.etherdev.txBandwidth 338 gbps = (rxbps + txbps) / 1e9 339 if options.graph: 340 graphdata(runs, 'bps', 'Bandwidth (Gbps)', gbps) 341 else: 342 printdata(runs, gbps) 343 return 344 345 if command == 'misses': 346 stat = system.L2.overall_mshr_misses 347 if options.binned: 348 print '%s kernel stats' % stat.name 349 stat.bins = 'kernel' 350 printdata(runs, stat) 351 352 print '%s idle stats' % stat.name 353 stat.bins = 'idle' 354 printdata(runs, stat) 355 356 print '%s user stats' % stat.name 357 stat.bins = 'user' 358 printdata(runs, stat) 359 360 print '%s total stats' % stat.name 361 362 stat.bins = None 363 if options.graph: 364 graphdata(runs, 'misses', 'Overall MSHR Misses', stat) 365 else: 366 printdata(runs, stat) 367 return 368 369 if command == 'mpkb': 370 misses = system.L2.overall_mshr_misses 371 rxbytes = system.tsunami.etherdev.rxBytes 372 txbytes = system.tsunami.etherdev.txBytes 373 374 if options.binned: 375 print 'mpkb kernel stats' 376 misses.bins = 'kernel' 377 mpkb = misses / ((rxbytes + txbytes) / 1024) 378 printdata(runs, mpkb) 379 380 print 'mpkb idle stats' 381 misses.bins = 'idle' 382 mpkb = misses / ((rxbytes + txbytes) / 1024) 383 printdata(runs, mpkb) 384 385 print 'mpkb user stats' 386 misses.bins = 'user' 387 mpkb = misses / ((rxbytes + txbytes) / 1024) 388 printdata(runs, mpkb) 389 390 print 'mpkb total stats' 391 392 mpkb = misses / ((rxbytes + txbytes) / 1024) 393 misses.bins = None 394 if options.graph: 395 graphdata(runs, 'mpkb', 'Misses / KB', mpkb) 396 else: 397 printdata(runs, mpkb) 398 return 399 400 if command == 'execute': 401 printdata(runs, system.full_cpu.ISSUE__count) 402 return 403 404 if command == 'commit': 405 printdata(runs, system.full_cpu.COM__count) 406 return 407 408 if command == 'fetch': 409 printdata(runs, system.full_cpu.FETCH__count) 410 return 411 412 if command == 'bpp': 413 ed = system.tsunami.etherdev 414 bpp = (ed.rxBytes + ed.txBytes) / (ed.rxPackets + ed.txPackets) 415 if options.graph: 416 graphdata(runs, 'bpp', 'Bytes / Packet', bpp) 417 else: 418 printdata(runs, bpp) 419 return 420 421 if command == 'rxbpp': 422 bpp = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.rxPackets 423 if options.graph: 424 graphdata(runs, 'rxbpp', 'Receive Bytes / Packet', bpp) 425 else: 426 printdata(runs, bpp) 427 return 428 429 if command == 'txbpp': 430 bpp = system.tsunami.etherdev.txBytes / system.tsunami.etherdev.txPackets 431 if options.graph: 432 graphdata(runs, 'txbpp', 'Transmit Bytes / Packet', bpp) 433 else: 434 printdata(runs, bpp) 435 return 436 437 if command == 'rtp': 438 rtp = system.tsunami.etherdev.rxPackets / system.tsunami.etherdev.txPackets 439 if options.graph: 440 graphdata(runs, 'rtp', 'rxPackets / txPackets', rtp) 441 else: 442 printdata(runs, rtp) 443 return 444 445 if command == 'rtb': 446 rtb = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.txBytes 447 if options.graph: 448 graphdata(runs, 'rtb', 'rxBytes / txBytes', rtb) 449 else: 450 printdata(runs, rtb) 451 return 452 453 raise CommandException 454 455 456class Options: pass 457 458if __name__ == '__main__': 459 import getpass 460 461 options = Options() 462 options.host = 'zizzer.pool' 463 options.db = None 464 options.passwd = '' 465 options.user = getpass.getuser() 466 options.runs = None 467 options.system = 'client' 468 options.get = None 469 options.binned = False 470 options.graph = False 471 472 opts, args = getopts(sys.argv[1:], '-BEFGd:g:h:pr:s:u:') 473 for o,a in opts: 474 if o == '-B': 475 options.binned = True 476 if o == '-E': 477 printval.mode = 'E' 478 if o == '-F': 479 printval.mode = 'F' 480 if o == '-G': 481 options.graph = True; 482 if o == '-d': 483 options.db = a 484 if o == '-g': 485 options.get = a 486 if o == '-h': 487 options.host = a 488 if o == '-p': 489 options.passwd = getpass.getpass() 490 if o == '-r': 491 options.runs = a 492 if o == '-u': 493 options.user = a 494 if o == '-s': 495 options.system = a 496 497 if len(args) == 0: 498 usage() 499 500 command = args[0] 501 args = args[1:] 502 503 try: 504 commands(options, command, args) 505 except CommandException: 506 usage() 507