Move to android_mallopt for malloc debug calls.
Bug: 130028357
Test: Enable backtrace for mediaserver, run dumpsys media.player -m
Change-Id: I75adddfc5048f732ee7ec27c17192efd5857af38
Merged-In: I75adddfc5048f732ee7ec27c17192efd5857af38
(cherry picked from commit bd0195ecacaa5381278d8f96b51af36631dc0cd9)
diff --git a/media/utils/MemoryLeakTrackUtil.cpp b/media/utils/MemoryLeakTrackUtil.cpp
index 18f5f25..2988b52 100644
--- a/media/utils/MemoryLeakTrackUtil.cpp
+++ b/media/utils/MemoryLeakTrackUtil.cpp
@@ -22,6 +22,8 @@
#include "media/MemoryLeakTrackUtil.h"
#include <sstream>
+#include <bionic_malloc.h>
+
/*
* The code here originally resided in MediaPlayerService.cpp
*/
@@ -47,29 +49,22 @@
namespace android {
-extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize,
- size_t* infoSize, size_t* totalMemory, size_t* backtraceSize);
-
-extern "C" void free_malloc_leak_info(uint8_t* info);
-
std::string dumpMemoryAddresses(size_t limit)
{
- uint8_t *info;
- size_t overallSize;
- size_t infoSize;
- size_t totalMemory;
- size_t backtraceSize;
- get_malloc_leak_info(&info, &overallSize, &infoSize, &totalMemory, &backtraceSize);
+ android_mallopt_leak_info_t leak_info;
+ if (!android_mallopt(M_GET_MALLOC_LEAK_INFO, &leak_info, sizeof(leak_info))) {
+ return "";
+ }
size_t count;
- if (info == nullptr || overallSize == 0 || infoSize == 0
- || (count = overallSize / infoSize) == 0) {
+ if (leak_info.buffer == nullptr || leak_info.overall_size == 0 || leak_info.info_size == 0
+ || (count = leak_info.overall_size / leak_info.info_size) == 0) {
ALOGD("no malloc info, libc.debug.malloc.program property should be set");
- return std::string();
+ return "";
}
std::ostringstream oss;
- oss << totalMemory << " bytes in " << count << " allocations\n";
+ oss << leak_info.total_memory << " bytes in " << count << " allocations\n";
oss << " ABI: '" ABI_STRING "'" << "\n\n";
if (count > limit) count = limit;
@@ -83,14 +78,14 @@
uintptr_t backtrace[];
};
- const AllocEntry * const e = (AllocEntry *)(info + i * infoSize);
+ const AllocEntry * const e = (AllocEntry *)(leak_info.buffer + i * leak_info.info_size);
oss << (e->size * e->allocations)
<< " bytes ( " << e->size << " bytes * " << e->allocations << " allocations )\n";
- oss << backtrace_string(e->backtrace, backtraceSize) << "\n";
+ oss << backtrace_string(e->backtrace, leak_info.backtrace_size) << "\n";
}
oss << "\n";
- free_malloc_leak_info(info);
+ android_mallopt(M_FREE_MALLOC_LEAK_INFO, &leak_info, sizeof(leak_info));
return oss.str();
}