Skip to content

Commit

Permalink
add api logfile, added clockr
Browse files Browse the repository at this point in the history
  • Loading branch information
1majom committed Oct 9, 2024
1 parent d67c648 commit a97a199
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
18 changes: 14 additions & 4 deletions base_try.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 "&')
Expand Down Expand Up @@ -147,17 +150,24 @@ 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"
with open(file_path1, 'r') as file:
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)
Expand Down
55 changes: 30 additions & 25 deletions good-try.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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':
Expand Down Expand Up @@ -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 '
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"


Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a97a199

Please sign in to comment.