ENH split update and dynamic drawing functions

This commit is contained in:
Nathan Dwarshuis 2021-07-27 23:47:26 -04:00
parent bdbcf0ab75
commit 73c8396a30
10 changed files with 56 additions and 52 deletions

View File

@ -63,7 +63,8 @@ return function()
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
local update = function() local update = function(trigger)
if trigger == 0 then
local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n') local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n')
Common.text_row_set(smart, (smart_pid == '') and 'Error' or 'Running') Common.text_row_set(smart, (smart_pid == '') and 'Error' or 'Running')
@ -72,6 +73,7 @@ return function()
Common.compound_bar_set(fs, i, percent * 0.01) Common.compound_bar_set(fs, i, percent * 0.01)
end end
end end
end
local draw_static = function(cr) local draw_static = function(cr)
Common.drawHeader(cr, header) Common.drawHeader(cr, header)
@ -80,11 +82,11 @@ return function()
Common.compound_bar_draw_static(fs, cr) Common.compound_bar_draw_static(fs, cr)
end end
local draw_dynamic = function(cr, trigger) local draw_dynamic = function(cr)
if trigger == 0 then update() end -- if trigger == 0 then update() end
Common.text_row_draw_dynamic(smart, cr) Common.text_row_draw_dynamic(smart, cr)
Common.compound_bar_draw_dynamic(fs, cr) Common.compound_bar_draw_dynamic(fs, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -206,7 +206,7 @@ return function(update_freq)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
update() -- update()
Common.text_row_draw_dynamic(status, cr) Common.text_row_draw_dynamic(status, cr)
Common.text_row_crit_draw_dynamic(internal_temp, cr) Common.text_row_crit_draw_dynamic(internal_temp, cr)
@ -216,5 +216,5 @@ return function(update_freq)
Common.percent_plot_draw_dynamic(vid_util, cr) Common.percent_plot_draw_dynamic(vid_util, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -183,7 +183,7 @@ return function(update_freq)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
update() -- update()
Common.dial_draw_dynamic(mem, cr) Common.dial_draw_dynamic(mem, cr)
Common.dial_draw_dynamic(swap, cr) Common.dial_draw_dynamic(swap, cr)
@ -195,5 +195,5 @@ return function(update_freq)
Table.draw_dynamic(tbl, cr) Table.draw_dynamic(tbl, cr)
end end
return {dynamic = draw_dynamic, static = draw_static} return {dynamic = draw_dynamic, static = draw_static, update = update}
end end

View File

@ -101,10 +101,10 @@ return function(update_freq)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
update() -- update()
Common.annotated_scale_plot_draw_dynamic(rx, cr) Common.annotated_scale_plot_draw_dynamic(rx, cr)
Common.annotated_scale_plot_draw_dynamic(tx, cr) Common.annotated_scale_plot_draw_dynamic(tx, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -42,10 +42,10 @@ return function()
Common.text_rows_draw_static(rows, cr) Common.text_rows_draw_static(rows, cr)
end end
local draw_dynamic = function(cr, pacman_stats) local draw_dynamic = function(cr)
update(pacman_stats) -- update(pacman_stats)
Common.text_rows_draw_dynamic(rows, cr) Common.text_rows_draw_dynamic(rows, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -127,12 +127,12 @@ return function(update_freq)
Common.annotated_scale_plot_draw_static(bat, cr) Common.annotated_scale_plot_draw_static(bat, cr)
end end
local draw_dynamic = function(cr, is_using_ac) local draw_dynamic = function(cr)
update(is_using_ac) -- update(is_using_ac)
Common.annotated_scale_plot_draw_dynamic(pkg0, cr) Common.annotated_scale_plot_draw_dynamic(pkg0, cr)
Common.annotated_scale_plot_draw_dynamic(dram, cr) Common.annotated_scale_plot_draw_dynamic(dram, cr)
Common.annotated_scale_plot_draw_dynamic(bat, cr) Common.annotated_scale_plot_draw_dynamic(bat, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -186,8 +186,8 @@ return function(update_freq)
Table.draw_static(tbl, cr) Table.draw_static(tbl, cr)
end end
local draw_dynamic = function(cr, trigger) local draw_dynamic = function(cr)
update(trigger) -- update(trigger)
for i = 1, #cores do for i = 1, #cores do
CompoundDial.draw_dynamic(cores[i].loads, cr) CompoundDial.draw_dynamic(cores[i].loads, cr)
@ -200,5 +200,5 @@ return function(update_freq)
Table.draw_dynamic(tbl, cr) Table.draw_dynamic(tbl, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -98,10 +98,10 @@ return function(update_freq)
end end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
update() -- update()
Common.annotated_scale_plot_draw_dynamic(reads, cr) Common.annotated_scale_plot_draw_dynamic(reads, cr)
Common.annotated_scale_plot_draw_dynamic(writes, cr) Common.annotated_scale_plot_draw_dynamic(writes, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -22,12 +22,7 @@ return function()
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
) )
local draw_static = function(cr) local update = function(pacman_stats)
Common.drawHeader(cr, header)
Common.text_rows_draw_static(rows, cr)
end
local draw_dynamic = function(cr, pacman_stats)
local last_update, last_sync = "N/A", "N/A" local last_update, last_sync = "N/A", "N/A"
if pacman_stats then if pacman_stats then
last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*") last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
@ -37,8 +32,16 @@ return function()
Common.text_rows_set(rows, 2, Util.conky('$uptime')) Common.text_rows_set(rows, 2, Util.conky('$uptime'))
Common.text_rows_set(rows, 3, last_update) Common.text_rows_set(rows, 3, last_update)
Common.text_rows_set(rows, 4, last_sync) Common.text_rows_set(rows, 4, last_sync)
end
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_rows_draw_static(rows, cr)
end
local draw_dynamic = function(cr)
Common.text_rows_draw_dynamic(rows, cr) Common.text_rows_draw_dynamic(rows, cr)
end end
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic, update = update}
end end

View File

@ -60,34 +60,33 @@ function conky_start(update_interval)
local STATS_FILE = '/tmp/.conky_pacman' local STATS_FILE = '/tmp/.conky_pacman'
draw_dynamic = function(cr, _updates) draw_dynamic = function(cr, _updates)
-- timings of each line when cpu set to performance -- draw static components
-- 0.7ms
draw_static(cr) draw_static(cr)
-- update dynamic components
local t1 = _updates % (update_freq * 10) local t1 = _updates % (update_freq * 10)
local pacman_stats = Util.read_file(STATS_FILE) local pacman_stats = Util.read_file(STATS_FILE)
-- 0.1ms
local is_using_ac = using_ac() local is_using_ac = using_ac()
-- <0.1ms sys.update(pacman_stats)
sys.dynamic(cr, pacman_stats) gfx.update()
-- 0.3ms proc.update(t1)
rw.update()
net.update()
pcm.update(pacman_stats)
fs.update(t1)
pwr.update(is_using_ac)
mem.update()
-- draw dynamic components
sys.dynamic(cr)
gfx.dynamic(cr) gfx.dynamic(cr)
-- 0.8-1.1ms proc.dynamic(cr)
proc.dynamic(cr, t1)
-- 0.1-0.3ms
rw.dynamic(cr) rw.dynamic(cr)
-- 0.2ms
net.dynamic(cr) net.dynamic(cr)
pcm.dynamic(cr)
-- <0.1ms fs.dynamic(cr)
pcm.dynamic(cr, pacman_stats) pwr.dynamic(cr)
-- <0.1ms
fs.dynamic(cr, t1)
-- 0.3ms
pwr.dynamic(cr, is_using_ac)
-- 0.5ms
mem.dynamic(cr) mem.dynamic(cr)
end end
end end