Add failing test for one short-reel possibility.
[dcpomatic.git] / hacks / optimise / plotlog
1 #!/usr/bin/python
2
3 from pylab import *
4 import sys
5
6 class Point:
7     def __init__(self, t, a):
8         self.time = t
9         self.awake = a
10
11 decoder = []
12 writer = []
13 encoder = dict()
14
15 f = open(sys.argv[1], 'r')
16 for l in f.readlines():
17     l = l.strip()
18     s = l.split()
19     if len(s) == 0:
20         continue
21
22     t = s[0].split(':')
23     if len(t) != 2:
24         continue
25
26     secs = float(t[0]) + float(t[1]) / 1e6
27     if s[1] == 'decoder' and s[2] == 'sleeps':
28         decoder.append(Point(secs, False))
29     elif s[1] == 'decoder' and s[2] == 'wakes':
30         decoder.append(Point(secs, True))
31     elif s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'finishes':
32         if s[3] not in encoder:
33             print 'new encoder %s' % s[3]
34             encoder[s[3]] = []
35         encoder[str(s[3])].append(Point(secs, False))
36     elif s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'begins':
37         if s[3] not in encoder:
38             print 'new encoder %s' % s[3]
39             encoder[s[3]] = []
40         encoder[s[3]].append(Point(secs, True))
41     elif s[1] == 'writer' and s[2] == 'sleeps':
42         writer.append(Point(secs, False))
43     elif s[1] == 'writer' and s[2] == 'wakes':
44         writer.append(Point(secs, True))
45
46 def do_a_plot(points, tit, pos):
47     x = []
48     y = []
49     awake = False
50     for p in points:
51         if p.awake != awake:
52             x.append(p.time)
53             y.append(int(awake) + pos)
54             x.append(p.time)
55             y.append(int(p.awake) + pos)
56             awake = p.awake
57
58     plot(x, y)
59 #    fill_between(x, y, 0, color='0.8')
60     title(tit)
61
62 figure()
63
64 N = len(encoder) + 2
65
66 do_a_plot(decoder, 'dec', 0)
67 do_a_plot(writer, 'wri', 1)
68
69 encoder_list = []
70 for k, v in encoder.iteritems():
71     encoder_list.append(v)
72
73 print len(encoder_list)
74
75 y = 2
76 for e in encoder_list:
77     do_a_plot(e, 'enc', y)
78     y += 1
79
80 show()