-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
171 lines (137 loc) · 4.78 KB
/
__init__.py
File metadata and controls
171 lines (137 loc) · 4.78 KB
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
162
163
164
165
166
167
168
169
170
171
import re
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Generic, TypeVar
from ..config import Config
from ..util import iterate
T = TypeVar("T")
class AbstractBenchmark(ABC, Generic[T]):
"""
Abstract Benchmark
"""
def __init__(self, param_cls: type[T]):
self.P = param_cls
@abstractmethod
def get_command(self, params: T, config: Config) -> str:
"""Return command to execute
Args:
params (T): Current parameter combination
config (Config): Updated benchmark configuration
Returns:
str: Command to execute as benchmark
"""
@abstractmethod
def get_env(self, params: T, config: Config) -> dict:
"""Return dictionary of environment variables to set before running benchmark
Args:
params (T): Current parameter combination
config (Config): Updated benchmark configuration
Returns:
dict: Dictionary of environment variables
"""
@abstractmethod
def get_varparams(self) -> dict[str, list]:
"""Return the parameter space definition as a map
parameter name => list of parameter values
Returns:
dict[str, list]: Parameter space definition
"""
@abstractmethod
def filter_varparams(self, params: T, config: Config) -> bool:
"""Return True if given initial configuration and parameter combination is valid
Args:
params (T): Current parameter combination
config (Config): Initial configuration
Returns:
bool: True if initial configuration and current parameter combination is valid
"""
@abstractmethod
def update_config(self, params: T, config: Config) -> Config:
"""Update configuration from given parameters
Args:
params (T): Current parameter iteration
config (Config): Initial configuration
Returns:
Config: Updated configuration from current parameter iteration
"""
@abstractmethod
def get_data_rows(self, params: T, stats: dict) -> dict | list[dict]:
"""Return a single data row or multiple data rows to be written to a CSV file
Args:
params (T): _description_
stats (dict): _description_
Returns:
dict | list[dict]: Return single or multiple data rows
"""
@property
def name(self):
"""
Benchmark name
"""
return self.__class__.__name__
def get_bench_command(self, config: Config) -> str:
"""
Update Config
"""
return self.get_command(self.P(**config.parameters), config)
def get_env_vars(self, config: Config) -> dict:
"""
Update Config
"""
return self.get_env(self.P(**config.parameters), config)
def get_parameter_list(self, config: Config) -> list[dict]:
"""
Get filtered parameter list
"""
parameters = [
p
for p in iterate(self.get_varparams())
if self.filter_varparams(self.P(**p), config)
]
assert len(parameters) > 0
return parameters
def get_updated_config(self, config: Config) -> Config:
"""
Update Config
"""
return self.update_config(self.P(**config.parameters), config)
def get_column_keys(self, config: Config) -> dict:
"""
Return dictionary for parsed parameter columns
"""
params_dict = dict(**config.parameters)
return params_dict
def get_data_rows_from_stats(self, stats: dict) -> list[dict]:
params = dict([(k, stats[k]) for k in self.get_varparams().keys()])
r = self.get_data_rows(self.P(**params), stats)
if isinstance(r, dict):
r = [r]
for e in r:
e.update(
dict(
bench_name=stats["bench_name"],
bench_id=stats["bench_id"],
roi_id=stats["roi_id"],
**params,
)
)
return r
def parse_output_log(self, output_file: Path) -> dict:
if not output_file.exists():
return dict()
output_log = output_file.read_text()
cdict: dict = dict(
aborted=dict(), links=dict(), router=dict(), network=dict(links=list())
)
for l in iter(output_log.splitlines()):
p = r"BEGIN LIBC BACKTRACE"
m = re.search(p, l)
if m:
cdict["aborted"]["backtrace"] = True
continue
else:
cdict["aborted"]["backtrace"] = False
return cdict
def parse_stdout_log(self, stdout_file: Path) -> dict:
rdict = dict()
return rdict