stats.py revision 1308
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 == 'stats':
253        if len(args) == 0:
254            info.source.listStats()
255        elif len(args) == 1:
256            info.source.listStats(args[0])
257        else:
258            raise CommandException
259
260        return
261
262    if command == 'stat':
263        if len(args) != 1:
264            raise CommandException
265
266        stats = info.source.getStat(args[0])
267        for stat in stats:
268            if options.graph:
269                graphdata(runs, options, stat.name, stat.name, stat)
270            else:
271                if options.ticks:
272                   print 'only displaying sample %s' % options.ticks
273                   stat.ticks = options.ticks
274
275                if options.binned:
276                    print 'kernel ticks'
277                    stat.bins = 'kernel'
278                    printdata(runs, stat)
279
280                    print 'idle ticks'
281                    stat.bins = 'idle'
282                    printdata(runs, stat)
283
284                    print 'user ticks'
285                    stat.bins = 'user'
286                    printdata(runs, stat)
287
288                    print 'interrupt ticks'
289                    stat.bins = 'interrupt'
290                    printdata(runs, stat)
291
292                    print 'total ticks'
293
294                stat.bins = None
295                print stat.name
296                printdata(runs, stat)
297        return
298
299    if command == 'formula':
300        if len(args) != 1:
301            raise CommandException
302
303        stats = eval(args[0])
304        for stat in stats:
305            if options.graph:
306                graphdata(runs, options, stat.name, stat.name, stat)
307            else:
308                if options.binned:
309                    print 'kernel ticks'
310                    stat.bins = 'kernel'
311                    printdata(runs, stat)
312
313                    print 'idle ticks'
314                    stat.bins = 'idle'
315                    printdata(runs, stat)
316
317                    print 'user ticks'
318                    stat.bins = 'user'
319                    printdata(runs, stat)
320
321                    print 'interrupt ticks'
322                    stat.bins = 'interrupt'
323                    printdata(runs, stat)
324
325                    print 'total ticks'
326
327                stat.bins = None
328                print args[0]
329                printdata(runs, stat)
330        return
331
332    if command == 'bins':
333        if len(args) == 0:
334            info.source.listBins()
335        elif len(args) == 1:
336            info.source.listBins(args[0])
337        else:
338            raise CommandException
339
340        return
341
342    if command == 'formulas':
343        if len(args) == 0:
344            info.source.listFormulas()
345        elif len(args) == 1:
346            info.source.listFormulas(args[0])
347        else:
348            raise CommandException
349
350        return
351
352    if command == 'samples':
353        if len(args):
354            raise CommandException
355
356        info.source.listTicks(runs)
357        return
358
359    if len(args):
360        raise CommandException
361
362    system = info.source.__dict__[options.system]
363
364    if command == 'usertime':
365        import copy
366        kernel = copy.copy(system.full_cpu.numCycles)
367        kernel.bins = 'kernel'
368
369        user = copy.copy(system.full_cpu.numCycles)
370        user.bins = 'user'
371
372        if options.graph:
373            graphdata(runs, options, 'usertime', 'User Fraction',
374                      user / system.full_cpu.numCycles)
375        else:
376            printdata(runs, user / system.full_cpu.numCycles)
377        return
378
379    if command == 'ticks':
380        if options.binned:
381            print 'kernel ticks'
382            system.full_cpu.numCycles.bins = 'kernel'
383            printdata(runs, system.full_cpu.numCycles)
384
385            print 'idle ticks'
386            system.full_cpu.numCycles.bins = 'idle'
387            printdata(runs, system.full_cpu.numCycles)
388
389            print 'user ticks'
390            system.full_cpu.numCycles.bins = 'user'
391            printdata(runs, system.full_cpu.numCycles)
392
393            print 'total ticks'
394
395        system.full_cpu.numCycles.bins = None
396        printdata(runs, system.full_cpu.numCycles)
397        return
398
399    if command == 'packets':
400        packets = system.tsunami.etherdev.rxPackets
401        if options.graph:
402            graphdata(runs, options, 'packets', 'Packets', packets)
403        else:
404            printdata(runs, packets)
405        return
406
407    if command == 'ppt' or command == 'tpp':
408        ppt = system.tsunami.etherdev.rxPackets / sim_ticks
409        printdata(runs, ppt, command == 'tpp')
410        return
411
412    if command == 'pps':
413        pps = system.tsunami.etherdev.rxPackets / sim_seconds
414        if options.graph:
415            graphdata(runs, options, 'pps', 'Packets/s', pps)
416        else:
417            printdata(runs, pps)
418        return
419
420    if command == 'bpt' or command == 'tpb':
421        bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
422        bpt = bytes / sim_ticks * 8
423        if options.graph:
424            graphdata(runs, options, 'bpt', 'bps / Hz', bpt)
425        else:
426            printdata(runs, bpt, command == 'tpb')
427        return
428
429    if command == 'bptb' or command == 'tpbb':
430        bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
431
432        print 'kernel stats'
433        bytes.bins = 'kernel'
434        printdata(runs, bytes / ticks)
435
436        print 'idle stats'
437        bytes.bins = 'idle'
438        printdata(runs, bytes / ticks)
439
440        print 'user stats'
441        bytes.bins = 'user'
442        printdata(runs, bytes / ticks)
443
444        return
445
446    if command == 'bytes':
447        stat = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
448
449        if options.binned:
450            print '%s kernel stats' % stat.name
451            stat.bins = 'kernel'
452            printdata(runs, stat)
453
454            print '%s idle stats' % stat.name
455            stat.bins = 'idle'
456            printdata(runs, stat)
457
458            print '%s user stats' % stat.name
459            stat.bins = 'user'
460            printdata(runs, stat)
461
462            print '%s total stats' % stat.name
463            stat.bins = None
464
465        printdata(runs, stat)
466        return
467
468    if command == 'rxbps':
469        gbps = system.tsunami.etherdev.rxBandwidth / 1e9
470        if options.graph:
471            graphdata(runs, options, 'rxbps', 'Bandwidth (Gbps)',  gbps)
472        else:
473            printdata(runs, gbps)
474        return
475
476    if command == 'txbps':
477        gbps = system.tsunami.etherdev.txBandwidth / 1e9
478        if options.graph:
479            graphdata(runs, options, 'txbps', 'Bandwidth (Gbps)',  gbps)
480        else:
481            printdata(runs, gbps)
482        return
483
484    if command == 'bps':
485        rxbps = system.tsunami.etherdev.rxBandwidth
486        txbps = system.tsunami.etherdev.txBandwidth
487        gbps = (rxbps + txbps) / 1e9
488        if options.graph:
489            graphdata(runs, options, 'bps', 'Bandwidth (Gbps)',  gbps)
490        else:
491            printdata(runs, gbps)
492        return
493
494    if command == 'misses':
495        stat = system.L2.overall_mshr_misses
496        if options.binned:
497            print '%s kernel stats' % stat.name
498            stat.bins = 'kernel'
499            printdata(runs, stat)
500
501            print '%s idle stats' % stat.name
502            stat.bins = 'idle'
503            printdata(runs, stat)
504
505            print '%s user stats' % stat.name
506            stat.bins = 'user'
507            printdata(runs, stat)
508
509            print '%s total stats' % stat.name
510
511        stat.bins = None
512        if options.graph:
513            graphdata(runs, options, 'misses', 'Overall MSHR Misses', stat)
514        else:
515            printdata(runs, stat)
516        return
517
518    if command == 'mpkb':
519        misses = system.L2.overall_mshr_misses
520        rxbytes = system.tsunami.etherdev.rxBytes
521        txbytes = system.tsunami.etherdev.txBytes
522
523        if options.binned:
524            print 'mpkb kernel stats'
525            misses.bins = 'kernel'
526            mpkb = misses / ((rxbytes + txbytes) / 1024)
527            printdata(runs, mpkb)
528
529            print 'mpkb idle stats'
530            misses.bins = 'idle'
531            mpkb = misses / ((rxbytes + txbytes) / 1024)
532            printdata(runs, mpkb)
533
534            print 'mpkb user stats'
535            misses.bins = 'user'
536            mpkb = misses / ((rxbytes + txbytes) / 1024)
537            printdata(runs, mpkb)
538
539            print 'mpkb total stats'
540
541        mpkb = misses / ((rxbytes + txbytes) / 1024)
542        misses.bins = None
543        if options.graph:
544            graphdata(runs, options, 'mpkb', 'Misses / KB',  mpkb)
545        else:
546            printdata(runs, mpkb)
547        return
548
549    if command == 'ipkb':
550        interrupts = system.full_cpu.kern.faults[4]
551        rxbytes = system.tsunami.etherdev.rxBytes
552        txbytes = system.tsunami.etherdev.txBytes
553
554        if options.binned:
555            print 'ipkb kernel stats'
556            interrupts.bins = 'kernel'
557            ipkb = interrupts / ((rxbytes + txbytes) / 1024)
558            printdata(runs, ipkb)
559
560            print 'ipkb idle stats'
561            interrupts.bins = 'idle'
562            ipkb = interrupts / ((rxbytes + txbytes) / 1024)
563            printdata(runs, ipkb)
564
565            print 'ipkb user stats'
566            interrupts.bins = 'user'
567            ipkb = interrupts / ((rxbytes + txbytes) / 1024)
568            printdata(runs, ipkb)
569
570            print 'ipkb total stats'
571
572        ipkb = interrupts / ((rxbytes + txbytes) / 1024)
573        interrupts.bins = None
574        if options.graph:
575            graphdata(runs, options, 'ipkb', 'Interrupts / KB',  ipkb)
576        else:
577            printdata(runs, ipkb)
578        return
579
580    if command == 'execute':
581        printdata(runs, system.full_cpu.ISSUE__count)
582        return
583
584    if command == 'commit':
585        printdata(runs, system.full_cpu.COM__count)
586        return
587
588    if command == 'fetch':
589        printdata(runs, system.full_cpu.FETCH__count)
590        return
591
592    if command == 'bpp':
593        ed = system.tsunami.etherdev
594        bpp = (ed.rxBytes + ed.txBytes) / (ed.rxPackets + ed.txPackets)
595        if options.graph:
596            graphdata(runs, options, 'bpp', 'Bytes / Packet',  bpp)
597        else:
598            printdata(runs, bpp)
599        return
600
601    if command == 'rxbpp':
602        bpp = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.rxPackets
603        if options.graph:
604            graphdata(runs, options, 'rxbpp', 'Receive Bytes / Packet',  bpp)
605        else:
606            printdata(runs, bpp)
607        return
608
609    if command == 'txbpp':
610        bpp = system.tsunami.etherdev.txBytes / system.tsunami.etherdev.txPackets
611        if options.graph:
612            graphdata(runs, options, 'txbpp', 'Transmit Bytes / Packet',  bpp)
613        else:
614            printdata(runs, bpp)
615        return
616
617    if command == 'rtp':
618        rtp = system.tsunami.etherdev.rxPackets / system.tsunami.etherdev.txPackets
619        if options.graph:
620            graphdata(runs, options, 'rtp', 'rxPackets / txPackets',  rtp)
621        else:
622            printdata(runs, rtp)
623        return
624
625    if command == 'rtb':
626        rtb = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.txBytes
627        if options.graph:
628            graphdata(runs, options, 'rtb', 'rxBytes / txBytes',  rtb)
629        else:
630            printdata(runs, rtb)
631        return
632
633    raise CommandException
634
635
636class Options: pass
637
638if __name__ == '__main__':
639    import getpass
640
641    options = Options()
642    options.host = 'zizzer.pool'
643    options.db = None
644    options.passwd = ''
645    options.user = getpass.getuser()
646    options.runs = None
647    options.system = 'client'
648    options.get = None
649    options.binned = False
650    options.graph = False
651    options.graph68 = False
652    options.ticks = False
653
654    opts, args = getopts(sys.argv[1:], '-6BEFGd:g:h:pr:s:u:T:')
655    for o,a in opts:
656        if o == '-6':
657            options.graph68 = True
658        if o == '-B':
659            options.binned = True
660        if o == '-E':
661            printval.mode = 'E'
662        if o == '-F':
663            printval.mode = 'F'
664        if o == '-G':
665            options.graph = True;
666        if o == '-d':
667            options.db = a
668        if o == '-g':
669            options.get = a
670        if o == '-h':
671            options.host = a
672        if o == '-p':
673            options.passwd = getpass.getpass()
674        if o == '-r':
675            options.runs = a
676        if o == '-u':
677            options.user = a
678        if o == '-s':
679            options.system = a
680        if o == '-T':
681            options.ticks = a
682
683    if len(args) == 0:
684        usage()
685
686    command = args[0]
687    args = args[1:]
688
689    try:
690        commands(options, command, args)
691    except CommandException:
692        usage()
693