]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: enable tracking of calls to c_str()
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 18 Oct 2013 15:23:40 +0000 (08:23 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Sat, 23 Nov 2013 00:14:03 +0000 (16:14 -0800)
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 <josh.durgin@inktank.com>
src/common/buffer.cc
src/include/buffer.h

index 66a43913cc4b49c320256f2268e70079371f947d..229625910192f29cf131921afcbf349b0edb3746 100644 (file)
@@ -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;
   }
 
index 6eefd3494cfc7724262151b21491131f7759d242..8bd7603c4639fc32be4d41029499f2bece1b0c59 100644 (file)
@@ -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: