diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-21 02:36:35 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-21 02:36:35 +0100 |
commit | e3853a9cb2a9a2cffa174d1334e2ca8ba610f151 (patch) | |
tree | 13aa04faea320afe85636e23686280386c1c2910 /Plugins/Monitors/MultiCpu.hs | |
parent | 598bfe5deeff079280e8513c55dc7bda3e8cf9a0 (diff) | |
download | xmobar-e3853a9cb2a9a2cffa174d1334e2ca8ba610f151.tar.gz xmobar-e3853a9cb2a9a2cffa174d1334e2ca8ba610f151.tar.bz2 |
Haskell sources moved to src/ to unclutter toplevel
Diffstat (limited to 'Plugins/Monitors/MultiCpu.hs')
-rw-r--r-- | Plugins/Monitors/MultiCpu.hs | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs deleted file mode 100644 index 535196a..0000000 --- a/Plugins/Monitors/MultiCpu.hs +++ /dev/null @@ -1,81 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Plugins.Monitors.MultiCpu --- Copyright : (c) Jose A Ortega Ruiz --- License : BSD-style (see LICENSE) --- --- Maintainer : Jose A Ortega <jao@gnu.org> --- Stability : unstable --- Portability : unportable --- --- A multi-cpu monitor for Xmobar --- ------------------------------------------------------------------------------ - -module Plugins.Monitors.MultiCpu(multiCpuConfig, runMultiCpu) where - -import Plugins.Monitors.Common -import qualified Data.ByteString.Lazy.Char8 as B -import Data.List (isPrefixOf, transpose, unfoldr) - -multiCpuConfig :: IO MConfig -multiCpuConfig = - mkMConfig "Cpu: <total>%" $ - map ("auto" ++) monitors - ++ [ k ++ n | n <- "" : map show [0 :: Int ..] - , k <- monitors] - where monitors = ["bar","total","user","nice","system","idle"] - - -cpuData :: IO [[Float]] -cpuData = do s <- B.readFile "/proc/stat" - return $ cpuParser s - -cpuParser :: B.ByteString -> [[Float]] -cpuParser = map parseList . cpuLists - where cpuLists = takeWhile isCpu . map B.words . B.lines - isCpu (w:_) = "cpu" `isPrefixOf` B.unpack w - isCpu _ = False - parseList = map (read . B.unpack) . tail - -parseCpuData :: IO [[Float]] -parseCpuData = - do (as, bs) <- doActionTwiceWithDelay 950000 cpuData - let p0 = zipWith percent bs as - return p0 - -percent :: [Float] -> [Float] -> [Float] -percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0] - where dif = zipWith (-) b a - tot = foldr (+) 0 dif - -formatMultiCpus :: [[Float]] -> Monitor [String] -formatMultiCpus [] = return $ repeat "" -formatMultiCpus xs = fmap concat $ mapM formatCpu xs - -formatCpu :: [Float] -> Monitor [String] -formatCpu xs - | length xs < 4 = showPercentsWithColors $ replicate 6 0.0 - | otherwise = let t = foldr (+) 0 $ take 3 xs - in do b <- showPercentBar (100 * t) t - ps <- showPercentsWithColors (t:xs) - return (b:ps) - -splitEvery :: (Eq a) => Int -> [a] -> [[a]] -splitEvery n = unfoldr (\x -> if x == [] - then Nothing - else Just $ splitAt n x) - -groupData :: [String] -> [[String]] -groupData = transpose . tail . splitEvery 6 - -formatAutoCpus :: [String] -> Monitor [String] -formatAutoCpus [] = return $ replicate 6 "" -formatAutoCpus xs = return $ map unwords (groupData xs) - -runMultiCpu :: [String] -> Monitor String -runMultiCpu _ = - do c <- io parseCpuData - l <- formatMultiCpus c - a <- formatAutoCpus l - parseTemplate (a ++ l) |