Skip to content

Commit

Permalink
linuxperf: Remove linuxperf_cpus param
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuba314 committed Sep 20, 2023
1 parent 7e1e3a6 commit a19207d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 53 deletions.
25 changes: 7 additions & 18 deletions lnst/RecipeCommon/Perf/Measurements/LinuxPerfMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
class LinuxPerfMeasurement(BaseMeasurement):
_MEASUREMENT_VERSION: int = 1

host_cpus: dict[Host, list[int]]
_start_timestamp: float
_end_timestamp: float
_data_folder: str
Expand All @@ -34,13 +33,13 @@ class LinuxPerfMeasurement(BaseMeasurement):

def __init__(
self,
host_cpus: dict[Host, list[int]],
hosts: list[Host],
data_folder: str,
recipe_conf: Any = None,
):
super().__init__(recipe_conf)

self.host_cpus = host_cpus
self.hosts = hosts
self._data_folder = data_folder

# create output folders
Expand All @@ -50,10 +49,6 @@ def __init__(
except FileExistsError:
pass

@property
def hosts(self) -> list[Host]:
return list(self.host_cpus.keys())

@property
def version(self) -> Optional[dict[str, Any]]:
if self._version:
Expand Down Expand Up @@ -84,12 +79,9 @@ def _get_host_perf_version(self) -> Optional[str]:

def start(self) -> None:
self._start_timestamp = time.time()
for host, cpus in self.host_cpus.items():
filename = "perf"
if cpus:
filename += f".cpus.{'.'.join(map(str, cpus))}"
filename += ".data"
self._running_jobs.append(host.run(LinuxPerf(output_file=filename, cpus=cpus), bg=True))
for host in self.hosts:
filename = "perf.data"
self._running_jobs.append(host.run(LinuxPerf(output_file=filename), bg=True))

def finish(self) -> None:
for job in self._running_jobs:
Expand All @@ -107,7 +99,7 @@ def finish(self) -> None:
def collect_results(self) -> list[BaseMeasurementResults]:
self._collection_index += 1
results: list[BaseMeasurementResults] = []
for job, (host, cpus) in zip(self._finished_jobs, self.host_cpus.items()):
for job, host in zip(self._finished_jobs, self.hosts):
if job.result is None:
continue

Expand All @@ -128,7 +120,6 @@ def collect_results(self) -> list[BaseMeasurementResults]:
self,
host,
dst_filepath,
cpus,
self._start_timestamp,
self._end_timestamp,
)
Expand All @@ -142,8 +133,6 @@ def report_results(
aggregated_results: list[AggregatedLinuxPerfMeasurementResults],
):
for aggregated_result in aggregated_results:
cpus = aggregated_result.individual_results[0].cpus
cpu_text = f"CPU(s) {','.join(map(str, cpus))}" if cpus else "all CPUs"
hostid: str = aggregated_result.individual_results[0].host.hostid
files: str = "\n ".join(
result.filename for result in aggregated_result.individual_results
Expand All @@ -152,7 +141,7 @@ def report_results(
recipe.add_custom_result(
MeasurementResult(
"linuxperf",
description=f"perf-record recorded {cpu_text} on {hostid} to files:\n {files}",
description=f"perf-record recorded all CPUs on {hostid} to files:\n {files}",
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class LinuxPerfMeasurementResults(BaseMeasurementResults):
_host: Host
_filename: str
_cpus: list[int]

_start_timestamp: float
_end_timestamp: float
Expand All @@ -15,14 +14,12 @@ def __init__(
measurement,
host: Host,
filename: str,
cpus: list[int],
start_timestamp: float,
end_timestamp: float,
):
super().__init__(measurement)
self._host = host
self._filename = filename
self._cpus = cpus
self._start_timestamp = start_timestamp
self._end_timestamp = end_timestamp

Expand All @@ -34,10 +31,6 @@ def host(self):
def filename(self):
return self._filename

@property
def cpus(self):
return self._cpus

@property
def start_timestamp(self):
return self._start_timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,32 @@
)
from lnst.RecipeCommon.Perf.Measurements.BaseMeasurement import BaseMeasurement
from lnst.RecipeCommon.Perf.Measurements import LinuxPerfMeasurement
from lnst.Common.Parameters import BoolParam, DictParam
from lnst.Common.Parameters import BoolParam


class LinuxPerfMeasurementGenerator(BaseMeasurementGenerator):
do_linuxperf_measurement = BoolParam(default=False)

# host -> cpu list mapping, empty/missing cpu list means every CPU is measured
linuxperf_cpus = DictParam(default={})

def generate_perf_measurements_combinations(self, config):
combinations = super().generate_perf_measurements_combinations(config)

if self.params.do_linuxperf_measurement:
# create linuxperf data folder
linuxperf_data_folder: str = os.path.abspath(
os.path.join(self.current_run.log_dir, "linuxperf-data")
)
try:
os.mkdir(linuxperf_data_folder)
except FileExistsError:
pass
if not self.params.do_linuxperf_measurement:
yield from combinations
return

host_cpus = {
host: self.params.linuxperf_cpus.get(host.hostid, []) for host in self.matched
}
for combination in combinations:
res: list[BaseMeasurement]
if self.params.do_linuxperf_measurement:
measurement: BaseMeasurement = LinuxPerfMeasurement(
host_cpus,
data_folder=linuxperf_data_folder,
recipe_conf=config,
)
res = [measurement] + combination
else:
res = combination
# create linuxperf data folder
linuxperf_data_folder: str = os.path.abspath(
os.path.join(self.current_run.log_dir, "linuxperf-data")
)
try:
os.mkdir(linuxperf_data_folder)
except FileExistsError:
pass

yield res
for combination in combinations:
measurement: BaseMeasurement = LinuxPerfMeasurement(
hosts=self.matched,
data_folder=linuxperf_data_folder,
recipe_conf=config,
)
yield [measurement] + combination

0 comments on commit a19207d

Please sign in to comment.