aggregate-mod.py 11.3 KB
Newer Older
1
2
3
4
5
6
7
8
#!/usr/bin/env python3
# vim: expandtab shiftwidth=4 softtabstop=4


#iperf -V -Z cubic -t 30 -c fdb2:f689:4248:2bc8::3 -p 12345

import argparse
import copy
Deathcrow's avatar
Deathcrow committed
9
import json
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
import math
import os
import re
import signal
import subprocess
import tempfile
#import threading
import time

def signal_handler(signum, frame):
    clean_up()
    raise SystemExit

def testy(a,b):
    print(a)
    print(b)
    print(sender)
    return 0

def clean_up():
# Clean up
    if args.legacy:
        tcpprobe.terminate()
    if args.tcpdump == "1":
        tcpdump.terminate()
    if args.cpunetlog != "":
        cpunetlog.terminate()
    for i in sender:
#        if i['utility'].returncode == None:
            try:
                i['utility'].kill()
            except ProcessLookupError:
                pass
#        i['utility_file'].close()
    time.sleep(1)

#def parse_dir(directory):

def qsort1(list):
    """Quicksort using list comprehensions"""
    if list == []: 
        return []
    else:
        pivot = list[0]
        lesser = qsort1([x for x in list[1:] if x < pivot])
        greater = qsort1([x for x in list[1:] if x >= pivot])
        return lesser + [pivot] + greater 

def quantil(list,p):
    length = len(list)
    len_p = (length * p)-1
    if math.ceil(len_p) == len_p:
        return ((list[int(len_p)] + list[int(len_p + 1)]) / 2)
    else:
        return list[math.ceil(len_p)]
    

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

parser = argparse.ArgumentParser(description='Configure test environment.')

parser.add_argument('folders', nargs="*", default="./", help="Folder to search for files")
parser.add_argument('-m', '--mask', default="")
Deathcrow's avatar
Deathcrow committed
74
parser.add_argument('-t', '--time', default="300", help="Length of tests to analyze (for bw)")
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

args = parser.parse_args()

mypid = os.getpid()

#print(args.folders)

#for key, folder in enumerate(args.folders):
#    args.folders[key] = os.path.abspath(folder)

args.folders = [os.path.abspath(folder) for folder in args.folders]

print(args.folders)
rtt_values_file = tempfile.TemporaryFile(mode='r+')
bw_values_file = tempfile.TemporaryFile(mode='r+')
netperf_throughput_file = tempfile.TemporaryFile(mode='r+')
netperf_retrans_file = tempfile.TemporaryFile(mode='r+')
Deathcrow's avatar
Deathcrow committed
92
93
94
95
iperf3_throughput_file = tempfile.TemporaryFile(mode='r+')
iperf3_retrans_file = tempfile.TemporaryFile(mode='r+')
iperf3_host_cpu_file = tempfile.TemporaryFile(mode='r+')
iperf3_remote_cpu_file = tempfile.TemporaryFile(mode='r+')
96
97
98
99
100
101
102
103
104
105
106
107
108
109
rtt_file_lines = 0
bw_file_lines = 0

for folder in args.folders:
    for path, dirs, files in os.walk(folder):
        for file in files:
            if file[:9+len(args.mask)] == "tcpprobe_"+args.mask:
                tcpprobe_file = open(path + "/" + file)
                for line in tcpprobe_file:
                    line = line.split(" ")
                    #print(line[9])
                    rtt_values_file.write(line[9]+'\n')
                    rtt_file_lines += 1
                tcpprobe_file.close()
Deathcrow's avatar
Deathcrow committed
110
            elif file[:3+len(args.mask)] == "bw_"+args.mask: #black magic (create a bw value for each second)
111
112
                bw_file = open(path + "/" + file)
                sum_b = 0
Deathcrow's avatar
Deathcrow committed
113
                last_bw = (1, 0)
114
115
116
                for line in bw_file:
                    line = line.split(" ")
                    this_bw = (float(line[0]), float(line[3]))
Deathcrow's avatar
Deathcrow committed
117
                    if this_bw[0] < math.ceil(last_bw[0]): # still within same second
118
                        sum_b+= (this_bw[0] - last_bw[0])*this_bw[1]
Deathcrow's avatar
Deathcrow committed
119
120
121
122
123
124
125
126
127
#                    elif math.floor(this_bw[0]) - math.ceil(last_bw[0]) >= 1: #no value for more than a second, but we still want _something_
#                        sum_b += (math.ceil(last_bw[0]) - last_bw[0]) * float(line[3]
#                        bw_values_file.write(str(sum_b)+"\n")
#                        for i in range(math.floor(this_bw[0]) - math.ceil(last_bw[0])):
#                            #bw_values_file.write("0"+"\n")
#                            bw_values_file.write(str(this_bw[1])+"\n")
#                            #print(math.floor(last_bw[0])+i,0)
#                            sum_b = (this_bw[0] - math.floor(this_bw[0]))*this_bw[1]
                    else: #transition to a new second
