diff options
author | Mathias Agopian <mathias@google.com> | 2009-04-10 20:34:46 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2009-04-10 20:34:46 -0700 |
commit | af9a515299b24031c7aa77bf163d0985cc862069 (patch) | |
tree | ce96435679723e8e6592a7283c3841ec8daf5097 /libs/ui | |
parent | 7e25da07af7f4f8a876ac97be6e4745877aecb08 (diff) | |
download | frameworks_base-af9a515299b24031c7aa77bf163d0985cc862069.zip frameworks_base-af9a515299b24031c7aa77bf163d0985cc862069.tar.gz frameworks_base-af9a515299b24031c7aa77bf163d0985cc862069.tar.bz2 |
more debugging tools around BufferMapper
Diffstat (limited to 'libs/ui')
-rw-r--r-- | libs/ui/BufferMapper.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/libs/ui/BufferMapper.cpp b/libs/ui/BufferMapper.cpp index a97188e..c7e439c 100644 --- a/libs/ui/BufferMapper.cpp +++ b/libs/ui/BufferMapper.cpp @@ -34,6 +34,13 @@ #include <hardware/gralloc.h> +// --------------------------------------------------------------------------- +// enable mapping debugging +#define DEBUG_MAPPINGS 1 +// never remove mappings from the list +#define DEBUG_MAPPINGS_KEEP_ALL 1 +// --------------------------------------------------------------------------- + namespace android { // --------------------------------------------------------------------------- @@ -53,6 +60,10 @@ status_t BufferMapper::map(buffer_handle_t handle, void** addr) Mutex::Autolock _l(mLock); status_t err = mAllocMod->map(mAllocMod, handle, addr); LOGW_IF(err, "map(...) failed %d (%s)", err, strerror(-err)); +#if DEBUG_MAPPINGS + if (err == NO_ERROR) + logMapLocked(handle); +#endif return err; } @@ -61,6 +72,10 @@ status_t BufferMapper::unmap(buffer_handle_t handle) Mutex::Autolock _l(mLock); status_t err = mAllocMod->unmap(mAllocMod, handle); LOGW_IF(err, "unmap(...) failed %d (%s)", err, strerror(-err)); +#if DEBUG_MAPPINGS + if (err == NO_ERROR) + logUnmapLocked(handle); +#endif return err; } @@ -79,5 +94,68 @@ status_t BufferMapper::unlock(buffer_handle_t handle) return err; } +void BufferMapper::logMapLocked(buffer_handle_t handle) +{ + CallStack stack; + stack.update(2); + + map_info_t info; + ssize_t index = mMapInfo.indexOfKey(handle); + if (index >= 0) { + info = mMapInfo.valueAt(index); + } + + ssize_t stackIndex = info.callstacks.indexOfKey(stack); + if (stackIndex >= 0) { + info.callstacks.editValueAt(stackIndex) += 1; + } else { + info.callstacks.add(stack, 1); + } + + if (index < 0) { + info.count = 1; + mMapInfo.add(handle, info); + } else { + info.count++; + mMapInfo.replaceValueAt(index, info); + } +} + +void BufferMapper::logUnmapLocked(buffer_handle_t handle) +{ + ssize_t index = mMapInfo.indexOfKey(handle); + if (index < 0) { + LOGE("unmapping %p which doesn't exist!", handle); + return; + } + + map_info_t& info = mMapInfo.editValueAt(index); + info.count--; + if (info.count == 0) { +#if DEBUG_MAPPINGS_KEEP_ALL + info.callstacks.clear(); +#else + mMapInfo.removeItemsAt(index, 1); +#endif + } +} + +void BufferMapper::dump(buffer_handle_t handle) +{ + Mutex::Autolock _l(mLock); + ssize_t index = mMapInfo.indexOfKey(handle); + if (index < 0) { + LOGD("handle %p is not mapped through BufferMapper", handle); + return; + } + + const map_info_t& info = mMapInfo.valueAt(index); + LOGD("dumping buffer_handle_t %p mappings (count=%d)", handle, info.count); + for (size_t i=0 ; i<info.callstacks.size() ; i++) { + LOGD("#%d, count=%d", i, info.callstacks.valueAt(i)); + info.callstacks.keyAt(i).dump(); + } +} + // --------------------------------------------------------------------------- }; // namespace android |