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