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 /bench | |
parent | 7bc2e6b0d6372a602a450a33ba4602e4d84206eb (diff) | |
download | xmobar-2ae720ab47213d93ffd22a40cd99b80bec1d022a.tar.gz xmobar-2ae720ab47213d93ffd22a40cd99b80bec1d022a.tar.bz2 |
Initial support for benchmarks of the plugins
Diffstat (limited to 'bench')
-rw-r--r-- | bench/main.hs | 44 |
1 files changed, 44 insertions, 0 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)] |