ENH update to lua 5.3
This commit is contained in:
parent
7125292168
commit
d1c31f1f38
|
@ -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
|
local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB
|
||||||
|
|
||||||
Dial.set(dial, used_percent)
|
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
|
local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1
|
||||||
__cairo_path_destroy(cache_arc.path)
|
__cairo_path_destroy(cache_arc.path)
|
||||||
|
|
|
@ -9,6 +9,8 @@ local LabelPlot = require 'LabelPlot'
|
||||||
local Table = require 'Table'
|
local Table = require 'Table'
|
||||||
local Util = require 'Util'
|
local Util = require 'Util'
|
||||||
|
|
||||||
|
local __string_format = string.format
|
||||||
|
|
||||||
local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s'
|
local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s'
|
||||||
|
|
||||||
local NUM_PHYSICAL_CORES = 4
|
local NUM_PHYSICAL_CORES = 4
|
||||||
|
@ -28,7 +30,6 @@ local _MODULE_Y_ = 614
|
||||||
local _DIAL_INNER_RADIUS_ = 30
|
local _DIAL_INNER_RADIUS_ = 30
|
||||||
local _DIAL_OUTER_RADIUS_ = 42
|
local _DIAL_OUTER_RADIUS_ = 42
|
||||||
local _DIAL_SPACING_ = 1
|
local _DIAL_SPACING_ = 1
|
||||||
local _TEXT_Y_OFFSET_ = 15
|
|
||||||
local _SEPARATOR_SPACING_ = 20
|
local _SEPARATOR_SPACING_ = 20
|
||||||
local _TEXT_SPACING_ = 22
|
local _TEXT_SPACING_ = 22
|
||||||
local _PLOT_SECTION_BREAK_ = 23
|
local _PLOT_SECTION_BREAK_ = 23
|
||||||
|
@ -39,7 +40,7 @@ local _TABLE_HEIGHT_ = 114
|
||||||
local _create_core_ = function(cores, id, x, y)
|
local _create_core_ = function(cores, id, x, y)
|
||||||
local conky_loads = {}
|
local conky_loads = {}
|
||||||
local conky_freqs = {}
|
local conky_freqs = {}
|
||||||
|
|
||||||
for c = 0, NUM_PHYSICAL_CORES * NUM_THREADS_PER_CORE - 1 do
|
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
|
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)..'}')
|
table.insert(conky_loads, '${cpu cpu'..(c+1)..'}')
|
||||||
|
@ -55,7 +56,7 @@ local _create_core_ = function(cores, id, x, y)
|
||||||
cores[id +1] = {
|
cores[id +1] = {
|
||||||
dials = _G_Widget_.CompoundDial{
|
dials = _G_Widget_.CompoundDial{
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
inner_radius = _DIAL_INNER_RADIUS_,
|
inner_radius = _DIAL_INNER_RADIUS_,
|
||||||
outer_radius = _DIAL_OUTER_RADIUS_,
|
outer_radius = _DIAL_OUTER_RADIUS_,
|
||||||
spacing = _DIAL_SPACING_,
|
spacing = _DIAL_SPACING_,
|
||||||
|
@ -157,7 +158,7 @@ local total_load = {
|
||||||
x_align = 'right',
|
x_align = 'right',
|
||||||
append_end = '%',
|
append_end = '%',
|
||||||
critical_limit = '>80'
|
critical_limit = '>80'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
|
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
|
||||||
|
@ -186,13 +187,13 @@ local update = function(cr)
|
||||||
|
|
||||||
local load_sum = 0
|
local load_sum = 0
|
||||||
local freq_sum = 0
|
local freq_sum = 0
|
||||||
|
|
||||||
for c = 1, NUM_PHYSICAL_CORES do
|
for c = 1, NUM_PHYSICAL_CORES do
|
||||||
local core = cores[c]
|
local core = cores[c]
|
||||||
|
|
||||||
local conky_loads = core.conky_loads
|
local conky_loads = core.conky_loads
|
||||||
local conky_freqs = core.conky_freqs
|
local conky_freqs = core.conky_freqs
|
||||||
|
|
||||||
for t = 1, NUM_THREADS_PER_CORE do
|
for t = 1, NUM_THREADS_PER_CORE do
|
||||||
local percent = Util.conky_numeric(conky_loads[t]) * 0.01
|
local percent = Util.conky_numeric(conky_loads[t]) * 0.01
|
||||||
CompoundDial.set(core.dials, t, percent)
|
CompoundDial.set(core.dials, t, percent)
|
||||||
|
@ -201,34 +202,37 @@ local update = function(cr)
|
||||||
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
|
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local process_glob = Util.execute_cmd('ps -A -o s')
|
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)
|
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)
|
LabelPlot.update(plot, load_percent)
|
||||||
|
|
||||||
for r = 1, NUM_ROWS do
|
for r = 1, NUM_ROWS do
|
||||||
local pid = conky(TABLE_CONKY[r].pid, '(%S+)')
|
local pid = conky(TABLE_CONKY[r].pid, '(%S+)')
|
||||||
if pid ~= '' then
|
if pid ~= '' then
|
||||||
local cpu = conky(TABLE_CONKY[r].cpu)
|
local cpu = conky(TABLE_CONKY[r].cpu)
|
||||||
local comm = Util.read_file('/proc/'..pid..'/stat', '%d+%s+%((.+)%)')
|
local comm = Util.read_file('/proc/'..pid..'/stat', '%d+%s+%((.+)%)')
|
||||||
Table.set(tbl, cr, 1, r, comm)
|
Table.set(tbl, cr, 1, r, comm)
|
||||||
Table.set(tbl, cr, 2, r, pid)
|
Table.set(tbl, cr, 2, r, pid)
|
||||||
Table.set(tbl, cr, 3, r, cpu)
|
Table.set(tbl, cr, 3, r, cpu)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -254,7 +258,7 @@ _PLOT_Y_ = nil
|
||||||
local draw_static = function(cr)
|
local draw_static = function(cr)
|
||||||
Text.draw(header.text, cr)
|
Text.draw(header.text, cr)
|
||||||
Line.draw(header.underline, cr)
|
Line.draw(header.underline, cr)
|
||||||
|
|
||||||
for c = 1, NUM_PHYSICAL_CORES do
|
for c = 1, NUM_PHYSICAL_CORES do
|
||||||
local this_core = cores[c]
|
local this_core = cores[c]
|
||||||
Arc.draw(this_core.inner_ring, cr)
|
Arc.draw(this_core.inner_ring, cr)
|
||||||
|
@ -282,10 +286,10 @@ local draw_dynamic = function(cr)
|
||||||
|
|
||||||
Text.draw(process.value, cr)
|
Text.draw(process.value, cr)
|
||||||
Text.draw(ave_freq.value, cr)
|
Text.draw(ave_freq.value, cr)
|
||||||
|
|
||||||
CriticalText.draw(total_load.value, cr)
|
CriticalText.draw(total_load.value, cr)
|
||||||
LabelPlot.draw_dynamic(plot, cr)
|
LabelPlot.draw_dynamic(plot, cr)
|
||||||
|
|
||||||
Table.draw_dynamic(tbl, cr)
|
Table.draw_dynamic(tbl, cr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,27 +25,27 @@ end
|
||||||
local update_stat = function(cr, stat, byte_cnt, update_frequency)
|
local update_stat = function(cr, stat, byte_cnt, update_frequency)
|
||||||
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
||||||
stat.prev_byte_cnt = byte_cnt
|
stat.prev_byte_cnt = byte_cnt
|
||||||
|
|
||||||
if delta_bytes > 0 then
|
if delta_bytes > 0 then
|
||||||
local bps = delta_bytes * update_frequency
|
local bps = delta_bytes * update_frequency
|
||||||
local unit = Util.get_unit(bps)
|
local unit = Util.get_unit(bps)
|
||||||
stat.rate.append_end = ' '..unit..'/s'
|
stat.rate.append_end = ' '..unit..'/s'
|
||||||
Text.set(stat.rate, cr, Util.precision_convert_bytes(bps, 'B', unit, 3))
|
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
|
else
|
||||||
stat.rate.append_end = ' B/s'
|
stat.rate.append_end = ' B/s'
|
||||||
Text.set(stat.rate, cr, '0.00')
|
Text.set(stat.rate, cr, '0.00')
|
||||||
ScalePlot.update(stat.plot, cr, 0)
|
ScalePlot.update(stat.plot, cr, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local io_label_function = function(bytes)
|
local io_label_function = function(bytes)
|
||||||
local new_unit = Util.get_unit(bytes)
|
local new_unit = Util.get_unit(bytes)
|
||||||
|
|
||||||
local converted = Util.convert_bytes(bytes, 'B', new_unit)
|
local converted = Util.convert_bytes(bytes, 'B', new_unit)
|
||||||
local precision = 0
|
local precision = 0
|
||||||
if converted < 10 then precision = 1 end
|
if converted < 10 then precision = 1 end
|
||||||
|
|
||||||
return Util.round_to_string(converted, precision)..' '..new_unit..'/s'
|
return Util.round_to_string(converted, precision)..' '..new_unit..'/s'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ local draw_dynamic = function(cr, update_frequency)
|
||||||
|
|
||||||
Text.draw(reads.rate, cr)
|
Text.draw(reads.rate, cr)
|
||||||
ScalePlot.draw_dynamic(reads.plot, cr)
|
ScalePlot.draw_dynamic(reads.plot, cr)
|
||||||
|
|
||||||
Text.draw(writes.rate, cr)
|
Text.draw(writes.rate, cr)
|
||||||
ScalePlot.draw_dynamic(writes.plot, cr)
|
ScalePlot.draw_dynamic(writes.plot, cr)
|
||||||
end
|
end
|
||||||
|
|
22
main.lua
22
main.lua
|
@ -51,14 +51,14 @@ local UPDATE_FREQUENCY = 1 --Hz
|
||||||
|
|
||||||
_G_INIT_DATA_ = {
|
_G_INIT_DATA_ = {
|
||||||
UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY,
|
UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY,
|
||||||
|
|
||||||
LEFT_X = 32,
|
LEFT_X = 32,
|
||||||
SECTION_WIDTH = 436,
|
SECTION_WIDTH = 436,
|
||||||
CENTER_PAD = 20,
|
CENTER_PAD = 20,
|
||||||
PANEL_HORZ_SPACING = 10,
|
PANEL_HORZ_SPACING = 10,
|
||||||
PANEL_MARGIN_X = 20,
|
PANEL_MARGIN_X = 20,
|
||||||
PANEL_MARGIN_Y = 10,
|
PANEL_MARGIN_Y = 10,
|
||||||
|
|
||||||
TOP_Y = 21,
|
TOP_Y = 21,
|
||||||
SIDE_HEIGHT = 1020,
|
SIDE_HEIGHT = 1020,
|
||||||
CENTER_HEIGHT = 220,
|
CENTER_HEIGHT = 220,
|
||||||
|
@ -167,7 +167,7 @@ cr_static = nil
|
||||||
|
|
||||||
--
|
--
|
||||||
-- create some useful functions
|
-- create some useful functions
|
||||||
--
|
--
|
||||||
local using_ac = function()
|
local using_ac = function()
|
||||||
return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1
|
return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1
|
||||||
end
|
end
|
||||||
|
@ -198,11 +198,11 @@ function conky_main()
|
||||||
|
|
||||||
__cairo_set_source_surface(cr, cs_static, 0, 0)
|
__cairo_set_source_surface(cr, cs_static, 0, 0)
|
||||||
__cairo_paint(cr)
|
__cairo_paint(cr)
|
||||||
|
|
||||||
updates = updates + 1
|
updates = updates + 1
|
||||||
|
|
||||||
local t1 = updates % (UPDATE_FREQUENCY * 10)
|
local t1 = updates % (UPDATE_FREQUENCY * 10)
|
||||||
|
|
||||||
local t2
|
local t2
|
||||||
local is_using_ac = using_ac()
|
local is_using_ac = using_ac()
|
||||||
if is_using_ac then
|
if is_using_ac then
|
||||||
|
@ -210,22 +210,22 @@ function conky_main()
|
||||||
else
|
else
|
||||||
t2 = updates % (UPDATE_FREQUENCY * 300)
|
t2 = updates % (UPDATE_FREQUENCY * 300)
|
||||||
end
|
end
|
||||||
|
|
||||||
local log_is_changed = false
|
local log_is_changed = false
|
||||||
if t2 == 0 then log_is_changed = check_if_log_changed() end
|
if t2 == 0 then log_is_changed = check_if_log_changed() end
|
||||||
|
|
||||||
System.draw_dynamic(cr, log_is_changed)
|
System.draw_dynamic(cr, log_is_changed)
|
||||||
Graphics.draw_dynamic(cr)
|
Graphics.draw_dynamic(cr)
|
||||||
Processor.draw_dynamic(cr)
|
Processor.draw_dynamic(cr)
|
||||||
|
|
||||||
ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY)
|
ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY)
|
||||||
Network.draw_dynamic(cr, UPDATE_FREQUENCY)
|
Network.draw_dynamic(cr, UPDATE_FREQUENCY)
|
||||||
|
|
||||||
Pacman.draw_dynamic(cr, log_is_changed)
|
Pacman.draw_dynamic(cr, log_is_changed)
|
||||||
FileSystem.draw_dynamic(cr, t1)
|
FileSystem.draw_dynamic(cr, t1)
|
||||||
Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac)
|
Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac)
|
||||||
Memory.draw_dynamic(cr)
|
Memory.draw_dynamic(cr)
|
||||||
|
|
||||||
__cairo_surface_destroy(cs)
|
__cairo_surface_destroy(cs)
|
||||||
__cairo_destroy(cr)
|
__cairo_destroy(cr)
|
||||||
__collectgarbage()
|
__collectgarbage()
|
||||||
|
|
|
@ -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)
|
M = Util.set_finalizer(M, function() print('Cleaning up Patterns.lua') end)
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue