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