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