From: Sage Weil Date: Fri, 27 Sep 2013 22:29:06 +0000 (-0700) Subject: common/buffer: instrument utilization of cached crcs X-Git-Tag: v0.72-rc1~42^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6464516d9c852a1079f8bfc6d96a69b7c6c94aaa;p=ceph.git common/buffer: instrument utilization of cached crcs 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 --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 09dac01db175..3a8190f0280b 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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; diff --git a/src/include/buffer.h b/src/include/buffer.h index ffa3d6e1b977..0b497a7cf38d 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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. */