2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
2009-08-06 18:18:45 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local tonumber = tonumber
|
2010-03-13 02:11:41 +01:00
|
|
|
local io = { lines = io.lines }
|
2009-08-06 18:18:45 +02:00
|
|
|
local setmetatable = setmetatable
|
2009-10-05 00:10:47 +02:00
|
|
|
local string = { match = string.match }
|
2009-08-06 18:18:45 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Cpuinf: provides speed and cache information for all available CPUs/cores
|
|
|
|
module("vicious.cpuinf")
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ CPU Information widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format)
|
2009-10-02 23:31:46 +02:00
|
|
|
local cpu_id = nil
|
2009-08-06 18:18:45 +02:00
|
|
|
local cpu_info = {}
|
|
|
|
|
2010-03-13 02:11:41 +01:00
|
|
|
-- Get CPU info
|
|
|
|
for line in io.lines("/proc/cpuinfo") do
|
2009-10-05 00:10:47 +02:00
|
|
|
if string.match(line, "^processor.*") then
|
|
|
|
cpu_id = string.match(line, "([%d]+)")
|
|
|
|
elseif string.match(line, "^cpu MHz.*") then
|
2009-10-26 20:32:48 +01:00
|
|
|
local cpu_speed = tonumber(string.match(line, "([%d]+)%."))
|
2009-10-02 23:31:46 +02:00
|
|
|
cpu_info["{cpu"..cpu_id.." mhz}"] = cpu_speed
|
2009-10-26 20:32:48 +01:00
|
|
|
cpu_info["{cpu"..cpu_id.." ghz}"] = cpu_speed / 1000
|
2009-10-05 00:10:47 +02:00
|
|
|
elseif string.match(line, "^cache size.*") then
|
2009-10-26 20:32:48 +01:00
|
|
|
local cpu_cache = tonumber(string.match(line, "([%d]+)[%s]KB"))
|
2009-10-02 23:31:46 +02:00
|
|
|
cpu_info["{cpu"..cpu_id.." kb}"] = cpu_cache
|
2009-10-26 20:32:48 +01:00
|
|
|
cpu_info["{cpu"..cpu_id.." mb}"] = cpu_cache / 1024
|
2009-08-06 18:18:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return cpu_info
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|