diff --git a/drawing/Common.lua b/drawing/Common.lua index e956a91..b4a7ead 100644 --- a/drawing/Common.lua +++ b/drawing/Common.lua @@ -137,10 +137,10 @@ M.percent_label_style = Startup.label_style( function(z) return Util.round_to_string(z * 100)..'%' end ) -M.initThemedLabelPlot = function(x, y, w, h, label_style) +M.initThemedLabelPlot = function(x, y, w, h, label_style, update_freq) return Startup.LabelPlot( Startup.make_box(x, y, w, h), - 1 / _G_INIT_DATA_.UPDATE_INTERVAL, + update_freq, M.default_plot_style, label_style ) @@ -149,7 +149,7 @@ end -------------------------------------------------------------------------------- -- percent plot (label plot with percent signs and some indicator data above it) -M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format) +M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, update_freq, format) return { label = _left_text(Startup.make_point(x, y), label), value = Startup.formattedThresholdText( @@ -164,13 +164,14 @@ M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format) y + spacing, w, h, - M.percent_label_style + M.percent_label_style, + update_freq ), } end -M.initPercentPlot = function(x, y, w, h, spacing, label) - return M.initPercentPlot_formatted(x, y, w, h, spacing, label, '%s%%') +M.initPercentPlot = function(x, y, w, h, spacing, label, update_freq) + return M.initPercentPlot_formatted(x, y, w, h, spacing, label, update_freq, '%s%%') end M.percent_plot_draw_static = function(pp, cr) @@ -203,10 +204,10 @@ M.base_2_scale_data = function(m) return Startup.scale_data(2, m, 0.9) end -M.initThemedScalePlot = function(x, y, w, h, f, min_domain) +M.initThemedScalePlot = function(x, y, w, h, f, min_domain, update_freq) return Startup.ScalePlot( Startup.make_box(x, y, w, h), - 1 / _G_INIT_DATA_.UPDATE_INTERVAL, + update_freq, M.default_plot_style, Startup.label_style( Theme.INACTIVE_TEXT_FG, @@ -221,7 +222,7 @@ end -- scaled plot (with textual data above it) M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing, - label, min_domain) + label, min_domain, update_freq) return { label = _left_text(Startup.make_point(x, y), label), value = Startup.formatted_text( @@ -230,7 +231,7 @@ M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing, M.right_text_style, format_fun ), - plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain), + plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq), } end diff --git a/drawing/Graphics.lua b/drawing/Graphics.lua index 957ef0f..5102fbc 100644 --- a/drawing/Graphics.lua +++ b/drawing/Graphics.lua @@ -79,39 +79,13 @@ local separator3 = Common.initSeparator( local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_ -local gpu_util = Common.initPercentPlot_formatted( - Geometry.LEFT_X, - _GPU_UTIL_Y_, - Geometry.SECTION_WIDTH, - _PLOT_HEIGHT_, - _PLOT_SEC_BREAK_, - 'GPU Utilization', - na_percent_format -) local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 -local mem_util = Common.initPercentPlot_formatted( - Geometry.LEFT_X, - _MEM_UTIL_Y_, - Geometry.SECTION_WIDTH, - _PLOT_HEIGHT_, - _PLOT_SEC_BREAK_, - 'Memory Utilization', - na_percent_format -) + local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 -local vid_util = Common.initPercentPlot_formatted( - Geometry.LEFT_X, - _VID_UTIL_Y_, - Geometry.SECTION_WIDTH, - _PLOT_HEIGHT_, - _PLOT_SEC_BREAK_, - 'Video Utilization', - na_percent_format -) --[[ vars to process the nv settings glob @@ -136,87 +110,120 @@ local NV_REGEX = '(%d+)\n'.. '(%d+),(%d+)\n'.. 'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n' -local nvidia_off = function(cr) - Common.text_row_crit_set(internal_temp, cr, -1) - Common.text_rows_set(clock_speed, cr, 1, NA) - Common.text_rows_set(clock_speed, cr, 2, NA) - - Common.percent_plot_set(gpu_util, cr, nil) - Common.percent_plot_set(vid_util, cr, nil) - Common.percent_plot_set(mem_util, cr, nil) -end - local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control' -local update = function(cr) - 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 - Common.text_row_set(status, cr, 'On') +-- _MODULE_Y_ = nil +-- _SEPARATOR_SPACING_ = nil +-- _TEXT_SPACING_ = nil +-- _PLOT_SEC_BREAK_ = nil +-- _PLOT_HEIGHT_ = 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 - local used_memory, total_memory, temp_reading, gpu_frequency, - memory_frequency, gpu_utilization, vid_utilization - = __string_match(nvidia_settings_glob, NV_REGEX) +return function(update_freq) - Common.text_row_crit_set(internal_temp, cr, temp_reading) - Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz') - Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz') + local gpu_util = Common.initPercentPlot_formatted( + Geometry.LEFT_X, + _GPU_UTIL_Y_, + Geometry.SECTION_WIDTH, + _PLOT_HEIGHT_, + _PLOT_SEC_BREAK_, + 'GPU Utilization', + update_freq, + na_percent_format + ) - Common.percent_plot_set(gpu_util, cr, gpu_utilization) - Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100) - Common.percent_plot_set(vid_util, cr, vid_utilization) - end - else - Text.set(status.value, cr, 'Off') - nvidia_off(cr) + local mem_util = Common.initPercentPlot_formatted( + Geometry.LEFT_X, + _MEM_UTIL_Y_, + Geometry.SECTION_WIDTH, + _PLOT_HEIGHT_, + _PLOT_SEC_BREAK_, + 'Memory Utilization', + update_freq, + na_percent_format + ) + + local vid_util = Common.initPercentPlot_formatted( + Geometry.LEFT_X, + _VID_UTIL_Y_, + Geometry.SECTION_WIDTH, + _PLOT_HEIGHT_, + _PLOT_SEC_BREAK_, + 'Video Utilization', + update_freq, + na_percent_format + ) + + local nvidia_off = function(cr) + Common.text_row_crit_set(internal_temp, cr, -1) + Common.text_rows_set(clock_speed, cr, 1, NA) + Common.text_rows_set(clock_speed, cr, 2, NA) + Common.percent_plot_set(gpu_util, cr, nil) + Common.percent_plot_set(vid_util, cr, nil) + Common.percent_plot_set(mem_util, cr, nil) end -end -_MODULE_Y_ = nil -_SEPARATOR_SPACING_ = nil -_TEXT_SPACING_ = nil -_PLOT_SEC_BREAK_ = nil -_PLOT_HEIGHT_ = 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 + local update = function(cr) + 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 + Common.text_row_set(status, cr, 'On') -local draw_static = function(cr) - Common.drawHeader(cr, header) + local used_memory, total_memory, temp_reading, gpu_frequency, + memory_frequency, gpu_utilization, vid_utilization + = __string_match(nvidia_settings_glob, NV_REGEX) - Common.text_row_draw_static(status, cr) - Line.draw(separator1, cr) + Common.text_row_crit_set(internal_temp, cr, temp_reading) + Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz') + Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz') - Common.text_row_crit_draw_static(internal_temp, cr) - Line.draw(separator2, cr) + Common.percent_plot_set(gpu_util, cr, gpu_utilization) + Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100) + Common.percent_plot_set(vid_util, cr, vid_utilization) + end + else + Text.set(status.value, cr, 'Off') + nvidia_off(cr) + end + end - Common.text_rows_draw_static(clock_speed, cr) - Line.draw(separator3, cr) + local draw_static = function(cr) + Common.drawHeader(cr, header) - Common.percent_plot_draw_static(gpu_util, cr) - Common.percent_plot_draw_static(mem_util, cr) - Common.percent_plot_draw_static(vid_util, cr) -end + Common.text_row_draw_static(status, cr) + Line.draw(separator1, cr) -local draw_dynamic = function(cr) - update(cr) + Common.text_row_crit_draw_static(internal_temp, cr) + Line.draw(separator2, cr) - Common.text_row_draw_dynamic(status, cr) - Common.text_row_crit_draw_dynamic(internal_temp, cr) - Common.text_rows_draw_dynamic(clock_speed, cr) - Common.percent_plot_draw_dynamic(gpu_util, cr) - Common.percent_plot_draw_dynamic(mem_util, cr) - Common.percent_plot_draw_dynamic(vid_util, cr) -end + Common.text_rows_draw_static(clock_speed, cr) + Line.draw(separator3, cr) + + Common.percent_plot_draw_static(gpu_util, cr) + Common.percent_plot_draw_static(mem_util, cr) + Common.percent_plot_draw_static(vid_util, cr) + end + + local draw_dynamic = function(cr) + update(cr) + + Common.text_row_draw_dynamic(status, cr) + Common.text_row_crit_draw_dynamic(internal_temp, cr) + Common.text_rows_draw_dynamic(clock_speed, cr) + Common.percent_plot_draw_dynamic(gpu_util, cr) + Common.percent_plot_draw_dynamic(mem_util, cr) + Common.percent_plot_draw_dynamic(vid_util, cr) + end -return function() return {static = draw_static, dynamic = draw_dynamic} end diff --git a/drawing/Memory.lua b/drawing/Memory.lua index 7089ea4..fce338d 100644 --- a/drawing/Memory.lua +++ b/drawing/Memory.lua @@ -96,13 +96,6 @@ local cache = Common.initTextRows_color( local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2 -local plot = Common.initThemedLabelPlot( - Geometry.RIGHT_X, - _PLOT_Y_, - Geometry.SECTION_WIDTH, - _PLOT_HEIGHT_, - Common.percent_label_style -) local tbl = Common.initTable( Geometry.RIGHT_X, @@ -113,91 +106,102 @@ local tbl = Common.initTable( {'Name', 'PID', 'Mem (%)'} ) -local update = function(cr) - local conky = Util.conky - -- see source for the 'free' command (sysinfo.c) for formulas +-- _MODULE_Y_ = nil +-- _DIAL_THICKNESS_ = nil +-- _DIAL_SPACING_ = nil +-- _TEXT_Y_OFFSET_ = nil +-- _TEXT_LEFT_X_OFFSET_ = nil +-- _TEXT_SPACING_ = nil +-- _PLOT_SECTION_BREAK_ = nil +-- _PLOT_HEIGHT_ = nil +-- _TABLE_SECTION_BREAK_ = nil +-- _TABLE_HEIGHT_ = nil +-- _LINE_1_Y_ = nil +-- _TEXT_LEFT_X_ = nil +-- _RIGHT_X_ = nil +-- _PLOT_Y_ = nil - local memfree_kb, buffers_kb, cached_kb, swap_total_kb, swap_free_kb, - slab_reclaimable_kb = __string_match(Util.read_file('/proc/meminfo'), MEMINFO_REGEX) - - local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB - - Dial.set(dial, used_percent) - Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100)) - - local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1 - __cairo_path_destroy(cache_arc.path) - cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta) - - Common.text_row_crit_set(swap, cr, - Util.precision_round_to_string( - (swap_total_kb - swap_free_kb) - / swap_total_kb * 100)) - - Common.text_rows_set(cache, cr, 1, Util.precision_round_to_string( - cached_kb / MEM_TOTAL_KB * 100)) - - Common.text_rows_set(cache, cr, 2, Util.precision_round_to_string( - buffers_kb / MEM_TOTAL_KB * 100)) - - Common.text_rows_set(cache, cr, 3, Util.precision_round_to_string( - slab_reclaimable_kb / MEM_TOTAL_KB * 100)) - - LabelPlot.update(plot, used_percent) - - for r = 1, NUM_ROWS do - local comm = conky(TABLE_CONKY[r].comm, '(%S+)') -- may have trailing space - local pid = conky(TABLE_CONKY[r].pid) - local mem = conky(TABLE_CONKY[r].mem) - Table.set(tbl, cr, 1, r, comm) - Table.set(tbl, cr, 2, r, pid) - Table.set(tbl, cr, 3, r, mem) - end -end - -_MODULE_Y_ = nil -_DIAL_THICKNESS_ = nil -_DIAL_SPACING_ = nil -_TEXT_Y_OFFSET_ = nil -_TEXT_LEFT_X_OFFSET_ = nil -_TEXT_SPACING_ = nil -_PLOT_SECTION_BREAK_ = nil -_PLOT_HEIGHT_ = nil -_TABLE_SECTION_BREAK_ = nil -_TABLE_HEIGHT_ = nil -_LINE_1_Y_ = nil -_TEXT_LEFT_X_ = nil -_RIGHT_X_ = nil -_PLOT_Y_ = nil - -local draw_static = function(cr) - Common.drawHeader(cr, header) - - Common.text_ring_draw_static(text_ring, cr) - Dial.draw_static(dial, cr) - - Common.text_row_crit_draw_static(swap, cr) - Common.text_rows_draw_static(cache, cr) - LabelPlot.draw_static(plot, cr) - - Table.draw_static(tbl, cr) -end - -local draw_dynamic = function(cr) - update(cr) - - Dial.draw_dynamic(dial, cr) - Arc.draw(cache_arc, cr) - Common.text_ring_draw_dynamic(text_ring, cr) - - Common.text_row_crit_draw_dynamic(swap, cr) - Common.text_rows_draw_dynamic(cache, cr) - - LabelPlot.draw_dynamic(plot, cr) - - Table.draw_dynamic(tbl, cr) -end return function(update_freq) + + local plot = Common.initThemedLabelPlot( + Geometry.RIGHT_X, + _PLOT_Y_, + Geometry.SECTION_WIDTH, + _PLOT_HEIGHT_, + Common.percent_label_style, + update_freq + ) + + local update = function(cr) + local conky = Util.conky + -- see source for the 'free' command (sysinfo.c) for formulas + + local memfree_kb, buffers_kb, cached_kb, swap_total_kb, swap_free_kb, + slab_reclaimable_kb = __string_match(Util.read_file('/proc/meminfo'), MEMINFO_REGEX) + + local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB + + Dial.set(dial, used_percent) + Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100)) + + local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1 + __cairo_path_destroy(cache_arc.path) + cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta) + + Common.text_row_crit_set(swap, cr, + Util.precision_round_to_string( + (swap_total_kb - swap_free_kb) + / swap_total_kb * 100)) + + Common.text_rows_set(cache, cr, 1, Util.precision_round_to_string( + cached_kb / MEM_TOTAL_KB * 100)) + + Common.text_rows_set(cache, cr, 2, Util.precision_round_to_string( + buffers_kb / MEM_TOTAL_KB * 100)) + + Common.text_rows_set(cache, cr, 3, Util.precision_round_to_string( + slab_reclaimable_kb / MEM_TOTAL_KB * 100)) + + LabelPlot.update(plot, used_percent) + + for r = 1, NUM_ROWS do + local comm = conky(TABLE_CONKY[r].comm, '(%S+)') -- may have trailing space + local pid = conky(TABLE_CONKY[r].pid) + local mem = conky(TABLE_CONKY[r].mem) + Table.set(tbl, cr, 1, r, comm) + Table.set(tbl, cr, 2, r, pid) + Table.set(tbl, cr, 3, r, mem) + end + end + + local draw_static = function(cr) + Common.drawHeader(cr, header) + + Common.text_ring_draw_static(text_ring, cr) + Dial.draw_static(dial, cr) + + Common.text_row_crit_draw_static(swap, cr) + Common.text_rows_draw_static(cache, cr) + LabelPlot.draw_static(plot, cr) + + Table.draw_static(tbl, cr) + end + + local draw_dynamic = function(cr) + update(cr) + + Dial.draw_dynamic(dial, cr) + Arc.draw(cache_arc, cr) + Common.text_ring_draw_dynamic(text_ring, cr) + + Common.text_row_crit_draw_dynamic(swap, cr) + Common.text_rows_draw_dynamic(cache, cr) + + LabelPlot.draw_dynamic(plot, cr) + + Table.draw_dynamic(tbl, cr) + end + return {dynamic = draw_dynamic, static = draw_static} end diff --git a/drawing/Network.lua b/drawing/Network.lua index 9bc166f..cbd14d6 100644 --- a/drawing/Network.lua +++ b/drawing/Network.lua @@ -18,14 +18,26 @@ local value_format_function = function(bits) return Util.precision_round_to_string(value, 3)..' '..unit..'b/s' end -local header = Common.Header( - Geometry.CENTER_RIGHT_X, - Geometry.TOP_Y, - Geometry.SECTION_WIDTH, - 'NETWORK' -) -local dnload = Common.initLabeledScalePlot( + +local interface_counters_tbl = {} + +local get_bits = function(path) + return Util.read_file(path, nil, '*n') * 8 +end + +-- _PLOT_SEC_BREAK_ = nil +-- _PLOT_HEIGHT_ = nil + +return function(update_freq) + local header = Common.Header( + Geometry.CENTER_RIGHT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, + 'NETWORK' + ) + + local dnload = Common.initLabeledScalePlot( Geometry.CENTER_RIGHT_X, header.bottom_y, Geometry.SECTION_WIDTH, @@ -34,10 +46,11 @@ local dnload = Common.initLabeledScalePlot( network_label_function, _PLOT_SEC_BREAK_, 'Download', - 2 -) + 2, + update_freq + ) -local upload = Common.initLabeledScalePlot( + local upload = Common.initLabeledScalePlot( Geometry.CENTER_RIGHT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, Geometry.SECTION_WIDTH, @@ -46,25 +59,10 @@ local upload = Common.initLabeledScalePlot( network_label_function, _PLOT_SEC_BREAK_, 'Upload', - 2 -) + 2, + update_freq + ) -local interface_counters_tbl = {} - -local get_bits = function(path) - return Util.read_file(path, nil, '*n') * 8 -end - -_PLOT_SEC_BREAK_ = nil -_PLOT_HEIGHT_ = nil - -local draw_static = function(cr) - Common.drawHeader(cr, header) - Common.annotated_scale_plot_draw_static(dnload, cr) - Common.annotated_scale_plot_draw_static(upload, cr) -end - -return function(update_freq) local _update = function(cr) local dspeed, uspeed = 0, 0 @@ -108,6 +106,12 @@ return function(update_freq) Common.annotated_scale_plot_set(upload, cr, uspeed) end + local draw_static = function(cr) + Common.drawHeader(cr, header) + Common.annotated_scale_plot_draw_static(dnload, cr) + Common.annotated_scale_plot_draw_static(upload, cr) + end + local draw_dynamic = function(cr) _update(cr) Common.annotated_scale_plot_draw_dynamic(dnload, cr) diff --git a/drawing/Power.lua b/drawing/Power.lua index 73f3f02..c84af33 100644 --- a/drawing/Power.lua +++ b/drawing/Power.lua @@ -36,7 +36,24 @@ local header = Common.Header( 'POWER' ) -local pkg0 = Common.initLabeledScalePlot( +local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_ + + +local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj' +local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj' + +local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n') +local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n') + +-- _MODULE_Y_ = nil +-- _TEXT_SPACING_ = nil +-- _PLOT_SEC_BREAK_ = nil +-- _PLOT_HEIGHT_ = nil +-- _CORE_Y_ = nil + +return function(update_freq) + + local pkg0 = Common.initLabeledScalePlot( Geometry.RIGHT_X, header.bottom_y, Geometry.SECTION_WIDTH, @@ -45,12 +62,11 @@ local pkg0 = Common.initLabeledScalePlot( power_label_function, _PLOT_SEC_BREAK_, 'PKG0', - 0 -) + 0, + update_freq + ) -local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_ - -local dram = Common.initLabeledScalePlot( + local dram = Common.initLabeledScalePlot( Geometry.RIGHT_X, _CORE_Y_, Geometry.SECTION_WIDTH, @@ -59,11 +75,11 @@ local dram = Common.initLabeledScalePlot( power_label_function, _PLOT_SEC_BREAK_, 'DRAM', - 0 -) -dram.value.append_end = ' W' + 0, + update_freq + ) -local battery_draw = Common.initLabeledScalePlot( + local battery_draw = Common.initLabeledScalePlot( Geometry.RIGHT_X, _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_, Geometry.SECTION_WIDTH, @@ -72,30 +88,9 @@ local battery_draw = Common.initLabeledScalePlot( power_label_function, _PLOT_SEC_BREAK_, 'Battery Draw', - 0 -) - -local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj' -local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj' - -local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n') -local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n') - - -_MODULE_Y_ = nil -_TEXT_SPACING_ = nil -_PLOT_SEC_BREAK_ = nil -_PLOT_HEIGHT_ = nil -_CORE_Y_ = nil - -local draw_static = function(cr) - Common.drawHeader(cr, header) - Common.annotated_scale_plot_draw_static(pkg0, cr) - Common.annotated_scale_plot_draw_static(dram, cr) - Common.annotated_scale_plot_draw_static(battery_draw, cr) -end - -return function(update_freq) + 0, + update_freq + ) local _update = function(cr, is_using_ac) local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n') @@ -122,6 +117,13 @@ return function(update_freq) end end + local draw_static = function(cr) + Common.drawHeader(cr, header) + Common.annotated_scale_plot_draw_static(pkg0, cr) + Common.annotated_scale_plot_draw_static(dram, cr) + Common.annotated_scale_plot_draw_static(battery_draw, cr) + end + local draw_dynamic = function(cr, is_using_ac) _update(cr, is_using_ac) Common.annotated_scale_plot_draw_dynamic(pkg0, cr) diff --git a/drawing/Processor.lua b/drawing/Processor.lua index 8f67c43..304dcf9 100644 --- a/drawing/Processor.lua +++ b/drawing/Processor.lua @@ -113,14 +113,6 @@ local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ -local total_load = Common.initPercentPlot( - Geometry.LEFT_X, - _LOAD_Y_, - Geometry.SECTION_WIDTH, - _PLOT_HEIGHT_, - _PLOT_SECTION_BREAK_, - "Total Load" -) local tbl = Common.initTable( Geometry.LEFT_X, @@ -197,107 +189,120 @@ local _read_hwp = function() end end -local update = function(cr, trigger) - local conky = Util.conky - local load_sum = 0 - -- TODO bundle all the crap down below into this function and make it return - -- something useful rather than totally use a side effect (it will be mildly - -- slower) - -- this entire loop is about 10% total execution time - _read_cpu() - for c = 1, NUM_PHYSICAL_CORES do - local core = cores[c] +-- _MODULE_Y_ = nil +-- _DIAL_INNER_RADIUS_ = nil +-- _DIAL_OUTER_RADIUS_ = nil +-- _DIAL_THICKNESS_ = nil +-- _TEXT_Y_OFFSET_ = nil +-- _SEPARATOR_SPACING_ = nil +-- _TEXT_SPACING_ = nil +-- _PLOT_SECTION_BREAK_ = nil +-- _PLOT_HEIGHT_ = nil +-- _TABLE_SECTION_BREAK_ = nil +-- _TABLE_HEIGHT_ = nil +-- _create_core_ = nil +-- _FREQ_Y_ = nil +-- _LOAD_Y_ = nil +-- _SEP_Y_ = nil +-- _HWP_Y_ = nil +-- _PLOT_Y_ = nil - for t = 1, NUM_THREADS_PER_CORE do - -- TODO these might not match the actual core numbers (if I care) - local cl = cpu_loads[(c - 1) * NUM_THREADS_PER_CORE + t] - -- this is necessary to prevent 1/0 errors - if cl.total > cl.total_prev then - local p = (cl.active - cl.active_prev) / (cl.total - cl.total_prev) - CompoundDial.set(core.dials, t, p) - load_sum = load_sum + p + +return function(update_freq) + + local total_load = Common.initPercentPlot( + Geometry.LEFT_X, + _LOAD_Y_, + Geometry.SECTION_WIDTH, + _PLOT_HEIGHT_, + _PLOT_SECTION_BREAK_, + "Total Load", + update_freq + ) + + local update = function(cr, trigger) + local conky = Util.conky + local load_sum = 0 + + -- TODO bundle all the crap down below into this function and make it return + -- something useful rather than totally use a side effect (it will be mildly + -- slower) + -- this entire loop is about 10% total execution time + _read_cpu() + for c = 1, NUM_PHYSICAL_CORES do + local core = cores[c] + + for t = 1, NUM_THREADS_PER_CORE do + -- TODO these might not match the actual core numbers (if I care) + local cl = cpu_loads[(c - 1) * NUM_THREADS_PER_CORE + t] + -- this is necessary to prevent 1/0 errors + if cl.total > cl.total_prev then + local p = (cl.active - cl.active_prev) / (cl.total - cl.total_prev) + CompoundDial.set(core.dials, t, p) + load_sum = load_sum + p + end + end + Common.text_ring_set( + core.text_ring, + cr, + __math_floor(0.001 * Util.read_file(core.coretemp_path, nil, '*n')) + ) + end + + -- For some reason this call is slow (querying anything with pstate in + -- general seems slow), but I also don't need to see an update every cycle, + -- hence the trigger + if trigger == 0 then + Common.text_rows_set(cpu_status, cr, 1, _read_hwp()) + end + Common.text_rows_set(cpu_status, cr, 2, _read_freq()) + + Common.percent_plot_set(total_load, cr, load_sum / NCPU * 100) + + for r = 1, NUM_ROWS do + local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces + if pid ~= '' then + local cpu = conky(TABLE_CONKY[r].cpu) + local comm = Util.read_file('/proc/'..pid..'/comm', '(%C+)') + Table.set(tbl, cr, 1, r, comm) + Table.set(tbl, cr, 2, r, pid) + Table.set(tbl, cr, 3, r, cpu) end end - Common.text_ring_set( - core.text_ring, - cr, - __math_floor(0.001 * Util.read_file(core.coretemp_path, nil, '*n')) - ) end - -- For some reason this call is slow (querying anything with pstate in - -- general seems slow), but I also don't need to see an update every cycle, - -- hence the trigger - if trigger == 0 then - Common.text_rows_set(cpu_status, cr, 1, _read_hwp()) - end - Common.text_rows_set(cpu_status, cr, 2, _read_freq()) + local draw_static = function(cr) + Common.drawHeader(cr, header) - Common.percent_plot_set(total_load, cr, load_sum / NCPU * 100) - - for r = 1, NUM_ROWS do - local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces - if pid ~= '' then - local cpu = conky(TABLE_CONKY[r].cpu) - local comm = Util.read_file('/proc/'..pid..'/comm', '(%C+)') - Table.set(tbl, cr, 1, r, comm) - Table.set(tbl, cr, 2, r, pid) - Table.set(tbl, cr, 3, r, cpu) + for c = 1, NUM_PHYSICAL_CORES do + local this_core = cores[c] + Common.text_ring_draw_static(this_core.text_ring, cr) + CompoundDial.draw_static(this_core.dials, cr) end - end -end -_MODULE_Y_ = nil -_DIAL_INNER_RADIUS_ = nil -_DIAL_OUTER_RADIUS_ = nil -_DIAL_THICKNESS_ = nil -_TEXT_Y_OFFSET_ = nil -_SEPARATOR_SPACING_ = nil -_TEXT_SPACING_ = nil -_PLOT_SECTION_BREAK_ = nil -_PLOT_HEIGHT_ = nil -_TABLE_SECTION_BREAK_ = nil -_TABLE_HEIGHT_ = nil -_create_core_ = nil -_FREQ_Y_ = nil -_LOAD_Y_ = nil -_SEP_Y_ = nil -_HWP_Y_ = nil -_PLOT_Y_ = nil + Common.text_rows_draw_static(cpu_status, cr) + Line.draw(separator, cr) -local draw_static = function(cr) - Common.drawHeader(cr, header) + Common.percent_plot_draw_static(total_load, cr) - for c = 1, NUM_PHYSICAL_CORES do - local this_core = cores[c] - Common.text_ring_draw_static(this_core.text_ring, cr) - CompoundDial.draw_static(this_core.dials, cr) + Table.draw_static(tbl, cr) end - Common.text_rows_draw_static(cpu_status, cr) - Line.draw(separator, cr) + local draw_dynamic = function(cr, trigger) + update(cr, trigger) - Common.percent_plot_draw_static(total_load, cr) + for c = 1, NUM_PHYSICAL_CORES do + local this_core = cores[c] + CompoundDial.draw_dynamic(this_core.dials, cr) + Common.text_ring_draw_dynamic(this_core.text_ring, cr) + end - Table.draw_static(tbl, cr) -end + Common.text_rows_draw_dynamic(cpu_status, cr) + Common.percent_plot_draw_dynamic(total_load, cr) -local draw_dynamic = function(cr, trigger) - update(cr, trigger) - - for c = 1, NUM_PHYSICAL_CORES do - local this_core = cores[c] - CompoundDial.draw_dynamic(this_core.dials, cr) - Common.text_ring_draw_dynamic(this_core.text_ring, cr) + Table.draw_dynamic(tbl, cr) end - Common.text_rows_draw_dynamic(cpu_status, cr) - Common.percent_plot_draw_dynamic(total_load, cr) - - Table.draw_dynamic(tbl, cr) -end - -return function() return {static = draw_static, dynamic = draw_dynamic} end diff --git a/drawing/ReadWrite.lua b/drawing/ReadWrite.lua index a0e5078..6705f8c 100644 --- a/drawing/ReadWrite.lua +++ b/drawing/ReadWrite.lua @@ -30,14 +30,15 @@ local format_value_function = function(bps) return Util.precision_round_to_string(value, 3)..' '..unit..'B/s' end -local header = Common.Header( - Geometry.CENTER_LEFT_X, - Geometry.TOP_Y, - Geometry.SECTION_WIDTH, - 'INPUT / OUTPUT' -) +return function(update_freq) + local header = Common.Header( + Geometry.CENTER_LEFT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, + 'INPUT / OUTPUT' + ) -local reads = Common.initLabeledScalePlot( + local reads = Common.initLabeledScalePlot( Geometry.CENTER_LEFT_X, header.bottom_y, Geometry.SECTION_WIDTH, @@ -46,11 +47,11 @@ local reads = Common.initLabeledScalePlot( io_label_function, _PLOT_SEC_BREAK_, 'Reads', - 2 + 2, + update_freq + ) -) - -local writes = Common.initLabeledScalePlot( + local writes = Common.initLabeledScalePlot( Geometry.CENTER_LEFT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, Geometry.SECTION_WIDTH, @@ -59,23 +60,13 @@ local writes = Common.initLabeledScalePlot( io_label_function, _PLOT_SEC_BREAK_, 'Writes', - 2 -) + 2, + update_freq + ) -_PLOT_SEC_BREAK_ = nil -_PLOT_HEIGHT_ = nil - -reads.byte_cnt = 0 -writes.byte_cnt = 0 -reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file() - -local draw_static = function(cr) - Common.drawHeader(cr, header) - Common.annotated_scale_plot_draw_static(reads, cr) - Common.annotated_scale_plot_draw_static(writes, cr) -end - -return function(update_freq) + reads.byte_cnt = 0 + writes.byte_cnt = 0 + reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file() local update_stat = function(cr, stat, byte_cnt) local delta_bytes = byte_cnt - stat.prev_byte_cnt @@ -95,6 +86,12 @@ return function(update_freq) update_stat(cr, writes, write_byte_cnt) end + local draw_static = function(cr) + Common.drawHeader(cr, header) + Common.annotated_scale_plot_draw_static(reads, cr) + Common.annotated_scale_plot_draw_static(writes, cr) + end + local draw_dynamic = function(cr) update(cr) Common.annotated_scale_plot_draw_dynamic(reads, cr) diff --git a/main.lua b/main.lua index 2d4b44b..63dd15e 100644 --- a/main.lua +++ b/main.lua @@ -1,12 +1,3 @@ --- --- initialialize global geometric data --- -local UPDATE_FREQUENCY = 1 --Hz - -_G_INIT_DATA_ = { - UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY, -} - -- -- init cairo -- @@ -102,8 +93,8 @@ function conky_start(update_interval) local pwr = Power(update_freq) local fs = FileSystem() local sys = System() - local gfx = Graphics() - local proc = Processor() + local gfx = Graphics(update_freq) + local proc = Processor(update_freq) local pcm = Pacman() local cs_left = _make_static_surface(