ENH make plot heights/y ticks configurable per modules

This commit is contained in:
Nathan Dwarshuis 2022-08-16 23:49:13 -04:00
parent fb79ea899d
commit 4b5f289b99
9 changed files with 155 additions and 136 deletions

View File

@ -11,8 +11,8 @@ let TextGeo = { Type = { text_spacing : Natural }, default.text_spacing = 20 }
let SepGeo = { Type = { sep_spacing : Natural }, default.sep_spacing = 20 }
let PlotGeo_ =
{ Type = { sec_break : Natural, height : Natural }
, default = { sec_break = 20, height = 56 }
{ Type = { sec_break : Natural, height : Natural, ticks_y : Natural }
, default = { sec_break = 20, height = 56, ticks_y = 4 }
}
let PlotGeo = { Type = { plot : PlotGeo_.Type }, default.plot = PlotGeo_::{=} }
@ -156,10 +156,9 @@ let PlotGeometry =
{ spacing : Natural
, height : Natural
, seconds : Natural
, ticks : Vector2 Natural
, ticks_x : Natural
}
, default =
{ seconds = 90, ticks = { x = 9, y = 4 }, height = 56, spacing = 20 }
, default = { seconds = 90, ticks_x = 9, height = 56, spacing = 20 }
}
let TableGeometry =

View File

