generate_excel.py 3.85 KB
Newer Older
1
2
import json
from itertools import product
3
4
5
from pathlib import Path

import pandas as pd
6
7
8
9


def get_branch_name_from_hash(hash):
    import subprocess
10
11
12
13
14
15

    process = subprocess.Popen(
        ["git", "name-rev", "--name-only", hash],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
16
17
18
19
    stdout, stderr = process.communicate()
    if len(stderr) > 0:
        return hash[:10]
    else:
20
        return stdout.decode("utf-8").strip("\n")
21
22
23
24
25
26
27
28
29
30


def main():
    results_path = Path("../results")
    results_path.is_dir()
    machines = [f for f in results_path.glob("*") if f.is_dir()]
    output_results_dict = {}
    for machine in machines:
        per_machine_result = {}
        commit_results_json_paths = [
31
32
            f for f in machine.glob("*") if f.name != "machine.json"
        ]
33
34
35
        for commit in commit_results_json_paths:
            with commit.open() as f:
                commit_result = json.load(f)
36
            commit_hash = commit_result["commit_hash"]
37
            per_commit_result = {}
38
            for test_name, result in commit_result["results"].items():
39
                per_commit_result[test_name] = []
40
41
                if result["result"] is None:
                    for test_args in product(*result["params"]):
42
                        per_commit_result[test_name].append(
43
44
                            {"params": ", ".join(test_args), "result": None}
                        )
45
                else:
46
47
48
                    for test_args, performance_number in zip(
                        product(*result["params"]), result["result"]
                    ):
49
                        per_commit_result[test_name].append(
50
51
52
53
54
                            {
                                "params": ", ".join(test_args),
                                "result": performance_number,
                            }
                        )
55
56
57
58
59
60
61
62
63
64
            per_machine_result[commit_hash] = per_commit_result
        output_results_dict[machine.name] = per_machine_result
    return output_results_dict


def dict_to_csv(output_results_dict):
    with open("../results/benchmarks.json") as f:
        benchmark_conf = json.load(f)
    unit_dict = {}
    for k, v in benchmark_conf.items():
65
66
        if k != "version":
            unit_dict[k] = v["unit"]
67
68
69
70
71
72
73
74
75
    result_list = []
    for machine, per_machine_result in output_results_dict.items():
        for commit, test_cases in per_machine_result.items():
            branch_name = get_branch_name_from_hash(commit)
            result_column_name = "number_{}".format(branch_name)
            # per_commit_result_list = []
            for test_case_name, results in test_cases.items():
                for result in results:
                    result_list.append(
76
77
78
79
80
81
82
83
84
                        {
                            "test_name": test_case_name,
                            "params": result["params"],
                            "unit": unit_dict[test_case_name],
                            "number": result["result"],
                            "commit": branch_name,
                            "machine": machine,
                        }
                    )
85
86
87
88
89
    df = pd.DataFrame(result_list)
    return df


def side_by_side_view(df):
90
91
    commits = df["commit"].unique().tolist()
    full_df = df.loc[df["commit"] == commits[0]]
92
    for commit in commits[1:]:
93
        per_commit_df = df.loc[df["commit"] == commit]
94
        full_df: pd.DataFrame = full_df.merge(
95
96
97
98
99
100
101
102
103
            per_commit_df,
            on=["test_name", "params", "machine", "unit"],
            how="outer",
            suffixes=(
                "_{}".format(full_df.iloc[0]["commit"]),
                "_{}".format(per_commit_df.iloc[0]["commit"]),
            ),
        )
    full_df = full_df.loc[:, ~full_df.columns.str.startswith("commit")]
104
105
106
107
108
109
    return full_df


output_results_dict = main()
df = dict_to_csv(output_results_dict)
sbs_df = side_by_side_view(df)
110
sbs_df.to_csv("result.csv")