Remove in-place translations support.
[dcpomatic.git] / hacks / optimise / analog
1 #!/usr/bin/python
2
3 import sys
4
5 class Encoder:
6       def __init__(self):
7             self.awake = 0
8             self.asleep = 0
9             self.last_event = 0
10             self.state = None
11
12 encoders = dict()
13
14 f = open(sys.argv[1], 'r')
15 while 1:
16       l = f.readline()
17       if l == '':
18          break
19
20       s = l.split()
21       if len(s) == 0:
22             continue
23
24       t = s[0].split(':')
25       if len(t) != 2:
26             continue
27
28       secs = float(t[0]) + float(t[1]) / 1e6
29       if s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'finishes':
30             tid = s[3]
31             if not tid in encoders:
32                   encoders[tid] = Encoder()
33
34             assert(encoders[tid].state == None or encoders[tid].state == 'awake')
35             if encoders[tid].state == 'awake':
36                   encoders[tid].awake += (secs - encoders[tid].last_event)
37
38             encoders[tid].state = 'asleep'
39             encoders[tid].last_event = secs
40
41       elif s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'begins':
42             tid = s[3]
43             if not tid in encoders:
44                   encoders[tid] = Encoder()
45
46             if encoders[tid].state is not None:
47                   encoders[tid].asleep += (secs - encoders[tid].last_event)
48
49             encoders[tid].state = 'awake'
50             encoders[tid].last_event = secs
51
52 for k, v in encoders.iteritems():
53       print '%s: awake %f asleep %f' % (k, v.awake, v.asleep)