Add support for signal dumping log stats.
Adding the new option log_allocator_stats_on_signal that will call
mallopt(M_LOG_STATS, 0), when a signal is sent to a process.
This call does not happen in the signal handler, but a variable
is set to trigger the mallopt call. The next time any allocation
call occurs, the mallopt call will be made.
Also, includes new unit tests for the new config option.
Test: All unit tests pass.
Test: Enabling the new feature and stop/start and sending the signal to
Test: a process and observing the log contains the memory stats.
Test: Did the above for a scudo and jemalloc based device.
Change-Id: Idcf6fca74036efb065b9c4cc037aaf9bcf0f139e
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index b06ec9e..3731a5d 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -53,6 +53,7 @@
#include "Config.h"
#include "DebugData.h"
+#include "LogAllocatorStats.h"
#include "Unreachable.h"
#include "UnwindBacktrace.h"
#include "backtrace.h"
@@ -517,11 +518,15 @@
}
static TimedResult InternalMalloc(size_t size) {
- if ((g_debug->config().options() & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) {
+ uint64_t options = g_debug->config().options();
+ if ((options & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) {
debug_dump_heap(android::base::StringPrintf(
"%s.%d.txt", g_debug->config().backtrace_dump_prefix().c_str(), getpid())
.c_str());
}
+ if (options & LOG_ALLOCATOR_STATS_ON_SIGNAL) {
+ LogAllocatorStats::CheckIfShouldLog();
+ }
if (size == 0) {
size = 1;
@@ -593,11 +598,15 @@
}
static TimedResult InternalFree(void* pointer) {
- if ((g_debug->config().options() & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) {
+ uint64_t options = g_debug->config().options();
+ if ((options & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) {
debug_dump_heap(android::base::StringPrintf(
"%s.%d.txt", g_debug->config().backtrace_dump_prefix().c_str(), getpid())
.c_str());
}
+ if (options & LOG_ALLOCATOR_STATS_ON_SIGNAL) {
+ LogAllocatorStats::CheckIfShouldLog();
+ }
void* free_pointer = pointer;
size_t bytes;