#!/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 json 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="") parser.add_argument('-t', '--time', default="300", help="Length of tests to analyze (for bw)") 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+') 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+') 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() elif file[:3+len(args.mask)] == "bw_"+args.mask: #black magic (create a bw value for each second) bw_file = open(path + "/" + file) sum_b = 0 last_bw = (1, 0) for line in bw_file: line = line.split(" ") this_bw = (float(line[0]), float(line[3])) if this_bw[0] < math.ceil(last_bw[0]): # still within same second sum_b+= (this_bw[0] - last_bw[0])*this_bw[1] # 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 sum_b += (math.ceil(last_bw[0]) - last_bw[0]) * float(line[3]) bw_values_file.write(str(sum_b)+"\n") 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 #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 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") #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() 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") bw_values_file.seek(0) #print(bw_values_file.read()) #bw_values_file.seek(0) rtt_values_file.seek(0) netperf_throughput_file.seek(0) netperf_retrans_file.seek(0) iperf3_throughput_file.seek(0) iperf3_retrans_file.seek(0) iperf3_host_cpu_file.seek(0) iperf3_remote_cpu_file.seek(0) def statify_list(sorted_list): n = len(sorted_list) 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 ]) 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) print("Bandwidth: ") print("=============================") sorted_bw = statify_list(sorted_bw) print("") print("Round Trip Time: ") print("=============================") 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) from pylab import * #boxplot(sorted_bw) #show() #boxplot(sorted_rtt) #show() #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)