2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local CriticalText = require 'CriticalText'
|
|
|
|
local Text = require 'Text'
|
|
|
|
local TextColumn = require 'TextColumn'
|
|
|
|
local Line = require 'Line'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local __tonumber = tonumber
|
|
|
|
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
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local header = _G_Widget_.Header{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _MODULE_Y_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
header = 'NVIDIA GRAPHICS'
|
|
|
|
}
|
|
|
|
|
|
|
|
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
|
|
|
|
local status = {
|
2017-07-20 00:49:24 -04:00
|
|
|
label = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = header.bottom_y,
|
|
|
|
text = 'Status'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
value = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = header.bottom_y,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
text = '<status>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local separator1 = _G_Widget_.Line{
|
2017-07-19 00:36:15 -04:00
|
|
|
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_1_},
|
|
|
|
p2 = {x = _RIGHT_X_, y = _SEP_Y_1_}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_
|
|
|
|
|
|
|
|
local internal_temp = {
|
2017-07-20 00:49:24 -04:00
|
|
|
label = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _INTERNAL_TEMP_Y_,
|
|
|
|
text = 'Internal Temperature'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
value = _G_Widget_.CriticalText{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _INTERNAL_TEMP_Y_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
text = '<gpu_temp>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local separator2 = _G_Widget_.Line{
|
2017-07-19 00:36:15 -04:00
|
|
|
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_2_},
|
|
|
|
p2 = {x = _RIGHT_X_, y = _SEP_Y_2_}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_
|
|
|
|
|
|
|
|
local clock_speed = {
|
2017-07-20 00:49:24 -04:00
|
|
|
labels = _G_Widget_.TextColumn{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _CLOCK_SPEED_Y_,
|
|
|
|
spacing = _TEXT_SPACING_,
|
|
|
|
'GPU Clock Speed',
|
|
|
|
'Memory Clock Speed'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
values = _G_Widget_.TextColumn{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
y = _CLOCK_SPEED_Y_,
|
|
|
|
spacing = _TEXT_SPACING_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
num_rows = 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local separator3 = _G_Widget_.Line{
|
2017-07-19 00:36:15 -04:00
|
|
|
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_3_},
|
|
|
|
p2 = {x = _RIGHT_X_, y = _SEP_Y_3_}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
|
|
|
|
|
|
|
|
local gpu_util = {
|
2017-07-20 00:49:24 -04:00
|
|
|
label = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _GPU_UTIL_Y_,
|
|
|
|
text = 'GPU Utilization'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
value = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _GPU_UTIL_Y_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
text = '<gpu_util>'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
plot = _G_Widget_.LabelPlot{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _GPU_UTIL_Y_ + _PLOT_SEC_BREAK_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
height = _PLOT_HEIGHT_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
|
|
|
|
|
|
|
local mem_util = {
|
2017-07-20 00:49:24 -04:00
|
|
|
label = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _MEM_UTIL_Y_,
|
|
|
|
text = 'Memory Utilization'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
value = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _MEM_UTIL_Y_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
text = '<mem_util>'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
plot = _G_Widget_.LabelPlot{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _MEM_UTIL_Y_ + _PLOT_SEC_BREAK_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
height = _PLOT_HEIGHT_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
|
|
|
|
|
|
|
local vid_util = {
|
2017-07-20 00:49:24 -04:00
|
|
|
label = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _VID_UTIL_Y_,
|
|
|
|
text = 'Video Utilization'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
value = _G_Widget_.Text{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _VID_UTIL_Y_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2017-07-19 00:36:15 -04:00
|
|
|
text = '<vid_util>'
|
|
|
|
},
|
2017-07-20 00:49:24 -04:00
|
|
|
plot = _G_Widget_.LabelPlot{
|
2017-07-19 00:36:15 -04:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _VID_UTIL_Y_ + _PLOT_SEC_BREAK_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
height = _PLOT_HEIGHT_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--[[
|
|
|
|
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)
|
2020-01-30 23:48:02 -05:00
|
|
|
CriticalText.set(internal_temp.value, cr, NA, false)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2020-01-30 23:48:02 -05:00
|
|
|
TextColumn.set(clock_speed.values, cr, 1, NA)
|
|
|
|
TextColumn.set(clock_speed.values, cr, 2, NA)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
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
|
|
|
|
Text.set(status.value, cr, 'On')
|
|
|
|
|
|
|
|
local used_memory, total_memory, temp_reading, gpu_frequency,
|
|
|
|
memory_frequency, gpu_utilization, vid_utilization
|
|
|
|
= __string_match(nvidia_settings_glob, NV_REGEX)
|
|
|
|
|
|
|
|
local is_critical = false
|
|
|
|
if __tonumber(temp_reading) > 80 then is_critical = true end
|
|
|
|
|
|
|
|
CriticalText.set(internal_temp.value, cr, temp_reading..'°C', is_critical)
|
|
|
|
|
|
|
|
TextColumn.set(clock_speed.values, cr, 1, gpu_frequency..' Mhz')
|
|
|
|
TextColumn.set(clock_speed.values, cr, 2, memory_frequency..' Mhz')
|
|
|
|
|
|
|
|
local percent_used_memory = used_memory / total_memory
|
|
|
|
|
|
|
|
Text.set(gpu_util.value, cr, gpu_utilization..'%')
|
2020-03-07 10:58:28 -05:00
|
|
|
Text.set(mem_util.value, cr, Util.round_to_string(percent_used_memory * 100)..'%')
|
2020-01-30 23:48:02 -05:00
|
|
|
Text.set(vid_util.value, cr, vid_utilization..'%')
|
|
|
|
|
|
|
|
LabelPlot.update(gpu_util.plot, gpu_utilization * 0.01)
|
|
|
|
LabelPlot.update(mem_util.plot, percent_used_memory)
|
|
|
|
LabelPlot.update(vid_util.plot, vid_utilization * 0.01)
|
|
|
|
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
|
|
|
|
_RIGHT_X_ = 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
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
local draw_static = function(cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Text.draw(header.text, cr)
|
|
|
|
Line.draw(header.underline, cr)
|
|
|
|
|
|
|
|
Text.draw(status.label, cr)
|
|
|
|
Line.draw(separator1, cr)
|
|
|
|
|
|
|
|
Text.draw(internal_temp.label, cr)
|
|
|
|
Line.draw(separator2, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2018-08-05 11:35:00 -04:00
|
|
|
TextColumn.draw(clock_speed.labels, cr)
|
|
|
|
Line.draw(separator3, cr)
|
|
|
|
|
|
|
|
Text.draw(gpu_util.label, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_static(gpu_util.plot, cr)
|
|
|
|
|
2018-08-05 11:35:00 -04:00
|
|
|
Text.draw(mem_util.label, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_static(mem_util.plot, cr)
|
|
|
|
|
2018-08-05 11:35:00 -04:00
|
|
|
Text.draw(vid_util.label, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_static(vid_util.plot, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local draw_dynamic = function(cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
update(cr)
|
|
|
|
|
|
|
|
Text.draw(status.value, cr)
|
|
|
|
Text.draw(internal_temp.value, cr)
|
|
|
|
TextColumn.draw(clock_speed.values, cr)
|
2020-01-30 23:48:02 -05:00
|
|
|
|
2018-08-05 11:08:37 -04:00
|
|
|
Text.draw(gpu_util.value, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_dynamic(gpu_util.plot, cr)
|
2020-01-30 23:48:02 -05:00
|
|
|
|
2018-08-05 11:08:37 -04:00
|
|
|
Text.draw(mem_util.value, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_dynamic(mem_util.plot, cr)
|
2020-01-30 23:48:02 -05:00
|
|
|
|
2018-08-05 11:08:37 -04:00
|
|
|
Text.draw(vid_util.value, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_dynamic(vid_util.plot, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
M.draw_static = draw_static
|
|
|
|
M.draw_dynamic = draw_dynamic
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
return M
|