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