diff --git a/drawing/Memory.lua b/drawing/Memory.lua index 3552cbb..7b4b0d4 100644 --- a/drawing/Memory.lua +++ b/drawing/Memory.lua @@ -148,7 +148,7 @@ local update = function(cr) local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB Dial.set(dial, used_percent) - CriticalText.set(total_used, cr, Util.round(used_percent * 100)) + CriticalText.set(total_used, 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) diff --git a/drawing/Processor.lua b/drawing/Processor.lua index c41fada..b334290 100644 --- a/drawing/Processor.lua +++ b/drawing/Processor.lua @@ -9,6 +9,8 @@ local LabelPlot = require 'LabelPlot' local Table = require 'Table' local Util = require 'Util' +local __string_format = string.format + local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s' local NUM_PHYSICAL_CORES = 4 @@ -28,7 +30,6 @@ local _MODULE_Y_ = 614 local _DIAL_INNER_RADIUS_ = 30 local _DIAL_OUTER_RADIUS_ = 42 local _DIAL_SPACING_ = 1 -local _TEXT_Y_OFFSET_ = 15 local _SEPARATOR_SPACING_ = 20 local _TEXT_SPACING_ = 22 local _PLOT_SECTION_BREAK_ = 23 @@ -39,7 +40,7 @@ local _TABLE_HEIGHT_ = 114 local _create_core_ = function(cores, id, x, y) local conky_loads = {} local conky_freqs = {} - + for c = 0, NUM_PHYSICAL_CORES * NUM_THREADS_PER_CORE - 1 do if Util.read_file('/sys/devices/system/cpu/cpu'..c..'/topology/core_id', nil, '*n') == id then table.insert(conky_loads, '${cpu cpu'..(c+1)..'}') @@ -55,7 +56,7 @@ local _create_core_ = function(cores, id, x, y) cores[id +1] = { dials = _G_Widget_.CompoundDial{ x = x, - y = y, + y = y, inner_radius = _DIAL_INNER_RADIUS_, outer_radius = _DIAL_OUTER_RADIUS_, spacing = _DIAL_SPACING_, @@ -157,7 +158,7 @@ local total_load = { x_align = 'right', append_end = '%', critical_limit = '>80' - } + } } local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ @@ -186,13 +187,13 @@ local update = function(cr) local load_sum = 0 local freq_sum = 0 - + for c = 1, NUM_PHYSICAL_CORES do local core = cores[c] - + local conky_loads = core.conky_loads local conky_freqs = core.conky_freqs - + for t = 1, NUM_THREADS_PER_CORE do local percent = Util.conky_numeric(conky_loads[t]) * 0.01 CompoundDial.set(core.dials, t, percent) @@ -201,34 +202,37 @@ local update = function(cr) freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t]) end - CriticalText.set(core.coretemp_text, cr, Util.round(0.001 * Util.read_file(core.coretemp_path, nil, '*n'))) + CriticalText.set(core.coretemp_text, cr, Util.round_to_string(0.001 * Util.read_file(core.coretemp_path, nil, '*n'))) end local process_glob = Util.execute_cmd('ps -A -o s') - - --subtract one from running b/c ps will always be "running" - Text.set(process.value, cr, (char_count(process_glob, 'R') - 1)..' | '.. - char_count(process_glob, 'S')..' | '.. - char_count(process_glob, 'D')..' | '.. - char_count(process_glob, 'T')..' | '.. - char_count(process_glob, 'Z')) - Text.set(ave_freq.value, cr, Util.round(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz') + --subtract one from running b/c ps will always be "running" + Text.set(process.value, cr, + __string_format('%s | %s | %s | %s | %s', + (char_count(process_glob, 'R') - 1), + char_count(process_glob, 'S'), + char_count(process_glob, 'D'), + char_count(process_glob, 'T'), + char_count(process_glob, 'Z'))) + + Text.set(ave_freq.value, cr, Util.round_to_string(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz') local load_percent = Util.round(load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE, 2) - CriticalText.set(total_load.value, cr, load_percent * 100) + CriticalText.set(total_load.value, cr, + Util.round_to_string(load_percent * 100)) LabelPlot.update(plot, load_percent) for r = 1, NUM_ROWS do - local pid = conky(TABLE_CONKY[r].pid, '(%S+)') - if pid ~= '' then - local cpu = conky(TABLE_CONKY[r].cpu) - local comm = Util.read_file('/proc/'..pid..'/stat', '%d+%s+%((.+)%)') - Table.set(tbl, cr, 1, r, comm) - Table.set(tbl, cr, 2, r, pid) - Table.set(tbl, cr, 3, r, cpu) - end + local pid = conky(TABLE_CONKY[r].pid, '(%S+)') + if pid ~= '' then + local cpu = conky(TABLE_CONKY[r].cpu) + local comm = Util.read_file('/proc/'..pid..'/stat', '%d+%s+%((.+)%)') + Table.set(tbl, cr, 1, r, comm) + Table.set(tbl, cr, 2, r, pid) + Table.set(tbl, cr, 3, r, cpu) + end end end @@ -254,7 +258,7 @@ _PLOT_Y_ = nil local draw_static = function(cr) Text.draw(header.text, cr) Line.draw(header.underline, cr) - + for c = 1, NUM_PHYSICAL_CORES do local this_core = cores[c] Arc.draw(this_core.inner_ring, cr) @@ -282,10 +286,10 @@ local draw_dynamic = function(cr) Text.draw(process.value, cr) Text.draw(ave_freq.value, cr) - + CriticalText.draw(total_load.value, cr) LabelPlot.draw_dynamic(plot, cr) - + Table.draw_dynamic(tbl, cr) end diff --git a/drawing/ReadWrite.lua b/drawing/ReadWrite.lua index c1d5c7e..0d7067a 100644 --- a/drawing/ReadWrite.lua +++ b/drawing/ReadWrite.lua @@ -25,27 +25,27 @@ end local update_stat = function(cr, stat, byte_cnt, update_frequency) local delta_bytes = byte_cnt - stat.prev_byte_cnt stat.prev_byte_cnt = byte_cnt - + if delta_bytes > 0 then local bps = delta_bytes * update_frequency local unit = Util.get_unit(bps) stat.rate.append_end = ' '..unit..'/s' Text.set(stat.rate, cr, Util.precision_convert_bytes(bps, 'B', unit, 3)) - ScalePlot.update(stat.plot, cr, bps) + ScalePlot.update(stat.plot, cr, bps) else stat.rate.append_end = ' B/s' Text.set(stat.rate, cr, '0.00') - ScalePlot.update(stat.plot, cr, 0) + ScalePlot.update(stat.plot, cr, 0) end end local io_label_function = function(bytes) local new_unit = Util.get_unit(bytes) - + local converted = Util.convert_bytes(bytes, 'B', new_unit) local precision = 0 if converted < 10 then precision = 1 end - + return Util.round_to_string(converted, precision)..' '..new_unit..'/s' end @@ -132,7 +132,7 @@ local draw_dynamic = function(cr, update_frequency) Text.draw(reads.rate, cr) ScalePlot.draw_dynamic(reads.plot, cr) - + Text.draw(writes.rate, cr) ScalePlot.draw_dynamic(writes.plot, cr) end diff --git a/main.lua b/main.lua index 9e880a7..8c48132 100644 --- a/main.lua +++ b/main.lua @@ -51,14 +51,14 @@ local UPDATE_FREQUENCY = 1 --Hz _G_INIT_DATA_ = { UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY, - + LEFT_X = 32, SECTION_WIDTH = 436, CENTER_PAD = 20, PANEL_HORZ_SPACING = 10, PANEL_MARGIN_X = 20, PANEL_MARGIN_Y = 10, - + TOP_Y = 21, SIDE_HEIGHT = 1020, CENTER_HEIGHT = 220, @@ -167,7 +167,7 @@ cr_static = nil -- -- create some useful functions --- +-- local using_ac = function() return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1 end @@ -198,11 +198,11 @@ function conky_main() __cairo_set_source_surface(cr, cs_static, 0, 0) __cairo_paint(cr) - + updates = updates + 1 - + local t1 = updates % (UPDATE_FREQUENCY * 10) - + local t2 local is_using_ac = using_ac() if is_using_ac then @@ -210,22 +210,22 @@ function conky_main() else t2 = updates % (UPDATE_FREQUENCY * 300) end - + local log_is_changed = false if t2 == 0 then log_is_changed = check_if_log_changed() end - + System.draw_dynamic(cr, log_is_changed) Graphics.draw_dynamic(cr) Processor.draw_dynamic(cr) - + ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY) Network.draw_dynamic(cr, UPDATE_FREQUENCY) - + Pacman.draw_dynamic(cr, log_is_changed) FileSystem.draw_dynamic(cr, t1) Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac) Memory.draw_dynamic(cr) - + __cairo_surface_destroy(cs) __cairo_destroy(cr) __collectgarbage() diff --git a/schema/Patterns.lua b/schema/Patterns.lua index 155d64e..dc6b031 100644 --- a/schema/Patterns.lua +++ b/schema/Patterns.lua @@ -101,5 +101,4 @@ M.TRANSPARENT_BLACK = Color.init{hex_rgba = 0x000000, alpha = 0.7} M = Util.set_finalizer(M, function() print('Cleaning up Patterns.lua') end) - return M