forked from hundeboll/riddler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data.py
More file actions
335 lines (265 loc) · 11.6 KB
/
plot_data.py
File metadata and controls
335 lines (265 loc) · 11.6 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import numpy
import cPickle as pickle
from operator import itemgetter
macs = {'alice': '1c:7e:e5:5c:9a:d7', 'relay': '1c:7e:e5:5c:97:e5', 'bob': '34:08:04:99:f2:f6'}
class data:
def __init__(self, path):
self.load_pickle(path)
self.profile = self.data.args.test_profile
self.agg_data = {}
self.avg_data = {}
self.avg_count = {}
# Read measurements from riddler test
def load_pickle(self, path):
self.data = pickle.load(open(path))
self.relays = self.data.relays
self.sources = self.data.sources
self.nodes = self.data.nodes
self.macs = macs
# Read specified field in sorted order
def keys(self, rd, field):
keys = map(lambda r: r[0].run_info[field], rd)
keys = list(set(keys))
return sorted(keys)
# Return values of a dictionary sorted by their keys
def sort_data(self, data):
# Yeah, we love it
return numpy.array(map(lambda i: i[1], sorted(data.iteritems())))
# Average over a field in a result set
def average_result(self, rd, field, par):
avg = {}
# For each run_no in test
for r in rd:
key = r[0].run_info[par]
# Read result field for each loop in run_no
val = map(lambda d: d.result[field], r)
avg[key] = numpy.average(val)
# Return a list sorted by rates
return self.sort_data(avg)
def prepare_grids(self, c):
# Mad man sorting
x,y,z = zip(*c)
c_sorted = [c[i] for i in numpy.lexsort((z,y,x))]
# Shape our sorted axes and values
x_,y_,z_ = zip(*c_sorted)
x_len = len(numpy.unique(x_))
y_len = len(numpy.unique(y_))
x_ = numpy.reshape(x_, (y_len, x_len), order='F')
y_ = numpy.reshape(y_, (y_len, x_len), order='F')
z_ = numpy.reshape(z_, (y_len, x_len), order='F')
return {'x': x_, 'y': y_, 'z': z_}
def average_result_3d(self, rd, field, x_par, y_par):
c = []
for r in rd:
x = r[0].run_info[x_par]
y = r[0].run_info[y_par]
z = map(lambda d: d.result[field], r)
z = numpy.average(z)
c.append((x, y, z))
return self.prepare_grids(c)
def average_samples_3d(self, rd, field, x_par, y_par):
c = []
for r in rd:
x = r[0].run_info[x_par]
y = r[0].run_info[y_par]
z = self.average_run_samples(r, field)
c.append((x,y,z))
return self.prepare_grids(c)
def difference_samples_3d(self, rd, field, x_par, y_par):
sample_diff = lambda r, f: r.samples[-1][f] - r.samples[0][f]
c = []
for r in rd:
x = r[0].run_info[x_par]
y = r[0].run_info[y_par]
z = map(lambda d: sample_diff(d, field), r)
z = numpy.average(z)
c.append((x,y,z))
return self.prepare_grids(c)
# Average over a field in a sample set (from one run)
def average_run_samples(self, r, field):
avg = []
# For each loop in run_no
for loop in r:
# Read sample field for each sample set in loop
samples = map(lambda s: s[field], loop.samples)
# Average over samples in this loop
avg.append(numpy.average(samples))
return numpy.average(avg)
# Average over a field in a sample set (from multiple loops)
def average_samples(self, rd, field, par):
avg = {}
# For each run_no in test
for r in rd:
key = r[0].run_info[par]
val = self.average_run_samples(r, field)
avg[key] = val
# Return a list sorted by rates
return self.sort_data(avg)
# Read the difference from the first and last sample in each sample set
def difference_samples(self, rd, field, par):
sample_diff = lambda r, f: r.samples[-1][f] - r.samples[0][f]
avg = {}
# For each run_no in test
for r in rd:
key = r[0].run_info[par]
# Read difference in first and last sample in each loop
val = map(lambda d: sample_diff(d, field) if d.samples else 0, r)
avg[key] = numpy.average(val)
# Return a list sorted by rates
return self.sort_data(avg)
def sum_samples(self, rd, field, par):
avg = {}
for r in rd:
key = r[0].run_info[par]
summed = []
for loop in r:
s = reduce(lambda acc, sample: acc + sample[field], loop.samples, 0)
summed.append(s)
avg[key] = numpy.average(summed)
return self.sort_data(avg)
# Add data to system data
def update_system_data(self, name, data, coding):
# Initialize zeros if needed
if name not in self.agg_data:
self.agg_data[name] = {coding: {}, not coding: {}}
self.avg_data[name] = {coding: {}, not coding: {}}
self.avg_count[name] = {coding: 0, not coding: 0}
# Read length of data
l = len(data.values()[0])
# Initialize zeros
for key in data:
self.agg_data[name][coding][key] = numpy.zeros(l)
self.agg_data[name][not coding][key] = numpy.zeros(l)
self.avg_data[name][coding][key] = numpy.zeros(l)
self.avg_data[name][not coding][key] = numpy.zeros(l)
# Add data to existing data
self.avg_count[name][coding] += 1
for key,val in data.items():
# Add to summed data
self.agg_data[name][coding][key] += val
# Update average
agg = self.agg_data[name][coding][key]
self.avg_data[name][coding][key] = agg/self.avg_count[name][coding]
# Read out system data
def get_system_data(self, name, coding):
agg = self.agg_data[name][coding]
avg = self.avg_data[name][coding]
return agg,avg
def udp_source_data(self, node, coding):
# Get data objects from storage
rd = self.data.get_run_data_node(node, {'coding': coding})
# Read out data from objects
data = {}
data['rates'] = self.keys(rd, 'rate')
data['throughput'] = self.average_result(rd, 'throughput', 'rate')
data['jitter'] = self.average_result(rd, 'jitter', 'rate')
data['cpu'] = self.average_samples(rd, 'cpu', 'rate')
data['power'] = self.average_samples(rd, 'power_watt', 'rate')
data['iw_rx'] = self.difference_samples(rd, 'iw rx bytes', 'rate')
data['ip_rx'] = self.difference_samples(rd, 'ip_rx_bytes', 'rate')
data['iw_tx_pkts'] = self.difference_samples(rd, 'iw tx packets', 'rate')
self.update_system_data('udp_sources', data, coding)
return data
def udp_ratio_source_data(self, node, coding):
rd = self.data.get_run_data_node(node, {'coding': coding})
data = {}
data['throughput'] = self.average_result_3d(rd, 'throughput', 'ratio', 'rate')
return data
def udp_ratio_relay_data(self, node, coding):
rd = self.data.get_run_data_node(node, {'coding': coding})
data = {}
data['coded'] = self.difference_samples_3d(rd, 'nc Coded', 'ratio', 'rate')
data['power'] = self.average_samples_3d(rd, 'power_watt', 'ratio', 'rate')
return data
def udp_relay_data(self, node, coding):
# Get data objects from storage
rd = self.data.get_run_data_node(node, {'coding': coding})
# Read out data from objects
data = {}
data['rates'] = self.keys(rd, 'rate')
data['cpu'] = self.average_samples(rd, 'cpu', 'rate')
data['power'] = self.average_samples(rd, 'power_watt', 'rate')
data['coded'] = self.difference_samples(rd, 'nc Coded', 'rate')
data['fwd'] = self.difference_samples(rd, 'nc Forwarded', 'rate')
data['fwd_coded'] = self.difference_samples(rd, 'nc FwdCoded', 'rate')
data['tx'] = self.difference_samples(rd, 'iw tx bytes', 'rate')
data['iw_tx_pkts'] = self.difference_samples(rd, 'iw tx packets', 'rate')
data['capture_rx'] = self.udp_mac_capture_rx(rd, 'rate')
data['coded_diff'] = self.udp_rx_coded_diff(rd, 'rate')
data['ratio_coded'] = data['coded']/data['fwd_coded']/2
data['ratio_fwd'] = data['fwd']/data['fwd_coded']
data['ratio_total'] = data['ratio_coded'] + data['ratio_fwd']
self.update_system_data('udp_relays', data, coding)
return data
def tcp_source_data(self, node, coding):
rd = self.data.get_run_data_node(node, {'coding': coding})
data = {}
data['algos'] = self.keys(rd, 'tcp_algo')
data['throughput'] = self.average_result(rd, 'throughput', 'tcp_algo')
return data
def tcp_window_source_data(self, node, coding):
rd = self.data.get_run_data_node(node, {'coding': coding})
data = {}
data['tcp_windows'] = self.keys(rd, 'tcp_window')
data['throughput'] = self.average_result(rd, 'throughput', 'tcp_window')
return data
def udp_mac_capture(self, coding):
sample_diff = lambda s, f: s[-1][f] - s[0][f]
# This is slow as hell - yes, I know!
rd = {}
loops = {}
vals = {}
rates = []
diffs = []
for node in self.sources:
rd[node] = self.data.get_run_data_node(node, {'coding': coding})
for i in range(len(rd[node])):
for node in self.sources:
loops[node] = map(lambda d: d.samples, rd[node][i])
vals[node] = numpy.array(map(lambda s: sample_diff(s, 'iw tx packets'), loops[node]))
rate = rd[node][i][0].run_info['rate']
time = rd[node][i][0].run_info['test_time']
diff = vals['alice'] - vals['bob']
diff_avg = numpy.average(numpy.absolute(diff))
rates.append(rate)
diffs.append(diff_avg)
return {'rates': rates, 'diffs': diffs}
def udp_mac_capture_rx(self, rd, par):
sample_diff = lambda s, f: s[-1][f] - s[0][f]
data = {}
# For each new parameter
for r in rd:
key = r[0].run_info[par]
vals = []
# For each loop with this parameter
for loop in r:
rx = []
for node in self.sources:
field = "iw {} rx packets".format(self.macs[node])
val = sample_diff(loop.samples, field)
rx.append(val)
# Calculate and save the Mean Absolute Deviation (MAD)
#rx = numpy.array(rx)
#mad = numpy.abs(rx - rx.mean()).sum() / len(rx)
# Until now, we can live with the difference of two sources
vals.append(numpy.absolute(rx[0] - rx[1]))
data[key] = numpy.average(vals)
return self.sort_data(data)
def udp_rx_coded_diff(self, rd, par):
sample_diff = lambda s, f: s[-1][f] - s[0][f]
data = {}
for r in rd:
key = r[0].run_info[par]
vals = []
for loop in r:
rx = []
for node in self.sources:
field = "iw {} rx packets".format(self.macs[node])
val = sample_diff(loop.samples, field)
rx.append(val)
coded = sample_diff(loop.samples, "nc Coded")
#print("rx: {} coded: {}".format(min(rx), coded))
diff = (min(rx) - coded/2)
vals.append(diff)
data[key] = numpy.average(vals)
return self.sort_data(data)