-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpu.lua
More file actions
executable file
·48 lines (40 loc) · 1.07 KB
/
gpu.lua
File metadata and controls
executable file
·48 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local file_gpu_name = io.popen("nvidia-smi --query-gpu=gpu_name --format=csv,noheader,nounits")
local gpuname = file_gpu_name:read("*all")
file_gpu_name:close()
gpuname = gpuname:gsub("\n$", "")
function conky_gpuName()
return gpuname
end
function column(s,n)
local p=string.rep("%s+.-",n-1).."(%S+)"
return s:match(p)
end
function conky_listGPUProcesses()
local file_df = io.popen("nvidia-smi pmon --select mu -c 1")
local dftext = file_df:read("*all")
file_df:close()
local res = false
local processes = {}
local pid = 0
for line in string.gmatch(dftext,"(.-)\n") do
--processes.pid = column(line,2)
res = string.find(line,"^#")
if res == nil then
p = {}
p.pid= column(line,3)
p.name= column(line,10)
p.mem= column(line,5)
p.memper= column(line,7)
p.usage= column(line,6)
table.insert(processes, p)
end
end
table.sort(processes,function(a,b)
return a.usage>b.usage
end)
local output = ""
for key,value in pairs(processes) do
output = output.."${goto 10}"..value.name.."${alignr 10}"..value.usage.."%\n"
end
return output
end