]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: instrument utilization of cached crcs
authorSage Weil <sage@inktank.com>
Fri, 27 Sep 2013 22:29:06 +0000 (15:29 -0700)
committerSage Weil <sage@inktank.com>
Wed, 16 Oct 2013 16:28:13 +0000 (09:28 -0700)
This is similar to the alloc tracking, but I've added a method to let
you enable it easily (in this case, from the unit test).

Signed-off-by: Sage Weil <sage@inktank.com>
src/common/buffer.cc
src/include/buffer.h

index 09dac01db1757cdd403881ddc40d6302d00fc7ee..3a8190f0280beb23eaac9f26caadf0c22e7266a0 100644 (file)
@@ -43,8 +43,8 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
 # define bendl std::endl; }
 #endif
 
-atomic_t buffer_total_alloc;
-bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
+  atomic_t buffer_total_alloc;
+  bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
 
   void buffer::inc_total_alloc(unsigned len) {
     if (buffer_track_alloc)
@@ -58,6 +58,21 @@ bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
     return buffer_total_alloc.read();
   }
 
+  atomic_t buffer_cached_crc;
+  atomic_t buffer_cached_crc_adjusted;
+  bool buffer_track_crc = get_env_bool("CEPH_BUFFER_TRACK");
+
+  void buffer::track_cached_crc(bool b) {
+    buffer_track_crc = b;
+  }
+  int buffer::get_cached_crc() {
+    return buffer_cached_crc.read();
+  }
+  int buffer::get_cached_crc_adjusted() {
+    return buffer_cached_crc_adjusted.read();
+  }
+
+
   class buffer::raw {
   public:
     char *data;
@@ -1311,6 +1326,8 @@ __u32 buffer::list::crc32c(__u32 crc) const
        if (ccrc.first == crc) {
          // got it already
          crc = ccrc.second;
+         if (buffer_track_crc)
+           buffer_cached_crc.inc();
        } else {
          /* If we have cached crc32c(buf, v) for initial value v,
           * we can convert this to a different initial value v' by:
@@ -1328,6 +1345,8 @@ __u32 buffer::list::crc32c(__u32 crc) const
          if (remaining)
            adjustment = ceph_crc32c(adjustment, zbuf, remaining);
          crc = ccrc.second ^ adjustment;
+         if (buffer_track_crc)
+           buffer_cached_crc_adjusted.inc();
        }
       } else {
        uint32_t base = crc;
index ffa3d6e1b9772782722ffecfee796534267cd20f..0b497a7cf38d6344d9b1ce290ce4aed4abb21db6 100644 (file)
@@ -103,8 +103,20 @@ public:
   };
 
 
+  /// total bytes allocated
   static int get_total_alloc();
 
+  /// enable/disable alloc tracking
+  static void track_alloc(bool b);
+
+  /// count of cached crc hits (matching input)
+  static int get_cached_crc();
+  /// count of cached crc hits (mismatching input, required adjustment)
+  static int get_cached_crc_adjusted();
+  /// enable/disable tracking of cached crcs
+  static void track_cached_crc(bool b);
+
+
 private:
  
   /* hack for memory utilization debugging. */