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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/usr/bin/python
from pylab import *
import sys
class Point:
def __init__(self, t, a):
self.time = t
self.awake = a
decoder = []
writer = []
encoder = dict()
f = open(sys.argv[1], 'r')
for l in f.readlines():
l = l.strip()
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] == 'decoder' and s[2] == 'sleeps':
decoder.append(Point(secs, False))
elif s[1] == 'decoder' and s[2] == 'wakes':
decoder.append(Point(secs, True))
elif s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'finishes':
if s[3] not in encoder:
print 'new encoder %s' % s[3]
encoder[s[3]] = []
encoder[str(s[3])].append(Point(secs, False))
elif s[1] == 'encoder' and s[2] == 'thread' and s[4] == 'begins':
if s[3] not in encoder:
print 'new encoder %s' % s[3]
encoder[s[3]] = []
encoder[s[3]].append(Point(secs, True))
elif s[1] == 'writer' and s[2] == 'sleeps':
writer.append(Point(secs, False))
elif s[1] == 'writer' and s[2] == 'wakes':
writer.append(Point(secs, True))
def do_a_plot(points, tit, pos):
x = []
y = []
awake = False
for p in points:
if p.awake != awake:
x.append(p.time)
y.append(int(awake) + pos)
x.append(p.time)
y.append(int(p.awake) + pos)
awake = p.awake
plot(x, y)
# fill_between(x, y, 0, color='0.8')
title(tit)
figure()
N = len(encoder) + 2
do_a_plot(decoder, 'dec', 0)
do_a_plot(writer, 'wri', 1)
encoder_list = []
for k, v in encoder.iteritems():
encoder_list.append(v)
print len(encoder_list)
y = 2
for e in encoder_list:
do_a_plot(e, 'enc', y)
y += 1
show()
|