summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-02-13 04:57:17 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-02-13 04:57:17 +0100
commit31715e3db637702d1289819909131a32abb3777a (patch)
treef2bc074c66479c940c88aadffacf5300619c8af7
parent8f7606493f55c503e5be9047b176ad4941c06a0b (diff)
downloadxmobar-31715e3db637702d1289819909131a32abb3777a.tar.gz
xmobar-31715e3db637702d1289819909131a32abb3777a.tar.bz2
Cpu and MultiCpu should also be more accurate now
-rw-r--r--NEWS5
-rw-r--r--README2
-rw-r--r--src/Plugins/Monitors.hs36
-rw-r--r--src/Plugins/Monitors/Cpu.hs34
-rw-r--r--src/Plugins/Monitors/MultiCpu.hs24
-rw-r--r--src/Plugins/Monitors/Net.hs5
6 files changed, 64 insertions, 42 deletions
diff --git a/NEWS b/NEWS
index 4adffb0..499731e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
% xmobar - Release notes
% Jose A. Ortega Ruiz
-## Version 0.12.1
+## Version 0.13
_New features_
@@ -28,6 +28,7 @@ _Bug fixes_
- [issue 40]: Battery monitor now supports the new power_now, that
replaces current_now in linux kernels for v. 2.36 and above.
- [issue 42]: More accurate net monitor rates.
+ - Cpu and MultiCpu monitors are also more accurate now.
- Text is now correctly centered vertically.
- `FullBM` border spec fixed.
@@ -45,7 +46,7 @@ _Bug fixes_
xmobar has a new [maintainer], a new [website], a new [mailing
list] and uses a new [source code repository].
-Many thanks to Andrea Rossato, xombar's author and maintainer so far,
+Many thanks to Andrea Rossato, xmobar's author and maintainer so far,
for creating xmobar in the first place, and for giving me the chance
to become its maintainer. And a big thanks to Ben Boeckel, Petr Rockai
and Norbert Zeh for their patches.
diff --git a/README b/README
index 894167f..920ba9c 100644
--- a/README
+++ b/README
@@ -12,7 +12,7 @@ xmobar was inspired by the [Ion3] status bar, and supports similar
features, like dynamic color management, output templates, and
extensibility through plugins.
-This page documents xmobar 0.12 (see [release notes]).
+This page documents xmobar 0.13 (see [release notes]).
[This is a screen shot] of Andrea's desktop with [xmonad] and xmobar.
[This] is xmobar running under [sawfish], with antialiased fonts. And
diff --git a/src/Plugins/Monitors.hs b/src/Plugins/Monitors.hs
index 616ae21..0007bec 100644
--- a/src/Plugins/Monitors.hs
+++ b/src/Plugins/Monitors.hs
@@ -104,28 +104,28 @@ instance Exec Monitors where
#ifdef ALSA
alias (Volume m c _ _) = m ++ ":" ++ c
#endif
- start (Weather s a r) = runM (a ++ [s]) weatherConfig runWeather r
start (Network i a r) = startNet i a r
- start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r
- start (Memory a r) = runM a memConfig runMem r
- start (Swap a r) = runM a swapConfig runSwap r
- start (Cpu a r) = runM a cpuConfig runCpu r
- start (MultiCpu a r) = runM a multiCpuConfig runMultiCpu r
- start (Battery a r) = runM a battConfig runBatt r
- start (BatteryP s a r) = runM a battConfig (runBatt' s) r
- start (CpuFreq a r) = runM a cpuFreqConfig runCpuFreq r
- start (CoreTemp a r) = runM a coreTempConfig runCoreTemp r
- start (DiskU s a r) = runM a diskUConfig (runDiskU s) r
- start (DiskIO s a r) = runM a diskIOConfig (runDiskIO s) r
- start (TopMem a r) = runM a topMemConfig runTopMem r
- start (Uptime a r) = runM a uptimeConfig runUptime r
- start (TopProc a r) = startTop a r
+ start (Cpu a r) = startCpu a r
+ start (MultiCpu a r) = startMultiCpu a r
+ start (TopProc a r) = startTop a r
+ start (TopMem a r) = runM a topMemConfig runTopMem r
+ start (Weather s a r) = runM (a ++ [s]) weatherConfig runWeather r
+ start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r
+ start (Memory a r) = runM a memConfig runMem r
+ start (Swap a r) = runM a swapConfig runSwap r
+ start (Battery a r) = runM a battConfig runBatt r
+ start (BatteryP s a r) = runM a battConfig (runBatt' s) r
+ start (CpuFreq a r) = runM a cpuFreqConfig runCpuFreq r
+ start (CoreTemp a r) = runM a coreTempConfig runCoreTemp r
+ start (DiskU s a r) = runM a diskUConfig (runDiskU s) r
+ start (DiskIO s a r) = runM a diskIOConfig (runDiskIO s) r
+ start (Uptime a r) = runM a uptimeConfig runUptime r
#ifdef IWLIB
- start (Wireless i a r) = runM (a ++ [i]) wirelessConfig runWireless r
+ start (Wireless i a r) = runM (a ++ [i]) wirelessConfig runWireless r
#endif
#ifdef LIBMPD
- start (MPD a r) = runM a mpdConfig runMPD r
+ start (MPD a r) = runM a mpdConfig runMPD r
#endif
#ifdef ALSA
- start (Volume m c a r) = runM a volumeConfig (runVolume m c) r
+ start (Volume m c a r) = runM a volumeConfig (runVolume m c) r
#endif
diff --git a/src/Plugins/Monitors/Cpu.hs b/src/Plugins/Monitors/Cpu.hs
index 8715245..919f7a4 100644
--- a/src/Plugins/Monitors/Cpu.hs
+++ b/src/Plugins/Monitors/Cpu.hs
@@ -1,7 +1,8 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Cpu
--- Copyright : (c) Andrea Rossato
+-- Copyright : (c) 2011 Jose Antonio Ortega Ruiz
+-- (c) 2007-2010 Andrea Rossato
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
@@ -12,27 +13,30 @@
--
-----------------------------------------------------------------------------
-module Plugins.Monitors.Cpu where
+module Plugins.Monitors.Cpu (startCpu) where
import Plugins.Monitors.Common
import qualified Data.ByteString.Lazy.Char8 as B
+import Data.IORef (IORef, newIORef, readIORef, writeIORef)
cpuConfig :: IO MConfig
cpuConfig = mkMConfig
"Cpu: <total>%"
["bar","total","user","nice","system","idle"]
+type CpuDataRef = IORef [Float]
+
cpuData :: IO [Float]
-cpuData = do s <- B.readFile "/proc/stat"
- return $ cpuParser s
+cpuData = cpuParser `fmap` B.readFile "/proc/stat"
cpuParser :: B.ByteString -> [Float]
-cpuParser =
- map (read . B.unpack) . tail . B.words . head . B.lines
+cpuParser = map (read . B.unpack) . tail . B.words . head . B.lines
-parseCPU :: IO [Float]
-parseCPU =
- do (a,b) <- doActionTwiceWithDelay 750000 cpuData
+parseCpu :: CpuDataRef -> IO [Float]
+parseCpu cref =
+ do a <- readIORef cref
+ b <- cpuData
+ writeIORef cref b
let dif = zipWith (-) b a
tot = foldr (+) 0 dif
percent = map (/ tot) dif
@@ -46,8 +50,14 @@ formatCpu xs = do
ps <- showPercentsWithColors (t:xs)
return (b:ps)
-runCpu :: [String] -> Monitor String
-runCpu _ =
- do c <- io parseCPU
+runCpu :: CpuDataRef -> [String] -> Monitor String
+runCpu cref _ =
+ do c <- io (parseCpu cref)
l <- formatCpu c
parseTemplate l
+
+startCpu :: [String] -> Int -> (String -> IO ()) -> IO ()
+startCpu a r cb = do
+ cref <- newIORef []
+ _ <- parseCpu cref
+ runM a cpuConfig (runCpu cref) r cb
diff --git a/src/Plugins/Monitors/MultiCpu.hs b/src/Plugins/Monitors/MultiCpu.hs
index d93c788..a1bb082 100644
--- a/src/Plugins/Monitors/MultiCpu.hs
+++ b/src/Plugins/Monitors/MultiCpu.hs
@@ -12,11 +12,12 @@
--
-----------------------------------------------------------------------------
-module Plugins.Monitors.MultiCpu(multiCpuConfig, runMultiCpu) where
+module Plugins.Monitors.MultiCpu (startMultiCpu) where
import Plugins.Monitors.Common
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List (isPrefixOf, transpose, unfoldr)
+import Data.IORef (IORef, newIORef, readIORef, writeIORef)
multiCpuConfig :: IO MConfig
multiCpuConfig =
@@ -26,6 +27,7 @@ multiCpuConfig =
, k <- monitors]
where monitors = ["bar","total","user","nice","system","idle"]
+type CpuDataRef = IORef [[Float]]
cpuData :: IO [[Float]]
cpuData = parse `fmap` B.readFile "/proc/stat"
@@ -35,9 +37,11 @@ cpuData = parse `fmap` B.readFile "/proc/stat"
isCpu _ = False
parseList = map (parseFloat . B.unpack) . tail
-parseCpuData :: IO [[Float]]
-parseCpuData =
- do (as, bs) <- doActionTwiceWithDelay 950000 cpuData
+parseCpuData :: CpuDataRef -> IO [[Float]]
+parseCpuData cref =
+ do as <- readIORef cref
+ bs <- cpuData
+ writeIORef cref bs
let p0 = zipWith percent bs as
return p0
@@ -68,9 +72,15 @@ formatAutoCpus :: [String] -> Monitor [String]
formatAutoCpus [] = return $ replicate 6 ""
formatAutoCpus xs = return $ map unwords (groupData xs)
-runMultiCpu :: [String] -> Monitor String
-runMultiCpu _ =
- do c <- io parseCpuData
+runMultiCpu :: CpuDataRef -> [String] -> Monitor String
+runMultiCpu cref _ =
+ do c <- io $ parseCpuData cref
l <- formatMultiCpus c
a <- formatAutoCpus l
parseTemplate $ a ++ l
+
+startMultiCpu :: [String] -> Int -> (String -> IO ()) -> IO ()
+startMultiCpu a r cb = do
+ cref <- newIORef [[]]
+ _ <- parseCpuData cref
+ runM a multiCpuConfig (runMultiCpu cref) r cb
diff --git a/src/Plugins/Monitors/Net.hs b/src/Plugins/Monitors/Net.hs
index 500a753..8382542 100644
--- a/src/Plugins/Monitors/Net.hs
+++ b/src/Plugins/Monitors/Net.hs
@@ -1,7 +1,8 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Net
--- Copyright : (c) Andrea Rossato
+-- Copyright : (c) 2011 Jose Antonio Ortega Ruiz
+-- (c) 2007-2010 Andrea Rossato
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
@@ -12,7 +13,7 @@
--
-----------------------------------------------------------------------------
-module Plugins.Monitors.Net (netConfig, startNet) where
+module Plugins.Monitors.Net (startNet) where
import Plugins.Monitors.Common