Skip to content

Commit

Permalink
More docstrings and prints
Browse files Browse the repository at this point in the history
  • Loading branch information
JackKelly committed Oct 3, 2023
1 parent b2b92ce commit aaf745c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 5 additions & 3 deletions scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import shutil
import subprocess
import sys
import typer
from typing_extensions import Annotated
from typing import Optional

import typer
from perfcapture.workload import discover_workloads
from typing_extensions import Annotated

app = typer.Typer()

Expand Down Expand Up @@ -60,7 +60,7 @@ def bench(
" vmtouch. Or run with the --keep-cache option, which does not call vmtouch.")

workloads = discover_workloads(recipe_path)
print(f"Found {len(workloads)} Workload(s) in {recipe_path}")
print(f"Found {len(workloads)} Workload class(es) in {recipe_path}")

# Filter workloads (if necessary).
if selected_workloads:
Expand All @@ -69,9 +69,11 @@ def bench(

# Prepare datasets (if necessary).
all_datasets = set([workload.dataset for workload in workloads])
print(f"Found {len(all_datasets)} Dataset object(s).")
for dataset in all_datasets:
dataset.set_path(data_path)
if not dataset.already_exists():
print(f"Creating dataset for {dataset}")
dataset.prepare()

# Run the workloads!
Expand Down
15 changes: 13 additions & 2 deletions src/perfcapture/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ class Dataset(abc.ABC):
Datasets are read by `Workload`s.
"""
def set_path(self, base_data_path: pathlib.Path):
self.path = base_data_path / self.name
def set_path(self, base_data_path: pathlib.Path) -> None:
self._path = base_data_path / self.name

@property
def path(self) -> pathlib.Path:
try:
return self._path
except Exception as e:
e.add_note("Run `Dataset.set_path()` before attempting to access `Dataset.path`!")
raise

@property
def name(self) -> str:
"""The name of this dataset.
Must be unique amongst all the datasets used in the benchmark suite.
The default implementation will use the name of the class. Override
this method if you wish to set a custom name.
"""
return self.__class__.__name__

Expand Down
7 changes: 5 additions & 2 deletions src/perfcapture/workload.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import abc
import inspect
import pathlib
from perfcapture.dataset import Dataset

from perfcapture.dataset import Dataset
from perfcapture.utils import load_module_from_filename, path_not_empty


Expand All @@ -14,7 +14,10 @@ def __init__(self):

@abc.abstractmethod
def init_dataset(self) -> Dataset:
"""Initialises and returns a concrete Dataset objects."""
"""Initialises and returns a concrete Dataset objects.
Use this method to assign a Dataset object to this Workload.
"""

@abc.abstractmethod
def run(self) -> dict[str, object]:
Expand Down

0 comments on commit aaf745c

Please sign in to comment.