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

Commit 32a9284d authored by Liana Kazanova's avatar Liana Kazanova Committed by Android (Google) Code Review
Browse files

Merge "Merge "Add Memory headers to ANR reports" into udc-dev am: b735496b am: 1bf01e7f"

parents bcd276d6 d0eec93e
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR;
import static com.android.server.am.ActivityManagerService.MY_PID;
import static com.android.server.am.ProcessRecord.TAG;
import static com.android.server.stats.pull.ProcfsMemoryUtil.readMemorySnapshotFromProcfs;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AnrController;
import android.app.ApplicationErrorReport;
@@ -56,6 +58,7 @@ import com.android.internal.os.anr.AnrLatencyTracker;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.ResourcePressureUtil;
import com.android.server.criticalevents.CriticalEventLog;
import com.android.server.stats.pull.ProcfsMemoryUtil.MemorySnapshot;
import com.android.server.wm.WindowProcessController;

import java.io.File;
@@ -400,6 +403,8 @@ class ProcessErrorStateRecord {
                });
            }
        }
        // Build memory headers for the ANRing process.
        String memoryHeaders = buildMemoryHeadersFor(pid);

        // Get critical event log before logging the ANR so that it doesn't occur in the log.
        latencyTracker.criticalEventLogStarted();
@@ -500,7 +505,8 @@ class ProcessErrorStateRecord {
        File tracesFile = StackTracesDumpHelper.dumpStackTraces(firstPids,
                isSilentAnr ? null : processCpuTracker, isSilentAnr ? null : lastPids,
                nativePidsFuture, tracesFileException, firstPidEndOffset, annotation,
                criticalEventLog, auxiliaryTaskExecutor, firstPidFilePromise, latencyTracker);
                criticalEventLog, memoryHeaders, auxiliaryTaskExecutor, firstPidFilePromise,
                latencyTracker);

        if (isMonitorCpuUsage()) {
            // Wait for the first call to finish
@@ -714,6 +720,26 @@ class ProcessErrorStateRecord {
            resolver.getUserId()) != 0;
    }

    private @Nullable String buildMemoryHeadersFor(int pid) {
        if (pid <= 0) {
            Slog.i(TAG, "Memory header requested with invalid pid: " + pid);
            return null;
        }
        MemorySnapshot snapshot = readMemorySnapshotFromProcfs(pid);
        if (snapshot == null) {
            Slog.i(TAG, "Failed to get memory snapshot for pid:" + pid);
            return null;
        }

        StringBuilder memoryHeaders = new StringBuilder();
        memoryHeaders.append("RssHwmKb: ")
            .append(snapshot.rssHighWaterMarkInKilobytes)
            .append("\n");
        memoryHeaders.append("RssKb: ").append(snapshot.rssInKilobytes).append("\n");
        memoryHeaders.append("RssAnonKb: ").append(snapshot.anonRssInKilobytes).append("\n");
        memoryHeaders.append("VmSwapKb: ").append(snapshot.swapInKilobytes).append("\n");
        return memoryHeaders.toString();
    }
    /**
     * Unless configured otherwise, swallow ANRs in background processes & kill the process.
     * Non-private access is for tests only.
+7 −6
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class StackTracesDumpHelper {
            Future<ArrayList<Integer>> nativePidsFuture, StringWriter logExceptionCreatingFile,
            @NonNull Executor auxiliaryTaskExecutor, AnrLatencyTracker latencyTracker) {
        return dumpStackTraces(firstPids, processCpuTracker, lastPids, nativePidsFuture,
                logExceptionCreatingFile, null, null, null, auxiliaryTaskExecutor, null,
                logExceptionCreatingFile, null, null, null, null, auxiliaryTaskExecutor, null,
                latencyTracker);
    }

@@ -108,7 +108,7 @@ public class StackTracesDumpHelper {
            AnrLatencyTracker latencyTracker) {
        return dumpStackTraces(firstPids, processCpuTracker, lastPids, nativePidsFuture,
                logExceptionCreatingFile, null, subject, criticalEventSection,
                auxiliaryTaskExecutor, null, latencyTracker);
                /* memoryHeaders= */ null, auxiliaryTaskExecutor, null, latencyTracker);
    }

    /**
@@ -119,8 +119,8 @@ public class StackTracesDumpHelper {
            ProcessCpuTracker processCpuTracker, SparseBooleanArray lastPids,
            Future<ArrayList<Integer>> nativePidsFuture, StringWriter logExceptionCreatingFile,
            AtomicLong firstPidEndOffset, String subject, String criticalEventSection,
            @NonNull Executor auxiliaryTaskExecutor, Future<File> firstPidFilePromise,
            AnrLatencyTracker latencyTracker) {
            String memoryHeaders, @NonNull Executor auxiliaryTaskExecutor,
           Future<File> firstPidFilePromise, AnrLatencyTracker latencyTracker) {
        try {

            if (latencyTracker != null) {
@@ -160,9 +160,10 @@ public class StackTracesDumpHelper {
                return null;
            }

            if (subject != null || criticalEventSection != null) {
            if (subject != null || criticalEventSection != null || memoryHeaders != null) {
                appendtoANRFile(tracesFile.getAbsolutePath(),
                        (subject != null ? "Subject: " + subject + "\n\n" : "")
                        (subject != null ? "Subject: " + subject + "\n" : "")
                        + (memoryHeaders != null ? memoryHeaders + "\n\n" : "")
                        + (criticalEventSection != null ? criticalEventSection : ""));
            }