-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainCLI.py
161 lines (131 loc) · 4.1 KB
/
mainCLI.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""SPECtate.
Usage:
mainCLI.py run [options] <config> [--props <props>]
mainCLI.py validate [options] <config>
mainCLI.py dialogue [options]
mainCLI.py (-h | --help)
mainCLI.py --version
Options:
--level=<log-level> Set the logging level. Uses python.logging's names for the different leves. [default: INFO]
"""
# library imports
import json
import os
import logging
import sys
from subprocess import call
from shutil import copy, rmtree
# external imports
from docopt import docopt
# source imports
import dialogue
from src import validate
from src import run_generator
from src import benchmark_run
def to_list(s):
if s["run_type"].lower() in ["hbir", "hbir_rt"]:
return [
s["run_type"], # RUNTYPE
s["kit_version"], # kitVersion
s["tag"], # tag
s["jdk"], # JDK
s["rt_start"], # RT curve start
" ".join(s["jvm_options"]), # JVM options
s["numa_node"], # NUMA node
s["data"], # DATA
s["t"][0], # T1
s["t"][1], # T2
s["t"][2], # T3
]
else:
return [
s["run_type"], # runtype
s["kit_version"], # kitversion
s["tag"], # tag
s["jdk"], # jdk
s["rt_start"], # rt curve start
s["duration"],
" ".join(s["jvm_options"]), # jvm options
s["numa_node"], # numa node
s["data"], # data
s["t"][0], # t1
s["t"][1], # t2
s["t"][2], # t3
]
def relative_to_main(relname):
return os.path.join(os.path.dirname(__file__), relname)
blackbox_artifacts = [
'.run_number',
'controller.out',
'specjbb2015.props',
'sut.txt',
]
def do_run(arguments):
"""
Does a run using scripts/run.sh from the provided property template and configuration.
"""
with open(arguments['<config>'], 'r') as f:
args = json.loads(f.read())
stringified = list(map(lambda arg: str(arg), to_list(args['specjbb'])))
workdir = args['specjbb'].get('workdir', 'scripts')
scripts_abspath = relative_to_main(workdir)
workdir_abspath = relative_to_main('scripts')
# if we don't already have the scripts available to us
# copy them into the new location
if workdir != 'scripts':
copy(scripts_abspath, workdir_abspath)
def cleanup():
# we need to cleanup the cwd or worktree for some reason
if workdir != 'scripts':
rmtree(workdir_abspath)
else:
for name in map(lambda name: os.path.join(scripts_abspath, name),
blackbox_artifacts):
os.remove(name)
try:
if not call(['bash', 'run.sh'] + stringified, cwd=workdir_abspath):
cleanup()
except:
cleanup()
def do_validate(arguments):
"""
Validate a configuration based on the schema provided.
"""
with open(arguments['<config>'], 'r') as f:
args = json.loads(f.read())
try:
if validate.validate_blackbox(args) is not None:
return
except Exception as e:
print(e)
print("attempting to validate SPECtate configuration...")
try:
return validate.validate(args) is None
except Exception as e:
return e
return True
def do_dialogue(arguments):
dialogue.dialogue()
def do_run(arguments):
with open(arguments['<config>'], 'r') as f:
args = json.loads(f.read())
rs = run_generator.RunGenerator(**args)
for r in rs.runs:
s = benchmark_run.SpecJBBRun(**r)
s.run()
# dictionary of runnables
# these are functions that take arguments from the
# command line and do something with them.
do = {
'run': do_run,
'validate': do_validate,
'dialogue': do_dialogue,
}
if __name__ == "__main__":
arguments = docopt(__doc__, version='SPECtate v0.1')
logging.basicConfig(level=logging.getLevelName(arguments['--level']))
for key, func in do.items():
if arguments[key]:
r = func(arguments)
if not r or r is not None:
sys.exit(r)