From c37fdf4c1ad2d2c08fefe3adb172981f0c8c343f Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Mon, 18 Jan 2010 00:31:09 +0100 Subject: Checking for division by 0 in MultiCpus Ignore-this: 37834de5acc423c47e29c9e0a492b71c darcs-hash:20100117233109-40885-cd534ebe12270f0c46426e6ffd057d03b59c7f86.gz --- Plugins/Monitors/MultiCpu.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index 02fa842..f1b7b20 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -45,12 +45,12 @@ parseMultiCpu = return $ zipWith (\x y -> zipWith (\a b -> (a + b) / 2.0) x y) p1 p0 percent :: [Float] -> [Float] -> [Float] -percent b a = map (/ tot) $ take 4 dif +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 $ take 15 (repeat "-1%") +formatMultiCpus [] = return $ take 15 (repeat "0%") formatMultiCpus xs = fmap concat $ mapM formatMultiCpu xs formatMultiCpu :: [Float] -> Monitor [String] -- cgit v1.2.3