Files
lucisv/tools/perf/sweeptable.py
T

97 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Turn `sweep.sh`'s `/usr/bin/time -l` logs into the document's §7 table.
python3 tools/perf/sweeptable.py <out-dir> [--labels 0.49.0,0.43.0,0.39.0]
Reads every `<label>__<tree>__<command>__<cache>.txt` in `<out-dir>`, pulls the
`real` seconds and the `maximum resident set size` out of each try's block, and
prints a Markdown table with one row per (tree, command, cache) and one column
per label — first try, then the range over the repeats, then peak RSS.
It also prints the summary line each run reported (`N files would be
reformatted`, the finding count), because a timing that moved because the work
moved is not a timing finding.
"""
import argparse
import os
import re
import sys
REAL = re.compile(r"([0-9.]+)\s+real")
RSS = re.compile(r"(\d+)\s+maximum resident set size")
COMMANDS = [("format", "cold"), ("format", "warm"), ("check", "default"), ("check", "select")]
COMMAND_NAMES = {
("format", "cold"): "`format --check`, cold cache",
("format", "warm"): "`format --check`, warm cache",
("check", "default"): "`check` (default rules)",
("check", "select"): "`check --select error,warning,style`",
}
TREES = ["hw/ip", "hw/top_earlgrey/ip", "hw/top_darjeeling/ip", "hw/dv", "hw/vendor"]
def cell(directory, label, tree, command, cache):
"""(reals, peak_rss_mb, summary_lines) for one cell, or None if absent."""
name = "%s__%s__%s__%s.txt" % (label, tree.replace("/", "_"), command, cache)
path = os.path.join(directory, name)
if not os.path.exists(path):
return None
text = open(path, encoding="utf-8", errors="replace").read()
reals = [float(v) for v in REAL.findall(text)]
rss = [int(v) for v in RSS.findall(text)]
# The run's own total line, not its per-file lines: a timing that moved
# because the *work* moved is not a timing finding.
summary = [
line.strip()
for line in text.splitlines()
if re.match(r"^(\d+ files? would be reformatted|found \d+ violations|"
r"no violations|All \d+)", line.strip())
]
return reals, (max(rss) / 1048576.0 if rss else 0.0), summary
def render(reals):
if not reals:
return "—"
if len(reals) == 1:
return "%.2f" % reals[0]
rest = reals[1:]
if abs(max(rest) - min(rest)) < 0.005:
return "%.2f / %.2f" % (reals[0], min(rest))
return "%.2f / %.2f–%.2f" % (reals[0], min(rest), max(rest))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("directory")
parser.add_argument("--labels", default="0.49.0,0.43.0,0.39.0")
args = parser.parse_args()
labels = args.labels.split(",")
print("| Tree | command | " + " | ".join(labels) + " | peak RSS (MB) |")
print("|---|---|" + "---:|" * (len(labels) + 1))
for tree in TREES:
for command, cache in COMMANDS:
cells = [cell(args.directory, label, tree, command, cache) for label in labels]
if not any(cells):
continue
times = " | ".join(render(c[0]) if c else "—" for c in cells)
rss = " → ".join("%.0f" % c[1] for c in cells if c)
print("| `%s` | %s | %s | %s |" % (tree, COMMAND_NAMES[(command, cache)], times, rss))
print()
print("Summary lines, per cell (what the run reported):")
for tree in TREES:
for command, cache in COMMANDS:
for label in labels:
found = cell(args.directory, label, tree, command, cache)
if not found or not found[2]:
continue
print(" %-22s %-8s %-8s %-8s %s" % (
tree, command, cache, label, found[2][0]))
return 0
if __name__ == "__main__":
sys.exit(main())