| 1 |
|
| 2 |
> |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
local io = { open = io.open } |
| 20 |
local string = { match = string.match } |
| 21 |
local tonumber = tonumber |
| 22 |
local type = type |
| 23 |
|
| 24 |
local helpers = require("vicious.helpers") |
| 25 |
|
| 26 |
local _mem = nil |
| 27 |
|
| 28 |
|
| 29 |
return helpers.setcall(function (format, warg) |
| 30 |
if not warg then return end |
| 31 |
|
| 32 |
|
| 33 |
local amdgpu = "/sys/class/drm/"..warg.."/device" |
| 34 |
local _data = {} |
| 35 |
|
| 36 |
local f = io.open(amdgpu .. "/gpu_busy_percent", "r") |
| 37 |
if f then |
| 38 |
_data["{gpu_usage}"] = f:read("*line") |
| 39 |
f:close() |
| 40 |
else |
| 41 |
_data["{gpu_usage}"] = "N/A" |
| 42 |
end |
| 43 |
|
| 44 |
if _mem == nil then |
| 45 |
f = io.open(amdgpu .. "/mem_info_vram_total", "r") |
| 46 |
if f then |
| 47 |
_mem = tonumber(string.match(f:read("*line"), "([%d]+)")) |
| 48 |
f:close() |
| 49 |
end |
| 50 |
end |
| 51 |
|
| 52 |
f = io.open(amdgpu .. "/mem_info_vram_used", "r") |
| 53 |
if f then |
| 54 |
local _used = tonumber(string.match(f:read("*line"), "([%d]+)")) |
| 55 |
if type(_used) == 'number' and type(_mem) == 'number' |
| 56 |
and _mem > 0 then |
| 57 |
_data["{mem_usage}"] = _used/_mem*100 |
| 58 |
else |
| 59 |
_data["{mem_usage}"] = "N/A" |
| 60 |
end |
| 61 |
f:close() |
| 62 |
else |
| 63 |
_data["{mem_usage}"] = "N/A" |
| 64 |
end |
| 65 |
|
| 66 |
return _data |
| 67 |
|
| 68 |
end) |
| 69 |
|