stats.py revision 1049
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 = ['std', 'csa', 'ht1', 'ht4', 'htx', 'ocm', 'occ', 'ocp' ]
45    benchmarks = [ 'm', 's' ]
46    dmas = [ 'x', 'd', 'b' ]
47    caches = [ '1', '2', '3', '4', '5' ]
48    systems = [ 'M' ]
49    checkpoints = [ '1' ]
50
51    names = []
52    for bench in benchmarks:
53        for dma in dmas:
54            for cache in caches:
55                for sys in systems:
56                    for cpt in checkpoints:
57                        names.append([bench, dma, cache, sys, cpt])
58
59    for bench,dma,cache,sys,cpt in names:
60        base = '%s.%s.%s.%s.%s' % (bench, dma, cache, sys, cpt)
61        fname = '/n/ziff/z/binkertn/graph/data.ibm/%s.%s.dat' % (tag, base)
62        f = open(fname, 'w')
63        print >>f, '#set TITLE = %s' % base
64        print >>f, '#set xlbl = Configuration'
65        print >>f, '#set ylbl = %s' % label
66        print >>f, '#set sublabels = %s' % ' '.join(configs)
67
68        for speed,freq in zip(['s', 'q'],['4GHz','10GHz']):
69            print >>f, '"%s"' % freq,
70            for conf in configs:
71                name = '%s.%s.%s.%s.%s.%s.%s' % (conf, bench, dma, speed,
72                                                 cache, sys, cpt)
73                run = info.source.allRunNames[name]
74                info.display_run = run.run;
75                val = float(value)
76                if val == 1e300*1e300:
77                    print >>f, 0.0,
78                else:
79                    print >>f, "%f" % val,
80            print >>f
81        f.close()
82
83def printdata(runs, value, invert = False):
84    import info
85    for run in runs:
86        info.display_run = run.run;
87        val = float(value)
88        printval(run.name, val)
89
90class CommandException(Exception):
91    pass
92
93def commands(options, command, args):
94    if command == 'database':
95        if len(args) == 0: raise CommandException
96
97        import dbinit
98        mydb = dbinit.MyDB(options)
99
100        if args[0] == 'drop':
101            if len(args) > 2: raise CommandException
102            mydb.admin()
103            mydb.drop()
104            if len(args) == 2 and args[1] == 'init':
105                mydb.create()
106                mydb.connect()
107                mydb.populate()
108            mydb.close()
109            return
110
111        if args[0] == 'init':
112            if len(args) > 1: raise CommandException
113            mydb.admin()
114            mydb.create()
115            mydb.connect()
116            mydb.populate()
117            mydb.close()
118            return
119
120        if args[0] == 'clean':
121            if len(args) > 1: raise CommandException
122            mydb.connect()
123            mydb.clean()
124            return
125
126        raise CommandException
127
128    import db, info
129    info.source = db.Database()
130    info.source.host = options.host
131    info.source.db = options.db
132    info.source.passwd = options.passwd
133    info.source.user = options.user
134    info.source.connect()
135    info.source.update_dict(globals())
136
137    system = info.source.__dict__[options.system]
138
139    if type(options.get) is str:
140        info.source.get = options.get
141
142    if options.runs is None:
143        runs = info.source.allRuns
144    else:
145        rx = re.compile(options.runs)
146        runs = []
147        for run in info.source.allRuns:
148            if rx.match(run.name):
149                runs.append(run)
150
151    info.display_run = runs[0].run
152
153    if command == 'runs':
154        user = None
155        opts, args = getopts(args, '-u')
156        if len(args):
157            raise CommandException
158        for o,a in opts:
159            if o == '-u':
160                user = a
161        info.source.listRuns(user)
162        return
163
164    if command == 'stats':
165        if len(args) == 0:
166            info.source.listStats()
167        elif len(args) == 1:
168            info.source.listStats(args[0])
169        else:
170            raise CommandException
171
172        return
173
174    if command == 'stat':
175        if len(args) != 1:
176            raise CommandException
177
178        stats = info.source.getStat(args[0])
179        for stat in stats:
180            if graph:
181                graphdata(runs, stat.name, stat.name, stat)
182            else:
183                print stat.name
184                printdata(runs, stat)
185        return
186
187    if command == 'bins':
188        if len(args) == 0:
189            info.source.listBins()
190        elif len(args) == 1:
191            info.source.listBins(args[0])
192        else:
193            raise CommandException
194
195        return
196
197    if command == 'formulas':
198        if len(args) == 0:
199            info.source.listFormulas()
200        elif len(args) == 1:
201            info.source.listFormulas(args[0])
202        else:
203            raise CommandException
204
205        return
206
207    if command == 'samples':
208        if len(args):
209            raise CommandException
210
211        info.source.listTicks(runs)
212        return
213
214    if len(args):
215        raise CommandException
216
217    if command == 'usertime':
218        import copy
219        kernel = copy.copy(system.full_cpu.numCycles)
220        kernel.bins = 'kernel'
221
222        user = copy.copy(system.full_cpu.numCycles)
223        user.bins = 'user'
224
225        if graph:
226            graphdata(runs, 'usertime', 'User Fraction',
227                      user / system.full_cpu.numCycles)
228        else:
229            printdata(runs, user / system.full_cpu.numCycles)
230        return
231
232    if command == 'ticks':
233        if binned:
234            print 'kernel ticks'
235            system.full_cpu.numCycles.bins = 'kernel'
236            printdata(runs, system.full_cpu.numCycles)
237
238            print 'idle ticks'
239            system.full_cpu.numCycles.bins = 'idle'
240            printdata(runs, system.full_cpu.numCycles)
241
242            print 'user ticks'
243            system.full_cpu.numCycles.bins = 'user'
244            printdata(runs, system.full_cpu.numCycles)
245
246            print 'total ticks'
247
248        system.full_cpu.numCycles.bins = None
249        printdata(runs, system.full_cpu.numCycles)
250        return
251
252    if command == 'packets':
253        packets = system.tsunami.nsgige.rxPackets
254        if graph:
255            graphdata(runs, 'packets', 'Packets', packets)
256        else:
257            printdata(runs, packets)
258        return
259
260    if command == 'ppt' or command == 'tpp':
261        ppt = system.tsunami.nsgige.rxPackets / sim_ticks
262        printdata(runs, ppt, command == 'tpp')
263        return
264
265    if command == 'pps':
266        pps = system.tsunami.nsgige.rxPackets / sim_seconds
267        if graph:
268            graphdata(runs, 'pps', 'Packets/s', pps)
269        else:
270            printdata(runs, pps)
271        return
272
273    if command == 'bpt' or command == 'tpb':
274        bytes = system.tsunami.nsgige.rxBytes + system.tsunami.nsgige.txBytes
275        bpt = bytes / sim_ticks * 8
276        if graph:
277            graphdata(runs, 'bpt', 'bps / Hz', bpt)
278        else:
279            printdata(runs, bpt, command == 'tpb')
280        return
281
282    if command == 'bptb' or command == 'tpbb':
283        bytes = system.tsunami.nsgige.rxBytes + system.tsunami.nsgige.txBytes
284
285        print 'kernel stats'
286        bytes.bins = 'kernel'
287        printdata(runs, bytes / ticks)
288
289        print 'idle stats'
290        bytes.bins = 'idle'
291        printdata(runs, bytes / ticks)
292
293        print 'user stats'
294        bytes.bins = 'user'
295        printdata(runs, bytes / ticks)
296
297        return
298
299    if command == 'bytes':
300        stat = system.tsunami.nsgige.rxBytes + system.tsunami.nsgige.txBytes
301
302        if binned:
303            print '%s kernel stats' % stat.name
304            stat.bins = 'kernel'
305            printdata(runs, stat)
306
307            print '%s idle stats' % stat.name
308            stat.bins = 'idle'
309            printdata(runs, stat)
310
311            print '%s user stats' % stat.name
312            stat.bins = 'user'
313            printdata(runs, stat)
314
315            print '%s total stats' % stat.name
316            stat.bins = None
317
318        printdata(runs, stat)
319        return
320
321    if command == 'rxbps':
322        gbps = system.tsunami.nsgige.rxBandwidth / 1e9
323        if graph:
324            graphdata(runs, 'rxbps', 'Bandwidth (Gbps)',  gbps)
325        else:
326            printdata(runs, gbps)
327        return
328
329    if command == 'txbps':
330        gbps = system.tsunami.nsgige.txBandwidth / 1e9
331        if graph:
332            graphdata(runs, 'txbps', 'Bandwidth (Gbps)',  gbps)
333        else:
334            printdata(runs, gbps)
335        return
336
337    if command == 'bps':
338        rxbps = system.tsunami.nsgige.rxBandwidth
339        txbps = system.tsunami.nsgige.txBandwidth
340        gbps = (rxbps + txbps) / 1e9
341        if graph:
342            graphdata(runs, 'bps', 'Bandwidth (Gbps)',  gbps)
343        else:
344            printdata(runs, gbps)
345        return
346
347    if command == 'misses':
348        stat = system.L3.overall_mshr_misses
349        if binned:
350            print '%s kernel stats' % stat.name
351            stat.bins = 'kernel'
352            printdata(runs, stat)
353
354            print '%s idle stats' % stat.name
355            stat.bins = 'idle'
356            printdata(runs, stat)
357
358            print '%s user stats' % stat.name
359            stat.bins = 'user'
360            printdata(runs, stat)
361
362            print '%s total stats' % stat.name
363
364        stat.bins = None
365        if graph:
366            graphdata(runs, 'misses', 'Overall MSHR Misses', stat)
367        else:
368            printdata(runs, stat)
369        return
370
371    if command == 'mpkb':
372        misses = system.L3.overall_mshr_misses
373        rxbytes = system.tsunami.nsgige.rxBytes
374        txbytes = system.tsunami.nsgige.txBytes
375
376        if binned:
377            print 'mpkb kernel stats'
378            misses.bins = 'kernel'
379            mpkb = misses / ((rxbytes + txbytes) / 1024)
380            printdata(runs, mpkb)
381
382            print 'mpkb idle stats'
383            misses.bins = 'idle'
384            mpkb = misses / ((rxbytes + txbytes) / 1024)
385            printdata(runs, mpkb)
386
387            print 'mpkb user stats'
388            misses.bins = 'user'
389            mpkb = misses / ((rxbytes + txbytes) / 1024)
390            printdata(runs, mpkb)
391
392            print 'mpkb total stats'
393
394        mpkb = misses / ((rxbytes + txbytes) / 1024)
395        misses.bins = None
396        if graph:
397            graphdata(runs, 'mpkb', 'Misses / KB',  mpkb)
398        else:
399            printdata(runs, mpkb)
400        return
401
402    if command == 'execute':
403        printdata(runs, system.full_cpu.ISSUE__count)
404        return
405
406    if command == 'commit':
407        printdata(runs, system.full_cpu.COM__count)
408        return
409
410    if command == 'fetch':
411        printdata(runs, system.full_cpu.FETCH__count)
412        return
413
414    if command == 'rxbpp':
415        bpp = system.tsunami.nsgige.rxBytes / system.tsunami.nsgige.rxPackets
416        printdata(run, 8 * bpp)
417        return
418
419    if command == 'txbpp':
420        bpp = system.tsunami.nsgige.txBytes / system.tsunami.nsgige.txPackets
421        printdata(run, 8 * bpp)
422        return
423
424    raise CommandException
425
426
427graph = False
428binned = False
429
430class Options: pass
431
432if __name__ == '__main__':
433    import getpass
434
435    options = Options()
436    options.host = 'zizzer.pool'
437    options.db = None
438    options.passwd = ''
439    options.user = getpass.getuser()
440    options.runs = None
441    options.system = 'client'
442    options.get = None
443
444    opts, args = getopts(sys.argv[1:], '-BEFGd:g:h:pr:s:u:')
445    for o,a in opts:
446        if o == '-B':
447            options.binned = True
448        if o == '-E':
449            printval.mode = 'E'
450        if o == '-F':
451            printval.mode = 'F'
452        if o == '-G':
453            options.graph = True;
454        if o == '-d':
455            options.db = a
456        if o == '-g':
457            options.get = a
458        if o == '-h':
459            options.host = a
460        if o == '-p':
461            options.passwd = getpass.getpass()
462        if o == '-r':
463            options.runs = a
464        if o == '-u':
465            options.user = a
466        if o == '-s':
467            options.system = a
468
469    if len(args) == 0:
470        usage()
471
472    command = args[0]
473    args = args[1:]
474
475    try:
476        commands(options, command, args)
477    except CommandException:
478        usage()
479