REF rename more stuff

This commit is contained in:
Nathan Dwarshuis 2021-07-30 22:46:20 -04:00
parent 6621b861ce
commit e64260d58b
7 changed files with 163 additions and 147 deletions

View File

@ -51,12 +51,12 @@ local DIAL_THETA0 = 90
local DIAL_THETA1 = 360 local DIAL_THETA1 = 360
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- helper functions -- text helper functions
local make_font_spec = function(f, s, bold) local make_font_spec = function(f, size, bold)
return { return {
family = f, family = f,
size = s, size = size,
weight = bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL, weight = bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL,
slant = CAIRO_FONT_WEIGHT_NORMAL, slant = CAIRO_FONT_WEIGHT_NORMAL,
} }
@ -69,19 +69,96 @@ local _text_row_style = function(x_align, color)
return text.style(normal_font_spec, color, x_align, 'center') return text.style(normal_font_spec, color, x_align, 'center')
end end
local left_text_style = _text_row_style('left', theme.INACTIVE_TEXT_FG) local _left_text_style = _text_row_style('left', theme.INACTIVE_TEXT_FG)
local right_text_style = _text_row_style('right', theme.PRIMARY_FG) local _right_text_style = _text_row_style('right', theme.PRIMARY_FG)
local _bare_text = function(pt, _text, style) local _bare_text = function(pt, _text, style)
return text.make_plain(pt, _text, style) return text.make_plain(pt, _text, style)
end end
local _left_text = function(pt, _text) local _left_text = function(pt, _text)
return _bare_text(pt, _text, left_text_style) return _bare_text(pt, _text, _left_text_style)
end end
local _right_text = function(pt, _text) local _right_text = function(pt, _text)
return _bare_text(pt, _text, right_text_style) return _bare_text(pt, _text, _right_text_style)
end
--------------------------------------------------------------------------------
-- timeseries helper functions
local _default_grid_config = timeseries.grid_config(
PLOT_GRID_X_N,
PLOT_GRID_Y_N,
theme.PLOT_GRID_FG
)
local _default_plot_config = timeseries.config(
PLOT_NUM_POINTS,
theme.PLOT_OUTLINE_FG,
theme.PLOT_FILL_BORDER_PRIMARY,
theme.PLOT_FILL_BG_PRIMARY,
_default_grid_config
)
local _format_percent_label = function(_)
return function(z) return util.round_to_string(z * 100)..'%' end
end
local _format_percent_maybe = function(z)
if z == false then return 'N/A' else return string.format('%s%%', z) end
end
local _percent_label_config = timeseries.label_config(
theme.INACTIVE_TEXT_FG,
label_font_spec,
_format_percent_label
)
local _make_timeseries = function(x, y, w, h, label_config, update_freq)
return timeseries.make(
F.make_box(x, y, w, h),
update_freq,
_default_plot_config,
label_config
)
end
local _make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq, format)
return {
label = _left_text(F.make_point(x, y), label),
value = thresholdtext.make_formatted(
F.make_point(x + w, y),
nil,
_right_text_style,
format,
thresholdtext.style(theme.CRITICAL_FG, 80)
),
plot = M.make_percent_timeseries(
x,
y + spacing,
w,
h,
update_freq
),
}
end
--------------------------------------------------------------------------------
-- scaled timeseries helper functions
local _base_2_scale_data = function(m)
return scaledtimeseries.scaling_parameters(2, m, 0.9)
end
local _make_scaled_timeseries = function(x, y, w, h, f, min_domain, update_freq)
return scaledtimeseries.make(
F.make_box(x, y, w, h),
update_freq,
_default_plot_config,
timeseries.label_config(theme.INACTIVE_TEXT_FG, label_font_spec, f),
_base_2_scale_data(min_domain)
)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -120,86 +197,49 @@ M.draw_header = function(cr, header)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- label plot -- percent timeseries
local default_grid_config = timeseries.grid_config( M.make_percent_timeseries = function(x, y, w, h, update_freq)
PLOT_GRID_X_N, return _make_timeseries(x, y, w, h, _percent_label_config, update_freq)
PLOT_GRID_Y_N,
theme.PLOT_GRID_FG
)
local default_plot_config = timeseries.config(
PLOT_NUM_POINTS,
theme.PLOT_OUTLINE_FG,
theme.PLOT_FILL_BORDER_PRIMARY,
theme.PLOT_FILL_BG_PRIMARY,
default_grid_config
)
M.percent_label_config = timeseries.label_config(
theme.INACTIVE_TEXT_FG,
label_font_spec,
function(_) return function(z) return util.round_to_string(z * 100)..'%' end end
)
M.make_label_timeseries = function(x, y, w, h, label_config, update_freq)
return timeseries.make(
F.make_box(x, y, w, h),
update_freq,
default_plot_config,
label_config
)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- percent plot (label plot with percent signs and some indicator data above it) -- tagged percent timeseries
M.make_percent_timeseries_formatted = function(x, y, w, h, spacing, label, update_freq, format) M.make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq)
return { return _make_tagged_percent_timeseries(
label = _left_text(F.make_point(x, y), label), x, y, w, h, spacing, label, update_freq, '%s%%'
value = thresholdtext.make_formatted( )
F.make_point(x + w, y),
nil,
right_text_style,
format,
thresholdtext.style(theme.CRITICAL_FG, 80)
),
plot = M.make_label_timeseries(
x,
y + spacing,
w,
h,
M.percent_label_config,
update_freq
),
}
end end
M.make_percent_timeseries = function(x, y, w, h, spacing, label, update_freq) M.make_tagged_maybe_percent_timeseries = function(x, y, w, h, spacing, label, update_freq)
return M.make_percent_timeseries_formatted(x, y, w, h, spacing, label, update_freq, '%s%%') return _make_tagged_percent_timeseries(
x, y, w, h, spacing, label, update_freq, _format_percent_maybe
)
end end
M.percent_timeseries_draw_static = function(pp, cr) M.tagged_percent_timeseries_draw_static = function(pp, cr)
text.draw(pp.label, cr) text.draw(pp.label, cr)
timeseries.draw_static(pp.plot, cr) timeseries.draw_static(pp.plot, cr)
end end
M.percent_timeseries_draw_dynamic = function(pp, cr) M.tagged_percent_timeseries_draw_dynamic = function(obj, cr)
thresholdtext.draw(pp.value, cr) thresholdtext.draw(obj.value, cr)
timeseries.draw_dynamic(pp.plot, cr) timeseries.draw_dynamic(obj.plot, cr)
end end
-- TODO this is pretty confusing, nil means -1 which gets fed to any text M.tagged_percent_timeseries_set = function(obj, value)
-- formatting functions text.set(obj.value, math.floor(value))
M.percent_timeseries_set = function(pp, value) timeseries.update(obj.plot, value * 0.01)
local t = -1 end
local p = 0
if value ~= nil then M.tagged_maybe_percent_timeseries_set = function(obj, value)
t = math.floor(value) if value == false then
p = value * 0.01 text.set(obj.value, false)
timeseries.update(obj.plot, 0)
else
M.tagged_percent_timeseries_set(obj, value)
end end
text.set(pp.value, t)
timeseries.update(pp.plot, p)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -233,48 +273,34 @@ M.converted_y_label_format_generator = function(unit)
end end
end end
local base_2_scale_data = function(m)
return scaledtimeseries.scaling_parameters(2, m, 0.9)
end
M.make_scaled_timeseries = function(x, y, w, h, f, min_domain, update_freq)
return scaledtimeseries.make(
F.make_box(x, y, w, h),
update_freq,
default_plot_config,
timeseries.label_config(theme.INACTIVE_TEXT_FG, label_font_spec, f),
base_2_scale_data(min_domain)
)
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- scaled plot (with textual data above it) -- tagged scaled plot
M.make_labeled_scaled_timeseries = function(x, y, w, h, format_fun, label_fun, M.make_tagged_scaled_timeseries = function(x, y, w, h, format_fun, label_fun,
spacing, label, min_domain, spacing, label, min_domain,
update_freq) update_freq)
return { return {
label = _left_text(F.make_point(x, y), label), label = _left_text(F.make_point(x, y), label),
value = text.make_formatted( value = text.make_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
0, 0,
right_text_style, _right_text_style,
format_fun format_fun
), ),
plot = M.make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = _make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq),
} }
end end
M.labeled_scale_plot_draw_static = function(asp, cr) M.tagged_scaled_timeseries_draw_static = function(asp, cr)
text.draw(asp.label, cr) text.draw(asp.label, cr)
end end
M.labeled_scale_plot_draw_dynamic = function(asp, cr) M.tagged_scaled_timeseries_draw_dynamic = function(asp, cr)
text.draw(asp.value, cr) text.draw(asp.value, cr)
scaledtimeseries.draw_dynamic(asp.plot, cr) scaledtimeseries.draw_dynamic(asp.plot, cr)
end end
M.labeled_scale_plot_set = function(asp, value) M.tagged_scaled_timeseries_set = function(asp, value)
text.set(asp.value, value) text.set(asp.value, value)
scaledtimeseries.update(asp.plot, value) scaledtimeseries.update(asp.plot, value)
end end
@ -300,10 +326,10 @@ M.make_rate_timeseries = function(x, y, w, h, format_fun, label_fun, spacing,
value = text.make_formatted( value = text.make_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
0, 0,
right_text_style, _right_text_style,
format_fun format_fun
), ),
plot = M.make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = _make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq),
prev_value = init, prev_value = init,
derive = make_differential(update_freq), derive = make_differential(update_freq),
} }
@ -317,7 +343,7 @@ M.update_rate_timeseries = function(obj, value)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- ring -- circle
M.make_circle = function(x, y, r) M.make_circle = function(x, y, r)
return arc.make( return arc.make(
@ -413,7 +439,7 @@ M.make_compound_bar = function(x, y, w, pad, labels, spacing, thickness, thresho
labels = textcolumn.make( labels = textcolumn.make(
F.make_point(x, y), F.make_point(x, y),
labels, labels,
left_text_style, _left_text_style,
nil, nil,
spacing spacing
), ),
@ -492,12 +518,7 @@ M.make_threshold_text_row = function(x, y, w, label, append_end, limit)
value = thresholdtext.make_formatted( value = thresholdtext.make_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
nil, nil,
text.style( _right_text_style,
normal_font_spec,
theme.PRIMARY_FG,
'right',
'center'
),
append_end, append_end,
thresholdtext.style(theme.CRITICAL_FG, limit) thresholdtext.style(theme.CRITICAL_FG, limit)
) )
@ -522,14 +543,14 @@ M.make_text_rows_formatted = function(x, y, w, spacing, labels, format)
labels = textcolumn.make( labels = textcolumn.make(
F.make_point(x, y), F.make_point(x, y),
labels, labels,
left_text_style, _left_text_style,
nil, nil,
spacing spacing
), ),
values = textcolumn.make_n( values = textcolumn.make_n(
F.make_point(x + w, y), F.make_point(x + w, y),
#labels, #labels,
_text_row_style('right', theme.PRIMARY_FG), _right_text_style,
format, format,
spacing, spacing,
0 0

View File

@ -91,20 +91,15 @@ return function(update_freq)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- gpu utilization plot -- gpu utilization plot
local na_percent_format = function(x)
if x == -1 then return NA else return __string_format('%s%%', x) end
end
local make_plot = function(y, label) local make_plot = function(y, label)
return common.make_percent_timeseries_formatted( return common.make_tagged_maybe_percent_timeseries(
geometry.LEFT_X, geometry.LEFT_X,
y, y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
PLOT_HEIGHT, PLOT_HEIGHT,
PLOT_SEC_BREAK, PLOT_SEC_BREAK,
label, label,
update_freq, update_freq
na_percent_format
) )
end end
@ -153,9 +148,9 @@ return function(update_freq)
common.threshold_text_row_set(internal_temp, -1) common.threshold_text_row_set(internal_temp, -1)
common.text_rows_set(clock_speed, 1, NA) common.text_rows_set(clock_speed, 1, NA)
common.text_rows_set(clock_speed, 2, NA) common.text_rows_set(clock_speed, 2, NA)
common.percent_timeseries_set(gpu_util, nil) common.tagged_maybe_percent_timeseries_set(gpu_util, false)
common.percent_timeseries_set(vid_util, nil) common.tagged_maybe_percent_timeseries_set(vid_util, false)
common.percent_timeseries_set(mem_util, nil) common.tagged_maybe_percent_timeseries_set(mem_util, false)
end end
local update = function() local update = function()
@ -170,14 +165,15 @@ return function(update_freq)
local used_memory, total_memory, temp_reading, gpu_frequency, local used_memory, total_memory, temp_reading, gpu_frequency,
memory_frequency, gpu_utilization, vid_utilization memory_frequency, gpu_utilization, vid_utilization
= __string_match(nvidia_settings_glob, NV_REGEX) = __string_match(nvidia_settings_glob, NV_REGEX)
local mem_utilization = used_memory / total_memory * 100
common.threshold_text_row_set(internal_temp, temp_reading) common.threshold_text_row_set(internal_temp, temp_reading)
common.text_rows_set(clock_speed, 1, gpu_frequency..' Mhz') common.text_rows_set(clock_speed, 1, gpu_frequency..' Mhz')
common.text_rows_set(clock_speed, 2, memory_frequency..' Mhz') common.text_rows_set(clock_speed, 2, memory_frequency..' Mhz')
common.percent_timeseries_set(gpu_util, gpu_utilization) common.tagged_maybe_percent_timeseries_set(gpu_util, gpu_utilization)
common.percent_timeseries_set(mem_util, used_memory / total_memory * 100) common.tagged_maybe_percent_timeseries_set(mem_util, mem_utilization)
common.percent_timeseries_set(vid_util, vid_utilization) common.tagged_maybe_percent_timeseries_set(vid_util, vid_utilization)
end end
else else
text.set(status.value, 'Off') text.set(status.value, 'Off')
@ -200,18 +196,18 @@ return function(update_freq)
common.text_rows_draw_static(clock_speed, cr) common.text_rows_draw_static(clock_speed, cr)
line.draw(separator3, cr) line.draw(separator3, cr)
common.percent_timeseries_draw_static(gpu_util, cr) common.tagged_percent_timeseries_draw_static(gpu_util, cr)
common.percent_timeseries_draw_static(mem_util, cr) common.tagged_percent_timeseries_draw_static(mem_util, cr)
common.percent_timeseries_draw_static(vid_util, cr) common.tagged_percent_timeseries_draw_static(vid_util, cr)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
common.text_row_draw_dynamic(status, cr) common.text_row_draw_dynamic(status, cr)
common.threshold_text_row_draw_dynamic(internal_temp, cr) common.threshold_text_row_draw_dynamic(internal_temp, cr)
common.text_rows_draw_dynamic(clock_speed, cr) common.text_rows_draw_dynamic(clock_speed, cr)
common.percent_timeseries_draw_dynamic(gpu_util, cr) common.tagged_percent_timeseries_draw_dynamic(gpu_util, cr)
common.percent_timeseries_draw_dynamic(mem_util, cr) common.tagged_percent_timeseries_draw_dynamic(mem_util, cr)
common.percent_timeseries_draw_dynamic(vid_util, cr) common.tagged_percent_timeseries_draw_dynamic(vid_util, cr)
end end
return {static = draw_static, dynamic = draw_dynamic, update = update} return {static = draw_static, dynamic = draw_dynamic, update = update}

View File

@ -99,12 +99,11 @@ return function(update_freq)
local PLOT_Y = header.bottom_y + PLOT_SECTION_BREAK + DIAL_DIAMETER local PLOT_Y = header.bottom_y + PLOT_SECTION_BREAK + DIAL_DIAMETER
local plot = common.make_label_timeseries( local plot = common.make_percent_timeseries(
geometry.RIGHT_X, geometry.RIGHT_X,
PLOT_Y, PLOT_Y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
PLOT_HEIGHT, PLOT_HEIGHT,
common.percent_label_config,
update_freq update_freq
) )

View File

@ -96,13 +96,13 @@ return function(update_freq)
local draw_static = function(cr) local draw_static = function(cr)
common.draw_header(cr, header) common.draw_header(cr, header)
common.labeled_scale_plot_draw_static(rx, cr) common.tagged_scaled_timeseries_draw_static(rx, cr)
common.labeled_scale_plot_draw_static(tx, cr) common.tagged_scaled_timeseries_draw_static(tx, cr)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
common.labeled_scale_plot_draw_dynamic(rx, cr) common.tagged_scaled_timeseries_draw_dynamic(rx, cr)
common.labeled_scale_plot_draw_dynamic(tx, cr) common.tagged_scaled_timeseries_draw_dynamic(tx, cr)
end end
return {static = draw_static, dynamic = draw_dynamic, update = update} return {static = draw_static, dynamic = draw_dynamic, update = update}

View File

@ -98,7 +98,7 @@ return function(update_freq)
end end
local BAT_Y = DRAM_Y + PLOT_SEC_BREAK * 2 + PLOT_HEIGHT local BAT_Y = DRAM_Y + PLOT_SEC_BREAK * 2 + PLOT_HEIGHT
local bat = common.make_labeled_scaled_timeseries( local bat = common.make_tagged_scaled_timeseries(
geometry.RIGHT_X, geometry.RIGHT_X,
BAT_Y, BAT_Y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
@ -117,20 +117,20 @@ return function(update_freq)
local update = function(is_using_ac) local update = function(is_using_ac)
common.update_rate_timeseries(pkg0, read_pkg0_joules()) common.update_rate_timeseries(pkg0, read_pkg0_joules())
common.update_rate_timeseries(dram, read_dram_joules()) common.update_rate_timeseries(dram, read_dram_joules())
common.labeled_scale_plot_set(bat, read_battery_power(is_using_ac)) common.tagged_scaled_timeseries_set(bat, read_battery_power(is_using_ac))
end end
local draw_static = function(cr) local draw_static = function(cr)
common.draw_header(cr, header) common.draw_header(cr, header)
common.labeled_scale_plot_draw_static(pkg0, cr) common.tagged_scaled_timeseries_draw_static(pkg0, cr)
common.labeled_scale_plot_draw_static(dram, cr) common.tagged_scaled_timeseries_draw_static(dram, cr)
common.labeled_scale_plot_draw_static(bat, cr) common.tagged_scaled_timeseries_draw_static(bat, cr)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
common.labeled_scale_plot_draw_dynamic(pkg0, cr) common.tagged_scaled_timeseries_draw_dynamic(pkg0, cr)
common.labeled_scale_plot_draw_dynamic(dram, cr) common.tagged_scaled_timeseries_draw_dynamic(dram, cr)
common.labeled_scale_plot_draw_dynamic(bat, cr) common.tagged_scaled_timeseries_draw_dynamic(bat, cr)
end end
return {static = draw_static, dynamic = draw_dynamic, update = update} return {static = draw_static, dynamic = draw_dynamic, update = update}

View File

@ -101,7 +101,7 @@ return function(update_freq)
local LOAD_Y = SEP_Y + SEPARATOR_SPACING local LOAD_Y = SEP_Y + SEPARATOR_SPACING
local total_load = common.make_percent_timeseries( local total_load = common.make_tagged_percent_timeseries(
geometry.LEFT_X, geometry.LEFT_X,
LOAD_Y, LOAD_Y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
@ -158,7 +158,7 @@ return function(update_freq)
end end
common.text_rows_set(cpu_status, 2, cpu.read_freq()) common.text_rows_set(cpu_status, 2, cpu.read_freq())
common.percent_timeseries_set(total_load, load_sum / ncpus * 100) common.tagged_percent_timeseries_set(total_load, load_sum / ncpus * 100)
for r = 1, NUM_ROWS do for r = 1, NUM_ROWS do
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
@ -181,7 +181,7 @@ return function(update_freq)
common.text_rows_draw_static(cpu_status, cr) common.text_rows_draw_static(cpu_status, cr)
line.draw(separator, cr) line.draw(separator, cr)
common.percent_timeseries_draw_static(total_load, cr) common.tagged_percent_timeseries_draw_static(total_load, cr)
texttable.draw_static(tbl, cr) texttable.draw_static(tbl, cr)
end end
@ -193,7 +193,7 @@ return function(update_freq)
end end
common.text_rows_draw_dynamic(cpu_status, cr) common.text_rows_draw_dynamic(cpu_status, cr)
common.percent_timeseries_draw_dynamic(total_load, cr) common.tagged_percent_timeseries_draw_dynamic(total_load, cr)
texttable.draw_dynamic(tbl, cr) texttable.draw_dynamic(tbl, cr)
end end

View File

@ -93,13 +93,13 @@ return function(update_freq)
local draw_static = function(cr) local draw_static = function(cr)
common.draw_header(cr, header) common.draw_header(cr, header)
common.labeled_scale_plot_draw_static(reads, cr) common.tagged_scaled_timeseries_draw_static(reads, cr)
common.labeled_scale_plot_draw_static(writes, cr) common.tagged_scaled_timeseries_draw_static(writes, cr)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
common.labeled_scale_plot_draw_dynamic(reads, cr) common.tagged_scaled_timeseries_draw_dynamic(reads, cr)
common.labeled_scale_plot_draw_dynamic(writes, cr) common.tagged_scaled_timeseries_draw_dynamic(writes, cr)
end end
return {static = draw_static, dynamic = draw_dynamic, update = update} return {static = draw_static, dynamic = draw_dynamic, update = update}