Merge "add csv output to format_benchmarks" into main am: 802de330d3
Original change: https://android-review.googlesource.com/c/platform/build/+/3094187 Change-Id: Iecabc5b4e7f954610c930ff154c5a9e9a28d0402 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import os
|
|||||||
import pathlib
|
import pathlib
|
||||||
import statistics
|
import statistics
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
import csv
|
||||||
|
|
||||||
import pretty
|
import pretty
|
||||||
import utils
|
import utils
|
||||||
@@ -103,7 +104,7 @@ class Table:
|
|||||||
def SetFixedCol(self, row_key, columns):
|
def SetFixedCol(self, row_key, columns):
|
||||||
self._fixed_cols[row_key] = columns
|
self._fixed_cols[row_key] = columns
|
||||||
|
|
||||||
def Write(self, out):
|
def Write(self, out, fmt):
|
||||||
table = []
|
table = []
|
||||||
# Expand the column items
|
# Expand the column items
|
||||||
for row in zip(*self._cols):
|
for row in zip(*self._cols):
|
||||||
@@ -114,26 +115,33 @@ class Table:
|
|||||||
# Update the last row of the header with title and add separator
|
# Update the last row of the header with title and add separator
|
||||||
for i in range(len(self._titles)):
|
for i in range(len(self._titles)):
|
||||||
table[len(table)-1][i] = self._titles[i]
|
table[len(table)-1][i] = self._titles[i]
|
||||||
table.append(pretty.SEPARATOR)
|
if fmt == "table":
|
||||||
|
table.append(pretty.SEPARATOR)
|
||||||
# Populate the data
|
# Populate the data
|
||||||
for row in self._rows:
|
for row in self._rows:
|
||||||
table.append([str(row)]
|
table.append([str(row)]
|
||||||
+ self._fixed_cols[row]
|
+ self._fixed_cols[row]
|
||||||
+ [str(self._data.get((col, row), "")) for col in self._cols])
|
+ [str(self._data.get((col, row), "")) for col in self._cols])
|
||||||
out.write(pretty.FormatTable(table, alignments="LL"))
|
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"
|
"Format a duration in ns to second precision"
|
||||||
sec = round(ns / 1000000000)
|
sec = round(ns / 1000000000)
|
||||||
h, sec = divmod(sec, 60*60)
|
if fmt_sec:
|
||||||
m, sec = divmod(sec, 60)
|
return f"{sec}"
|
||||||
result = ""
|
else:
|
||||||
if h > 0:
|
h, sec = divmod(sec, 60*60)
|
||||||
result += f"{h:2d}h "
|
m, sec = divmod(sec, 60)
|
||||||
if h > 0 or m > 0:
|
result = ""
|
||||||
result += f"{m:2d}m "
|
if h > 0:
|
||||||
return result + f"{sec:2d}s"
|
result += f"{h:2d}h "
|
||||||
|
if h > 0 or m > 0:
|
||||||
|
result += f"{m:2d}m "
|
||||||
|
return result + f"{sec:2d}s"
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
@@ -142,6 +150,12 @@ def main(argv):
|
|||||||
allow_abbrev=False, # Don't let people write unsupportable scripts.
|
allow_abbrev=False, # Don't let people write unsupportable scripts.
|
||||||
description="Print analysis tables for benchmarks")
|
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="*",
|
parser.add_argument("--tags", nargs="*",
|
||||||
help="The tags to print, in order.")
|
help="The tags to print, in order.")
|
||||||
|
|
||||||
@@ -196,9 +210,9 @@ def main(argv):
|
|||||||
summary["branch"],
|
summary["branch"],
|
||||||
summary["tag"]]
|
summary["tag"]]
|
||||||
+ list(key)),
|
+ 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__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
Reference in New Issue
Block a user