| 1 | -- contrib/nvinf_all.lua |
| 2 | -- Copyright (C) 2015 Ziyuan Guo <[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 string = { gmatch = string.gmatch } |
| 24 | local setmetatable = setmetatable |
| 25 | local helpers = require("vicious.helpers") |
| 26 | -- }}} |
| 27 | |
| 28 | |
| 29 | -- vicious.widgets.nvinf |
| 30 | local nvinf_all = {} |
| 31 | |
| 32 | |
| 33 | -- {{{ NVIDIA infomation widget type |
| 34 | local function worker(format, warg) |
| 35 | if not warg then warg = "0" end |
| 36 | local nv_inf = {} |
| 37 | local f = io.popen("LC_ALL=C nvidia-settings -q GPUUtilization -q [gpu:"..helpers.shellquote(warg).."]/GPUCoreTemp -q [gpu:"..helpers.shellquote(warg).."]/GPUCurrentClockFreqs -t") |
| 38 | local all_info = f:read("*all") |
| 39 | f:close() |
| 40 | |
| 41 | for num in string.gmatch(all_info, "%d+") do |
| 42 | nv_inf[#nv_inf + 1] = tonumber(num) |
| 43 | end |
| 44 | |
| 45 | return nv_inf |
| 46 | end |
| 47 | -- }}} |
| 48 | |
| 49 | return setmetatable(nvinf_all, { __call = function(_, ...) return worker(...) end }) |