From 82e82c31578d7b056b831aa2b0579efc9464e501 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Fri, 17 Jul 2020 16:09:00 +0200 Subject: Use less CPU in goma Only re-draw when something changes and update once per 5 sec --- src/goma.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/goma.cc b/src/goma.cc index c82920d..47f0a43 100644 --- a/src/goma.cc +++ b/src/goma.cc @@ -28,6 +28,14 @@ struct State { std::string msg_; uint64_t running_{0}; uint64_t failed_{0}; + + bool operator==(State const& state) const { + if (error_ != state.error_) + return false; + if (error_) + return msg_ == state.msg_; + return running_ == state.running_ && failed_ == state.failed_; + } }; class GomaPoll { @@ -86,9 +94,11 @@ private: { std::unique_lock lock(mutex_); - state_ = state; - io::write(pipe_, "s", 1); - cond_.wait_for(lock, std::chrono::seconds(1)); + if (!(state_ == state)) { + state_ = state; + io::write(pipe_, "s", 1); + } + cond_.wait_for(lock, std::chrono::seconds(5)); if (quit_) break; } -- cgit v1.3