diff --git a/src/modules/graphics.lua b/src/modules/graphics.lua index 87e8d4f..55dce11 100644 --- a/src/modules/graphics.lua +++ b/src/modules/graphics.lua @@ -1,5 +1,5 @@ -local pure = require 'pure' -local i_o = require 'i_o' +local pure = require 'pure' +local i_o = require 'i_o' return function(update_freq, config, common, width, point) local NA = 'N/A' diff --git a/src/modules/processor.lua b/src/modules/processor.lua index 2bbc05e..d1d0d7e 100644 --- a/src/modules/processor.lua +++ b/src/modules/processor.lua @@ -31,21 +31,22 @@ return function(update_freq, main_state, config, common, width, point) mod_state = cpu.read_cpu_loads(mod_state) end + -- test that the core groups we want are actually displayable + for _, g in pairs(config.core_groups) do + i_o.assertf( + topology[g.threads] ~= nil, + 'processor: no group with %s threads', 1 + ) + local ncores = #topology[g.threads] + i_o.assertf( + math.fmod(ncores, g.rows) == 0, + 'processor: could not evenly divide %s cores into %s rows', ncores, g.rows + ) + end + ----------------------------------------------------------------------------- -- cores (loads and temps) - -- TODO add this back - -- local is_evenly_distributed = function(ncores, rows) - -- if rows == 0 then - -- return false - -- elseif math.fmod(ncores, rows) == 0 then - -- return true - -- else - -- i_o.warnf('could not evenly distribute %i cores over %i rows', ncores, rows) - -- return false - -- end - -- end - local create_core = function(core_cols, y, nthreads, padding, c) local dial_x = point.x + (core_cols == 1 diff --git a/src/sys.lua b/src/sys.lua index 175c945..d83b0a3 100644 --- a/src/sys.lua +++ b/src/sys.lua @@ -88,10 +88,10 @@ end -------------------------------------------------------------------------------- -- intel powercap -local SYSFS_RAPL = '/sys/class/powercap' +M.SYSFS_RAPL = '/sys/class/powercap' M.intel_powercap_reader = function(dev) - local uj = __string_format('%s/%s/energy_uj', SYSFS_RAPL, dev) + local uj = __string_format('%s/%s/energy_uj', M.SYSFS_RAPL, dev) i_o.assert_file_readable(uj) return function() return read_micro(uj) end end @@ -99,10 +99,10 @@ end -------------------------------------------------------------------------------- -- battery -local SYSFS_POWER = '/sys/class/power_supply' +M.SYSFS_POWER = '/sys/class/power_supply' local format_power_path = function(battery, property) - local p = __string_format('%s/%s/%s', SYSFS_POWER, battery, property) + local p = __string_format('%s/%s/%s', M.SYSFS_POWER, battery, property) i_o.assert_file_readable(p) return p end diff --git a/src/validate.lua b/src/validate.lua index 1c1d6be..e5547e8 100644 --- a/src/validate.lua +++ b/src/validate.lua @@ -3,6 +3,7 @@ local M = {} local err = require 'err' local i_o = require 'i_o' local pure = require 'pure' +local sys = require 'sys' M.assert_non_nil = function(what, x) i_o.assertf(x ~= nil, '%s: %f must not be nil', what, x) @@ -98,6 +99,15 @@ M.assert_color_stop_alpha = function(what, x) M.assert_unit_fraction(what..'.alpha', x.alpha) end +M.assert_file_exists = function(what, path) + i_o.assertf(i_o.file_exists(path), '%s: %s does not exist', what, path) +end + +M.assert_file_readable = function(what, path) + M.assert_file_exists(what, path) + i_o.assertf(i_o.file_readable(path), '%s: %s is not readable', what, path) +end + M.assert_valid_pattern = function(what, pat) local t = pat.type if t == "RGB" then @@ -120,34 +130,52 @@ end -- TODO make spacing parameters aware of thickness, right now they start at the -- centry of lines, circles, etc. -local validate_filesystem = function(x, width) - -- TODO ensure paths exist here - M.assert_greater_than('filesystem.bar_spacing', x.geometry.bar_spacing, 10) - M.assert_between('filesystem.bar_pad', x.geometry.bar_pad, 20, width) +local validate_filesystem = function(x) + for _, f in pairs(x.fs_paths) do + M.assert_file_exists('filesystem.fs_paths', f.path) + end end local validate_graphics = function(x) + M.assert_file_readable('graphics.dev_power', x.dev_power) + M.assert_greater_than('graphics.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) end local validate_memory = function(x) + M.assert_greater_than('memory.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) end local validate_network = function(x) + M.assert_greater_than('network.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) end -local validate_pacman = function(x) +local validate_pacman = function(_) + -- nothing to check here end local validate_power = function(x) + M.assert_file_readable('power.battery', sys.SYSFS_POWER..'/'..x.battery) + for _, f in pairs(x.rapl_specs) do + M.assert_file_readable('power.rapl_specs', sys.SYSFS_RAPL..'/'..f.address) + end + M.assert_greater_than('power.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) end local validate_processor = function(x) + -- NOTE need to check that the processor groups actually exist after querying + -- the cpu in the module + M.assert_greater_than('processor.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) + for _, c in pairs(x.core_groups) do + M.assert_greater_than('processor.core_groups.[].rows', c.rows, 0) + end end local validate_readwrite = function(x) + M.assert_greater_than('readwrite.genometry.plot.ticks_y', x.geometry.plot.ticks_y, 2) end -local validate_system = function(x) +local validate_system = function(_) + -- nothing to check here end M.validate_config = function(config) @@ -195,7 +223,7 @@ M.validate_config = function(config) local t = block.type local d = block.data if t == "filesystem" then - validate_filesystem(d, column.width) + validate_filesystem(d) elseif t == "graphics" then validate_graphics(d) elseif t == "memory" then diff --git a/src/widget/text/text_internal.lua b/src/widget/text/text_internal.lua index 51e5db3..9486121 100644 --- a/src/widget/text/text_internal.lua +++ b/src/widget/text/text_internal.lua @@ -130,6 +130,7 @@ M.get_delta_y = function(y_align, font) local fe = set_font_extents(font) local descents = { top = fe.height, + -- TODO this 92 thing shouldn't be hardcoded (probably) center = 0.92 * fe.height * 0.5 - fe.descent, bottom = -fe.descent }