From 79791681b96a24cfb7c60c9ef2e444246ad0d77f Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Fri, 12 Feb 2010 23:14:59 +0100 Subject: hlinting Ignore-this: ab56894a498e5d5b2b551fbadafade08 darcs-hash:20100212221459-1d908-944944fcb9f40a91f7cc064a2a6a97f527c84941.gz --- Plugins/Monitors/Top.hs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Plugins/Monitors/Top.hs b/Plugins/Monitors/Top.hs index 2e235d8..38686f6 100644 --- a/Plugins/Monitors/Top.hs +++ b/Plugins/Monitors/Top.hs @@ -23,7 +23,7 @@ import System.Directory import System.FilePath import System.Posix.Unistd (getSysVar, SysVar(ClockTick)) import Foreign.C.Types -import Data.List (sortBy, foldl') +import Data.List (sortBy) import Data.Ord (comparing) import Data.IORef @@ -111,24 +111,20 @@ type TimeEntry = (Pid, TimeInfo) type Times = IntMap TimeInfo type TimesRef = IORef Times -timeinfo :: FilePath -> IO TimeEntry -timeinfo = handlePidFile (0, ("", 0)) $ \fs -> +timeEntry :: FilePath -> IO TimeEntry +timeEntry = handlePidFile (0, ("", 0)) $ \fs -> let rf = read . (fs!!) !pid = read (head fs) !n = drop 1 $ init (fs!!1) !t = rf 13 + rf 14 - in evaluate $ (pid, (n, t)) + in evaluate (pid, (n, t)) timeinfos :: IO Times -timeinfos = do - fs <- processes - tis <- mapM timeinfo $! fs - return $ foldl' acc M.empty tis - where acc m (p, (n, t)) = M.insert p (n, t) m +timeinfos = fmap M.fromList (processes >>= mapM timeEntry) combineTimeInfos :: Times -> Times -> Times combineTimeInfos !t0 !t1 = M.intersectionWith timeDiff t1 t0 - where timeDiff (n, x1) (_, x0) = (n, (x1 - x0)) + where timeDiff (n, x1) (_, x0) = (n, x1 - x0) topTimeProcesses :: Int -> TimesRef -> Float -> IO [TimeInfo] topTimeProcesses n tref lapse = do -- cgit v1.2.3