gputaskman 0.3.2__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {gputaskman-0.3.2 → gputaskman-0.3.4}/PKG-INFO +73 -3
  2. {gputaskman-0.3.2 → gputaskman-0.3.4}/README.md +72 -2
  3. {gputaskman-0.3.2 → gputaskman-0.3.4}/pyproject.toml +1 -1
  4. {gputaskman-0.3.2 → gputaskman-0.3.4}/pyproject.toml.orig +1 -1
  5. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/app.py +174 -45
  6. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/cli.py +3 -3
  7. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/collector.py +36 -16
  8. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/dxgi.py +14 -4
  9. gputaskman-0.3.4/src/gputaskman/nvml.py +161 -0
  10. gputaskman-0.3.4/src/gputaskman/recovery.py +169 -0
  11. gputaskman-0.3.2/src/gputaskman/nvml.py +0 -105
  12. {gputaskman-0.3.2 → gputaskman-0.3.4}/LICENSE +0 -0
  13. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/__init__.py +0 -0
  14. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/__main__.py +0 -0
  15. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/adl.py +0 -0
  16. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/amdsmi.py +0 -0
  17. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/diff.py +0 -0
  18. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/drm.py +0 -0
  19. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/gguf.py +0 -0
  20. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/handy.py +0 -0
  21. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/linux.py +0 -0
  22. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/llm.py +0 -0
  23. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/macos.py +0 -0
  24. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/pdh.py +0 -0
  25. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/procinfo.py +0 -0
  26. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/report.py +0 -0
  27. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/stores.py +0 -0
  28. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/telemetry.py +0 -0
  29. {gputaskman-0.3.2 → gputaskman-0.3.4}/src/gputaskman/wslhost.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gputaskman
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: An htop for what's inside your GPU: per-process VRAM, engine load, and LLM weights / KV cache breakdown
5
5
  Author: Scott Hanselman
6
6
  License-Expression: MIT
@@ -44,12 +44,33 @@ CPU-only, NPU-only, and cloud workloads are out of scope.
44
44
  > Early, experimental software. Device and process counters are measurements; classifications
45
45
  > and GGUF-derived breakdowns are estimates. This does not dump VRAM or enumerate a game's textures.
46
46
 
