From 32fc8214c567c7f4a4caad10fab98c760a1685b7 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Tue, 13 Aug 2019 21:41:15 +0200 Subject: Implement timer coalescing (noticeably less CPU/power usage) xmobar currently runs every monitor in its own thread. Monitors that do periodic updates simply sleep and loop. This unfortunately leads to these threads coming out of sync, and xmobar ends up waking up and redrawing for every periodic monitor. In my case, that is 7 times per second, which is enough for xmobar to be at the top of "top" with more than 1% CPU usage, and to have a noticeable impact on battery life. This commit adds a central timer coordination thread which makes sure that periodic updates happen together and that we only redraw once they're all done. Together with PR #409, I managed to lower the idle power draw of my laptop from 4W to 3W. --- src/Xmobar/Run/Exec.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/Xmobar/Run') diff --git a/src/Xmobar/Run/Exec.hs b/src/Xmobar/Run/Exec.hs index db7e7b4..ad68232 100644 --- a/src/Xmobar/Run/Exec.hs +++ b/src/Xmobar/Run/Exec.hs @@ -23,6 +23,7 @@ import Prelude import Data.Char import Control.Concurrent +import Xmobar.App.Timer (doEveryTenthSeconds) import Xmobar.System.Signal -- | Work around to the Int max bound: since threadDelay takes an Int, it @@ -34,10 +35,6 @@ tenthSeconds s | s >= x = do threadDelay (x * 100000) | otherwise = threadDelay (s * 100000) where x = (maxBound :: Int) `div` 100000 -doEveryTenthSeconds :: Int -> IO () -> IO () -doEveryTenthSeconds r action = go - where go = action >> tenthSeconds r >> go - class Show e => Exec e where alias :: e -> String alias e = takeWhile (not . isSpace) $ show e -- cgit v1.2.3