forked from JoshGelua/Bufferbloat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_ping.py
69 lines (58 loc) · 1.66 KB
/
plot_ping.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
'''
Plot ping RTTs over time
'''
import os, sys
from helper import *
import plot_defaults
from matplotlib.ticker import MaxNLocator
from pylab import figure
parser = argparse.ArgumentParser()
parser.add_argument('--files', '-f',
help="Ping output files to plot",
required=True,
action="store",
nargs='+')
parser.add_argument('--freq',
help="Frequency of pings (per second)",
type=int,
default=10)
parser.add_argument('--out', '-o',
help="Output png file for the plot.",
default=None) # Will show the plot
args = parser.parse_args()
def parse_ping(fname):
ret = []
lines = open(fname).readlines()
num = 0
for line in lines:
if 'bytes from' not in line:
continue
try:
rtt = line.split(' ')[-2]
rtt = rtt.split('=')[1]
rtt = float(rtt)
ret.append([num, rtt])
num += 1
except:
break
return ret
m.rc('figure', figsize=(16, 6))
fig = figure()
ax = fig.add_subplot(111)
for i, f in enumerate(args.files):
data = parse_ping(f)
if len(data) == 0:
print >>sys.stderr, "%s: error: no ping data"%(sys.argv[0])
sys.exit(1)
xaxis = map(float, col(0, data))
start_time = xaxis[0]
xaxis = map(lambda x: (x - start_time) / args.freq, xaxis)
qlens = map(float, col(1, data))
ax.scatter(xaxis, qlens, lw=2)
ax.xaxis.set_major_locator(MaxNLocator(4))
plt.ylabel("RTT (ms)")
plt.grid(True)
if args.out:
plt.savefig(args.out)
else:
plt.show()