forked from bbbrumley/portsmash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_raw_simple.py
49 lines (38 loc) · 1015 Bytes
/
parse_raw_simple.py
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
import sys
import array
import numpy as np
import matplotlib.pyplot as plt
CEIL = 511
def normalize(x):
if x > CEIL: x = CEIL
if x < 0: x = CEIL
return x
def running_mean(x, N):
cumsum = np.cumsum(np.insert(x, 0, 0))
return (cumsum[N:] - cumsum[:-N]) / N
try:
fp = open(sys.argv[1])
except:
print "Usage: python %s <timings.bin>" % (sys.argv[0])
sys.exit(1)
out = fp.read()
fp.close()
timings = array.array('I')
timings.fromstring(out)
lats = []
for i in range(0,len(timings),2):
lats.append(timings[i+1]-timings[i])
lats = map(normalize, lats)
ma2 = running_mean(lats, 2)
ma4 = running_mean(lats, 4)
ma8 = running_mean(lats, 8)
params = {'fillstyle':'full','markeredgewidth':0.0,'ms':4.0}
f, axarr = plt.subplots(4, sharex=True, sharey=True)
# plot the trace
axarr[0].plot(lats,**params)
# plot the moving average trade
axarr[1].plot(ma2,**params)
axarr[2].plot(ma4,**params)
axarr[3].plot(ma8,**params)
plt.get_current_fig_manager().full_screen_toggle()
plt.show()