]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: perf counter for bufferlist history total alloc
authorXinze Chi <xinze@xsky.com>
Thu, 8 Oct 2015 01:51:39 +0000 (09:51 +0800)
committerXinze Chi <xinze@xsky.com>
Thu, 8 Oct 2015 02:51:14 +0000 (10:51 +0800)
this is useful for tracking how many bytes malloc at bufferlist

Signed-off-by: Xinze Chi <xinze@xsky.com>
src/common/buffer.cc
src/include/buffer.h
src/osd/OSD.cc
src/osd/OSD.h

index a7ed8883f0e58c6bd1243d009ed12e0da1b55f0b..f7b328c50466d9dc9d6920142c22c9832567bdb2 100644 (file)
@@ -48,6 +48,8 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
 #endif
 
   static atomic_t buffer_total_alloc;
+  static atomic64_t buffer_history_alloc_bytes;
+  static atomic64_t buffer_history_alloc_num;
   const bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
 
   void buffer::inc_total_alloc(unsigned len) {
@@ -58,9 +60,21 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     if (buffer_track_alloc)
       buffer_total_alloc.sub(len);
   }
+  void buffer::inc_history_alloc(uint64_t len) {
+    if (buffer_track_alloc) {
+      buffer_history_alloc_bytes.add(len);
+      buffer_history_alloc_num.inc();
+    }
+  }
   int buffer::get_total_alloc() {
     return buffer_total_alloc.read();
   }
+  uint64_t buffer::get_history_alloc_bytes() {
+    return buffer_history_alloc_bytes.read();
+  }
+  uint64_t buffer::get_history_alloc_num() {
+    return buffer_history_alloc_num.read();
+  }
 
   static atomic_t buffer_cached_crc;
   static atomic_t buffer_cached_crc_adjusted;
@@ -227,6 +241,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
        data = 0;
       }
       inc_total_alloc(len);
+      inc_history_alloc(len);
       bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
     }
     raw_malloc(unsigned l, char *b) : raw(b, l) {
@@ -251,6 +266,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       if (!data)
        throw bad_alloc();
       inc_total_alloc(len);
+      inc_history_alloc(len);
       bdout << "raw_mmap " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
     }
     ~raw_mmap_pages() {
@@ -280,6 +296,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       if (!data)
        throw bad_alloc();
       inc_total_alloc(len);
+      inc_history_alloc(len);
       bdout << "raw_posix_aligned " << this << " alloc " << (void *)data << " l=" << l << ", align=" << align << " total_alloc=" << buffer::get_total_alloc() << bendl;
     }
     ~raw_posix_aligned() {
@@ -307,6 +324,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       else
        data = realdata;
       inc_total_alloc(len+align-1);
+      inc_history_alloc(len+align-1);
       //cout << "hack aligned " << (unsigned)data
       //<< " in raw " << (unsigned)realdata
       //<< " off " << off << std::endl;
@@ -356,6 +374,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       }
 
       inc_total_alloc(len);
+      inc_history_alloc(len);
       bdout << "raw_pipe " << this << " alloc " << len << " "
            << buffer::get_total_alloc() << bendl;
     }
@@ -510,6 +529,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       else
        data = 0;
       inc_total_alloc(len);
+      inc_history_alloc(len);
       bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
     }
     raw_char(unsigned l, char *b) : raw(b, l) {
index 854a286358128ae29e6804dc4cf01795e554d0ba..7170def20f1a539dafdb2fbd6a170e413f839365 100644 (file)
@@ -101,6 +101,12 @@ public:
   /// total bytes allocated
   static int get_total_alloc();
 
+  /// history total bytes allocated
+  static uint64_t get_history_alloc_bytes();
+
+  /// total num allocated
+  static uint64_t get_history_alloc_num();
+
   /// enable/disable alloc tracking
   static void track_alloc(bool b);
 
@@ -120,6 +126,7 @@ private:
  
   /* hack for memory utilization debugging. */
   static void inc_total_alloc(unsigned len);
+  static void inc_history_alloc(uint64_t len);
   static void dec_total_alloc(unsigned len);
 
   /*
index 09e4c570d15a7d13ecc8f755b040b2361a1c7c32..0dd6d7079af64c9bd908ee3beb2334e208ac822e 100644 (file)
@@ -2175,6 +2175,8 @@ void OSD::create_logger()
 
   osd_plb.add_u64(l_osd_loadavg, "loadavg", "CPU load");
   osd_plb.add_u64(l_osd_buf, "buffer_bytes", "Total allocated buffer size");       // total ceph::buffer bytes
+  osd_plb.add_u64(l_osd_history_alloc_bytes, "history_alloc_Mbytes");       // total ceph::buffer bytes in history
+  osd_plb.add_u64(l_osd_history_alloc_num, "history_alloc_num");       // total ceph::buffer num in history
 
   osd_plb.add_u64(l_osd_pg, "numpg", "Placement groups");   // num pgs
   osd_plb.add_u64(l_osd_pg_primary, "numpg_primary", "Placement groups for which this osd is primary"); // num primary pgs
@@ -3966,6 +3968,8 @@ void OSD::tick()
   dout(5) << "tick" << dendl;
 
   logger->set(l_osd_buf, buffer::get_total_alloc());
+  logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20));
+  logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num());
 
   if (is_active() || is_waiting_for_healthy()) {
     map_lock.get_read();
@@ -5886,6 +5890,8 @@ void OSD::_dispatch(Message *m)
   dout(20) << "_dispatch " << m << " " << *m << dendl;
 
   logger->set(l_osd_buf, buffer::get_total_alloc());
+  logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20));
+  logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num());
 
   switch (m->get_type()) {
 
@@ -5938,6 +5944,8 @@ void OSD::_dispatch(Message *m)
   }
 
   logger->set(l_osd_buf, buffer::get_total_alloc());
+  logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20));
+  logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num());
 
 }
 
index 996e7777af2faaff8667ddcee2dbf348e1aa1e27..029203af2d63a8ec74926d7bda568c5e4f0ac71a 100644 (file)
@@ -105,6 +105,8 @@ enum {
 
   l_osd_loadavg,
   l_osd_buf,
+  l_osd_history_alloc_bytes,
+  l_osd_history_alloc_num,
 
   l_osd_pg,
   l_osd_pg_primary,