From 9bc49228b0d7f864de04124dc58643ec0a63208b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 8 Dec 2009 08:25:21 -0800 Subject: [PATCH] logger: avoid dup lines when we get behind If we get behind (say, after SIGSTOP ... SIGCONT), instead of printing dup lines for every interval we missed, print just the first and last. That will make any graph have a nice, hopefully obvious perfectly horizontal line. --- src/common/Logger.cc | 32 +++++++++++++++++++------------- src/common/Logger.h | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/common/Logger.cc b/src/common/Logger.cc index 527004fd5a7f7..17b02137fa15c 100644 --- a/src/common/Logger.cc +++ b/src/common/Logger.cc @@ -88,13 +88,17 @@ static void flush_all_loggers() int now_sec = fromstart.sec(); // do any catching up we need to - while (now_sec - last_flush >= g_conf.logger_interval) { - generic_dout(20) << "fromstart " << fromstart << " last_flush " << last_flush << " flushing" << dendl; - for (list::iterator p = logger_list.begin(); - p != logger_list.end(); - ++p) - (*p)->_flush(); - last_flush += g_conf.logger_interval; + bool twice = now_sec - last_flush >= 2 * g_conf.logger_interval; + again: + generic_dout(20) << "fromstart " << fromstart << " last_flush " << last_flush << " flushing" << dendl; + for (list::iterator p = logger_list.begin(); + p != logger_list.end(); + ++p) + (*p)->_flush(); + last_flush = now_sec - (now_sec % g_conf.logger_interval); + if (twice) { + twice = false; + goto again; } // schedule next flush event @@ -185,7 +189,7 @@ Logger::~Logger() } -void Logger::_flush() +void Logger::_flush(bool reset) { // header? wrote_header_last++; @@ -228,11 +232,13 @@ void Logger::_flush() } out << std::endl; - // reset the counters - for (int i=0; inum_keys; i++) { - if (type->inc_keys[i]) { - this->vals[i] = 0; - this->fvals[i] = 0; + if (reset) { + // reset the counters + for (int i=0; inum_keys; i++) { + if (type->inc_keys[i]) { + this->vals[i] = 0; + this->fvals[i] = 0; + } } } } diff --git a/src/common/Logger.h b/src/common/Logger.h index 771f20b1cac54..c8a75115895e8 100644 --- a/src/common/Logger.h +++ b/src/common/Logger.h @@ -69,7 +69,7 @@ class Logger { double favg(int f, double v); //void flush(); - void _flush(); + void _flush(bool reset=true); void set_start(utime_t s); }; -- 2.39.5