diff --git a/artifact/common_util.py b/artifact/common_util.py index c47c4c6..5cee1d8 100644 --- a/artifact/common_util.py +++ b/artifact/common_util.py @@ -3,11 +3,37 @@ import asyncio import time -# pwd = "/Users/victoryang00/Documents/project/MVVM-bench/" -pwd = "/mnt/MVVM" +pwd = "/Users/victoryang00/Documents/project/MVVM-bench/" +# pwd = "/mnt/MVVM" slowtier = "epyc" burst = "mac" +def parse_time(time_string): + # Split the time string into components + components = time_string.split(":") + hours = int(components[0]) + minutes = int(components[1]) + seconds, milliseconds = map(int, components[2].split(".")) + + # Calculate the total seconds + total_seconds = hours * 3600 + minutes * 60 + seconds + milliseconds / 1000 + + return total_seconds + + +def parse_time_no_msec(time_string): + # Split the time string into components + components = time_string.split(":") + hours = int(components[0]) + minutes = int(components[1]) + seconds = int(components[2]) + + # Calculate the total seconds + total_seconds = hours * 3600 + minutes * 60 + seconds + if total_seconds < 10000: + print(time_string) + raise ValueError + return total_seconds def get_func_index(func, file): cmd = ["wasm2wat", "--enable-all", file] @@ -363,6 +389,7 @@ def run_checkpoint_restore_slowtier( f"script -q /dev/null -c 'ssh -t {slowtier} {pwd}/build/MVVM_restore -t {pwd}/build/bench/{aot_file1} {extra2}' >> MVVM_restore.1.out &" ) os.system(f"ssh -t {slowtier} {pwd}/artifact/run_with_cpu_monitoring_nocommand.sh MVVM_restore &") + # print(f"ssh -t {slowtier} bash -c 'cd {pwd}/build && {pwd}/artifact/run_with_cpu_monitoring_nocommand.sh MVVM_restore' &") os.system( f"script -q /dev/null -c './MVVM_restore -t ./bench/{aot_file1} {extra3}' >> MVVM_restore.out &" ) @@ -372,10 +399,10 @@ def run_checkpoint_restore_slowtier( os.system( f"../artifact/run_with_cpu_monitoring.sh ./MVVM_checkpoint -t ./bench/{aot_file1} {' '.join(['-a ' + str(x) for x in arg1])} -e {env} {extra1} &" ) - os.system("mv MVVM_checkpoint.out MVVM_checkpoint.1.out") - os.system("mv MVVM_checkpoint.ps.out MVVM_checkpoint.ps.1.out") os.system("sleep 10") os.system(f"pkill -SIGINT -f MVVM_checkpoint") + os.system("mv MVVM_checkpoint.out MVVM_checkpoint.1.out") + os.system("mv MVVM_checkpoint.ps.out MVVM_checkpoint.ps.1.out") os.system( f"../artifact/run_with_cpu_monitoring.sh ./MVVM_checkpoint -t ./bench/{aot_file} {' '.join(['-a ' + str(x) for x in arg])} -e {env}" ) @@ -384,6 +411,7 @@ def run_checkpoint_restore_slowtier( # print(checkpoint_result, restore_result) # Return a combined result or just the checkpoint result as needed os.system("sleep 100") + os.system(f"scp -r {slowtier}:{pwd}/build/MVVM_restore.ps.out ./MVVM_restore.ps.1.out") cmd = f"cat ./MVVM_checkpoint.out ./MVVM_checkpoint.1.out ./MVVM_restore.1.out ./MVVM_restore.out" cmd = cmd.split() @@ -407,6 +435,11 @@ def run_checkpoint_restore_burst( extra1: str = "", extra2: str = "", extra3: str = "", + extra4: str = "", + extra5: str = "", + extra6: str = "", + extra7: str = "", + extra8: str = "", ): # Execute run_checkpoint and capture its result res = [] @@ -416,7 +449,7 @@ def run_checkpoint_restore_burst( os.system( f"script -q /dev/null -c 'ssh -t {burst} {pwd}/build/MVVM_restore -t {pwd}/build/bench/{aot_file1} {extra2}' >> MVVM_restore.1.out &" ) - os.system(f"ssh -t {burst} ../artifact/run_with_energy_monitoring.sh MVVM_restore 1 &") + os.system(f"ssh -t {burst} bash -c ../artifact/run_with_energy_monitoring.sh MVVM_restore 1 &") os.system( f"script -q /dev/null -c './MVVM_restore -t ./bench/{aot_file1} {extra3}' >> MVVM_restore.out &" ) @@ -431,10 +464,10 @@ def run_checkpoint_restore_burst( os.system("sleep 10") os.system(f"pkill -SIGINT -f MVVM_checkpoint") os.system( - f"../artifact/run_with_energy_monitoring_mac.sh ./MVVM_checkpoint -t ./bench/{aot_file} {' '.join(['-a ' + str(x) for x in arg])} -e {env}" - ) + f"../artifact/run_with_energy_monitoring_mac.sh ./MVVM_checkpoint -t ./bench/{aot_file} {' '.join(['-a ' + str(x) for x in arg])} -e {env} {extra4}" + ) #redis os.system(f"ssh -t {burst} pkill -SIGINT -f MVVM_restore") - + os.system(f"") # print(checkpoint_result, restore_result) # Return a combined result or just the checkpoint result as needed os.system("sleep 100") diff --git a/artifact/result/optimistic.pdf b/artifact/result/optimistic.pdf index cc1df62..9d805ad 100644 Binary files a/artifact/result/optimistic.pdf and b/artifact/result/optimistic.pdf differ diff --git a/artifact/result/optimistic_computing.csv b/artifact/result/optimistic_computing.csv new file mode 100644 index 0000000..9fadadb --- /dev/null +++ b/artifact/result/optimistic_computing.csv @@ -0,0 +1,5 @@ +name,fasttier,slowtier,snapshot Time +OMP_NUM_THREADS=1 bc.aot -g10 -n100000,22.031722,29.936722,0.00499 +OMP_NUM_THREADS=1 bfs.aot -g10 -n1000000,72.930075,148.328455,0.004893 +OMP_NUM_THREADS=1 bc.aot -g10 -n100000,21.618244,29.969255,0.005453 +OMP_NUM_THREADS=1 bfs.aot -g10 -n1000000,74.279264,147.493264,0.004207 diff --git a/artifact/result/optimistic_computing.pdf b/artifact/result/optimistic_computing.pdf new file mode 100644 index 0000000..779bd47 Binary files /dev/null and b/artifact/result/optimistic_computing.pdf differ diff --git a/artifact/result/optimistic_cpu.pdf b/artifact/result/optimistic_cpu.pdf new file mode 100644 index 0000000..bd7e6f7 Binary files /dev/null and b/artifact/result/optimistic_cpu.pdf differ diff --git a/artifact/result/optimistic_memory.pdf b/artifact/result/optimistic_memory.pdf new file mode 100644 index 0000000..6b3adf3 Binary files /dev/null and b/artifact/result/optimistic_memory.pdf differ diff --git a/artifact/run_with_cpu_monitoring.sh b/artifact/run_with_cpu_monitoring.sh index 8c87c8f..116bcab 100644 --- a/artifact/run_with_cpu_monitoring.sh +++ b/artifact/run_with_cpu_monitoring.sh @@ -2,25 +2,19 @@ echo "$@" "$@" &> $1.out & pid1=$! +echo $pid1 # echo $pid > /sys/fs/cgroup/memory/my_cgroup/cgroup.procs # echo $(($first_arg * 1024 * 1024 * 1024)) > /sys/fs/cgroup/memory/my_cgroup/memory.limit_in_bytes +date >> $1.ps.out while true; do line=$(ps auxh -q $pid1) if [ "$line" == "" ]; then break fi - date >> $1.ps.out echo $line >>$1.ps.out - for child in $(pgrep -P $pid1); do - line=$(ps auxh -q $child) - if [ "$line" == "" ]; then - continue - fi - date >> $1.ps.out - echo $line >>$1.ps.out - done - sleep 0.01 + sleep 0.5 if ! ps -p $pid1 >/dev/null; then sleep 0.5 + exit 0 fi done \ No newline at end of file diff --git a/artifact/run_with_cpu_monitoring_nocommand.sh b/artifact/run_with_cpu_monitoring_nocommand.sh index b2f3fe5..e03bb31 100644 --- a/artifact/run_with_cpu_monitoring_nocommand.sh +++ b/artifact/run_with_cpu_monitoring_nocommand.sh @@ -1,18 +1,20 @@ #!/bin/bash echo "$@" -pid1=`ps aux | grep $1 | grep -v grep | awk '{print $2}'|tail -n 1` +pid1=`ps aux | grep $1 | grep -v grep | grep -v nocommand | grep -v ssh | awk '{print $2}'|head -n 1` echo $pid1 +sleep 2 # echo $pid > /sys/fs/cgroup/memory/my_cgroup/cgroup.procs # echo $(($first_arg * 1024 * 1024 * 1024)) > /sys/fs/cgroup/memory/my_cgroup/memory.limit_in_bytes +date >> $1.ps.out while true; do line=$(ps auxh -q $pid1) if [ "$line" == "" ]; then break fi - date >> $1.ps.out echo $line >>$1.ps.out - sleep 0.01 + sleep 0.5 if ! ps -p $pid1 >/dev/null; then sleep 0.5 + exit 0 fi done \ No newline at end of file diff --git a/artifact/run_with_energy_monitoring.sh b/artifact/run_with_energy_monitoring.sh index 28d97e9..260293a 100644 --- a/artifact/run_with_energy_monitoring.sh +++ b/artifact/run_with_energy_monitoring.sh @@ -1,28 +1,21 @@ #!/bin/bash echo "$@" -pid1=`ps aux | grep $1 | grep -v grep | awk '{print $2}'|tail -n 1` +pid1=`ps aux | grep $1 | grep -v grep | awk '{print $2}'|head -n 1` # echo $pid > /sys/fs/cgroup/memory/my_cgroup/cgroup.procs # echo $(($first_arg * 1024 * 1024 * 1024)) > /sys/fs/cgroup/memory/my_cgroup/memory.limit_in_bytes -pcm-power 1 -m -1 &> $1.$2.energy.out & +pcm-power 1 -m -1 &> $1.energy.$2.out & pid2=$! +date >> $1.ps.$2.out while true; do line=$(ps auxh -q $pid1) if [ "$line" == "" ]; then break fi - date >> $1.$2.ps.out - echo $line >> $1.$2.ps.out - for child in $(pgrep -P $pid1); do - line=$(ps auxh -q $child) - if [ "$line" == "" ]; then - continue - fi - date >> $1.$2.ps.out - echo $line >> $1.$2.ps.out - done + echo $line >> $1.ps.$2.out sleep 0.01 if ! ps -p $pid1 >/dev/null; then sleep 0.5 sudo kill -9 $pid2 + exit 0 fi done \ No newline at end of file diff --git a/artifact/run_with_energy_monitoring_mac.sh b/artifact/run_with_energy_monitoring_mac.sh index 2137d71..3c879f1 100644 --- a/artifact/run_with_energy_monitoring_mac.sh +++ b/artifact/run_with_energy_monitoring_mac.sh @@ -1,28 +1,21 @@ #!/bin/bash echo "$@" -pid1=`ps aux | grep $1 | grep -v grep | awk '{print $2}'|tail -n 1` +pid1=`ps aux | grep $1 | grep -v grep | awk '{print $2}'|head -n 1` # echo $pid > /sys/fs/cgroup/memory/my_cgroup/cgroup.procs # echo $(($first_arg * 1024 * 1024 * 1024)) > /sys/fs/cgroup/memory/my_cgroup/memory.limit_in_bytes -sudo asitop --show_cores &> $1.$2.energy.out & +sudo asitop --show_cores &> $1.energy.$2.out & pid2=$! +date >> $1.ps.$2.out while true; do line=$(ps auxh -q $pid1) if [ "$line" == "" ]; then break fi - date >> $1.$2.ps.out - echo $line >> $1.$2.ps.out - for child in $(pgrep -P $pid1); do - line=$(ps auxh -q $child) - if [ "$line" == "" ]; then - continue - fi - date >> $1.$2.ps.out - echo $line >> $1.$2.ps.out - done + echo $line >> $1.ps.$2.out sleep 0.01 if ! ps -p $pid1 >/dev/null; then sleep 0.5 sudo kill -9 $pid2 + exit 0 fi done \ No newline at end of file diff --git a/artifact/usecase_burst_computing.py b/artifact/usecase_burst_computing.py index 6521904..b4af2e0 100644 --- a/artifact/usecase_burst_computing.py +++ b/artifact/usecase_burst_computing.py @@ -3,11 +3,16 @@ from multiprocessing import Pool from matplotlib import pyplot as plt import numpy as np +from common_util import parse_time, parse_time_no_msec from collections import defaultdict -ip = ["128.114.53.32", "192.168.0.1"] -port = 12346 +ip = ["128.114.53.32", "128.114.59.134"] +port = 12345 +port2 = 12346 new_port = 1235 +new_port1 = 1238 +new_port2 = 1236 +new_port12 = 1239 cmd = [ "redis", # low priority task "rgbd_tum", # high priority task @@ -44,6 +49,7 @@ def get_cloud_result(): exec_time = line.split(" ")[-2] print(exec, exec_time) results.append((exec, exec_time)) # discover 4 aot_variant + return results def get_edge_result(): @@ -55,13 +61,7 @@ def get_edge_result(): results1.append( pool.apply_async( common_util.run_slowtier, - ( - aot, - arg[i], - envs[i], - f"-i {ip[0]} -e {port}", - f"-o {ip[1]} -s {port}", - ), + (aot, arg[i], envs[i]), ) ) # print the results @@ -73,6 +73,7 @@ def get_edge_result(): exec_time = line.split(" ")[-2] print(exec, exec_time) results.append((exec, exec_time)) # discover 4 aot_variant + return results def get_snapshot_overhead(): @@ -98,6 +99,7 @@ def get_snapshot_overhead(): exec_time = line.split(" ")[-2] print(exec, exec_time) results.append((exec, exec_time)) # discover 4 aot_variant + return results def get_burst_compute(): @@ -113,7 +115,13 @@ def get_burst_compute(): envs[0], f"-o {ip[1]} -s {port}", f"-i {ip[1]} -e {port} -o {ip[0]} -s {new_port}", - f"-i {ip[0]} -e {new_port}", + f"-i {ip[0]} -e {new_port} -o {ip[1]} -s {new_port1}", + f"-i {ip[1]} -e {new_port1} -o {ip[0]} -s {port}", + f"-o {ip[0]} -s {port2}", + f"-i {ip[0]} -e {port2} -o {ip[1]} -s {new_port2}", + f"-i {ip[1]} -e {new_port2} -o {ip[0]} -s {new_port12}", + f"-i {ip[0]} -e {new_port12} -o {ip[0]} -s {port2}", + ) return results1 @@ -230,22 +238,192 @@ def plot(file_name): # %% -def plog_time(): - pass +def plot_time(reu, checkpoint, checkpoint1, restore, restore1): + # get from reu + # start time -> end time -> start time + reu = reu.split("\\n") + state = 0 + time = [] + exec_time = [[], [], [], []] + for line in reu: + try: + if line.__contains__("Trial"): + to_append = float(line.split(" ")[-1].replace("\\r", "")) + if to_append < 0.001 and to_append > 0: + exec_time[state].append(to_append) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + if line.__contains__("Snapshot ") or line.__contains__("Execution "): + time.append(parse_time(line.split(" ")[1].replace("]", ""))) + print("time ", time) + state += 1 + except: + print(line) + # print(exec_time) + # print(time) + # record time + fig, ax = plt.subplots() + base = time[1] - sum(exec_time[1]) + + time_spots2 = [time[0] - sum(exec_time[0]) - base] + + for i in exec_time[0]: + # Add the current increment to the last time spot + new_time_spot = time_spots2[-1] + i + # Append the new time spot to the sequence + time_spots2.append(new_time_spot) + time_spots2.pop(0) + + time_spots = [time[1] - sum(exec_time[1]) - base] + for i in exec_time[1]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(0) + to_pop = len(time_spots) + time_spots.append(time[2] - sum(exec_time[2]) - base) + for i in exec_time[2]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(len(time_spots) - 1) + + to_pop = len(time_spots) + time_spots.append(time[3] - sum(exec_time[3]) - base) + for i in exec_time[3]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(to_pop - 1) + print(time[3] - sum(exec_time[3])) + ax.plot(time_spots, exec_time[1] + exec_time[2] + exec_time[3], "blue") + ax.plot(time_spots2, exec_time[0], "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average Trial Time (s)") + plt.savefig("burst.pdf") + + cpu = [] + memory = [] + exec_time_checkpoint = [] + cpu1 = [] + memory1 = [] + exec_time_checkpoint1 = [] + checkpoint = checkpoint.split("\n") + checkpoint1 = checkpoint1.split("\n") + restore = restore.split("\n") + restore1 = restore1.split("\n") + + for line in checkpoint1: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append(parse_time_no_msec(line.split(" ")[3])) + cpu1.append(0) + memory1.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu1.append(float(line.split(" ")[2])) + memory1.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + + except: + print(line) + for line in checkpoint1: + try: + if line.__contains__("2024"): + exec_time_checkpoint1.append( + parse_time_no_msec(line.split(" ")[3]) - 10 + ) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint1.append(exec_time_checkpoint1[-1] + 0.5) + + except: + print(line) + print(len(exec_time_checkpoint), len(cpu)) + for line in restore: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append(parse_time_no_msec(line.split(" ")[3])) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + + except: + print(line) + print(len(exec_time_checkpoint), len(cpu)) + for line in restore1: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append(parse_time_no_msec(line.split(" ")[3])) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + + except: + print(line) + print(exec_time_checkpoint) + ax.plot(exec_time_checkpoint, cpu, "b") + ax.plot(exec_time_checkpoint1, cpu1, "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average CPU (percentage)") + plt.savefig("burst_cpu.pdf") + fig, ax = plt.subplots() + ax.plot(exec_time_checkpoint, memory, "b") + ax.plot(exec_time_checkpoint1, memory1, "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average Memory (B)") + plt.savefig("burst_memory.pdf") + # parse energy if __name__ == "__main__": - fasttier = get_cloud_result() - slowtier = get_edge_result() - snapshot = get_snapshot_overhead() - print("fasttier = ", fasttier) - print("slowtier = ", slowtier) - print("snapshot = ", snapshot) - # plot skew - write_to_csv("burst_computing.csv") - - results = read_from_csv("burst_computing.csv") + # fasttier = get_cloud_result() + # slowtier = get_edge_result() + # snapshot = get_snapshot_overhead() + # print("fasttier = ", fasttier) + # print("slowtier = ", slowtier) + # print("snapshot = ", snapshot) + # # plot skew + # write_to_csv("burst_computing.csv") + + # results = read_from_csv("burst_computing.csv") + # plot(results) reu = get_burst_compute() + with open("burst.txt", "w") as f: + f.write(str(reu)) + reu = "" + with open("burst.txt", "r") as f: + reu = f.read() + with open("MVVM_checkpoint.ps.1.out") as f: + checkpoint1 = f.read() + with open("MVVM_checkpoint.ps.out") as f: + checkpoint = f.read() + with open("MVVM_restore.ps.1.out") as f: + restore1 = f.read() + with open("MVVM_restore.ps.out") as f: + restore = f.read() - plot(results) - plog_time(results) + plot_time(reu, checkpoint, checkpoint1, restore, restore1) diff --git a/artifact/usecase_optimistic_computing.py b/artifact/usecase_optimistic_computing.py index 18c17dd..eff138e 100644 --- a/artifact/usecase_optimistic_computing.py +++ b/artifact/usecase_optimistic_computing.py @@ -1,10 +1,11 @@ import csv import common_util +from common_util import parse_time, parse_time_no_msec from multiprocessing import Pool from matplotlib import pyplot as plt import numpy as np from collections import defaultdict -import json +import sys ip = ["128.114.53.32", "128.114.59.234"] port = 12346 @@ -231,17 +232,7 @@ def plot(file_name): plt.savefig("optimisitc_computing.pdf") # %% -def parse_time(time_string): - # Split the time string into components - components = time_string.split(':') - hours = int(components[0]) - minutes = int(components[1]) - seconds, milliseconds = map(int, components[2].split('.')) - - # Calculate the total seconds - total_seconds = hours * 3600 + minutes * 60 + seconds + milliseconds / 1000 - - return total_seconds + def plot_time(reu): # get from reu @@ -249,36 +240,36 @@ def plot_time(reu): reu = reu.split("\\n") state = 0 time = [] - exec_time = [[],[],[],[]] + exec_time = [[], [], [], []] for line in reu: try: if line.__contains__("Trial"): - to_append = float(line.split(" ")[-1].replace("\\r","")) - if to_append<0.001 and to_append>0: + to_append = float(line.split(" ")[-1].replace("\\r", "")) + if to_append < 0.001 and to_append > 0: exec_time[state].append(to_append) # print(exec_time) # print("exec_time ",exec_time[-1]) if line.__contains__("Snapshot ") or line.__contains__("Execution "): - time.append(parse_time(line.split(" ")[1].replace("]",""))) - print("time ",time) + time.append(parse_time(line.split(" ")[1].replace("]", ""))) + print("time ", time) state += 1 except: print(line) # print(exec_time) - + # print(time) # record time fig, ax = plt.subplots() - base = time[0]-sum(exec_time[0]) - time_spots2 = [time[1]-sum(exec_time[1])-base] + base = time[0] - sum(exec_time[0]) + time_spots2 = [time[1] - sum(exec_time[1]) - base] for i in exec_time[1]: # Add the current increment to the last time spot new_time_spot = time_spots2[-1] + i # Append the new time spot to the sequence time_spots2.append(new_time_spot) time_spots2.pop(0) - - time_spots = [time[0]-sum(exec_time[0])-base] + + time_spots = [time[0] - sum(exec_time[0]) - base] for i in exec_time[0]: # Add the current increment to the last time spot new_time_spot = time_spots[-1] + i @@ -286,31 +277,198 @@ def plot_time(reu): time_spots.append(new_time_spot) time_spots.pop(0) to_pop = len(time_spots) - time_spots.append(time[2]-sum(exec_time[2])-base) - + time_spots.append(time[2] - sum(exec_time[2]) - base) + for i in exec_time[2]: # Add the current increment to the last time spot new_time_spot = time_spots[-1] + i # Append the new time spot to the sequence time_spots.append(new_time_spot) - time_spots.pop(to_pop-1) - + time_spots.pop(to_pop - 1) + to_pop = len(time_spots) - time_spots.append(time[3]-sum(exec_time[3])-base) + time_spots.append(time[3] - sum(exec_time[3]) - base) for i in exec_time[3]: # Add the current increment to the last time spot new_time_spot = time_spots[-1] + i # Append the new time spot to the sequence time_spots.append(new_time_spot) - time_spots.pop(to_pop-1) - print(time[3]-sum(exec_time[3])) - ax.plot( time_spots, exec_time[0]+exec_time[2] +exec_time[3] ,"blue") + time_spots.pop(to_pop - 1) + print(time[3] - sum(exec_time[3])) + ax.plot(time_spots, exec_time[0] + exec_time[2] + exec_time[3], "blue") ax.plot(time_spots2, exec_time[1], "r") ax.set_xlabel("Time (s)") ax.set_ylabel("Average Trial Time (s)") plt.savefig("optimistic.pdf") +def plot_time(reu, checkpoint, checkpoint1, restore, restore1): + # get from reu + # start time -> end time -> start time + reu = reu.split("\\n") + state = 0 + time = [] + exec_time = [[], [], [], []] + for line in reu: + try: + if line.__contains__("Trial"): + to_append = float(line.split(" ")[-1].replace("\\r", "")) + if to_append < 0.001 and to_append > 0: + exec_time[state].append(to_append) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + if line.__contains__("Snapshot ") or line.__contains__("Execution "): + time.append(parse_time(line.split(" ")[1].replace("]", ""))) + print("time ", time) + state += 1 + except: + print(line) + # print(exec_time) + # print(time) + # record time + fig, ax = plt.subplots() + base = time[1] - sum(exec_time[1]) + + time_spots2 = [time[0] - sum(exec_time[0]) - base] + + for i in exec_time[0]: + # Add the current increment to the last time spot + new_time_spot = time_spots2[-1] + i + # Append the new time spot to the sequence + time_spots2.append(new_time_spot) + time_spots2.pop(0) + + time_spots = [time[1] - sum(exec_time[1]) - base] + for i in exec_time[1]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(0) + to_pop = len(time_spots) + time_spots.append(time[2] - sum(exec_time[2]) - base) + for i in exec_time[2]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(len(time_spots) - 1) + + to_pop = len(time_spots) + time_spots.append(time[3] - sum(exec_time[3]) - base) + for i in exec_time[3]: + # Add the current increment to the last time spot + new_time_spot = time_spots[-1] + i + # Append the new time spot to the sequence + time_spots.append(new_time_spot) + time_spots.pop(to_pop - 1) + print(time[3] - sum(exec_time[3])) + ax.plot(time_spots, exec_time[1] + exec_time[2] + exec_time[3], "blue") + ax.plot(time_spots2, exec_time[0], "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average Trial Time (s)") + plt.savefig("optimistic.pdf") + + cpu = [] + memory = [] + exec_time_checkpoint = [] + cpu1 = [] + memory1 = [] + exec_time_checkpoint1 = [] + checkpoint = checkpoint.split("\n") + checkpoint1 = checkpoint1.split("\n") + restore = restore.split("\n") + restore1 = restore1.split("\n") + + for line in checkpoint1: + try: + if line.__contains__("2024"): + exec_time_checkpoint1.append(parse_time_no_msec(line.split(" ")[3])) + cpu1.append(0) + memory1.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu1.append(float(line.split(" ")[2])) + memory1.append(float(line.split(" ")[5])) + exec_time_checkpoint1.append(exec_time_checkpoint1[-1] + 0.5) + else: + exec_time_checkpoint[-1] = exec_time_checkpoint[-1] + 0.5 + except: + print(line) + for line in checkpoint: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append( + parse_time_no_msec(line.split(" ")[3]) + ) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + else: + exec_time_checkpoint[-1] = exec_time_checkpoint[-1] + 0.5 + except: + print(line) + print(len(exec_time_checkpoint), len(cpu)) + for line in restore1: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append(parse_time_no_msec(line.split(" ")[3])) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + else: + exec_time_checkpoint[-1] = exec_time_checkpoint[-1] + 0.5 + except: + print(line) + print(exec_time_checkpoint) + for line in restore: + try: + if line.__contains__("2024"): + exec_time_checkpoint.append(parse_time_no_msec(line.split(" ")[3])) + cpu.append(0) + memory.append(0) + # print(exec_time) + # print("exec_time ",exec_time[-1]) + else: + if float(line.split(" ")[2]) > 10: + cpu.append(float(line.split(" ")[2])) + memory.append(float(line.split(" ")[5])) + exec_time_checkpoint.append(exec_time_checkpoint[-1] + 0.5) + else: + exec_time_checkpoint[-1] = exec_time_checkpoint[-1] + 0.5 + except: + print(line) + print(len(exec_time_checkpoint), len(cpu)) + + fig, ax = plt.subplots() + + ax.plot(exec_time_checkpoint, cpu, "b") + ax.plot(exec_time_checkpoint1, cpu1, "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average CPU (percentage)") + plt.savefig("optimistic_cpu.pdf") + fig, ax = plt.subplots() + ax.plot(exec_time_checkpoint, memory, "b") + ax.plot(exec_time_checkpoint1, memory1, "r") + ax.set_xlabel("Time (s)") + ax.set_ylabel("Average Memory (B)") + plt.savefig("optimistic_memory.pdf") + + if __name__ == "__main__": # fasttier = get_fasttier_result() # slowtier = get_slowtier_result() @@ -324,12 +482,19 @@ def plot_time(reu): # results = read_from_csv("optimisitc_computing.csv") # plot(results) - reu = get_optimiztic_compute_overhead() - with open('optimistic.txt', 'w') as f: - f.write(str(reu)) + # reu = get_optimiztic_compute_overhead() + # with open("optimistic.txt", "w") as f: + # f.write(str(reu)) reu = "" with open("optimistic.txt", "r") as f: reu = f.read() + with open("MVVM_checkpoint.ps.1.out") as f: + checkpoint1 = f.read() + with open("MVVM_checkpoint.ps.out") as f: + checkpoint = f.read() + with open("MVVM_restore.ps.1.out") as f: + restore1 = f.read() + with open("MVVM_restore.ps.out") as f: + restore = f.read() # print(reu) - plot_time(reu) - + plot_time(reu, checkpoint, checkpoint1, restore, restore1)