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 @@ class buffer { /// 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: