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 (AMD support, v0.3.0) into macos
Sameh Khamisb413bc0d2c1a
diff --cc AGENTS.mdindex 081bdd4,6e0b4d6..e8d4c07--- a/AGENTS.md+++ b/AGENTS.md@@@ -120,6 -118,6 +120,7 @@@ run builds artifacts without publishing## Known limits-Validated live: Windows 11 with an RTX 4080 SUPER (WDDM, plus WSL2), and a Linux container with an-RTX 3060 Ti. Not yet validated on hardware: bare-metal Linux, multi-GPU systems, and GPU-backed-WinML on Copilot+ PCs. Planned work is listed under **Next** in the README.+Validated live: Windows 11 with an RTX 4080 SUPER (WDDM, plus WSL2), a Linux container with an- RTX 3060 Ti, and macOS 26.3.1 on an M4 Mac mini (Metal; own-user processes, not run as root). Not yet validated on hardware: bare-metal Linux, multi-GPU systems, and GPU-backed- WinML on Copilot+ PCs. Planned work is listed under **Next** in the README.++RTX 3060 Ti, and macOS 26.3.1 on an M4 Mac mini (Metal; own-user processes, not run as root).++Not yet validated on hardware: bare-metal Linux, multi-GPU systems, and GPU-backed WinML on++Copilot+ PCs. Planned work is listed under **Next** in the README.diff --cc README.mdindex f8dca05,0febc78..7297bf7--- a/README.md+++ b/README.md@@@ -2,8 -2,7 +2,8 @@@**An `htop` for what's inside your GPU, not just how full it is.**- Windows + NVIDIA, with Linux and WSL support (see [Linux and WSL](#linux-and-wsl)) and macOS on Apple- Silicon (see [macOS](#macos-apple-silicon)). A terminal UI-Windows + NVIDIA/AMD, with NVIDIA support on Linux and WSL (see [Linux and WSL](#linux-and-wsl)). A terminal UI++Windows + NVIDIA/AMD, with NVIDIA support on Linux and WSL (see [Linux and WSL](#linux-and-wsl)) and++macOS on Apple Silicon (see [macOS](#macos-apple-silicon)). A terminal UIthat connects per-process GPU memory and engine activity with loaded runtimes, model files, andLLM buffer breakdowns.@@@ -576,8 -558,8 +598,9 @@@ downloads are bundled in this repositor| `pdh.py` / `dxgi.py` | Windows counters and adapter enumeration || `linux.py` | Linux backend: NVML adapters and per-process usage, container PID matching, WSL detection, `/dev/dxg` holders || `wslhost.py` | WSL: interop check, Windows host counter stream, adapter pairing, context matching |+| `macos.py` | macOS backend: IOKit device stats and per-process GPU time, `footprint` GPU memory poller, libproc memory maps || `nvml.py` | NVIDIA device readings |+ | `adl.py`, `amdsmi.py` | Optional AMD device readings || `procinfo.py` | Runtime, mapped-file, and process discovery || `stores.py` | Friendly names from Ollama, LM Studio, and Hugging Face model stores || `gguf.py` | Model metadata, kind, and size estimates |diff --cc src/gputaskman/app.pyindex 934224a,94d5609..74cade3--- a/src/gputaskman/app.py+++ b/src/gputaskman/app.py@@@ -269,9 -267,17 +270,18 @@@ class GpuTaskManager(App)def apply(self, snap: Snapshot) -> None:self.snap = snapnv = snap.nv+ amd = bool(snap.adapter and snap.adapter.vendor_id == 0x1002)+ if getattr(self, "_amd_chart_labels", None) != amd:+ self._amd_chart_labels = amd+ selector = self.query_one("#chart-mode", Select)+ selected = selector.value- selector.set_options([("All charts", -1), *(("GFX clock" if amd and name == "SM clock" else name, index)- for index, name in enumerate(self.CHARTS))])++ selector.set_options([("All charts", -1), *(++ ("GFX clock" if amd and self.CHARTS[index] == "SM clock" else self.CHARTS[index], index)++ for index in self.available_charts)]) # macOS offers only the charts IOKit has data for+ selector.value = selectedif nv:self.hist_util.append(nv.util_gpu)- self.hist_clock.append(nv.sm_clock)+ self.hist_clock.append(nv.gfx_clock if amd else nv.sm_clock)self.hist_bw.append(nv.util_mem)self.hist_temp.append(nv.temp)self.hist_power.append(nv.power_w)@@@ -295,11 -302,9 +306,12 @@@def render_device(self, s: Snapshot) -> Group:nv = s.nvname = s.adapter.name if s.adapter else (nv.name if nv else "GPU")- info = (f" driver {s.driver}" if s.driver else "") + (f" CUDA {s.cuda}" if s.cuda else "")- head = Text.assemble((name, "bold"), info + " ",- (nv.driver_model if nv else "", "bold yellow"), f" {nv.pci_bus if nv else ''}")+ if s.backend == "metal":+ head = Text.assemble((name, "bold"), f" {s.driver} ", ("Metal", "bold yellow"), " unified memory")+ else:- head = Text.assemble((name, "bold"), f" driver {s.driver} CUDA {s.cuda} ",++ info = (f" driver {s.driver}" if s.driver else "") + (f" CUDA {s.cuda}" if s.cuda else "")++ head = Text.assemble((name, "bold"), info + " ",+ (nv.driver_model if nv else "", "bold yellow"), f" {nv.pci_bus if nv else ''}")if self.paused:head.append(" [PAUSED]", style="bold red")@@@ -309,15 -314,16 +321,16 @@@if r.gpu.attributed: # unknown shares stay in "unattributed" instead of showing as 0by_kind[r.kind] = by_kind.get(r.kind, 0) + r.gpu.dedicatedattributed = sum(by_kind.values())- scale = min(1.0, s.vram_used / attributed) if attributed else 1.0+ scale = min(1.0, s.vram_used / attributed) if attributed and s.vram_used is not None else 1.0order = sorted(by_kind.items(), key=lambda kv: -kv[1])- parts = [(v * scale, KIND_STYLE.get(k, "white")) for k, v in order]- other = max(s.vram_used - attributed * scale, 0)+ parts = [(v * scale, KIND_STYLE.get(k, "white")) for k, v in order] if s.vram_used is not None else []+ other = max(s.vram_used - attributed * scale, 0) if s.vram_used is not None else 0parts.append((other, "grey35"))width = max(min(self.size.width - 40, 90), 20)- vram = Text("VRAM ")+ vram = Text("GPU mem " if s.backend == "metal" else "VRAM ")vram.append_text(stacked_bar(parts, s.vram_total, width))- vram.append(f" {gb(s.vram_used)} / {gb(s.vram_total)}", style="bold")+ used_label = gb(s.vram_used) if s.vram_used is not None else "N/A"+ vram.append(f" {used_label} / {gb(s.vram_total)}", style="bold")legend = Text(" ")for k, v in order[:7]:legend.append("■ ", style=KIND_STYLE.get(k, "white"))@@@ -410,9 -419,8 +431,9 @@@_, power_scale, _, _ = self.chart_series(self.CHARTS.index("Power"), self.snap.nv)_, clock_scale, _, _ = self.chart_series(self.CHARTS.index("SM clock"), self.snap.nv)self.query_one("#chart-note", Static).update(+ "Recent samples · blank = no reading" if self.snap.backend == "metal" elsef"Recent samples · blank = no reading · power 0–{power_scale:.0f} W · "- f"SM clock 0–{clock_scale:.0f} MHz"+ f"{'GFX' if getattr(self, '_amd_chart_labels', False) else 'SM'} clock 0–{clock_scale:.0f} MHz")def on_resize(self) -> None:diff --cc src/gputaskman/cli.pyindex 959d9ca,182691d..2ce4aa2--- a/src/gputaskman/cli.py+++ b/src/gputaskman/cli.py@@@ -22,9 -23,16 +23,16 @@@ def main() -> Noneif not math.isfinite(args.interval) or args.interval <= 0:ap.error("--interval must be a finite number greater than zero")- if sys.platform != "win32" and not sys.platform.startswith("linux"):- sys.exit("gputaskman supports Windows (WDDM) and Linux/WSL (NVML) only.")+ if sys.platform not in ("win32", "darwin") and not sys.platform.startswith("linux"):+ sys.exit("gputaskman supports Windows (WDDM), Linux/WSL (NVML) and macOS (Apple Silicon) only.")+ if args.list_gpus:+ from .collector import enumerate_adapters, ordered_adapters++ for i, adapter in enumerate(ordered_adapters(enumerate_adapters())):+ print(f"{i}: {adapter.name} ({adapter.vendor}, LUID 0x{adapter.luid & 0xffffffffffffffff:016x})")+ return+if args.gpu:from .collector import enumerate_adapters, select_adapterdiff --cc src/gputaskman/collector.pyindex b9a39d9,fef6b9f..5fe2f5e--- a/src/gputaskman/collector.py+++ b/src/gputaskman/collector.py@@@ -105,10 -103,10 +108,10 @@@ class Snapshotdriver: strcuda: strvram_total: int- vram_used: int # adapter-wide dedicated usage (WDDM counters, or NVML on Linux): the ground truth- shared_used: int+ vram_used: int | None # WDDM adapter-wide dedicated usage+ shared_used: int | Noneprocs: list[ProcRow] = field(default_factory=list)- backend: str = "wddm" # wddm (Windows) | nvml (native Linux) | wsl (device-wide only)+ backend: str = "wddm" # wddm (Windows) | nvml (native Linux) | wsl (device-wide only) | metal (macOS)host_status: str = "" # WSL only: Windows host counters via interop -- ok | starting | off (...) | ...wsl_split: str = "" # WSL only: why Linux rows have no (inferred) VRAM, when they don't@@@ -160,7 -172,8 +178,9 @@@ class Collectorself.adapter = select_adapter(self.adapters, gpu_index)self.counters = GpuCounters()self.nvml = Nvml()+ self.amdsmi = AmdSmi(self.adapter, self.adapters)+ self.adl = Adl(self.adapter, self.adapters)+ self._mac_driver = f"macOS {macos_version()}".strip() if BACKEND == "metal" else ""self.inspector = ProcInspector()self.prober = ServerProber()self.scan_budget = scan_budget # None = scan every candidate now (one-shot output)@@@ -200,18 -213,18 +220,22 @@@luid = self.adapter.luid if self.adapter else (next(iter(per_luid), 0))procs = per_luid.get(luid, {})a = adapters.get(luid)- nvs = self.nvml.sample() if self.nvml.ok else []- nv = select_nv_device(self.adapter, nvs, self.gpu_index, self.adapters)- if self.adapter and self.adapter.vendor_id == 0x1002:- nv = self.adl.sample() or self.amdsmi.sample()+ if BACKEND == "metal":+ nv = self.counters.device # IOKit's device stats in the shape the header renders (no NVML on macOS)+ else:+ nvs = self.nvml.sample() if self.nvml.ok else []- nv = select_nv_device(self.adapter, nvs, self.gpu_index)++ nv = select_nv_device(self.adapter, nvs, self.gpu_index, self.adapters)++ if self.adapter and self.adapter.vendor_id == 0x1002:++ nv = self.adl.sample() or self.amdsmi.sample()total = (nv.mem_total if nv else 0) or (self.adapter.dedicated_vram if self.adapter else 0)snap = Snapshot(taken=time.time(), adapter=self.adapter, adapters=self.adapters, nv=nv,- driver=self._mac_driver or self.nvml.driver, cuda=self.nvml.cuda_version, vram_total=total,- vram_used=int(a.dedicated) if a else (nv.mem_used if nv else 0),- shared_used=int(a.shared) if a else 0, backend=BACKEND,- driver=(self.amdsmi.driver if nv and nv.source == "AMD SMI" else self.nvml.driver if nv and nv.source == "NVML" else ""),++ driver=self._mac_driver or (self.amdsmi.driver if nv and nv.source == "AMD SMI"++ else self.nvml.driver if nv and nv.source == "NVML" else ""),+ cuda=self.nvml.cuda_version if nv and nv.source == "NVML" else "", vram_total=total,+ vram_used=int(a.dedicated) if a and a.dedicated is not None else None,+ shared_used=int(a.shared) if a and a.shared is not None else None, backend=BACKEND,)snap.host_status = self.host_statusdiff --cc src/gputaskman/macos.pyindex 0571324,0000000..536c1ccmode 100644,000000..100644--- a/src/gputaskman/macos.py+++ b/src/gputaskman/macos.py@@@ -1,386 -1,0 +1,386 @@@+"""macOS GPU backend (Apple Silicon): device stats and per-process GPU time from IOKit, GPU memory from footprint.++Apple GPUs share one pool of memory with the CPU (unified memory), so there is no VRAM to divide up and no+spill/commit counters. What macOS does expose without root:++- Device-wide: the IOAccelerator's PerformanceStatistics -- "Device Utilization %" and "Alloc system memory"+ (GPU allocations across all processes).+- Per process, for every user: each Metal client (AGXDeviceUserClient) names its creator PID and keeps a+ cumulative accumulatedGPUTime in ns. GPU% is the change between two samples.+- Per process, own processes only: footprint(1) reports the process's memory charged to graphics (Metal+ buffers and textures) -- the "(graphics)" categories. Other users' processes (WindowServer, daemons) need+ root, so their GPU memory is unknown, never zero.++Measured on an M4 Mac mini (macOS 26.3): a PyTorch MPS job with a 2 GiB buffer showed 2.01 GiB (2062 MiB) of graphics+footprint, GPU time matched Device Utilization (98% vs 99%), and Alloc system memory rose by the same amount.+"""++from __future__ import annotations++import ctypes+import json+import os+import plistlib+import re+import subprocess+import tempfile+import threading+import time+from collections import defaultdict+from dataclasses import dataclass++from .dxgi import Adapter+from .nvml import NvDevice+from .pdh import AdapterGpu, ProcGpu++VENDOR_APPLE = 0x106B+ADAPTER_KEY = 1 # one integrated GPU+_CREATOR = re.compile(r"pid (\d+)")+# Other users' processes show only GPU time; keep the idle ones out of the table (except the compositor).+ALWAYS_SHOWN = {"windowserver"}+++def _ioreg(*args: str) -> list | None:+ try:+ out = subprocess.run(["ioreg", "-a", "-w", "0", "-r", *args], capture_output=True, timeout=5).stdout+ return plistlib.loads(out) if out.strip() else []+ except (OSError, subprocess.SubprocessError, plistlib.InvalidFileException, ValueError):+ return None+++@dataclass+class DeviceStats:+ model: str = "Apple GPU"+ cores: int | None = None+ utilization: float | None = None # Device Utilization %+ renderer: float | None = None+ tiler: float | None = None+ allocated: int = 0 # Alloc system memory: GPU allocations, all processes+++def parse_accelerator(entries: list | None) -> DeviceStats | None:+ for e in entries or []:+ stats = e.get("PerformanceStatistics")+ if not isinstance(stats, dict):+ continue+ return DeviceStats(model=str(e.get("model", "Apple GPU")), cores=e.get("gpu-core-count"),+ utilization=stats.get("Device Utilization %"),+ renderer=stats.get("Renderer Utilization %"), tiler=stats.get("Tiler Utilization %"),+ allocated=int(stats.get("Alloc system memory", 0)))+ return None+++def parse_clients(entries: list | None) -> dict[int, dict[int, int]]:+ """{pid: {client id: accumulated GPU ns}}. Rates are taken per client: a closed client takes its+ accumulated time with it, so per-process sums would drop and hide real work."""+ out: dict[int, dict[int, int]] = defaultdict(dict)+ for i, e in enumerate(entries or []):+ m = _CREATOR.match(str(e.get("IOUserClientCreator", "")))+ if not m:+ continue+ cid = e.get("IORegistryEntryID", -1 - i)+ out[int(m[1])][cid] = sum(int(u.get("accumulatedGPUTime", 0))+ for u in e.get("AppUsage") or [] if isinstance(u, dict))+ return dict(out)+++def graphics_bytes(process: dict) -> int:+ """footprint JSON: dirty bytes of the categories macOS charges to graphics."""+ return int(sum(v.get("dirty", 0) for k, v in (process.get("categories") or {}).items() if k.endswith("(graphics)")))+++def physical_memory() -> int:+ try:+ return os.sysconf("SC_PHYS_PAGES") * os.sysconf("SC_PAGE_SIZE")+ except (ValueError, OSError, AttributeError): # no os.sysconf on Windows+ return 0+++def macos_version() -> str:+ try:+ return subprocess.run(["sw_vers", "-productVersion"], capture_output=True, text=True, timeout=5).stdout.strip()+ except (OSError, subprocess.SubprocessError):+ return ""+++def enumerate_adapters() -> list[Adapter]:+ dev = parse_accelerator(_ioreg("-d", "1", "-c", "IOAccelerator"))+ if dev is None:+ return []+ return [Adapter(luid=ADAPTER_KEY, name=dev.model, vendor_id=VENDOR_APPLE, dedicated_vram=physical_memory(),+ shared_system=0, software=False)]+++def _owner(pid: int) -> int | None:+ try:+ import psutil+ return psutil.Process(pid).uids().real+ except Exception:+ return None+++def _identity(pid: int) -> float | None:+ """Process start time: tells a reused PID from the process that had it before."""+ try:+ import psutil+ return psutil.Process(pid).create_time()+ except Exception:+ return None+++class FootprintPoller:+ """footprint(1) takes ~70 ms per process, too slow for the refresh loop, so a background thread measures+ the targets: busy or not-yet-measured processes every pass (~2 s), idle ones every 30 s. Results are tied+ to a process identity (PID + start time), so a measurement never lands on a reused PID."""++ CYCLE = 2.0 # seconds between passes+ IDLE_EVERY = 30.0 # re-measure idle processes this often+ FAIL_LIMIT = 3 # consecutive failures before backing off (one timeout under load is not "denied")+ FAIL_RETRY = 60.0++ def __init__(self, run=subprocess.run, clock=time.monotonic) -> None:+ self._run = run+ self._clock = clock+ self._targets: dict[int, tuple[object, bool]] = {} # pid -> (identity, busy), busiest first+ self._sizes: dict[int, tuple[object, int]] = {} # pid -> (identity, graphics bytes)+ self._due: dict[int, float] = {}+ self._fails: dict[int, int] = {}+ self._retry: dict[int, float] = {}+ self._lock = threading.Lock()+ self._wake = threading.Event()+ self._passed = threading.Event() # set after each completed pass+ self._stop = False+ self._thread: threading.Thread | None = None++ def start(self) -> None:+ if self._thread is None:+ self._thread = threading.Thread(target=self._loop, name="macos-footprint", daemon=True)+ self._thread.start()++ def set_targets(self, targets: list[tuple[int, object, bool]]) -> None:+ """[(pid, identity, busy)], busiest first. Anything else, or a PID whose identity changed, is forgotten."""+ with self._lock:+ self._targets = {pid: (ident, busy) for pid, ident, busy in targets}+ for store in (self._sizes, self._due, self._fails, self._retry):+ for pid in list(store):+ if pid not in self._targets:+ del store[pid]+ for pid, (ident, _) in self._targets.items():+ if pid in self._sizes and self._sizes[pid][0] != ident: # reused PID+ for store in (self._sizes, self._due, self._fails, self._retry):+ store.pop(pid, None)+ self._wake.set()++ def get(self, pid: int, identity: object = None) -> int | None:+ with self._lock:+ hit = self._sizes.get(pid)+ return hit[1] if hit and hit[0] == identity else None++ def measure(self, pid: int) -> int | None:+ with tempfile.TemporaryDirectory() as d:+ path = os.path.join(d, "fp.json")+ try:+ self._run(["footprint", "-f", "bytes", "-j", path, "-p", str(pid)],+ capture_output=True, timeout=10)+ with open(path, encoding="utf-8") as f:+ data = json.load(f)+ except (OSError, subprocess.SubprocessError, ValueError):+ return None+ for p in data.get("processes") or []:+ if p.get("pid") == pid:+ return graphics_bytes(p)+ return None++ def poll_once(self) -> None:+ with self._lock:+ targets = list(self._targets.items())+ for pid, (ident, busy) in targets:+ if self._stop:+ return+ now = self._clock()+ with self._lock:+ if self._retry.get(pid, 0) > now:+ continue+ if not busy and pid in self._sizes and self._due.get(pid, 0) > now:+ continue+ size = self.measure(pid)+ with self._lock:+ if self._targets.get(pid, (None,))[0] != ident:+ continue # exited or reused while footprint ran: don't resurrect it+ if size is None:+ self._fails[pid] = self._fails.get(pid, 0) + 1+ if self._fails[pid] >= self.FAIL_LIMIT: # other user's process, or footprint keeps failing+ self._retry[pid] = now + self.FAIL_RETRY+ self._sizes.pop(pid, None)+ else:+ self._sizes[pid] = (ident, size)+ self._fails.pop(pid, None)+ self._due[pid] = now + self.IDLE_EVERY++ def wait_pass(self, timeout: float) -> bool:+ self._passed.clear()+ return self._passed.wait(timeout)++ def _loop(self) -> None:+ while not self._stop:+ start = self._clock()+ self.poll_once()+ self._passed.set()+ self._wake.wait(max(self.CYCLE - (self._clock() - start), 0.2))+ self._wake.clear()++ def close(self) -> None:+ self._stop = True+ self._wake.set()+++class MacCounters:+ """Same interface as pdh.GpuCounters: sample() -> ({adapter key: {pid: ProcGpu}}, {adapter key: AdapterGpu}).+ `device` carries the device-wide stats in the NvDevice shape the header already renders."""++ def __init__(self, poller: FootprintPoller | None = None, uid: int | None = None, root: bool | None = None,+ identity=_identity, owner=_owner) -> None:+ self.ok = True+ self.device: NvDevice | None = None+ self._uid = os.getuid() if uid is None else uid+ # As root footprint can read every process, so every process is measurable (not only uid 0's).+ self._root = (os.geteuid() == 0) if root is None else root+ self._identity, self._owner = identity, owner+ self._prev: dict[int, tuple[object, dict[int, int]]] = {} # pid -> (identity, {client id: ns})+ self._last: float | None = None # monotonic time of the previous sample+ self._owners: dict[int, int | None] = {}+ self._names: dict[int, str] = {}+ self.poller = poller or FootprintPoller()+ self.poller.start()+ self.sample() # baseline: GPU% is a rate, like the WDDM counters' first collection++ def warm_up(self, timeout: float) -> None:+ """One-shot output: wait for a full footprint pass so own processes have their GPU memory."""+ self.poller.wait_pass(timeout)++ def _name(self, pid: int) -> str:+ if pid not in self._names:+ try:+ import psutil+ self._names[pid] = psutil.Process(pid).name()+ except Exception:+ self._names[pid] = ""+ return self._names[pid]++ def sample(self, accel: list | None = None, clients: list | None = None,+ now: float | None = None) -> tuple[dict[int, dict[int, ProcGpu]], dict[int, AdapterGpu]]:+ now = time.monotonic() if now is None else now # a rate: immune to wall-clock adjustments+ accel = _ioreg("-d", "1", "-c", "IOAccelerator") if accel is None else accel+ clients = _ioreg("-l", "-c", "AGXDeviceUserClient") if clients is None else clients+ procs: dict[int, dict[int, ProcGpu]] = defaultdict(dict)+ adapters: dict[int, AdapterGpu] = defaultdict(AdapterGpu)+ dev = parse_accelerator(accel)+ if dev is None:+ self.device = None # no reading this time: never keep showing the last one as current+ else:+ adapters[ADAPTER_KEY].dedicated = float(dev.allocated)+ self.device = NvDevice(index=0, name=dev.model, driver_model="Metal", mem_total=physical_memory(),- mem_used=dev.allocated, util_gpu=dev.utilization)++ mem_used=dev.allocated, util_gpu=dev.utilization, source="IOKit")+ per_pid = parse_clients(clients)+ elapsed = now - self._last if self._last is not None else None+ targets: list[tuple[float, int, object]] = []+ current: dict[int, tuple[object, dict[int, int]]] = {}+ for pid, times in per_pid.items():+ ident = self._identity(pid)+ prev = self._prev.get(pid)+ if prev is None or prev[0] != ident:+ prev_times = {}+ self._owners.pop(pid, None) # new or reused PID: re-read its owner and name+ self._names.pop(pid, None)+ else:+ prev_times = prev[1]+ current[pid] = (ident, times)+ pct = 0.0+ if elapsed and elapsed > 0:+ # A client that appeared since the last sample did all of its work in this interval.+ busy_ns = sum(max(ns - prev_times.get(cid, 0), 0) for cid, ns in times.items())+ pct = min(busy_ns / 1e9 / elapsed * 100.0, 100.0)+ if pid not in self._owners:+ self._owners[pid] = self._owner(pid)+ mine = self._root or self._owners[pid] == self._uid+ g = ProcGpu()+ if pct:+ g.engines["gpu"] = pct+ if mine:+ targets.append((pct, pid, ident))+ size = self.poller.get(pid, ident)+ if size is None:+ g.attributed = False # not measured yet (or footprint failed): unknown, not zero+ else:+ g.dedicated = float(size)+ else:+ g.attributed = False # footprint needs root for other users' processes+ if pct < 0.5 and self._name(pid).lower() not in ALWAYS_SHOWN:+ continue+ procs[ADAPTER_KEY][pid] = g+ self._prev, self._last = current, now+ self._owners = {p: o for p, o in self._owners.items() if p in per_pid}+ self._names = {p: n for p, n in self._names.items() if p in per_pid}+ targets.sort(key=lambda t: -t[0])+ self.poller.set_targets([(pid, ident, pct >= 0.5) for pct, pid, ident in targets])+ return procs, adapters++ def close(self) -> None:+ self.poller.close()+++# ---------------------------------------------------------------- memory maps (psutil has none on macOS)++PROC_PIDREGIONINFO = 7+++class _RegionInfo(ctypes.Structure): # struct proc_regioninfo, <sys/proc_info.h>+ _fields_ = [(n, ctypes.c_uint32) for n in ("protection", "max_protection", "inheritance", "flags")] + [+ ("offset", ctypes.c_uint64)] + [(n, ctypes.c_uint32) for n in (+ "behavior", "user_wired_count", "user_tag", "pages_resident", "pages_shared_now_private",+ "pages_swapped_out", "pages_dirtied", "ref_count", "shadow_depth", "share_mode",+ "private_pages_resident", "shared_pages_resident", "obj_id", "depth")] + [+ ("address", ctypes.c_uint64), ("size", ctypes.c_uint64)]+++@dataclass+class MappedFile:+ path: str+ rss: int+++_libproc = None+++def _load_libproc():+ global _libproc+ if _libproc is None:+ lib = ctypes.CDLL("/usr/lib/libproc.dylib", use_errno=True)+ lib.proc_pidinfo.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_int]+ lib.proc_regionfilename.argtypes = [ctypes.c_int, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_uint32]+ _libproc = lib+ return _libproc+++def memory_maps(pid: int, max_regions: int = 200_000) -> list[MappedFile]:+ """File-backed regions of a process, grouped by path (like psutil's memory_maps(grouped=True)). Walks the+ address space with proc_pidinfo(PROC_PIDREGIONINFO) -- ~4 ms for a desktop app. Raises PermissionError+ for processes this user can't inspect."""+ lib = _load_libproc()+ info, buf = _RegionInfo(), ctypes.create_string_buffer(4096)+ page = os.sysconf("SC_PAGE_SIZE") # macOS only+ files: dict[str, int] = {}+ addr, n = 0, 0+ while n < max_regions:+ if lib.proc_pidinfo(pid, PROC_PIDREGIONINFO, addr, ctypes.byref(info), ctypes.sizeof(info)) != ctypes.sizeof(info):+ break+ n += 1+ if lib.proc_regionfilename(pid, info.address, buf, len(buf)) > 0:+ path = buf.value.decode("utf-8", "replace")+ files[path] = files.get(path, 0) + info.pages_resident * page+ if info.size == 0:+ break+ addr = info.address + info.size+ if n == 0:+ raise PermissionError(f"cannot read the address space of pid {pid}")+ return [MappedFile(p, rss) for p, rss in files.items()]diff --cc src/gputaskman/procinfo.pyindex 72b6f41,b64922b..c3d09d7--- a/src/gputaskman/procinfo.py+++ b/src/gputaskman/procinfo.py@@@ -14,17 -14,17 +14,18 @@@ import psutifrom .gguf import is_gguf, read_gguffrom .stores import store_name-# (tag, library patterns: Windows DLLs and Linux shared objects with the version suffix removed, see-# _lib_name). Order = display priority (most specific first).+# (tag, library patterns: Windows DLLs, Linux shared objects with the version suffix removed, and macOS+# dylibs, see _lib_name). Order = display priority (most specific first).RUNTIMES: list[tuple[str, tuple[str, ...]]] = [- ("llama.cpp", ("llama.dll", "libllama*.dll", "llama-*.dll", "llm_engine*", "libllama*.so")),- ("whisper.cpp", ("whisper*.dll", "libwhisper*.so")),- ("ggml", ("ggml*.dll", "libggml*.so")),- ("PyTorch", ("torch_cuda*.dll", "torch_cpu.dll", "libtorch_cuda*.so", "libtorch_cpu.so")),+ ("llama.cpp", ("llama.dll", "libllama*.dll", "llama-*.dll", "llm_engine*", "libllama*.so", "libllama*.dylib")),+ ("whisper.cpp", ("whisper*.dll", "libwhisper*.so", "libwhisper*.dylib")),+ ("ggml", ("ggml*.dll", "libggml*.so", "libggml*.dylib")),+ ("PyTorch", ("torch_cuda*.dll", "torch_cpu.dll", "libtorch_cuda*.so", "libtorch_cpu.so", "libtorch_cpu.dylib")),+ ("MLX", ("libmlx*.dylib",)),("TensorRT", ("nvinfer*.dll", "libnvinfer*.so")),- ("ONNX RT", ("onnxruntime*.dll", "libonnxruntime*.so")),+ ("ONNX RT", ("onnxruntime*.dll", "libonnxruntime*.so", "libonnxruntime*.dylib")),("DirectML", ("directml.dll",)),+ ("HIP", ("amdhip64.dll", "amdhip64_*.dll", "libamdhip64.so")),("cuDNN", ("cudnn*.dll", "libcudnn*.so")),("CUDA", ("nvcuda.dll", "nvcuda64.dll", "cudart64_*.dll", "cublas64_*.dll","libcuda.so", "libcudart.so", "libcublas.so")),diff --cc src/gputaskman/report.pyindex 0df099c,14eec75..9dfb586--- a/src/gputaskman/report.py+++ b/src/gputaskman/report.py@@@ -113,19 -109,19 +114,27 @@@ def to_text(s: Snapshot, limit: int = 3out = []nv = s.nvname = s.adapter.name if s.adapter else "GPU"- info = f" driver {s.driver}" if s.driver else ""- if s.cuda:- info += f" CUDA {s.cuda}"- out.append(f"{name}{info} {nv.driver_model if nv else ''}")- used = gb(s.vram_used) if s.vram_used is not None else "N/A"- shared = gb(s.shared_used) if s.shared_used is not None else "N/A"- memory = f"VRAM {used} / {gb(s.vram_total)}"- if s.backend == "wddm" or s.host_data:- memory += f" shared (in system RAM) {shared}"- out.append(memory)+ if s.backend == "metal":++ used = gb(s.vram_used) if s.vram_used is not None else "N/A"+ out.append(f"{name} {s.driver} Metal")- out.append(f"GPU memory {gb(s.vram_used)} allocated / {gb(s.vram_total)} unified")++ out.append(f"GPU memory {used} allocated / {gb(s.vram_total)} unified")+ out.append(METAL_NOTE)+ if nv:+ out.append(f"GPU {format_metric(nv.util_gpu, unit='%')}")+ else:- out.append(f"{name} driver {s.driver} CUDA {s.cuda} {nv.driver_model if nv else ''}")- shared = f" shared (in system RAM) {gb(s.shared_used)}" if s.backend == "wddm" or s.host_data else ""- out.append(f"VRAM {gb(s.vram_used)} / {gb(s.vram_total)}{shared}")++ info = f" driver {s.driver}" if s.driver else ""++ if s.cuda:++ info += f" CUDA {s.cuda}"++ out.append(f"{name}{info} {nv.driver_model if nv else ''}")++ used = gb(s.vram_used) if s.vram_used is not None else "N/A"++ shared = gb(s.shared_used) if s.shared_used is not None else "N/A"++ memory = f"VRAM {used} / {gb(s.vram_total)}"++ if s.backend == "wddm" or s.host_data:++ memory += f" shared (in system RAM) {shared}"++ out.append(memory)if s.backend == "wsl":out.append(wsl_note(s))- if nv:+ if nv and s.backend != "metal":rx = nv.pcie_rx_kbs / 1024 if nv.pcie_rx_kbs is not None else Nonetx = nv.pcie_tx_kbs / 1024 if nv.pcie_tx_kbs is not None else Nonepstate = f"P{nv.pstate}" if nv.pstate is not None else "P N/A"