mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +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
+67
-2
@@ -285,6 +285,64 @@ def record(adb: str, serial: str, path: str, seconds: float, display: int | None
|
||||
return {"ok": True, "command": "record", "path": str(destination), "seconds": seconds, "display": display}
|
||||
|
||||
|
||||
def pacing_summary(text: str, package: str = PACKAGE) -> dict:
|
||||
"""What reached the panel, from a `dumpsys SurfaceFlinger --timestats -dump`.
|
||||
|
||||
The game is on the compositor's own layer (droiddeck_wayland_game) when it has one, otherwise on
|
||||
the session's SurfaceView. SurfaceFlinger keeps one record per layer AND refresh rate, so a panel
|
||||
that switches between 60 and 120 Hz mid-capture splits the same layer into several records: they
|
||||
are summed. A game's own fps counter does not show any of this - it counts frames handed over, not
|
||||
frames shown, and 60 handed over can be 48 on screen with one in four held for two refreshes.
|
||||
"""
|
||||
records = {"game": [], "surface": []}
|
||||
for part in re.split(r"^layerName = ", text, flags=re.M)[1:]:
|
||||
name, _, body = part.partition("\n")
|
||||
kind = ("game" if "droiddeck_wayland_game" in name
|
||||
else "surface" if f"SurfaceView[{package}/" in name else None)
|
||||
frames = re.search(r"^totalFrames = (\d+)", body, re.M)
|
||||
hist = re.search(r"^present2present histogram is as below:\n(.*)", body, re.M)
|
||||
if kind and frames and hist:
|
||||
records[kind].append((re.sub(r"#\d+$", "", name.strip()), int(frames.group(1)), hist.group(1)))
|
||||
chosen = records["game"] or records["surface"]
|
||||
histogram: dict[int, int] = {}
|
||||
for _, _, hist in chosen:
|
||||
for ms, count in re.findall(r"(\d+)ms=(\d+)", hist):
|
||||
if int(count):
|
||||
histogram[int(ms)] = histogram.get(int(ms), 0) + int(count)
|
||||
intervals = sum(histogram.values())
|
||||
cadence = max(histogram, key=histogram.get) if histogram else None
|
||||
off = intervals - histogram.get(cadence, 0) if histogram else 0
|
||||
return {
|
||||
"layers": sorted({name for name, _, _ in chosen}),
|
||||
"frames": sum(frames for _, frames, _ in chosen),
|
||||
"refreshRates": sorted({int(r) for r in re.findall(r"^displayRefreshRate = (\d+)", text, re.M)}),
|
||||
"presentToPresentMs": {str(ms): histogram[ms] for ms in sorted(histogram)},
|
||||
"cadenceMs": cadence,
|
||||
"offCadence": off,
|
||||
"offCadencePercent": round(100.0 * off / intervals, 1) if intervals else None,
|
||||
}
|
||||
|
||||
|
||||
def pacing(adb: str, serial: str, seconds: float) -> dict:
|
||||
"""Frames on screen and their intervals over `seconds`, from SurfaceFlinger's timestats."""
|
||||
seconds = max(1.0, min(600.0, seconds))
|
||||
timestats = ("shell", "dumpsys", "SurfaceFlinger", "--timestats")
|
||||
if run_adb(adb, serial, *timestats, "-clear", "-enable").returncode != 0:
|
||||
raise ControlError("could not enable SurfaceFlinger timestats", "PACING_FAILED")
|
||||
started = time.monotonic()
|
||||
time.sleep(seconds)
|
||||
dump = run_adb(adb, serial, *timestats, "-dump", timeout=60)
|
||||
elapsed = time.monotonic() - started
|
||||
run_adb(adb, serial, *timestats, "-disable")
|
||||
if dump.returncode != 0:
|
||||
raise ControlError(dump.stderr.decode(errors="replace").strip() or "timestats dump failed", "PACING_FAILED")
|
||||
summary = pacing_summary(dump.stdout.decode(errors="replace"))
|
||||
if not summary["layers"]:
|
||||
raise ControlError("No DroidDeck layer drew during the capture: is a session on screen?", "NO_FRAMES")
|
||||
summary["fpsOnScreen"] = round(summary["frames"] / elapsed, 1)
|
||||
return {"ok": True, "command": "pacing", "seconds": round(elapsed, 1), **summary}
|
||||
|
||||
|
||||
|
||||
def start_session(adb: str, serial: str, request: dict) -> dict:
|
||||
if request.get("mode") == "run":
|
||||
@@ -504,6 +562,9 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
if command == "record":
|
||||
return add_serial(record(adb, serial, args.path, args.seconds, args.display), serial)
|
||||
|
||||
if command == "pacing":
|
||||
return add_serial(pacing(adb, serial, args.seconds), serial)
|
||||
|
||||
if command == "wake":
|
||||
run_adb(adb, serial, "shell", "input", "keyevent", "KEYCODE_WAKEUP")
|
||||
run_adb(adb, serial, "shell", "wm", "dismiss-keyguard")
|
||||
@@ -661,6 +722,9 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
rec.add_argument("--seconds", type=float, default=10)
|
||||
rec.add_argument("--display", type=int)
|
||||
|
||||
pace = commands.add_parser("pacing", help="frames that reached the screen and their intervals (SurfaceFlinger)")
|
||||
pace.add_argument("--seconds", type=float, default=30)
|
||||
|
||||
commands.add_parser("displays", help="the device's displays and their capture ids")
|
||||
commands.add_parser("wake", help="wake the device and dismiss the keyguard")
|
||||
return parser
|
||||
@@ -670,10 +734,11 @@ EXIT_ADB = {"ADB_NOT_FOUND", "ADB_FAILED", "INVALID_PROVIDER_RESPONSE"}
|
||||
EXIT_SESSION = {
|
||||
"SESSION_ACTIVE", "NO_ACTIVE_SESSION", "SESSION_NOT_SUSPENDED", "SESSION_FAILED", "GUEST_EXIT",
|
||||
"GUEST_START_FAILED", "RUNTIME_INSTALL_FAILED", "DESKTOP_INSTALL_FAILED", "ACTIVITY_START_FAILED",
|
||||
"NO_STEAM_SESSION", "SESSION_NOT_READY", "AGENT_UNAVAILABLE", "LAUNCH_REJECTED", "NO_PAD",
|
||||
"NO_STEAM_SESSION", "SESSION_NOT_READY", "AGENT_UNAVAILABLE", "LAUNCH_REJECTED", "NO_PAD", "NO_FRAMES",
|
||||
}
|
||||
EXIT_TIMEOUT = {"TIMEOUT", "ARTIFACT_TIMEOUT"}
|
||||
EXIT_FILE = {"NO_SESSION_LOGS", "LOG_PULL_FAILED", "SCREENSHOT_FAILED", "FILE_IO", "RECORD_FAILED", "PUSH_FAILED"}
|
||||
EXIT_FILE = {"NO_SESSION_LOGS", "LOG_PULL_FAILED", "SCREENSHOT_FAILED", "FILE_IO", "RECORD_FAILED", "PUSH_FAILED",
|
||||
"PACING_FAILED"}
|
||||
EXIT_DENIED = {"AGENT_COMMANDS_DISABLED", "PROTECTED_PREFS", "PROTECTED_CONTROL"}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user