Skip to content

Commit b7fecd9

Browse files
committed
Completed nvml and powerletrics plugins
+ made changing the logfile location a bit more dynamic.
1 parent 91920d7 commit b7fecd9

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

examples/powerletrics-profiling/RunnerConfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def before_experiment(self) -> None:
6868
"""Perform any activity required before starting the experiment here
6969
Invoked only once during the lifetime of the program."""
7070

71-
PowerLetrics.source_name = ".env/bin/powerletrics"
7271
self.profiler = PowerLetrics(additional_args={
7372
"--show-process-io": None,
7473
"--show-process-netstats": None})
@@ -115,6 +114,7 @@ def populate_run_data(self, context: RunnerContext) -> Optional[Dict[str, Any]]:
115114
# Powerletrics outputs stats for each process
116115
pl_log = self.profiler.parse_log(self.profiler.logfile)
117116

117+
# Parse the stats for the values you are interested in
118118
first_process = pl_log[0][0]
119119
return {"energy_footprint": first_process['Energy Footprint'],
120120
"cpu_utilization": first_process["CPU Utilization (%)"],

experiment-runner/Plugins/Profilers/DataSource.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ def __contains__(self, key):
6666

6767
return False
6868

69+
class ValueRef:
70+
def __init__(self, value):
71+
self.value = value
72+
6973
class DataSource(ABC):
7074
def __init__(self):
7175
self._validate_platform()
72-
self._logfile = None
7376

7477
def _validate_platform(self):
7578
if platform.system() in self.supported_platforms:
@@ -110,21 +113,26 @@ def stop(self):
110113
def parse_log():
111114
pass
112115

113-
class Logfile:
114-
def __init__(self, file: str):
115-
self.file = file
116-
117116
class CLISource(DataSource):
118117
def __init__(self):
119118
self.process = None
120119
self.args = None
120+
self._logfile = ValueRef(None)
121121

122122
super().__init__()
123123

124124
def __del__(self):
125125
if self.process:
126126
self.process.kill()
127127

128+
@property
129+
def logfile(self):
130+
return self._logfile.value
131+
132+
@logfile.setter
133+
def logfile(self, value):
134+
self._logfile.value = value
135+
128136
@property
129137
@abstractmethod
130138
def parameters(self) -> ParameterDict:
@@ -177,8 +185,8 @@ def _format_cmd(self):
177185
for p, v in self.args.items():
178186
if v == None:
179187
cmd += f" {p}"
180-
elif isinstance(v, Logfile):
181-
cmd += f" {p} {v.file}"
188+
elif isinstance(v, ValueRef):
189+
cmd += f" {p} {v.value}"
182190
elif isinstance(v, Iterable) and not (isinstance(v, StrEnum) or isinstance(v, str)):
183191
cmd += f" {p} {",".join(map(str, v))}"
184192
else:

experiment-runner/Plugins/Profilers/PowerJoular.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
22
from pathlib import Path
33
import pandas as pd
4-
from Plugins.Profilers.DataSource import CLISource, ParameterDict
4+
from Plugins.Profilers.DataSource import CLISource, ParameterDict, ValueRef
55

66
# Supported Paramters for the PowerJoular metrics plugin
77
POWERJOULAR_PARAMETERS = {
88
("-p",): int,
99
("-a",): str,
10-
("-f",): Path,
10+
("-f",): ValueRef,
1111
("-o",): Path,
1212
("-t",): None,
1313
("-l",): None,
@@ -31,7 +31,7 @@ def __init__(self,
3131
self.logfile = out_file
3232
self.args = {
3333
"-l": None,
34-
"-f": Path(self.logfile),
34+
"-f": self._logfile,
3535
}
3636

3737
if target_pid:

experiment-runner/Plugins/Profilers/PowerLetrics.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from enum import StrEnum
44
import weakref
5-
from Plugins.Profilers.DataSource import CLISource, ParameterDict, Logfile
5+
from Plugins.Profilers.DataSource import CLISource, ParameterDict, ValueRef
66

77
# How to format the output
88
class PLFormatTypes(StrEnum):
@@ -20,7 +20,7 @@ class PLOrderTypes(StrEnum):
2020
# ("-h", "--help"): None, # Dont support this
2121
("-i", "--sample-rate"): int,
2222
("-n", "--sample-count"): int,
23-
("-o", "--output-file"): Logfile,
23+
("-o", "--output-file"): ValueRef,
2424
("-r", "--order"): PLOrderTypes,
2525
("-A", "--show-all"): None,
2626
("--show-process-io"): None,
@@ -48,14 +48,16 @@ class PowerLetrics(CLISource):
4848

4949
def __init__(self,
5050
sample_frequency: int = 1000,
51-
out_file: Path = "pm_out.plist",
51+
out_file: Path = "pl_out.plist",
5252
additional_args: dict = {},
5353
order: PLOrderTypes = PLOrderTypes.PL_ORDER_CPU):
5454

5555
super().__init__()
56+
57+
print(self._logfile)
5658

5759
self.requires_admin = True
58-
self._logfile = Logfile(out_file)
60+
self.logfile = out_file
5961

6062
self.args = {
6163
"--output-file": self._logfile,
@@ -67,14 +69,6 @@ def __init__(self,
6769
}
6870

6971
self.update_parameters(add=additional_args)
70-
71-
@property
72-
def logfile(self):
73-
return self._logfile.file
74-
75-
@logfile.setter
76-
def logfile(self, value):
77-
self._logfile.file = value
7872

7973
@staticmethod
8074
def parse_log(logfile: Path):

experiment-runner/Plugins/Profilers/PowerMetrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
import plistlib
55

6-
from Plugins.Profilers.DataSource import ParameterDict, CLISource
6+
from Plugins.Profilers.DataSource import ParameterDict, CLISource, ValueRef
77

88
# How to format the output
99
class PMFormatTypes(StrEnum):
@@ -41,7 +41,7 @@ class PMSampleTypes(StrEnum):
4141
("--format", "-f"): PMFormatTypes,
4242
("--sample-rate", "-i"): int,
4343
("--sample-count", "-n"): int,
44-
("--output-file", "-o"): Path,
44+
("--output-file", "-o"): ValueRef,
4545
("--order", "-r"): PMOrderTypes,
4646
("--samplers", "-s"): list[PMSampleTypes],
4747
("--wakeup-cost", "-t"): int,
@@ -86,7 +86,7 @@ def __init__(self,
8686
self.logfile = out_file
8787
# Grab all available power stats by default
8888
self.args = {
89-
"--output-file": Path(self.logfile),
89+
"--output-file": self._logfile,
9090
"--sample-rate": sample_frequency,
9191
"--format": PMFormatTypes.PM_FMT_PLIST,
9292
"--samplers": [PMSampleTypes.PM_SAMPLE_CPU_POWER,

0 commit comments

Comments
 (0)