From 416fa4876018e5fbb9c3f537ea9c353d1d8b9982 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 4 Oct 2026 18:52:40 +0200 Subject: feat(gpu): show VRAM in use as a bar with a percentage Sum drm-resident-vram0 from DRM fdinfo, the same per-client counters gputop reads, counting each drm-client-id once since a client repeats its totals on every fd it holds. One grep over /proc/*/fdinfo, about 10ms warm, sampled through new_gate every ~2s. The 12 GiB total is hardcoded: xe exposes no VRAM capacity in sysfs. Co-Authored-By: Claude Opus 5.5 --- test/test_data.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/test_data.lua') diff --git a/test/test_data.lua b/test/test_data.lua index 2d4d5c7..ec2b6ed 100644 --- a/test/test_data.lua +++ b/test/test_data.lua @@ -479,6 +479,26 @@ assert(up.upgrade == 3 and up.bump == 1 and up.current == 46 and up.missing == 1 'updates summary') assert(data.nvtable_parse('') == nil, 'updates: empty cache is nil') +-- drm_vram_parse: xe clients counted once across their fds, other drivers +-- skipped, units honoured. +local fdinfo = table.concat({ + '/proc/1/fdinfo/5:drm-driver:\txe', + '/proc/1/fdinfo/5:drm-client-id:\t7', + '/proc/1/fdinfo/5:drm-resident-vram0:\t1024 KiB', + '/proc/1/fdinfo/6:drm-driver:\txe', + '/proc/1/fdinfo/6:drm-client-id:\t7', + '/proc/1/fdinfo/6:drm-resident-vram0:\t1024 KiB', + '/proc/2/fdinfo/9:drm-driver:\txe', + '/proc/2/fdinfo/9:drm-client-id:\t8', + '/proc/2/fdinfo/9:drm-resident-vram0:\t2 MiB', + '/proc/3/fdinfo/4:drm-driver:\tamdgpu', + '/proc/3/fdinfo/4:drm-client-id:\t9', + '/proc/3/fdinfo/4:drm-resident-vram0:\t5 GiB', +}, '\n') +assert(data.drm_vram_parse(fdinfo) == 3 * 1024 ^ 2, + 'drm vram: got ' .. tostring(data.drm_vram_parse(fdinfo))) +assert(data.drm_vram_parse('') == nil, 'drm vram: no clients is nil') + -- new_gate: opens at most once per interval on the clock it is given. local gate = data.new_gate(1.9) assert(gate(100.0) == true, 'gate: first call opens') -- cgit v1.2.3