[cpu_freebsd] Deprecate synchronous sysctl
This commit is contained in:
parent
2b60a72d06
commit
04e8a49d2e
|
@ -19,7 +19,8 @@ Fixed:
|
||||||
|
|
||||||
- Deprecate the use of `io.popen` in following widgets:
|
- Deprecate the use of `io.popen` in following widgets:
|
||||||
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
||||||
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd
|
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd,
|
||||||
|
cpu_freebsd
|
||||||
* volume, gmail, mdir, mpd, fs
|
* volume, gmail, mdir, mpd, fs
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
local tonumber = tonumber
|
|
||||||
local setmetatable = setmetatable
|
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local string = { gmatch = string.gmatch }
|
local string = { gmatch = string.gmatch }
|
||||||
-- }}}
|
-- }}}
|
||||||
|
@ -16,54 +14,55 @@ local cpu_total = {}
|
||||||
local cpu_idle = {}
|
local cpu_idle = {}
|
||||||
|
|
||||||
-- {{{ CPU widget type
|
-- {{{ CPU widget type
|
||||||
local function worker(format)
|
function cpu_freebsd.async(format, warg, callback)
|
||||||
local cp_times = helpers.sysctl("kern.cp_times")
|
|
||||||
local matches = {}
|
local matches = {}
|
||||||
local tmp_total = {}
|
local tmp_total = {}
|
||||||
local tmp_idle = {}
|
local tmp_idle = {}
|
||||||
local tmp_usage = {}
|
local tmp_usage = {}
|
||||||
|
|
||||||
-- Read input data
|
helpers.sysctl_async({ "kern.cp_times" }, function(ret)
|
||||||
for v in string.gmatch(cp_times, "([%d]+)") do
|
-- Read input data
|
||||||
table.insert(matches, v)
|
for v in string.gmatch(ret["kern.cp_times"], "([%d]+)") do
|
||||||
end
|
table.insert(matches, v)
|
||||||
|
end
|
||||||
|
|
||||||
-- Set first value of function tables
|
-- Set first value of function tables
|
||||||
if #cpu_total == 0 then -- check for empty table
|
if #cpu_total == 0 then -- check for empty table
|
||||||
|
for i = 1, #matches / 5 + 1 do
|
||||||
|
cpu_total[i] = 0
|
||||||
|
cpu_idle[i] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
for i = 1, #matches / 5 + 1 do
|
for i = 1, #matches / 5 + 1 do
|
||||||
cpu_total[i] = 0
|
tmp_total[i] = 0
|
||||||
cpu_idle[i] = 0
|
tmp_idle[i] = 0
|
||||||
|
tmp_usage[i] = 0
|
||||||
end
|
end
|
||||||
end
|
|
||||||
for i = 1, #matches / 5 + 1 do
|
|
||||||
tmp_total[i] = 0
|
|
||||||
tmp_idle[i] = 0
|
|
||||||
tmp_usage[i] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- CPU usage
|
-- CPU usage
|
||||||
for i, v in ipairs(matches) do
|
for i, v in ipairs(matches) do
|
||||||
local index = math.floor((i-1) / 5) + 2 -- current cpu
|
local index = math.floor((i-1) / 5) + 2 -- current cpu
|
||||||
|
|
||||||
tmp_total[1] = tmp_total[1] + v
|
tmp_total[1] = tmp_total[1] + v
|
||||||
tmp_total[index] = tmp_total[index] + v
|
tmp_total[index] = tmp_total[index] + v
|
||||||
|
|
||||||
if (i-1) % 5 == 4 then
|
if (i-1) % 5 == 4 then
|
||||||
tmp_idle[1] = tmp_idle[1] + v
|
tmp_idle[1] = tmp_idle[1] + v
|
||||||
tmp_idle[index] = tmp_idle[index] + v
|
tmp_idle[index] = tmp_idle[index] + v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, #tmp_usage do
|
for i = 1, #tmp_usage do
|
||||||
tmp_usage[i] = tmp_total[i] - cpu_total[i]
|
tmp_usage[i] = tmp_total[i] - cpu_total[i]
|
||||||
tmp_usage[i] = math.floor((tmp_usage[i] - (tmp_idle[i] - cpu_idle[i])) / tmp_usage[i] * 100)
|
tmp_usage[i] = math.floor((tmp_usage[i] - (tmp_idle[i] - cpu_idle[i])) / tmp_usage[i] * 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
cpu_total = tmp_total
|
cpu_total = tmp_total
|
||||||
cpu_idle = tmp_idle
|
cpu_idle = tmp_idle
|
||||||
|
|
||||||
return tmp_usage
|
return callback(tmp_usage)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(cpu_freebsd, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(cpu_freebsd)
|
||||||
|
|
|
@ -16,15 +16,7 @@ function thermal_freebsd.async(format, warg, callback)
|
||||||
helpers.sysctl_async(warg, function(ret)
|
helpers.sysctl_async(warg, function(ret)
|
||||||
local thermals = {}
|
local thermals = {}
|
||||||
|
|
||||||
for k, v in pairs(ret) do
|
|
||||||
print(k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=1,#warg do
|
for i=1,#warg do
|
||||||
print(warg[i])
|
|
||||||
print(ret[warg[i]])
|
|
||||||
print(ret["hw.acpi.thermal.tz0.temperature"])
|
|
||||||
print(ret['hw.acpi.thermal.tz0.temperature'])
|
|
||||||
if ret[warg[i]] ~= nil then
|
if ret[warg[i]] ~= nil then
|
||||||
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local setmetatable = setmetatable
|
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
|
|
Loading…
Reference in New Issue