128
129
                        sum_b += (math.ceil(last_bw[0]) - last_bw[0]) * float(line[3])
                        bw_values_file.write(str(sum_b)+"\n")
Deathcrow's avatar
Deathcrow committed
130
131
132
                        if (math.floor(this_bw[0]) - math.ceil(last_bw[0]) >= 1): #if we skipped some seconds
                            for i in range(math.floor(this_bw[0]) - math.ceil(last_bw[0])): # write the current bw (which should be the average)
                                bw_values_file.write(str(this_bw[1])+"\n") # for each missed second
133
134
135
136
                        #print(math.floor(last_bw[0]), sum_b)
                        sum_b = (this_bw[0] - math.floor(this_bw[0]))*this_bw[1]
                    
                    last_bw = this_bw
Deathcrow's avatar
Deathcrow committed
137
138
139
                if int(last_bw[0]) < int(args.time):
                    for i in range(int(last_bw[0]),int(args.time)):
                        bw_values_file.write("0"+"\n")
140
141
142
143
144
145
146
147
148
149
150
151
152
153

                    #bw_values_file.write(line[3])
                    #bw_file_lines += 1
                bw_file.close()
            elif file[:8+len(args.mask)] == "netperf_"+args.mask:
                netperf_file = open(path + "/" + file)
                count = 0
                for line in netperf_file:
                    count+=1
                    if count == 6:
                        netperf_throughput_file.write(line[11:])
                    elif count == 42:
                        netperf_retrans_file.write(line[24:])
                netperf_file.close()
Deathcrow's avatar
Deathcrow committed
154
155
156
157
158
159
160
161

            elif file[:7+len(args.mask)] == "iperf3_"+args.mask:
                with open(path + "/" + file) as iperf3_file:
                    json_data = json.load(iperf3_file)
                iperf3_throughput_file.write(str(json_data["end"]["sum_sent"]["bits_per_second"] / 1000000) + "\n")
                iperf3_retrans_file.write(str(json_data["end"]["sum_sent"]["retransmits"]) + "\n")
                iperf3_host_cpu_file.write(str(json_data["end"]["cpu_utilization_percent"]["host_total"]) + "\n")
                iperf3_remote_cpu_file.write(str(json_data["end"]["cpu_utilization_percent"]["remote_total"]) + "\n")
162
163

bw_values_file.seek(0)
Deathcrow's avatar
Deathcrow committed
164
165
#print(bw_values_file.read())
#bw_values_file.seek(0)
166
167
168
rtt_values_file.seek(0)
netperf_throughput_file.seek(0)
netperf_retrans_file.seek(0)
Deathcrow's avatar
Deathcrow committed
169
170
171
172
173
iperf3_throughput_file.seek(0)
iperf3_retrans_file.seek(0)
iperf3_host_cpu_file.seek(0)
iperf3_remote_cpu_file.seek(0)

174

Deathcrow's avatar
Deathcrow committed
175
176
def statify_list(sorted_list):
    n = len(sorted_list)
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
    avg = sum( sorted_list ) / n
    std_deviation = math.sqrt((1/(n - 1)) * sum( [ (value-avg)**2 for value in sorted_list ] ))
    q_25 = quantil(sorted_list, 0.25)
    q_75 = quantil(sorted_list, 0.75)
    iqr = q_75 - q_25
    bot = sorted_list[0]
    top = sorted_list[len(sorted_list) - 1]
    whisker_bot = bot
    for value in sorted_list:
        if value >= (q_25 - iqr*1.5):
            whisker_bot = value
            break
    whisker_top = top
    for value in reversed(sorted_list):
        if value <= (q_75 + iqr*1.5):
            whisker_top = value
            break
    
    percent_under_whisker = 0
    count = 0
    for value in sorted_list:
        if value < whisker_bot:
            count += 1
        else:
            percent_under_whisker = (count / n) * 100
            break

    count = 0
    for value in reversed(sorted_list):
        if value > whisker_top:
            count += 1
        else:
            percent_over_whisker = (count / n) * 100
            break
            
    print("Average:\t"+str(avg))
    print("Std. deviation:\t"+str(std_deviation))
    print("0.25 Quantil:\t"+str(q_25))
    print("0.75 Quantil:\t"+str(q_75))
    print("IQR:\t\t"+str(iqr))
    print("bot. whisker:\t"+str(whisker_bot))
    print("top whisker:\t"+str(whisker_top))
    print("% < whisker:\t"+str(percent_under_whisker))
    print("% > whisker:\t"+str(percent_over_whisker))

    #return list with extreme outliers removed
    for value in sorted_list:
        if value < (q_25 - iqr*3.0):
            del sorted_list[0]
        else:
            break
    for value in reversed(sorted_list):
        if value > (q_75 + iqr*3.0):
            del sorted_list[len(sorted_list)-1]
        else:
            break
    print("min. without outliers: "+str(sorted_list[0]))
    print("max. without outliers: "+str(sorted_list[len(sorted_list)-1]))
    print("Std. deviation without outliers: "+str(math.sqrt((1/(n - 1)) * sum( [ (value-avg)**2 for value in sorted_list ] ))))

    return sorted_list