@ -103,19 +103,23 @@ return function(config)
-----------------------------------------------------------------------------
-- timeseries helper functions
local _default_grid_config = timeseries.grid_config(
geometry.plot.ticks.x,
geometry.plot.ticks.y,
patterns.plot.grid
)
local _default_grid_config = function(ticks_y)
return timeseries.grid_config(
geometry.plot.ticks_x,
ticks_y,
patterns.plot.grid
)
end
local _default_plot_config = timeseries.config(
geometry.plot.seconds,
patterns.plot.outline,
patterns.plot.data.border,
patterns.plot.data.fill,
_default_grid_config
)
local _default_plot_config = function(ticks_y)
return timeseries.config(
geometry.plot.seconds,
patterns.plot.outline,
patterns.plot.data.border,
patterns.plot.data.fill,
_default_grid_config(ticks_y)
)
end
local _format_percent_label = function(_)
return function(z) return __string_format('%i%%', math.floor(z * 100)) end
@ -131,18 +135,20 @@ return function(config)
_format_percent_label
)
local _make_timeseries = function(x, y, w, h, label_config, update_freq)
local _make_timeseries = function(x, y, w, h, ticks_y, label_config, update_freq)
return timeseries.make(
geom.make_box(x, y, w, h),
update_freq,
_default_plot_config,
_default_plot_config(ticks_y),
label_config
)
end
local gplot = geometry.plot
local _make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq, _format)
local _make_tagged_percent_timeseries = function(x, y, w, h, ticks_y,
spacing, label, update_freq,
_format)
return {
label = _left_text(geom.make_point(x, y), label),
value = text_threshold.make_formatted(
@ -157,6 +163,7 @@ return function(config)
y + _maybe_config(gplot.spacing, spacing),
w,
_maybe_config(gplot.height, h),
ticks_y,
update_freq
),
}
@ -169,11 +176,11 @@ return function(config)
return scaled_timeseries.scaling_parameters(2, m, 0.9)
end
local _make_scaled_timeseries = function(x, y, w, h, f, min_domain, update_freq)
local _make_scaled_timeseries = function(x, y, w, h, ticks_y, f, min_domain, update_freq)
return scaled_timeseries.make(
geom.make_box(x, y, w, h),
update_freq,
_default_plot_config,
_default_plot_config(ticks_y),
timeseries.label_config(patterns.text.inactive, label_font_spec, f),
_base_2_scale_data(min_domain)
)
@ -216,22 +223,24 @@ return function(config)
-----------------------------------------------------------------------------
-- percent timeseries
M.make_percent_timeseries = function(x, y, w, h, update_freq)
return _make_timeseries(x, y, w, h, _percent_label_config, update_freq)
M.make_percent_timeseries = function(x, y, w, h, ticks_y, update_freq)
return _make_timeseries(x, y, w, h, ticks_y, _percent_label_config, update_freq)
end
-----------------------------------------------------------------------------
-- tagged percent timeseries
M.make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq)
M.make_tagged_percent_timeseries = function(x, y, w, h, ticks_y, spacing,
label, update_freq)
return _make_tagged_percent_timeseries(
x, y, w, h, spacing, label, update_freq, '%s%%'
x, y, w, h, ticks_y, spacing, label, update_freq, '%s%%'
)
end
M.make_tagged_maybe_percent_timeseries = function(x, y, w, h, spacing, label, update_freq)
M.make_tagged_maybe_percent_timeseries = function(x, y, w, h, ticks_y,
spacing, label, update_freq)
return _make_tagged_percent_timeseries(
x, y, w, h, spacing, label, update_freq, _format_percent_maybe
x, y, w, h, ticks_y, spacing, label, update_freq, _format_percent_maybe
)
end
@ -294,9 +303,9 @@ return function(config)
-----------------------------------------------------------------------------
-- tagged scaled plot
M.make_tagged_scaled_timeseries = function(x, y, w, h, format_fun, label_fun,
spacing, label, min_domain,
update_freq)
M.make_tagged_scaled_timeseries = function(x, y, w, h, ticks_y, format_fun,
label_fun, spacing, label,
min_domain, update_freq)
return {
label = _left_text(geom.make_point(x, y), label),
value = text.make_formatted(
@ -310,6 +319,7 @@ return function(config)
y + spacing,
w,
h,
ticks_y,
label_fun,
min_domain,
update_freq
@ -341,8 +351,9 @@ return function(config)
end
end
M.make_rate_timeseries = function(x, y, w, h, format_fun, label_fun, spacing,
label, min_domain, update_freq, init)
M.make_rate_timeseries = function(x, y, w, h, ticks_y, format_fun,
label_fun, spacing, label, min_domain,
update_freq, init)
return {
label = _left_text(geom.make_point(x, y), label),
value = text.make_formatted(
@ -356,6 +367,7 @@ return function(config)
y + spacing,
w,
h,
ticks_y,
label_fun,
min_domain,
update_freq

View File

@ -3,10 +3,10 @@ local i_o = require 'i_o'
return function(update_freq, config, common, width, point)
local geo = config.geometry
local SEPARATOR_SPACING = geo.sep_spacing
local TEXT_SPACING = geo.text_spacing
local PLOT_SEC_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local sep_spacing = geo.sep_spacing
local text_spacing = geo.text_spacing
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
local NA = 'N/A'
local NVIDIA_EXE = 'nvidia-settings'
local __string_match = string.match
@ -89,8 +89,9 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
PLOT_SEC_BREAK,
plot_height,
geo.plot.ticks_y,
plot_sec_break,
label,
update_freq
)
@ -103,7 +104,7 @@ return function(update_freq, config, common, width, point)
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
plot_height + plot_sec_break,
update,
static,
dynamic
@ -155,7 +156,7 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
TEXT_SPACING,
text_spacing,
{'GPU Clock Speed', 'Memory Clock Speed'}
)
local update = function()
@ -169,7 +170,7 @@ return function(update_freq, config, common, width, point)
end
local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return common.mk_acc(width, TEXT_SPACING, update, static, dynamic)
return common.mk_acc(width, text_spacing, update, static, dynamic)
end
-----------------------------------------------------------------------------
@ -207,19 +208,19 @@ return function(update_freq, config, common, width, point)
point = point,
width = width,
set_state = update_state,
top = {{mk_status, true, SEPARATOR_SPACING}},
top = {{mk_status, true, sep_spacing}},
common.mk_section(
SEPARATOR_SPACING,
{mk_temp, config.show_temp, SEPARATOR_SPACING}
sep_spacing,
{mk_temp, config.show_temp, sep_spacing}
),
common.mk_section(
SEPARATOR_SPACING,
{mk_clock, config.show_clock, SEPARATOR_SPACING}
sep_spacing,
{mk_clock, config.show_clock, sep_spacing}
),
common.mk_section(
SEPARATOR_SPACING,
{mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK},
{mk_mem_util, config.show_mem_util, PLOT_SEC_BREAK},
sep_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}
)
}

