]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Revert "Speed optimizations. Merged 3 writes into 1."
authorSage Weil <sage@redhat.com>
Sun, 25 Oct 2015 15:50:20 +0000 (11:50 -0400)
committerSage Weil <sage@redhat.com>
Sun, 25 Oct 2015 15:50:20 +0000 (11:50 -0400)
This reverts commit 91497e46331b4755b9ff23b7ba11e631d64413ac.

Oops, this is injecting \0 in the log output.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/PrebufferedStreambuf.cc
src/common/PrebufferedStreambuf.h
src/include/utime.h
src/log/Entry.h
src/log/Log.cc

index d160176813309152313c293edef6662587112a60..d6db8bbe0af219e599739670567773792574bcfc 100644 (file)
@@ -1,6 +1,6 @@
 
 #include "common/PrebufferedStreambuf.h"
-#include <string.h>
+
 PrebufferedStreambuf::PrebufferedStreambuf(char *buf, size_t len)
   : m_buf(buf), m_buf_len(len)
 {
@@ -61,42 +61,3 @@ std::string PrebufferedStreambuf::get_str() const
     return std::string(m_buf, this->pptr() - m_buf);
   }  
 }
-// returns current size of content
-size_t PrebufferedStreambuf::size() const
-{
-  if(m_overflow.size() == 0) {
-    return this->pptr() - m_buf;
-  } else {
-    return m_buf_len + m_overflow.size();
-  }
-}
-
-// extracts up to avail chars of content
-int PrebufferedStreambuf::snprintf(char* dst, size_t avail) const
-{
-  size_t o_size=m_overflow.size();
-  size_t len_a;
-  size_t len_b;
-  if(o_size>0){
-    len_a = m_buf_len;
-    len_b = o_size;
-  } else {
-    len_a = this->pptr() - m_buf;
-    len_b = 0;
-  }
-  if(avail > len_a + len_b ) {
-    memcpy(dst, m_buf, len_a);
-    memcpy(dst + m_buf_len, m_overflow.c_str(), len_b);
-    dst[len_a + len_b] = 0;
-  } else {
-    if(avail > len_a ) {
-      memcpy(dst, m_buf, len_a);
-      memcpy(dst + m_buf_len, m_overflow.c_str(), avail - len_a - 1);
-      dst[avail - 1] = 0;
-    } else {
-      memcpy(dst, m_buf, avail - 1);
-      dst[avail - 1] = 0;
-    }
-  }
-  return len_a + len_b;
-}
index ac123810b6bc033d239b668fd082ee7e69245301..80a89aa43f3ea2782b51c9cb4668759ff415daef 100644 (file)
@@ -37,12 +37,6 @@ public:
 
   /// return a string copy (inefficiently)
   std::string get_str() const;
-
-  // returns current size of content
-  size_t size() const;
-
-  // extracts up to avail chars of content
-  int snprintf(char* dst, size_t avail) const;
-};
+};    
 
 #endif
index 27241e0b32425c09060ac36d1fc7f4b9ef3d62b1..30780d1af3937311d6bd7dd5105d852ec2f4ead4 100644 (file)
@@ -239,22 +239,12 @@ public:
     time_t tt = sec();
     localtime_r(&tt, &bdt);
 
-    return ::snprintf(out, outlen,
+    return snprintf(out, outlen,
                    "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
                    bdt.tm_year + 1900, bdt.tm_mon + 1, bdt.tm_mday,
                    bdt.tm_hour, bdt.tm_min, bdt.tm_sec, usec());
   }
 
-  static int snprintf(char *out, int outlen, time_t tt) {
-    struct tm bdt;
-    localtime_r(&tt, &bdt);
-
-    return ::snprintf(out, outlen,
-        "%04d-%02d-%02d %02d:%02d:%02d",
-        bdt.tm_year + 1900, bdt.tm_mon + 1, bdt.tm_mday,
-        bdt.tm_hour, bdt.tm_min, bdt.tm_sec);
-  }
-
   static int parse_date(const string& date, uint64_t *epoch, uint64_t *nsec,
                         string *out_date=NULL, string *out_time=NULL) {
     struct tm tm;
index 02217609d28f3f3c56564edbd75ff6a3217da369..7cdf11612acbf01b0c92fbacf78cd71abdfc9c07 100644 (file)
@@ -48,16 +48,6 @@ struct Entry {
   std::string get_str() const {
     return m_streambuf.get_str();
   }
-
-  // returns current size of content
-  size_t size() const {
-    return m_streambuf.size();
-  }
-
-  // extracts up to avail chars of content
-  int snprintf(char* dst, size_t avail) const {
-    return m_streambuf.snprintf(dst, avail);
-  }
 };
 
 }
index e4ce80a09b7d213863b98a96feb2e8919f08555d..3dc6c631061a5385d7b85f5dc1b46f01b0e30da4 100644 (file)
@@ -209,6 +209,7 @@ void Log::flush()
 void Log::_flush(EntryQueue *t, EntryQueue *requeue, bool crash)
 {
   Entry *e;
+  char buf[80];
   while ((e = t->dequeue()) != NULL) {
     unsigned sub = e->m_subsys;
 
@@ -218,8 +219,7 @@ void Log::_flush(EntryQueue *t, EntryQueue *requeue, bool crash)
     bool do_stderr = m_stderr_crash >= e->m_prio && should_log;
 
     if (do_fd || do_syslog || do_stderr) {
-      size_t buflen = 0;
-      char buf[80 + e->size()];
+      int buflen = 0;
 
       if (crash)
        buflen += snprintf(buf, sizeof(buf), "%6d> ", -t->m_len);
@@ -227,23 +227,25 @@ void Log::_flush(EntryQueue *t, EntryQueue *requeue, bool crash)
       buflen += snprintf(buf + buflen, sizeof(buf)-buflen, " %lx %2d ",
                        (unsigned long)e->m_thread, e->m_prio);
 
-      buflen += e->snprintf(buf + buflen, sizeof(buf) - buflen - 1 );
-      if(buflen > sizeof(buf) - 1 ) //paranoid check, buf was declared to hold everything
-        buflen = sizeof(buf) - 1;
+      // FIXME: this is slow
+      string s = e->get_str();
+
+      if (do_fd) {
+       int r = safe_write(m_fd, buf, buflen);
+       if (r >= 0)
+         r = safe_write(m_fd, s.data(), s.size());
+       if (r >= 0)
+         r = write(m_fd, "\n", 1);
+       if (r < 0)
+         cerr << "problem writing to " << m_log_file << ": " << cpp_strerror(r) << std::endl;
+      }
 
       if (do_syslog) {
-        syslog(LOG_USER, "%s", buf);
+       syslog(LOG_USER, "%s%s", buf, s.c_str());
       }
 
       if (do_stderr) {
-        cerr << buf << std::endl;
-      }
-      if (do_fd) {
-        buf[buflen-1]='\n';
-        buf[buflen]='\0';
-        int r=safe_write(m_fd, buf, buflen+1);
-        if (r < 0)
-          cerr << "problem writing to " << m_log_file << ": " << cpp_strerror(r) << std::endl;
+       cerr << buf << s << std::endl;
       }
     }