From 054741725f1272e035366d452027648966b7ae6d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 1 Jul 2014 15:43:47 -0700 Subject: [PATCH] common/RefCountedObject: optionally debug Introduce a 'refs' subsys for logging. Print log ref count inc and dec for any RefCountedObject that gets a cct passed to its ctor. Signed-off-by: Sage Weil --- src/common/RefCountedObj.h | 20 ++++++++++++++------ src/common/config_opts.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/RefCountedObj.h b/src/common/RefCountedObj.h index 042adb5878068..84bd22f57b02b 100644 --- a/src/common/RefCountedObj.h +++ b/src/common/RefCountedObj.h @@ -18,21 +18,29 @@ #include "common/Mutex.h" #include "common/Cond.h" #include "include/atomic.h" - +#include "common/ceph_context.h" struct RefCountedObject { atomic_t nref; - RefCountedObject() : nref(1) {} + CephContext *cct; + RefCountedObject(CephContext *c = NULL) : nref(1), cct(c) {} virtual ~RefCountedObject() {} RefCountedObject *get() { - //generic_dout(0) << "RefCountedObject::get " << this << " " << nref.read() << " -> " << (nref.read() + 1) << dendl; - nref.inc(); + int v = nref.inc(); + if (cct) + lsubdout(cct, refs, 1) << "RefCountedObject::get " << this << " " + << (v - 1) << " -> " << v + << dendl; return this; } void put() { - //generic_dout(0) << "RefCountedObject::put " << this << " " << nref.read() << " -> " << (nref.read() - 1) << dendl; - if (nref.dec() == 0) + int v = nref.dec(); + if (cct) + lsubdout(cct, refs, 1) << "RefCountedObject::put " << this << " " + << (v + 1) << " -> " << v + << dendl; + if (v == 0) delete this; } }; diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 1c9dbacc71d0b..1257ae47a4ade 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -95,6 +95,7 @@ SUBSYS(rgw, 1, 5) // log level for the Rados gateway SUBSYS(javaclient, 1, 5) SUBSYS(asok, 1, 5) SUBSYS(throttle, 1, 1) +SUBSYS(refs, 0, 0) OPTION(key, OPT_STR, "") OPTION(keyfile, OPT_STR, "") -- 2.39.5