aggregate-mod.py 8.83 KB
Newer Older
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
#!/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
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
73
parser.add_argument('-t', '--time', default="300", help="Length of tests to analyze (for bw)")
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

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+')
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
105
            elif file[:3+len(args.mask)] == "bw_"+args.mask: #black magic (create a bw value for each second)
106
107
                bw_file = open(path + "/" + file)
                sum_b = 0
Deathcrow's avatar
Deathcrow committed
108
                last_bw = (1, 0)
109
110
111
                for line in bw_file:
                    line = line.split(" ")
                    this_bw = (float(line[0]), float(line[3]))
Deathcrow's avatar
Deathcrow committed
112
                    if this_bw[0] < math.ceil(last_bw[0]): # still within same second
113
                        sum_b+= (this_bw[0] - last_bw[0])*this_bw[1]
Deathcrow's avatar
Deathcrow committed
114
115
116
117
118
119
120
121
122
#                    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
123
124
                        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
125
126
127
                        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
128
129
130
131
                        #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
132
133
134
                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")
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

                    #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()
                

bw_values_file.seek(0)
Deathcrow's avatar
Deathcrow committed
152
153
#print(bw_values_file.read())
#bw_values_file.seek(0)
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
rtt_values_file.seek(0)
netperf_throughput_file.seek(0)
netperf_retrans_file.seek(0)

def statify_list(sorted_list, n):
    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 ])
print("Bandwidth: ")
print("=============================")
sorted_bw = statify_list(sorted_bw, len(sorted_bw))
print("")
print("Round Trip Time: ")
print("=============================")
sorted_rtt = statify_list(sorted_rtt, len(sorted_rtt))
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, 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, len(sorted_netperf_retrans))

Deathcrow's avatar
Deathcrow committed
245
from pylab import *
246

Deathcrow's avatar
Deathcrow committed
247
248
249
250
boxplot(sorted_bw)
show()
boxplot(sorted_rtt)
show()
251
252
253
254
255
256
257
258

#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)