]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
logger: avoid dup lines when we get behind
authorSage Weil <sage@newdream.net>
Tue, 8 Dec 2009 16:25:21 +0000 (08:25 -0800)
committerSage Weil <sage@newdream.net>
Tue, 8 Dec 2009 16:25:21 +0000 (08:25 -0800)
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
src/common/Logger.h

index 527004fd5a7f713d62b0905774185dd1d0ea6611..17b02137fa15ca498fc454dd2f46d35165509d7c 100644 (file)
@@ -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<Logger*>::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<Logger*>::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; i<type->num_keys; i++) {
-    if (type->inc_keys[i]) {
-      this->vals[i] = 0;
-      this->fvals[i] = 0;
+  if (reset) {
+    // reset the counters
+    for (int i=0; i<type->num_keys; i++) {
+      if (type->inc_keys[i]) {
+       this->vals[i] = 0;
+       this->fvals[i] = 0;
+      }
     }
   }
 }
index 771f20b1cac545ecc35eb7ce5ca0db2dc1733dcd..c8a75115895e89316ac5316c0fe2b827a6f8e345 100644 (file)
@@ -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);
 };