Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c7cdd53 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge changes I66eac0c5,I07602072 into qt-dev am: e252d155

am: db47069d

Change-Id: Ie8060f317ea0ed9829ae8279aa08a81cac5f0639
parents 49330e08 db47069d
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -713,11 +713,15 @@ 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,
+23 −3
Original line number Diff line number Diff line
@@ -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;