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
Intel whole-GPU load, video load and power (root only)
Martin Pluskaldee7eff75372
diff --git a/src/gputaskman/app.py b/src/gputaskman/app.pyindex e73ae80..361cab9 100644--- a/src/gputaskman/app.py+++ b/src/gputaskman/app.py@@ -584,6 +584,8 @@ class GpuTaskManager(App):m.append(f" PCIe↓{format_metric(rx, '.0f'):>5} ↑{format_metric(tx, '.0f'):>4} MB/s")if nv.enc or nv.dec:m.append(f" enc {format_metric(nv.enc, unit='%')} dec {format_metric(nv.dec, unit='%')}")+ if nv.video is not None:+ m.append(f" video {format_metric(nv.video, unit='%')}")lines.append(m)clock_label = (f"gfx {format_metric(nv.gfx_clock)} MHz" if is_amd elsef"GT {format_metric(nv.sm_clock)}/{format_metric(nv.sm_clock_max)} MHz" if is_intel elsediff --git a/src/gputaskman/collector.py b/src/gputaskman/collector.pyindex 0e4b624..c967126 100644--- a/src/gputaskman/collector.py+++ b/src/gputaskman/collector.py@@ -126,7 +126,8 @@ class Snapshot:wsl_split: str = "" # WSL only: why Linux rows have no (inferred) VRAM, when they don't# False on an APU (amdgpu iGPU): its GTT is ordinary GPU memory, not spill from a full VRAM.shared_is_spill: bool = True- counter_status: str = "" # Windows counter availability or adapter matching problem+ counter_status: str = "" # Windows counter availability or adapter matching problem;+ # Intel DRM privilege explanation (needs root) when its load/video/power are N/Acounter_adapter_matched: bool | None = None # Windows PDH LUID matched the selected DXGI adapternv_lost: bool = False # NVML faulted for this GPU after a disable/re-enable; restart restores it@property@@ -348,6 +349,10 @@ class Collector:snap.counter_status = " ".join(filter(None, (snap.counter_status, self.adapter.identity_status)))if self.drm_card is not None:snap.process_status = self.counters.drm.status+ if self.drm_card.intel and nv is not None:+ from .drm import intel_counter_status++ snap.counter_status = intel_counter_status(self.drm_card)live = [(pid, g) for pid, g in procs.items() if _is_live(g)]live.sort(key=lambda x: -(x[1].shown_vram or 0))for pid, g in live:diff --git a/src/gputaskman/drm.py b/src/gputaskman/drm.pyindex 2448420..f21728e 100644--- a/src/gputaskman/drm.py+++ b/src/gputaskman/drm.py@@ -10,8 +10,12 @@ counter, and have no per-process or device-wide memory sysfs beyond a discrete cfrom __future__ import annotations+import ctypes+import errnoimport os+import platformimport re+import structimport timefrom bisect import bisect_leftfrom dataclasses import dataclass@@ -516,6 +520,15 @@ def read_device(card: DrmCard, index: int) -> DeviceTelemetry:dev.gfx_clock = curdev.sm_clock_max = _int(os.path.join(gt, "rps_RP0_freq_mhz"))dev.throttle = _intel_throttle(gt)+ util, video = _intel_pmu_rates(d)+ dev.util_gpu = util+ dev.video = video+ if dev.power_w is None and card.integrated:+ # No hwmon energy either: RAPL's uncore zone is the integrated GPU's power.+ # A discrete card keeps N/A here (uncore is not its power).+ dev.power_w = _intel_rapl_w()+ if dev.power_w is not None:+ dev.power_kind = "RAPL uncore"# sysfs current_link_* on i915/xe can report the power-on default instead of the live link# (2.5 GT/s x1 shown while a measured DMA transfer ran at ~19 GB/s), so both stay unset:# unknown beats a confidently wrong number.@@ -562,6 +575,210 @@ def _intel_power_w(hwmon: str) -> float | None:_INTEL_ENERGY_STATE: dict[str, tuple[int, float]] = {} # hwmon path -> (last uJ, last read time); per card+# Whole-GPU load and power for Intel (i915) need privileges a normal user lacks, so they live apart+# from the sysfs readings above: the i915 performance counters (engine busy time) via perf_event_open+# and GPU power via RAPL's uncore energy zone. File descriptors stay open for the process's life+# (like Adl/NVML handles); the previous readings sit beside them. A card whose counters can never be+# opened records why ("denied" or "missing") instead of retrying a failing syscall every refresh.+_PERF_NR = {"x86_64": 298, "aarch64": 241} # __NR_perf_event_open+_INTEL_PMU_ENGINES = (("render", "rcs0-busy"), ("copy", "bcs0-busy"),+ ("video", "vcs0-busy"), ("video-enhance", "vecs0-busy"))+_INTEL_PMU_STATE: dict[str, dict] = {} # card sysfs dir -> {"fds", "prev", "fail"}+_INTEL_RAPL_STATE: dict[str, dict] = {} # energy_uj path -> {"max", "prev", "fail"}++_LIBC = ctypes.CDLL(None, use_errno=True)+_LIBC.syscall.restype = ctypes.c_long+++def _perf_open(pmu_type: int, config: int, cpu: int) -> int | None:+ """One system-wide perf counter fd, or None. The explicit c_long wrappers matter: plain ints+ would cross the variadic call boundary as 32-bit values."""+ nr = _PERF_NR.get(platform.machine())+ if nr is None:+ return None+ attr = ctypes.create_string_buffer(64) # PERF_ATTR_SIZE_VER0: type/size/config is all counting needs+ struct.pack_into("IIQ", attr, 0, pmu_type, 64, config)+ fd = _LIBC.syscall(ctypes.c_long(nr), attr, ctypes.c_long(-1),+ ctypes.c_long(cpu), ctypes.c_long(-1), ctypes.c_ulong(0))+ return fd if fd >= 0 else None+++def _intel_pmu_spec(pmu_root: str = "/sys/bus/event_source/devices/i915") -> tuple[int, int, dict[str, int]] | None:+ """(PMU type, CPU, {engine kind: event config}) from the i915 PMU in sysfs; None when absent."""+ root = pmu_root+ pmu_type = _int(os.path.join(root, "type"))+ mask = _read(os.path.join(root, "cpumask"))+ if pmu_type is None or not mask:+ return None+ try:+ cpu = int(re.split(r"[-,]", mask.strip())[0])+ except ValueError:+ return None+ configs = {}+ for kind, event in _INTEL_PMU_ENGINES:+ value = _read(os.path.join(root, "events", event))+ if not value or "=" not in value:+ continue+ try:+ configs[kind] = int(value.split("=", 1)[1].strip(), 16)+ except ValueError:+ continue+ return (pmu_type, cpu, configs) if configs else None+++def _read_counter(fd: int) -> int | None:+ """One 64-bit perf counter value; None when it can't be read."""+ try:+ return struct.unpack("Q", os.read(fd, 8))[0]+ except (OSError, struct.error):+ return None+++def _intel_pmu_rates(sysfs: str, now: int | None = None) -> tuple[float | None, float | None]:+ """Whole-GPU busy % (busiest engine) and video-engine busy % for an Intel card; (None, None) when+ unreadable. The first sample only arms the baseline (a rate needs an interval); a counter stepping+ back re-arms it instead of reporting a negative load."""+ if now is None:+ now = time.monotonic_ns()+ state = _INTEL_PMU_STATE.get(sysfs)+ if state is None:+ state = {"fds": {}, "prev": {}, "fail": None}+ _INTEL_PMU_STATE[sysfs] = state+ spec = _intel_pmu_spec()+ if spec is None:+ state["fail"] = "missing"+ return None, None+ pmu_type, cpu, configs = spec+ for kind, config in configs.items():+ fd = _perf_open(pmu_type, config, cpu)+ if fd is None:+ for open_fd in state["fds"].values():+ os.close(open_fd)+ state["fds"] = {}+ err = ctypes.get_errno()+ state["fail"] = "denied" if err in (errno.EACCES, errno.EPERM) else "missing"+ return None, None+ state["fds"][kind] = fd+ if not state["fds"]:+ state["fail"] = "missing"+ return None, None+ if state["fail"] or not state["fds"]:+ return None, None+ busy: dict[str, float] = {}+ for kind, fd in state["fds"].items():+ value = _read_counter(fd)+ if value is None:+ for open_fd in state["fds"].values():+ try:+ os.close(open_fd)+ except OSError:+ pass+ del _INTEL_PMU_STATE[sysfs] # transient: a fresh attempt next sample+ return None, None+ prev = state["prev"].get(kind)+ state["prev"][kind] = (value, now)+ if prev is None:+ continue # first sample arms the baseline+ delta, elapsed = value - prev[0], now - prev[1]+ if elapsed <= 0 or delta < 0:+ continue # torn read or stepped-back counter: unknown, not a negative load+ busy[kind] = delta * 100.0 / elapsed+ if not busy:+ return None, None+ video = max([v for k, v in busy.items() if k in ("video", "video-enhance")], default=None)+ util = max(busy.values(), default=None)+ return util, video+++def _intel_rapl_zone(powercap_root: str = "/sys/class/powercap") -> tuple[str, int | None] | None:+ """(energy_uj path, max range or None) of the first package's uncore zone; None when absent."""+ try:+ roots = sorted(os.listdir(powercap_root))+ except OSError:+ return None+ for root in roots:+ if not re.fullmatch(r"intel-rapl:\d+", root):+ continue+ package = os.path.join(powercap_root, root)+ try:+ children = sorted(os.listdir(package))+ except OSError:+ continue+ for child in children:+ zone = os.path.join(package, child)+ if _read(os.path.join(zone, "name")) == "uncore":+ energy = os.path.join(zone, "energy_uj")+ if os.path.exists(energy):+ return energy, _int(os.path.join(zone, "max_energy_range_uj"))+ return None+++def _intel_rapl_w(now: float | None = None) -> float | None:+ """GPU (uncore) power in watts from RAPL's cumulative energy counter; None when unreadable.++ The first sample only arms the baseline. A wrapped counter adds its range (unknown range with a+ wrapped counter is unknown, not a negative power draw)."""+ if now is None:+ now = time.perf_counter()+ zone = _intel_rapl_zone()+ if zone is None:+ return None+ energy_path, max_range = zone+ state = _INTEL_RAPL_STATE.get(energy_path)+ if state is None:+ state = {"prev": None, "fail": None}+ _INTEL_RAPL_STATE[energy_path] = state+ try:+ with open(energy_path, encoding="utf-8") as f:+ energy = int(f.read().strip())+ except (OSError, ValueError):+ try:+ with open(energy_path, encoding="utf-8") as f:+ f.read(1)+ state["fail"] = "missing" # readable but unparseable: a broken counter, not denial+ except OSError as err:+ state["fail"] = "denied" if err.errno in (errno.EACCES, errno.EPERM) else "missing"+ return None+ prev = state["prev"]+ state["prev"] = (energy, now)+ if prev is None:+ return None+ delta, seconds = energy - prev[0], now - prev[1]+ if seconds <= 0:+ return None+ if delta < 0:+ if max_range is None:+ return None+ delta += max_range+ return delta / 1e6 / seconds if delta >= 0 else None+++def intel_counter_status(card: DrmCard) -> str:+ """Why Intel whole-GPU load, video load or power are N/A, for Snapshot.counter_status; "" when+ all present (or not Intel). Unknown stays explained, never a bare blank."""+ if not card.intel:+ return ""+ pmu_fail = _INTEL_PMU_STATE.get(card.sysfs, {}).get("fail")+ states = [s for s in _INTEL_RAPL_STATE.values()]+ rapl_fail = states[0]["fail"] if states else None+ if pmu_fail is None and rapl_fail is None:+ return ""+ parts = []+ if pmu_fail == "denied":+ para = _read("/proc/sys/kernel/perf_event_paranoid") or "?"+ parts.append(f"GPU and video load need perf privileges this user lacks (perf_event_paranoid={para})")+ elif pmu_fail == "missing":+ parts.append("no i915 performance counters on this kernel")+ if card.integrated:+ if rapl_fail == "denied":+ parts.append("GPU power needs root (RAPL energy is root-only)")+ elif rapl_fail == "missing":+ parts.append("no RAPL uncore zone found")+ if not parts:+ return ""+ return "Intel device metrics unavailable: " + "; ".join(parts) + ". N/A is unknown, not zero."++def _vcn_major(device: str) -> int:"""Major version of the card's video block (VCN, listed as UVD in amdgpu's IP discovery); 0 if unknown."""return _int(os.path.join(device, "ip_discovery", "die", "0", "UVD", "0", "major")) or 0diff --git a/src/gputaskman/telemetry.py b/src/gputaskman/telemetry.pyindex 9abc839..41e252f 100644--- a/src/gputaskman/telemetry.py+++ b/src/gputaskman/telemetry.py@@ -18,6 +18,7 @@ class DeviceTelemetry:util_mem: float | None = Noneenc: float | None = Nonedec: float | None = None+ video: float | None = None # video-engine busy % (unified decode+encode on Intel; enc/dec stay unset)temp: float | None = Nonetemp_kind: str = "" # where a fallback temperature comes from ("CPU package"), else its own sensorpower_w: float | None = Nonediff --git a/tests/test_drm.py b/tests/test_drm.pyindex e9d72a9..765a8fb 100644--- a/tests/test_drm.py+++ b/tests/test_drm.py@@ -1,6 +1,7 @@from __future__ import annotationsimport os+import sysimport tempfileimport unittestfrom unittest.mock import patch@@ -579,6 +580,20 @@ class ReadDeviceTests(unittest.TestCase):d = drm.read_device(card, 0)self.assertEqual((d.temp, d.temp_kind), (61, ""))+ def test_read_device_intel_reports_pmu_and_rapl(self):+ with tempfile.TemporaryDirectory() as tmp:+ card_sysfs = Path(tmp) / "card1"+ dev = card_sysfs / "device"+ dev.mkdir(parents=True)+ card = drm.DrmCard(key=32, pdev="0000:00:02.0", sysfs=str(dev), driver="i915",+ vendor_id=0x8086, device_id=0xA7AD, name="Intel Intel Graphics",+ vram_total=0, integrated=True, intel=True)+ with patch.object(drm, "_intel_pmu_rates", return_value=(42.0, 7.0)), \+ patch.object(drm, "_intel_rapl_w", return_value=5.0):+ d = drm.read_device(card, 0)+ self.assertEqual((d.util_gpu, d.video), (42.0, 7.0))+ self.assertEqual((d.power_w, d.power_kind), (5.0, "RAPL uncore"))+def test_read_device_discrete_intel_without_sensor_stays_unknown(self):# The CPU package shares a die with an integrated GPU only; on a discrete card it is# not the GPU's temperature, so there is no fallback.@@ -593,6 +608,21 @@ class ReadDeviceTests(unittest.TestCase):d = drm.read_device(card, 0)self.assertEqual((d.temp, d.temp_kind), (None, ""))+ def test_read_device_discrete_intel_skips_rapl(self):+ with tempfile.TemporaryDirectory() as tmp:+ card_sysfs = Path(tmp) / "card1"+ dev = card_sysfs / "device"+ dev.mkdir(parents=True)+ card = drm.DrmCard(key=12288, pdev="0000:03:00.0", sysfs=str(dev), driver="i915",+ vendor_id=0x8086, device_id=0x56A0, name="Intel Arc A770",+ vram_total=16 * GiB, integrated=False, intel=True)+ with patch.object(drm, "_intel_pmu_rates", return_value=(42.0, None)), \+ patch.object(drm, "_intel_rapl_w") as rapl:+ d = drm.read_device(card, 0)+ rapl.assert_not_called() # uncore is not a discrete card's power+ self.assertEqual(d.util_gpu, 42.0)+ self.assertIsNone(d.power_w)+class DrmCountersTests(unittest.TestCase):def test_drm_counters(self):@@ -1482,6 +1512,202 @@ class IntelScanTests(unittest.TestCase):self.assertIsNone(counters.sample()[1][card.key].dedicated) # one client unreadable: the sum is unknown+class IntelPmuTests(unittest.TestCase):+ """Whole-GPU load from the i915 performance counters, against a fake PMU sysfs tree."""++ def setUp(self):+ drm._INTEL_PMU_STATE.clear()++ def _pmu(self, root, events=("rcs0-busy", "bcs0-busy", "vcs0-busy"), cpumask="0\n"):+ (root / "type").write_text("28\n")+ (root / "cpumask").write_text(cpumask)+ events_dir = root / "events"+ events_dir.mkdir(exist_ok=True)+ for i, event in enumerate(events):+ (events_dir / event).write_text(f"config=0x{i * 0x1000:x}\n")++ def test_spec_parses_type_cpu_and_configs(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp)+ self._pmu(root)+ pmu_type, cpu, configs = drm._intel_pmu_spec(str(root))+ self.assertEqual((pmu_type, cpu), (28, 0))+ self.assertEqual(configs, {"render": 0, "copy": 0x1000, "video": 0x2000})++ def test_spec_missing_is_unknown(self):+ with tempfile.TemporaryDirectory() as tmp:+ self.assertIsNone(drm._intel_pmu_spec(str(Path(tmp) / "no-such-dir")))+ root = Path(tmp)+ (root / "type").write_text("28\n")+ (root / "cpumask").write_text("not-a-cpu\n")+ self.assertIsNone(drm._intel_pmu_spec(str(root)))++ def test_rates_need_two_samples(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp)+ self._pmu(root)+ with patch.object(drm, "_intel_pmu_spec", return_value=(28, 0, {"render": 0, "copy": 0x1000})), \+ patch.object(drm, "_perf_open", side_effect=[10, 11]) as opened, \+ patch.object(drm, "_read_counter", side_effect=[0, 0, 500_000_000, 250_000_000]):+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device", now=0), (None, None))+ self.assertEqual(opened.call_count, 2)+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device", now=1_000_000_000), (50.0, None))+ # "copy" is not video; with no video engine the video figure stays unknown+ self.assertEqual(drm._INTEL_PMU_STATE["/x/card1/device"]["fail"], None)++ def test_video_is_the_video_engines_busy_share(self):+ with tempfile.TemporaryDirectory() as tmp:+ with patch.object(drm, "_intel_pmu_spec", return_value=(28, 0, {"video": 0, "video-enhance": 1})), \+ patch.object(drm, "_perf_open", side_effect=[10, 11]), \+ patch.object(drm, "_read_counter", side_effect=[0, 0, 800_000_000, 200_000_000]):+ drm._intel_pmu_rates("/x/card1/device", now=0)+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device", now=1_000_000_000), (80.0, 80.0))++ @unittest.skipIf(sys.platform == "win32", "powercap sysfs names contain a colon")+ def test_stepped_back_counter_re_arms(self):+ with tempfile.TemporaryDirectory() as tmp:+ with patch.object(drm, "_intel_pmu_spec", return_value=(28, 0, {"render": 0})), \+ patch.object(drm, "_perf_open", return_value=10), \+ patch.object(drm, "_read_counter", side_effect=[1_000_000_000, 900_000_000, 1_500_000_000]) as reads:+ drm._intel_pmu_rates("/x/card1/device", now=0)+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device", now=1_000_000_000), (None, None))+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device", now=2_000_000_000), (60.0, None))+ self.assertEqual(reads.call_count, 3)++ def test_denied_open_reports_denied(self):+ with tempfile.TemporaryDirectory() as tmp:+ with patch.object(drm, "_intel_pmu_spec", return_value=(28, 0, {"render": 0})), \+ patch.object(drm, "_perf_open", return_value=None), \+ patch.object(drm.ctypes, "get_errno", return_value=13):+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device"), (None, None))+ self.assertEqual(drm._INTEL_PMU_STATE["/x/card1/device"]["fail"], "denied")++ def test_missing_spec_reports_missing(self):+ with patch.object(drm, "_intel_pmu_spec", return_value=None):+ self.assertEqual(drm._intel_pmu_rates("/x/card1/device"), (None, None))+ self.assertEqual(drm._INTEL_PMU_STATE["/x/card1/device"]["fail"], "missing")+++class IntelRaplTests(unittest.TestCase):+ """GPU power from RAPL's uncore zone, against a fake powercap tree."""++ def setUp(self):+ drm._INTEL_RAPL_STATE.clear()++ def _zone(self, root, energy="1000000\n", max_range="100000000\n", name="uncore"):+ package = root / "intel-rapl:0"+ package.mkdir(parents=True, exist_ok=True)+ zone = package / "intel-rapl:0:1"+ zone.mkdir(exist_ok=True)+ (zone / "name").write_text(name + "\n")+ energy_path = zone / "energy_uj"+ energy_path.write_text(energy)+ if max_range is not None:+ (zone / "max_energy_range_uj").write_text(max_range)+ return str(energy_path)++ @unittest.skipIf(sys.platform == "win32", "powercap sysfs names contain a colon")+ def test_zone_discovery_prefers_uncore(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp)+ energy = self._zone(root)+ (root / "intel-rapl:0" / "intel-rapl:0:0" / "name").parent.mkdir(parents=True, exist_ok=True)+ self.assertEqual(drm._intel_rapl_zone(str(root))[0], energy)++ @unittest.skipIf(sys.platform == "win32", "powercap sysfs names contain a colon")+ def test_zone_missing_is_unknown(self):+ with tempfile.TemporaryDirectory() as tmp:+ self.assertIsNone(drm._intel_rapl_zone(str(Path(tmp) / "no-such-dir")))+ root = Path(tmp)+ package = root / "intel-rapl:0"+ package.mkdir()+ self.assertIsNone(drm._intel_rapl_zone(str(root))) # no uncore zone: unknown, not 0 W++ @unittest.skipIf(sys.platform == "win32", "powercap sysfs names contain a colon")+ def test_power_needs_two_samples(self):+ with tempfile.TemporaryDirectory() as tmp:+ energy = self._zone(Path(tmp))+ with patch.object(drm, "_intel_rapl_zone", return_value=(energy, 100_000_000)):+ self.assertIsNone(drm._intel_rapl_w(now=0.0))+ Path(energy).write_text("6000000\n") # 5 J in 1 s+ self.assertAlmostEqual(drm._intel_rapl_w(now=1.0), 5.0)++ def test_wrapped_counter_adds_its_range(self):+ with tempfile.TemporaryDirectory() as tmp:+ energy = self._zone(Path(tmp))+ with patch.object(drm, "_intel_rapl_zone", return_value=(energy, 10_000_000)):+ self.assertIsNone(drm._intel_rapl_w(now=0.0))+ Path(energy).write_text("1000\n") # wrapped past 10 mJ+ self.assertAlmostEqual(drm._intel_rapl_w(now=1.0), 9.001)++ def test_wrapped_counter_without_range_is_unknown(self):+ with tempfile.TemporaryDirectory() as tmp:+ energy = self._zone(Path(tmp), max_range=None)+ with patch.object(drm, "_intel_rapl_zone", return_value=(energy, None)):+ self.assertIsNone(drm._intel_rapl_w(now=0.0))+ Path(energy).write_text("1000\n")+ self.assertIsNone(drm._intel_rapl_w(now=1.0))++ def test_unreadable_zone_reports_denied(self):+ with patch.object(drm, "_intel_rapl_zone", return_value=("/no/energy_uj", 10_000_000)):+ self.assertIsNone(drm._intel_rapl_w(now=0.0))+ self.assertEqual(drm._INTEL_RAPL_STATE["/no/energy_uj"]["fail"], "missing")++ @unittest.skipIf(sys.platform == "win32", "powercap sysfs names contain a colon")+ def test_unparseable_zone_reports_missing(self):+ with tempfile.TemporaryDirectory() as tmp:+ energy = self._zone(Path(tmp), energy="lots\n")+ with patch.object(drm, "_intel_rapl_zone", return_value=(energy, 10_000_000)):+ self.assertIsNone(drm._intel_rapl_w(now=0.0))+ self.assertEqual(drm._INTEL_RAPL_STATE[energy]["fail"], "missing")+++class IntelCounterStatusTests(unittest.TestCase):+ """The N/A explanation names what is missing and why; silence when all present."""++ def _card(self, pdev="0000:00:02.0", integrated=True):+ return drm.DrmCard(key=32, pdev=pdev, sysfs="/x/card1/device", driver="i915",+ vendor_id=0x8086, device_id=0xA7AD, name="Intel Intel Graphics",+ vram_total=0, integrated=integrated, intel=True)++ def setUp(self):+ drm._INTEL_PMU_STATE.clear()+ drm._INTEL_RAPL_STATE.clear()++ def test_not_intel_is_silent(self):+ card = drm.DrmCard(key=0, pdev="0000:03:00.0", sysfs="/x/amd/device", driver="amdgpu",+ vendor_id=0x1002, device_id=0x7480, name="AMD GPU", vram_total=8 * GiB,+ integrated=False)+ self.assertEqual(drm.intel_counter_status(card), "")++ def test_denied_names_privileges(self):+ drm._INTEL_PMU_STATE["/x/card1/device"] = {"fail": "denied"}+ drm._INTEL_RAPL_STATE["/z/energy_uj"] = {"fail": "denied", "prev": None}+ with patch.object(drm, "_read", return_value="2"):+ status = drm.intel_counter_status(self._card())+ self.assertIn("perf_event_paranoid=2", status)+ self.assertIn("root", status)+ self.assertIn("unknown, not zero", status)++ def test_missing_names_the_gap(self):+ drm._INTEL_PMU_STATE["/x/card1/device"] = {"fail": "missing"}+ drm._INTEL_RAPL_STATE["/z/energy_uj"] = {"fail": "missing", "prev": None}+ status = drm.intel_counter_status(self._card())+ self.assertIn("performance counters", status)+ self.assertIn("uncore", status)++ def test_all_present_is_silent(self):+ self.assertEqual(drm.intel_counter_status(self._card()), "")++ def test_discrete_card_omits_rapal(self):+ drm._INTEL_PMU_STATE["/x/card1/device"] = {"fail": "denied"}+ drm._INTEL_RAPL_STATE["/z/energy_uj"] = {"fail": "denied", "prev": None}+ with patch.object(drm, "_read", return_value="2"):+ status = drm.intel_counter_status(self._card(integrated=False))+ self.assertIn("load", status)+ self.assertNotIn("RAPL", status)++class IntelNoteTests(unittest.TestCase):"""Intel's device VRAM used is a sum over the clients gputaskman can inspect and its total is a PCI window size,and the output says so."""