From d52a1dc3a6c4de5d250789f57ee0d26fa26e94c9 Mon Sep 17 00:00:00 2001 From: mutlusun Date: Thu, 5 Jan 2017 10:48:25 +0100 Subject: [PATCH] add cpufreq and cpuinf widget (not tested for date like bug) --- README.md | 40 ++++++++++++++-------- widgets/cpu_freebsd.lua | 7 ---- widgets/cpufreq_freebsd.lua | 34 ++++++++++++++++++ widgets/{cpufreq.lua => cpufreq_linux.lua} | 4 +-- widgets/{cpuinf.lua => cpuinf_linux.lua} | 4 +-- widgets/thermal_freebsd.lua | 5 --- widgets/volume_freebsd.lua | 5 --- 7 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 widgets/cpufreq_freebsd.lua rename widgets/{cpufreq.lua => cpufreq_linux.lua} (93%) rename widgets/{cpuinf.lua => cpuinf_linux.lua} (91%) diff --git a/README.md b/README.md index d4a1335..dcde298 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,32 @@ Supported platforms: Linux, FreeBSD. * returns 1st value as usage of all CPUs/cores, 2nd as usage of first CPU/core, 3rd as usage of second CPU/core etc. +**vicious.widgets.cpufreq** + +Provides freq, voltage and governor info for a requested CPU. +Supported platforms: Linux, FreeBSD. + +- Arguments (per platform): + * Linux: takes the CPU ID as an argument, i.e. "cpu0" + * FreeBSD: takes the CPU ID as an argument, i.e. "0" +- Returns (per platform): + * Linux: returns 1st value as frequency of requested CPU in MHz, 2nd in GHz, + 3rd as voltage in mV, 4th as voltage in V and 5th as the governor state + * FreeBSD: returns 1st value as frequency of requested CPU in MHz, 2nd in GHz, + 3rd as voltage in mV, 4th as voltage in V and 5th as the governor state, + but only the first two are supported (other values will be always `"N/A"`) + +**vicious.widgets.cpuinf** + +Provides speed and cache information for all available CPUs/cores. +Supported platforms: Linux. + +- Arguments: + * None +- Returns: + * returns a table with string keys, using CPU ID as a base: `{cpu0 mhz}`, + `{cpu0 ghz}`, `{cpu0 kb}`, `{cpu0 mb}`, `{cpu1 mhz}` etc. + **vicious.widgets.date** Provides access to os.date, with optional time formatting provided as the @@ -336,20 +362,6 @@ Supported platforms: platform independent. `{windkmh}`, `{sky}`, `{weather}`, `{tempf}`, `{tempc}`, `{humid}`, `{dewf}`, `{dewc}` and `{press}` -**vicious.widgets.cpuinf** - - - provides speed and cache information for all available CPUs/cores - - returns a table with string keys, using CPU ID as a base: - {cpu0 mhz}, {cpu0 ghz}, {cpu0 kb}, {cpu0 mb}, {cpu1 mhz} etc. - -**vicious.widgets.cpufreq** - - - provides freq, voltage and governor info for a requested CPU - - takes the CPU ID as an argument, i.e. "cpu0" - - returns 1st value as frequency of requested CPU in MHz, 2nd in - GHz, 3rd as voltage in mV, 4th as voltage in V and 5th as the - governor state - **vicious.widgets.mem** - provides RAM and Swap usage statistics diff --git a/widgets/cpu_freebsd.lua b/widgets/cpu_freebsd.lua index eb21165..044286c 100644 --- a/widgets/cpu_freebsd.lua +++ b/widgets/cpu_freebsd.lua @@ -1,10 +1,3 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2011, Adrian C. --- * (c) 2009, Lucas de Vries --- * (c) 2011, Jörg Thalheim ---------------------------------------------------- - -- {{{ Grab environment local helpers = require("vicious.helpers") local tonumber = tonumber diff --git a/widgets/cpufreq_freebsd.lua b/widgets/cpufreq_freebsd.lua new file mode 100644 index 0000000..351cc68 --- /dev/null +++ b/widgets/cpufreq_freebsd.lua @@ -0,0 +1,34 @@ +-- {{{ Grab environment +local tonumber = tonumber +local setmetatable = setmetatable +local helpers = require("vicious.helpers") +-- }}} + + +-- Cpufreq: provides freq, voltage and governor info for a requested CPU +-- vicious.widgets.cpufreq +local cpufreq_freebsd = {} + + +-- {{{ CPU frequency widget type +local function worker(format, warg) + if not warg then return end + + -- Default frequency and voltage values + local freqv = { + ["mhz"] = "N/A", ["ghz"] = "N/A", + ["v"] = "N/A", ["mv"] = "N/A", + } + + local freq = tonumber(helpers.sysctl("dev.cpu." .. warg .. ".freq")) + + freqv.mhz = freq + freqv.ghz = freq / 1000 + + local governor = "N/A" + + return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor} +end +-- }}} + +return setmetatable(cpufreq_freebsd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpufreq.lua b/widgets/cpufreq_linux.lua similarity index 93% rename from widgets/cpufreq.lua rename to widgets/cpufreq_linux.lua index 39470a4..4cac998 100644 --- a/widgets/cpufreq.lua +++ b/widgets/cpufreq_linux.lua @@ -13,7 +13,7 @@ local helpers = require("vicious.helpers") -- Cpufreq: provides freq, voltage and governor info for a requested CPU -- vicious.widgets.cpufreq -local cpufreq = {} +local cpufreq_linux = {} -- {{{ CPU frequency widget type @@ -58,4 +58,4 @@ local function worker(format, warg) end -- }}} -return setmetatable(cpufreq, { __call = function(_, ...) return worker(...) end }) +return setmetatable(cpufreq_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpuinf.lua b/widgets/cpuinf_linux.lua similarity index 91% rename from widgets/cpuinf.lua rename to widgets/cpuinf_linux.lua index b0ea782..11a7012 100644 --- a/widgets/cpuinf.lua +++ b/widgets/cpuinf_linux.lua @@ -13,7 +13,7 @@ local string = { gmatch = string.gmatch } -- Cpuinf: provides speed and cache information for all available CPUs/cores -- vicious.widgets.cpuinf -local cpuinf = {} +local cpuinf_linux = {} -- {{{ CPU Information widget type @@ -41,4 +41,4 @@ local function worker(format) end -- }}} -return setmetatable(cpuinf, { __call = function(_, ...) return worker(...) end }) +return setmetatable(cpuinf_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/thermal_freebsd.lua b/widgets/thermal_freebsd.lua index 160cf23..718fc1f 100644 --- a/widgets/thermal_freebsd.lua +++ b/widgets/thermal_freebsd.lua @@ -1,8 +1,3 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- - -- {{{ Grab environment local setmetatable = setmetatable local string = { match = string.match } diff --git a/widgets/volume_freebsd.lua b/widgets/volume_freebsd.lua index 37a5833..13798d7 100644 --- a/widgets/volume_freebsd.lua +++ b/widgets/volume_freebsd.lua @@ -1,8 +1,3 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- - -- {{{ Grab environment local tonumber = tonumber local io = { popen = io.popen }