diff options
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/modules/stats.py | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/deckit/modules/stats.py b/deckit/modules/stats.py index 947b334..121572e 100644 --- a/deckit/modules/stats.py +++ b/deckit/modules/stats.py @@ -17,7 +17,7 @@ """System stats: CPU, memory, GPU (Intel xe), network, uptime, pending updates. The Arc driver exposes temperature and fan through hwmon and no VRAM capacity; -VRAM in use comes from the DRM fdinfo scan, as quickshell's perf panel does. +VRAM in use and engine busy cycles come from the DRM fdinfo scan, as quickshell's perf panel does. """ import json @@ -52,9 +52,15 @@ def _parse_bytes(value): return int(float(m[1]) * UNITS[m[2].upper()]) -def _intel_vram_used(root=Path("/proc")): - """Sum drm-resident-vram0 over xe clients, counting each client id once.""" - seen, total = set(), 0 +ENGINES = ("rcs", "ccs") # render (games) and compute (local LLMs) + + +def _intel_fdinfo(root=Path("/proc")): + """One pass over xe clients, each client id counted once. + + Returns (VRAM bytes, {engine: busy cycles summed}, {engine: GPU cycles}). + """ + seen, total, busy, clock = set(), 0, dict.fromkeys(ENGINES, 0), {} for fdinfo in root.glob("[0-9]*/fdinfo/*"): try: text = fdinfo.read_text() @@ -65,15 +71,32 @@ def _intel_vram_used(root=Path("/proc")): key, sep, value = line.partition(":") if sep and key.startswith("drm-"): fields[key] = value.strip() - client, resident = fields.get("drm-client-id"), fields.get("drm-resident-vram0") - if fields.get("drm-driver") != "xe" or not client or client in seen or not resident: - continue - m = re.match(r"(\d+)\s*([KMGT]?)(?:i?B)?", resident) - if not m: + client = fields.get("drm-client-id") + if fields.get("drm-driver") != "xe" or not client or client in seen: continue seen.add(client) - total += int(m[1]) * UNITS[m[2].upper()] - return total + for e in ENGINES: + if fields.get(f"drm-cycles-{e}", "").isdigit(): + busy[e] += int(fields[f"drm-cycles-{e}"]) + clock[e] = max(clock.get(e, 0), int(fields.get(f"drm-total-cycles-{e}", "0") or 0)) + m = re.match(r"(\d+)\s*([KMGT]?)(?:i?B)?", fields.get("drm-resident-vram0", "")) + if m: + total += int(m[1]) * UNITS[m[2].upper()] + return total, busy, clock + + +def _gpu_util(before, after): + """Busiest engine's percentage between two _intel_fdinfo samples, or None.""" + if not before: + return None + pcts = [] + for e in ENGINES: + dt = after[2].get(e, 0) - before[2].get(e, 0) + if dt > 0: + # ponytail: a client exiting mid-sample takes its cycles with it, + # so the delta can dip below zero; clamp rather than track clients. + pcts.append(min(100, max(0, 100 * (after[1][e] - before[1][e]) / dt))) + return round(max(pcts)) if pcts else None def _cpu_sensor(hw): @@ -182,7 +205,7 @@ def make(cfg: dict) -> Module: cpu_name = _cpu_name(_read("/proc/cpuinfo")) or "CPU" os_info = {**_os(_read("/etc/os-release")), "kernel": platform.release()} gpu_total = _parse_bytes(hw.get("gpu_mem_total", "")) if gpu else None - prev = {"cpu": None, "net": None, "t": None, "gpu_t": 0, "gpu_v": None} + prev = {"cpu": None, "net": None, "t": None, "gpu_t": 0, "gpu_v": None, "gpu_s": None} def cpu_percent(): fields = list(map(int, _read("/proc/stat").splitlines()[0].split()[1:])) @@ -213,17 +236,18 @@ def make(cfg: dict) -> Module: # The fdinfo scan touches every process, so keep it to once every 2 s. if time.time() - prev["gpu_t"] < 2: return prev["gpu_v"] + sample = _intel_fdinfo() temp = _read(gpu["hwmon"] / "temp2_input") fan = _read(gpu["hwmon"] / "fan1_input") v = { "name": gpu["name"], - "util": None, + "util": _gpu_util(prev["gpu_s"], sample), "temp": round(int(temp) / 1000) if temp else None, "fan": int(fan) if fan else None, - "memUsed": _intel_vram_used(), + "memUsed": sample[0], "memTotal": gpu_total, } - prev.update(gpu_t=time.time(), gpu_v=v) + prev.update(gpu_t=time.time(), gpu_v=v, gpu_s=sample) return v def state(): |
