-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
105 lines (85 loc) · 2.49 KB
/
launcher.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import datetime
import os
from pathlib import Path
import sys
import subprocess
JOBS_DIR = "jobs"
REPORTS_DIR = "reports"
OUTPUT_FORMAT = "normal,terse,json,json+"
DEBUG = False
DRY_RUN = False
def get_current_dir():
return Path().absolute()
def new_experiment():
dt = datetime.datetime.now()
id_date = dt.strftime("%Y-%m-%d")
id_exp_number = 0
while True:
exp_id = "{0}-{1}".format(id_date, "{:02d}".format(id_exp_number))
path = Path.joinpath(get_current_dir(), REPORTS_DIR, exp_id)
if not Path.exists(path):
break
id_exp_number += 1
return exp_id, path
def get_jobs(jobs_dir):
jobs = []
for file in os.listdir(jobs_dir):
if file.endswith(".fio"):
jobs.append((file, str(Path.joinpath(get_current_dir(), JOBS_DIR, file))))
return jobs
# noinspection PyListCreation
def get_cmd(job, exp):
cmd = ["fio"]
cmd.append("--output-format={0}".format(OUTPUT_FORMAT))
cmd.append("--output={0}.report".format(Path.joinpath(exp[1], job[0])))
if DEBUG:
cmd.append("--debug")
# the last should be:
cmd.append(job[1])
return cmd
def run_experiment(exp):
exp[1].mkdir()
jobs_dir = Path.joinpath(get_current_dir(), JOBS_DIR)
print("Jobs dir: {0}".format(jobs_dir))
jobs = get_jobs(jobs_dir)
print("Jobs found: {0}".format(len(jobs)))
i = 0
for job in jobs:
i += 1
cmd = get_cmd(job, exp)
cmd_str = " ".join(cmd)
print("Job {0} ({1}/{2}) is running".format(job[0], i, len(jobs)))
print("Command: {0}".format(cmd_str))
if not DRY_RUN:
subprocess.call(cmd)
else:
print("DRY RUN!")
print("Job {0} was done".format(job[0]))
def set_params(args):
if "--debug" in args:
global DEBUG
DEBUG = True
print("DEBUG is ON")
if "--dry-run" in args:
global DRY_RUN
print("DRY_RUN is ON")
DRY_RUN = True
def main(args):
print("Started fio launcher")
print("Current dir: {0}".format(get_current_dir()))
set_params(args)
exp = new_experiment()
print("Experiment {0} is running".format(exp[0]))
run_experiment(exp)
print("Finished")
sys.exit(0)
def pre_init():
jd = Path.joinpath(get_current_dir(), JOBS_DIR)
if not jd.exists():
Path.mkdir(jd)
rd = Path.joinpath(get_current_dir(), REPORTS_DIR)
if not rd.exists():
Path.mkdir(rd)
if __name__ == '__main__':
pre_init()
main(sys.argv)