Skip to content
Snippets Groups Projects
Commit 06837f57 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Finished the hpvm-profiler

parent 98f92667
No related branches found
No related tags found
No related merge requests found
from pathlib import Path from pathlib import Path
from subprocess import CalledProcessError, PIPE
from typing import Iterable, List, Tuple, Union from typing import Iterable, List, Tuple, Union
from dataclasses import dataclass from dataclasses import dataclass
from tqdm import trange
PathLike = Union[Path, str] PathLike = Union[Path, str]
conf_opening, conf_closing = "+++++", "-----"
def profile_configs( def profile_configs(
...@@ -43,12 +46,18 @@ def profile_configs( ...@@ -43,12 +46,18 @@ def profile_configs(
raise ValueError("Config file with no configs is unsupported.") raise ValueError("Config file with no configs is unsupported.")
temp_file = NamedTemporaryFile("w") temp_file = NamedTemporaryFile("w")
baseline_time, baseline_acc = None, None baseline_time, baseline_acc = None, None
for idx, config in enumerate(configs): for idx in trange(len(configs), desc="Configs profiled"):
config = configs[idx]
# Write config to temp config file # Write config to temp config file
write_hpvm_config(header, [config], Path(temp_file.name)) write_hpvm_config(header, [config], Path(temp_file.name))
# Run binary_path binary, # Run binary_path binary,
# which generates `profile_filename` and `qos_filename` file in cwd. # which generates `profile_filename` and `qos_filename` file in cwd.
check_call(str(binary_path)) try:
check_call([str(binary_path), "-c", str(temp_file.name)], stdout=PIPE)
except CalledProcessError as e:
print("Output from the program:")
print(e.output)
raise e
# Read these two files for time and QoS info. # Read these two files for time and QoS info.
time = _read_profile_file(Path(profile_filename)) time = _read_profile_file(Path(profile_filename))
acc = _read_qos_file(Path(qos_filename)) acc = _read_qos_file(Path(qos_filename))
...@@ -129,7 +138,8 @@ class Config: ...@@ -129,7 +138,8 @@ class Config:
self.qos_loss, self.qos_loss,
] ]
header = " ".join(str(field) for field in header_fields) header = " ".join(str(field) for field in header_fields)
return f"{header}\n{self.config_body}" lines = [conf_opening, header, *self.config_body, conf_closing]
return "\n".join(lines)
__str__ = __repr__ __str__ = __repr__
...@@ -139,13 +149,12 @@ def read_hpvm_configs(config_file: PathLike) -> Tuple[str, List[Config]]: ...@@ -139,13 +149,12 @@ def read_hpvm_configs(config_file: PathLike) -> Tuple[str, List[Config]]:
ret_configs = [] ret_configs = []
with open(config_file) as f: with open(config_file) as f:
text = f.read() text = f.read()
opening, closing = "+++++", "-----"
# There's 1 float sitting on the first line of config file. # There's 1 float sitting on the first line of config file.
# We don't use it, but want to keep that intact. # We don't use it, but want to keep that intact.
header, *configs = text.split(opening) header, *configs = text.split(conf_opening)
header = header.strip() header = header.strip()
for config_text in configs: for config_text in configs:
config_text = config_text.replace(closing, "").strip() config_text = config_text.replace(conf_closing, "").strip()
config_header, *config_body = config_text.splitlines() config_header, *config_body = config_text.splitlines()
conf_name, *number_fields = config_header.split(" ") conf_name, *number_fields = config_header.split(" ")
speedup, energy, qos, qos_drop = [float(s) for s in number_fields] speedup, energy, qos, qos_drop = [float(s) for s in number_fields]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment