Compare commits

...
Author SHA1 Message Date
Kurt Himebauch 8364e40ada Merge branch 'main' into fix/wowf-no-window-after-launch 2026-11-24 17:34:06 -05:00
The412Banner 99c5714f31 fix(game-debug): skip the Proton log instead of reusing an occupied log folder 2026-11-20 07:18:28 +00:00
The412Banner 098bf537c8 Merge branch 'main' into fix/wowf-no-window-after-launch 2026-11-20 00:10:19 -05:00
The412Banner 109cee5dee chore(game-debug): merge main into the Proton run log fix
Keeps both new imports in droiddeck-game-debug and uses DD_DEBUG_DIR in
the new test after the branding rename on main.
2026-11-20 04:29:31 +00:00
The412Banner 4595bad798 fix(game-debug): a second Proton run of a game no longer deletes the first run's log
Proton removes steam-<SteamGameId>.log in PROTON_LOG_DIR when it starts.
A store hand-off (Battle.net.exe --exec=launch) runs Proton again with
the same game id while the client is still running. That unlinked the log
the client and the game it starts were writing to. When that log already
exists, a run now writes its Proton, crash and DXVK logs to its own
proton-runs subfolder of the session logs.
2026-11-17 13:16:05 +00:00
3 changed files with 112 additions and 3 deletions

No files matched your search