View File

@ -6,14 +6,14 @@ local sys = require 'sys'
return function(update_freq, config, common, width, point)
local geo = config.geometry
local DIAL_THICKNESS = 8
local DIAL_RADIUS = 32
local DIAL_X_SPACING = 40
local CACHE_Y_OFFSET = 7
local CACHE_X_OFFSET = 50
local PLOT_SECTION_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local TABLE_SECTION_BREAK = geo.table.sec_break
local dial_thickness = 8
local dial_radius = 32
local dial_x_spacing = 40
local cache_y_offset = 7
local cache_x_offset = 50
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
local table_sec_break = geo.table.sec_break
local __math_floor = math.floor
local __string_format = string.format
@ -49,33 +49,33 @@ return function(update_freq, config, common, width, point)
-- mem stats (dial + text)
local mk_stats = function(y)
local MEM_X = point.x + DIAL_RADIUS + DIAL_THICKNESS / 2
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
local CACHE_X
local SWAP_X
local mem_x = point.x + dial_radius + dial_thickness / 2
local dial_diameter = dial_radius * 2 + dial_thickness
local cache_x
local swap_x
if _show_swap == true then
SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_X_SPACING
CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
swap_x = mem_x + dial_diameter + dial_x_spacing
cache_x = swap_x + cache_x_offset + dial_diameter / 2
else
CACHE_X = MEM_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
cache_x = mem_x + cache_x_offset + dial_diameter / 2
end
local CACHE_WIDTH = point.x + width - CACHE_X
local cache_width = point.x + width - cache_x
local format_percent = pure.partial(__string_format, '%i%%', true)
-- memory bits (used no matter what)
local mem = common.make_dial(
MEM_X,
y + DIAL_RADIUS,
DIAL_RADIUS,
DIAL_THICKNESS,
mem_x,
y + dial_radius,
dial_radius,
dial_thickness,
80,
format_percent,
__math_floor
)
local cache = common.make_text_rows_formatted(
CACHE_X,
y + CACHE_Y_OFFSET,
CACHE_WIDTH,
cache_x,
y + cache_y_offset,
cache_width,
geo.text_spacing,
{'Page Cache', 'Buffers', 'Shared', 'Kernel Slab'},
'%.1f%%'
@ -98,15 +98,15 @@ return function(update_freq, config, common, width, point)
common.dial_draw_dynamic(mem, cr)
common.text_rows_draw_dynamic(cache, cr)
end
local ret = pure.partial(common.mk_acc, width, DIAL_DIAMETER)
local ret = pure.partial(common.mk_acc, width, dial_diameter)
-- add swap bits if needed
if _show_swap == true then
local swap = common.make_dial(
SWAP_X,
y + DIAL_RADIUS,
DIAL_RADIUS,
DIAL_THICKNESS,
swap_x,
y + dial_radius,
dial_radius,
dial_thickness,
80,
format_percent,
__math_floor
@ -135,12 +135,13 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
plot_height,
geo.plot.ticks_y,
update_freq
)
return common.mk_acc(
width,
PLOT_HEIGHT,
plot_height,
function() timeseries.update(obj, mod_state.mem.used_percent) end,
pure.partial(timeseries.draw_static, obj),
pure.partial(timeseries.draw_dynamic, obj)
@ -152,14 +153,15 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
PLOT_SECTION_BREAK,
plot_height,
geo.plot.ticks_y,
plot_sec_break,
"Total Memory",
update_freq
)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SECTION_BREAK,
plot_height + plot_sec_break,
function()
common.tagged_percent_timeseries_set(
obj,
@ -216,8 +218,8 @@ return function(update_freq, config, common, width, point)
width = width,
set_state = read_state,
top = {
{mk_stats, config.show_stats, PLOT_SECTION_BREAK},
{mk_plot, config.show_plot, TABLE_SECTION_BREAK},
{mk_stats, config.show_stats, plot_sec_break},
{mk_plot, config.show_plot, table_sec_break},
{mk_tbl, config.table_rows > 0, 0},
}
}

View File

@ -5,8 +5,8 @@ local sys = require 'sys'
return function(update_freq, config, common, width, point)
local geo = config.geometry
local PLOT_SEC_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
local interface_paths = sys.get_net_interface_paths()
local get_bits = function(path)
@ -41,10 +41,11 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
plot_height,
geo.plot.ticks_y,
value_format_function,
common.converted_y_label_format_generator('b'),
PLOT_SEC_BREAK,
plot_sec_break,
label,
2,
update_freq,
@ -52,7 +53,7 @@ return function(update_freq, config, common, width, point)
)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
plot_height + plot_sec_break,
function() common.update_rate_timeseries(obj, mod_state[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
@ -71,7 +72,7 @@ return function(update_freq, config, common, width, point)
width = width,
set_state = read_interfaces,
top = {
{mk_rx, true, PLOT_SEC_BREAK},
{mk_rx, true, plot_sec_break},
{mk_tx, true, 0},
}
}

View File

@ -4,8 +4,8 @@ local sys = require 'sys'
return function(update_freq, config, common, width, point)
local geo = config.geometry
local PLOT_SEC_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
local power_label_function = function(plot_max)
local fmt = common.y_label_format_string(plot_max, 'W')
@ -30,10 +30,11 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
plot_height,
geo.plot.ticks_y,
format_rapl,
power_label_function,
PLOT_SEC_BREAK,
plot_sec_break,
label,
0,
update_freq,
@ -41,7 +42,7 @@ return function(update_freq, config, common, width, point)
)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
plot_height + plot_sec_break,
function(_) common.update_rate_timeseries(obj, read_joules()) end,
mk_static(obj),
mk_dynamic(obj)
@ -72,17 +73,18 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
plot_height,
geo.plot.ticks_y,
format_ac,
power_label_function,
PLOT_SEC_BREAK,
plot_sec_break,
'Battery Draw',
0,
update_freq
)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
plot_height + plot_sec_break,
function()
common.tagged_scaled_timeseries_set(
obj,

View File

@ -7,16 +7,16 @@ local pure = require 'pure'
local __math_floor = math.floor
return function(update_freq, main_state, config, common, width, point)
local dial_inner_radius = 30
local dial_outer_radius = 42
local dial_thickness = 5.5
local dial_y_spacing = 20
local geo = config.geometry
local DIAL_INNER_RADIUS = 30
local DIAL_OUTER_RADIUS = 42
local DIAL_THICKNESS = 5.5
local DIAL_Y_SPACING = 20
local SEPARATOR_SPACING = geo.sep_spacing
local TEXT_SPACING = geo.text_spacing
local PLOT_SECTION_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local TABLE_SECTION_BREAK = geo.table.sec_break
local sep_spacing = geo.sep_spacing
local text_spacing = geo.text_spacing
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
-----------------------------------------------------------------------------
-- processor state
@ -52,26 +52,26 @@ return function(update_freq, main_state, config, common, width, point)
local dial_x = point.x +
(core_cols == 1
and (width / 2)
or (config.core_padding + DIAL_OUTER_RADIUS +
(width - 2 * (DIAL_OUTER_RADIUS + config.core_padding))
or (config.core_padding + dial_outer_radius +
(width - 2 * (dial_outer_radius + config.core_padding))
* math.fmod(c - 1, core_cols) / (core_cols - 1)))
local dial_y = y + DIAL_OUTER_RADIUS +
(2 * DIAL_OUTER_RADIUS + DIAL_Y_SPACING)
local dial_y = y + dial_outer_radius +
(2 * dial_outer_radius + dial_y_spacing)
* math.floor((c - 1) / core_cols)
return {
loads = common.make_compound_dial(
dial_x,
dial_y,
DIAL_OUTER_RADIUS,
DIAL_INNER_RADIUS,
DIAL_THICKNESS,
dial_outer_radius,
dial_inner_radius,
dial_thickness,
80,
nthreads
),
coretemp = common.make_text_circle(
dial_x,
dial_y,
DIAL_INNER_RADIUS - 2,
dial_inner_radius - 2,
'%s°C',
80,
__math_floor
@ -116,8 +116,8 @@ return function(update_freq, main_state, config, common, width, point)
end
return common.mk_acc(
width,
(DIAL_OUTER_RADIUS * 2 + DIAL_Y_SPACING) * config.core_rows
- DIAL_Y_SPACING,
(dial_outer_radius * 2 + dial_y_spacing) * config.core_rows
- dial_y_spacing,
update,
static,
dynamic
@ -133,7 +133,7 @@ return function(update_freq, main_state, config, common, width, point)
point.x,
y,
width,
TEXT_SPACING,
text_spacing,
{'HWP Preference', 'Ave Freq'}
)
local update = function()
@ -149,7 +149,7 @@ return function(update_freq, main_state, config, common, width, point)
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
return common.mk_acc(
width,
TEXT_SPACING,
text_spacing,
update,
static,
dynamic
@ -164,8 +164,9 @@ return function(update_freq, main_state, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
PLOT_SECTION_BREAK,
plot_height,
geo.plot.ticks_y,
plot_sec_break,
"Total Load",
update_freq
)
@ -178,7 +179,7 @@ return function(update_freq, main_state, config, common, width, point)
end
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SECTION_BREAK,
plot_height + plot_sec_break,
update,
pure.partial(common.tagged_percent_timeseries_draw_static, total_load),
pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load)
@ -230,12 +231,12 @@ return function(update_freq, main_state, config, common, width, point)
width = width,
set_state = update_state,
top = {
{mk_cores, show_cores, TEXT_SPACING},
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
{mk_cores, show_cores, text_spacing},
{mk_hwp_freq, config.show_stats, sep_spacing},
},
common.mk_section(
SEPARATOR_SPACING,
{mk_load_plot, config.show_plot, TABLE_SECTION_BREAK},
sep_spacing,
{mk_load_plot, config.show_plot, geo.table.sec_break},
{mk_tbl, config.table_rows > 0, 0}
)
}

View File

@ -6,8 +6,8 @@ local impure = require 'impure'
return function(update_freq, config, common, width, point)
local geo = config.geometry
local PLOT_SEC_BREAK = geo.plot.sec_break
local PLOT_HEIGHT = geo.plot.height
local plot_sec_break = geo.plot.sec_break
local plot_height = geo.plot.height
local mod_state = {read = 0, write = 0}
local device_paths = sys.get_disk_paths(config.devices)
@ -34,10 +34,11 @@ return function(update_freq, config, common, width, point)
point.x,
y,
width,
PLOT_HEIGHT,
plot_height,
geo.plot.ticks_y,
format_value_function,
common.converted_y_label_format_generator('B'),
PLOT_SEC_BREAK,
plot_sec_break,
label,
2,
update_freq,
@ -45,7 +46,7 @@ return function(update_freq, config, common, width, point)
)
return common.mk_acc(
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
plot_height + plot_sec_break,
function() common.update_rate_timeseries(obj, mod_state[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
@ -64,7 +65,7 @@ return function(update_freq, config, common, width, point)
width = width,
set_state = update_state,
top = {
{mk_reads, true, PLOT_SEC_BREAK},
{mk_reads, true, plot_sec_break},
{mk_writes, true, 0},
}
}

View File

@ -2,7 +2,7 @@ local i_o = require 'i_o'
local pure = require 'pure'
return function(main_state, config, common, width, point)
local TEXT_SPACING = config.geometry.text_spacing
local text_spacing = config.geometry.text_spacing
local __string_match = string.match
@ -11,7 +11,7 @@ return function(main_state, config, common, width, point)
point.x,
y,
width,
TEXT_SPACING,
text_spacing,
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
)
-- just update this once
@ -35,7 +35,7 @@ return function(main_state, config, common, width, point)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return common.mk_acc(
width,
TEXT_SPACING * 3,
text_spacing * 3,
update,
static,
dynamic