diff options
Diffstat (limited to 'src/Plugins/Monitors/Top.hs')
-rw-r--r-- | src/Plugins/Monitors/Top.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Plugins/Monitors/Top.hs b/src/Plugins/Monitors/Top.hs index 6f16bdb..3d246ff 100644 --- a/src/Plugins/Monitors/Top.hs +++ b/src/Plugins/Monitors/Top.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Top --- Copyright : (c) Jose A Ortega Ruiz +-- Copyright : (c) 2010, 2011, 2012, 2013, 2014 Jose A Ortega Ruiz -- License : BSD-style (see LICENSE) -- -- Maintainer : Jose A Ortega Ruiz <jao@gnu.org> @@ -57,10 +57,15 @@ processes :: IO [FilePath] processes = fmap (filter isPid) (getDirectoryContents "/proc") where isPid = (`elem` ['0'..'9']) . head +statWords :: [String] -> [String] +statWords line@(x:pn:ppn:xs) = + if last pn == ')' then line else statWords (x:(pn ++ " " ++ ppn):xs) +statWords _ = replicate 52 "0" + getProcessData :: FilePath -> IO [String] getProcessData pidf = handle ign $ withFile ("/proc" </> pidf </> "stat") ReadMode readWords - where readWords = fmap words . hGetLine + where readWords = fmap (statWords . words) . hGetLine ign = const (return []) :: SomeException -> IO [String] handleProcesses :: ([String] -> a) -> IO [a] @@ -96,7 +101,7 @@ meminfos = handleProcesses meminfo showMemInfo :: Float -> MemInfo -> Monitor [String] showMemInfo scale (nm, rss) = - showInfo nm (showWithUnits 2 1 rss) (100 * rss / sc) + showInfo nm (showWithUnits 3 1 rss) (100 * rss / sc) where sc = if scale > 0 then scale else 100 showMemInfos :: [MemInfo] -> Monitor [[String]] |