Compare commits

..
4 changed files with 74 additions and 114 deletions

No files matched your search

@@ -6,13 +6,11 @@ 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_]*)")
@@ -52,31 +50,6 @@ 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()
@@ -88,20 +61,16 @@ 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": log_dir,
"PROTON_CRASH_REPORT_DIR": log_dir or debug_dir,
"DXVK_LOG_PATH": log_dir or debug_dir,
"PROTON_LOG_DIR": debug_dir,
"PROTON_CRASH_REPORT_DIR": debug_dir,
"DXVK_LOG_PATH": 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
@@ -1286,6 +1286,16 @@ def system_graphics_launch(command, env):
return [str(wrapper), *command], result
AUDIO_STREAMS_PROBE = (
'folder=$1; launch=$2; shift 2; n=0; '
'for t in "$@"; do '
'while [ "$n" -lt "$t" ]; do kill -0 "$launch" 2>/dev/null || exit 0; sleep 1; n=$((n + 1)); done; '
'kill -0 "$launch" 2>/dev/null || exit 0; '
'{ echo "== $(date +%T)"; pactl list sink-inputs 2>&1 | head -80; } >> "$folder/audio-streams.txt"; '
'done'
)
def game_logs(command, env, app_id, now=None):
"""Detailed graphics logs for one game launch, in the session's log folder: Proton's own log,
DXVK's and vkd3d-proton's, and the Vulkan driver's startup messages. The app turns this on
@@ -1327,8 +1337,7 @@ def game_logs(command, env, app_id, now=None):
pass
# Whether the game's sound reaches PulseAudio: the streams 20 s and 60 s in, without waiting.
try:
subprocess.Popen(["sh", "-c", 'for t in 20 40; do sleep $t; { echo "== $(date +%T)"; '
'pactl list sink-inputs 2>&1 | head -80; } >> "$1/audio-streams.txt"; done', "audio", str(folder)],
subprocess.Popen(["sh", "-c", AUDIO_STREAMS_PROBE, "audio", str(folder), str(os.getpid()), "20", "60"],
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
start_new_session=True)
except OSError:
-10
View File
@@ -68,16 +68,6 @@ 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):
+60 -68
View File
@@ -9,6 +9,7 @@ import shlex
import subprocess
import sys
import tempfile
import time
from unittest import mock
import unittest
from unittest.mock import patch
@@ -705,74 +706,6 @@ 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) ",
@@ -2081,6 +2014,65 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertIn("exe: first.exe", (Path(first["PROTON_LOG_DIR"]) / "launch.txt").read_text())
self.assertIn("exe: second.exe", (Path(second["PROTON_LOG_DIR"]) / "launch.txt").read_text())
def test_audio_probe_watches_this_launch(self):
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen") as popen:
env = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp}
result = MODULE["game_logs"](["/proton", "waitforexitandrun", "game.exe"], env, "42", now=0)
self.assertEqual(popen.call_args.args[0], [
"sh", "-c", MODULE["AUDIO_STREAMS_PROBE"], "audio", result["PROTON_LOG_DIR"], str(os.getpid()), "20", "60",
])
def test_audio_probe_ends_with_the_game_and_keeps_its_samples_while_it_runs(self):
probe = ["sh", "-c", MODULE["AUDIO_STREAMS_PROBE"], "audio"]
def samples(folder):
path = Path(folder) / "audio-streams.txt"
return sum(line.startswith("== ") for line in path.read_text().splitlines()) if path.exists() else 0
with tempfile.TemporaryDirectory() as tmp:
game = subprocess.Popen(["sleep", "60"])
try:
subprocess.run(probe + [tmp, str(game.pid), "1", "2"], timeout=15, check=True)
self.assertEqual(samples(tmp), 2)
finally:
game.kill()
game.wait()
with tempfile.TemporaryDirectory() as tmp:
game = subprocess.Popen(["sleep", "60"])
running = subprocess.Popen(probe + [tmp, str(game.pid), "1", "600"])
try:
deadline = time.monotonic() + 15
while samples(tmp) < 1 and time.monotonic() < deadline:
time.sleep(0.1)
self.assertEqual(samples(tmp), 1)
game.kill()
game.wait()
self.assertEqual(running.wait(timeout=10), 0)
self.assertEqual(samples(tmp), 1)
finally:
game.kill()
game.wait()
running.kill()
running.wait()
with tempfile.TemporaryDirectory() as tmp:
ended = subprocess.Popen(["true"])
ended.wait()
subprocess.run(probe + [tmp, str(ended.pid), "20", "60"], timeout=10, check=True)
self.assertEqual(samples(tmp), 0)
with tempfile.TemporaryDirectory() as tmp:
game = subprocess.Popen(["sleep", "0.5"])
running = subprocess.Popen(probe + [tmp, str(game.pid), "1"])
try:
game.wait()
self.assertEqual(running.wait(timeout=10), 0)
self.assertEqual(samples(tmp), 0)
finally:
running.kill()
running.wait()
def test_open_driver_pairs_report_the_drivers_own_vkd3d_caps(self):
apply = MODULE["apply_config"]
config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"},