diff options
author | Abhishek Arpure <abhishekarpure@codeaurora.org> | 2013-04-05 14:52:42 +0530 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2013-11-08 12:08:42 -0800 |
commit | 65c92b986513a18a157fe32e8725a80dd798211e (patch) | |
tree | c4fd2477ab45025fa1ff8f0a68603ab652ea5d60 | |
parent | 018cc711cc4bd90c9f14929984184fd9f32e5345 (diff) | |
download | android_dalvik-65c92b986513a18a157fe32e8725a80dd798211e.tar.gz android_dalvik-65c92b986513a18a157fe32e8725a80dd798211e.tar.bz2 android_dalvik-65c92b986513a18a157fe32e8725a80dd798211e.zip |
Dump hprof when app encounters Out of memory.
These changes will only dump application hprof when debug
property "dalvik.debug.oom" is set to 1.
Change-Id: Iea8cd545f5cb81f333b78578c6fc38c340bf0fd4
-rw-r--r-- | vm/alloc/Heap.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/vm/alloc/Heap.cpp b/vm/alloc/Heap.cpp index 5e5dd9a8a..3c8342af3 100644 --- a/vm/alloc/Heap.cpp +++ b/vm/alloc/Heap.cpp @@ -29,11 +29,15 @@ #include "alloc/HeapSource.h" #include "alloc/MarkSweep.h" #include "os/os.h" +#include "hprof/Hprof.h" #include <sys/time.h> #include <sys/resource.h> #include <limits.h> #include <errno.h> +#include <cutils/process_name.h> +#include <cutils/properties.h> + #include <cutils/trace.h> #include <cutils/properties.h> @@ -192,6 +196,9 @@ static void gcForMalloc(bool clearSoftReferences) static void *tryMalloc(size_t size) { void *ptr; + int result = -1; + char* hprof_file = NULL; + char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; //TODO: figure out better heuristics // There will be a lot of churn if someone allocates a bunch of @@ -268,6 +275,46 @@ static void *tryMalloc(size_t size) //TODO: tell the HeapSource to dump its state dvmDumpThread(dvmThreadSelf(), false); + /* Read the property to check whether hprof should be generated or not */ + property_get("dalvik.debug.oom",prop_value,"0"); + + if(atoi(prop_value) == 1) { + LOGE_HEAP("Generating hprof for process: %s PID: %d", + get_process_name(),getpid()); + dvmUnlockHeap(); + + /* allocate memory for hprof file name. Allocate approx 30 bytes. + * 11 byte for directory path, 10 bytes for pid, 6 bytes for + * extension + "\0'. + */ + hprof_file = (char*) malloc (sizeof(char) * 30); + + /* creation of hprof will fail if /data/misc permission is not set + * to 0777. + */ + + if(hprof_file) { + snprintf(hprof_file,30,"/data/misc/%d.hprof",getpid()); + LOGE_HEAP("Generating hprof in file: %s",hprof_file ); + + result = hprofDumpHeap(hprof_file, -1, false); + free(hprof_file); + } else { + LOGE_HEAP("Failed to allocate memory for file name." + "Generating hprof in default file: /data/misc/app_oom.hprof"); + result = hprofDumpHeap("/data/misc/app_oom.hprof", -1, false); + } + + dvmLockMutex(&gDvm.gcHeapLock); + + if (result != 0) { + /* ideally we'd throw something more specific based on actual failure */ + dvmThrowRuntimeException( + "Failure during heap dump; check log output for details"); + LOGE_HEAP(" hprofDumpHeap failed with result: %d ",result); + } + } + return NULL; } |