summaryrefslogtreecommitdiffstats
path: root/analyze
blob: 3ebb1b47bbb76017404f2df2912c04c90e9d2615 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python

import binary_data as bd
from plot import decode
from oplot import load_outliers

import optparse
import sys
from os.path import splitext

o = optparse.make_option

opts = [
    o('-p', '--cycles-per-usec', action='store', dest='cycles', type='int',
      help='how many cycles per usec'),

    o('-i', '--iqr-extent', action='store', dest='extent', type='float',
      help='what extent to use for outlier removal'),

    o('-c', '--cut-off', action='store', dest='cutoff', type='int',
      help='max number of samples to use'),

    o('-o', '--outlier-list', action='store', dest='outlier_file',
      help='list of outliers to remove'),
    ]

defaults = {
    'cycles'  : 2128,
    'extent'  : 0,
    'cutoff'  : None,
    'outlier_file' : None,
    'outliers' : {},
    }

options = None

def fmt_cell(x):
    if type(x) == str:
        return "%15s" % x
    if type(x) == int:
        return "%15d" % x
    else:
        return "%15.5f" % x

def write_header():
    labels = ["Plugin", "Overhead", "#tasks",
              "#samples", "#filtered",
              "max", "avg", "min", "med", "std", "var",
              "iqr_max", "iqr_min"]
    header = ", ".join(fmt_cell(x) for x in labels)
    print '#%s' % header[1:]


def stats_file(fname):
    name, ext = splitext(fname)
    conf = decode(name)

    scale = 1.0 / options.cycles
    if conf['overhead'] == 'RELEASE-LATENCY':
        scale = 1.0 / 1000 # convert from nanoseconds

    take_off = None
    if options.outlier_file:
        if conf['scheduler'] in options.outliers:
            n = int(conf['n'])
            for (i, t) in options.outliers[conf['scheduler']]:
                if i == n:
                    take_off = t
                    break

    stats = bd.compact_file(fname,
                            extent=options.extent,
                            scale=scale,
                            cutoff=options.cutoff,
                            manual=take_off)
    info = [conf['scheduler'], conf['overhead'], conf['n']]
    print ", ".join([fmt_cell(x) for x in  info + stats])

if __name__ == '__main__':
    parser = optparse.OptionParser(option_list=opts)
    parser.set_defaults(**defaults)
    (options, files) = parser.parse_args()

    try:
        if options.outlier_file:
            options.outliers = load_outliers(options.outlier_file)

        write_header()
        for f in files:
            try:
                stats_file(f)
            except IOError, msg:
                print >> sys.stderr, msg
    except KeyboardInterrupt:
        pass