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

« back to all changes in this revision

Viewing changes to scripts/libplot.py

  • Committer: Michael Hope
  • Date: 2010-09-13 07:53:58 UTC
  • Revision ID: michael.hope@linaro.org-20100913075358-386yj5lqacpw2hh5
Minor readme update before 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Shared routines for the plotters."""
2
 
 
3
 
import fileinput
4
 
import collections
5
 
 
6
 
Record = collections.namedtuple('Record', 'variant function bytes loops alignment elapsed rest')
7
 
 
8
 
 
9
 
def make_colours():
10
 
    return iter('m b g r c y k pink orange brown grey'.split())
11
 
 
12
 
def parse_value(v):
13
 
    """Turn text into a primitive"""
14
 
    try:
15
 
        if '.' in v:
16
 
            return float(v)
17
 
        else:
18
 
            return int(v)
19
 
    except ValueError:
20
 
        return v
21
 
 
22
 
 
23
 
def unique(records, name, prefer=''):
24
 
    """Return the unique values of a column in the records"""
25
 
    values = list(set(getattr(x, name) for x in records))
26
 
 
27
 
    if not values:
28
 
        return values
29
 
    elif type(values[0]) == str:
30
 
        return sorted(values, key=lambda x: '%-06d|%s' % (-prefer.find(x), x))
31
 
    else:
32
 
        return sorted(values)
33
 
 
34
 
def parse_row(line):
35
 
    return Record(*[parse_value(y) for y in line.split(':')])
36
 
 
37
 
def parse():
38
 
    """Parse a record file into named tuples, correcting for loop
39
 
    overhead along the way.
40
 
    """
41
 
    records = [parse_row(x) for x in fileinput.input()]
42
 
 
43
 
    # Pull out any bounce values
44
 
    costs = {}
45
 
 
46
 
    for record in [x for x in records if x.function=='bounce']:
47
 
        costs[(record.bytes, record.loops)] = record.elapsed
48
 
 
49
 
    # Fix up all of the records for cost
50
 
    out = []
51
 
 
52
 
    for record in records:
53
 
        if record.function == 'bounce':
54
 
            continue
55
 
 
56
 
        cost = costs.get((record.bytes, record.loops), None)
57
 
 
58
 
        if not cost:
59
 
            out.append(record)
60
 
        else:
61
 
            # Unfortunately you can't update a namedtuple...
62
 
            values = list(record)
63
 
            values[-2] -= cost
64
 
            out.append(Record(*values))
65
 
 
66
 
    return out