diff options
author | Sibi Prabakaran <sibi@psibi.in> | 2020-06-13 14:52:36 +0530 |
---|---|---|
committer | Sibi Prabakaran <sibi@psibi.in> | 2020-06-13 14:52:36 +0530 |
commit | 2ae720ab47213d93ffd22a40cd99b80bec1d022a (patch) | |
tree | 167797ec0c4088869a615c69ffb06cba09adf1b6 | |
parent | 7bc2e6b0d6372a602a450a33ba4602e4d84206eb (diff) | |
download | xmobar-2ae720ab47213d93ffd22a40cd99b80bec1d022a.tar.gz xmobar-2ae720ab47213d93ffd22a40cd99b80bec1d022a.tar.bz2 |
Initial support for benchmarks of the plugins
-rw-r--r-- | bench/main.hs | 44 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Common/Run.hs | 5 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Cpu.hs | 2 | ||||
-rw-r--r-- | xmobar.cabal | 18 |
4 files changed, 61 insertions, 8 deletions
diff --git a/bench/main.hs b/bench/main.hs new file mode 100644 index 0000000..205acc8 --- /dev/null +++ b/bench/main.hs @@ -0,0 +1,44 @@ +{-#LANGUAGE RecordWildCards#-} + +import Gauge +import Xmobar +import Xmobar.Plugins.Monitors.Common.Types +import Xmobar.Plugins.Monitors.Common.Run +import Xmobar.Plugins.Monitors.Cpu +import Control.Monad.Reader +import Data.IORef (newIORef) + +main :: IO () +main = do + cpuParams <- mkCpuArgs + defaultMain $ normalBench cpuParams + where + normalBench args = [ bgroup "Cpu Benchmarks" $ normalCpuBench args] + +runMonitor :: MConfig -> Monitor a -> IO a +runMonitor config r = runReaderT r config + +data CpuArguments = CpuArguments { + cpuRef :: CpuDataRef, + cpuMConfig :: MConfig, + cpuArgs :: [String] + } + +mkCpuArgs :: IO CpuArguments +mkCpuArgs = do + cpuRef <- newIORef [] + _ <- parseCpu cpuRef + cpuMConfig <- cpuConfig + let cpuArgs = ["-L","3","-H","50","--normal","green","--high","red"] + pure $ CpuArguments {..} + +-- | The action which will be benchmarked +cpuAction :: CpuArguments -> IO String +cpuAction CpuArguments{..} = runMonitor cpuMConfig (doArgs cpuArgs (runCpu cpuRef) (\_ -> return True)) + + +cpuBenchmark :: CpuArguments -> Benchmarkable +cpuBenchmark cpuParams = nfIO $ cpuAction cpuParams + +normalCpuBench :: CpuArguments -> [Benchmark] +normalCpuBench args = [bench "CPU normal args" (cpuBenchmark args)] diff --git a/src/Xmobar/Plugins/Monitors/Common/Run.hs b/src/Xmobar/Plugins/Monitors/Common/Run.hs index 3baa7aa..760eab1 100644 --- a/src/Xmobar/Plugins/Monitors/Common/Run.hs +++ b/src/Xmobar/Plugins/Monitors/Common/Run.hs @@ -22,6 +22,7 @@ module Xmobar.Plugins.Monitors.Common.Run ( runM , runML , runMLD , getArgvs + , doArgs ) where import Control.Exception (SomeException,handle) @@ -35,8 +36,8 @@ import Xmobar.Run.Exec (doEveryTenthSeconds) options :: [OptDescr Opts] options = [ - Option "H" ["High"] (ReqArg High "number") "The high threshold" - , Option "L" ["Low"] (ReqArg Low "number") "The low threshold" + Option ['H'] ["High"] (ReqArg High "number") "The high threshold" + , Option ['L'] ["Low"] (ReqArg Low "number") "The low threshold" , Option "h" ["high"] (ReqArg HighColor "color number") "Color for the high threshold: ex \"#FF0000\"" , Option "n" ["normal"] (ReqArg NormalColor "color number") "Color for the normal threshold: ex \"#00FF00\"" , Option "l" ["low"] (ReqArg LowColor "color number") "Color for the low threshold: ex \"#0000FF\"" diff --git a/src/Xmobar/Plugins/Monitors/Cpu.hs b/src/Xmobar/Plugins/Monitors/Cpu.hs index 157631d..acb3cfd 100644 --- a/src/Xmobar/Plugins/Monitors/Cpu.hs +++ b/src/Xmobar/Plugins/Monitors/Cpu.hs @@ -13,7 +13,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.Monitors.Cpu (startCpu) where +module Xmobar.Plugins.Monitors.Cpu (startCpu, runCpu, cpuConfig, CpuDataRef, parseCpu) where import Xmobar.Plugins.Monitors.Common import qualified Data.ByteString.Lazy.Char8 as B diff --git a/xmobar.cabal b/xmobar.cabal index b309433..d1e7660 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -95,7 +95,10 @@ library default-language: Haskell2010 hs-source-dirs: src - exposed-modules: Xmobar + exposed-modules: Xmobar, + Xmobar.Plugins.Monitors.Common.Types, + Xmobar.Plugins.Monitors.Common.Run, + Xmobar.Plugins.Monitors.Cpu other-modules: Paths_xmobar, Xmobar.Config.Types, @@ -140,14 +143,11 @@ library Xmobar.Plugins.Monitors, Xmobar.Plugins.Monitors.Batt, Xmobar.Plugins.Monitors.Common, - Xmobar.Plugins.Monitors.Common.Types, - Xmobar.Plugins.Monitors.Common.Run, Xmobar.Plugins.Monitors.Common.Output, Xmobar.Plugins.Monitors.Common.Parsers, Xmobar.Plugins.Monitors.Common.Files, Xmobar.Plugins.Monitors.CoreTemp, Xmobar.Plugins.Monitors.CpuFreq, - Xmobar.Plugins.Monitors.Cpu, Xmobar.Plugins.Monitors.Disk, Xmobar.Plugins.Monitors.Mem, Xmobar.Plugins.Monitors.MultiCoreTemp, @@ -331,7 +331,6 @@ test-suite XmobarTest other-modules: Xmobar.Plugins.Monitors.CommonSpec Xmobar.Plugins.Monitors.Common Xmobar.Plugins.Monitors.Common.Parsers - Xmobar.Plugins.Monitors.Common.Run Xmobar.Plugins.Monitors.Common.Types Xmobar.Plugins.Monitors.Common.Output Xmobar.Plugins.Monitors.Common.Files @@ -348,3 +347,12 @@ test-suite XmobarTest Xmobar.Plugins.Monitors.AlsaSpec cpp-options: -DALSA + +benchmark xmobarbench + type: exitcode-stdio-1.0 + main-is: main.hs + hs-source-dirs: + bench + ghc-options: -O2 + build-depends: base, gauge, xmobar, mtl + default-language: Haskell2010 |