From 6b40826d2ea67b817511a32dc371ef842975654d Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 19 Jan 2024 16:35:02 +0000 Subject: [PATCH] Add the rebuilt modules to the benchmark formatting Test: format_benchmarks Change-Id: Ib3fffc99a1c66a2f700c27821886e8de2e2ec041 --- tools/perf/format_benchmarks | 21 ++++++++++++++++----- tools/perf/pretty.py | 6 +++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/perf/format_benchmarks b/tools/perf/format_benchmarks index 845d73fe62..162c5770a9 100755 --- a/tools/perf/format_benchmarks +++ b/tools/perf/format_benchmarks @@ -86,10 +86,12 @@ def group_by(l, key): class Table: - def __init__(self): + def __init__(self, row_title, fixed_titles=[]): self._data = {} self._rows = [] self._cols = [] + self._fixed_cols = {} + self._titles = [row_title] + fixed_titles def Set(self, column_key, row_key, data): self._data[(column_key, row_key)] = data @@ -98,19 +100,27 @@ class Table: if not row_key in self._rows: self._rows.append(row_key) + def SetFixedCol(self, row_key, columns): + self._fixed_cols[row_key] = columns + def Write(self, out): table = [] # Expand the column items for row in zip(*self._cols): if row.count(row[0]) == len(row): continue - table.append([""] + [col for col in row]) + table.append([""] * len(self._titles) + [col for col in row]) if table: + # Update the last row of the header with title and add separator + for i in range(len(self._titles)): + table[len(table)-1][i] = self._titles[i] table.append(pretty.SEPARATOR) # Populate the data for row in self._rows: - table.append([str(row)] + [str(self._data.get((col, row), "")) for col in self._cols]) - out.write(pretty.FormatTable(table)) + table.append([str(row)] + + self._fixed_cols[row] + + [str(self._data.get((col, row), "")) for col in self._cols]) + out.write(pretty.FormatTable(table, alignments="LL")) def format_duration_sec(ns): @@ -173,11 +183,12 @@ def main(argv): in group_by(summary["benchmarks"], bm_key)] # Build the table - table = Table() + table = Table("Benchmark", ["Rebuild"]) for filename, summary in summaries: for key, column in summary["columns"]: for id, cell in column: duration_ns = statistics.median([b["duration_ns"] for b in cell]) + table.SetFixedCol(cell[0]["title"], [" ".join(cell[0]["modules"])]) table.Set(tuple([summary["date"].strftime("%Y-%m-%d"), summary["branch"], summary["tag"]] diff --git a/tools/perf/pretty.py b/tools/perf/pretty.py index 1b590983ba..14fdc9ed8d 100644 --- a/tools/perf/pretty.py +++ b/tools/perf/pretty.py @@ -19,7 +19,7 @@ class Sentinel(): SEPARATOR = Sentinel() -def FormatTable(data, prefix=""): +def FormatTable(data, prefix="", alignments=[]): """Pretty print a table. Prefixes each row with `prefix`. @@ -40,10 +40,10 @@ def FormatTable(data, prefix=""): else: for i in range(len(row)): cell = row[i] if row[i] else "" - if i != 0: + if i >= len(alignments) or alignments[i] == "R": result += " " * (widths[i] - len(cell)) result += cell - if i == 0: + if i < len(alignments) and alignments[i] == "L": result += " " * (widths[i] - len(cell)) result += colsep result += "\n"