From 0872cc236c0f41cb0b231febe7bb7c53598287ec Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Sat, 4 Aug 2018 17:54:34 -0400 Subject: [PATCH] small speedup for top table --- drawing/Processor.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drawing/Processor.lua b/drawing/Processor.lua index 7c06b1b..fc64b12 100644 --- a/drawing/Processor.lua +++ b/drawing/Processor.lua @@ -13,12 +13,13 @@ local NUM_PHYSICAL_CORES = 4 local NUM_THREADS_PER_CORE = 2 local NUM_ROWS = 5 -local TABLE_CONKY = {{}, {}, {}} + +local TABLE_CONKY = {} for r = 1, NUM_ROWS do - TABLE_CONKY[1][r] = '${top name '..r..'}' - TABLE_CONKY[2][r] = '${top pid '..r..'}' - TABLE_CONKY[3][r] = '${top cpu '..r..'}' + TABLE_CONKY[r] = {} + TABLE_CONKY[r].pid = '${top pid '..r..'}' + TABLE_CONKY[r].cpu = '${top cpu '..r..'}' end local _MODULE_Y_ = 614 @@ -187,7 +188,6 @@ local update = function(cr) for c = 1, NUM_PHYSICAL_CORES do local core = cores[c] - local conky_loads = core.conky_loads local conky_freqs = core.conky_freqs @@ -218,11 +218,15 @@ local update = function(cr) LabelPlot.update(plot, load_percent) - for c = 1, 3 do - local column = TABLE_CONKY[c] - for r = 1, NUM_ROWS do - Table.set(tbl, cr, c, r, conky(column[r], '(%S+)')) - end + 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 end end