A GPU task manager for Windows, Linux, and WSL: per-process VRAM, GPU activity, and LLM model/KV-cache insights (Windows AMD and NVIDIA).
Python
Merge main into PR 27
Scott Hanselmane10ac10c14f2
diff --cc src/gputaskman/app.pyindex b40450c,8e08827..8a857b9--- a/src/gputaskman/app.py+++ b/src/gputaskman/app.py@@@ -17,10 -17,10 +17,11 @@@ from textual.screen import ModalScreefrom textual.widgets import DataTable, Footer, Markdown, Select, Staticfrom textual.worker import get_current_worker+from .host import HostSample, HostSamplerfrom .collector import BACKEND, Collector, ProcRow, Snapshot, enumerate_adapters, ordered_adapters- from .llm import gb+ from .llm import gb, redact_cmdlinefrom .nvml import NvDevice, format_metric+ from .recovery import LiveCollectorsfrom .report import (DRM_RESIDENT_NOTE, METAL_NOTE, WSL_EMPTY, drm_note, has_engine_counters, has_spill_counters, has_wddm_counters,inferred_note, vram_label, wsl_note)@@@ -213,13 -211,8 +214,15 @@@ class GpuTaskManager(App)}CHARTS = tuple(CHART_COLORS)- def __init__(self, gpu_index: int | None = None, interval: float = 1.0, host: bool = True) -> None:+ def __init__(self, gpu_index: int | None = None, interval: float = 1.0, host: bool = True,+ system: bool = True) -> None:super().__init__()+ self.system = system+ self.host_sample: HostSample | None = None++ self.host_error: str | None = None++ self._sampler: HostSampler | None = None+ self.hist_cpu: deque = deque(maxlen=60)+ self.hist_ram: deque = deque(maxlen=60)self.gpu_index = gpu_indexself.interval = intervalself.host = host@@@ -287,6 -275,19 +290,21 @@@@work(thread=True, exclusive=True)def poll(self) -> None:worker = get_current_worker()++ self._sample_host() # the first reading only primes the CPU rates+ if BACKEND == "wddm":+ live = LiveCollectors(self.gpu_index, collector_factory=Collector, discover=enumerate_adapters)+ try:+ worker.cancelled_event.wait(0.5)+ while not worker.is_cancelled:+ if not self.paused:+ snapshots = live.sample()++ host = self._sample_host()+ if not worker.is_cancelled:- self.call_from_thread(self.apply_all, snapshots)++ self.call_from_thread(self.apply_all, snapshots, host)+ worker.cancelled_event.wait(self.interval)+ finally:+ live.close()+ returnindices = ([self.gpu_index] if self.gpu_index is not None elselist(range(len(ordered_adapters(enumerate_adapters())))) or [0])with ExitStack() as stack:@@@ -303,29 -303,25 +320,48 @@@while not worker.is_cancelled:if not self.paused:snapshots = [collector.sample() for collector in collectors]- host = hs.sample() if hs else None++ host = self._sample_host()if not worker.is_cancelled:- self.call_from_thread(self.apply_all, snapshots)+ self.call_from_thread(self.apply_all, snapshots, host)worker.cancelled_event.wait(self.interval)++ def _sample_host(self) -> HostSample | None:++ """The RAM/CPU panel is optional: a failed OS query shows its reason and never stops GPU sampling."""++ if not self.system:++ return None++ try:++ if self._sampler is None:++ self._sampler = HostSampler()++ host = self._sampler.sample()++ except Exception as error:++ self.host_error = f"{type(error).__name__}: {error}"++ return None++ self.host_error = None++ return host++# ------------------------------------------------------------------ renderingdef apply(self, snap: Snapshot) -> None:self.apply_all([snap])- def apply_all(self, snapshots: list[Snapshot]) -> None:+ def apply_all(self, snapshots: list[Snapshot], host: HostSample | None = None) -> None:if not self.is_running:return # A worker may finish sampling after shutdown has removed the widgets.- self.snapshots = snapshots+ if host is not None:+ self.host_sample = host+ self.hist_cpu.append(host.cpu_pct)+ self.hist_ram.append(100 * host.ram_used / host.ram_total if host.ram_total else None)+ for snap in snapshots:+ for row in snap.procs: # Windows (W:) / outside (H:) rows have no local pid: RAM/CPU stay unknown+ hp = self.host_sample.proc(row.pid) if self.host_sample and not row.host else None+ row.ram, row.cpu = (hp.rss, hp.cpu_pct) if hp else (None, None)multi = len(snapshots) > 1+ if self.snapshots and multi != (len(self.snapshots) > 1) and self.selected_key is not None:+ if multi:+ self.selected_key = f"0:{self.selected_key}"+ else:+ self.selected_key = self.selected_key[2:] if self.selected_key.startswith("0:") else None+ self.snapshots = snapshotstable = self.query_one("#procs", DataTable)if multi and "GPU" not in table.columns:table.add_column("GPU", key="GPU")