stats.py revision 1209
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', 'b' ]
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 = '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    if type(options.get) is str:
136        info.source.get = options.get
137
138    if options.runs is None:
139        runs = info.source.allRuns
140    else:
141        rx = re.compile(options.runs)
142        runs = []
143        for run in info.source.allRuns:
144            if rx.match(run.name):
145                runs.append(run)
146
147    info.display_run = runs[0].run
148
149    if command == 'runs':
150        user = None
151        opts, args = getopts(args, '-u')
152        if len(args):
153            raise CommandException
154        for o,a in opts:
155            if o == '-u':
156                user = a
157        info.source.listRuns(user)
158        return
159
160    if command == 'stats':
161        if len(args) == 0:
162            info.source.listStats()
163        elif len(args) == 1:
164            info.source.listStats(args[0])
165        else:
166            raise CommandException
167
168        return
169
170    if command == 'stat':
171        if len(args) != 1:
172            raise CommandException
173
174        stats = info.source.getStat(args[0])
175        for stat in stats:
176            if options.graph:
177                graphdata(runs, stat.name, stat.name, stat)
178            else:
179                if options.binned:
180                    print 'kernel ticks'
181                    stat.bins = 'kernel'
182                    printdata(runs, stat)
183
184                    print 'idle ticks'
185                    stat.bins = 'idle'
186                    printdata(runs, stat)
187
188                    print 'user ticks'
189                    stat.bins = 'user'
190                    printdata(runs, stat)
191
192                    print 'interrupt ticks'
193                    stat.bins = 'user'
194                    printdata(runs, stat)
195
196                    print 'total ticks'
197
198                stat.bins = None
199                print stat.name
200                printdata(runs, stat)
201        return
202
203    if command == 'bins':
204        if len(args) == 0:
205            info.source.listBins()
206        elif len(args) == 1:
207            info.source.listBins(args[0])
208        else:
209            raise CommandException
210
211        return
212
213    if command == 'formulas':
214        if len(args) == 0:
215            info.source.listFormulas()
216        elif len(args) == 1:
217            info.source.listFormulas(args[0])
218        else:
219            raise CommandException
220
221        return
222
223    if command == 'samples':
224        if len(args):
225            raise CommandException
226
227        info.source.listTicks(runs)
228        return
229
230    if len(args):
231        raise CommandException
232
233    system = info.source.__dict__[options.system]
234
235    if command == 'usertime':
236        import copy
237        kernel = copy.copy(system.full_cpu.numCycles)
238        kernel.bins = 'kernel'
239
240        user = copy.copy(system.full_cpu.numCycles)
241        user.bins = 'user'
242
243        if options.graph:
244            graphdata(runs, 'usertime', 'User Fraction',
245                      user / system.full_cpu.numCycles)
246        else:
247            printdata(runs, user / system.full_cpu.numCycles)
248        return
249
250    if command == 'ticks':
251        if options.binned:
252            print 'kernel ticks'
253            system.full_cpu.numCycles.bins = 'kernel'
254            printdata(runs, system.full_cpu.numCycles)
255
256            print 'idle ticks'
257            system.full_cpu.numCycles.bins = 'idle'
258            printdata(runs, system.full_cpu.numCycles)
259
260            print 'user ticks'
261            system.full_cpu.numCycles.bins = 'user'
262            printdata(runs, system.full_cpu.numCycles)
263
264            print 'total ticks'
265
266        system.full_cpu.numCycles.bins = None
267        printdata(runs, system.full_cpu.numCycles)
268        return
269
270    if command == 'packets':
271        packets = system.tsunami.etherdev.rxPackets
272        if options.graph:
273            graphdata(runs, 'packets', 'Packets', packets)
274        else:
275            printdata(runs, packets)
276        return
277
278    if command == 'ppt' or command == 'tpp':
279        ppt = system.tsunami.etherdev.rxPackets / sim_ticks
280        printdata(runs, ppt, command == 'tpp')
281        return
282
283    if command == 'pps':
284        pps = system.tsunami.etherdev.rxPackets / sim_seconds
285        if options.graph:
286            graphdata(runs, 'pps', 'Packets/s', pps)
287        else:
288            printdata(runs, pps)
289        return
290
291    if command == 'bpt' or command == 'tpb':
292        bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
293        bpt = bytes / sim_ticks * 8
294        if options.graph:
295            graphdata(runs, 'bpt', 'bps / Hz', bpt)
296        else:
297            printdata(runs, bpt, command == 'tpb')
298        return
299
300    if command == 'bptb' or command == 'tpbb':
301        bytes = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
302
303        print 'kernel stats'
304        bytes.bins = 'kernel'
305        printdata(runs, bytes / ticks)
306
307        print 'idle stats'
308        bytes.bins = 'idle'
309        printdata(runs, bytes / ticks)
310
311        print 'user stats'
312        bytes.bins = 'user'
313        printdata(runs, bytes / ticks)
314
315        return
316
317    if command == 'bytes':
318        stat = system.tsunami.etherdev.rxBytes + system.tsunami.etherdev.txBytes
319
320        if options.binned:
321            print '%s kernel stats' % stat.name
322            stat.bins = 'kernel'
323            printdata(runs, stat)
324
325            print '%s idle stats' % stat.name
326            stat.bins = 'idle'
327            printdata(runs, stat)
328
329            print '%s user stats' % stat.name
330            stat.bins = 'user'
331            printdata(runs, stat)
332
333            print '%s total stats' % stat.name
334            stat.bins = None
335
336        printdata(runs, stat)
337        return
338
339    if command == 'rxbps':
340        gbps = system.tsunami.etherdev.rxBandwidth / 1e9
341        if options.graph:
342            graphdata(runs, 'rxbps', 'Bandwidth (Gbps)',  gbps)
343        else:
344            printdata(runs, gbps)
345        return
346
347    if command == 'txbps':
348        gbps = system.tsunami.etherdev.txBandwidth / 1e9
349        if options.graph:
350            graphdata(runs, 'txbps', 'Bandwidth (Gbps)',  gbps)
351        else:
352            printdata(runs, gbps)
353        return
354
355    if command == 'bps':
356        rxbps = system.tsunami.etherdev.rxBandwidth
357        txbps = system.tsunami.etherdev.txBandwidth
358        gbps = (rxbps + txbps) / 1e9
359        if options.graph:
360            graphdata(runs, 'bps', 'Bandwidth (Gbps)',  gbps)
361        else:
362            printdata(runs, gbps)
363        return
364
365    if command == 'misses':
366        stat = system.L2.overall_mshr_misses
367        if options.binned:
368            print '%s kernel stats' % stat.name
369            stat.bins = 'kernel'
370            printdata(runs, stat)
371
372            print '%s idle stats' % stat.name
373            stat.bins = 'idle'
374            printdata(runs, stat)
375
376            print '%s user stats' % stat.name
377            stat.bins = 'user'
378            printdata(runs, stat)
379
380            print '%s total stats' % stat.name
381
382        stat.bins = None
383        if options.graph:
384            graphdata(runs, 'misses', 'Overall MSHR Misses', stat)
385        else:
386            printdata(runs, stat)
387        return
388
389    if command == 'mpkb':
390        misses = system.L2.overall_mshr_misses
391        rxbytes = system.tsunami.etherdev.rxBytes
392        txbytes = system.tsunami.etherdev.txBytes
393
394        if options.binned:
395            print 'mpkb kernel stats'
396            misses.bins = 'kernel'
397            mpkb = misses / ((rxbytes + txbytes) / 1024)
398            printdata(runs, mpkb)
399
400            print 'mpkb idle stats'
401            misses.bins = 'idle'
402            mpkb = misses / ((rxbytes + txbytes) / 1024)
403            printdata(runs, mpkb)
404
405            print 'mpkb user stats'
406            misses.bins = 'user'
407            mpkb = misses / ((rxbytes + txbytes) / 1024)
408            printdata(runs, mpkb)
409
410            print 'mpkb total stats'
411
412        mpkb = misses / ((rxbytes + txbytes) / 1024)
413        misses.bins = None
414        if options.graph:
415            graphdata(runs, 'mpkb', 'Misses / KB',  mpkb)
416        else:
417            printdata(runs, mpkb)
418        return
419
420    if command == 'execute':
421        printdata(runs, system.full_cpu.ISSUE__count)
422        return
423
424    if command == 'commit':
425        printdata(runs, system.full_cpu.COM__count)
426        return
427
428    if command == 'fetch':
429        printdata(runs, system.full_cpu.FETCH__count)
430        return
431
432    if command == 'bpp':
433        ed = system.tsunami.etherdev
434        bpp = (ed.rxBytes + ed.txBytes) / (ed.rxPackets + ed.txPackets)
435        if options.graph:
436            graphdata(runs, 'bpp', 'Bytes / Packet',  bpp)
437        else:
438            printdata(runs, bpp)
439        return
440
441    if command == 'rxbpp':
442        bpp = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.rxPackets
443        if options.graph:
444            graphdata(runs, 'rxbpp', 'Receive Bytes / Packet',  bpp)
445        else:
446            printdata(runs, bpp)
447        return
448
449    if command == 'txbpp':
450        bpp = system.tsunami.etherdev.txBytes / system.tsunami.etherdev.txPackets
451        if options.graph:
452            graphdata(runs, 'txbpp', 'Transmit Bytes / Packet',  bpp)
453        else:
454            printdata(runs, bpp)
455        return
456
457    if command == 'rtp':
458        rtp = system.tsunami.etherdev.rxPackets / system.tsunami.etherdev.txPackets
459        if options.graph:
460            graphdata(runs, 'rtp', 'rxPackets / txPackets',  rtp)
461        else:
462            printdata(runs, rtp)
463        return
464
465    if command == 'rtb':
466        rtb = system.tsunami.etherdev.rxBytes / system.tsunami.etherdev.txBytes
467        if options.graph:
468            graphdata(runs, 'rtb', 'rxBytes / txBytes',  rtb)
469        else:
470            printdata(runs, rtb)
471        return
472
473    raise CommandException
474
475
476class Options: pass
477
478if __name__ == '__main__':
479    import getpass
480
481    options = Options()
482    options.host = 'zizzer.pool'
483    options.db = None
484    options.passwd = ''
485    options.user = getpass.getuser()
486    options.runs = None
487    options.system = 'client'
488    options.get = None
489    options.binned = False
490    options.graph = False
491
492    opts, args = getopts(sys.argv[1:], '-BEFGd:g:h:pr:s:u:')
493    for o,a in opts:
494        if o == '-B':
495            options.binned = True
496        if o == '-E':
497            printval.mode = 'E'
498        if o == '-F':
499            printval.mode = 'F'
500        if o == '-G':
501            options.graph = True;
502        if o == '-d':
503            options.db = a
504        if o == '-g':
505            options.get = a
506        if o == '-h':
507            options.host = a
508        if o == '-p':
509            options.passwd = getpass.getpass()
510        if o == '-r':
511            options.runs = a
512        if o == '-u':
513            options.user = a
514        if o == '-s':
515            options.system = a
516
517    if len(args) == 0:
518        usage()
519
520    command = args[0]
521    args = args[1:]
522
523    try:
524        commands(options, command, args)
525    except CommandException:
526        usage()
527