summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-04-18 18:55:04 +0100
committerjao <jao@gnu.org>2022-04-18 18:55:04 +0100
commit552d6f8baa1048ddb5fd22269efd50b90303ca4d (patch)
treef3cd4fdf5facd76633abb99607aa438b4172def2
parent082ef98c1c265ad927b728402d8803a86bbbaeef (diff)
downloadxmobar-552d6f8baa1048ddb5fd22269efd50b90303ca4d.tar.gz
xmobar-552d6f8baa1048ddb5fd22269efd50b90303ca4d.tar.bz2
CpuFreq: new template parameters max, min and avg.
Fixes #166.
-rw-r--r--changelog.md1
-rw-r--r--doc/plugins.org7
-rw-r--r--src/Xmobar/Plugins/Monitors/Common/Files.hs9
-rw-r--r--src/Xmobar/Plugins/Monitors/CpuFreq.hs11
4 files changed, 22 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index f9767bf..5bea14b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,7 @@ _New features_
Lawler, with FreeBSD support thanks to MichaƂ Zielonka).
- New argument `scale` for `Memory` monitor to scale size units.
- New dbus signal: `SetAlpha` (see issue #499).
+ - `CpuFreq`: new template parameters `max`, `min` and `avg`.
_Bug fixes_
diff --git a/doc/plugins.org b/doc/plugins.org
index 383207c..8abc461 100644
--- a/doc/plugins.org
+++ b/doc/plugins.org
@@ -382,7 +382,9 @@
- Thresholds refer to frequency in GHz
- Variables that can be used with the =-t/--template= argument:
- =cpu0=, =cpu1=, .., =cpuN=
+ =cpu0=, =cpu1=, .., =cpuN=, give the current frequency of the
+ respective CPU core, and =max=, =min= and =avg= the maximum, minimum
+ and average frequency over all available cores.
- Default template: =Freq: <cpu0>GHz=
@@ -393,6 +395,9 @@
#+begin_src haskell
Run CpuFreq ["-t", "Freq:<cpu0>|<cpu1>GHz", "-L", "0", "-H", "2",
"-l", "lightblue", "-n","white", "-h", "red"] 50
+
+ Run CpuFreq ["-t", "Freq:<avg> GHz", "-L", "0", "-H", "2",
+ "-l", "lightblue", "-n","white", "-h", "red"] 50
#+end_src
***** =CoreTemp Args RefreshRate=
diff --git a/src/Xmobar/Plugins/Monitors/Common/Files.hs b/src/Xmobar/Plugins/Monitors/Common/Files.hs
index b08fe6c..9f28d6b 100644
--- a/src/Xmobar/Plugins/Monitors/Common/Files.hs
+++ b/src/Xmobar/Plugins/Monitors/Common/Files.hs
@@ -14,7 +14,9 @@
--
-----------------------------------------------------------------------------
-module Xmobar.Plugins.Monitors.Common.Files (checkedDataRetrieval) where
+module Xmobar.Plugins.Monitors.Common.Files ( checkedDataRetrieval
+ , checkedDataRead)
+where
#if __GLASGOW_HASKELL__ < 800
import Control.Applicative
@@ -49,6 +51,11 @@ retrieveData path lbl trans fmt = do
=<< mapM (showWithColors fmt . trans . read) pairs
)
+checkedDataRead :: [[String]] -> Monitor [Double]
+checkedDataRead paths = concat <$> mapM readData paths
+ where readData path = map (read . snd) . sortBy (compare `on` fst) <$>
+ (mapM readFiles =<< findFilesAndLabel path Nothing)
+
-- | Represents the different types of path components
data Comp = Fix String
| Var [String]
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: <cpu0>" (map ((++) "cpu" . show) [0 :: Int ..])
+ mkMConfig "Freq: <cpu0>"
+ (["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