Skip to content

Commit

Permalink
tc: Generate batchfiles before running measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuba314 committed Aug 14, 2023
1 parent 93585a0 commit e5996f2
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lnst/RecipeCommon/Perf/Measurements/TcRunMeasurement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from os import PathLike
from tempfile import NamedTemporaryFile
from typing import Optional

Expand All @@ -19,21 +18,21 @@
class TcRunInstance:
MAX_ID = 0xFFFF

def __init__(self, device: Device, num_rules: int, instance_id:int):
def __init__(self, device: Device, num_rules: int, instance_id: int, batchfile_path: Optional[str] = None):
self._device = device
self._num_rules = num_rules
self._instance_id = instance_id
self._batchfile_path: PathLike = None

if batchfile_path is None:
batchfile_path = self._generate_batchfile()
self._batchfile_path = batchfile_path

self.validate()

@property
def batchfile_path(self):
return self._batchfile_path

@batchfile_path.setter
def batchfile_path(self, p: PathLike):
self._batchfile_path = p

def validate(self):
if self._instance_id > self.MAX_ID:
raise ValueError(f"Maximum number of instances supported is {self.MAX_ID}")
Expand Down Expand Up @@ -68,7 +67,7 @@ def start_mac(self) -> str:
def end_mac(self) -> str:
return f"{self.pool_oui}:ff:ff:ff"

def generate_batchfile(self) -> str:
def _generate_batchfile(self) -> str:
logging.info(f"Generating tc batchfile for {self.device.name} instance {self._instance_id} num_rules={self.num_rules}")
rules = self.generate_rules()
with NamedTemporaryFile(
Expand All @@ -78,7 +77,6 @@ def generate_batchfile(self) -> str:
f.write(r)

remote_path = self.host.copy_file_to_machine(f.name)
self.batchfile_path = remote_path
logging.info(f"tc batchfile written to {self.host.hostname}:{remote_path}")
return remote_path

Expand Down Expand Up @@ -154,9 +152,8 @@ def start(self):
self._running_jobs.append(job)

def _prepare_jobs(self) -> list[Job]:
batchfiles = [i.generate_batchfile() for i in self.instance_configs]
params: dict = {
"batchfiles": batchfiles,
"batchfiles": [i.batchfile_path for i in self.instance_configs],
}
if self._cpu_bind is not None:
params["cpu_bind"] = self._cpu_bind
Expand Down

0 comments on commit e5996f2

Please sign in to comment.