From c9abd1fe0518063504907baddde78ab44792ff10 Mon Sep 17 00:00:00 2001 From: razormontana <60733278+razormontana@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:16:27 +0100 Subject: [PATCH 1/3] Scripts: align world-load stalls with logged compiles and GPU waits Summarize terminal zero-present samples and align them with numbered driver compile intervals and logged queue wait observations. Part of #505. --- README.md | 10 +++ scripts/test_world_load_stall.py | 99 +++++++++++++++++++++ scripts/world_load_stall.py | 147 +++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 scripts/test_world_load_stall.py create mode 100644 scripts/world_load_stall.py diff --git a/README.md b/README.md index 2adb044fab..dfb8fb1d84 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,16 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder `XCL_PSO_TRACE=1` logs every driver compile. A huge compute program the driver refuses is logged with the driver's verdict (`the driver refused the compute PSO of record HASH … with 0x…`): its dispatches are skipped. +- To investigate a world-load pause, save a run's `xcl.log` with `XCL_ACTIVITY=1` (set by + `scripts/smoke.ps1`) and `XCL_PSO_TRACE=1` for full driver compile tracing. Run + `python scripts/world_load_stall.py path/to/xcl.log` on the saved file. It finds the final + run of zero-present samples after a sample with presents, up to the last sample before any + timed shutdown. It reports sampled submit, draw, dispatch and DirectStorage activity alongside + overlapping driver compiles and logged GPU wait events. Compile overlap counts concurrent + work once and shows possible additional overlap when a finish is missing. Without the trace + switch, XCL logs only huge driver compiles. The wait-before-signal bridge messages are capped. + The samples give a time window for investigation. Confirm the visible scene separately, and + use thread or queue diagnostics to determine what the title was waiting on. - With `XCL_DRED=1`, a D3D12 device removal logs GPU breadcrumbs in `xcl.log`. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. For each, it names the translated diff --git a/scripts/test_world_load_stall.py b/scripts/test_world_load_stall.py new file mode 100644 index 0000000000..49cf7014a0 --- /dev/null +++ b/scripts/test_world_load_stall.py @@ -0,0 +1,99 @@ +import unittest + +from world_load_stall import summarize + + +def log(time, message, tid=11, level="INFO "): + return f"[{time:9.3f}][{tid:5}][{level}] {message}\n" + + +def activity(time, presents, submits=0, draws=0, dispatches=0, requests=0): + return log( + time, + f"activity (2 s): {presents} presents, {submits} submits, {draws} draws, " + f"{dispatches} dispatches, 0 frame-event waits (0 timed out), " + f"0 frame statistics (0 not flipped); DirectStorage {requests} requests, 0 MB, 0 failed", + ) + + +def compile_start(time, number): + return log( + time, f"D3D12.X: driver compile start #{number}: compute PSO, 65536 B DXIL, " + "record fedcba9876543210, driver blob absent", tid=15, + ) + + +def compile_finish(time, number): + return log( + time, f"D3D12.X: driver compile finish #{number}: compute PSO, 65536 B DXIL, 3000 ms", + tid=15, + ) + + +class StallSummaryTests(unittest.TestCase): + def test_correlates_and_merges_compiles_across_the_window(self): + report = summarize([ + activity(2, 0), + activity(4, 20), + compile_start(5, 10), + compile_finish(6, 10), + compile_start(7, 12), + activity(8, 60), + compile_start(9, 31), + compile_finish(11, 12), + activity(10, 0, 6, 5, 3, 9), + compile_finish(11, 31), + compile_start(11.5, 45), + activity(12, 0, 1, 0, 2, 1), + activity(14, 0), + compile_start(15, 59), + ]) + + self.assertIn("Last sample with presents: 8.000 s (60 presents)", report) + self.assertIn("Sampled window: 8.000 to 14.000 s (6.000 s)", report) + self.assertIn("7 submits, 5 draws, 5 dispatches, 10 DirectStorage requests", report) + self.assertIn("Logged driver compiles overlapping the window: 3 (1 began earlier)", report) + self.assertIn("Matched driver compile overlap: 3.000 s", report) + self.assertIn("Possible overlap including 1 start without a logged finish: 5.500 s", report) + self.assertIn("First overlapping compile: #12 compute (65536 B DXIL) at 7.000 s", report) + + def test_aligns_logged_waits_and_excludes_post_stop_activity(self): + report = summarize([ + activity(8, 55), + activity(10, 0), + log(10.1, "D3D12.X: Wait64BitValueX at 0x2000 >= 0x6 bridged to GPU queue.Wait " + "(waiter=q1/ty0, prod=qNone/tySome(2); wait-before-signal, after_write64=false)"), + # The bridge for this release may not have been logged. + log(10.2, "D3D12.X: GPU queue.Wait at 0x1000 >= 0x4 did not complete within 5000 ms " + "(waiter=q0/ty0, prod=qSome(2)/tySome(2), recorded=0x4, submitted=0x4, completed=0x0)" + " – released on CPU to prevent GPU hang", level="WARN "), + activity(12, 0), + log(13, "XCL_RUN_SECONDS: 13 s – ending the title (60 frames shown, 60 PresentX calls)"), + activity(14, 30, 10), + compile_start(13.1, 16), + ]) + + self.assertIn("Sampled window: 8.000 to 12.000 s (4.000 s)", report) + self.assertIn("Logged driver compiles overlapping the window: 0", report) + self.assertIn("Logged wait-before-signal bridges: 1 (first at 10.100 s)", report) + self.assertIn("Logged GPU wait watchdog releases: 1 (first at 10.200 s)", report) + + def test_startup_without_presents_has_no_presentation_loss_window(self): + report = summarize([activity(2, 0), activity(4, 0)]) + self.assertIn("Activity samples contain no presents", report) + + def test_earlier_pause_ends_when_presents_resume(self): + report = summarize([ + activity(2, 33), + activity(4, 0), + activity(6, 22), + ]) + self.assertIn("No terminal zero-present activity samples", report) + + def test_no_activity_samples(self): + report = summarize(["not a runtime log", compile_start(4, 1)]) + self.assertIn("No activity samples found. Capture with XCL_ACTIVITY=1.", report) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/world_load_stall.py b/scripts/world_load_stall.py new file mode 100644 index 0000000000..48670e4575 --- /dev/null +++ b/scripts/world_load_stall.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +"""Summarize the final sampled pause in presents from one saved XCL runtime log.""" + +import argparse +import re +from dataclasses import dataclass +from pathlib import Path + + +LOG_LINE = re.compile(r"^\[\s*(\d+\.\d{3})\]\[\s*\d+\]\[[A-Z ]{5}\] (.*)") +ACTIVITY = re.compile( + r"activity \(2 s\): (\d+) presents, (\d+) submits, (\d+) draws, " + r"(\d+) dispatches, .*; DirectStorage (\d+) requests," +) +COMPILE_START = re.compile(r"D3D12\.X: driver compile start #(\d+): (.+?) PSO, (\d+) B DXIL") +COMPILE_FINISH = re.compile(r"D3D12\.X: driver compile finish #(\d+): ") + + +@dataclass(frozen=True) +class Activity: + time: float + presents: int + submits: int + draws: int + dispatches: int + requests: int + + +@dataclass(frozen=True) +class Compile: + time: float + kind: str + dxil_bytes: int + + +def overlap_seconds(intervals): + """Measure the union so concurrent compiles contribute only once.""" + total = 0.0 + covered_end = 0.0 + for start, end in sorted(intervals): + total += max(0, end - max(start, covered_end)) + covered_end = max(covered_end, end) + return total + + +def event_count(times, start, end): + in_window = [time for time in times if start < time <= end] + return f"{len(in_window)} (first at {min(in_window):.3f} s)" if in_window else "0" + + +def summarize(lines): + samples = [] + starts = {} + finishes = {} + bridges = [] + releases = [] + stop = float("inf") + for line in lines: + match = LOG_LINE.match(line) + if not match: + continue + time = float(match[1]) + message = match[2] + if activity := ACTIVITY.match(message): + samples.append(Activity(time, *map(int, activity.groups()))) + elif compile_start := COMPILE_START.match(message): + starts[int(compile_start[1])] = Compile(time, compile_start[2], int(compile_start[3])) + elif finish := COMPILE_FINISH.match(message): + finishes[int(finish[1])] = time + elif message.startswith("D3D12.X: Wait64BitValueX at ") and " bridged to GPU queue.Wait " in message: + bridges.append(time) + elif (message.startswith("D3D12.X: GPU queue.Wait at ") + and " released on CPU to prevent GPU hang" in message): + releases.append(time) + elif message.startswith("XCL_RUN_SECONDS: ") and " ending the title " in message: + stop = min(stop, time) + + # Log timestamps are taken before the file lock. Use them to align threads. + samples = sorted((sample for sample in samples if sample.time < stop), key=lambda sample: sample.time) + if not samples: + return "No activity samples found. Capture with XCL_ACTIVITY=1." + last_present = next((i for i in reversed(range(len(samples))) if samples[i].presents), None) + if last_present is None: + return "Activity samples contain no presents. No presentation-loss window can be measured." + last_active = samples[last_present] + tail = samples[last_present + 1:] + if not tail: + return f"No terminal zero-present activity samples. Last sample with presents: {last_active.time:.3f} s." + + start = last_active.time + end = tail[-1].time + matches = [] + unmatched = [] + intersecting = [] + for number, build in starts.items(): + finish = finishes.get(number) + left = max(start, build.time) + right = min(end, finish) if finish is not None else end + if right <= left: + continue + (matches if finish is not None else unmatched).append((left, right)) + intersecting.append(number) + + began_earlier = sum(starts[number].time < start for number in intersecting) + report = [ + f"Last sample with presents: {start:.3f} s ({last_active.presents} presents)", + f"Terminal zero-present samples: {len(tail)} (first at {tail[0].time:.3f} s)", + f"Sampled window: {start:.3f} to {end:.3f} s ({end - start:.3f} s)", + f"Sampled activity: {sum(sample.submits for sample in tail)} submits, " + f"{sum(sample.draws for sample in tail)} draws, " + f"{sum(sample.dispatches for sample in tail)} dispatches, " + f"{sum(sample.requests for sample in tail)} DirectStorage requests", + f"Logged driver compiles overlapping the window: {len(intersecting)} ({began_earlier} began earlier)", + f"Matched driver compile overlap: {overlap_seconds(matches):.3f} s", + ] + if unmatched: + report.append( + f"Possible overlap including {len(unmatched)} " + f"{'start' if len(unmatched) == 1 else 'starts'} without a logged finish: " + f"{overlap_seconds(matches + unmatched):.3f} s (through the last sample)" + ) + if intersecting: + number = min(intersecting, key=lambda number: (starts[number].time, number)) + build = starts[number] + report.append( + f"First overlapping compile: #{number} {build.kind} ({build.dxil_bytes} B DXIL) at {build.time:.3f} s" + ) + report.extend([ + f"Logged wait-before-signal bridges: {event_count(bridges, start, end)}", + f"Logged GPU wait watchdog releases: {event_count(releases, start, end)}", + ]) + return "\n".join(report) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("log", type=Path, help="path to one saved xcl.log") + args = parser.parse_args() + try: + with args.log.open(encoding="utf-8-sig", errors="replace") as log: + print(summarize(log)) + except OSError as error: + parser.error(str(error)) + + +if __name__ == "__main__": + main() From c9c531ee5bce18f64fe63844502fc449a884c451 Mon Sep 17 00:00:00 2001 From: razormontana <60733278+razormontana@users.noreply.github.com> Date: Wed, 25 Nov 2026 23:30:34 +0100 Subject: [PATCH 2/3] Scripts: show sampled title-thread candidates for world-load stalls With an explicit title basename, inspect the latest dump within the existing zero-present sample window. Report visible XCL offsets above the first title frame and the coverage of the saved dump. Suggested by GreemSC with Claude Code (Claude Opus 5.5): https://github.com/xcl-dev/xcl/pull/2529#issuecomment-7175569296 --- README.md | 4 ++ scripts/test_world_load_stall.py | 63 ++++++++++++++++++++++++++++++ scripts/world_load_stall.py | 67 ++++++++++++++++++++++++++++++-- 3 files changed, 131 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dfb8fb1d84..9ded6962d8 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,10 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder switch, XCL logs only huge driver compiles. The wait-before-signal bridge messages are capped. The samples give a time window for investigation. Confirm the visible scene separately, and use thread or queue diagnostics to determine what the title was waiting on. + If the log includes dumps from `XCL_THREAD_DUMP_AT`, add `--title-exe MyTitle.exe` to inspect the + latest dump after the last positive sample through the closing zero-present sample. The report + lists thread IDs and visible `xcl.exe` offsets above their first title frame. Use those sampled + candidates to investigate the pause. A short unwind can hide the title frame or XCL callers. - With `XCL_DRED=1`, a D3D12 device removal logs GPU breadcrumbs in `xcl.log`. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. For each, it names the translated diff --git a/scripts/test_world_load_stall.py b/scripts/test_world_load_stall.py index 49cf7014a0..d4ba2d8013 100644 --- a/scripts/test_world_load_stall.py +++ b/scripts/test_world_load_stall.py @@ -30,6 +30,11 @@ def compile_finish(time, number): ) +def thread_dump(time, *rows, count=None): + count = len(rows) if count is None else count + return [log(time, f"thread dump ({count} threads):"), *(row + "\r\n" for row in rows)] + + class StallSummaryTests(unittest.TestCase): def test_correlates_and_merges_compiles_across_the_window(self): report = summarize([ @@ -94,6 +99,64 @@ def test_no_activity_samples(self): report = summarize(["not a runtime log", compile_start(4, 1)]) self.assertIn("No activity samples found. Capture with XCL_ACTIVITY=1.", report) + def test_latest_dump_including_closing_sample_matches_windows_module_names(self): + lines = [ + activity(8, 50), + activity(10, 0), + *thread_dump(12, "thread 42 'worker's caller': dxgi.dll+0x1 < XCL.EXE+0xA " + "< xcl.exe+0xb < … 19 frames … < GAME.EXE+0xc < xcl.exe+0xd", + "thread 43 '': game.exe+0x1 < xcl.exe+0xe", + "thread 44 '': " + " < ".join(["xcl.exe+0xf"] * 14), + "thread 45 '': xcl.exe+0x2 < game.exe+0x3"), + *thread_dump(11, "thread 21 '': xcl.exe+0x11 < game.exe+0x12"), + activity(12, 0), + ] + report = summarize(lines, title_exe="Game.exe") + self.assertIn("Thread dump at 12.000 s: 4/4 thread lines parsed, 3 with a visible title frame", report) + self.assertIn("Sampled title-thread candidates: 2", report) + self.assertIn("Thread 42: 0xa < 0xb\n", report) + self.assertTrue(report.endswith("Thread 45: 0x2")) + self.assertNotIn("Thread 21", report) + self.assertEqual(summarize(lines), summarize([activity(8, 50), activity(10, 0), activity(12, 0)])) + + def test_ignores_dumps_at_opening_sample_outside_window_and_after_shutdown(self): + report = summarize([ + activity(8, 50), + *thread_dump(8), + activity(10, 0), + *thread_dump(10.5), + log(11, "XCL_RUN_SECONDS: 11 s – ending the title (50 frames shown, 50 PresentX calls)"), + *thread_dump(11.5), + activity(12, 0), + ], title_exe="game.exe") + self.assertIn("No timestamped thread dump in the sampled window.", report) + + def test_latest_partial_dump_reports_coverage(self): + report = summarize([ + activity(8, 50), + *thread_dump(9), + *thread_dump(10, "thread 60 '': game.exe+0x10", count=2), + activity(10, 0), + "thread 61 '': xcl.exe+0x62 < game.exe+0x63\n", + ], title_exe="game.exe") + self.assertIn("1/2 thread lines parsed, 1 with a visible title frame (incomplete dump)", report) + self.assertIn("Sampled title-thread candidates: 0", report) + + def test_zero_thread_dump_is_a_valid_sample(self): + report = summarize([activity(8, 50), *thread_dump(9), activity(10, 0)], title_exe="game.exe") + self.assertIn("Thread dump at 9.000 s: 0/0 thread lines parsed, 0 with a visible title frame", report) + self.assertTrue(report.endswith("Sampled title-thread candidates: 0")) + + def test_unterminated_last_thread_row_is_incomplete(self): + report = summarize([ + activity(8, 50), + activity(10, 0), + log(10, "thread dump (1 threads):"), + "thread 61 '': xcl.exe+0x1 < game.exe+0x2", + ], title_exe="game.exe") + self.assertIn("0/1 thread lines parsed, 0 with a visible title frame (incomplete dump)", report) + self.assertTrue(report.endswith("Sampled title-thread candidates: 0")) + if __name__ == "__main__": unittest.main() diff --git a/scripts/world_load_stall.py b/scripts/world_load_stall.py index 48670e4575..25cfb4008d 100644 --- a/scripts/world_load_stall.py +++ b/scripts/world_load_stall.py @@ -14,6 +14,9 @@ ) COMPILE_START = re.compile(r"D3D12\.X: driver compile start #(\d+): (.+?) PSO, (\d+) B DXIL") COMPILE_FINISH = re.compile(r"D3D12\.X: driver compile finish #(\d+): ") +THREAD_DUMP = re.compile(r"thread dump \((\d+) threads\):") +THREAD_ROW = re.compile(r"thread (\d+) '.*': (.*)") +MODULE_FRAME = re.compile(r"(.+)\+(0x[0-9a-f]+)", re.IGNORECASE) @dataclass(frozen=True) @@ -48,20 +51,73 @@ def event_count(times, start, end): return f"{len(in_window)} (first at {min(in_window):.3f} s)" if in_window else "0" -def summarize(lines): +def thread_dump_report(dumps, start, end, title_exe): + latest = max( + (dump for dump in reversed(dumps) if start < dump[0] <= end), + key=lambda dump: dump[0], + default=None, + ) + if latest is None: + return ["No timestamped thread dump in the sampled window."] + + time, expected, rows = latest + title_exe = title_exe.casefold() + visible_title = 0 + candidates = [] + for thread_id, stack in rows: + offsets = [] + for entry in stack.split(" < "): + frame = MODULE_FRAME.fullmatch(entry) + if not frame: + continue + module, offset = frame.groups() + module = module.casefold() + if module == title_exe: + visible_title += 1 + if offsets: + candidates.append(f" Thread {thread_id}: {' < '.join(offsets)}") + break + if module == "xcl.exe": + offsets.append(offset.lower()) + + completeness = " (incomplete dump)" if len(rows) < expected else "" + return [ + f"Thread dump at {time:.3f} s: {len(rows)}/{expected} thread lines parsed, " + f"{visible_title} with a visible title frame{completeness}", + f"Sampled title-thread candidates: {len(candidates)}", + *candidates, + ] + + +def summarize(lines, *, title_exe=None): samples = [] starts = {} finishes = {} bridges = [] releases = [] + dumps = [] + dump_rows = None stop = float("inf") for line in lines: match = LOG_LINE.match(line) if not match: + # The logger writes a dump header and its unprefixed rows as one record. + if dump_rows is not None: + row = THREAD_ROW.fullmatch(line.rstrip("\r\n")) if line.endswith("\n") else None + if row: + dump_rows.append(row.groups()) + if not row or len(dump_rows) == dumps[-1][1]: + dump_rows = None continue + dump_rows = None time = float(match[1]) message = match[2] - if activity := ACTIVITY.match(message): + if title_exe is not None and (header := THREAD_DUMP.fullmatch(message.rstrip("\r"))): + expected = int(header[1]) + rows = [] + dumps.append((time, expected, rows)) + dump_rows = rows if expected else None + elif activity := ACTIVITY.match(message): samples.append(Activity(time, *map(int, activity.groups()))) elif compile_start := COMPILE_START.match(message): starts[int(compile_start[1])] = Compile(time, compile_start[2], int(compile_start[3])) @@ -129,16 +185,21 @@ def summarize(lines): f"Logged wait-before-signal bridges: {event_count(bridges, start, end)}", f"Logged GPU wait watchdog releases: {event_count(releases, start, end)}", ]) + if title_exe is not None: + report.extend(thread_dump_report(dumps, start, end, title_exe)) return "\n".join(report) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("log", type=Path, help="path to one saved xcl.log") + parser.add_argument("--title-exe", metavar="NAME", help="title executable basename for thread dump analysis") args = parser.parse_args() + if args.title_exe is not None and not re.fullmatch(r"[^\\/:\r\n]+\.exe", args.title_exe, re.IGNORECASE): + parser.error("--title-exe requires an executable basename") try: with args.log.open(encoding="utf-8-sig", errors="replace") as log: - print(summarize(log)) + print(summarize(log, title_exe=args.title_exe)) except OSError as error: parser.error(str(error)) From 92e99a3f0bd935a63b6ff344bd558718325ba992 Mon Sep 17 00:00:00 2001 From: RavenCurseBurg <360931527+RavenCurseBurg@users.noreply.github.com> Date: Thu, 26 Nov 2026 15:42:31 +0800 Subject: [PATCH 3/3] Scripts: recognize renamed XCL hosts in saved thread dumps AI-assisted with OpenAI Codex (GPT-6) for implementation and Windows CPU checks. (cherry picked from commit 290f6404cd5856b2d675120760907463c2020542) --- README.md | 5 +++-- scripts/test_world_load_stall.py | 7 +++++++ scripts/world_load_stall.py | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9ded6962d8..5ec3204803 100644 --- a/README.md +++ b/README.md @@ -286,8 +286,9 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder use thread or queue diagnostics to determine what the title was waiting on. If the log includes dumps from `XCL_THREAD_DUMP_AT`, add `--title-exe MyTitle.exe` to inspect the latest dump after the last positive sample through the closing zero-present sample. The report - lists thread IDs and visible `xcl.exe` offsets above their first title frame. Use those sampled - candidates to investigate the pause. A short unwind can hide the title frame or XCL callers. + lists thread IDs and visible XCL offsets above their first title frame. The default host is + `xcl.exe`. If you renamed the executable, pass its basename with `--host-exe xcl-main.exe`. + Use those sampled candidates to investigate the pause. A short unwind can hide the title frame or XCL callers. - With `XCL_DRED=1`, a D3D12 device removal logs GPU breadcrumbs in `xcl.log`. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. For each, it names the translated diff --git a/scripts/test_world_load_stall.py b/scripts/test_world_load_stall.py index d4ba2d8013..233b2c34c8 100644 --- a/scripts/test_world_load_stall.py +++ b/scripts/test_world_load_stall.py @@ -119,6 +119,13 @@ def test_latest_dump_including_closing_sample_matches_windows_module_names(self) self.assertNotIn("Thread 21", report) self.assertEqual(summarize(lines), summarize([activity(8, 50), activity(10, 0), activity(12, 0)])) + def test_renamed_host_only_matches_that_module_above_the_title(self): + lines = [activity(8, 50), + *thread_dump(9, "thread 42 '': xcl.exe+0x1 < xcl-main.EXE+0x2 < game.exe+0x3 < xcl-main.exe+0x4"), + activity(10, 0)] + report = summarize(lines, title_exe="GAME.EXE", host_exe="XCL-MAIN.exe") + self.assertTrue(report.endswith(" Thread 42: 0x2")) + def test_ignores_dumps_at_opening_sample_outside_window_and_after_shutdown(self): report = summarize([ activity(8, 50), diff --git a/scripts/world_load_stall.py b/scripts/world_load_stall.py index 25cfb4008d..a4163263c3 100644 --- a/scripts/world_load_stall.py +++ b/scripts/world_load_stall.py @@ -17,6 +17,7 @@ THREAD_DUMP = re.compile(r"thread dump \((\d+) threads\):") THREAD_ROW = re.compile(r"thread (\d+) '.*': (.*)") MODULE_FRAME = re.compile(r"(.+)\+(0x[0-9a-f]+)", re.IGNORECASE) +DEFAULT_HOST_EXE = "xcl.exe" @dataclass(frozen=True) @@ -51,7 +52,7 @@ def event_count(times, start, end): return f"{len(in_window)} (first at {min(in_window):.3f} s)" if in_window else "0" -def thread_dump_report(dumps, start, end, title_exe): +def thread_dump_report(dumps, start, end, title_exe, host_exe=DEFAULT_HOST_EXE): latest = max( (dump for dump in reversed(dumps) if start < dump[0] <= end), key=lambda dump: dump[0], @@ -62,6 +63,7 @@ def thread_dump_report(dumps, start, end, title_exe): time, expected, rows = latest title_exe = title_exe.casefold() + host_exe = host_exe.casefold() visible_title = 0 candidates = [] for thread_id, stack in rows: @@ -77,7 +79,7 @@ def thread_dump_report(dumps, start, end, title_exe): if offsets: candidates.append(f" Thread {thread_id}: {' < '.join(offsets)}") break - if module == "xcl.exe": + if module == host_exe: offsets.append(offset.lower()) completeness = " (incomplete dump)" if len(rows) < expected else "" @@ -89,7 +91,7 @@ def thread_dump_report(dumps, start, end, title_exe): ] -def summarize(lines, *, title_exe=None): +def summarize(lines, *, title_exe=None, host_exe=DEFAULT_HOST_EXE): samples = [] starts = {} finishes = {} @@ -186,7 +188,7 @@ def summarize(lines, *, title_exe=None): f"Logged GPU wait watchdog releases: {event_count(releases, start, end)}", ]) if title_exe is not None: - report.extend(thread_dump_report(dumps, start, end, title_exe)) + report.extend(thread_dump_report(dumps, start, end, title_exe, host_exe)) return "\n".join(report) @@ -194,12 +196,15 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("log", type=Path, help="path to one saved xcl.log") parser.add_argument("--title-exe", metavar="NAME", help="title executable basename for thread dump analysis") + parser.add_argument("--host-exe", metavar="NAME", default=DEFAULT_HOST_EXE, + help="XCL executable basename for thread dump analysis (default: %(default)s)") args = parser.parse_args() - if args.title_exe is not None and not re.fullmatch(r"[^\\/:\r\n]+\.exe", args.title_exe, re.IGNORECASE): - parser.error("--title-exe requires an executable basename") + for flag, name in (("--title-exe", args.title_exe), ("--host-exe", args.host_exe)): + if name is not None and not re.fullmatch(r"[^\\/:\r\n]+\.exe", name, re.IGNORECASE): + parser.error(f"{flag} requires an executable basename") try: with args.log.open(encoding="utf-8-sig", errors="replace") as log: - print(summarize(log, title_exe=args.title_exe)) + print(summarize(log, title_exe=args.title_exe, host_exe=args.host_exe)) except OSError as error: parser.error(str(error))