"""My process's share of GPU time over a span — the #146 admissibility rule. accumulatedGPUTime is cumulative since client creation, so WindowServer always dominates the totals. The question that decides whether a rail reading may be attributed to this process is the DELTA over the measured span. """ import re, subprocess, time, os, sys, threading def gpu_times(): out = subprocess.run(["ioreg","-r","-c","IOAccelerator","-l","-w0"], capture_output=True, text=True, timeout=30).stdout tot = {} for b in out.split("IOUserClientCreator")[1:]: m = re.search(r'pid (\d+), ([^"]+)', b) if not m: continue key = (int(m.group(1)), m.group(2).strip()) g = sum(int(x) for x in re.findall(r'"accumulatedGPUTime"\s*=\s*(\d+)', b[:4000])) if g: tot[key] = tot.get(key, 0) + g return tot def load(stop): import mlx.core as mx a = mx.random.normal((2048,2048)); b = mx.random.normal((2048,2048)) while not stop.is_set(): mx.eval(a @ b) me = os.getpid() stop = threading.Event() t = threading.Thread(target=load, args=(stop,), daemon=True); t.start() time.sleep(0.5) before = gpu_times(); t0 = time.perf_counter() time.sleep(4.0) after = gpu_times(); span = time.perf_counter() - t0 stop.set(); t.join(timeout=3) delta = {} for k, v in after.items(): d = v - before.get(k, 0) if d > 0: delta[k] = d s = sum(delta.values()) mine = sum(v for (pid, _n), v in delta.items() if pid == me) print(f"span {span:.2f}s clients advancing: {len(delta)} total GPU time in span: {s/1e9:.3f}s") print(f"this process (pid {me}): {mine/1e9:.3f}s = {100*mine/s if s else 0:.1f}% of GPU time in the span") for (pid, n), v in sorted(delta.items(), key=lambda kv: -kv[1])[:6]: tag = " <-- me" if pid == me else "" print(f" pid {pid:>7} {n[:34]:<34} {v/1e9:>8.3f}s {100*v/s:>5.1f}%{tag}") print() print("#146 rule:", "HwShunt (>=99%)" if s and mine/s >= 0.99 else ("exactly 0 (no GPU time)" if mine == 0 else "NO GPU FIGURE — span is CPU only, Partial"))