2017-12-01 00:21:33 -06:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2014, Adrian C. <anrxc@sysphere.org>
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local tonumber = tonumber
|
|
|
|
local io = { popen = io.popen }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = { match = string.match }
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- nvsmi: provides GPU information from nvidia SMI
|
|
|
|
-- vicious.contrib.nvsmi
|
|
|
|
local nvsmi = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ GPU Information widget type
|
|
|
|
local function worker(format, warg)
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Fallback to querying first device
|
|
|
|
if not warg then warg = "0" end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Get data from smi
|
|
|
|
-- * Todo: support more; MEMORY,UTILIZATION,ECC,POWER,CLOCK,COMPUTE,PIDS,PERFORMANCE
|
|
|
|
local f = io.popen("nvidia-smi -q -d TEMPERATURE -i " .. warg)
|
|
|
|
local smi = f:read("*all")
|
|
|
|
f:close()
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Not installed
|
|
|
|
if smi == nil then return {0} end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Get temperature information
|
|
|
|
local _thermal = string.match(smi, "Gpu[%s]+:[%s]([%d]+)[%s]C")
|
|
|
|
-- Handle devices without data
|
|
|
|
if _thermal == nil then return {0} end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
return {tonumber(_thermal)}
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return setmetatable(nvsmi, { __call = function(_, ...) return worker(...) end })
|