forked from sebva/sgx-orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
superrunner.py
executable file
·86 lines (71 loc) · 3.72 KB
/
superrunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python3 -u
import argparse
import os
import sys
import time
import traceback
from typing import List
sys.path.insert(1, os.path.join(sys.path[0], '../results-parser'))
import logs_parser
from kubernetes.client import V1Pod
from kubernetes.client.models.v1_delete_options import V1DeleteOptions
import runner
def running_experiment_pods(include_attacker=False) -> List[V1Pod]:
return [x for x in runner.api.list_namespaced_pod("default").items if
x.metadata.name.startswith("experiment-") and (include_attacker or ("attacker" not in x.metadata.name))
]
def clean_experiment_pods():
pod_names = (x.metadata.name for x in running_experiment_pods(include_attacker=True))
for pod_name in pod_names:
print("Deleting " + pod_name)
runner.api.delete_namespaced_pod(pod_name, "default", V1DeleteOptions())
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Super Runner")
parser.add_argument("-s", "--scheduler", help="Scheduler(s) to use", nargs="+", required=True)
parser.add_argument("-x", "--sgx", help="Fraction(s) of SGX jobs", type=float, nargs="+", required=True)
parser.add_argument("-a", "--attacker", help="Fraction(s) of memory allocated by attacker", type=float, nargs="+",
required=True)
parser.add_argument("-k", "--skip", default=-1, type=int, nargs="?", help="Skip every nth job")
parser.add_argument("trace", help="Trace file")
args = parser.parse_args()
filename_time = time.strftime("%Y-%m-%d-%H%M")
print("--- SUPER RUNNER ---")
for scheduler in args.scheduler:
for sgx_fraction in args.sgx:
for attacker_fraction in args.attacker:
try:
runner.scheduler_name = scheduler
runner.proportion_sgx = sgx_fraction
runner.memory_fraction_attacked = attacker_fraction
print("Checking that no experiment pods are present")
if len(running_experiment_pods()) > 0:
print("Cleaning up before new job")
clean_experiment_pods()
print("SR job starts. scheduler: '%s', sgx: %f, attack: %f, trace: '%s', skip: %d" % (
scheduler, sgx_fraction, attacker_fraction, args.trace, args.skip
))
intermediate_file = "rawrunner_%s_%s_%f_%f.txt" % (
filename_time, scheduler, sgx_fraction, attacker_fraction
)
with open(intermediate_file, "w") as f:
runner.main(args.trace, args.skip, f)
print("Runner finished, waiting for all pods to finish...")
while True:
nb_pods = len(
[x for x in running_experiment_pods() if x.status.phase in ("Pending", "Running")])
print("Still %d pods to wait" % nb_pods)
if nb_pods > 0:
time.sleep(10)
else:
break
print("Finished, now parsing logs")
output_file = "runner_%s_%s_%f_%f.txt" % (filename_time, scheduler, sgx_fraction, attacker_fraction)
print("Output is: " + output_file)
logs_parser.main(intermediate_file, output_file)
print("Parsing finished, cleaning up...")
clean_experiment_pods()
print("SR job ends")
except: # Gotta Catch 'Em All!
traceback.print_exc()
print("SR JOB HAS CRASHED! Continuing...")
print("--- SUPER RUNNER END ---")