-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making a start on separating the dataset from the benchmark workload
- Loading branch information
Showing
4 changed files
with
84 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import abc | ||
import pathlib | ||
|
||
from perfcapture.utils import path_not_empty | ||
|
||
|
||
class Dataset(abc.ABC): | ||
"""Inherit from `Dataset` to implement a new benchmark dataset. | ||
Datasets are read by `Workload`s. | ||
""" | ||
def __init__(self, base_data_path: pathlib.Path): | ||
self.path_to_dataset = base_data_path / self.name | ||
|
||
@property | ||
@abc.abstractmethod | ||
def name(self) -> str: | ||
"""The name of this dataset. Must be unique amongst all the datasets used in the benchmark suite.""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def prepare(self) -> None: | ||
"""Override this method if your workload needs to prepare a local dataset. | ||
Store your dataset at `self.path_to_dataset`. | ||
Every time the workload runner executes, it runs this pseudocode: | ||
if not dataset.already_exists(): | ||
dataset.prepare() | ||
""" | ||
pass | ||
|
||
def already_exists(self) -> bool: | ||
"""Returns True if the dataset is already on disk.""" | ||
path_is_dir_which_is_not_empty = ( | ||
self.path_to_dataset.exists() and | ||
self.path_to_dataset.is_dir() and | ||
path_not_empty(self.path_to_dataset) | ||
) | ||
path_is_single_file = ( | ||
self.path_to_dataset.exists() and | ||
not self.path_to_dataset.is_dir() | ||
) | ||
return path_is_dir_which_is_not_empty or path_is_single_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,16 @@ | ||
import abc | ||
import pathlib | ||
from perfcapture.dataset import Dataset | ||
|
||
from perfcapture.utils import path_not_empty | ||
|
||
|
||
""" | ||
TODO: Workload and Dataset should be separate classes. | ||
This is so single Dataset can be used by multiple Workloads. | ||
""" | ||
|
||
class Workload(abc.ABC): | ||
"""To implement a new benchmark workload, inherit from `Workload`. | ||
Most folks will want to override just two methods: | ||
- prepare_dataset | ||
- run_workload | ||
""" | ||
|
||
def __init__(self, path_to_dataset: pathlib.Path): | ||
self.path_to_dataset = path_to_dataset | ||
"""Inherit from `Workload` to implement a new benchmark workload.""" | ||
|
||
def prepare_dataset(self) -> None: | ||
"""Override this method if your workload needs to prepare a local dataset. | ||
Every time the workload runner executes, it runs this pseudocode | ||
before calling `run_workload`: | ||
def __init__(self, dataset: Dataset): | ||
self.dataset = dataset | ||
|
||
if not workload.dataset_already_exists(): | ||
workload.prepare_dataset() | ||
Store your dataset at `self.path_to_dataset`. | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def run_workload(self) -> dict[str, object]: | ||
"""Must be overridden. This method implements the workload. | ||
""" | ||
|
||
def dataset_already_exists(self) -> bool: | ||
"""Returns True if the dataset is already on disk. | ||
""" | ||
path_is_dir_which_is_not_empty = ( | ||
self.path_to_dataset.exists() and | ||
self.path_to_dataset.is_dir() and | ||
path_not_empty(self.path_to_dataset) | ||
) | ||
path_is_single_file = ( | ||
self.path_to_dataset.exists() and | ||
not self.path_to_dataset.is_dir() | ||
) | ||
return path_is_dir_which_is_not_empty or path_is_single_file | ||
def run(self) -> dict[str, object]: | ||
"""Must be overridden to implement the workload.""" |