From 99944631c77cb0518a0dd955a071374fda627d61 Mon Sep 17 00:00:00 2001 From: Shadowmourne G Date: Sun, 19 Jul 2015 20:51:00 +0800 Subject: [PATCH] contrib: add nvidia infomation widget type --- contrib/README | 8 ++++++++ contrib/nvinf.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 contrib/nvinf.lua diff --git a/contrib/README b/contrib/README index 74dda00..a6c0416 100644 --- a/contrib/README +++ b/contrib/README @@ -76,6 +76,14 @@ vicious.contrib.openweather - returns a table with string keys: {city}, {wind deg}, {wind aim}, {wind kmh}, {wind mps}, {sky}, {weather}, {temp c}, {humid}, {press} +vicious.contrib.nvinf + - provides GPU utilization, core temperature, clock frequency information + about Nvidia GPU from nvidia-settings + - takes optional card ID as an argument, i.e. "1", or defaults to ID 0 + - returns first 4 values as usage of GPU core, memory, video engine and + PCIe bandwidth, 5th as temperature of requested graphics device, 6th + as frequency of GPU core, 7th as memory transfer rate + vicious.contrib.nvsmi - provides (very basic) information about Nvidia GPU status from SMI - takes optional card ID as an argument, i.e. "1", or defaults to ID 0 diff --git a/contrib/nvinf.lua b/contrib/nvinf.lua new file mode 100644 index 0000000..b277b78 --- /dev/null +++ b/contrib/nvinf.lua @@ -0,0 +1,35 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2015, Ziyuan Guo +--------------------------------------------------- + +-- {{{ Grab environment +local tonumber = tonumber +local io = { popen = io.popen } +local string = { gmatch = string.gmatch } +local setmetatable = setmetatable +local helpers = require("vicious.helpers") +-- }}} + + +-- vicious.widgets.nvinf +local nvinf = {} + + +-- {{{ NVIDIA infomation widget type +local function worker(format, warg) + if not warg then warg = "0" end + local nv_inf = {} + local f = io.popen("LC_ALL=C nvidia-settings -q GPUUtilization -q [gpu:"..helpers.shellquote(warg).."]/GPUCoreTemp -q [gpu:"..helpers.shellquote(warg).."]/GPUCurrentClockFreqs -t") + local all_info = f:read("*all") + f:close() + + for num in string.gmatch(all_info, "%d+") do + nv_inf[#nv_inf + 1] = tonumber(num) + end + + return nv_inf +end +-- }}} + +return setmetatable(nvinf, { __call = function(_, ...) return worker(...) end })