Skip to content
Snippets Groups Projects
Commit a2ed392c authored by Christoph Alt's avatar Christoph Alt
Browse files

addded a script for parsing the benchmarking results

parent 31a8eb74
No related merge requests found
import json
import argparse
def parse_benchmarks(lines):
perf = {}
bw = {}
current_dict = None
for line in lines:
if line.startswith("Performance Benchmarks:"):
current_dict = perf
elif line.startswith("Bandwidth Benchmarks:"):
current_dict = bw
else:
parts = line.split()
if len(parts) == 3:
key = parts[0]
value = float(parts[1])
current_dict[key] = value
return perf, bw
def transform_to_json(file_content):
lines = file_content.split('\n')
hostname = lines[0].split()[0]
date = ' '.join(lines[0].split()[1:6])
perf, bw = parse_benchmarks(lines[1:])
result = {
"hostname": hostname,
"date": date,
"perf": perf,
"bw": bw
}
return result
def get_data(output_file):
try:
with open(output_file, "r") as file:
data = json.load(file)
return data
except (FileNotFoundError, ):
return {}
def parse_input_files(input_files):
data = dict()
for input_file in input_files:
with open(input_file, 'r') as f:
file_content = f.read()
json_output = transform_to_json(file_content)
data.update({json_output["hostname"]: json_output})
return data
def main(input_files, output_file):
data = get_data(output_file)
data.update(parse_input_files(input_files))
with open(output_file, "w") as f:
json.dump(data, f, indent=4)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Transform benchmark files to JSON format.")
parser.add_argument("input_files", nargs="+", help="Input benchmark files")
parser.add_argument("-o", "--output_file", help="Output JSON file", required=True)
args = parser.parse_args()
main(args.input_files, args.output_file)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment