~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to scripts/plot.py

  • Committer: Michael Hope
  • Date: 2010-09-13 08:30:44 UTC
  • mfrom: (14.1.1 cortex-strings)
  • Revision ID: michael.hope@linaro.org-20100913083044-0rr37rigcpd0gg7q
Added autogen.sh.  Tidied up the NEON configure rules using AM_CONDITIONAL.  Made make distcheck pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Plot the results for each test.  Spits out a set of images into the
2
 
current directory.
3
 
"""
4
 
 
5
 
import fileinput
6
 
import collections
7
 
import pprint
8
 
 
9
 
import pylab
10
 
 
11
 
Record = collections.namedtuple('Record', 'variant test size loops alignment rawtime comment time bytes rate')
12
 
 
13
 
def unique(rows, name):
14
 
    """Takes a list of values, pulls out the named field, and returns
15
 
    a list of the unique values of this field.
16
 
    """
17
 
    return sorted(set(getattr(x, name) for x in rows))
18
 
 
19
 
def to_float(v):
20
 
    """Convert a string into a better type.
21
 
 
22
 
    >>> to_float('foo')
23
 
    'foo'
24
 
    >>> to_float('1.23')
25
 
    1.23
26
 
    >>> to_float('45')
27
 
    45
28
 
    """
29
 
    try:
30
 
        if '.' in v:
31
 
            return float(v)
32
 
        else:
33
 
            return int(v)
34
 
    except:
35
 
        return v
36
 
 
37
 
def parse():
38
 
    # Split the input up
39
 
    rows = [x.strip().split(':') for x in fileinput.input()]
40
 
    # Automatically turn numbers into the base type
41
 
    rows = [[to_float(y) for y in x] for x in rows]
42
 
 
43
 
    # Scan once to calculate the overhead
44
 
    r = [Record(*(x + [0, 0, 0])) for x in rows]
45
 
    bounces = pylab.array([(x.loops, x.rawtime) for x in r if x.test == 'bounce'])
46
 
    fit = pylab.polyfit(bounces[:,0], bounces[:,1], 1)
47
 
 
48
 
    records = []
49
 
 
50
 
    for row in rows:
51
 
        # Make a dummy record so we can use the names
52
 
        r1 = Record(*(row + [0, 0, 0]))
53
 
 
54
 
        bytes = r1.size * r1.loops
55
 
        # Calculate the bounce time
56
 
        delta = pylab.polyval(fit, [r1.loops])
57
 
        time = r1.rawtime - delta
58
 
        rate = bytes / time
59
 
 
60
 
        records.append(Record(*(row + [time, bytes, rate])))
61
 
 
62
 
    return records
63
 
 
64
 
def plot(records, field, scale, ylabel):
65
 
    variants = unique(records, 'variant')
66
 
    tests = unique(records, 'test')
67
 
 
68
 
    # A little hack.  We want the 'all' record to be drawn last so
69
 
    # that it's obvious on the graph.  Assume that no tests come
70
 
    # before it alphabetically
71
 
    variants.reverse()
72
 
 
73
 
    for test in tests:
74
 
        for variant in variants:
75
 
            v = [x for x in records if x.test==test and x.variant==variant]
76
 
            v.sort(key=lambda x: x.size)
77
 
            V = pylab.array([(x.size, getattr(x, field)) for x in v])
78
 
 
79
 
            # Ensure our results appear
80
 
            order = 1 if variant == 'this' else 0
81
 
 
82
 
            try:
83
 
                # A little hack.  We want the 'all' to be obvious on
84
 
                # the graph
85
 
                if variant == 'all':
86
 
                    pylab.scatter(V[:,0], V[:,1]/scale, label=variant)
87
 
                    pylab.plot(V[:,0], V[:,1]/scale)
88
 
                else:
89
 
                    pylab.plot(V[:,0], V[:,1]/scale, label=variant, zorder=order)
90
 
 
91
 
            except Exception, ex:
92
 
                # michaelh1 likes to run this script while the test is
93
 
                # still running which can lead to bad data
94
 
                print ex, 'on %s of %s' % (variant, test)
95
 
 
96
 
        pylab.legend(loc='lower right', ncol=2, prop={'size': 'small'})
97
 
        pylab.xlabel('Block size (B)')
98
 
        pylab.ylabel(ylabel)
99
 
        pylab.title('%s %s' % (test, field))
100
 
        pylab.grid()
101
 
 
102
 
        pylab.savefig('%s-%s.png' % (test, field), dpi=100)
103
 
        pylab.semilogx(basex=2)
104
 
        pylab.savefig('%s-%s-semilog.png' % (test, field), dpi=100)
105
 
        pylab.clf()
106
 
 
107
 
def test():
108
 
    import doctest
109
 
    doctest.testmod()
110
 
 
111
 
def main():
112
 
    records = parse()
113
 
 
114
 
    plot(records, 'rate', 1024**2, 'Rate (MB/s)')
115
 
    plot(records, 'time', 1, 'Total time (s)')
116
 
 
117
 
if __name__ == '__main__':
118
 
    main()