From a97a1996cb645e079c3dc6370ced5f6ba1aa02e3 Mon Sep 17 00:00:00 2001 From: Balazs Szenczy Date: Wed, 9 Oct 2024 14:31:50 +0200 Subject: [PATCH] add api logfile, added clockr --- base_try.py | 18 ++++++++++++++---- good-try.py | 55 +++++++++++++++++++++++++++++------------------------ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/base_try.py b/base_try.py index 2d5ea3f8..a370b62d 100644 --- a/base_try.py +++ b/base_try.py @@ -44,10 +44,13 @@ def main(): parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--filename', type=str, required=True, help='Filename for the output without .txt') parser.add_argument('--clock', action='store_true', help='Use clocked') + parser.add_argument('--clockr', action='store_true', help='Use clocked') parser.add_argument('--tls-verify', action='store_true', help='Use tls_verify') parser.add_argument('--track', type=str, required=True, help='Track name') args = parser.parse_args() clocked = args.clock + clockedr = args.clockr + tls_verify = args.tls_verify setLogLevel('critical') @@ -118,7 +121,7 @@ def main(): sleep(1) # CLI(net) track = args.track - if not clocked: + if not clocked and not clockedr: vidi_filenammm = track.split("_")[1] baseline_pub.cmd(f'xterm -hold -T "baseline-pub" -e bash -c "export GST_PLUGIN_PATH="${{PWD}}/../moq-gst/target/debug${{GST_PLUGIN_PATH:+:$GST_PLUGIN_PATH}}:${{PWD}}/../6gxr-latency-clock"; gst-launch-1.0 -q -v -e filesrc location="./dev/{vidi_filenammm}.mp4" ! qtdemux name=before01 \ before01.video_0 ! h264parse name=before02 ! avdec_h264 name=before03 ! videoconvert name=before2 ! timestampoverlay name=middle ! videoconvert name=after1 ! x264enc tune=zerolatency name=after2 ! h264parse name=after3 ! isofmp4mux chunk-duration=1 fragment-duration=1 name=after4 ! moqsink {tls_verify_gst_str} url="https://12.0.1.2:4443" namespace="{track}";sleep 0.1 "&') @@ -147,7 +150,7 @@ def main(): else: baseline_pub.cmd(f'xterm -hold -T "baseline-pub" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --publish --namespace {track} https://12.0.1.2:4443" &') sleep(0.5) - baseline_sub.cmd(f'xterm -hold -T "baselin-sub" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --namespace {track} https://12.0.1.2:4443 {tls_verify_str} >> measurements/assumed_baseline_clock_pre_{filename}.txt" &') + baseline_sub.cmd(f'xterm -hold -T "baselin-sub" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --namespace {track} https://12.0.1.2:4443 {tls_verify_str} | tee measurements/assumed_baseline_clock_pre_{filename}.txt" &') sleep(30) subprocess.call(['sudo', 'pkill', '-f', 'xterm'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) file_path1 = f"measurements/assumed_baseline_clock_pre_{filename}.txt" @@ -155,9 +158,16 @@ def main(): file_latencies = [] for line in file: try: - latency = int(line.strip()) * 1000000 - file_latencies.append(latency) + number=int(line.strip()) + if clocked: + latency = number*1000000 + file_latencies.append(latency) + else: + if number<1000 and clockedr: + latency = number*1000000 + file_latencies.append(latency) except ValueError: + #todo continue if file_latencies: assumed_baseline, median, percentile_99 = calculate_statistics(file_latencies) diff --git a/good-try.py b/good-try.py index 33a44951..8d7c237b 100644 --- a/good-try.py +++ b/good-try.py @@ -36,7 +36,7 @@ gst_shark = int(os.getenv("SHARK", 0)) topofile= os.getenv("TOPO", "tiniest_topo.yaml") folding= os.getenv("BUILD", False) -# # gst mostly, clock, ffmpeg +# gst mostly, clock for moq-clock, clockr cuts off seconds of first delays, ffmpeg for no measurement mode = os.getenv("MODE", "clock") @@ -65,8 +65,6 @@ def extract_latency(line): if not os.geteuid() == 0: exit("** This script must be run as root") -else: - print("** Mopping up remaining mininet") if not os.path.exists('the_path.py'): exit("** the_path module is not available") @@ -91,9 +89,11 @@ def extract_latency(line): for topo_idx in range(len(test_set)): for try_idx in range(num_of_tries): + print("** Mopping up remaining mininet") subprocess.call(['sudo', 'mn', '-c'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.call(['sudo', 'pkill', '-f','gst-launch'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.call(['sudo', 'pkill', '-f','xterm'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) if my_debug or folding: print("** Folding them needed binaries") @@ -122,8 +122,8 @@ def extract_latency(line): baseline_tls_str="" baseline_path_clk_str="" - if config['mode'] == 'clock': - baseline_clk_str="--clock" + if config['mode'] in ['clock', 'clockr']: + baseline_clk_str=f"--{config['mode']}" baseline_path_clk_str="clocked_" if forklift_certified: baseline_tls_str="--tls-verify" @@ -139,6 +139,7 @@ def extract_latency(line): baseline_content = file.read().strip() based_line = float(baseline_content) else: + print("** No baseline because debugging NO_BASE envvar") based_line = 0.0 with open(baseline_path, 'w') as file: file.write(str(based_line)) @@ -167,7 +168,6 @@ def extract_latency(line): connections.append(connection) debug(f"I see {src} to {dst} at index {connection['node1']} and {connection['node2']} with latency {connection['delay']}ms") edges = connections - print(edges) # print("** Baking fresh cert") @@ -254,7 +254,7 @@ def extract_latency(line): for edge in edges: if ((i+1 == edge['node1'] and j+1 == edge['node2']) or (i+1 == edge['node2'] and j+1 == edge['node1'])) and searching: delay=edge['delay'] - print(f"delay between {i+1} and {j+1} is {delay}") + debug(f"delay between {i+1} and {j+1} is {delay}") searching=False # break ip1 = f"10.0.{network_counter}.1/24" @@ -278,8 +278,7 @@ def extract_latency(line): host2.cmd(f'ip route add 10.3.0.{i+1}/32 via {ip1}') debug(f'ip route add 10.3.0.{j+1}/32 via {ip2}') debug(f'ip route add 10.3.0.{i+1}/32 via {ip1}') - # print ips - print(f"relay {i+1} ip: {ip1} relay {j+1} ip: {ip2}") + debug(f"relay {i+1} ip: {ip1} relay {j+1} ip: {ip2}") network_counter += 1 delay=None @@ -289,7 +288,6 @@ def extract_latency(line): intf = net.addLink( root, api ).intf1 root.setIP( '10.2.0.99', intf=intf ) - # *** Setting up "api network" ip_counter = 1 net.addLink( @@ -381,7 +379,7 @@ def get_video_duration(file_path): if track_duration > max_video_duration: max_video_duration = track_duration else: - if config['mode']=='clock': + if config['mode'] in ['clock', 'clockr']: try: max_video_duration=int(vidi_filenammm.split("-")[2]) except: @@ -390,8 +388,9 @@ def get_video_duration(file_path): resolution=track.split("_")[1].split("-")[1] if int(resolution)>max_resolution: max_resolution=int(resolution) + le_cmd="" - if config['mode'] == 'clock': + if config['mode'] in ['clock', 'clockr']: le_cmd=(f'xterm -hold -T "{h.name}-pub" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --publish --namespace {track} https://{first_hop_relay[k][0]}:4443 {tls_verify_str}" &') else: if config['mode'] == 'ffmpeg': @@ -432,8 +431,9 @@ def get_video_duration(file_path): filename = f"measurements/{track}_{current_time}_{h.name}" errorfile1=f"measurements/{track}_{current_time}_{h.name}_iferror" errorfile2=f"measurements/{track}_{current_time}_{h.name}_iferror2" - if config['mode'] == 'clock': - le_cmd=(f'xterm -hold -T "{h.name}-sub-t" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --namespace {track} https://{last_hop_relay[k][0]}:4443 {tls_verify_str} >> {filename}.txt" &') + if config['mode'] in ['clock', 'clockr']: + + le_cmd=(f'xterm -hold -T "{h.name}-sub-t" -e bash -c "RUST_LOG=info ./target/debug/moq-clock --namespace {track} https://{last_hop_relay[k][0]}:4443 {tls_verify_str} | tee {filename}.txt" &') else: if config['mode'] == 'ffmpeg': le_cmd=(f'xterm -hold -T "{h.name}-sub-t" -e bash -c "RUST_LOG=info RUST_BACKTRACE=1 ./target/debug/moq-sub --name {track} {tls_verify_str} https://{last_hop_relay[k][0]}:4443 ' @@ -475,7 +475,6 @@ def get_video_duration(file_path): subprocess.call(['xdotool', 'search', '--name', f'h{i}sub', 'windowmove', f'{i*max_resolution+50}', '0']) - if all_gas_no_brakes and not my_debug: sleep(max_video_duration+2) else: @@ -524,11 +523,14 @@ def get_video_duration(file_path): all_network_receive_packets += int(stats[1]) all_network_transmit_bytes += int(stats[8]) all_network_transmit_packets += int(stats[9]) + with open(f"measurements/{current_time}_api_network.txt", 'w') as file: + file.write(api.cmd('cat /proc/net/dev')) + file.write(api.cmd('ip -br a')) sum_cost = {} - if config['mode'] == 'clock': + if config['mode'] in ['clock', 'clockr']: for (h, track) in subs: file_path1 = f"measurements/{track}_{current_time}_{h.name}.txt" @@ -537,10 +539,13 @@ def get_video_duration(file_path): file_path2 = f"measurements/{track}_{current_time}_{h.name}_clocked.txt" with open(file_path2, 'w') as file: counter2=0 + # we leave out the first 5 lines because regardless of the hw resources they are always around 1 second and so spoil the averages for line in output.splitlines(): try: - latency = int(line.strip())*1000000 - file.write(f"{latency},{counter2}\n") + number=int(line.strip()) + if number<1000: + latency = number*1000000 + file.write(f"{latency},{counter2}\n") except ValueError: continue @@ -591,7 +596,7 @@ def get_video_duration(file_path): with open(f"{filename}_cleaned.txt", 'w') as file: file.writelines(csv_lines) - if (config['mode'] == 'gst') or (config['mode'] == 'clock'): + if config['mode'] in ['gst','clock','clockr']: if gst_shark>0: print("latest_files: ", latest_files) @@ -657,7 +662,7 @@ def get_video_duration(file_path): if config['mode'] == 'gst': end_of_file_part="cleaned" else: - if config['mode'] == 'clock': + if config['mode'] in ['clock', 'clockr']: end_of_file_part="clocked" @@ -668,10 +673,10 @@ def get_video_duration(file_path): enddelays_file.write(f"{header}") print(f"{header}") clock_str="" - if config['mode'] == 'clock': - clock_str="-clock" + if config['mode'] in ['clock', 'clockr']: + clock_str=f"-{config['mode']}" enddelays_file.write(f"\n{config['api']}{clock_str}-{topofile}") - print(f"{config['api']}-{topofile}") + print(f"{config['mode']}-{config['api']}-{topofile}") for (h,track) in subs: file_path = f"measurements/{track}_{current_time}_{h.name}" with open(f"{file_path}_{end_of_file_part}.txt", 'r') as file: @@ -706,8 +711,8 @@ def get_video_duration(file_path): else: ending_time=0 did_it_warn=0 - actual_line=f"\n{file_path.replace('measurements/','')};{average};{distribution};{based_line};{average-based_line};{count};{did_it_warn};{ending_time};{sum_cost[track]};;{all_network_receive_bytes};{all_network_transmit_bytes};{all_network_receive_packets};{all_network_transmit_packets}" - enddelays_file.write(f"{actual_line}") + actual_line=f"{file_path.replace('measurements/','')};{average};{distribution};{based_line};{average-based_line};{count};{did_it_warn};{ending_time};{sum_cost[track]};;{all_network_receive_bytes};{all_network_transmit_bytes};{all_network_receive_packets};{all_network_transmit_packets}" + enddelays_file.write(f"\n{actual_line}") print(f"{actual_line}") if gst_shark == 2: enddelays_file.write(f">> subtracting average interlatency: {average-baseline}\n")