Skip to content

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

docs/workflows/perf-ab.md: measure a launcher change with traces and a flame chart

sim6e2ec10231d4
diff --git a/AGENTS.md b/AGENTS.md
index f8edbadbf..5f0816c76 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -62,7 +62,7 @@ share their TV's list afterwards, follow [Add a TV list](#add-a-tv-list) below.
| `SHOWCASE.md` | Projects built on this repo that live in their own repositories. |
| `CODE_OF_CONDUCT.md` | Includes the rule against publishing device identifiers, Wi-Fi names and IPs. |
| `examples/` | One folder per tested TV model: `debloat.txt`, sometimes a `README.md` and a `config.json`. Indexed in `examples/README.md`. |
-| `docs/` | `docs/TROUBLESHOOTING.md`, `docs/REMOTE.md` (another home, over Tailscale), `docs/modules.md` and `docs/specs/card.md` (module cards), `docs/PRESS.md`, and `docs/devices/` for models with notes but no tested list. |
+| `docs/` | `docs/TROUBLESHOOTING.md`, `docs/REMOTE.md` (another home, over Tailscale), `docs/modules.md` and `docs/specs/card.md` (module cards), `docs/PRESS.md`, `docs/devices/` for models with notes but no tested list, and `docs/workflows/` for multi-step methods (`perf-ab.md`: measuring a performance change). |
| `launcher/` | The reference launcher, package `com.gathin.tvhome`: plain Java, AndroidX RecyclerView and DynamicAnimation, `minSdk` 26, no `INTERNET` permission. |
| `themes/` | One folder per theme: `config.json`, a required `screenshot.jpg`, optional wallpapers. Keys are documented in `themes/README.md`. |
| `addons/` | Optional module-card apps, each its own Gradle project, never built into the launcher. |
diff --git a/docs/workflows/perf-ab.md b/docs/workflows/perf-ab.md
new file mode 100644
index 000000000..903ac0155
--- /dev/null
+++ b/docs/workflows/perf-ab.md
@@ -0,0 +1,82 @@
+# Workflow: measure a launcher performance change, before and after
+
+**When to use this:** you changed the launcher to make it faster or lighter, and the pull request has to
+show by how much, and where the time went. This is the method #666 used.
+
+Tools: [`tools/trace.py` and `tools/trace_report.py`](../../tools/trace.md), then
+[`tools/flamechart.py`](../../tools/flamechart.md). Install them once:
+
+```bash
+tools/venv/bin/pip install -r tools/requirements-perf.txt
+```
+
+Copy this checklist into your notes and tick it off:
+
+```
+- [ ] 1. Write down the scenario and the slices you expect to shrink
+- [ ] 2. Trace the base build, 5 runs
+- [ ] 3. Trace your build, 5 runs
+- [ ] 4. Report; if the change isn't there, go back to your code
+- [ ] 5. Draw the flame charts
+- [ ] 6. Check the behaviour your change could break
+- [ ] 7. Write it up
+```
+
+## 1. Decide before you measure
+
+Write down two things:
+- **The scenario:** `home` (the return to Home), `cold` (start-up) or `nav` (D-pad, drawing).
+- **The slice names** your change should remove or shorten, e.g. `activityResume`, `RV OnBindView`.
+
+They become `trace.py`'s scenario and `flamechart.py`'s `--highlight`. Choosing them after looking at
+the results proves nothing.
+
+## 2–3. Trace both builds
+
+Install each build with `launcher/build-and-install.sh`, using the same config, theme and wallpaper.
+Let Home sit for a minute after each install, then record:
+
+```bash
+tools/venv/bin/python -I tools/trace.py home --runs 5 --out traces/before # base build installed
+tools/venv/bin/python -I tools/trace.py home --runs 5 --out traces/after # your build installed
+```
+
+## 4. Report
+
+```bash
+tools/venv/bin/python tools/trace_report.py traces/before --vs traces/after --markdown
+```
+
+- **No change, or the wrong steps moved:** fix the code before drawing anything.
+- **A starred run** (one over twice the median) stays in the table, named as an outlier.
+
+## 5. Draw
+
+```bash
+tools/venv/bin/python tools/flamechart.py traces/before traces/after \
+ --highlight '<the slices from step 1>' \
+ --subtitle '<TV>, <Android version> · magenta: <what they are>' --out chart.png
+```
+
+For a change to Home, add the frames after the start:
+
+```bash
+tools/venv/bin/python tools/flamechart.py traces/before traces/after \
+ --window start:1500 --threads RenderThread --highlight '^DrawFrame' --out frames.png
+```
+
+## 6. Behaviour
+
+On the TV, check what your change could break, and note what you saw. For the return to Home, for
+example:
+- an app disabled while another app was in front is gone on return;
+- focus comes back to the tile you left from;
+- Home on Home goes to the first tile.
+
+## 7. The pull request
+
+- **Tested on:** the TV, Android version and firmware.
+- **The tables:** `trace_report.py --markdown` before, after and the change, with outliers named.
+- **The charts:** each with its `--highlight` stated.
+- **The behaviour checks:** what you checked and what you saw.
+- **Leave out** `traces/`: the files are large and hold your TV's process list.
diff --git a/tools/flamechart.md b/tools/flamechart.md
index b550c7ce4..b8e64eb8b 100644
--- a/tools/flamechart.md
+++ b/tools/flamechart.md
@@ -31,3 +31,5 @@ A Home change usually needs two charts:
- **Pass folders, not single runs.** The tool picks the median run. If you pass single traces, say why.
- **Magenta is main and render thread time only.** Work moved to another thread or to the GPU isn't gone:
add that thread as a lane, or use the `nav` GPU numbers.
+
+The whole before/after method for a pull request is in [`docs/workflows/perf-ab.md`](../docs/workflows/perf-ab.md).
diff --git a/tools/trace.md b/tools/trace.md
index e84788c92..896493f78 100644
--- a/tools/trace.md
+++ b/tools/trace.md
@@ -59,3 +59,5 @@ With `--vs`, a third table shows the change in each median. A run over twice the
- **Expect no latency gain from off-main-thread work.** It removes work, but doesn't shorten the time to
the first frame.
- **Never commit the `.pftrace` files.** They hold the TV's process list.
+
+The whole before/after method for a pull request is in [`docs/workflows/perf-ab.md`](../docs/workflows/perf-ab.md).