Debian Codegraph @

vicious/contrib/nvsmi_all.lua

raw symbols SCIP
1 -- contrib/nvsmi_all.lua
2 -- Copyright (C) 2014 Adrian C. <[email protected]>
3 -- Copyright (C) 2017 Jörg Thalheim <[email protected]>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
21 local tonumber = tonumber
22 local io = { popen = io.popen }
23 local setmetatable = setmetatable
24 local string = { match = string.match }
25 -- }}}
26
27
28 -- nvsmi: provides GPU information from nvidia SMI
29 -- vicious.contrib.nvsmi
30 local nvsmi_all = {}
31
32
33 -- {{{ GPU Information widget type
34 local function worker(format, warg)
35 -- Fallback to querying first device
36 if not warg then warg = "0" end
37
38 -- Get data from smi
39 -- * Todo: support more; MEMORY,UTILIZATION,ECC,POWER,CLOCK,COMPUTE,PIDS,PERFORMANCE
40 local f = io.popen("nvidia-smi -q -d TEMPERATURE -i " .. warg)
41 local smi = f:read("*all")
42 f:close()
43
44 -- Not installed
45 if smi == nil then return {0} end
46
47 -- Get temperature information
48 local _thermal = string.match(smi, "Gpu[%s]+:[%s]([%d]+)[%s]C")
49 -- Handle devices without data
50 if _thermal == nil then return {0} end
51
52 return {tonumber(_thermal)}
53 end
54 -- }}}
55
56 return setmetatable(nvsmi_all, { __call = function(_, ...) return worker(...) end })