From: Sage Weil Date: Tue, 1 Jul 2014 22:43:47 +0000 (-0700) Subject: common/RefCountedObject: optionally debug X-Git-Tag: v0.84~148^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=054741725f1272e035366d452027648966b7ae6d;p=ceph.git 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 --- diff --git a/src/common/RefCountedObj.h b/src/common/RefCountedObj.h index 042adb58780..84bd22f57b0 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 1c9dbacc71d..1257ae47a4a 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, "")