From 35b72669b6b2a3fab27bb805805a70d88ef253e3 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 28 Nov 2026 22:02:13 -0500 Subject: [PATCH] fix(games): keep Proton's log under 64 MiB while the game runs (#3337) --- docs/development/game-environment.md | 5 ++ .../usr/local/bin/droiddeck-game-debug | 45 ++++++++++++++++ .../overlay/usr/local/bin/droiddeck-game-env | 2 + .../tests/test_desktop_program_diagnostics.py | 53 +++++++++++++++++++ 4 files changed, 105 insertions(+) diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 916fa30dc6..5d780b1253 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -134,6 +134,11 @@ spaces, quotes, or shell characters stay literal. Existing arguments and settings on the next launch. It does not change Steam probes or native Linux programs, whose ordinary output remains in the session log. +Proton's log is held to its first 64 MiB, whichever setting turned it on: a +watcher checks `steam-.log` and `steam-proton.log` every second while the game runs and +cuts them back, and later output continues after the cut. A game stuck in an exception loop +otherwise writes gigabytes per run. + After reproducing once, stop the session and use **Latest session logs > Share logs**. The archive includes the generated Wine/Proton and graphics logs. Debug logging can reduce performance and consume storage; disable it after collecting diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug index 9cf741bf87..24147636b7 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug @@ -3,6 +3,7 @@ import contextlib import json import os import re +import subprocess import sys import tempfile import threading @@ -74,6 +75,50 @@ def apply_game_debug_logs(env, config=None, debug_dir=None): return result +# Proton appends its log through one inherited descriptor and never limits it; a game that loops on an +# exception wrote 3 GB per run. Truncating keeps the first part and frees the rest, and Proton's +# appends continue from the new end. +PROTON_LOG_CAP = 64 * 1024 * 1024 +PROTON_LOG_CHECK_S = 1 +CAP_WATCH = r""" +import os, stat, sys, time +pid, limit, every, paths = int(sys.argv[1]), int(sys.argv[2]), float(sys.argv[3]), sys.argv[4:] +while os.path.isdir("/proc/%d" % pid): + for path in paths: + try: + info = os.lstat(path) + if stat.S_ISREG(info.st_mode) and info.st_size > limit: + os.truncate(path, limit) + except OSError: + pass + time.sleep(every) +""" + + +def proton_log_paths(env): + if env.get("PROTON_LOG", "0") in ("", "0"): + return [] + folder = env.get("PROTON_LOG_DIR") or env.get("HOME") or os.environ.get("HOME") or "/root" + paths = [os.path.join(folder, "steam-proton.log")] + if env.get("SteamGameId"): + paths.insert(0, os.path.join(folder, "steam-%s.log" % env["SteamGameId"])) + return paths + + +def cap_proton_log(env, pid=None, limit=PROTON_LOG_CAP, every=PROTON_LOG_CHECK_S, popen=subprocess.Popen): + """Keep Proton's log under `limit` bytes while process `pid` (this launcher, which becomes Proton) runs.""" + paths = proton_log_paths(env) + if not paths: + return None + try: + return popen([sys.executable, "-c", CAP_WATCH, str(pid or os.getpid()), str(limit), str(every)] + paths, + stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + start_new_session=True) + except OSError as error: + print("droiddeck-game-env: Proton log size limit unavailable (%s)" % error, file=sys.stderr) + return None + + def capped_log(path, limit, mirror=False): os.makedirs(os.path.dirname(path), exist_ok=True) handle = open(path, "wb") diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index d309e8e7f0..a71a8edd94 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -1748,6 +1748,8 @@ def main(): except OSError as undo: print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); Wine uses its own copy " "and the next launch puts the file back" % undo, file=sys.stderr) + if len(command) > 1 and command[1] == "waitforexitandrun": + GAME_DEBUG["cap_proton_log"](env) sync = load_sync() launch, launch_env = select_sync(command, env, sync) if launch[0] != command[0]: diff --git a/tools/tests/test_desktop_program_diagnostics.py b/tools/tests/test_desktop_program_diagnostics.py index aafb89d20b..9124f2a810 100644 --- a/tools/tests/test_desktop_program_diagnostics.py +++ b/tools/tests/test_desktop_program_diagnostics.py @@ -6,6 +6,7 @@ import runpy import subprocess import sys import tempfile +import time import unittest @@ -13,6 +14,58 @@ BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" DEBUG = runpy.run_path(str(BIN / "droiddeck-game-debug")) +class ProtonLogCapTest(unittest.TestCase): + def test_only_an_enabled_proton_log_is_watched(self): + self.assertEqual(DEBUG["proton_log_paths"]({"PROTON_LOG": "0", "SteamGameId": "1"}), []) + self.assertEqual(DEBUG["proton_log_paths"]({"SteamGameId": "1"}), []) + self.assertEqual(DEBUG["proton_log_paths"]({"PROTON_LOG": "1", "PROTON_LOG_DIR": "/logs", "SteamGameId": "584400"}), + ["/logs/steam-584400.log", "/logs/steam-proton.log"]) + self.assertEqual(DEBUG["proton_log_paths"]({"PROTON_LOG": "+seh", "HOME": "/root"}), ["/root/steam-proton.log"]) + + def test_the_watcher_outlives_nothing_but_the_launcher(self): + calls = [] + DEBUG["cap_proton_log"]({"PROTON_LOG": "1", "PROTON_LOG_DIR": "/logs", "SteamGameId": "7"}, pid=42, + popen=lambda argv, **kw: calls.append((argv, kw))) + argv, kw = calls[0] + self.assertEqual(argv[3:], ["42", str(DEBUG["PROTON_LOG_CAP"]), str(DEBUG["PROTON_LOG_CHECK_S"]), + "/logs/steam-7.log", "/logs/steam-proton.log"]) + self.assertTrue(kw["start_new_session"]) + self.assertIsNone(DEBUG["cap_proton_log"]({"PROTON_LOG": "0"}, popen=lambda *a, **k: self.fail("spawned"))) + + def test_a_flooding_log_is_cut_back_and_appends_continue_after_the_cut(self): + with tempfile.TemporaryDirectory() as folder: + log = Path(folder) / "steam-9.log" + launcher = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(3)"]) + with open(log, "ab") as proton: + proton.write(b"Proton: header\n" + b"x" * 300_000) + proton.flush() + watcher = DEBUG["cap_proton_log"]({"PROTON_LOG": "1", "PROTON_LOG_DIR": folder, "SteamGameId": "9"}, + pid=launcher.pid, limit=1000, every=0.1) + deadline = time.monotonic() + 5 + while log.stat().st_size > 1000 and time.monotonic() < deadline: + time.sleep(0.05) + self.assertEqual(log.stat().st_size, 1000) + proton.write(b"tail") + proton.flush() + self.assertTrue(log.read_bytes().startswith(b"Proton: header")) + self.assertTrue(log.read_bytes().endswith(b"tail")) + self.assertEqual(log.stat().st_size, 1004) + launcher.wait() + watcher.wait(timeout=5) + + def test_symlinks_are_left_alone(self): + with tempfile.TemporaryDirectory() as folder: + target = Path(folder) / "other" + target.write_bytes(b"y" * 5000) + (Path(folder) / "steam-3.log").symlink_to(target) + launcher = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(0.5)"]) + watcher = DEBUG["cap_proton_log"]({"PROTON_LOG": "1", "PROTON_LOG_DIR": folder, "SteamGameId": "3"}, + pid=launcher.pid, limit=10, every=0.1) + launcher.wait() + watcher.wait(timeout=5) + self.assertEqual(target.stat().st_size, 5000) + + class DesktopProgramDiagnosticsTest(unittest.TestCase): def launch(self, folder, desktop=True, **settings): env = dict(os.environ, DD_DEBUG_DIR=folder, WINEDEBUG="-all", PROTON_LOG="0")