From 2b13b5cf6595d81280c95eb9cf507a9817e3f641 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sat, 13 Jun 2020 17:33:12 +0530 Subject: Add some optimization --- src/Xmobar/Plugins/Monitors/Cpu.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Xmobar/Plugins/Monitors/Cpu.hs b/src/Xmobar/Plugins/Monitors/Cpu.hs index acb3cfd..3d18da3 100644 --- a/src/Xmobar/Plugins/Monitors/Cpu.hs +++ b/src/Xmobar/Plugins/Monitors/Cpu.hs @@ -43,10 +43,15 @@ cpuConfig = mkMConfig type CpuDataRef = IORef [Int] cpuData :: IO [Int] -cpuData = cpuParser `fmap` B.readFile "/proc/stat" +cpuData = cpuParser <$> B.readFile "/proc/stat" + +readInt :: B.ByteString -> Int +readInt bs = case B.readInt bs of + Nothing -> 0 + Just (i, _) -> i cpuParser :: B.ByteString -> [Int] -cpuParser = map (read . B.unpack) . tail . B.words . head . B.lines +cpuParser = map readInt . tail . B.words . head . B.lines parseCpu :: CpuDataRef -> IO [Float] parseCpu cref = -- cgit v1.2.3