Commit 619a3927 authored by Deathcrow's avatar Deathcrow
Browse files

Merge branch 'master' of git.scc.kit.edu:usbml/asteriskperf-python-wrapper

parents e40658f6 8768a041
...@@ -103,6 +103,9 @@ def process_proc_tcpprobe(sender): #sampling ...@@ -103,6 +103,9 @@ def process_proc_tcpprobe(sender): #sampling
tcpprobe_proc.close() tcpprobe_proc.close()
def process_proc_tcpprobe_optimized(sender): #sampling def process_proc_tcpprobe_optimized(sender): #sampling
starty = time.perf_counter() starty = time.perf_counter()
unprocessed_senders = set([key for key in range(len(sender))]) unprocessed_senders = set([key for key in range(len(sender))])
...@@ -128,6 +131,10 @@ def process_proc_tcpprobe_optimized(sender): #sampling ...@@ -128,6 +131,10 @@ def process_proc_tcpprobe_optimized(sender): #sampling
tcpprobe_proc.close() tcpprobe_proc.close()
def signal_handler(signum, frame): def signal_handler(signum, frame):
clean_up() clean_up()
raise SystemExit raise SystemExit
...@@ -168,10 +175,12 @@ signal.signal(signal.SIGTERM, signal_handler) ...@@ -168,10 +175,12 @@ signal.signal(signal.SIGTERM, signal_handler)
parser = argparse.ArgumentParser(description='Configure test environment.') parser = argparse.ArgumentParser(description='Configure test environment.')
parser.add_argument('-l', '--label', default="default") parser.add_argument('-l', '--label', default="default")
parser.add_argument('-u', '--utility', default='iperf') parser.add_argument('-u', '--utility', default='iperf') ## XXX Note: iperf support is not tested!!
parser.add_argument('-t', '--time', default="60") parser.add_argument('-t', '--time', default="60")
parser.add_argument('-s', '--sender', action='append', nargs='+', required=True, \ parser.add_argument('-s', '--sender', action='append', nargs='+', required=True, \
help="Specify senders: <src ip>#<dst ip>#<port>#<congestion>#<number>#<interface> -- individual specifications overwrite globals") help="Specify senders: <src ip>#<dst ip>#<port>#<congestion>#<number>#<interface> -- individual specifications overwrite globals")
## "--receiver" sets the receiver if there was no receiver was specified
# (XXX same for --port, etc)
parser.add_argument('-r', '--receiver', default="localhost") parser.add_argument('-r', '--receiver', default="localhost")
parser.add_argument('-p', '--port', default="5001") parser.add_argument('-p', '--port', default="5001")
parser.add_argument('-T', '--tmp-folder', default="/tmp") parser.add_argument('-T', '--tmp-folder', default="/tmp")
...@@ -186,10 +195,10 @@ parser.add_argument('-P', '--cpunetlog' , default="", \ ...@@ -186,10 +195,10 @@ parser.add_argument('-P', '--cpunetlog' , default="", \
help="Path to cpunetlog folder") help="Path to cpunetlog folder")
parser.add_argument("--netperf-dataport", default=str(random.randint(15000,65000)), \ parser.add_argument("--netperf-dataport", default=str(random.randint(15000,65000)), \
help="Port for the data conncections by netperf. Will be incremented per sender") help="Port for the data conncections by netperf. Will be incremented per sender")
parser.add_argument('-D', '--tcpdump', default="1", \ parser.add_argument('-D', '--tcpdump', default="0", \
help="Enable/Disable tcpdump (Default: enabled") help="Enable/Disable tcpdump (Default: disabled")
parser.add_argument('-S', '--samplerate', default="0.1", \ parser.add_argument('-S', '--samplerate', default="0.1", \
help="Samplerate for measurements") help="Samplerate for measurements: Sleeptime between samples (in seconds)")
parser.add_argument('--legacy', action='store_true', \ parser.add_argument('--legacy', action='store_true', \
help="Record entire tcp_probe output instead of samples by samplerate. \ help="Record entire tcp_probe output instead of samples by samplerate. \
Can be less CPU intensive for certain samplerates. \ Can be less CPU intensive for certain samplerates. \
...@@ -211,12 +220,24 @@ os.mkdir(args.tmp_folder) ...@@ -211,12 +220,24 @@ os.mkdir(args.tmp_folder)
parse_senders( flat_sender_args, sender) parse_senders( flat_sender_args, sender)
#clean slate #clean slate
print("First, kill all remaining instances of '" + args.utility + "'")
subprocess.Popen(["killall", "-s", "9", args.utility]) subprocess.Popen(["killall", "-s", "9", args.utility])
print()
if args.cpunetlog != "": if args.cpunetlog != "":
args.cpunetlog = os.path.abspath(args.cpunetlog) args.cpunetlog = os.path.abspath(args.cpunetlog)
cpunetlog = subprocess.Popen(["python3", args.cpunetlog+"/__init__.py", "-l", "-d", "--path", args.tmp_folder+"/cpunetlog"]) #run cpunetlog in headless mode cpunetlog = subprocess.Popen(["python3", args.cpunetlog+"/__init__.py", "-l", "-d", "--path", args.tmp_folder+"/cpunetlog"]) #run cpunetlog in headless mode
## Prepare commandline to start experiment utilities (netperf, etc.) ##
# General conversion between commandline syntax of the tools/utilities
utility_args = {} utility_args = {}
utility_args['connect'] = "-c" utility_args['connect'] = "-c"
utility_args['time'] = "-t" utility_args['time'] = "-t"
...@@ -252,6 +273,9 @@ if args.tcpdump == "1": ...@@ -252,6 +273,9 @@ if args.tcpdump == "1":
#TODO? if congesion_algo == all check proc and do all #TODO? if congesion_algo == all check proc and do all
# Prapare command line for each sender
for key, i in enumerate(sender): for key, i in enumerate(sender):
i['utility_command'] = [ args.utility, \ i['utility_command'] = [ args.utility, \
utility_args['connect'], i['dst'], \ utility_args['connect'], i['dst'], \
...@@ -271,6 +295,11 @@ for key, i in enumerate(sender): ...@@ -271,6 +295,11 @@ for key, i in enumerate(sender):
#setup done, run tests in 5 seconds #setup done, run tests in 5 seconds
start_time = time.perf_counter() + 5 start_time = time.perf_counter() + 5
## Start senders in different processes
with multiprocessing.Pool(len(sender)) as pool: with multiprocessing.Pool(len(sender)) as pool:
# for key, i in enumerate(sender): # for key, i in enumerate(sender):
# i['utility'] = subprocess.Popen(i['utility_command'], stdout=i['utility_file']) # i['utility'] = subprocess.Popen(i['utility_command'], stdout=i['utility_file'])
...@@ -292,6 +321,10 @@ with multiprocessing.Pool(len(sender)) as pool: ...@@ -292,6 +321,10 @@ with multiprocessing.Pool(len(sender)) as pool:
i['utility'] = pool_results[key].get() i['utility'] = pool_results[key].get()
print(i['utility'].args) print(i['utility'].args)
## Find out which src_port belongs to which sender (not necessary for netperf) ##
if args.utility != "netperf": if args.utility != "netperf":
ss_file = tempfile.TemporaryFile(mode='r+') ss_file = tempfile.TemporaryFile(mode='r+')
subprocess.call(["ss", "-t", "-i", "-p", "-n"],stdout=ss_file) subprocess.call(["ss", "-t", "-i", "-p", "-n"],stdout=ss_file)
...@@ -331,12 +364,17 @@ if args.utility != "netperf": ...@@ -331,12 +364,17 @@ if args.utility != "netperf":
# ss_file.close() # ss_file.close()
# time.sleep(0.1) # time.sleep(0.1)
######## MAIN LOOP ########
if not args.legacy: if not args.legacy:
while (time.perf_counter() - start_time) < (float(args.time)-float(args.samplerate)): while (time.perf_counter() - start_time) < (float(args.time)-float(args.samplerate)):
# print("begin while") # print("begin while")
while_start = time.perf_counter() # remember beginning of this loop while_start = time.perf_counter() # remember beginning of this loop
process_proc_tcpprobe_optimized(sender) #heavy lifting here process_proc_tcpprobe_optimized(sender) # <-- heavy lifting here
try: try:
# sleep samplerate minus time spent in loop # sleep samplerate minus time spent in loop
...@@ -348,6 +386,14 @@ if not args.legacy: ...@@ -348,6 +386,14 @@ if not args.legacy:
else: else:
time.sleep(float(args.time)) time.sleep(float(args.time))
### Experiments finished ###
#for i in sender: #for i in sender:
# i['utility'].wait() # i['utility'].wait()
# wait doesn't work with multiprocessing (?! returncode always 0, even when netperf still running) # wait doesn't work with multiprocessing (?! returncode always 0, even when netperf still running)
...@@ -360,7 +406,11 @@ clean_up() ...@@ -360,7 +406,11 @@ clean_up()
if args.legacy: if args.legacy:
process_raw_tcpprobe_file(tcpprobe_file, sender) process_raw_tcpprobe_file(tcpprobe_file, sender)
#calculate bandwidth for each sender:
### After the experiments are finished, parse tcpprobe files again and calculate "goodput" ###
# calculate bandwidth for each sender:
for key, i in enumerate(sender): for key, i in enumerate(sender):
last_timestamp = 0 last_timestamp = 0
last_seq = 0 last_seq = 0
...@@ -395,6 +445,14 @@ for i in sender: ...@@ -395,6 +445,14 @@ for i in sender:
if args.comment is not "": if args.comment is not "":
subprocess.call(['cp', os.path.abspath(args.comment), args.tmp_folder]) subprocess.call(['cp', os.path.abspath(args.comment), args.tmp_folder])
## packing results into tar file ##
tar_return = subprocess.call(["tar", "cJf", args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz", "-C", os.path.abspath(args.tmp_folder+"/../"), os.path.basename(args.tmp_folder)]) tar_return = subprocess.call(["tar", "cJf", args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz", "-C", os.path.abspath(args.tmp_folder+"/../"), os.path.basename(args.tmp_folder)])
if tar_return is 0: if tar_return is 0:
#user_input = input("Results in tarfile: "+os.path.abspath(args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz")+"\nDelete Folder \""+args.tmp_folder+"\" ? (Y/n) ") #user_input = input("Results in tarfile: "+os.path.abspath(args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz")+"\nDelete Folder \""+args.tmp_folder+"\" ? (Y/n) ")
...@@ -408,3 +466,4 @@ print("done") ...@@ -408,3 +466,4 @@ print("done")
#while True: #while True:
# pass # pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment