Skip to content

Commit

Permalink
buffer: enable tracking of calls to c_str()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jdurgin committed Nov 23, 2013
1 parent 445fb18 commit 75d4a72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 75d4a72

Please sign in to comment.