diff options
| author | 2019-06-12 02:58:31 +0000 | |
|---|---|---|
| committer | 2019-06-12 02:58:31 +0000 | |
| commit | e252d155b13e0f63ea4d2ff148bbb74aaf7db1da (patch) | |
| tree | 240deb361b745f543b5b385dbc4bb72259822c64 | |
| parent | 1f7ee0bc98d7cdc52f7428515730772909960931 (diff) | |
| parent | 72768ed944a1348d77ad7ff300d6fc93f93e4827 (diff) | |
Merge changes I66eac0c5,I07602072 into qt-dev
* changes:
Frameworks: Add fdatasync after dumping a trace
Frameworks: Change Java stack trace dumping
| -rw-r--r-- | core/jni/android_os_Debug.cpp | 10 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 26 |
2 files changed, 30 insertions, 6 deletions
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 842679ec7d22..14dbabb1ce02 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -713,16 +713,20 @@ static bool dumpTraces(JNIEnv* env, jint pid, jstring fileName, jint timeoutSecs O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC | O_APPEND, 0666)); if (fd < 0) { - fprintf(stderr, "Can't open %s: %s\n", fileNameChars.c_str(), strerror(errno)); + PLOG(ERROR) << "Can't open " << fileNameChars.c_str(); return false; } - return (dump_backtrace_to_file_timeout(pid, dumpType, timeoutSecs, fd) == 0); + int res = dump_backtrace_to_file_timeout(pid, dumpType, timeoutSecs, fd); + if (fdatasync(fd.get()) != 0) { + PLOG(ERROR) << "Failed flushing trace."; + } + return res == 0; } static jboolean android_os_Debug_dumpJavaBacktraceToFileTimeout(JNIEnv* env, jobject clazz, jint pid, jstring fileName, jint timeoutSecs) { - const bool ret = dumpTraces(env, pid, fileName, timeoutSecs, kDebuggerdJavaBacktrace); + const bool ret = dumpTraces(env, pid, fileName, timeoutSecs, kDebuggerdJavaBacktrace); return ret ? JNI_TRUE : JNI_FALSE; } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 0c7fe114fd40..f14a3fdda8db 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -547,6 +547,7 @@ public class ActivityManagerService extends IActivityManager.Stub private static final int MAX_BUGREPORT_TITLE_SIZE = 50; private static final int NATIVE_DUMP_TIMEOUT_MS = 2000; // 2 seconds; + private static final int JAVA_DUMP_MINIMUM_SIZE = 100; // 100 bytes. OomAdjuster mOomAdjuster; final LowMemDetector mLowMemDetector; @@ -3805,9 +3806,28 @@ public class ActivityManagerService extends IActivityManager.Stub */ private static long dumpJavaTracesTombstoned(int pid, String fileName, long timeoutMs) { final long timeStart = SystemClock.elapsedRealtime(); - if (!Debug.dumpJavaBacktraceToFileTimeout(pid, fileName, (int) (timeoutMs / 1000))) { - Debug.dumpNativeBacktraceToFileTimeout(pid, fileName, - (NATIVE_DUMP_TIMEOUT_MS / 1000)); + boolean javaSuccess = Debug.dumpJavaBacktraceToFileTimeout(pid, fileName, + (int) (timeoutMs / 1000)); + if (javaSuccess) { + // Check that something is in the file, actually. Try-catch should not be necessary, + // but better safe than sorry. + try { + long size = new File(fileName).length(); + if (size < JAVA_DUMP_MINIMUM_SIZE) { + Slog.w(TAG, "Successfully created Java ANR file is empty!"); + javaSuccess = false; + } + } catch (Exception e) { + Slog.w(TAG, "Unable to get ANR file size", e); + javaSuccess = false; + } + } + if (!javaSuccess) { + Slog.w(TAG, "Dumping Java threads failed, initiating native stack dump."); + if (!Debug.dumpNativeBacktraceToFileTimeout(pid, fileName, + (NATIVE_DUMP_TIMEOUT_MS / 1000))) { + Slog.w(TAG, "Native stack dump failed!"); + } } return SystemClock.elapsedRealtime() - timeStart; |