From b6f459abbc594e3b5821bd500a3dca33fe6af84c Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Thu, 26 Oct 2023 15:55:08 -0700 Subject: [PATCH] Allow disabling callstack Bug: 302723053 Test: mma Change-Id: Idea326cc9914d4c81d75dad287e169c09a736486 --- libutils/binder/RefBase.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libutils/binder/RefBase.cpp b/libutils/binder/RefBase.cpp index 4b0cc161b..2d2e40b7e 100644 --- a/libutils/binder/RefBase.cpp +++ b/libutils/binder/RefBase.cpp @@ -55,14 +55,16 @@ // log all reference counting operations #define PRINT_REFS 0 +#if !defined(ANDROID_UTILS_CALLSTACK_ENABLED) #if defined(__linux__) // CallStack is only supported on linux type platforms. -#define CALLSTACK_ENABLED 1 +#define ANDROID_UTILS_CALLSTACK_ENABLED 1 #else -#define CALLSTACK_ENABLED 0 -#endif +#define ANDROID_UTILS_CALLSTACK_ENABLED 0 +#endif // defined(__linux__) +#endif // !defined(ANDROID_UTILS_CALLSTACK_ENABLED) -#if CALLSTACK_ENABLED +#if ANDROID_UTILS_CALLSTACK_ENABLED #include "../../include/utils/CallStack.h" #endif @@ -230,7 +232,7 @@ public: while (refs) { char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); -#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED +#if DEBUG_REFS_CALLSTACK_ENABLED && ANDROID_UTILS_CALLSTACK_ENABLED CallStack::logStack(LOG_TAG, refs->stack.get()); #endif refs = refs->next; @@ -244,7 +246,7 @@ public: while (refs) { char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); -#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED +#if DEBUG_REFS_CALLSTACK_ENABLED && ANDROID_UTILS_CALLSTACK_ENABLED CallStack::logStack(LOG_TAG, refs->stack.get()); #endif refs = refs->next; @@ -252,7 +254,7 @@ public: } if (dumpStack) { ALOGE("above errors at:"); -#if CALLSTACK_ENABLED +#if ANDROID_UTILS_CALLSTACK_ENABLED CallStack::logStack(LOG_TAG); #endif } @@ -341,7 +343,7 @@ private: { ref_entry* next; const void* id; -#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED +#if DEBUG_REFS_CALLSTACK_ENABLED && ANDROID_UTILS_CALLSTACK_ENABLED CallStack::CallStackUPtr stack; #endif int32_t ref; @@ -358,7 +360,7 @@ private: // decrement the reference count. ref->ref = mRef; ref->id = id; -#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED +#if DEBUG_REFS_CALLSTACK_ENABLED && ANDROID_UTILS_CALLSTACK_ENABLED ref->stack = CallStack::getCurrent(2); #endif ref->next = *refs; @@ -394,7 +396,7 @@ private: ref = ref->next; } -#if CALLSTACK_ENABLED +#if ANDROID_UTILS_CALLSTACK_ENABLED CallStack::logStack(LOG_TAG); #endif } @@ -422,7 +424,7 @@ private: snprintf(buf, sizeof(buf), "\t%c ID %p (ref %d):\n", inc, refs->id, refs->ref); out->append(buf); -#if DEBUG_REFS_CALLSTACK_ENABLED && CALLSTACK_ENABLED +#if DEBUG_REFS_CALLSTACK_ENABLED && ANDROID_UTILS_CALLSTACK_ENABLED out->append(CallStack::stackToString("\t\t", refs->stack.get())); #else out->append("\t\t(call stacks disabled)"); @@ -788,7 +790,7 @@ RefBase::~RefBase() "object.", mRefs->mWeak.load(), this); -#if CALLSTACK_ENABLED +#if ANDROID_UTILS_CALLSTACK_ENABLED CallStack::logStack(LOG_TAG); #endif } else if (strongs != 0) {