Loading tools/perf/format_benchmarks +28 −14 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import os import pathlib import statistics import zoneinfo import csv import pretty import utils Loading Loading @@ -103,7 +104,7 @@ class Table: def SetFixedCol(self, row_key, columns): self._fixed_cols[row_key] = columns def Write(self, out): def Write(self, out, fmt): table = [] # Expand the column items for row in zip(*self._cols): Loading @@ -114,18 +115,25 @@ class 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] if fmt == "table": table.append(pretty.SEPARATOR) # Populate the data for row in self._rows: table.append([str(row)] + self._fixed_cols[row] + [str(self._data.get((col, row), "")) for col in self._cols]) if fmt == "csv": csv.writer(sys.stdout, quoting=csv.QUOTE_MINIMAL).writerows(table) else: out.write(pretty.FormatTable(table, alignments="LL")) def format_duration_sec(ns): def format_duration_sec(ns, fmt_sec): "Format a duration in ns to second precision" sec = round(ns / 1000000000) if fmt_sec: return f"{sec}" else: h, sec = divmod(sec, 60*60) m, sec = divmod(sec, 60) result = "" Loading @@ -142,6 +150,12 @@ def main(argv): allow_abbrev=False, # Don't let people write unsupportable scripts. description="Print analysis tables for benchmarks") parser.add_argument("--csv", action="store_true", help="Print in CSV instead of table.") parser.add_argument("--sec", action="store_true", help="Print in seconds instead of minutes and seconds") parser.add_argument("--tags", nargs="*", help="The tags to print, in order.") Loading Loading @@ -196,9 +210,9 @@ def main(argv): summary["branch"], summary["tag"]] + list(key)), cell[0]["title"], format_duration_sec(duration_ns)) cell[0]["title"], format_duration_sec(duration_ns, args.sec)) table.Write(sys.stdout) table.Write(sys.stdout, "csv" if args.csv else "table") if __name__ == "__main__": main(sys.argv) Loading Loading
tools/perf/format_benchmarks +28 −14 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import os import pathlib import statistics import zoneinfo import csv import pretty import utils Loading Loading @@ -103,7 +104,7 @@ class Table: def SetFixedCol(self, row_key, columns): self._fixed_cols[row_key] = columns def Write(self, out): def Write(self, out, fmt): table = [] # Expand the column items for row in zip(*self._cols): Loading @@ -114,18 +115,25 @@ class 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] if fmt == "table": table.append(pretty.SEPARATOR) # Populate the data for row in self._rows: table.append([str(row)] + self._fixed_cols[row] + [str(self._data.get((col, row), "")) for col in self._cols]) if fmt == "csv": csv.writer(sys.stdout, quoting=csv.QUOTE_MINIMAL).writerows(table) else: out.write(pretty.FormatTable(table, alignments="LL")) def format_duration_sec(ns): def format_duration_sec(ns, fmt_sec): "Format a duration in ns to second precision" sec = round(ns / 1000000000) if fmt_sec: return f"{sec}" else: h, sec = divmod(sec, 60*60) m, sec = divmod(sec, 60) result = "" Loading @@ -142,6 +150,12 @@ def main(argv): allow_abbrev=False, # Don't let people write unsupportable scripts. description="Print analysis tables for benchmarks") parser.add_argument("--csv", action="store_true", help="Print in CSV instead of table.") parser.add_argument("--sec", action="store_true", help="Print in seconds instead of minutes and seconds") parser.add_argument("--tags", nargs="*", help="The tags to print, in order.") Loading Loading @@ -196,9 +210,9 @@ def main(argv): summary["branch"], summary["tag"]] + list(key)), cell[0]["title"], format_duration_sec(duration_ns)) cell[0]["title"], format_duration_sec(duration_ns, args.sec)) table.Write(sys.stdout) table.Write(sys.stdout, "csv" if args.csv else "table") if __name__ == "__main__": main(sys.argv) Loading