Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

tools: reject incompatible trace scenarios in reports

SlivenRed1c89073a9789
diff --git a/tests/test_trace_report.py b/tests/test_trace_report.py
index 8b2f3da79..3cad7098b 100644
--- a/tests/test_trace_report.py
+++ b/tests/test_trace_report.py
@@ -11,6 +11,7 @@ Run from the repository root: python3 -m unittest discover -s tests -v
import contextlib
import importlib.util
import io
+import json
import os
from pathlib import Path
import sqlite3
@@ -58,7 +59,9 @@ def fake_trace(cold=False, frames=(), draws=(), missed=1, gpu=()):
for i, dur in enumerate(frames):
jank = "App Deadline Missed" if i < missed else "Buffer Stuffing"
db.execute("insert into actual_frame_timeline_slice values (?, ?, 2, ?)", ((1060 + 20 * i) * MS, dur * MS, jank))
- return lambda sql: [dict(r) for r in db.execute(sql)]
+ q = lambda sql: [dict(r) for r in db.execute(sql)]
+ q.close = db.close
+ return q
class StartMetricsTest(unittest.TestCase):
@@ -144,6 +147,78 @@ class FilesTest(unittest.TestCase):
self.assertIn("requirements-perf.txt", str(caught.exception.code))
+class MainTest(unittest.TestCase):
+ def open_trace(self, path):
+ q = fake_trace(frames=[16])
+ return q, q.close
+
+ def trace(self, folder, name, scenario=None):
+ path = Path(folder, name + ".pftrace")
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_bytes(b"")
+ if scenario is not None:
+ path.with_suffix(".json").write_text(json.dumps({"scenario": scenario}))
+ return str(path)
+
+ def assert_rejected_before_opening_engine(self, argv):
+ with mock.patch.object(report, "opener", return_value=self.open_trace) as opener, \
+ contextlib.redirect_stdout(io.StringIO()):
+ with self.assertRaisesRegex(SystemExit, "nav.*start.*separately"):
+ report.main(argv)
+ opener.assert_not_called()
+
+ def test_mixed_folder_is_rejected_in_either_input_set(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ mixed, starts = Path(tmp, "mixed"), Path(tmp, "starts")
+ self.trace(mixed, "cold-1")
+ self.trace(mixed, "nav-1")
+ self.trace(starts, "home-1")
+ for argv in ([str(mixed)], [str(starts), "--vs", str(mixed)]):
+ with self.subTest(argv=argv):
+ self.assert_rejected_before_opening_engine(argv)
+
+ def test_vs_rejects_nav_against_start_in_both_directions(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ nav = self.trace(tmp, "nav-1")
+ start = self.trace(tmp, "cold-1")
+ for before, after in ((nav, start), (start, nav)):
+ with self.subTest(before=before):
+ self.assert_rejected_before_opening_engine([before, "--vs", after])
+
+ def test_sidecar_can_make_matching_file_names_incompatible(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ cold = self.trace(tmp, "cold-1")
+ renamed_nav = self.trace(tmp, "cold-2", scenario="nav")
+ self.assert_rejected_before_opening_engine([cold, renamed_nav])
+
+ def test_sidecar_can_make_different_file_names_a_valid_nav_set(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ nav = self.trace(tmp, "nav-1")
+ renamed_nav = self.trace(tmp, "cold-2", scenario="nav")
+ with mock.patch.object(report, "opener", return_value=self.open_trace), \
+ contextlib.redirect_stdout(io.StringIO()) as out:
+ report.main([nav, renamed_nav, "--markdown"])
+ self.assertIn("| frame time, median (ms) |", out.getvalue())
+ self.assertNotIn("| frames drawn in 1.5 s |", out.getvalue())
+
+ def test_matching_nav_and_start_sets_still_report_and_compare(self):
+ for scenarios, label in ((["nav"], "| frame time, median (ms) |"),
+ (["cold", "home", "coldsys", "custom"], "| frames drawn in 1.5 s |")):
+ with self.subTest(scenarios=scenarios), tempfile.TemporaryDirectory() as tmp:
+ before, after = Path(tmp, "before"), Path(tmp, "after")
+ for folder in (before, after):
+ for name in scenarios:
+ self.trace(folder, name + "-1")
+ open_trace = mock.Mock(side_effect=self.open_trace)
+ with mock.patch.object(report, "opener", return_value=open_trace) as opener, \
+ contextlib.redirect_stdout(io.StringIO()) as out:
+ report.main([str(before), "--vs", str(after), "--markdown"])
+ opener.assert_called_once_with(None)
+ self.assertEqual(open_trace.call_count, 2 * len(scenarios))
+ self.assertIn(label, out.getvalue())
+ self.assertIn("Change in the median:", out.getvalue())
+
+
@unittest.skipUnless(os.environ.get("CLEANYOURTV_TRACE") and importlib.util.find_spec("perfetto"),
"needs the optional perfetto package and CLEANYOURTV_TRACE=<a trace from tools/trace.py>")
class RealTraceTest(unittest.TestCase):
diff --git a/tools/trace.md b/tools/trace.md
index 8720735b9..fb95b4fda 100644
--- a/tools/trace.md
+++ b/tools/trace.md
@@ -33,6 +33,10 @@ TV_HOST=<tv ip> tools/venv/bin/python -I tools/trace.py home --runs 5 --out trac
## Report
+Keep `nav` traces separate from start traces (`home`, `cold`, `coldsys`, `custom`), since their frame
+counts use different time windows. Each input set and both sides of `--vs` must use the same family.
+For a folder containing both, pass matching files such as `traces/nav-*.pftrace` instead of the folder.
+
```bash
tools/venv/bin/python tools/trace_report.py traces/before --vs traces/after --markdown
```
diff --git a/tools/trace_report.py b/tools/trace_report.py
index b0a2c1f47..12330d067 100644
--- a/tools/trace_report.py
+++ b/tools/trace_report.py
@@ -271,9 +271,14 @@ def main(argv=None):
missing = [p for p in paths if not os.path.isfile(p)]
if missing:
sys.exit("not a file: " + ", ".join(missing))
+ families = [{"nav" if scenario_of(p) == "nav" else "start" for p in paths} for paths in sets]
+ if any(len(family) > 1 for family in families):
+ sys.exit("cannot mix nav and start traces in one set; report them separately")
+ if len(families) > 1 and families[0] != families[1]:
+ sys.exit("cannot compare nav and start traces with --vs; report them separately")
open_trace = opener(args.engine)
measured = [measure(paths, args.package, open_trace) for paths in sets]
- nav = all(scenario_of(p) == "nav" for p in sets[0])
+ nav = families[0] == {"nav"}
print(report(measured[0], measured[1] if len(measured) > 1 else None, args.markdown, nav))