From 552d6f8baa1048ddb5fd22269efd50b90303ca4d Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 18 Apr 2022 18:55:04 +0100 Subject: CpuFreq: new template parameters max, min and avg. Fixes #166. --- src/Xmobar/Plugins/Monitors/CpuFreq.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Xmobar/Plugins/Monitors/CpuFreq.hs') diff --git a/src/Xmobar/Plugins/Monitors/CpuFreq.hs b/src/Xmobar/Plugins/Monitors/CpuFreq.hs index 9274cd7..d8a4319 100644 --- a/src/Xmobar/Plugins/Monitors/CpuFreq.hs +++ b/src/Xmobar/Plugins/Monitors/CpuFreq.hs @@ -22,7 +22,8 @@ import Xmobar.Plugins.Monitors.Common -- get more cpu frequencies. cpuFreqConfig :: IO MConfig cpuFreqConfig = - mkMConfig "Freq: " (map ((++) "cpu" . show) [0 :: Int ..]) + mkMConfig "Freq: " + (["max", "min", "avg"] ++ map ((++) "cpu" . show) [0 :: Int ..]) -- | @@ -32,12 +33,14 @@ runCpuFreq :: [String] -> Monitor String runCpuFreq _ = do suffix <- getConfigValue useSuffix ddigits <- getConfigValue decDigits - let path = ["/sys/devices/system/cpu/cpu", "/cpufreq/scaling_cur_freq"] + let paths = ["/sys/devices/system/cpu/cpu", "/cpufreq/scaling_cur_freq"] divisor = 1e6 :: Double fmt x | x < 1 = if suffix then mhzFmt x ++ "MHz" else ghzFmt x | otherwise = ghzFmt x ++ if suffix then "GHz" else "" mhzFmt x = show (round (x * 1000) :: Integer) ghzFmt = showDigits ddigits - failureMessage <- getConfigValue naString - checkedDataRetrieval failureMessage [path] Nothing (/divisor) fmt + sts xs = [maximum xs, minimum xs, sum xs / fromIntegral (length xs)] + vs <- checkedDataRead [paths] + if null vs then getConfigValue naString + else mapM (showWithColors fmt . (/divisor)) (sts vs ++ vs) >>= parseTemplate -- cgit v1.2.3