Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio debug logs: list log names instead of building a Path per file on each poll (#17302)

Daniel Han4d880f680385
diff --git a/studio/backend/tests/test_debug_log_sources.py b/studio/backend/tests/test_debug_log_sources.py
index e2f53f225e1..b018b442cb5 100644
--- a/studio/backend/tests/test_debug_log_sources.py
+++ b/studio/backend/tests/test_debug_log_sources.py
@@ -267,6 +267,30 @@ def test_a_huge_directory_does_not_stat_every_file(monkeypatch):
assert calls["n"] < 400, "cost still scales with the directory"
+def test_a_huge_directory_builds_paths_only_for_the_presort_slice(monkeypatch):
+ """The 1 Hz poll lists names instead of building a Path per directory entry."""
+ directory = _home() / "logs" / "llama-server"
+ directory.mkdir(parents = True, exist_ok = True)
+ for i in range(400):
+ (directory / f"llama-17660000{i:03d}-port-8080.log").write_text("x\n", encoding = "utf-8")
+ (directory / "LLAMA-1766999999-port-8080.log").write_text("x\n", encoding = "utf-8")
+ (directory / "notes.txt").write_text("x\n", encoding = "utf-8")
+
+ def _no_glob(self, *args, **kwargs):
+ raise AssertionError("glob builds a Path per directory entry")
+
+ monkeypatch.setattr(Path, "glob", _no_glob)
+ names = sorted(
+ (path.name for path in debug_log_sources._family_files("llama-server")), reverse = True
+ )
+ assert len(names) == debug_log_sources.MAX_SOURCES_PER_FAMILY
+ if os.name != "nt": # Case folds on Windows only, so LLAMA-... is newest there.
+ expected = sorted(
+ (f"llama-17660000{i:03d}-port-8080.log" for i in range(400)), reverse = True
+ )
+ assert names == expected[: debug_log_sources.MAX_SOURCES_PER_FAMILY]
+
+
def test_a_literal_tilde_home_is_scanned_both_ways(tmp_path, monkeypatch):
"""Runners may write to a literal ~ dir, so scan both spellings or llama logs vanish."""
monkeypatch.chdir(tmp_path)
diff --git a/studio/backend/utils/debug_log_sources.py b/studio/backend/utils/debug_log_sources.py
index c55dc2be85c..825507e72bf 100644
--- a/studio/backend/utils/debug_log_sources.py
+++ b/studio/backend/utils/debug_log_sources.py
@@ -114,12 +114,13 @@ def _family_files(family: str) -> list[Path]:
except OSError:
continue
try:
- entries = list(directory.glob(pattern))
+ # Names, not a Path per file; fnmatch.filter folds case exactly as glob does (Windows only).
+ names = fnmatch.filter(os.listdir(directory), pattern)
except OSError:
continue
# Nothing prunes logs/llama-server and one file is written per load ATTEMPT (11,794 on this host), so a filename presort, which tracks time order, leaves a handful to stat. Every family's filename embeds its creation time (server-YYYYmmdd-HHMMSS, llama-<epoch>, diffusion-<epoch>, desktop ms epoch), and realpath + stat on every file cost ~356ms at a 1 Hz poll.
- entries.sort(key = lambda entry: entry.name, reverse = True)
- entries = entries[: MAX_SOURCES_PER_FAMILY * 3]
+ names.sort(reverse = True)
+ entries = [directory / name for name in names[: MAX_SOURCES_PER_FAMILY * 3]]
for entry in entries:
try:
real = Path(os.path.realpath(entry))