@@ -6,11 +6,13 @@ import re
import sys
import tempfile
import threading
import time
from pathlib import Path
GAME_DEBUG_CHANNELS = (
"timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree",
)
PROTON_RUN_LOGS = "proton-runs"
WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)")
@@ -50,6 +52,31 @@ def session_debug_dir(env):
return env.get("DD_DEBUG_DIR", "")
def proton_log_free(folder, game_id):
try:
names = os.listdir(folder)
except OSError:
return False
if game_id:
return "steam-%s.log" % game_id not in names
return not any(name.startswith("steam-") and name.endswith(".log") for name in names)
def proton_log_dir(env, debug_dir):
game_id = env.get("SteamGameId")
runs = os.path.join(debug_dir, PROTON_RUN_LOGS)
current = env.get("PROTON_LOG_DIR")
if isinstance(current, str) and os.path.dirname(current) == runs and proton_log_free(current, game_id):
return current
if proton_log_free(debug_dir, game_id):
return debug_dir
try:
os.makedirs(runs, exist_ok=True)
return tempfile.mkdtemp(prefix=time.strftime("%H%M%S-"), dir=runs)
except OSError:
return None
def apply_game_debug_logs(env, config=None, debug_dir=None):
if config is None:
config = load_config()
@@ -61,16 +88,20 @@ def apply_game_debug_logs(env, config=None, debug_dir=None):
or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)):
print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr)
return env
log_dir = proton_log_dir(env, debug_dir)
result = dict(env)
result.update({
"PROTON_LOG": "1",
"PROTON_LOG_DIR": debug_dir,
"PROTON_CRASH_REPORT_DIR": debug_dir,
"DXVK_LOG_PATH": debug_dir,
"PROTON_LOG_DIR": log_dir,
"PROTON_CRASH_REPORT_DIR": log_dir or debug_dir,
"DXVK_LOG_PATH": log_dir or debug_dir,
"DXVK_LOG_LEVEL": "debug",
"VKD3D_DEBUG": "info",
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
})
if log_dir is None:
print("droiddeck-game-env: Proton log skipped; no free log directory", file=sys.stderr)
del result["PROTON_LOG"], result["PROTON_LOG_DIR"]
return result
+10
View File
@@ -68,6 +68,16 @@ class StoreDebugEnvironmentTest(Temp):
self.assertEqual(result["PROTON_LOG_DIR"], str(self.tmp / "session"))
self.assertIn("+seh", result["WINEDEBUG"])
def test_store_handoff_does_not_replace_the_running_clients_proton_log(self):
self.config(True)
with mock.patch.dict(os.environ, self.env({"SteamGameId": "11150221161898442752"}), clear=True):
client = BNET["proton_env"]()
(self.tmp / "session/steam-11150221161898442752.log").write_text("client\n")
handoff = BNET["proton_env"]()
self.assertEqual(client["PROTON_LOG_DIR"], str(self.tmp / "session"))
self.assertEqual(Path(handoff["PROTON_LOG_DIR"]).parent, self.tmp / "session/proton-runs")
self.assertEqual(handoff["DXVK_LOG_PATH"], handoff["PROTON_LOG_DIR"])
def test_store_proton_command_keeps_debug_off_when_disabled(self):
self.config(False)
with mock.patch.dict(os.environ, self.env(), clear=True):
+68
View File
@@ -705,6 +705,74 @@ class GameDebugLoggingTest(unittest.TestCase):
self.assertIs(MODULE["apply_game_debug_logs"](normal, {**config, "gameDebugLogs": False}, debug_dir), normal)
self.assertEqual(MODULE["apply_game_debug_logs"](debug, config, debug_dir), debug)
@staticmethod
def proton_log_like_proton(env):
path = os.path.join(env["PROTON_LOG_DIR"], "steam-" + env["SteamGameId"] + ".log")
if os.path.lexists(path):
os.remove(path)
os.makedirs(env["PROTON_LOG_DIR"], exist_ok=True)
return open(path, "a")
def test_second_proton_run_of_a_game_keeps_the_first_runs_log(self):
config = {"version": 1, "gameDebugLogs": True}
with tempfile.TemporaryDirectory() as debug_dir:
base = {"DD_DEBUG_DIR": debug_dir, "SteamGameId": "11150221161898442752"}
first = MODULE["apply_game_debug_logs"](base, config, debug_dir)
self.assertEqual(first["PROTON_LOG_DIR"], debug_dir)
self.assertEqual(MODULE["apply_game_debug_logs"](first, config, debug_dir), first)
with self.proton_log_like_proton(first) as launcher:
launcher.write("launcher\n")
launcher.flush()
second = MODULE["apply_game_debug_logs"](base, config, debug_dir)
runs = os.path.join(debug_dir, "proton-runs")
self.assertEqual(os.path.dirname(second["PROTON_LOG_DIR"]), runs)
for key in ("PROTON_CRASH_REPORT_DIR", "DXVK_LOG_PATH"):
self.assertEqual(second[key], second["PROTON_LOG_DIR"])
self.assertEqual(MODULE["apply_game_debug_logs"](second, config, debug_dir), second)
with self.proton_log_like_proton(second) as handoff:
handoff.write("handoff\n")
launcher.write("game child\n")
log = Path(debug_dir, "steam-11150221161898442752.log")
self.assertEqual(log.read_text(), "launcher\ngame child\n")
self.assertEqual(Path(second["PROTON_LOG_DIR"], log.name).read_text(), "handoff\n")
third = MODULE["apply_game_debug_logs"](base, config, debug_dir)
self.assertNotIn(third["PROTON_LOG_DIR"], (debug_dir, second["PROTON_LOG_DIR"]))
self.assertEqual(len(os.listdir(runs)), 2)
def test_proton_log_folder_stays_the_session_folder_for_other_games(self):
config = {"version": 1, "gameDebugLogs": True}
with tempfile.TemporaryDirectory() as debug_dir:
Path(debug_dir, "steam-42.log").write_text("other game\n")
Path(debug_dir, "Wow-arm64_d3d11.log").write_text("dxvk\n")
env = MODULE["apply_game_debug_logs"]({"SteamGameId": "7"}, config, debug_dir)
self.assertEqual(env["PROTON_LOG_DIR"], debug_dir)
self.assertFalse(os.path.exists(os.path.join(debug_dir, "proton-runs")))
unknown = MODULE["apply_game_debug_logs"]({}, config, debug_dir)
self.assertEqual(os.path.dirname(unknown["PROTON_LOG_DIR"]), os.path.join(debug_dir, "proton-runs"))
outside = MODULE["apply_game_debug_logs"]({"SteamGameId": "42", "PROTON_LOG_DIR": "/elsewhere"},
config, debug_dir)
self.assertEqual(os.path.dirname(outside["PROTON_LOG_DIR"]), os.path.join(debug_dir, "proton-runs"))
self.assertEqual(Path(debug_dir, "steam-42.log").read_text(), "other game\n")
def test_proton_log_is_skipped_when_no_free_log_folder_can_be_made(self):
config = {"version": 1, "gameDebugLogs": True}
with tempfile.TemporaryDirectory() as debug_dir:
Path(debug_dir, "steam-42.log").write_text("first run\n")
Path(debug_dir, "proton-runs").write_text("not a folder\n")
inherited = {"SteamGameId": "42", "PROTON_LOG": "1", "PROTON_LOG_DIR": debug_dir, "WINEDEBUG": "+relay"}
with patch("sys.stderr", new_callable=io.StringIO) as stderr:
env = MODULE["apply_game_debug_logs"](inherited, config, debug_dir)
self.assertNotIn("PROTON_LOG", env)
self.assertNotIn("PROTON_LOG_DIR", env)
self.assertEqual(env["DXVK_LOG_PATH"], debug_dir)
self.assertEqual(env["PROTON_CRASH_REPORT_DIR"], debug_dir)
self.assertIn("+relay", env["WINEDEBUG"])
self.assertIn("+seh", env["WINEDEBUG"])
self.assertIn("Proton log skipped", stderr.getvalue())
self.assertEqual(Path(debug_dir, "steam-42.log").read_text(), "first run\n")
other = MODULE["apply_game_debug_logs"]({"SteamGameId": "7"}, config, debug_dir)
self.assertEqual(other["PROTON_LOG_DIR"], debug_dir)
def test_wine_debug_channels_are_formatted_deduplicated_and_diagnostics_win(self):
formatted = MODULE["game_debug_channels"](
" +relay, trace-vulkan, -all, -seh, +relay, trace+vulkan, garbage, $(touch never) ",