1 | #!/usr/bin/python3 |
---|
2 | import numpy as np |
---|
3 | import re |
---|
4 | import sys, getopt |
---|
5 | import argparse |
---|
6 | |
---|
7 | class Proc: |
---|
8 | def __init__(self, id, name, address): |
---|
9 | self.name = name |
---|
10 | self.address = address |
---|
11 | self.id = id |
---|
12 | |
---|
13 | class Point: |
---|
14 | def __init__(self, time, on): |
---|
15 | self.time = time |
---|
16 | self.on = on |
---|
17 | |
---|
18 | processors = {} |
---|
19 | data = {} |
---|
20 | |
---|
21 | #-------------------------------------------------------------------------------- |
---|
22 | # Parse data |
---|
23 | with open(sys.argv[1], "r") as f: |
---|
24 | for line in f: |
---|
25 | match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line) |
---|
26 | if match : |
---|
27 | id = int(match.group(1)) |
---|
28 | processors[id] = Proc(id, match.group(2), match.group(3)) |
---|
29 | continue |
---|
30 | |
---|
31 | match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line) |
---|
32 | if match : |
---|
33 | id = int(match.group(1)) |
---|
34 | if not id in data: |
---|
35 | data[id] = [] |
---|
36 | data[id].append(Point(int(match.group(2)), int(match.group(3)))) |
---|
37 | continue |
---|
38 | |
---|
39 | print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr) |
---|
40 | |
---|
41 | #-------------------------------------------------------------------------------- |
---|
42 | # Check data |
---|
43 | for d in data: |
---|
44 | if not d in processors: |
---|
45 | print("WARNING : unkown processor '%s'" % d, file=sys.stderr) |
---|
46 | |
---|
47 | prevT = data[d][0].time |
---|
48 | prevO = data[d][0].on |
---|
49 | for p in data[d][1:]: |
---|
50 | if prevT > p.time: |
---|
51 | print("WARNING : Time is inconsistant for Proc '%s'" % d, file=sys.stderr) |
---|
52 | |
---|
53 | if prevO == p.on: |
---|
54 | print("WARNING : State is inconsistant for Proc '%s' at %s-%s" % (d, prevT, p.time), file=sys.stderr) |
---|
55 | |
---|
56 | prevT = p.time |
---|
57 | prevO = p.on |
---|
58 | |
---|
59 | |
---|
60 | #-------------------------------------------------------------------------------- |
---|
61 | # Convert data to series |
---|
62 | offset = min(data) |
---|
63 | print(offset) |
---|
64 | |
---|
65 | series=dict() ## dict of pairs of arrays |
---|
66 | for d in data: |
---|
67 | series[d] = ([], [], []) |
---|
68 | for p in data[d]: |
---|
69 | series[d][0].append( p.time ) |
---|
70 | series[d][1].append(p.on + d - offset) |
---|
71 | series[d][2].append(d - offset) |
---|
72 | |
---|
73 | #-------------------------------------------------------------------------------- |
---|
74 | # setup matplotlib |
---|
75 | import matplotlib as mpl |
---|
76 | mpl.use('Agg') |
---|
77 | import matplotlib.pyplot as plt |
---|
78 | import matplotlib.ticker as ticker |
---|
79 | plt.style.use('dark_background') |
---|
80 | |
---|
81 | #-------------------------------------------------------------------------------- |
---|
82 | # setup plot |
---|
83 | dots_per_inch = 2000 |
---|
84 | height_inches = 5 |
---|
85 | width_inches = 12 |
---|
86 | fig = plt.figure(figsize=(width_inches, height_inches), dpi=dots_per_inch) |
---|
87 | print('number of series={}'.format(len(series))) |
---|
88 | for s, xy in series.items(): |
---|
89 | print(' plotting series {} with {} points'.format(s, len(xy[0]))) |
---|
90 | plt.fill_between(xy[0], xy[1], xy[2], step="post", alpha=0.4) |
---|
91 | plt.step(xy[0], xy[1], where='post') |
---|
92 | |
---|
93 | #-------------------------------------------------------------------------------- |
---|
94 | # y axis major, minor |
---|
95 | ax = plt.gca() |
---|
96 | ax.grid(which='major', axis='y', linestyle='-', color='lightgray') |
---|
97 | ax.yaxis.set_minor_locator(ticker.AutoMinorLocator()) |
---|
98 | ax.grid(which='minor', axis='y', linestyle='dotted', color='gray') |
---|
99 | |
---|
100 | #-------------------------------------------------------------------------------- |
---|
101 | # x axis major, minor |
---|
102 | ax.grid(which='major', axis='x', linestyle='-', color='lightgray') |
---|
103 | ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) |
---|
104 | ax.grid(which='minor', axis='x', linestyle='dotted', color='gray') |
---|
105 | |
---|
106 | #-------------------------------------------------------------------------------- |
---|
107 | # do the plot |
---|
108 | plt.tight_layout() |
---|
109 | print("saving figure image %s\n" % "out.svg") |
---|
110 | plt.savefig("out.svg") |
---|