Skip to content

Commit

Permalink
Remove unused Cache classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Feb 19, 2024
1 parent 9cb2a26 commit 5a5b9f3
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions tools/performance/engine-benchmarks/bench_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,75 +165,6 @@ def _read_json(json_file: str) -> Dict[Any, Any]:
return json.load(f)


class Cache:
"""
Cache is a directory filled with json files that have name of format <bench_run_id>.json, and
in every json, there is `BenchReport` dataclass serialized.
"""

def __init__(self, dirname: str):
assert path.exists(dirname) and path.isdir(dirname)
self._dir = dirname
# Keys are BenchRun ids
self._items: Dict[str, JobReport] = {}
for fname in os.listdir(dirname):
fname_without_ext, ext = path.splitext(fname)
if _is_benchrun_id(fname_without_ext) and ext == ".json":
logging.debug(f"Loading into cache from {fname}")
bench_report = _parse_bench_report_from_json(
_read_json(path.join(dirname, fname))
)
self._items[fname_without_ext] = bench_report

def __len__(self) -> int:
return len(self._items)

def __contains__(self, key: str) -> bool:
assert _is_benchrun_id(key)
return key in self._items

def __getitem__(self, item: str) -> Optional[JobReport]:
if not _is_benchrun_id(item):
return None
else:
return self._items[item]

def __setitem__(self, bench_run_id: str, bench_report: JobReport) -> None:
assert isinstance(bench_report, JobReport)
assert isinstance(bench_run_id, str)
assert _is_benchrun_id(bench_run_id)
self._items[bench_run_id] = bench_report
json_fname = path.join(self._dir, bench_run_id + ".json")
logging.debug(f"Putting {bench_run_id} into cache {json_fname}")
with open(json_fname, "w") as json_file:
json.dump(
_bench_report_to_json(bench_report),
json_file,
indent=2,
ensure_ascii=False
)

def __str__(self) -> str:
return str(self._items)

def contains(self, bench_run_id: str) -> bool:
return bench_run_id in self._items


class FakeCache:
def __getitem__(self, item):
return None

def __setitem__(self, key, value):
pass

def __contains__(self, item):
return False

def __len__(self):
return 0


async def get_bench_runs(since: datetime, until: datetime, branch: str, workflow_id: int) -> List[JobRun]:
"""
Fetches the list of all the job runs from the GH API for the specified `branch`.
Expand Down

0 comments on commit 5a5b9f3

Please sign in to comment.