sorted_bw = sorted([ float(line) for line in bw_values_file ])
sorted_rtt = sorted([ float(line) for line in rtt_values_file ])
sorted_netperf_throughput = sorted([ float(line) for line in netperf_throughput_file ])
sorted_netperf_retrans = sorted([ float(line) for line in netperf_retrans_file ])
Deathcrow's avatar
Deathcrow committed
243
244
245
246
247
sorted_iperf3_throughput = sorted([ float(line) for line in iperf3_throughput_file ])
sorted_iperf3_retrans = sorted([ float(line) for line in iperf3_retrans_file ])
sorted_iperf3_host_cpu = sorted([ float(line) for line in iperf3_host_cpu_file ])
sorted_iperf3_remote_cpu = sorted([ float(line) for line in iperf3_remote_cpu_file ])
print(sorted_iperf3_throughput)
248
249
print("Bandwidth: ")
print("=============================")
Deathcrow's avatar
Deathcrow committed
250
sorted_bw = statify_list(sorted_bw)
251
252
253
print("")
print("Round Trip Time: ")
print("=============================")
Deathcrow's avatar
Deathcrow committed
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
sorted_rtt = statify_list(sorted_rtt)


if len(sorted_netperf_throughput):
    print("")
    print("Netperf Throughput: ")
    print("=============================")
    if len(sorted_netperf_throughput) == 1:
        sorted_netperf_throughput += sorted_netperf_throughput
    sorted_netperf_throughput = statify_list(sorted_netperf_throughput)

if len(sorted_netperf_throughput):
    print("")
    print("Netperf Retransmissions: ")
    print("=============================")
    if len(sorted_netperf_retrans) == 1:
        sorted_netperf_retrans += sorted_netperf_retrans
    sorted_netperf_retrans = statify_list(sorted_netperf_retrans)

if len(sorted_iperf3_throughput):
    print("")
    print("Iperf3 Throughput: ")
    print("=============================")
    if len(sorted_iperf3_throughput) == 1:
        sorted_iperf3_throughput += sorted_iperf3_throughput
    sorted_iperf3_throughput = statify_list(sorted_iperf3_throughput)

if len(sorted_iperf3_retrans):
    print("")
    print("Iperf3 Retrans: ")
    print("=============================")
    if len(sorted_iperf3_retrans) == 1:
        sorted_iperf3_retrans += sorted_iperf3_retrans
    sorted_iperf3_retrans = statify_list(sorted_iperf3_retrans)

if len(sorted_iperf3_host_cpu):
    print("")
    print("Iperf3 Host CPU Usage: ")
    print("=============================")
    if len(sorted_iperf3_host_cpu) == 1:
        sorted_iperf3_host_cpu += sorted_iperf3_host_cpu
    sorted_iperf3_host_cpu = statify_list(sorted_iperf3_host_cpu)

if len(sorted_iperf3_remote_cpu):
    print("")
    print("Iperf3 Remote CPU Usage: ")
    print("=============================")
    if len(sorted_iperf3_remote_cpu) == 1:
        sorted_iperf3_remote_cpu += sorted_iperf3_remote_cpu
    sorted_iperf3_remote_cpu = statify_list(sorted_iperf3_remote_cpu)
304

Deathcrow's avatar
Deathcrow committed
305
from pylab import *
306

Deathcrow's avatar
Deathcrow committed
307
308
309
310
#boxplot(sorted_bw)
#show()
#boxplot(sorted_rtt)
#show()
311
312
313
314
315
316
317
318

#rtt_q_25 = quantil(sorted_rtt, 0.25)
#rtt_q_75 = quantil(sorted_rtt, 0.75)
#rtt_iqr = rtt_q_75 - rtt_q_25

#print(bw_values_file.read())
#print(bw_file_lines)