2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local Text = require 'Text'
|
|
|
|
local Line = require 'Line'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
local Common = require 'Common'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local __string_match = string.match
|
|
|
|
|
|
|
|
local _MODULE_Y_ = 145
|
|
|
|
local _SEPARATOR_SPACING_ = 20
|
|
|
|
local _TEXT_SPACING_ = 20
|
|
|
|
local _PLOT_SEC_BREAK_ = 20
|
|
|
|
local _PLOT_HEIGHT_ = 56
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local header = Common.Header(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_MODULE_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
'NVIDIA GRAPHICS'
|
|
|
|
)
|
|
|
|
|
|
|
|
local status = Common.initTextRow(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
header.bottom_y,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
'Status'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local separator1 = Common.initSeparator(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_SEP_Y_1_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local internal_temp = Common.initTextRowCrit(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_INTERNAL_TEMP_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
'Internal Temperature',
|
2021-07-10 19:07:45 -04:00
|
|
|
'%s°C',
|
2021-07-06 19:32:18 -04:00
|
|
|
80
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2017-10-23 02:40:12 -04:00
|
|
|
local _SEP_Y_2_ = _INTERNAL_TEMP_Y_ + _SEPARATOR_SPACING_
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local separator2 = Common.initSeparator(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_SEP_Y_2_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local clock_speed = Common.initTextRows(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_CLOCK_SPEED_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_TEXT_SPACING_,
|
|
|
|
{'GPU Clock Speed', 'Memory Clock Speed'}
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local separator3 = Common.initSeparator(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_SEP_Y_3_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local gpu_util = Common.initPercentPlot(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_GPU_UTIL_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
|
|
|
_PLOT_SEC_BREAK_,
|
|
|
|
'GPU Utilization'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local mem_util = Common.initPercentPlot(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_MEM_UTIL_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
|
|
|
_PLOT_SEC_BREAK_,
|
|
|
|
'Memory Utilization'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local vid_util = Common.initPercentPlot(
|
|
|
|
_G_INIT_DATA_.LEFT_X,
|
|
|
|
_VID_UTIL_Y_,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
|
|
|
_PLOT_SEC_BREAK_,
|
|
|
|
'Video Utilization'
|
|
|
|
)
|
2017-07-19 00:36:15 -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>
|
|
|
|
--]]
|
2020-01-30 23:48:02 -05:00
|
|
|
local NV_QUERY = 'nvidia-settings -t'..
|
2017-07-19 00:36:15 -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'..
|
2017-10-23 02:40:12 -04:00
|
|
|
'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local NA = 'N/A'
|
|
|
|
|
|
|
|
local nvidia_off = function(cr)
|
2021-07-11 20:56:05 -04:00
|
|
|
Common.text_row_crit_set(internal_temp, cr, NA)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_rows_set.set(clock_speed, cr, 1, NA)
|
|
|
|
Common.text_rows_set.set(clock_speed, cr, 2, NA)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-06 00:11:00 -04:00
|
|
|
-- TODO refactor this
|
2020-01-30 23:48:02 -05:00
|
|
|
Text.set(gpu_util.value, cr, NA)
|
|
|
|
Text.set(mem_util.value, cr, NA)
|
|
|
|
Text.set(vid_util.value, cr, NA)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2020-01-30 23:48:02 -05:00
|
|
|
LabelPlot.update(gpu_util.plot, 0)
|
|
|
|
LabelPlot.update(mem_util.plot, 0)
|
|
|
|
LabelPlot.update(vid_util.plot, 0)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
2020-01-30 23:48:02 -05:00
|
|
|
|
|
|
|
local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control'
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local update = function(cr)
|
2020-01-30 23:48:02 -05:00
|
|
|
if Util.read_file(gpu_bus_ctrl, nil, '*l') == 'on' then
|
|
|
|
local nvidia_settings_glob = Util.execute_cmd(NV_QUERY)
|
|
|
|
if nvidia_settings_glob == '' then
|
|
|
|
Text.set(status.value, cr, 'Error')
|
|
|
|
nvidia_off(cr)
|
|
|
|
else
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_set(status, cr, 'On')
|
2020-01-30 23:48:02 -05:00
|
|
|
|
|
|
|
local used_memory, total_memory, temp_reading, gpu_frequency,
|
2021-07-05 23:27:43 -04:00
|
|
|
memory_frequency, gpu_utilization, vid_utilization
|
2020-01-30 23:48:02 -05:00
|
|
|
= __string_match(nvidia_settings_glob, NV_REGEX)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_crit_set(internal_temp, cr, temp_reading)
|
|
|
|
Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz')
|
|
|
|
Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz')
|
2020-01-30 23:48:02 -05:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.percent_plot_set(gpu_util, cr, gpu_utilization)
|
|
|
|
Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100)
|
|
|
|
Common.percent_plot_set(vid_util, cr, vid_utilization)
|
2020-01-30 23:48:02 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
Text.set(status.value, cr, 'Off')
|
|
|
|
nvidia_off(cr)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
_MODULE_Y_ = nil
|
|
|
|
_SEPARATOR_SPACING_ = nil
|
|
|
|
_TEXT_SPACING_ = nil
|
|
|
|
_PLOT_SEC_BREAK_ = nil
|
|
|
|
_PLOT_HEIGHT_ = nil
|
|
|
|
_SEP_Y_1_ = nil
|
|
|
|
_SEP_Y_2_ = nil
|
|
|
|
_SEP_Y_3_ = nil
|
|
|
|
_INTERNAL_TEMP_Y_ = nil
|
|
|
|
_CLOCK_SPEED_Y_ = nil
|
|
|
|
_GPU_UTIL_Y_ = nil
|
|
|
|
_MEM_UTIL_Y_ = nil
|
|
|
|
_VID_UTIL_Y_ = nil
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_static = function(cr)
|
|
|
|
Common.drawHeader(cr, header)
|
2018-08-05 11:35:00 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_draw_static(status, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Line.draw(separator1, cr)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_crit_draw_static(internal_temp, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Line.draw(separator2, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_rows_draw_static(clock_speed, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Line.draw(separator3, cr)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.percent_plot_draw_static(gpu_util, cr)
|
|
|
|
Common.percent_plot_draw_static(mem_util, cr)
|
|
|
|
Common.percent_plot_draw_static(vid_util, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_dynamic = function(cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
update(cr)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.text_row_draw_dynamic(status, cr)
|
|
|
|
Common.text_row_crit_draw_dynamic(internal_temp, cr)
|
|
|
|
Common.text_rows_draw_dynamic(clock_speed, cr)
|
|
|
|
Common.percent_plot_draw_dynamic(gpu_util, cr)
|
|
|
|
Common.percent_plot_draw_dynamic(mem_util, cr)
|
|
|
|
Common.percent_plot_draw_dynamic(vid_util, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
return M
|