summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rsContext.cpp1
-rw-r--r--rsContext.h1
-rw-r--r--rsDebugHelper.h26
-rw-r--r--rsObjectBase.cpp68
-rw-r--r--rsObjectBase.h9
5 files changed, 62 insertions, 43 deletions
diff --git a/rsContext.cpp b/rsContext.cpp
index f8088b0a..0bf9d9df 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -253,7 +253,6 @@ void * Context::threadProc(void *vrsc) {
rsc->props.mLogTimes = getProp("debug.rs.profile") != 0;
rsc->props.mLogScripts = getProp("debug.rs.script") != 0;
- rsc->props.mLogObjects = getProp("debug.rs.object") != 0;
rsc->props.mLogShaders = getProp("debug.rs.shader") != 0;
rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes") != 0;
rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms") != 0;
diff --git a/rsContext.h b/rsContext.h
index dac276f4..5965caeb 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -216,7 +216,6 @@ public:
struct {
bool mLogTimes;
bool mLogScripts;
- bool mLogObjects;
bool mLogShaders;
bool mLogShadersAttr;
bool mLogShadersUniforms;
diff --git a/rsDebugHelper.h b/rsDebugHelper.h
index a70fe4d1..f81e2586 100644
--- a/rsDebugHelper.h
+++ b/rsDebugHelper.h
@@ -20,42 +20,36 @@
#include "rsUtils.h"
#include "rsInternalDefines.h"
-#ifndef RS_SERVER
-// This shouldn't ever be defined with RS_SERVER
-#define RS_OBJECT_DEBUG 0
-#endif
-
-#if RS_OBJECT_DEBUG
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
#include <utils/CallStack.h>
#endif
namespace android {
namespace renderscript {
-#if RS_OBJECT_DEBUG
class DebugHelper {
public:
DebugHelper() {
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
mStack.update(2);
+#endif
}
void dump() {
- mStack.dump();
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
+ String8 s = mStack.toString();
+ ALOGV("%s", s.string());
+ //mStack.dump();
+#endif
}
private:
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
CallStack mStack;
+#endif
};
-#else
-
-class DebugHelper {
-public:
- DebugHelper() { }
-};
-
-#endif
} // namespace renderscript
} // namespace android
diff --git a/rsObjectBase.cpp b/rsObjectBase.cpp
index dc94bcc4..4992633c 100644
--- a/rsObjectBase.cpp
+++ b/rsObjectBase.cpp
@@ -16,6 +16,7 @@
#include "rsObjectBase.h"
#include "rsContext.h"
+#include "rsDebugHelper.h"
using namespace android;
using namespace android::renderscript;
@@ -31,22 +32,30 @@ ObjectBase::ObjectBase(Context *rsc) {
mDH = nullptr;
mName = nullptr;
-#if RS_OBJECT_DEBUG
- mDH = new DebugHelper();
-#endif
+ if (gDebugStacks || gDebugReferences || gDebugLeaks) {
+ mDH = new DebugHelper();
+ }
rsAssert(rsc);
add();
- //ALOGV("ObjectBase %p con", this);
+
+ if (gDebugLifetime || gDebugReferences) {
+ ALOGV("ObjectBase constructed %p", this);
+ }
}
ObjectBase::~ObjectBase() {
- //ALOGE("~ObjectBase %p ref %i,%i", this, mUserRefCount, mSysRefCount);
-#if RS_OBJECT_DEBUG
- mDH->dump();
- delete mDH;
- mDH = nullptr;
-#endif
+ if (gDebugLifetime || gDebugReferences) {
+ ALOGV("ObjectBase destroyed %p refs %i %i", this, mUserRefCount, mSysRefCount);
+ }
+
+ if (gDebugStacks || gDebugReferences || gDebugLeaks) {
+ if (gDebugStacks || gDebugReferences) {
+ mDH->dump();
+ }
+ delete mDH;
+ mDH = nullptr;
+ }
free(const_cast<char *>(mName));
@@ -76,12 +85,16 @@ void ObjectBase::dumpLOGV(const char *op) const {
void ObjectBase::incUserRef() const {
__sync_fetch_and_add(&mUserRefCount, 1);
- //ALOGV("ObjectBase %p incU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (gDebugReferences) {
+ ALOGV("ObjectBase %p incU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ }
}
void ObjectBase::incSysRef() const {
__sync_fetch_and_add(&mSysRefCount, 1);
- //ALOGV("ObjectBase %p incS ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (gDebugReferences) {
+ ALOGV("ObjectBase %p incS ref %i, %i", this, mUserRefCount, mSysRefCount);
+ }
}
void ObjectBase::preDestroy() const {
@@ -116,12 +129,12 @@ bool ObjectBase::checkDelete(const ObjectBase *ref) {
bool ObjectBase::decUserRef() const {
rsAssert(mUserRefCount > 0);
-#if RS_OBJECT_DEBUG
- //ALOGV("ObjectBase %p decU ref %i, %i", this, mUserRefCount, mSysRefCount);
- if (mUserRefCount <= 0) {
- mDH->dump();
+ if (gDebugReferences) {
+ ALOGV("ObjectBase %p decU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (mUserRefCount <= 0) {
+ mDH->dump();
+ }
}
-#endif
if ((__sync_fetch_and_sub(&mUserRefCount, 1) <= 1)) {
@@ -134,7 +147,10 @@ bool ObjectBase::decUserRef() const {
}
bool ObjectBase::zeroUserRef() const {
- //ALOGV("ObjectBase %p zeroU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (gDebugReferences) {
+ ALOGV("ObjectBase %p zeroU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ }
+
__sync_and_and_fetch(&mUserRefCount, 0);
if (mSysRefCount <= 0) {
return checkDelete(this);
@@ -143,7 +159,10 @@ bool ObjectBase::zeroUserRef() const {
}
bool ObjectBase::decSysRef() const {
- //ALOGV("ObjectBase %p decS ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (gDebugReferences) {
+ ALOGV("ObjectBase %p decS ref %i, %i", this, mUserRefCount, mSysRefCount);
+ }
+
rsAssert(mSysRefCount > 0);
if ((__sync_fetch_and_sub(&mSysRefCount, 1) <= 1)) {
__sync_synchronize();
@@ -208,7 +227,7 @@ void ObjectBase::remove() const {
}
void ObjectBase::zeroAllUserRef(Context *rsc) {
- if (rsc->props.mLogObjects) {
+ if (gDebugReferences || gDebugLeaks) {
ALOGV("Forcing release of all outstanding user refs.");
}
@@ -226,14 +245,14 @@ void ObjectBase::zeroAllUserRef(Context *rsc) {
}
}
- if (rsc->props.mLogObjects) {
+ if (gDebugReferences || gDebugLeaks) {
ALOGV("Objects remaining.");
dumpAll(rsc);
}
}
void ObjectBase::freeAllChildren(Context *rsc) {
- if (rsc->props.mLogObjects) {
+ if (gDebugReferences) {
ALOGV("Forcing release of all child objects.");
}
@@ -248,7 +267,7 @@ void ObjectBase::freeAllChildren(Context *rsc) {
}
}
- if (rsc->props.mLogObjects) {
+ if (gDebugReferences) {
ALOGV("Objects remaining.");
dumpAll(rsc);
}
@@ -262,6 +281,9 @@ void ObjectBase::dumpAll(Context *rsc) {
while (o) {
ALOGV(" Object %p", o);
o->dumpLOGV(" ");
+ if (o->mDH != nullptr) {
+ o->mDH->dump();
+ }
o = o->mNext;
}
diff --git a/rsObjectBase.h b/rsObjectBase.h
index cd1b16e1..c51d85cb 100644
--- a/rsObjectBase.h
+++ b/rsObjectBase.h
@@ -19,7 +19,7 @@
#include "rsUtils.h"
#include "rsDefines.h"
-#include "rsDebugHelper.h"
+#include "rsInternalDefines.h"
namespace android {
namespace renderscript {
@@ -30,6 +30,11 @@ class OStream;
// An element is a group of Components that occupies one cell in a structure.
class ObjectBase {
public:
+ static const bool gDebugStacks = false;
+ static const bool gDebugReferences = false;
+ static const bool gDebugLeaks = false;
+ static const bool gDebugLifetime = false;
+
ObjectBase(Context *rsc);
void incSysRef() const;
@@ -89,7 +94,7 @@ private:
mutable const ObjectBase * mPrev;
mutable const ObjectBase * mNext;
- DebugHelper *mDH;
+ class DebugHelper *mDH;
};
template<class T>