diff options
author | jinleileiking <jinleileiking@gmail.com> | 2012-05-16 18:37:15 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2012-05-19 17:11:22 +0200 |
commit | 30db4bea7bd04df7d03edc31972f5da1f37887ad (patch) | |
tree | fefbeb1d739fed7f1b32699a3dd02240fbe9c017 /widgets | |
parent | 13cec6d35ae2a73c8f8e40385a7d64e3475f97a5 (diff) | |
download | vicious-legacy-30db4bea7bd04df7d03edc31972f5da1f37887ad.tar.xz |
cpufreq: handle not existing frequency/governer
In some cases not all cpu informations will be provided.
(ex. in virtual machines)
Therefore default to "N/A".
Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/cpufreq.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/widgets/cpufreq.lua b/widgets/cpufreq.lua index a4f2eaa..11949da 100644 --- a/widgets/cpufreq.lua +++ b/widgets/cpufreq.lua @@ -29,13 +29,20 @@ local function worker(format, warg) } -- Default voltage values local voltage = { v = "N/A", mv = "N/A" } + local freqmhz = "N/A" + local freqghz = "N/A" -- Get the current frequency local freq = tonumber(cpufreq.scaling_cur_freq) -- Calculate MHz and GHz - local freqmhz = freq / 1000 - local freqghz = freqmhz / 1000 + + if freq then + freqmhz = freq / 1000 + freqghz = freqmhz / 1000 + end + + -- Get the current voltage if cpufreq.scaling_voltages then @@ -47,7 +54,7 @@ local function worker(format, warg) -- Get the current governor local governor = cpufreq.scaling_governor -- Represent the governor as a symbol - governor = governor_state[governor] or governor + governor = governor_state[governor] or governor or "N/A" return {freqmhz, freqghz, voltage.mv, voltage.v, governor} end |