summaryrefslogtreecommitdiffstats
path: root/core/jni/android_os_Debug.cpp
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-06-08 17:23:59 -0700
committerDianne Hackborn <hackbod@google.com>2012-06-08 18:36:48 -0700
commitf72467ad9843bf5d4b75fb308386e77ebb5c3447 (patch)
tree65fbe419f8942bdb0a9c3d991bd510aaff23351f /core/jni/android_os_Debug.cpp
parent2e6f9be5633cf37223425b9b93c0b1512db091af (diff)
downloadframeworks_base-f72467ad9843bf5d4b75fb308386e77ebb5c3447.zip
frameworks_base-f72467ad9843bf5d4b75fb308386e77ebb5c3447.tar.gz
frameworks_base-f72467ad9843bf5d4b75fb308386e77ebb5c3447.tar.bz2
Include important native processes in watchdog stacks.
Helps us track down deadlocks involving native service processes. Bug: 6615693 Change-Id: I580047550772e29586195a8cf440141574e3f40c
Diffstat (limited to 'core/jni/android_os_Debug.cpp')
-rw-r--r--core/jni/android_os_Debug.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index 9586717..6724f36 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -17,8 +17,11 @@
#define LOG_TAG "android.os.Debug"
#include "JNIHelp.h"
#include "jni.h"
+#include <utils/String8.h>
#include "utils/misc.h"
+#include "cutils/debugger.h"
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -538,6 +541,35 @@ static void android_os_Debug_dumpNativeHeap(JNIEnv* env, jobject clazz,
}
+static void android_os_Debug_dumpNativeBacktraceToFile(JNIEnv* env, jobject clazz,
+ jint pid, jstring fileName)
+{
+ if (fileName == NULL) {
+ jniThrowNullPointerException(env, NULL);
+ return;
+ }
+ const jchar* str = env->GetStringCritical(fileName, 0);
+ String8 fileName8;
+ if (str) {
+ fileName8 = String8(str, env->GetStringLength(fileName));
+ env->ReleaseStringCritical(fileName, str);
+ }
+
+ int fd = open(fileName8.string(), O_CREAT | O_WRONLY | O_NOFOLLOW, 0666); /* -rw-rw-rw- */
+ if (fd < 0) {
+ fprintf(stderr, "Can't open %s: %s\n", fileName8.string(), strerror(errno));
+ return;
+ }
+
+ if (lseek(fd, 0, SEEK_END) < 0) {
+ fprintf(stderr, "lseek: %s\n", strerror(errno));
+ } else {
+ dump_backtrace_to_file(pid, fd);
+ }
+
+ close(fd);
+}
+
/*
* JNI registration.
*/
@@ -569,6 +601,8 @@ static JNINativeMethod gMethods[] = {
(void*)android_os_Debug_getProxyObjectCount },
{ "getBinderDeathObjectCount", "()I",
(void*)android_os_Debug_getDeathObjectCount },
+ { "dumpNativeBacktraceToFile", "(ILjava/lang/String;)V",
+ (void*)android_os_Debug_dumpNativeBacktraceToFile },
};
int register_android_os_Debug(JNIEnv *env)