Commit 08cc0c6f authored by Deathcrow's avatar Deathcrow

minor restructuring and fixes (use random src port by default for netperf)

parent f39c69a7
......@@ -9,6 +9,7 @@ import copy
import multiprocessing
import os
import re
import random
import signal
import subprocess
import tempfile
......@@ -104,20 +105,20 @@ def process_proc_tcpprobe(sender): #sampling
def process_proc_tcpprobe_optimized(sender): #sampling
starty = time.perf_counter()
tcpprobe_proc = open("/proc/net/tcpprobe", "r")
unprocessed_senders = set([key for key in range(len(sender))])
tcpprobe_proc = open("/proc/net/tcpprobe", "r")
# collect line from tcpprobe and write to file if it belongs to a
# unprocessed (one that didn't have a line written yet) sender
while len(unprocessed_senders) > 0:
while (len(unprocessed_senders) > 0) and (time.perf_counter() - starty < float(args.samplerate)): # find line matching all senders && TIMEOUT
line_split = tcpprobe_proc.readline().split(" ")
time_dif = time.perf_counter() - start_time
# try to match current tcpprobe line against all unprocessed senders
# try to match current tcpprobe line against all unprocessed senders
for key in unprocessed_senders:
if (line_split[1] == r"["+sender[key]['src']+r"]:"+sender[key]['src_port'] and line_split[2] == r"["+sender[key]['dst']+r"]:"+sender[key]['port']):
if (line_split[1] == r"["+sender[key]['src']+r"]:"+sender[key]['src_port']):
# and line_split[2] == r"["+sender[key]['dst']+r"]:"+sender[key]['port']): # pointless comparison?!
# write time + current tcpprobe line to file for this sender
unprocessed_senders.discard(key)
time_dif = time.perf_counter() - start_time
sender[key]['tcpprobe_file'].write(str(time_dif)+" "+" ".join(line_split[1:]))
break
else: # no break occured
......@@ -125,10 +126,6 @@ def process_proc_tcpprobe_optimized(sender): #sampling
print("CRITICAL ERROR!")
unprocessed_senders={}
#TIMEOUT
if time.perf_counter() - starty > float(args.samplerate):
unprocessed_senders={}
tcpprobe_proc.close()
def signal_handler(signum, frame):
......@@ -187,7 +184,7 @@ parser.add_argument('-C', '--comment', default="", \
help="Path to a (txt) file to be included in the final Tarball")
parser.add_argument('-P', '--cpunetlog' , default="", \
help="Path to cpunetlog folder")
parser.add_argument("--netperf-dataport", default="53699", \
parser.add_argument("--netperf-dataport", default=str(random.randint(15000,65000)), \
help="Port for the data conncections by netperf. Will be incremented per sender")
parser.add_argument('-D', '--tcpdump', default="1", \
help="Enable/Disable tcpdump (Default: enabled")
......@@ -335,7 +332,7 @@ if args.utility != "netperf":
# time.sleep(0.1)
if not args.legacy:
while time.perf_counter() - start_time < float(args.time):
while (time.perf_counter() - start_time) < (float(args.time)-float(args.samplerate)):
# print("begin while")
while_start = time.perf_counter() # remember beginning of this loop
......@@ -403,8 +400,8 @@ 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) ")
# if not user_input.lower().startswith("n"):
# subprocess.call(["rm", "-rf", args.tmp_folder])
print("Results in tarfile: "+os.path.abspath(args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz")+"\nDeleting Folder \""+args.tmp_folder+"\" in 5 seconds (ctrl+c to abort)...")
time.sleep(5)
print("Results in tarfile: "+os.path.abspath(args.tmp_folder+"/../"+args.label+"_"+str(mypid)+".tar.xz"))
# time.sleep(5)
subprocess.call(["rm", "-rf", args.tmp_folder])
print("done")
......
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