From afc6c5f3cf2c8317f138e19cd035e16e45370764 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 6 Sep 2023 15:27:26 +0200 Subject: [PATCH] implementing results csv and local to local --- benchmark.py | 36 +++++++++++++++++++++++++ results_tools.py | 23 ++++++++++++++++ run.py | 69 ++++++++++++++++++++++++------------------------ 3 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 benchmark.py create mode 100644 results_tools.py diff --git a/benchmark.py b/benchmark.py new file mode 100644 index 0000000..9581e7b --- /dev/null +++ b/benchmark.py @@ -0,0 +1,36 @@ +# copyright: Canonical +"Run the bench cases (remote to local)." +import datetime +import subprocess +from pathlib import Path + +from loguru import logger as log + + +def run_single_bench( + runnum, + test_case, + files_type, + source, + target, + results, +): + log.info(f"Syncing {runnum} {test_case} {files_type}") + start = datetime.datetime.now() + subprocess.run( + [ + "rsync", + "-a", + f"{source}", + f"{target}", + ], + capture_output=True, + # shell=True, + ) + time = datetime.datetime.now() - start + size = sum(f.stat().st_size for f in Path(target).glob("**/*") if f.is_file()) + size_MB = size / 1000 / 1000 / 8 + speed = size_MB / time.total_seconds() + log.info(f"{files_type} - {speed} MB/s") + subprocess.run(["rm", "-rf", target]) + results.add([runnum, test_case, files_type, speed, time.total_seconds(), size_MB]) diff --git a/results_tools.py b/results_tools.py new file mode 100644 index 0000000..f855308 --- /dev/null +++ b/results_tools.py @@ -0,0 +1,23 @@ +# copyright: Canonical +"Tools for managing results." +import csv +from uuid import uuid4 + + +class Results: + def __init__(self, *args, **kwargs): + self.result_list = [["Run num", "test_case", "files", "MB/s", "time", "full size"]] + + def add(self, row: list) -> None: + """Add a row to the results lists. + + Args: + row (list): a row of results. + """ + self.result_list.append(row) + + def save_to_csv(self) -> None: + """Save results to csv file in the current directory.""" + with open(f"results{uuid4()}.csv", "w") as f: + cw = csv.writer(f) + cw.writerows(self.result_list) diff --git a/run.py b/run.py index 8176ff7..6e4e038 100644 --- a/run.py +++ b/run.py @@ -1,46 +1,41 @@ -"Run the bench cases." # copyright: Canonical -import datetime +"Run the bench cases (remote to local)." import json -import subprocess -from pathlib import Path -from loguru import logger as log +import click +from benchmark import run_single_bench from definitions import BENCH_DIR_NAMES, CEPH_ROOT, INST_STO_ROOT, REMOTE_INST_STO_ROOT, SERV_URL +from results_tools import Results -RESULTS = [["Run num", "test_case", "files", "MB/s", "time", "full size"]] +results = Results() -def run_single_bench( - runnum, - test_case, - files_type, - source, - target, -): - log.info(f"Syncing {runnum} {test_case} {files_type}") - start = datetime.datetime.now() - subprocess.run( - [ - "rsync", - "-a", - f"{source}", - f"{target}", - ], - capture_output=True, - # shell=True, - ) - time = datetime.datetime.now() - start - size = sum(f.stat().st_size for f in Path(target).glob("**/*") if f.is_file()) - size_MB = size / 1000 / 1000 / 8 - speed = size_MB / time.total_seconds() - log.info(f"{files_type} - {speed} MB/s") - subprocess.run(["rm", "-rf", target]) - RESULTS.append([runnum, test_case, files_type, speed, time.total_seconds(), size_MB]) +@click.group() +def cli(): + pass -if __name__ == "__main__": +@cli.command() +def local(): + click.echo("Running locally") + for runnum in range(50): + for files_type in BENCH_DIR_NAMES: + test_case = "Distant-InsSto to InsSto" + source = f"{INST_STO_ROOT}/{files_type}" + target = CEPH_ROOT + files_type + run_single_bench( + runnum, + test_case, + files_type, + source, + target, + ) + + +@cli.command() +def distant(): + click.echo("Running distant to local") for runnum in range(50): for files_type in BENCH_DIR_NAMES: test_case = "Distant-InsSto to InsSto" @@ -63,6 +58,12 @@ if __name__ == "__main__": files_type, source, target, + results, ) - json.dump(RESULTS, open("results.json", "w")) + +if __name__ == "__main__": + cli() + + json.dump(results.result_list, open("results.json", "w")) + results.save_to_csv()