From a2ed392c8b0288880b8906d8c3812a8e48478f18 Mon Sep 17 00:00:00 2001
From: Christoph Alt <christoph.alt@fau.de>
Date: Wed, 6 Dec 2023 12:48:17 +0100
Subject: [PATCH] addded a script for parsing the benchmarking results

---
 roofline_data/parse_summaries.py | 76 ++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 roofline_data/parse_summaries.py

diff --git a/roofline_data/parse_summaries.py b/roofline_data/parse_summaries.py
new file mode 100644
index 0000000..d36f791
--- /dev/null
+++ b/roofline_data/parse_summaries.py
@@ -0,0 +1,76 @@
+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)
-- 
GitLab