diff --git a/src/omniperf_analyze/utils/tty.py b/src/omniperf_analyze/utils/tty.py index 4cbee58e9..3e659a211 100644 --- a/src/omniperf_analyze/utils/tty.py +++ b/src/omniperf_analyze/utils/tty.py @@ -25,6 +25,7 @@ import pandas as pd from pathlib import Path from tabulate import tabulate +import numpy as np from omniperf_analyze.utils import schema, parser @@ -37,82 +38,119 @@ def smartUnits(df): for curr_metric in row: curr_row = df[df["Metric"] == curr_metric] if not curr_row.empty: + # fix values if "Value" in curr_row: - if isinstance( - curr_row["Value"][0], - float, - ): - if curr_row.Value[0] < 0.001: - df.loc[ - (df["Metric"] == curr_metric), - "Unit", - ] = "Kb/s" - df.loc[ - (df["Metric"] == curr_metric), - "Value", - ] = ( - 1000000 * curr_row.Value - ) - elif curr_row.Value[0] < 1: - df.loc[ - (df["Metric"] == curr_metric), - "Unit", - ] = "Mb/s" - df.loc[ - (df["Metric"] == curr_metric), - "Value", - ] = ( - 1000 * curr_row.Value - ) + vals = curr_row["Value"].values + new_units = [] + percent_diff = 0 + + # if baseline + if isinstance(vals[0], np.ndarray): + val_1 = curr_row["Value"].values[0][0] + baseline = curr_row["Value"].values[0][1].split() + val_2 = float(baseline[0]) + percent_diff = baseline[1] + vals = np.array([val_1, val_2]) + + # calculate units + for val in vals: + if isinstance( + val, + float, + ): + if val < 0.001: + new_units.append("Kb/s") + elif val < 1: + new_units.append("Mb/s") + if len(new_units) == 2: + if new_units[0] == "Kb/s": + new_units[0] = "Mb/s" + else: + new_units.append("Gb/s") + if len(new_units) == 2: + new_units[0] = "Gb/s" + # Convert to new_units + if new_units[0] == "Mb/s": + vals = 1000 * vals + elif new_units[0] == "Kb/s": + vals = 1000000 * vals + vals = vals.tolist() + # if baseline + if len(new_units) == 2: + vals[1] = str(vals[1]) + " " + str(percent_diff) + + df.loc[df["Metric"] == curr_metric, "Value"] = vals + df.loc[df["Metric"] == curr_metric, "Unit"] = new_units[0] + elif "Avg" in curr_row: - if isinstance(curr_row["Avg"][0], float): - if curr_row.Avg[0] < 0.001: - df.loc[ - (df["Metric"] == curr_metric), - "Unit", - ] = "Kb/s" - df.loc[ - (df["Metric"] == curr_metric), - "Avg", - ] = ( - 1000000 * curr_row.Avg - ) - df.loc[ - (df["Metric"] == curr_metric), - "Min", - ] = ( - 1000000 * curr_row.Min - ) - df.loc[ - (df["Metric"] == curr_metric), - "Max", - ] = ( - 1000000 * curr_row.Max - ) - elif curr_row.Avg[0] < 1: - df.loc[ - (df["Metric"] == curr_metric), - "Unit", - ] = "Mb/s" - df.loc[ - (df["Metric"] == curr_metric), - "Avg", - ] = ( - 1000 * curr_row.Avg - ) - df.loc[ - (df["Metric"] == curr_metric), - "Min", - ] = ( - 1000 * curr_row.Min - ) - df.loc[ - (df["Metric"] == curr_metric), - "Max", - ] = ( - 1000 * curr_row.Max - ) - return df + avg_vals = curr_row["Avg"].values + max_vals = curr_row["Max"].values + min_vals = curr_row["Min"].values + new_units = [] + percent_diff = 0 + + # if baseline + if isinstance(avg_vals[0], np.ndarray): + avg_baseline = curr_row["Avg"].values[0][1].split() + avg_percent_diff = avg_baseline[1] + avg_val_1 = curr_row["Avg"].values[0][0] + avg_val_2 = float(avg_baseline[0]) + avg_vals = np.array([avg_val_1, avg_val_2]) + + min_baseline = curr_row["Min"].values[0][1].split() + min_percent_diff = min_baseline[1] + min_val_1 = curr_row["Min"].values[0][0] + min_val_2 = float(min_baseline[0]) + min_vals = np.array([min_val_1, min_val_2]) + + max_baseline = curr_row["Max"].values[0][1].split() + max_percent_diff = max_baseline[1] + max_val_1 = curr_row["Max"].values[0][0] + max_val_2 = float(max_baseline[0]) + max_vals = np.array([max_val_1, max_val_2]) + + # calculate units + for val in avg_vals: + if isinstance( + val, + float, + ): + if val < 0.001: + new_units.append("Kb/s") + elif val < 1: + new_units.append("Mb/s") + if len(new_units) == 2: + if new_units[0] == "Kb/s": + new_units[0] = "Mb/s" + else: + new_units.append("Gb/s") + if len(new_units) == 2: + new_units[0] = "Gb/s" + + # Convert to new_units + if new_units[0] == "Mb/s": + avg_vals = 1000 * avg_vals + max_vals = 1000 * max_vals + min_vals = 1000 * min_vals + elif new_units[0] == "Kb/s": + avg_vals = 1000000 * avg_vals + max_vals = 1000000 * max_vals + min_vals = 1000000 * min_vals + avg_vals = avg_vals.tolist() + max_vals = max_vals.tolist() + min_vals = min_vals.tolist() + + # if baseline + if len(new_units) == 2: + avg_vals[1] = str(avg_vals[1]) + " " + str(avg_percent_diff) + max_vals[1] = str(max_vals[1]) + " " + str(max_percent_diff) + min_vals[1] = str(min_vals[1]) + " " + str(min_percent_diff) + + df.loc[df["Metric"] == curr_metric, "Avg"] = avg_vals + df.loc[df["Metric"] == curr_metric, "Max"] = max_vals + df.loc[df["Metric"] == curr_metric, "Min"] = min_vals + df.loc[df["Metric"] == curr_metric, "Unit"] = new_units[0] + return df def string_multiple_lines(source, width, max_rows): @@ -232,11 +270,10 @@ def show_all(args, runs, archConfigs, output): else x for x in base_df[header] ] - if "Unit" in cur_df: - cur_df = smartUnits(cur_df) df = pd.concat([df, cur_df[header]], axis=1) - if not df.empty: + if "Unit" in df: + df = smartUnits(df) # subtitle for each table in a panel if existing table_id_str = ( str(table_config["id"] // 100)