-
Notifications
You must be signed in to change notification settings - Fork 2
/
ks-runner.py
70 lines (52 loc) · 1.57 KB
/
ks-runner.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
#! /usr/bin/python
import argparse
import subprocess
import time
import os
class Timer:
def __init__(self):
self.start = time.time_ns()
def stop(self):
end = time.time_ns()
duration = (end - self.start) / 1e9
return duration
def run_instances(instance, configs):
exec_time = {}
for conf in configs:
try:
print("Running", instance, conf)
timer = Timer()
subprocess.run(["python", "ks.py", "-c", conf, instance])
except:
pass
else:
time = timer.stop()
conf = os.path.basename(conf)
exec_time[conf] = time
return exec_time
def save_results(exec_time, output_file):
with open(output_file, "w") as file:
for conf, result in exec_time.items():
print(f"{conf},{result}", file=file)
def parse_args():
parser = argparse.ArgumentParser(
description="Run ks.py with the given set of configurations"
)
parser.add_argument("-i", "--instance", required=True)
parser.add_argument("-c", "--config", nargs="+")
parser.add_argument("-o", "--output")
return parser.parse_args()
def main():
args = parse_args()
if len(args.config) == 1:
dir_name = args.config[0]
configs = [os.path.join(dir_name, file) for file in os.listdir(dir_name)]
else:
configs = args.config
exec_time = run_instances(args.instance, configs)
if args.output:
save_results(exec_time, args.output)
else:
print(exec_time)
if __name__ == "__main__":
main()