Commit ea733d20 authored by Jan Kiene's avatar Jan Kiene
Browse files

add support for reference bars in the WMOPS worst case per op plot

parent f1ab6709
Loading
Loading
Loading
Loading
Loading
+129 −36
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ the United Nations Convention on Contracts on the International Sales of Goods.
"""

import argparse
from typing import Optional


MAX_VALUES = 40
@@ -138,6 +139,9 @@ DISPLAY_LABELS = {
}
DISPLAY_ELEM_TEMPLATE = '{{ lines: {{ show: true }}, points: {{ show: true, fillColor: "#ffffff" }}, borderWidth: 1.5, borderColor: "#BEBEBE", markingsLineWidth: .75, hoverable: true, clickable: false, shadowSize: 0, color: "{color}", id: "{id}", data: [ {data} ] }}'

REF_COLOR_FOR_COMP_BARS = dict(
    zip(DISPLAY_LABELS["wmops_per_op"], [REF_COLORS[0], REF_COLORS[2]])
)
LINE_COLORS = {
    "wmops": [
        REF_COLORS[0],
@@ -235,7 +239,9 @@ FILE_DATA = {
}


def main(wmops_log, wmops_per_op_log, rom_log, ram_log):
def main(
    wmops_log, wmops_per_op_log, rom_log, ram_log, wmops_per_op_log_for_comparison
):
    FILE_DATA["wmops"]["log_file"] = wmops_log
    FILE_DATA["wmops_per_op"]["log_file"] = wmops_per_op_log
    FILE_DATA["rom"]["log_file"] = rom_log
@@ -249,6 +255,73 @@ def main(wmops_log, wmops_per_op_log, rom_log, ram_log):
        ticks = []
        if x == "wmops_per_op":
            split_char = ";"
            log_lines, ticks = pre_proc_log_lines(
                log_lines, wmops_per_op_log_for_comparison
            )

        else:
            log_lines = log_lines[-MAX_VALUES:]

        runs = [
            create_runs_string(line.strip().split(split_char), x) for line in log_lines
        ]
        displays = create_display_strings(
            log_lines,
            data["references"],
            split_char,
            x,
            has_comparison=x == "wmops_per_op"
            and wmops_per_op_log_for_comparison is not None,
        )

        runs = ",\n".join(runs)
        displays = ",\n".join(displays)
        ticks = ",\n".join(ticks)

        js_string = JS_FILE_TEMPLATE.format(
            var_name=data["var_name"],
            elem_name=data["elem_name"],
            description=data["description"],
            runs=runs,
            displays=displays,
            ticks=ticks,
        )
        with open(data["filename"], "w") as f:
            print(js_string, file=f)


def pre_proc_log_lines(
    log_lines: list[str], wmops_per_op_log_for_comparison: Optional[str]
):
    if wmops_per_op_log_for_comparison is not None:
        with open(wmops_per_op_log_for_comparison) as f:
            log_lines_comp = f.readlines()

        log_lines_combined = []
        MISSING_LINE = "{};0;0;0"
        for line in log_lines:
            line_split = line.split(";")
            conf = line_split[0]

            # add - BASOP suffix to existing line
            new_line_split = line_split
            new_line_split[0] = conf + " - BASOP"
            new_line_basop = ";".join(new_line_split)
            log_lines_combined.append(new_line_basop)

            # search for same operating point in given comparison log
            ref_conf = conf + " - FLT REF"
            new_line_ref = MISSING_LINE.format(ref_conf)
            for line_comp in log_lines_comp:
                line_comp_split = line_comp.split(";")
                conf_comp = line_comp_split[0]
                if conf == conf_comp:
                    new_line_ref = ";".join([ref_conf] + line_comp_split[1:])
                    break
            log_lines_combined.append(new_line_ref)

        log_lines = log_lines_combined

    # some preprocessing is needed so that the later functions work as are
    # 1. need to make sure that modes are ordered by bandwidth
    # 2. need to add the bandwidth indicator as a column
@@ -273,34 +346,14 @@ def main(wmops_log, wmops_per_op_log, rom_log, ram_log):
        + in_between_offset_size
        + len(fb_lines) / 2
    )

    ticks = [
        f"['{wb_label_pos}', 'WB']",
        f"['{swb_label_pos}', 'SWB']",
        f"['{fb_label_pos}', 'FB']",
    ]

        else:
            log_lines = log_lines[-MAX_VALUES:]

        runs = [
            create_runs_string(line.strip().split(split_char), x) for line in log_lines
        ]
        displays = create_display_strings(log_lines, data["references"], split_char, x)

        runs = ",\n".join(runs)
        displays = ",\n".join(displays)
        ticks = ",\n".join(ticks)

        js_string = JS_FILE_TEMPLATE.format(
            var_name=data["var_name"],
            elem_name=data["elem_name"],
            description=data["description"],
            runs=runs,
            displays=displays,
            ticks=ticks,
        )
        with open(data["filename"], "w") as f:
            print(js_string, file=f)
    return log_lines, ticks


def create_runs_string(line: list[str], which: str) -> str:
@@ -312,7 +365,9 @@ def create_runs_string(line: list[str], which: str) -> str:
    return run


def create_display_strings(log_lines, references, split_char, which):
def create_display_strings(
    log_lines, references, split_char, which, has_comparison=False
):
    display_ids = DISPLAY_IDS[which]
    display_line_idx = DISPLAY_LINE_IDX[which]
    line_colors = LINE_COLORS[which]
@@ -329,10 +384,41 @@ def create_display_strings(log_lines, references, split_char, which):
                value = references[id]
            data.append(f"[{i}, {value}]")

        display = DISPLAY_ELEM_TEMPLATE.format(color=color, id=id, data=", ".join(data))
        if which == "wmops_per_op" and has_comparison:
            # de-interleave data
            data_basop = data[::2]
            data_flt_ref = data[1::2]

            display_basop = DISPLAY_ELEM_TEMPLATE.format(
                color=color, id=id + " - BASOP", data=", ".join(data_basop)
            )
            idx_data = display_basop.index("data:")
            label_string = f"label: '{label} - BASOP', "
            display_basop = (
                display_basop[:idx_data] + label_string + display_basop[idx_data:]
            )

            ref_color = REF_COLOR_FOR_COMP_BARS[label]

            display_flt_ref = DISPLAY_ELEM_TEMPLATE.format(
                color=ref_color, id=id + " - FLT REF", data=", ".join(data_flt_ref)
            )
            idx_data = display_flt_ref.index("data:")
            label_string = f"label: '{label} - FLT REF', "
            display_flt_ref = (
                display_flt_ref[:idx_data] + label_string + display_flt_ref[idx_data:]
            )

            display = display_basop + ", \n" + display_flt_ref
        else:
            display = DISPLAY_ELEM_TEMPLATE.format(
                color=color, id=id, data=", ".join(data)
            )

        if which == "wmops_per_op":
            display = display.replace("show: true", "show: false")

            if not has_comparison:
                idx_data = display.index("data:")
                label_string = f"label: '{label}', "
                display = display[:idx_data] + label_string + display[idx_data:]
@@ -350,7 +436,14 @@ if __name__ == "__main__":
    parser.add_argument("wmops_per_op_log")
    parser.add_argument("rom_log")
    parser.add_argument("ram_log")
    parser.add_argument("--wmops_per_op_log_for_comparison", default=None)

    args = parser.parse_args()

    main(args.wmops_log, args.wmops_per_op_log, args.rom_log, args.ram_log)
    main(
        args.wmops_log,
        args.wmops_per_op_log,
        args.rom_log,
        args.ram_log,
        args.wmops_per_op_log_for_comparison,
    )