fix: droiddeckctl pacing judges cadence per refresh-rate record and always turns timestats off (#894)

* fix: droiddeckctl pacing judges cadence per refresh-rate record and always turns timestats off

Follow-up to the CodeRabbit reviews of #843/#855:
- off-cadence is counted per layer record against that record's own cadence,
  allowing the neighbouring millisecond bucket (16.7 ms lands in 16 or 17);
- refreshRates comes from the chosen layer records only;
- records with no counted frames are skipped, so an empty game layer no longer
  hides the session's SurfaceView, and a capture with no frames exits NO_FRAMES;
- adb failures while enabling or dumping map to PACING_FAILED, and timestats
  is disabled in every case.

* fix: droiddeckctl pacing reports when timestats could not be turned off
This commit is contained in:
angelrenefm authored and GitHub committed 2026-10-16 09:50:43 -04:00
1 parent a4f2c3b3f0
commit cd04e056db
2 files changed
+100 -20

No files matched your search

+59
View File
@@ -305,6 +305,65 @@ class DroiddeckctlTest(FakeAdbTest):
self.assertEqual(4, code)
self.assertEqual("NO_FRAMES", out["error"]["code"])
def test_pacing_counts_both_buckets_of_one_cadence_and_only_the_chosen_layers_rates(self):
text = "SurfaceFlinger TimeStats:\n" + "".join([
timestats_record("droiddeck_wayland_game#7", 910, {16: 450, 17: 450, 33: 10}, 60),
timestats_record("StatusBar#106", 4, {8: 3}, 90),
])
summary = ctl.pacing_summary(text, "com.droiddeck.launcher")
self.assertEqual(10, summary["offCadence"])
self.assertEqual([60], summary["refreshRates"])
def test_pacing_skips_a_game_layer_with_no_frames_for_the_surfaceview(self):
text = "SurfaceFlinger TimeStats:\n" + "".join([
timestats_record("droiddeck_wayland_game#7", 0, {}, 120),
timestats_record("a1 SurfaceView[com.droiddeck.launcher/com.droiddeck.launcher.SessionActivity]#8", 600, {16: 598, 33: 1}, 120),
])
summary = ctl.pacing_summary(text, "com.droiddeck.launcher")
self.assertEqual(600, summary["frames"])
self.assertIn("SurfaceView[com.droiddeck.launcher/", summary["layers"][0])
def test_pacing_with_a_layer_that_drew_no_frames_exits_4(self):
self.configure({}, timestats="SurfaceFlinger TimeStats:\n" + timestats_record("droiddeck_wayland_game#7", 0, {}, 120))
with unittest.mock.patch.object(ctl.time, "sleep"):
code, out = self.run_ctl("pacing", "--seconds", "1")
self.assertEqual(4, code)
self.assertEqual("NO_FRAMES", out["error"]["code"])
def test_pacing_turns_timestats_off_when_the_dump_fails(self):
calls = []
def adb(_adb, _serial, *args, timeout=30):
calls.append(args[3:])
if "-dump" in args:
raise ctl.ControlError("timed out", "ADB_FAILED")
return ctl.subprocess.CompletedProcess(args, 0, b"", b"")
with unittest.mock.patch.object(ctl, "run_adb", adb), unittest.mock.patch.object(ctl.time, "sleep"):
with self.assertRaises(ctl.ControlError) as caught:
ctl.pacing("adb", "fake-1", 1)
self.assertEqual("PACING_FAILED", caught.exception.code)
self.assertEqual(("--timestats", "-disable"), calls[-1])
def test_pacing_fails_when_timestats_cannot_be_turned_off(self):
def adb(_adb, _serial, *args, timeout=30):
return ctl.subprocess.CompletedProcess(args, 1 if "-disable" in args else 0, b"", b"")
with unittest.mock.patch.object(ctl, "run_adb", adb), unittest.mock.patch.object(ctl.time, "sleep"):
with self.assertRaises(ctl.ControlError) as caught:
ctl.pacing("adb", "fake-1", 1)
self.assertEqual("PACING_FAILED", caught.exception.code)
self.assertIn("timestats off", str(caught.exception))
def test_pacing_maps_an_adb_failure_while_enabling_to_pacing_failed(self):
def adb(*_args, **_kwargs):
raise ctl.ControlError("adb vanished", "ADB_FAILED")
with unittest.mock.patch.object(ctl, "run_adb", adb):
with self.assertRaises(ctl.ControlError) as caught:
ctl.pacing("adb", "fake-1", 1)
self.assertEqual("PACING_FAILED", caught.exception.code)
def test_input_requests(self):
self.configure({"input": {"ok": True, "command": "input"}})
self.run_ctl("input", "tap", "0.5", "0.25", "--space", "fraction")