Skip to content

Commit

Permalink
misc: supprot benchmark on schedule
Browse files Browse the repository at this point in the history
supprot the benchmark on schedule by new mode in benchmark_summary.

Signed-off-by: Yadong Ding <[email protected]>
  • Loading branch information
Desiki-high authored and imeoer committed May 5, 2023
1 parent 5bfb155 commit 7a48992
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions misc/benchmark/benchmark_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import csv
import subprocess
import os
from argparse import ArgumentParser

COMMANDS_BENCHMARK = [
Expand Down Expand Up @@ -39,6 +40,9 @@
("nydus-filelist-prefetch-master.csv", "nydus-filelist-prefetch.csv")
]

BENCHMARK_CACHE = "benchmark-result/result.md"


class BenchmarkSummary:
def __init__(self, mode):
self.mode = mode
Expand All @@ -47,8 +51,10 @@ def summary(self):
self.prepare_csv()
if self.mode == "benchmark-result":
self.print_csv_result()
else:
elif self.mode == "benchmark-compare":
self.print_csv_compare()
else:
self.print_csv_schedule()

def print_csv_result(self):
print("| bench-result | pull(s) | create(s) | run(s) | total(s) | size(MB) | read-amount(MB) | read-count |")
Expand All @@ -65,6 +71,25 @@ def print_csv_compare(self):
else:
print_compare(item[0], item[1])

def print_csv_schedule(self):
print("| bench-result(current vs last) | pull(s) | create(s) | run(s) | total(s) | size(MB) | read-amount(MB) | read-count |")
print("|:------------------------------|:-------:|:---------:|:------:|:--------:|:--------:|:---------------:|:----------:|")
data = []
if os.path.exists(BENCHMARK_CACHE):
with open(BENCHMARK_CACHE, "r", newline='') as f:
reader = csv.reader(f, delimiter='|')
next(reader) # head
next(reader) # line
next(reader) # oci
for row in reader:
data.append(row[2:-1])
for index, file in enumerate(FILE_LIST):
if(file == "oci.csv") or index > len(data):
print_schedule(file)
else:
print_schedule(file, data[index-1])
self.save_cache()

def prepare_csv(self):
"""
move the csv to current workdir
Expand All @@ -75,6 +100,18 @@ def prepare_csv(self):
for cmd in COMMANDS_BENCHMARK_COMPARE:
subprocess.run(cmd, shell=True)

def save_cache(self):
with open(BENCHMARK_CACHE, 'w') as cache:
print("| bench-result | pull(s) | create(s) | run(s) | total(s) | size(MB) | read-amount(MB) | read-count |", file=cache)
print("|:-------------|:-------:|:---------:|:------:|:--------:|:--------:|:---------------:|:----------:|", file=cache)
for file in FILE_LIST:
with open(file, 'r') as f:
filename = file.rstrip(".csv")
rows = csv.reader(f)
for row in rows:
pull_elapsed, create_elapsed, run_elapsed, total_elapsed, image_size, read_amount, read_count = row
print(f"|{filename}|{pull_elapsed}|{create_elapsed}|{run_elapsed}|{total_elapsed}|{image_size}|{read_amount}|{read_count}|", file=cache)


def print_csv(file: str):
with open(file, 'r', newline='') as f:
Expand All @@ -95,31 +132,51 @@ def print_compare(file_master: str, file: str):
rows = csv.reader(f)
for row in rows:
pull_elapsed_master, create_elapsed_master, run_elapsed_master, total_elapsed_master, image_size_master, read_amount_master, read_count_master = row
pull_elapsed_compare = compare(pull_elapsed,pull_elapsed_master)
pull_elapsed_compare = compare(pull_elapsed, pull_elapsed_master)
create_elapsed_compare = compare(create_elapsed, create_elapsed_master)
run_elapsed_compare = compare(run_elapsed, run_elapsed_master)
total_elapsed_compare = compare(total_elapsed, total_elapsed_master,True)
total_elapsed_compare = compare(total_elapsed, total_elapsed_master, True)
image_size_compare = compare(image_size, image_size_master, True)
read_amount_compare = compare(read_amount, read_amount_master, True)
read_count_compare = compare(read_count, read_count_master, True)

print(f"|{filename}|{pull_elapsed_compare}|{create_elapsed_compare}|{run_elapsed_compare}|{total_elapsed_compare}|{image_size_compare}|{read_amount_compare}|{read_count_compare}|")


def print_schedule(file: str, data=[]):
with open(file, 'r', newline='') as f:
filename = file.rstrip(".csv")
rows = csv.reader(f)
for row in rows:
pull_elapsed, create_elapsed, run_elapsed, total_elapsed, image_size, read_amount, read_count = row
if filename != "oci":
pull_elapsed = compare(pull_elapsed, data[0])
create_elapsed = compare(create_elapsed, data[1])
run_elapsed = compare(run_elapsed, data[2])
total_elapsed = compare(total_elapsed, data[3], True)
image_size = compare(image_size, data[4], True)
read_amount = compare(read_amount, data[5], True)
read_count = compare(read_count, data[6], True)

print(f"|{filename}|{pull_elapsed}|{create_elapsed}|{run_elapsed}|{total_elapsed}|{image_size}|{read_amount}|{read_count}|")


def compare(data_current: str, data_master: str, compare: bool = False) -> str:
data_current = float(data_current)
data_master = float(data_master)
if abs(data_current - data_master) > data_master * 0.05 and compare:
if data_current > data_master:
return f"{data_current}/{data_master}↑"
else:
else:
return f"{data_current}/{data_master}↓"
return f"{data_current}/{data_master}"


def main():
parser = ArgumentParser()
parser.add_argument(
"--mode",
choices=["benchmark-result", "benchmark-compare"],
choices=["benchmark-result", "benchmark-compare", "benchmark-schedule"],
dest="mode",
type=str,
required=True,
Expand Down

0 comments on commit 7a48992

Please sign in to comment.