From e5e83c5b7952e1a40431f6dea7abdad5ca1f24ef Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 18 Jul 2022 00:36:44 -0400 Subject: [PATCH] ADD font and cpu core count to config --- config.yml | 15 ++++++--- drawing/common.lua | 26 ++++++++-------- drawing/memory.lua | 24 +++++++-------- drawing/processor.lua | 72 +++++++++++++++++++++++++++++-------------- schema.yml | 43 ++++++++++++++++++-------- 5 files changed, 115 insertions(+), 65 deletions(-) diff --git a/config.yml b/config.yml index 24f3058..d0e249a 100644 --- a/config.yml +++ b/config.yml @@ -17,17 +17,18 @@ modules: memory: show_stats: true show_plot: true - show_table: true + table_rows: 5 power: battery: BAT0 rapl_specs: - {name: PKG0, address: intel-rapl:0} - {name: DRAM, address: intel-rapl:0:2} processor: - show_cores: true + core_rows: 1 + core_padding: 0 show_stats: true show_plot: true - show_table: true + table_rows: 5 readwrite: devices: [sda, nvme0n1] @@ -49,7 +50,13 @@ layout: margins: [20, 10] theme: - font: Neuropolitical + font: + family: Neuropolitical + sizes: + normal: 13 + plot_label: 8 + table: 11 + header: 15 patterns: header: 0xefefef panel: diff --git a/drawing/common.lua b/drawing/common.lua index 58535bc..d4de6cc 100644 --- a/drawing/common.lua +++ b/drawing/common.lua @@ -56,17 +56,13 @@ return function(config) local M = {} local patterns = compile_patterns(config.theme.patterns) + local font = config.theme.font + local font_sizes = font.sizes + local font_family = font.family ----------------------------------------------------------------------------- -- constants - local FONT = config.theme.font - - local NORMAL_FONT_SIZE = 13 - local PLOT_LABEL_FONT_SIZE = 8 - local TABLE_FONT_SIZE = 11 - local HEADER_FONT_SIZE = 15 - local HEADER_HEIGHT = 45 local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND local HEADER_UNDERLINE_OFFSET = 26 @@ -103,13 +99,13 @@ return function(config) return { family = f, size = size, - weight = bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL, - slant = CAIRO_FONT_WEIGHT_NORMAL, + weight = bold and CAIRO_font_family_WEIGHT_BOLD or CAIRO_font_family_WEIGHT_NORMAL, + slant = CAIRO_font_family_WEIGHT_NORMAL, } end - local normal_font_spec = make_font_spec(FONT, NORMAL_FONT_SIZE, false) - local label_font_spec = make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false) + local normal_font_spec = make_font_spec(font_family, font_sizes.normal, false) + local label_font_spec = make_font_spec(font_family, font_sizes.plot_label, false) local _text_row_style = function(x_align, color) return text.config(normal_font_spec, color, x_align, 'center') @@ -218,7 +214,7 @@ return function(config) geom.make_point(x, y), _text, text.config( - make_font_spec(FONT, HEADER_FONT_SIZE, true), + make_font_spec(font_family, font_sizes.header, true), patterns.header, 'left', 'top' @@ -629,7 +625,7 @@ return function(config) ----------------------------------------------------------------------------- -- table - local default_table_font_spec = make_font_spec(FONT, TABLE_FONT_SIZE, false) + local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false) local default_table_config = function(label) return tbl.config( @@ -673,6 +669,10 @@ return function(config) ) end + M.table_height = function(n) + return TABLE_VERT_PAD * 2 + TABLE_HEADER_PAD + 13 * n + end + ----------------------------------------------------------------------------- -- panel diff --git a/drawing/memory.lua b/drawing/memory.lua index a751467..807b396 100644 --- a/drawing/memory.lua +++ b/drawing/memory.lua @@ -13,7 +13,6 @@ return function(update_freq, config, common, width, point) local PLOT_SECTION_BREAK = 22 local PLOT_HEIGHT = 56 local TABLE_SECTION_BREAK = 20 - local TABLE_HEIGHT = 114 local __string_match = string.match local __math_floor = math.floor @@ -141,8 +140,9 @@ return function(update_freq, config, common, width, point) -- memory top table local mk_tbl = function(y) - local NUM_ROWS = 5 - local TABLE_CONKY = pure.map_n( + local num_rows = config.table_rows + local table_height = common.table_height(num_rows) + local table_conky = pure.map_n( function(i) return { comm = '${top_mem name '..i..'}', @@ -150,25 +150,25 @@ return function(update_freq, config, common, width, point) mem = '${top_mem mem '..i..'}', } end, - NUM_ROWS) + num_rows) local obj = common.make_text_table( point.x, y, width, - TABLE_HEIGHT, - NUM_ROWS, + table_height, + num_rows, 'Mem (%)' ) local update = function() - for r = 1, NUM_ROWS do - text_table.set(obj, 1, r, i_o.conky(TABLE_CONKY[r].comm, '(%S+)')) - text_table.set(obj, 2, r, i_o.conky(TABLE_CONKY[r].pid)) - text_table.set(obj, 3, r, i_o.conky(TABLE_CONKY[r].mem)) + for r = 1, num_rows do + text_table.set(obj, 1, r, i_o.conky(table_conky[r].comm, '(%S+)')) + text_table.set(obj, 2, r, i_o.conky(table_conky[r].pid)) + text_table.set(obj, 3, r, i_o.conky(table_conky[r].mem)) end end return common.mk_acc( width, - TABLE_HEIGHT, + table_height, update, pure.partial(text_table.draw_static, obj), pure.partial(text_table.draw_dynamic, obj) @@ -186,7 +186,7 @@ return function(update_freq, config, common, width, point) top = { {mk_stats, config.show_stats, PLOT_SECTION_BREAK}, {mk_plot, config.show_plot, TABLE_SECTION_BREAK}, - {mk_tbl, config.show_table, 0}, + {mk_tbl, config.table_rows > 0, 0}, } } end diff --git a/drawing/processor.lua b/drawing/processor.lua index 95dc495..d37e149 100644 --- a/drawing/processor.lua +++ b/drawing/processor.lua @@ -10,12 +10,12 @@ return function(update_freq, config, main_state, common, width, point) local DIAL_INNER_RADIUS = 30 local DIAL_OUTER_RADIUS = 42 local DIAL_THICKNESS = 5.5 + local DIAL_SPACING = 20 local SEPARATOR_SPACING = 20 local TEXT_SPACING = 22 local PLOT_SECTION_BREAK = 23 local PLOT_HEIGHT = 56 local TABLE_SECTION_BREAK = 20 - local TABLE_HEIGHT = 114 ----------------------------------------------------------------------------- -- processor state @@ -33,6 +33,22 @@ return function(update_freq, config, main_state, common, width, point) local ncores = cpu.get_core_number() local nthreads = ncpus / ncores + local show_cores = false + + if config.core_rows > 0 then + if math.fmod(ncores, config.core_rows) == 0 then + show_cores = true + else + print( + string.format( + 'WARNING: could not evenly distribute %i cores over %i rows', + ncores, + config.core_rows + ) + ) + end + end + local create_core = function(x, y) return { loads = common.make_compound_dial( @@ -57,12 +73,23 @@ return function(update_freq, config, main_state, common, width, point) local mk_cores = function(y) local coretemp_paths = cpu.get_coretemp_paths() + local core_cols = ncores / config.core_rows local cores = {} - -- TODO what happens when the number of cores changes? for c = 1, ncores do - local dial_x = point.x + DIAL_OUTER_RADIUS + - (width - 2 * DIAL_OUTER_RADIUS) * (c - 1) / 3 - local dial_y = y + DIAL_OUTER_RADIUS + local dial_x + local dial_y + if core_cols == 1 then + dial_x = point.x + width / 2 + dial_y = y + DIAL_OUTER_RADIUS + + (2 * DIAL_OUTER_RADIUS + DIAL_SPACING) * (c - 1) + else + dial_x = point.x + config.core_padding + DIAL_OUTER_RADIUS + + (width - 2 * (DIAL_OUTER_RADIUS + config.core_padding)) + * math.fmod(c - 1, core_cols) / (core_cols - 1) + dial_y = y + DIAL_OUTER_RADIUS + + (2 * DIAL_OUTER_RADIUS + DIAL_SPACING) + * math.floor((c - 1) / core_cols) / (core_cols - 1) + end cores[c] = create_core(dial_x, dial_y) end local update = function() @@ -92,7 +119,8 @@ return function(update_freq, config, main_state, common, width, point) end return common.mk_acc( width, - DIAL_OUTER_RADIUS * 2, + (DIAL_OUTER_RADIUS * 2 + DIAL_SPACING) * config.core_rows + - DIAL_SPACING, update, static, dynamic @@ -166,38 +194,36 @@ return function(update_freq, config, main_state, common, width, point) -- cpu top table local mk_tbl = function(y) - local NUM_ROWS = 5 - local TABLE_CONKY = pure.map_n( + local num_rows = config.table_rows + local table_height = common.table_height(num_rows) + local table_conky = pure.map_n( function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end, - NUM_ROWS + num_rows ) local tbl = common.make_text_table( point.x, y, width, - TABLE_HEIGHT, - NUM_ROWS, + table_height, + num_rows, 'CPU (%)' ) - local update = function(state_) - for r = 1, NUM_ROWS do - local pid = i_o.conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces + local update = function() + for r = 1, num_rows do + local pid = i_o.conky(table_conky[r].pid, '(%d+)') -- may have leading spaces if pid ~= '' then text_table.set(tbl, 1, r, i_o.read_file('/proc/'..pid..'/comm', '(%C+)')) text_table.set(tbl, 2, r, pid) - text_table.set(tbl, 3, r, i_o.conky(TABLE_CONKY[r].cpu)) + text_table.set(tbl, 3, r, i_o.conky(table_conky[r].cpu)) end end - return state_ end - local static = pure.partial(text_table.draw_static, tbl) - local dynamic = pure.partial(text_table.draw_dynamic, tbl) return common.mk_acc( width, - TABLE_HEIGHT, + table_height, update, - static, - dynamic + pure.partial(text_table.draw_static, tbl), + pure.partial(text_table.draw_dynamic, tbl) ) end @@ -210,13 +236,13 @@ return function(update_freq, config, main_state, common, width, point) width = width, set_state = update_state, top = { - {mk_cores, config.show_cores, TEXT_SPACING}, + {mk_cores, show_cores, TEXT_SPACING}, {mk_hwp_freq, config.show_stats, SEPARATOR_SPACING}, }, common.mk_section( SEPARATOR_SPACING, {mk_load_plot, config.show_plot, TABLE_SECTION_BREAK}, - {mk_tbl, config.show_table, 0} + {mk_tbl, config.table_rows > 0, 0} ) } end diff --git a/schema.yml b/schema.yml index 937d98e..06b7fc1 100644 --- a/schema.yml +++ b/schema.yml @@ -49,7 +49,7 @@ properties: type: boolean memory: - required: [show_stats, show_plot, show_table] + required: [show_stats, show_plot, table_rows] additionalProperties: false properties: show_stats: @@ -58,9 +58,10 @@ properties: show_plot: description: show the RAM utilization plot type: boolean - show_table: - description: show the memory process table - type: boolean + table_rows: &table + descrition: the number of rows in the table (0 for no table) + type: integer + minimum: 0 power: required: [battery, rapl_specs] @@ -85,21 +86,24 @@ properties: type: string processor: - required: [show_cores, show_stats, show_plot, show_table] + required: [core_rows, show_stats, show_plot, table_rows] additionalProperties: false properties: - show_cores: - description: show individual CPU cores - type: boolean + core_rows: + description: the number of rows over which to show discrete cores + type: integer + minimum: 0 + core_padding: + description: horizontal padding to apply to the core layout + type: integer + minimum: 0 show_stats: description: show frequency/HWP stats type: boolean show_plot: description: show CPU utilization plot type: boolean - show_table: - description: show the CPU process table - type: boolean + table_rows: *table readwrite: required: [devices] @@ -178,8 +182,21 @@ properties: additionalProperties: false properties: font: - description: the font to use - type: string + required: [family, sizes] + additionalProperties: false + properties: + family: + type: string + sizes: + required: [normal, plot_label, table, header] + additionalProperties: false + properties: + normal: &font_size + type: integer + minimum: 5 + plot_label: *font_size + table: *font_size + header: *font_size patterns: required: [header, panel, text, border, plot, indicator] additionalProperties: false