47
+ ## Install from PyPI
48
+
49
+ [gputaskman is on PyPI](https://pypi.org/project/gputaskman/). No repository clone is needed:
50
+
51
+ ```powershell
52
+ uv tool install gputaskman
53
+ gputaskman
54
+ ```
55
+
56
+ Or, with [pipx](https://pipx.pypa.io/):
57
+
58
+ ```powershell
59
+ pipx install gputaskman
60
+ gputaskman
61
+ ```
62
+
63
+ Works on Windows, Linux/WSL, and macOS with Python 3.11+ and the supported GPU/driver
64
+ configuration described below. Both installers keep the app in an isolated environment.
65
+ The shorter `gtm` command is also available. Upgrade with `uv tool upgrade gputaskman`
66
+ or `pipx upgrade gputaskman`. For Windows without Python, use the portable download below.
67
+
47
68
  ## Portable Windows download
48
69
 
49
70
  The [Releases page](https://github.com/shanselman/gputaskman/releases) is where tagged builds
50
71
  publish two portable ZIPs: `gputaskman-VERSION-windows-x64.zip` for Intel/AMD Windows PCs, and
51
72
  `gputaskman-VERSION-windows-arm64.zip` for native Windows ARM64. These are separate native builds,
52
- not a universal executable. If no release is published yet, use the source instructions below.
73
+ not a universal executable.
53
74
 
54
75
  Extract the **entire ZIP**, keeping `_internal` beside `gputaskman.exe`. Open Windows Terminal
55
76
  or PowerShell in the extracted folder:
@@ -407,12 +428,22 @@ uv run --locked gputaskman --help
407
428
  | `s` | Cycle sort: VRAM, GPU%, spill, paged, name |
408
429
  | `c` | Cycle all charts or a single metric (also available in the **Charts** dropdown) |
409
430
  | `a` | Switch between top and all collected processes |
431
+ | `m` | Toggle full diagnostics / slim monitoring |
410
432
  | `p` | Pause / resume collection |
411
433
  | `?` | Explain the counters and their limits |
412
434
  | Escape | Close help |
413
435
  | `q` | Quit |
414
436
 
415
437
  A wide terminal (roughly 140 columns or more) makes the full table easier to read.
438
+ The TUI starts in **Full diagnostics** mode. Press `m` (or click **Slim/Full** in the
439
+ footer) for **Slim monitoring**: each GPU header hides driver/CUDA versions, PCI bus
440
+ address, driver model, PCIe generation/width, compute capability, power/clock limits,
441
+ performance state, and secondary memory/video clocks. GPU identity, memory bars and
442
+ provenance/availability warnings, utilization, PCIe throughput, temperature, current power
443
+ and SM/GFX clock, throttling alerts, charts, processes, and process inspection remain.
444
+ The header border names the active mode; press `m` again to restore the full details.
445
+ This is a session-only display toggle, applies to every GPU, and does not change collection
446
+ or one-shot text/JSON output.
416
447
  All eight history charts are shown by default: GPU, SM clock (GFX clock on AMD), VRAM, memory activity,
417
448
  temperature, power, encoder, and decoder. They stack in narrow terminals and share rows as
418
449
  the window widens. Click the **Charts** dropdown to focus on one metric or return to **All charts**.
@@ -421,12 +452,49 @@ scale, temperature uses 0–120°C, and the power and clock scales are displayed
421
452
  The dashboard and inspector scroll independently in short terminals so the process list stays usable.
422
453
  Model/runtime discovery is throttled, so newly loaded models may take about 15 seconds to appear.
423
454
 
455
+ On multi-GPU systems, the TUI stacks a header and trend charts for each GPU and adds a **GPU**
456
+ column to the combined process list. A process using two GPUs has a separate row for each;
457
+ selecting a row inspects its memory on that GPU. Single-GPU layouts are unchanged.
458
+ Memory totals and histories stay separate per device; model files and runtime buffer logs
459
+ can span devices and do not prove per-device model placement. Discovery's 150 ms scan budget
460
+ is divided across GPUs, though each GPU has its own counter and telemetry queries.
461
+ This layout is covered by synthetic tests, **not yet validated on multi-GPU hardware**.
462
+ On Windows, the live TUI checks DXGI adapter topology every five seconds in the existing
463
+ sampling worker (or on the next sample with a longer interval). Removed adapters retain their
464
+ session GPU number with unavailable readings; surviving adapters keep their collectors and
465
+ histories, and newly discovered adapters are appended. Re-enabling an adapter rebuilds its
466
+ providers. LUIDs identify adapters; if a LUID changes, only a unique PCI location **and**
467
+ matching vendor/description can reconnect the old slot. Without that evidence, the old slot
468
+ remains unavailable rather than transferring its history or process ownership to another GPU.
469
+ `--gpu N` pins the adapter selected at startup, not whichever adapter later occupies index N;
470
+ it does not start monitoring other newly discovered devices. Session GPU numbers therefore
471
+ need not match a fresh `--list-gpus` after a topology change.
472
+ NVML handles are reacquired at the same low-frequency cadence; missing counters, lost telemetry
473
+ or sampling errors trigger provider reconstruction at the next successful discovery. Persistent
474
+ failures back off to at most one reconstruction per minute; a reappearing or changed adapter retries immediately.
475
+ Discovery errors retain the last known topology with a warning, not invented zero usage.
476
+ Pausing suspends discovery as well as sampling; resume performs an overdue check.
477
+ This recovery is covered by mocks, **not validated with hardware disable/re-enable** on the
478
+ reporter's hybrid AMD/NVIDIA laptop. On a three-GPU desktop (RTX 5060 Ti, RTX 3060, AMD iGPU;
479
+ Windows 11 build 26200, NVIDIA driver 610.88), disabling and re-enabling the RTX 3060 recovered
480
+ its slot, history, VRAM and processes, but NVML reads for that GPU then faulted inside `nvml.dll`
481
+ and `nvmlShutdown()` hung on exit. A fresh process read it normally. gputaskman therefore stops
482
+ reading NVML for a GPU whose reads fault, shows "restart gputaskman to restore it", and skips
483
+ `nvmlShutdown()` once an NVIDIA adapter has gone away (process exit releases the session). That
484
+ mitigation is covered by mocks and not yet validated on that hardware. It is not a claim of
485
+ physical hot-swap support.
486
+ Other backends and one-shot output retain startup-only discovery.
487
+ Under multi-GPU WSL, host attribution is disabled with a reason rather than risking matching
488
+ two devices by memory usage; Linux processes are listed once with GPU `?`, because `/dev/dxg`
489
+ does not identify their GPU. `--gpu N` retains the existing single-device host matching.
490
+
424
491
  `--list-gpus` lists selectable hardware adapters with their vendor and LUID. `--gpu N` selects
425
492
  one of these adapters: NVIDIA adapters are listed first, followed by other vendors, with each
426
493
  group ordered by dedicated memory. An out-of-range
427
494
  index is rejected rather than silently selecting another device. Compute-only devices such as an
428
495
  NPU are not graphics adapters. AMD and NVIDIA hardware coverage is described below; configurations
429
- with multiple GPUs and mixed vendors need further validation.
496
+ with multiple GPUs and mixed vendors need further hardware validation. `--once` and `--json`
497
+ still default to GPU 0; use `--gpu N` to collect another device without changing the snapshot format.
430
498
  Device telemetry is matched to WDDM adapters by PCI location, not display name or enumeration order.
431
499
  If a unique match cannot be established, telemetry is unavailable; buffer logs can still span devices,
432
500
  so model-buffer attribution across GPUs is not yet reliable. This conservative matching also applies
@@ -627,6 +695,8 @@ Identification is designed to stay cheap. Measured on one Windows machine:
627
695
  | Probe | Cost | Used |
628
696
  |---|---|---|
629
697
  | Process list, command line, listening ports | under 1 ms | Once per process / every 5 s |
698
+ | Windows adapter discovery (DXGI + PCI location, no telemetry sample) | ~0.40 ms median; first/cold call up to 14.1 ms in 30 reads (Windows 11 build 26340, RTX 4080 SUPER, NVIDIA 630.20) | TUI only, every 5 s; synchronous OS calls, not a hard latency bound. Other drivers/multi-GPU laptops unmeasured; provider reconstruction after changes/errors has additional driver-dependent cost |
699
+ | Windows NVML handle reacquisition (no telemetry sample) | ~8.7 ms median, 9.3 ms max in 30 reads on the same machine | Every 5 s per active collector; retries initialization after NVML session-loss errors. Other drivers unmeasured |
630
700
  | Memory-map scan (DLLs + mapped files) | 1-50 ms per process | New processes, a 64 MiB / 10% memory change, or every 2 min; at most 150 ms per refresh |
631
701
  | GGUF header, model-store manifests | ms, cached | Once per file / every 60 s |
632
702
  | Local API probes | ms, local only | llama-server `/v1/models` only when its model path changes |
@@ -22,12 +22,33 @@ CPU-only, NPU-only, and cloud workloads are out of scope.
22
22
  > Early, experimental software. Device and process counters are measurements; classifications
23
23
  > and GGUF-derived breakdowns are estimates. This does not dump VRAM or enumerate a game's textures.
24
24
 
25
+ ## Install from PyPI
26
+
27
+ [gputaskman is on PyPI](https://pypi.org/project/gputaskman/). No repository clone is needed:
28
+
29
+ ```powershell
30
+ uv tool install gputaskman
31
+ gputaskman
32
+ ```
33
+
34
+ Or, with [pipx](https://pipx.pypa.io/):
35
+
36
+ ```powershell
37
+ pipx install gputaskman
38
+ gputaskman
39
+ ```
40
+
41
+ Works on Windows, Linux/WSL, and macOS with Python 3.11+ and the supported GPU/driver
42
+ configuration described below. Both installers keep the app in an isolated environment.
43
+ The shorter `gtm` command is also available. Upgrade with `uv tool upgrade gputaskman`
44
+ or `pipx upgrade gputaskman`. For Windows without Python, use the portable download below.
45
+
25
46
  ## Portable Windows download
26
47
 
27
48
  The [Releases page](https://github.com/shanselman/gputaskman/releases) is where tagged builds
28
49
  publish two portable ZIPs: `gputaskman-VERSION-windows-x64.zip` for Intel/AMD Windows PCs, and
29
50
  `gputaskman-VERSION-windows-arm64.zip` for native Windows ARM64. These are separate native builds,
30
- not a universal executable. If no release is published yet, use the source instructions below.
51
+ not a universal executable.
31
52
 
32
53
  Extract the **entire ZIP**, keeping `_internal` beside `gputaskman.exe`. Open Windows Terminal
33
54
  or PowerShell in the extracted folder:
@@ -385,12 +406,22 @@ uv run --locked gputaskman --help
385
406
  | `s` | Cycle sort: VRAM, GPU%, spill, paged, name |
386
407
  | `c` | Cycle all charts or a single metric (also available in the **Charts** dropdown) |
387
408
  | `a` | Switch between top and all collected processes |
409
+ | `m` | Toggle full diagnostics / slim monitoring |
388
410
  | `p` | Pause / resume collection |
389
411
  | `?` | Explain the counters and their limits |
390
412
  | Escape | Close help |
391
413
  | `q` | Quit |
392
414
 
393
415
  A wide terminal (roughly 140 columns or more) makes the full table easier to read.
416
+ The TUI starts in **Full diagnostics** mode. Press `m` (or click **Slim/Full** in the
417
+ footer) for **Slim monitoring**: each GPU header hides driver/CUDA versions, PCI bus
418
+ address, driver model, PCIe generation/width, compute capability, power/clock limits,
419
+ performance state, and secondary memory/video clocks. GPU identity, memory bars and
420
+ provenance/availability warnings, utilization, PCIe throughput, temperature, current power
421
+ and SM/GFX clock, throttling alerts, charts, processes, and process inspection remain.
422
+ The header border names the active mode; press `m` again to restore the full details.
423
+ This is a session-only display toggle, applies to every GPU, and does not change collection
424
+ or one-shot text/JSON output.
394
425
  All eight history charts are shown by default: GPU, SM clock (GFX clock on AMD), VRAM, memory activity,
395
426
  temperature, power, encoder, and decoder. They stack in narrow terminals and share rows as
396
427
  the window widens. Click the **Charts** dropdown to focus on one metric or return to **All charts**.
@@ -399,12 +430,49 @@ scale, temperature uses 0–120°C, and the power and clock scales are displayed
399
430
  The dashboard and inspector scroll independently in short terminals so the process list stays usable.
400
431
  Model/runtime discovery is throttled, so newly loaded models may take about 15 seconds to appear.
401
432
 
433
+ On multi-GPU systems, the TUI stacks a header and trend charts for each GPU and adds a **GPU**
434
+ column to the combined process list. A process using two GPUs has a separate row for each;
435
+ selecting a row inspects its memory on that GPU. Single-GPU layouts are unchanged.
436
+ Memory totals and histories stay separate per device; model files and runtime buffer logs
437
+ can span devices and do not prove per-device model placement. Discovery's 150 ms scan budget
438
+ is divided across GPUs, though each GPU has its own counter and telemetry queries.
439
+ This layout is covered by synthetic tests, **not yet validated on multi-GPU hardware**.
440
+ On Windows, the live TUI checks DXGI adapter topology every five seconds in the existing
441
+ sampling worker (or on the next sample with a longer interval). Removed adapters retain their
442
+ session GPU number with unavailable readings; surviving adapters keep their collectors and
443
+ histories, and newly discovered adapters are appended. Re-enabling an adapter rebuilds its
444
+ providers. LUIDs identify adapters; if a LUID changes, only a unique PCI location **and**
445
+ matching vendor/description can reconnect the old slot. Without that evidence, the old slot
446
+ remains unavailable rather than transferring its history or process ownership to another GPU.
447
+ `--gpu N` pins the adapter selected at startup, not whichever adapter later occupies index N;
448
+ it does not start monitoring other newly discovered devices. Session GPU numbers therefore
449
+ need not match a fresh `--list-gpus` after a topology change.
450
+ NVML handles are reacquired at the same low-frequency cadence; missing counters, lost telemetry
451
+ or sampling errors trigger provider reconstruction at the next successful discovery. Persistent
452
+ failures back off to at most one reconstruction per minute; a reappearing or changed adapter retries immediately.
453
+ Discovery errors retain the last known topology with a warning, not invented zero usage.
454
+ Pausing suspends discovery as well as sampling; resume performs an overdue check.
455
+ This recovery is covered by mocks, **not validated with hardware disable/re-enable** on the
456
+ reporter's hybrid AMD/NVIDIA laptop. On a three-GPU desktop (RTX 5060 Ti, RTX 3060, AMD iGPU;
457
+ Windows 11 build 26200, NVIDIA driver 610.88), disabling and re-enabling the RTX 3060 recovered
458
+ its slot, history, VRAM and processes, but NVML reads for that GPU then faulted inside `nvml.dll`
459
+ and `nvmlShutdown()` hung on exit. A fresh process read it normally. gputaskman therefore stops
460
+ reading NVML for a GPU whose reads fault, shows "restart gputaskman to restore it", and skips
461
+ `nvmlShutdown()` once an NVIDIA adapter has gone away (process exit releases the session). That
462
+ mitigation is covered by mocks and not yet validated on that hardware. It is not a claim of
463
+ physical hot-swap support.
464
+ Other backends and one-shot output retain startup-only discovery.
465
+ Under multi-GPU WSL, host attribution is disabled with a reason rather than risking matching
466
+ two devices by memory usage; Linux processes are listed once with GPU `?`, because `/dev/dxg`
467
+ does not identify their GPU. `--gpu N` retains the existing single-device host matching.
468
+
402
469
  `--list-gpus` lists selectable hardware adapters with their vendor and LUID. `--gpu N` selects
403
470
  one of these adapters: NVIDIA adapters are listed first, followed by other vendors, with each
404
471
  group ordered by dedicated memory. An out-of-range
405
472
  index is rejected rather than silently selecting another device. Compute-only devices such as an
406
473
  NPU are not graphics adapters. AMD and NVIDIA hardware coverage is described below; configurations
407
- with multiple GPUs and mixed vendors need further validation.
474
+ with multiple GPUs and mixed vendors need further hardware validation. `--once` and `--json`
475
+ still default to GPU 0; use `--gpu N` to collect another device without changing the snapshot format.
408
476
  Device telemetry is matched to WDDM adapters by PCI location, not display name or enumeration order.
409
477
  If a unique match cannot be established, telemetry is unavailable; buffer logs can still span devices,
410
478
  so model-buffer attribution across GPUs is not yet reliable. This conservative matching also applies
@@ -605,6 +673,8 @@ Identification is designed to stay cheap. Measured on one Windows machine:
605
673
  | Probe | Cost | Used |
606
674
  |---|---|---|
607
675
  | Process list, command line, listening ports | under 1 ms | Once per process / every 5 s |
676
+ | Windows adapter discovery (DXGI + PCI location, no telemetry sample) | ~0.40 ms median; first/cold call up to 14.1 ms in 30 reads (Windows 11 build 26340, RTX 4080 SUPER, NVIDIA 630.20) | TUI only, every 5 s; synchronous OS calls, not a hard latency bound. Other drivers/multi-GPU laptops unmeasured; provider reconstruction after changes/errors has additional driver-dependent cost |
677
+ | Windows NVML handle reacquisition (no telemetry sample) | ~8.7 ms median, 9.3 ms max in 30 reads on the same machine | Every 5 s per active collector; retries initialization after NVML session-loss errors. Other drivers unmeasured |
608
678
  | Memory-map scan (DLLs + mapped files) | 1-50 ms per process | New processes, a 64 MiB / 10% memory change, or every 2 min; at most 150 ms per refresh |
609
679
  | GGUF header, model-store manifests | ms, cached | Once per file / every 60 s |
610
680
  | Local API probes | ms, local only | llama-server `/v1/models` only when its model path changes |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gputaskman"
3
- version = "0.3.2"
3
+ version = "0.3.4"
4
4
  description = "An htop for what's inside your GPU: per-process VRAM, engine load, and LLM weights / KV cache breakdown"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gputaskman"
3
- version = "0.3.2"
3
+ version = "0.3.4"
4
4
  description = "An htop for what's inside your GPU: per-process VRAM, engine load, and LLM weights / KV cache breakdown"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -3,8 +3,8 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
- import time
7
6
  from collections import deque
7
+ from contextlib import ExitStack
8
8
 
9
9
  from rich.console import Group
10
10
  from rich.table import Table
@@ -17,9 +17,10 @@ from textual.screen import ModalScreen
17
17
  from textual.widgets import DataTable, Footer, Markdown, Select, Static
18
18
  from textual.worker import get_current_worker
19
19
 
20
- from .collector import BACKEND, Collector, ProcRow, Snapshot
20
+ from .collector import BACKEND, Collector, ProcRow, Snapshot, enumerate_adapters, ordered_adapters
21
21
  from .llm import gb
22
22
  from .nvml import NvDevice, format_metric
23
+ from .recovery import LiveCollectors
23
24
  from .report import (DRM_RESIDENT_NOTE, METAL_NOTE, WSL_EMPTY, drm_note, has_engine_counters, has_spill_counters, has_wddm_counters,
24
25
  inferred_note, vram_label, wsl_note)
25
26
 
@@ -58,6 +59,11 @@ EXPLAIN = {
58
59
  HELP_MD = """\
59
60
  # What can be known about GPU memory?
60
61
 
62
+ Press **m** (or click **Slim/Full** in the footer) to switch between full diagnostics
63
+ and slim monitoring. Slim hides hardware identifiers and secondary telemetry details;
64
+ live readings, charts, processes, inspection, and provenance/availability warnings stay visible.
65
+ This display-only choice applies to all GPUs and resets to full when the app restarts.
66
+
61
67
  | Layer | Source | Works for |
62
68
  |---|---|---|
63
69
  | **Device** telemetry | NVML, AMD ADL, or optional AMD SMI; amdgpu sysfs on Linux | availability varies by GPU and driver |
@@ -174,6 +180,7 @@ class GpuTaskManager(App):
174
180
  #chart-controls { height: 1; }
175
181
  #chart-label { width: 8; text-style: bold; }
176
182
  #chart-mode { width: 24; }
183
+ #chart-mode SelectOverlay { border: solid $accent; padding: 0 1; }
177
184
  #chart-hint { width: 1fr; color: $text-muted; }
178
185
  #charts { height: auto; }
179
186
  #chart-note { height: auto; color: $text-muted; }
@@ -185,6 +192,7 @@ class GpuTaskManager(App):
185
192
  Binding("s", "cycle_sort", "Sort"),
186
193
  Binding("c", "cycle_chart", "Chart"),
187
194
  Binding("a", "toggle_all", "All/Top"),
195
+ Binding("m", "toggle_monitoring", "Slim/Full"),
188
196
  Binding("p", "pause", "Pause"),
189
197
  Binding("question_mark", "help", "Explain"),
190
198
  ]
@@ -203,16 +211,20 @@ class GpuTaskManager(App):
203
211
  }
204
212
  CHARTS = tuple(CHART_COLORS)
205
213
 
206
- def __init__(self, gpu_index: int = 0, interval: float = 1.0, host: bool = True) -> None:
214
+ def __init__(self, gpu_index: int | None = None, interval: float = 1.0, host: bool = True) -> None:
207
215
  super().__init__()
208
216
  self.gpu_index = gpu_index
209
217
  self.interval = interval
210
218
  self.host = host
211
219
  self.snap: Snapshot | None = None
220
+ self.snapshots: list[Snapshot] = []
221
+ self._histories: dict[int, dict[str, deque]] = {}
222
+ self._row_snapshots: dict[str, Snapshot] = {}
212
223
  self.selected_key: str | None = None # ProcRow.key: Linux and Windows host PIDs can collide
213
224
  self.sort_idx = 0
214
225
  self.show_all = False
215
226
  self.paused = False
227
+ self.monitoring = False
216
228
  self.hist_util: deque = deque(maxlen=60)
217
229
  self.hist_clock: deque = deque(maxlen=60)
218
230
  self.hist_bw: deque = deque(maxlen=60)
@@ -228,7 +240,8 @@ class GpuTaskManager(App):
228
240
  def selected_pid(self) -> int | None:
229
241
  """PID of the selected local process; None for Windows (W:) and outside (H:) rows."""
230
242
  key = self.selected_key
231
- return int(key) if key and key.isdigit() else None
243
+ pid = key.rsplit(":", 1)[-1] if key else ""
244
+ return int(pid) if pid.isdigit() else None
232
245
 
233
246
  @selected_pid.setter
234
247
  def selected_pid(self, pid: int | None) -> None:
@@ -262,31 +275,88 @@ class GpuTaskManager(App):
262
275
  @work(thread=True, exclusive=True)
263
276
  def poll(self) -> None:
264
277
  worker = get_current_worker()
265
- collector = Collector(self.gpu_index, host=self.host)
266
- time.sleep(0.5)
267
- try:
278
+ if BACKEND == "wddm":
279
+ live = LiveCollectors(self.gpu_index, collector_factory=Collector, discover=enumerate_adapters)
280
+ try:
281
+ worker.cancelled_event.wait(0.5)
282
+ while not worker.is_cancelled:
283
+ if not self.paused:
284
+ snapshots = live.sample()
285
+ if not worker.is_cancelled:
286
+ self.call_from_thread(self.apply_all, snapshots)
287
+ worker.cancelled_event.wait(self.interval)
288
+ finally:
289
+ live.close()
290
+ return
291
+ indices = ([self.gpu_index] if self.gpu_index is not None else
292
+ list(range(len(ordered_adapters(enumerate_adapters())))) or [0])
293
+ with ExitStack() as stack:
294
+ collectors = []
295
+ for index in indices:
296
+ collector = Collector(index, scan_budget=Collector.SCAN_BUDGET / len(indices),
297
+ host=self.host and not (BACKEND == "wsl" and len(indices) > 1))
298
+ if BACKEND == "wsl" and len(indices) > 1 and self.host:
299
+ collector.host_status = "off (multi-GPU WSL host matching is not validated; use --gpu N)"
300
+ stack.callback(collector.close)
301
+ collectors.append(collector)
302
+ worker.cancelled_event.wait(0.5)
268
303
  while not worker.is_cancelled:
269
304
  if not self.paused:
270
- snap = collector.sample()
271
- self.call_from_thread(self.apply, snap)
272
- time.sleep(self.interval)
273
- finally:
274
- collector.close()
305
+ snapshots = [collector.sample() for collector in collectors]
306
+ if not worker.is_cancelled:
307
+ self.call_from_thread(self.apply_all, snapshots)
308
+ worker.cancelled_event.wait(self.interval)
275
309
 
276
310
  # ------------------------------------------------------------------ rendering
277
311
 
278
312
  def apply(self, snap: Snapshot) -> None:
313
+ self.apply_all([snap])
314
+
315
+ def apply_all(self, snapshots: list[Snapshot]) -> None:
316
+ if not self.is_running:
317
+ return # A worker may finish sampling after shutdown has removed the widgets.
318
+ multi = len(snapshots) > 1
319
+ if self.snapshots and multi != (len(self.snapshots) > 1) and self.selected_key is not None:
320
+ if multi:
321
+ self.selected_key = f"0:{self.selected_key}"
322
+ else:
323
+ self.selected_key = self.selected_key[2:] if self.selected_key.startswith("0:") else None
324
+ self.snapshots = snapshots
325
+ table = self.query_one("#procs", DataTable)
326
+ if multi and "GPU" not in table.columns:
327
+ table.add_column("GPU", key="GPU")
328
+ elif not multi and "GPU" in table.columns:
329
+ table.remove_column("GPU")
330
+ self._row_snapshots = {}
331
+ for index, snap in enumerate(snapshots):
332
+ for row in snap.procs:
333
+ row.gpu_index = index if multi else None
334
+ self._row_snapshots[row.key] = snap
335
+ self._use_history(index)
336
+ self._record_sample(snap)
337
+ self._use_history(0)
338
+ self.snap = snapshots[0]
339
+ if not self._auto_selected:
340
+ llm = next((r for r in sorted(
341
+ (r for s in snapshots for r in s.procs), key=self.SORTS[0][1]) if r.llm), None)
342
+ if llm:
343
+ self.selected_key = llm.key
344
+ self._auto_selected = True
345
+ self.render_dashboard()
346
+ self.render_table(self.snap)
347
+ self.render_inspector()
348
+
349
+ def _use_history(self, index: int) -> None:
350
+ names = ("util", "clock", "bw", "vram", "temp", "power", "enc", "dec")
351
+ if index not in self._histories:
352
+ self._histories[index] = {name: deque(maxlen=60) for name in names}
353
+ for name, history in self._histories[index].items():
354
+ setattr(self, f"hist_{name}", history)
355
+
356
+ def _record_sample(self, snap: Snapshot) -> None:
279
357
  self.snap = snap
280
358
  nv = snap.nv
281
359
  amd = bool(snap.adapter and snap.adapter.vendor_id == 0x1002)
282
- if getattr(self, "_amd_chart_labels", None) != amd:
283
- self._amd_chart_labels = amd
284
- selector = self.query_one("#chart-mode", Select)
285
- selected = selector.value
286
- selector.set_options([("All charts", -1), *(
287
- ("GFX clock" if amd and self.CHARTS[index] == "SM clock" else self.CHARTS[index], index)
288
- for index in self.available_charts)]) # macOS offers only the charts IOKit has data for
289
- selector.value = selected
290
360
  if nv:
291
361
  self.hist_util.append(nv.util_gpu)
292
362
  self.hist_clock.append(nv.gfx_clock if amd else nv.sm_clock)
@@ -301,20 +371,36 @@ class GpuTaskManager(App):
301
371
  history.append(None)
302
372
  self.hist_vram.append(100 * snap.vram_used / snap.vram_total
303
373
  if snap.vram_total and snap.vram_used is not None else None)
304
- if not self._auto_selected:
305
- llm = next((r for r in sorted(snap.procs, key=self.SORTS[0][1]) if r.llm), None)
306
- if llm:
307
- self.selected_key = llm.key
308
- self._auto_selected = True
309
- self.query_one("#device", Static).update(self.render_device(snap))
374
+
375
+ def render_dashboard(self) -> None:
376
+ amd = bool(self.snapshots[0].adapter and self.snapshots[0].adapter.vendor_id == 0x1002)
377
+ clock_label = "SM/GFX clock" if len(self.snapshots) > 1 else "GFX clock" if amd else "SM clock"
378
+ if getattr(self, "_clock_label", None) != clock_label:
379
+ self._clock_label = clock_label
380
+ selector = self.query_one("#chart-mode", Select)
381
+ selected = selector.value
382
+ selector.set_options([("All charts", -1), *(
383
+ (clock_label if self.CHARTS[index] == "SM clock" else self.CHARTS[index], index)
384
+ for index in self.available_charts)])
385
+ selector.value = selected
386
+ self._amd_chart_labels = amd
387
+ devices = []
388
+ for index, snap in enumerate(self.snapshots):
389
+ if len(self.snapshots) > 1:
390
+ devices.append(Text(f"GPU {index}", style="bold"))
391
+ devices.append(self.render_device(snap))
392
+ device = self.query_one("#device", Static)
393
+ device.border_title = "Slim monitoring" if self.monitoring else "Full diagnostics"
394
+ device.update(
395
+ Group(*devices) if len(self.snapshots) > 1 else devices[0])
310
396
  self.render_charts()
311
- self.render_table(snap)
312
- self.render_inspector()
313
397
 
314
398
  def render_device(self, s: Snapshot) -> Group:
315
399
  nv = s.nv
316
400
  name = s.adapter.name if s.adapter else (nv.name if nv else "GPU")
317
- if s.backend == "metal":
401
+ if self.monitoring:
402
+ head = Text(name, style="bold")
403
+ elif s.backend == "metal":
318
404
  head = Text.assemble((name, "bold"), f" {s.driver} ", ("Metal", "bold yellow"), " unified memory")
319
405
  else:
320
406
  info = (f" driver {s.driver}" if s.driver else "") + (f" CUDA {s.cuda}" if s.cuda else "")
@@ -380,12 +466,19 @@ class GpuTaskManager(App):
380
466
  clock_label = (f"gfx {format_metric(nv.gfx_clock)} MHz" if nv.source.startswith("AMD ") else
381
467
  f"SM {format_metric(nv.sm_clock)}/{format_metric(nv.sm_clock_max)} MHz")
382
468
  power_kind = f" {nv.power_kind}" if nv.power_kind else ""
383
- st = Text(f"{format_metric(nv.temp, unit='°C')} {format_metric(nv.power_w, '.0f')}/"
384
- f"{format_metric(nv.power_limit_w, '.0f')} W{power_kind} {pstate} "
385
- f"{clock_label} "
386
- f"mem {format_metric(nv.mem_clock)} MHz video {format_metric(nv.video_clock)} MHz "
387
- f"PCIe gen{format_metric(nv.pcie_gen)} x{format_metric(nv.pcie_width)} "
388
- + (f"CC {nv.compute_cap or 'N/A'}" if nv.source == "NVML" else nv.source), style="grey70")
469
+ if self.monitoring:
470
+ clock = nv.gfx_clock if nv.source.startswith("AMD ") else nv.sm_clock
471
+ label = "gfx" if nv.source.startswith("AMD ") else "SM"
472
+ st = Text(f"{format_metric(nv.temp, unit='°C')} "
473
+ f"{format_metric(nv.power_w, '.0f')} W{power_kind} "
474
+ f"{label} {format_metric(clock)} MHz", style="grey70")
475
+ else:
476
+ st = Text(f"{format_metric(nv.temp, unit='°C')} {format_metric(nv.power_w, '.0f')}/"
477
+ f"{format_metric(nv.power_limit_w, '.0f')} W{power_kind} {pstate} "
478
+ f"{clock_label} "
479
+ f"mem {format_metric(nv.mem_clock)} MHz video {format_metric(nv.video_clock)} MHz "
480
+ f"PCIe gen{format_metric(nv.pcie_gen)} x{format_metric(nv.pcie_width)} "
481
+ + (f"CC {nv.compute_cap or 'N/A'}" if nv.source == "NVML" else nv.source), style="grey70")
389
482
  if nv.throttle:
390
483
  st.append(" throttle: " + ",".join(nv.throttle), style="yellow")
391
484
  lines.append(st)
@@ -415,9 +508,28 @@ class GpuTaskManager(App):
415
508
  return self.hist_dec, 100, "%", color
416
509
 
417
510
  def render_charts(self) -> None:
418
- if self.snap is None:
511
+ if len(self.snapshots) > 1:
512
+ charts = []
513
+ notes = []
514
+ for index, snap in enumerate(self.snapshots):
515
+ self.snap = snap
516
+ self._use_history(index)
517
+ self._amd_chart_labels = bool(snap.adapter and snap.adapter.vendor_id == 0x1002)
518
+ grid, note = self._chart_content()
519
+ charts.extend([Text(f"GPU {index}", style="bold"), grid])
520
+ notes.append(f"GPU {index}: {note}")
521
+ self.query_one("#charts", Static).update(Group(*charts))
522
+ self.query_one("#chart-note", Static).update("\n".join(notes))
523
+ self.snap = self.snapshots[0]
524
+ self._use_history(0)
525
+ self._amd_chart_labels = bool(self.snap.adapter and self.snap.adapter.vendor_id == 0x1002)
419
526
  return
420
- widget = self.query_one("#charts", Static)
527
+ if self.snap is not None:
528
+ grid, note = self._chart_content()
529
+ self.query_one("#charts", Static).update(grid)
530
+ self.query_one("#chart-note", Static).update(note)
531
+
532
+ def _chart_content(self) -> tuple[Table, str]:
421
533
  # Reserve the border, padding, and scrollbar even before child resize events arrive.
422
534
  width = max(1, self.size.width - 6)
423
535
  indices = list(self.available_charts) if self.chart_idx == -1 else [self.chart_idx]
@@ -439,19 +551,18 @@ class GpuTaskManager(App):
439
551
  cells.append(cell)
440
552
  for start in range(0, len(cells), columns):
441
553
  grid.add_row(*cells[start:start + columns])
442
- widget.update(grid)
443
554
  _, power_scale, _, _ = self.chart_series(self.CHARTS.index("Power"), self.snap.nv)
444
555
  _, clock_scale, _, _ = self.chart_series(self.CHARTS.index("SM clock"), self.snap.nv)
445
- self.query_one("#chart-note", Static).update(
556
+ note = (
446
557
  "Recent samples · blank = no reading" if self.snap.backend == "metal" else
447
558
  f"Recent samples · blank = no reading · power 0–{power_scale:.0f} W · "
448
559
  f"{'GFX' if getattr(self, '_amd_chart_labels', False) else 'SM'} clock 0–{clock_scale:.0f} MHz"
449
560
  )
561
+ return grid, note
450
562
 
451
563
  def on_resize(self) -> None:
452
564
  if self.is_mounted and self.snap is not None:
453
- self.query_one("#device", Static).update(self.render_device(self.snap))
454
- self.call_after_refresh(self.render_charts)
565
+ self.call_after_refresh(self.render_dashboard)
455
566
 
456
567
  def visible_rows(self, s: Snapshot) -> list[ProcRow]:
457
568
  rows = s.procs
@@ -470,7 +581,12 @@ class GpuTaskManager(App):
470
581
 
471
582
  def render_table(self, s: Snapshot) -> None:
472
583
  t = self.query_one("#procs", DataTable)
473
- rows = self.visible_rows(s)
584
+ rows = [r for snap in self.snapshots for r in self.visible_rows(snap)] if len(self.snapshots) > 1 else self.visible_rows(s)
585
+ if len(self.snapshots) > 1:
586
+ rows = [r for r in rows if not (
587
+ self._row_snapshots[r.key].backend == "wsl" and not r.host and r.gpu_index != 0)]
588
+ if len(self.snapshots) > 1 and not any(snap.backend == "wsl" for snap in self.snapshots):
589
+ rows.sort(key=self.SORTS[self.sort_idx][1])
474
590
  keep = self.selected_key
475
591
  t.clear()
476
592
 
@@ -480,6 +596,7 @@ class GpuTaskManager(App):
480
596
  return Text(f"{v:.0f}" if v >= 0.5 else "", justify="right", style="bold" if v >= 20 else "")
481
597
 
482
598
  for r in rows:
599
+ s = self._row_snapshots.get(r.key, s)
483
600
  e = r.gpu.engines
484
601
  wddm = has_wddm_counters(s, r)
485
602
  engines = has_engine_counters(s, r)
@@ -503,6 +620,8 @@ class GpuTaskManager(App):
503
620
  pct(e.get("copy", 0) if split else None),
504
621
  pct(e.get("decode", 0) + e.get("encode", 0) + e.get("video", 0) if split else None),
505
622
  Text(r.inside, style="magenta" if r.llm else "grey62", overflow="ellipsis", no_wrap=True),
623
+ *([Text("?" if s.backend == "wsl" and not r.host else str(r.gpu_index))]
624
+ if len(self.snapshots) > 1 else []),
506
625
  key=r.key,
507
626
  )
508
627
  if keep is not None:
@@ -516,13 +635,15 @@ class GpuTaskManager(App):
516
635
 
517
636
  def render_inspector(self) -> None:
518
637
  panel = self.query_one("#inspector", Static)
519
- s = self.snap
638
+ s = self._row_snapshots.get(self.selected_key, self.snap)
520
639
  r = next((x for x in s.procs if x.key == self.selected_key), None) if s else None
521
640
  if r is None:
522
641
  panel.update(Text("Select a process (↑/↓) to see what's inside its GPU memory. Press ? to learn what's knowable.", style="grey62"))
523
642
  return
524
643
  where = {"windows": "Windows PID ", "outside": "host PID "}.get(r.origin, "") if r.host else ""
525
644
  panel.border_title = f"{r.name} ({where}{r.pid}) - {r.kind}"
645
+ if r.gpu_index is not None:
646
+ panel.border_title += " - GPU unknown" if s.backend == "wsl" and not r.host else f" - GPU {r.gpu_index}"
526
647
  out: list = []
527
648
  e = r.gpu.engines
528
649
  wddm = has_wddm_counters(s, r)
@@ -571,6 +692,9 @@ class GpuTaskManager(App):
571
692
 
572
693
  v = r.llm
573
694
  if v:
695
+ if r.gpu_index is not None:
696
+ out.append(Text("Model files, launch flags and runtime buffer logs can span GPUs. "
697
+ "The breakdown below is not a measured per-device model placement.", style="grey70"))
574
698
  width = max(min(self.size.width - 8, 100), 20)
575
699
  total = max(r.gpu.shown_vram or 0, sum(x.bytes for x in v.segments), 1)
576
700
  out.append(stacked_bar([(x.bytes, SEG_STYLE[x.kind]) for x in v.segments], total, width))
@@ -635,7 +759,7 @@ class GpuTaskManager(App):
635
759
  # ------------------------------------------------------------------ events/actions
636
760
 
637
761
  def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None:
638
- if event.row_key is not None and event.row_key.value is not None:
762
+ if self.is_running and event.row_key is not None and event.row_key.value is not None:
639
763
  self.selected_key = str(event.row_key.value)
640
764
  self.render_inspector()
641
765
 
@@ -669,7 +793,12 @@ class GpuTaskManager(App):
669
793
  def action_pause(self) -> None:
670
794
  self.paused = not self.paused
671
795
  if self.snap:
672
- self.query_one("#device", Static).update(self.render_device(self.snap))
796
+ self.render_dashboard()
797
+
798
+ def action_toggle_monitoring(self) -> None:
799
+ self.monitoring = not self.monitoring
800
+ if self.snap:
801
+ self.render_dashboard()
673
802
 
674
803
  def action_help(self) -> None:
675
804
  self.push_screen(HelpScreen())