/
parser_stats.py
executable file
·115 lines (72 loc) · 2.43 KB
/
parser_stats.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2012 IKT Leibniz Universitaet Hannover
# GPL2
# Zdravko Bozakov (zb@ikt.uni-hannover.de)
import os
import sys
import threading
import time
from numpy import *
import hphelper
options = hphelper.options
DEBUG = hphelper.DEBUG
ERROR = hphelper.err
def plot_hist(rtts):
import hplotting
gp = hplotting.gp_plotter(loglog=False)
data = '\n'.join(['%.6f' % rtt for rtt in rtts])
gp.setup(xlabel='bin width = 1e-6 s')
gp.cmd('binwidth=1e-6')
gp.cmd('set boxwidth binwidth')
gp.cmd('bin(x,width)=width*floor(x/width) + binwidth/2.0')
gp.cmd("plot '-' using (bin($1,binwidth)):(1.0) smooth freq with boxes\n %s\n e" % (data), flush=True)
gp.quit()
def statsparser(pipe, ns, slottimes=None):
hphelper.set_affinity('parser')
DEBUG('starting parser ', __name__)
#block until sender + receiver say they are ready
while not all([ns.RCV_READY,ns.SND_READY]):
time.sleep(0.1)
stats = hphelper.stats_stats()
# init empty array to store RTTs for histogram
rtts = -1.0*ones(options.pnum)
# start progress bar thread
hphelper.bar_init(options, stats, ns.cnum)
run_start = time.time()
while 1:
try:
data = pipe.recv()
if data == 'RCV_DONE':
break
(seq, currslot, rtt) = data
if currslot == -1:
rtt = -1
stats.snd_err += 1
continue
stats.update(seq, rtt, currslot)
if rtt<stats.min_rtt:
stats.min_rtt = rtt
rtts[seq] = rtt
except (KeyboardInterrupt) as e:
print 'parser canceled'
except (ValueError) as e:
print e
print 'done writing'
except (IndexError) as e:
print e, seq
pass ### TODO last sequence number causes error
# omit invalid rtts
rtts = rtts[rtts!=-1]
if not any(rtts):
ns.FATAL_ERROR = True
ERROR("could not calculate average delay")
# store mean RTT for use in other modules
ns.mean_rtt = mean(rtts)
stats.append_stats(median=('RTT median','%.6f' % median(rtts)),
std=('RTT std. dev.','%.6f' % std(rtts)),
#min=('min RTT','%.6f' % min(rtts)),
max=('RTT maximum','%.6f' % max(rtts)),
)
stats.pprint()
if options.hist:
plot_hist(rtts)
return