2022-07-13 01:06:15 -04:00
|
|
|
local pure = require 'pure'
|
2021-08-08 15:58:53 -04:00
|
|
|
local i_o = require 'i_o'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2022-07-17 18:40:24 -04:00
|
|
|
return function(update_freq, config, common, width, point)
|
2021-07-17 23:28:59 -04:00
|
|
|
local SEPARATOR_SPACING = 20
|
|
|
|
local TEXT_SPACING = 20
|
|
|
|
local PLOT_SEC_BREAK = 20
|
|
|
|
local PLOT_HEIGHT = 56
|
|
|
|
local NA = 'N/A'
|
2022-07-19 23:04:43 -04:00
|
|
|
local NVIDIA_EXE = 'nvidia-settings'
|
2021-07-17 23:28:59 -04:00
|
|
|
local __string_match = string.match
|
2021-11-10 16:55:10 -05:00
|
|
|
local __tonumber = tonumber
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2022-07-17 19:30:48 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- nvidia state
|
|
|
|
|
2022-07-19 23:04:43 -04:00
|
|
|
i_o.exe_assert(NVIDIA_EXE)
|
|
|
|
|
2022-07-17 19:30:48 -04:00
|
|
|
-- vars to process the nv settings glob
|
|
|
|
--
|
|
|
|
-- glob will be of the form:
|
|
|
|
-- <used_mem>
|
|
|
|
-- <total_mem>
|
|
|
|
-- <temp>
|
|
|
|
-- <gpu_freq>,<mem_freq>
|
|
|
|
-- graphics=<gpu_util>, memory=<mem_util>, video=<vid_util>, PCIe=<pci_util>
|
2022-07-19 23:04:43 -04:00
|
|
|
local NV_QUERY = NVIDIA_EXE..
|
|
|
|
' -t'..
|
2022-07-17 19:30:48 -04:00
|
|
|
' -q UsedDedicatedGPUmemory'..
|
|
|
|
' -q TotalDedicatedGPUmemory'..
|
|
|
|
' -q ThermalSensorReading'..
|
|
|
|
' -q [gpu:0]/GPUCurrentClockFreqs'..
|
|
|
|
' -q [gpu:0]/GPUutilization'
|
|
|
|
|
|
|
|
local NV_REGEX = '(%d+)\n'..
|
|
|
|
'(%d+)\n'..
|
|
|
|
'(%d+)\n'..
|
|
|
|
'(%d+),(%d+)\n'..
|
|
|
|
'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n'
|
|
|
|
|
|
|
|
local GPU_BUS_CTRL = '/sys/bus/pci/devices/0000:01:00.0/power/control'
|
|
|
|
|
|
|
|
local mod_state = {
|
|
|
|
error = false,
|
|
|
|
used_memory = 0,
|
|
|
|
total_memory = 0,
|
|
|
|
temp_reading = 0,
|
|
|
|
gpu_frequency = 0,
|
|
|
|
memory_frequency = 0,
|
|
|
|
gpu_utilization = 0,
|
|
|
|
vid_utilization = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
local update_state = function()
|
|
|
|
if i_o.read_file(GPU_BUS_CTRL, nil, '*l') == 'on' then
|
|
|
|
local nvidia_settings_glob = i_o.execute_cmd(NV_QUERY)
|
|
|
|
if nvidia_settings_glob == '' then
|
|
|
|
mod_state.error = 'Error'
|
|
|
|
else
|
|
|
|
mod_state.used_memory,
|
|
|
|
mod_state.total_memory,
|
|
|
|
mod_state.temp_reading,
|
|
|
|
mod_state.gpu_frequency,
|
|
|
|
mod_state.memory_frequency,
|
|
|
|
mod_state.gpu_utilization,
|
|
|
|
mod_state.vid_utilization
|
|
|
|
= __string_match(nvidia_settings_glob, NV_REGEX)
|
|
|
|
mod_state.error = false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
mod_state.error = 'Off'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- helper functions
|
|
|
|
|
2022-07-17 19:30:48 -04:00
|
|
|
local _from_state = function(def, get, set)
|
|
|
|
return function()
|
|
|
|
if mod_state.error == false then
|
|
|
|
set(get(mod_state))
|
2022-07-13 01:06:15 -04:00
|
|
|
else
|
|
|
|
set(def)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local _mk_plot = function(label, getter, y)
|
|
|
|
local obj = common.make_tagged_maybe_percent_timeseries(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-13 01:06:15 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:06:15 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
PLOT_SEC_BREAK,
|
|
|
|
label,
|
|
|
|
update_freq
|
|
|
|
)
|
|
|
|
local update = _from_state(
|
|
|
|
false,
|
|
|
|
getter,
|
|
|
|
pure.partial(common.tagged_maybe_percent_timeseries_set, obj)
|
|
|
|
)
|
|
|
|
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
|
|
|
|
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-16 00:00:06 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
|
|
|
update,
|
|
|
|
static,
|
|
|
|
dynamic
|
|
|
|
)
|
2022-07-13 01:06:15 -04:00
|
|
|
end
|
2021-07-13 00:14:04 -04:00
|
|
|
|
2021-07-17 23:28:59 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu status
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
local mk_status = function(y)
|
|
|
|
local obj = common.make_text_row(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-13 01:06:15 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:06:15 -04:00
|
|
|
'Status'
|
|
|
|
)
|
2022-07-17 19:30:48 -04:00
|
|
|
local update = function()
|
|
|
|
if mod_state.error == false then
|
2022-07-13 01:06:15 -04:00
|
|
|
common.text_row_set(obj, 'On')
|
|
|
|
else
|
2022-07-17 19:30:48 -04:00
|
|
|
common.text_row_set(obj, mod_state.error)
|
2022-07-13 01:06:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local static = pure.partial(common.text_row_draw_static, obj)
|
|
|
|
local dynamic = pure.partial(common.text_row_draw_dynamic, obj)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(width, 0, update, static, dynamic)
|
2022-07-13 01:06:15 -04:00
|
|
|
end
|
2021-07-17 23:28:59 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu temperature
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
local mk_temp = function(y)
|
|
|
|
local obj = common.make_threshold_text_row(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-13 01:06:15 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:06:15 -04:00
|
|
|
'Internal Temperature',
|
|
|
|
function(s)
|
|
|
|
if s == -1 then return NA else return string.format('%s°C', s) end
|
|
|
|
end,
|
|
|
|
80
|
|
|
|
)
|
|
|
|
local update = _from_state(
|
|
|
|
-1,
|
|
|
|
function(s) return __tonumber(s.temp_reading) end,
|
|
|
|
pure.partial(common.threshold_text_row_set, obj)
|
|
|
|
)
|
|
|
|
local static = pure.partial(common.threshold_text_row_draw_static, obj)
|
|
|
|
local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, obj)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(width, 0, update, static, dynamic)
|
2022-07-13 01:06:15 -04:00
|
|
|
end
|
2021-07-17 23:28:59 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu clock speeds
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
local mk_clock = function(y)
|
|
|
|
local obj = common.make_text_rows(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2021-07-17 23:28:59 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:06:15 -04:00
|
|
|
TEXT_SPACING,
|
|
|
|
{'GPU Clock Speed', 'memory Clock Speed'}
|
2021-07-17 23:28:59 -04:00
|
|
|
)
|
2022-07-17 19:30:48 -04:00
|
|
|
local update = function()
|
|
|
|
if mod_state.error == false then
|
|
|
|
common.text_rows_set(obj, 1, mod_state.gpu_frequency..' Mhz')
|
|
|
|
common.text_rows_set(obj, 2, mod_state.memory_frequency..' Mhz')
|
2022-07-13 01:06:15 -04:00
|
|
|
else
|
|
|
|
common.text_rows_set(obj, 1, NA)
|
|
|
|
common.text_rows_set(obj, 2, NA)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local static = pure.partial(common.text_rows_draw_static, obj)
|
|
|
|
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(width, TEXT_SPACING, update, static, dynamic)
|
2021-07-17 23:28:59 -04:00
|
|
|
end
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu utilization plot
|
|
|
|
|
|
|
|
local mk_gpu_util = pure.partial(
|
|
|
|
_mk_plot,
|
|
|
|
'GPU utilization',
|
|
|
|
function(s) return s.gpu_utilization end
|
|
|
|
)
|
2021-07-17 23:28:59 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu memory consumption plot
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
local mk_mem_util = pure.partial(
|
|
|
|
_mk_plot,
|
|
|
|
'Memory utilization',
|
|
|
|
function(s) return s.used_memory / s.total_memory * 100 end
|
|
|
|
)
|
2021-07-17 23:28:59 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- gpu video utilization plot
|
|
|
|
|
2022-07-13 01:06:15 -04:00
|
|
|
local mk_vid_util = pure.partial(
|
|
|
|
_mk_plot,
|
|
|
|
'Video utilization',
|
|
|
|
function(s) return s.vid_utilization end
|
|
|
|
)
|
2021-07-17 23:28:59 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- main drawing functions
|
|
|
|
|
2022-07-17 19:12:31 -04:00
|
|
|
return {
|
|
|
|
header = 'NVIDIA GRAPHICS',
|
|
|
|
point = point,
|
|
|
|
width = width,
|
2022-07-17 22:30:38 -04:00
|
|
|
set_state = update_state,
|
2022-07-17 19:12:31 -04:00
|
|
|
top = {{mk_status, true, SEPARATOR_SPACING}},
|
2022-07-17 18:54:23 -04:00
|
|
|
common.mk_section(
|
2022-07-16 23:48:01 -04:00
|
|
|
SEPARATOR_SPACING,
|
|
|
|
{mk_temp, config.show_temp, SEPARATOR_SPACING}
|
|
|
|
),
|
2022-07-17 18:54:23 -04:00
|
|
|
common.mk_section(
|
2022-07-16 23:48:01 -04:00
|
|
|
SEPARATOR_SPACING,
|
|
|
|
{mk_clock, config.show_clock, SEPARATOR_SPACING}
|
|
|
|
),
|
2022-07-17 18:54:23 -04:00
|
|
|
common.mk_section(
|
2022-07-16 23:48:01 -04:00
|
|
|
SEPARATOR_SPACING,
|
|
|
|
{mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK},
|
|
|
|
{mk_mem_util, config.show_mem_util, PLOT_SEC_BREAK},
|
|
|
|
{mk_vid_util, config.show_vid_util, 0}
|
|
|
|
)
|
2022-07-17 19:12:31 -04:00
|
|
|
}
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|