From cab25d680e644d962041d05a319e485b96136a5d Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 21 Mar 2013 17:12:40 -0700 Subject: [PATCH] improved CallStack a bit - added a ctor that updates and dumps the stack immediately - added a "logtag" parameter to dump() Change-Id: Ie51c256071d282591752243bdb4f68cf9ff8829d --- include/utils/CallStack.h | 6 ++++-- libs/binder/IMemory.cpp | 4 +--- libs/ui/Region.cpp | 4 +--- libs/utils/CallStack.cpp | 11 +++++++++-- libs/utils/RefBase.cpp | 12 ++++-------- opengl/libs/EGL/egl.cpp | 4 +--- opengl/libs/EGL/egl_tls.cpp | 4 +--- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/utils/CallStack.h b/include/utils/CallStack.h index 079e20c69..61dc832ea 100644 --- a/include/utils/CallStack.h +++ b/include/utils/CallStack.h @@ -35,6 +35,8 @@ public: }; CallStack(); + CallStack(const char* logtag, int32_t ignoreDepth=1, + int32_t maxDepth=MAX_DEPTH); CallStack(const CallStack& rhs); ~CallStack(); @@ -53,8 +55,8 @@ public: void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH); - // Dump a stack trace to the log - void dump(const char* prefix = 0) const; + // Dump a stack trace to the log using the supplied logtag + void dump(const char* logtag, const char* prefix = 0) const; // Return a string (possibly very long) containing the complete stack trace String8 toString(const char* prefix = 0) const; diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp index cd2451a67..07cb41a75 100644 --- a/libs/binder/IMemory.cpp +++ b/libs/binder/IMemory.cpp @@ -246,9 +246,7 @@ BpMemoryHeap::~BpMemoryHeap() { if (VERBOSE) { ALOGD("UNMAPPING binder=%p, heap=%p, size=%d, fd=%d", binder.get(), this, mSize, mHeapId); - CallStack stack; - stack.update(); - stack.dump("callstack"); + CallStack stack(LOG_TAG); } munmap(mBase, mSize); diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 1a613f800..488fba32c 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -530,9 +530,7 @@ bool Region::validate(const Region& reg, const char* name, bool silent) } if (result == false && !silent) { reg.dump(name); - CallStack stack; - stack.update(); - stack.dump(""); + CallStack stack(LOG_TAG); } return result; } diff --git a/libs/utils/CallStack.cpp b/libs/utils/CallStack.cpp index 66fabebc4..e60f5d8e7 100644 --- a/libs/utils/CallStack.cpp +++ b/libs/utils/CallStack.cpp @@ -30,6 +30,11 @@ CallStack::CallStack() : mCount(0) { } +CallStack::CallStack(const char* logtag, int32_t ignoreDepth, int32_t maxDepth) { + this->update(ignoreDepth+1, maxDepth); + this->dump(logtag); +} + CallStack::CallStack(const CallStack& rhs) : mCount(rhs.mCount) { if (mCount) { @@ -96,7 +101,7 @@ void CallStack::update(int32_t ignoreDepth, int32_t maxDepth) { mCount = count > 0 ? count : 0; } -void CallStack::dump(const char* prefix) const { +void CallStack::dump(const char* logtag, const char* prefix) const { backtrace_symbol_t symbols[mCount]; get_backtrace_symbols(mStack, mCount, symbols); @@ -104,7 +109,9 @@ void CallStack::dump(const char* prefix) const { char line[MAX_BACKTRACE_LINE_LENGTH]; format_backtrace_line(i, &mStack[i], &symbols[i], line, MAX_BACKTRACE_LINE_LENGTH); - ALOGD("%s%s", prefix, line); + ALOG(LOG_DEBUG, logtag, "%s%s", + prefix ? prefix : "", + line); } free_backtrace_symbols(symbols, mCount); } diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp index 3d3a59595..e538f6868 100644 --- a/libs/utils/RefBase.cpp +++ b/libs/utils/RefBase.cpp @@ -110,7 +110,7 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - refs->stack.dump(); + refs->stack.dump(LOG_TAG); #endif refs = refs->next; } @@ -124,16 +124,14 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - refs->stack.dump(); + refs->stack.dump(LOG_TAG); #endif refs = refs->next; } } if (dumpStack) { ALOGE("above errors at:"); - CallStack stack; - stack.update(); - stack.dump(); + CallStack stack(LOG_TAG); } } @@ -269,9 +267,7 @@ private: ref = ref->next; } - CallStack stack; - stack.update(); - stack.dump(); + CallStack stack(LOG_TAG); } } diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index a8691b5c9..a6e91e0ea 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -222,9 +222,7 @@ static int gl_no_context() { char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.callstack", value, "0"); if (atoi(value)) { - CallStack stack; - stack.update(); - stack.dump(); + CallStack stack(LOG_TAG); } } return 0; diff --git a/opengl/libs/EGL/egl_tls.cpp b/opengl/libs/EGL/egl_tls.cpp index 41cfae1b6..52312a2b7 100644 --- a/opengl/libs/EGL/egl_tls.cpp +++ b/opengl/libs/EGL/egl_tls.cpp @@ -78,9 +78,7 @@ void egl_tls_t::setErrorEtcImpl( char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.callstack", value, "0"); if (atoi(value)) { - CallStack stack; - stack.update(); - stack.dump(); + CallStack stack(LOG_TAG); } } tls->error = error;