mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
feat: droiddeckctl pacing reports the frames that reached the screen Reads SurfaceFlinger's timestats for the game's layer (or the session's SurfaceView) over a capture: frames on screen, fps on screen, the present-to-present histogram and how many intervals were off the usual cadence. Records split by a refresh-rate change are summed. A game's own fps counter counts frames handed over, so it can't show dropped or doubled frames. Co-authored-by: angelrenefm <17342133+angelrenefm@users.noreply.github.com>
This commit is contained in:
1 parent
af13f04156
commit
704e95edb3
3 files changed
+138
-4
No files matched your search
@@ -57,6 +57,8 @@ FAKE_ADB = textwrap.dedent('''\
|
||||
print(config.get("dumpsys_display", ""))
|
||||
elif args[:3] == ["shell", "dumpsys", "power"]:
|
||||
print(" mWakefulness=Awake")
|
||||
elif args[:3] == ["shell", "dumpsys", "SurfaceFlinger"] and "-dump" in args:
|
||||
print(config.get("timestats", ""))
|
||||
elif args[:2] == ["exec-out", "screencap"]:
|
||||
sys.stdout.buffer.write(b"\\x89PNG fake")
|
||||
with open(config["log"], "a") as log:
|
||||
@@ -79,6 +81,32 @@ DUMPSYS_DISPLAY = textwrap.dedent('''\
|
||||
''')
|
||||
|
||||
|
||||
def timestats_record(name, frames, histogram, hz):
|
||||
bins = " ".join(f"{ms}ms={histogram.get(ms, 0)}" for ms in (8, 16, 17, 25, 33, 50))
|
||||
return (f"displayRefreshRate = {hz} fps\nrenderRate = {hz} fps\nuid = 10479\nlayerName = {name}\n"
|
||||
f"packageName = \ntotalFrames = {frames}\ndroppedFrames = 0\n"
|
||||
f"present2present histogram is as below:\n{bins}\nlatch2present histogram is as below:\n8ms={frames}\n")
|
||||
|
||||
|
||||
# A capture where the panel went from 60 to 120 Hz: the game layer is split in two records. The
|
||||
# activity's own window and an unrelated app draw too, and must not count.
|
||||
TIMESTATS_SPLIT = "SurfaceFlinger TimeStats:\ntotalFrames = 2000\n" + "".join([
|
||||
timestats_record("droiddeck_wayland_game#6110", 900, {16: 700, 33: 199}, 60),
|
||||
timestats_record("droiddeck_wayland_game#6110", 900, {16: 850, 25: 49}, 120),
|
||||
timestats_record("com.droiddeck.launcher/com.droiddeck.launcher.SessionActivity#6097", 8, {16: 7}, 60),
|
||||
timestats_record("f291fb6 SurfaceView[com.droiddeck.launcher/com.droiddeck.launcher.SessionActivity]#6101",
|
||||
30, {33: 29}, 60),
|
||||
timestats_record("StatusBar#106", 1, {}, 60),
|
||||
])
|
||||
|
||||
# A build that presents the game on the session's SurfaceView instead of a layer of its own.
|
||||
TIMESTATS_SURFACEVIEW = "SurfaceFlinger TimeStats:\n" + "".join([
|
||||
timestats_record("a1b2c3 SurfaceView[com.droiddeck.launcher/com.droiddeck.launcher.SessionActivity]#77",
|
||||
1800, {16: 1796, 33: 3}, 120),
|
||||
timestats_record("a1b2c3 SurfaceView[com.other.app/com.other.app.Main]#12", 500, {8: 499}, 120),
|
||||
])
|
||||
|
||||
|
||||
def state(phase="READY", focused=None, focusable=()):
|
||||
focus = None if focused is None else {"focusedApp": focused, "focusableApps": list(focusable),
|
||||
"baselayerAppIds": [], "seq": 1, "t": 0}
|
||||
@@ -243,6 +271,40 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual(2, code)
|
||||
self.assertEqual("NO_SUCH_DISPLAY", out["error"]["code"])
|
||||
|
||||
def test_pacing_sums_split_records_of_the_game_layer_only(self):
|
||||
summary = ctl.pacing_summary(TIMESTATS_SPLIT, "com.droiddeck.launcher")
|
||||
self.assertEqual(["droiddeck_wayland_game"], summary["layers"])
|
||||
self.assertEqual(1800, summary["frames"])
|
||||
self.assertEqual([60, 120], summary["refreshRates"])
|
||||
self.assertEqual({"16": 1550, "25": 49, "33": 199}, summary["presentToPresentMs"])
|
||||
self.assertEqual(16, summary["cadenceMs"])
|
||||
self.assertEqual(248, summary["offCadence"])
|
||||
self.assertEqual(13.8, summary["offCadencePercent"])
|
||||
|
||||
def test_pacing_falls_back_to_the_sessions_surfaceview(self):
|
||||
summary = ctl.pacing_summary(TIMESTATS_SURFACEVIEW, "com.droiddeck.launcher")
|
||||
self.assertEqual(1, len(summary["layers"]))
|
||||
self.assertIn("SurfaceView[com.droiddeck.launcher/", summary["layers"][0])
|
||||
self.assertEqual(1800, summary["frames"])
|
||||
self.assertEqual(3, summary["offCadence"])
|
||||
|
||||
def test_pacing_captures_then_turns_timestats_off(self):
|
||||
self.configure({}, timestats=TIMESTATS_SURFACEVIEW)
|
||||
with unittest.mock.patch.object(ctl.time, "sleep"):
|
||||
code, out = self.run_ctl("pacing", "--seconds", "1")
|
||||
self.assertEqual(0, code)
|
||||
self.assertEqual("pacing", out["command"])
|
||||
self.assertIn("fpsOnScreen", out)
|
||||
sf = [c["args"][3:] for c in self.calls() if c["args"][:3] == ["shell", "dumpsys", "SurfaceFlinger"]]
|
||||
self.assertEqual([["--timestats", "-clear", "-enable"], ["--timestats", "-dump"], ["--timestats", "-disable"]], sf)
|
||||
|
||||
def test_pacing_without_a_session_on_screen_exits_4(self):
|
||||
self.configure({}, timestats="SurfaceFlinger TimeStats:\n" + timestats_record("StatusBar#1", 3, {16: 2}, 60))
|
||||
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_input_requests(self):
|
||||
self.configure({"input": {"ok": True, "command": "input"}})
|
||||
self.run_ctl("input", "tap", "0.5", "0.25", "--space", "fraction")
|
||||
|
||||
Reference in new issue
Block a user