Skip to content

Commit f7adba7

Browse files
committed
Implementation for full energibridge logging with self-measure
1 parent 57e9963 commit f7adba7

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

examples/measure-self-profiling/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ Optionally set self_measure_bin to the path of your executable.
2323
From the root directory of the repo, run the following command:
2424

2525
```bash
26-
python experiment-runner/ examples/energibridge-profiling/RunnerConfig.py
26+
python experiment-runner/ examples/measure-self-profiling/RunnerConfig.py
2727
```
2828

2929
## Results
3030

31-
The results are generated in the `examples/energibridge-profiling/experiments` folder.
31+
The results are generated in the `examples/measure-self-profiling/experiments` folder, and are added to your run table model.
32+
A log file can be specified to additionally save the full energibridge logs to a separate file.
3233

33-
**!!! WARNING !!!**: COLUMNS IN THE `energibridge.csv` FILES CAN BE DIFFERENT ACROSS MACHINES.
34-
ADJUST THE DATAFRAME COLUMN NAMES ACCORDINGLY.
34+
**!!! WARNING !!!**: COLUMNS IN THE `energibridge.log` FILES CAN BE DIFFERENT ACROSS MACHINES.
35+
ADJUST YOUR ANALYSIS OF THE RESULTS ACCORDINGLY.
3536

examples/measure-self-profiling/RunnerConfig.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RunnerConfig:
3131
time_between_runs_in_ms: int = 1000
3232

3333
"""
34-
Whether EnergiBridge should be used to measure the energy consumption of the entire system durring
34+
Whether EnergiBridge should be used to measure the energy consumption of the entire system during
3535
the experiment.
3636
3737
This parameter is optional and defaults to False
@@ -40,11 +40,19 @@ class RunnerConfig:
4040

4141
"""
4242
Where the EnergiBridge executable is located. As its not a package on linux distros, and must be
43-
installed manually install location can vary.
43+
installed manually, the install location can vary.
4444
4545
This parameter is optional and defaults to /usr/local/bin/energibridge
4646
"""
4747
self_measure_bin: Path = "/usr/local/bin/energibridge"
48+
49+
"""
50+
Where to save the full log files for energibridge. If specified, log files are saved to context.run_dir/<self_measure_logfile>.
51+
If self_measure_logfile is None, then no log file is generated.
52+
53+
This parameter is optional and defaults to None, where only summary results will be saved in the run table.
54+
"""
55+
self_measure_logfile: Path = "energibridge.log"
4856

4957
# Dynamic configurations can be one-time satisfied here before the program takes the config as-is
5058
# e.g. Setting some variable based on some criteria

experiment-runner/ConfigValidator/Config/Validation/ConfigValidator.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __check_expression(name, value, expected, expression):
2424

2525
# Verifies that an energybridge executable is present, and can be executed without error
2626
@staticmethod
27-
def __validate_energibridge(measure_enabled, eb_path):
27+
def __validate_energibridge(measure_enabled, eb_path, eb_logfile):
2828
# Do nothing if its not enabled
2929
if not measure_enabled:
3030
return
@@ -36,7 +36,13 @@ def __validate_energibridge(measure_enabled, eb_path):
3636
ConfigValidator.error_found = True
3737
ConfigValidator \
3838
.config_values_or_exception_dict["EnergiBridge"] = "EnergiBridge executable was not present or valid"
39-
39+
40+
if eb_logfile \
41+
and not is_path_exists_or_creatable_portable(eb_logfile):
42+
ConfigValidator.error_found = True
43+
ConfigValidator \
44+
.config_values_or_exception_dict["EnergiBridge"] = f"EnergiBridge logfile ({eb_logfile}) was not a valid path"
45+
4046
# Test run to see if energibridge works
4147
try:
4248
eb_args = [eb_path, "--summary", "-o", "/dev/null", "--", "sleep", "0.5"]
@@ -70,13 +76,17 @@ def validate_config(config: RunnerConfig):
7076
if '~' in str(config.experiment_path):
7177
config.experiment_path = config.experiment_path.expanduser()
7278

73-
# Set defaults to support configs without the self_measure parameter
79+
# Set defaults to support configs without the self_measure parameter and friends
7480
if not hasattr(config, "self_measure"):
7581
config.self_measure = False
7682

77-
if config.self_measure and not hasattr(config, "self_measure_bin"):
78-
config.self_measure_bin = "/usr/local/bin/energibridge" # This is spesific to linux, might work for osx as well
79-
83+
if config.self_measure:
84+
if not hasattr(config, "self_measure_bin"):
85+
config.self_measure_bin = "/usr/local/bin/energibridge" # This is spesific to linux, might work for osx as well
86+
87+
if not hasattr(config, "self_measure_logfile"):
88+
config.self_measure_logfile = None
89+
8090
# Convert class to dictionary with utility method
8191
ConfigValidator.config_values_or_exception_dict = class_to_dict(config)
8292

@@ -102,7 +112,10 @@ def validate_config(config: RunnerConfig):
102112
(lambda a, b: is_path_exists_or_creatable_portable(a))
103113
)
104114

105-
ConfigValidator.__validate_energibridge(config.self_measure, config.self_measure_bin)
115+
ConfigValidator.__validate_energibridge(config.self_measure,
116+
config.self_measure_bin,
117+
config.self_measure_logfile
118+
)
106119

107120
# Display config in user-friendly manner, including potential errors found
108121
print(

experiment-runner/ExperimentOrchestrator/Experiment/Run/RunController.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import os
23

34
from ProgressManager.RunTable.Models.RunProgress import RunProgress
45
from EventManager.Models.RunnerEvents import RunnerEvents
@@ -13,8 +14,15 @@ def start_eb(self):
1314
if not self.config.self_measure:
1415
return
1516

16-
eb_args = [self.config.self_measure_bin, "--summary",
17-
"-o", "/dev/null", "--", "sleep", "1000000"]
17+
eb_args = [self.config.self_measure_bin, "--summary"]
18+
19+
if self.config.self_measure_logfile:
20+
eb_args += ["--output",
21+
os.path.join(self.run_context.run_dir.resolve(), self.config.self_measure_logfile)]
22+
else:
23+
eb_args += ["-o", "/dev/null"]
24+
25+
eb_args += ["--", "sleep", "1000000"]
1826

1927
try:
2028
self.eb_proc = subprocess.Popen(eb_args, stdout=subprocess.PIPE,

0 commit comments

Comments
 (0)