summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-09-27 15:29:06 -0700
committerSage Weil <sage@inktank.com>2013-10-16 09:28:13 -0700
commit6464516d9c852a1079f8bfc6d96a69b7c6c94aaa (patch)
tree51fc6e23c4793640fb0bd62705d663d78b969b62
parent0c23a5624a80903fba7e635e8c44f38a79caf223 (diff)
downloadceph-6464516d9c852a1079f8bfc6d96a69b7c6c94aaa.tar.gz
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 <sage@inktank.com>
-rw-r--r--src/common/buffer.cc23
-rw-r--r--src/include/buffer.h12
2 files changed, 33 insertions, 2 deletions
diff --git a/src/common/buffer.cc b/src/common/buffer.cc
index 09dac01db17..3a8190f0280 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 ffa3d6e1b97..0b497a7cf38 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. */