diff options
author | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-04 16:24:34 +0200 |
---|---|---|
committer | Michal Zielonka <michal.zielonka.8001@gmail.com> | 2021-10-04 16:27:40 +0200 |
commit | 8bb906bc48571195495a6629efcac782eba440f6 (patch) | |
tree | 79c8e007e0cae6436859381ebe036410a40b1da8 /src/Xmobar/Plugins/Monitors | |
parent | 6525d5102ef3e1649bc71d29734bbae93cc8c1b7 (diff) | |
download | xmobar-8bb906bc48571195495a6629efcac782eba440f6.tar.gz xmobar-8bb906bc48571195495a6629efcac782eba440f6.tar.bz2 |
add reading memory specific for freebsd
In freebsd /proc/memoryinfo is absent so we should use sysctl for
obtaining info about stats of memory.
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Mem.hs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Mem.hs b/src/Xmobar/Plugins/Monitors/Mem.hs index 91ed3e6..6f3e383 100644 --- a/src/Xmobar/Plugins/Monitors/Mem.hs +++ b/src/Xmobar/Plugins/Monitors/Mem.hs @@ -1,3 +1,4 @@ +{-#LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Mem @@ -15,8 +16,12 @@ module Xmobar.Plugins.Monitors.Mem (memConfig, runMem, totalMem, usedMem) where import Xmobar.Plugins.Monitors.Common -import qualified Data.Map as M import System.Console.GetOpt +#ifdef FREEBSD +import System.BSD.Sysctl (sysctlReadUInt) +#else +import qualified Data.Map as M +#endif data MemOpts = MemOpts { usedIconPattern :: Maybe IconPattern @@ -49,6 +54,36 @@ memConfig = mkMConfig "usedratio", "freeratio", "availableratio", "total", "free", "buffer", "cache", "available", "used"] -- available replacements +#ifdef FREEBSD +parseMEM :: IO [Float] +parseMEM = do stats <- mapM sysctlReadUInt [ + "vm.stats.vm.v_page_size" + , "vm.stats.vm.v_page_count" + , "vm.stats.vm.v_free_count" + , "vm.stats.vm.v_active_count" + , "vm.stats.vm.v_inactive_count" + , "vm.stats.vm.v_wire_count" + , "vm.stats.vm.v_cache_count"] + + let [ pagesize, totalpages, freepages, activepages, inactivepages, wiredpages, cachedpages ] = fmap fromIntegral stats + usedpages = activepages + wiredpages + cachedpages + availablepages = inactivepages + cachedpages + freepages + bufferedpages = activepages + inactivepages + wiredpages + + available = availablepages * pagesize + used = usedpages * pagesize + free = freepages * pagesize + cache = cachedpages * pagesize + buffer = bufferedpages * pagesize + total = totalpages * pagesize + + usedratio = usedpages / totalpages + freeratio = freepages / totalpages + availableratio = availablepages / totalpages + + return [usedratio, freeratio, availableratio, total, free, buffer, cache, available, used] + +#else fileMEM :: IO String fileMEM = readFile "/proc/meminfo" @@ -64,6 +99,7 @@ parseMEM = freeratio = free / total availableratio = available / total return [usedratio, freeratio, availableratio, total, free, buffer, cache, available, used] +#endif totalMem :: IO Float totalMem = fmap ((*1024) . (!!1)) parseMEM |