diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-08-06 18:18:45 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-08-06 18:18:45 +0200 |
commit | d2d244f3aa69ff0ca76022d929c2c71001af0bcd (patch) | |
tree | be14f70973beb86f38480f478851adee77652419 /cpuinf.lua | |
parent | cbd9a53fbc5c6978352fd921a8d652f36fd6adf3 (diff) | |
download | vicious-legacy-d2d244f3aa69ff0ca76022d929c2c71001af0bcd.tar.xz |
CPU Information widget included.
Widget returns speed and cache information for all available
CPUs/cores. It stores cpu speed in mhz and ghz in a table as well as
cpu cache in kb and mb. Values are retrieved using the CPU ID, i.e. we
would retrieve speed in ghz for CPU or core 1 with this format string:
${1 ghz}.
Diffstat (limited to 'cpuinf.lua')
-rw-r--r-- | cpuinf.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cpuinf.lua b/cpuinf.lua new file mode 100644 index 0000000..76514b9 --- /dev/null +++ b/cpuinf.lua @@ -0,0 +1,48 @@ +---------------------------------------------------------- +-- Licensed under the GNU General Public License version 2 +-- * Copyright (C) 2009 Adrian C. <anrxc_sysphere_org> +---------------------------------------------------------- + +-- {{{ Grab environment +local tonumber = tonumber +local io = { open = io.open } +local setmetatable = setmetatable +-- }}} + + +-- Cpuinf: provides speed and cache information for all available CPUs/cores +module("vicious.cpuinf") + + +-- {{{ CPU Information widget type +function worker(format) + -- Initialise variables + cpu_id = nil + + -- Get cpuinfo + local f = io.open("/proc/cpuinfo") + local cpu_info = {} + + -- Get data + for line in f:lines() do + if line:match("^processor.*") then + cpu_id = line:match("([%d]+)") + elseif line:match("^cpu MHz.*") then + local cpu_speed = line:match("([%d]+)%.") + -- Store values + cpu_info["{"..cpu_id.." mhz}"] = cpu_speed + cpu_info["{"..cpu_id.." ghz}"] = tonumber(cpu_speed) / 1000 + elseif line:match("^cache size.*") then + local cpu_cache = line:match("([%d]+)[%s]KB") + -- Store values + cpu_info["{"..cpu_id.." kb}"] = cpu_cache + cpu_info["{"..cpu_id.." mb}"] = tonumber(cpu_cache) / 1024 + end + end + f:close() + + return cpu_info +end +-- }}} + +setmetatable(_M, { __call = function(_, ...) return worker(...) end }) |