From: Josh Durgin Date: Fri, 18 Oct 2013 15:23:40 +0000 (-0700) Subject: buffer: enable tracking of calls to c_str() X-Git-Tag: v0.74~65^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=75d4a72086bcfcab5c0d6834e72cbc6e473c801e;p=ceph.git buffer: enable tracking of calls to c_str() Track buffer::ptr::c_str() to catch internal calls that use it, like buffer::ptr::cmp(). buffer::list::c_str() will be captured by this as well, since it will do a final buffer::ptr::c_str() and possibly several more if it needs to rebuild into a single raw buffer. Signed-off-by: Josh Durgin --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 66a43913cc4b4..229625910192f 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -70,6 +70,16 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE return buffer_cached_crc_adjusted.read(); } + atomic_t buffer_c_str_accesses; + bool buffer_track_c_str = get_env_bool("CEPH_BUFFER_TRACK"); + + void buffer::track_c_str(bool b) { + buffer_track_c_str = b; + } + int buffer::get_c_str_accesses() { + return buffer_c_str_accesses.read(); + } + atomic_t buffer_max_pipe_size; int update_max_pipe_size() { #ifdef CEPH_HAVE_SETPIPE_SZ @@ -613,10 +623,14 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE const char *buffer::ptr::c_str() const { assert(_raw); + if (buffer_track_c_str) + buffer_c_str_accesses.inc(); return _raw->get_data() + _off; } char *buffer::ptr::c_str() { assert(_raw); + if (buffer_track_c_str) + buffer_c_str_accesses.inc(); return _raw->get_data() + _off; } diff --git a/src/include/buffer.h b/src/include/buffer.h index 6eefd3494cfc7..8bd7603c4639f 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -120,6 +120,10 @@ public: /// enable/disable tracking of cached crcs static void track_cached_crc(bool b); + /// count of calls to buffer::ptr::c_str() + static int get_c_str_accesses(); + /// enable/disable tracking of buffer::ptr::c_str() calls + static void track_c_str(bool b); private: