-
Notifications
You must be signed in to change notification settings - Fork 0
/
ns3_plot.py
executable file
·180 lines (142 loc) · 6.12 KB
/
ns3_plot.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
import argparse
import datetime
import json
import os
import re
import sys
import matplotlib.pyplot as plt
import numpy as np
import yaml
class Interval:
def __call__(self, string):
match = re.fullmatch(r"(?P<l>\d+\.?\d*?),(?P<h>\d+\.?\d*?)$", string.strip())
if not match:
raise argparse.ArgumentTypeError('Interval must be of form a,b')
try:
return float(match.group('l')), float(match.group('h'))
except:
raise argparse.ArgumentTypeError('Cannot convert interval values to float')
def deep_set(d, a, b, v):
s = d.get(a, {})
l = s.get(b, [])
l.append(v)
s[b] = l
d[a] = s
parser = argparse.ArgumentParser(description='Plots results from a result file')
parser.add_argument('file', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
subparsers = parser.add_subparsers(help='plot type help', dest='plot_type')
dct_ratio_cdf_parser = subparsers.add_parser('dct_ratio_cdf', help='plots a ratio of the DCT between two groups')
dct_ratio_cdf_parser.add_argument('-r', '--ref', type=str, required=True, help='the reference split group to compute the ratio from') # TODO rephrase
dct_ratio_cdf_parser = subparsers.add_parser('dct_ratio_boxplot', help='plots a ratio of the DCT between two groups')
dct_ratio_cdf_parser.add_argument('-r', '--ref', type=str, required=True, help='the reference split group to compute the ratio from') # TODO rephrase
gp_boxplot = subparsers.add_parser('gp_boxplot', help='plots the achieved goodput')
parser.add_argument('-t', '--test', help='plots results for TEST')
groups = {'filesize', 'plugin'}
parser.add_argument('-g', '--group-by', type=str, choices=groups, default='filesize', help='groups the plots in a single figure for this group')
parser.add_argument('-s', '--split-by', type=str, choices=groups, default='plugin', help='separates the plots over several figures for this group')
parser.add_argument('-xs', '--exclude-split', type=str, default='', help='excludes a group from the split group')
parser.add_argument('-xg', '--exclude-group', type=str, default='', help='excludes a group from the group group')
parser.add_argument('--xlim', type=Interval(), help='x axis limit interval')
parser.add_argument('--ylim', type=Interval(), help='y axis limit interval')
args = parser.parse_args()
if args.group_by == args.split_by:
print("group-by and split-by parameters must be different groups")
exit(-1)
script_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(script_dir, 'tests.yaml')) as f:
tests = yaml.load(f, Loader=yaml.SafeLoader)
results = json.load(args.file)
documents = []
groups.discard(args.split_by)
params_id = {'bandwidth', 'delay', 'paths', 'queue', 'bandwidth_balance', 'delay_balance', 'drops_to_client', 'drops_to_server'} | set(groups)
unused_fields = {'cmdline', 'start', 'end'}
mandatory_fields = {'transfer_time'}
colors = ['#4daf4a', '#984ea3', '#f781bf', '#377eb8', '#ff7f00', '#e41a1c', '#a65628', '#999999']
for t, variants in results.items():
for v, variant_results in variants['plugins'].items():
for r in variant_results:
r['plugin'] = v
r['test'] = t
try:
r['transfer_time'] = float(re.match(r"\d+\.\d+\s(?=ms)", r['transfer_time'])[0])
except:
print("Invalid result:", r)
for p, val in r['values'].items():
r[p] = val
del r['values']
documents.append(r)
transfer_times = {}
for d in documents:
for f in unused_fields:
if f in d:
del d[f]
params = {}
for p in params_id:
if p in d:
params[p] = d[p]
if p != args.group_by:
del d[p]
times = transfer_times.get(str(params), [])
times.append(d)
transfer_times[str(params)] = times
def set_box_color(bp, color):
plt.setp(bp['boxes'], color=color)
plt.setp(bp['whiskers'], color=color)
plt.setp(bp['caps'], color=color)
plt.setp(bp['medians'], color=color)
plt.setp(bp['fliers'], color=color, marker='.')
def new_fig():
plt.figure()
plt.clf()
if args.xlim:
plt.xlim(*args.xlim)
if args.ylim:
plt.ylim(*args.ylim)
ratios = {}
goodputs = {}
for params, runs in transfer_times.items():
ref_time = None
for r in runs:
if 'ref' in args and str(r[args.split_by]) == args.ref:
ref_time = r['transfer_time']
if 'ref' in args and ref_time is None:
print("Unable to get ref_time for ref:", args.ref)
continue
for r in runs:
group = str(r[args.group_by])
split = str(r[args.split_by])
if ('ref' not in args or split != args.ref) and split != args.exclude_split and group != args.exclude_group:
if r['transfer_time']:
if ref_time:
ratio = r['transfer_time'] / ref_time
deep_set(ratios, split, group, ratio)
goodput = ((r['filesize'][0] * 8) / 1000000) / (r['transfer_time'] / 1000)
deep_set(goodputs, split, group, goodput)
if args.plot_type == 'dct_ratio_boxplot':
new_fig()
plt.ylabel('DCT ratio (reference %s)' % args.ref)
plt.xlabel(args.group_by.title())
for s, c in zip(ratios, colors):
set_box_color(plt.boxplot(ratios[s].values(), labels=ratios[s].keys(), sym='.', widths=0.6), c)
plt.plot([], c=c, label=s.title())
plt.legend()
elif args.plot_type == 'dct_ratio_cdf':
for s in ratios:
new_fig()
plt.ylabel('CDF')
plt.ylim(0, 1)
plt.xlabel('DCT ratio %s/%s' % (s, args.ref))
for (g, data), c in zip(ratios[s].items(), colors):
increment = 1.0 / len(data)
plt.plot(sorted(data), np.arange(0, 1, increment), c=c, label=g)
plt.legend()
elif args.plot_type == 'gp_boxplot':
new_fig()
plt.ylabel('Achieved goodput (Mbps)')
plt.xlabel(args.group_by.title())
for s, c in zip(goodputs, colors):
set_box_color(plt.boxplot(goodputs[s].values(), labels=goodputs[s].keys(), sym='.', widths=0.6), c)
plt.plot([], c=c, label=s.title())
plt.legend()
plt.show()