-
Notifications
You must be signed in to change notification settings - Fork 14
/
continuum.py
161 lines (127 loc) · 4.85 KB
/
continuum.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
"""\
Entry file for the benchmark.
Parse the config file, and continue from there on.
Check the documentation and help for more information.
"""
import argparse
import os
import os.path
import sys
import logging
import time
from application import application
from execution_model import execution_model
from infrastructure import infrastructure
from resource_manager import resource_manager
# pylint: disable-next=redefined-builtin
from input import input
def make_wide(formatter, w=120, h=36):
"""Return a wider HelpFormatter
Args:
formatter (HelpFormatter): Format class for Python Argparse
w (int, optional): Width of Argparse output. Defaults to 120.
h (int, optional): Max help positions for Argparse output. Defaults to 36.
Returns:
formatter: Format class for Python Argparse, possibly with updated output sizes
"""
try:
kwargs = {"width": w, "max_help_position": h}
formatter(None, **kwargs)
return lambda prog: formatter(prog, **kwargs)
except TypeError:
print("Argparse help formatter failed, falling back.")
return formatter
def set_logging(args):
"""Enable logging to both stdout and file (BENCHMARK_FOLDER/logs)
If -v/--verbose is used, stdout will report logging.DEBUG, otherwise only logging.INFO
The file will always use logging.DEBUG (which is the bigger scope)
Args:
args (Namespace): Argparse object
Returns:
(timestamp): Timestamp of the log file, used for all saved files
"""
# Log to file parameters
log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
if args.config["infrastructure"]["infra_only"]:
log_name = "%s_infra_only.log" % (t)
elif args.config["benchmark"]["resource_manager_only"]:
log_name = "%s_%s_%s.log" % (
t,
args.config["mode"],
args.config["benchmark"]["resource_manager"],
)
else:
log_name = "%s_%s_%s_%s.log" % (
t,
args.config["mode"],
args.config["benchmark"]["resource_manager"],
args.config["benchmark"]["application"],
)
file_handler = logging.FileHandler(log_dir + "/" + log_name)
file_handler.setLevel(logging.DEBUG)
# Log to stdout parameters
stdout_handler = logging.StreamHandler(sys.stdout)
if args.verbose:
stdout_handler.setLevel(logging.DEBUG)
else:
stdout_handler.setLevel(logging.INFO)
# Set parameters
logging.basicConfig(
format="[%(asctime)s %(pathname)s:%(lineno)s - %(funcName)s() ] %(message)s",
level=logging.DEBUG,
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[file_handler, stdout_handler],
)
logging.info("Logging has been enabled. Writing to stdout and file %s/%s", log_dir, log_name)
return t
def main(args):
"""Main control function of the framework
Args:
args (Namespace): Argparse object
"""
machines = infrastructure.start(args.config)
resource_manager.start(args.config, machines)
if args.config["module"]["execution_model"]:
execution_model.start(args.config, machines)
if args.config["module"]["application"]:
application.start(args.config, machines)
if args.config["infrastructure"]["delete"]:
infrastructure.delete_vms(args.config, machines)
logging.info("Finished\n")
else:
s = []
for ssh in args.config["cloud_ssh"] + args.config["edge_ssh"] + args.config["endpoint_ssh"]:
s.append("ssh %s -i %s" % (ssh, args.config["ssh_key"]))
logging.info("To access the VMs:\n\t%s\n", "\n\t".join(s))
if "benchmark" in args.config and args.config["benchmark"]["observability"]:
logging.info(
"To access Grafana: ssh -L 3000:%s:3000 %s -i %s",
args.config["cloud_ips"][0],
args.config["cloud_ssh"][0],
args.config["ssh_key"],
)
logging.info(
"To access Prometheus: ssh -L 9090:%s:9090 %s -i %s",
args.config["cloud_ips"][0],
args.config["cloud_ssh"][0],
args.config["ssh_key"],
)
if __name__ == "__main__":
# Get input arguments, and validate those arguments
parser_obj = argparse.ArgumentParser(
formatter_class=make_wide(argparse.HelpFormatter, w=120, h=500)
)
parser_obj.add_argument(
"config",
type=lambda x: input.start(parser_obj, x),
help="benchmark config file",
)
parser_obj.add_argument("-v", "--verbose", action="store_true", help="increase verbosity level")
arguments = parser_obj.parse_args()
timestamp = set_logging(arguments)
arguments.config["timestamp"] = timestamp
input.print_input(arguments.config)
main(arguments)