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

Commit 645cd6c4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Replace memoryHeaders with a more generic extraHeaders, and add a...

Merge "Replace memoryHeaders with a more generic extraHeaders, and add a watchdog-specific header" into main
parents 2ed2d1a3 0906100d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -197,8 +197,8 @@ public final class SystemServerInitThreadPool implements Dumpable {
                /* processCpuTracker= */null, /* lastPids= */null,
                CompletableFuture.completedFuture(Watchdog.getInterestingNativePids()),
                /* logExceptionCreatingFile= */null, /* subject= */null,
                /* criticalEventSection= */null, Runnable::run,
                /* latencyTracker= */null);
                /* criticalEventSection= */null, /* extraHeaders= */ null,
                Runnable::run, /* latencyTracker= */null);
    }

    @Override
+7 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -991,6 +992,9 @@ public class Watchdog implements Dumpable {
            FrameworkStatsLog.write(FrameworkStatsLog.SYSTEM_SERVER_WATCHDOG_OCCURRED, subject);
        }

        final LinkedHashMap headersMap =
                com.android.server.am.Flags.enableDropboxWatchdogHeaders()
                ? new LinkedHashMap<>(Collections.singletonMap("Watchdog-Type", dropboxTag)) : null;
        long anrTime = SystemClock.uptimeMillis();
        StringBuilder report = new StringBuilder();
        report.append(ResourcePressureUtil.currentPsiState());
@@ -998,8 +1002,9 @@ public class Watchdog implements Dumpable {
        StringWriter tracesFileException = new StringWriter();
        final File stack = StackTracesDumpHelper.dumpStackTraces(
                pids, processCpuTracker, new SparseBooleanArray(),
                CompletableFuture.completedFuture(getInterestingNativePids()), tracesFileException,
                subject, criticalEvents, Runnable::run, /* latencyTracker= */null);
                CompletableFuture.completedFuture(getInterestingNativePids()),
                tracesFileException, subject, criticalEvents, headersMap,
                Runnable::run, /* latencyTracker= */null);
        // Give some extra time to make sure the stack traces get written.
        // The system's been hanging for a whlie, another second or two won't hurt much.
        SystemClock.sleep(5000);
+10 −12
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ 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 com.android.server.utils.AnrTimer;

import java.io.File;
import java.io.PrintWriter;
@@ -69,6 +68,7 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -429,7 +429,7 @@ class ProcessErrorStateRecord {
            }
        }
        // Build memory headers for the ANRing process.
        String memoryHeaders = buildMemoryHeadersFor(pid);
        LinkedHashMap<String, String> memoryHeaders = buildMemoryHeadersFor(pid);

        // Get critical event log before logging the ANR so that it doesn't occur in the log.
        latencyTracker.criticalEventLogStarted();
@@ -753,7 +753,7 @@ class ProcessErrorStateRecord {
            resolver.getUserId()) != 0;
    }

    private @Nullable String buildMemoryHeadersFor(int pid) {
    private @Nullable LinkedHashMap<String, String> buildMemoryHeadersFor(int pid) {
        if (pid <= 0) {
            Slog.i(TAG, "Memory header requested with invalid pid: " + pid);
            return null;
@@ -764,15 +764,13 @@ class ProcessErrorStateRecord {
            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("RssShmemKb: ").append(snapshot.rssShmemKilobytes).append("\n");
        memoryHeaders.append("VmSwapKb: ").append(snapshot.swapInKilobytes).append("\n");
        return memoryHeaders.toString();
        LinkedHashMap<String, String> memoryHeaders = new LinkedHashMap<>();
        memoryHeaders.put("RssHwmKb", Integer.toString(snapshot.rssHighWaterMarkInKilobytes));
        memoryHeaders.put("RssKb", Integer.toString(snapshot.rssInKilobytes));
        memoryHeaders.put("RssAnonKb", Integer.toString(snapshot.anonRssInKilobytes));
        memoryHeaders.put("RssShmemKb", Integer.toString(snapshot.rssShmemKilobytes));
        memoryHeaders.put("VmSwapKb", Integer.toString(snapshot.swapInKilobytes));
        return memoryHeaders;
    }
    /**
     * Unless configured otherwise, swallow ANRs in background processes & kill the process.
+21 −5
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -100,15 +102,17 @@ public class StackTracesDumpHelper {
    /**
     * @param subject the subject of the dumped traces
     * @param criticalEventSection the critical event log, passed as a string
     * @param extraHeaders Optional, Extra headers added by the dumping method
     */
    public static File dumpStackTraces(ArrayList<Integer> firstPids,
            ProcessCpuTracker processCpuTracker, SparseBooleanArray lastPids,
            Future<ArrayList<Integer>> nativePidsFuture, StringWriter logExceptionCreatingFile,
            String subject, String criticalEventSection, @NonNull Executor auxiliaryTaskExecutor,
            String subject, String criticalEventSection,
            LinkedHashMap<String, String> extraHeaders, @NonNull Executor auxiliaryTaskExecutor,
            AnrLatencyTracker latencyTracker) {
        return dumpStackTraces(firstPids, processCpuTracker, lastPids, nativePidsFuture,
                logExceptionCreatingFile, null, subject, criticalEventSection,
                /* memoryHeaders= */ null, auxiliaryTaskExecutor, null, latencyTracker);
                extraHeaders, auxiliaryTaskExecutor, null, latencyTracker);
    }

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

@@ -159,11 +163,12 @@ public class StackTracesDumpHelper {
                }
                return null;
            }
            boolean extraHeadersExist = extraHeaders != null && !extraHeaders.isEmpty();

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

@@ -614,4 +619,15 @@ public class StackTracesDumpHelper {
        return pids;
    }

    private static String stringifyHeaders(@NonNull LinkedHashMap<String, String> headers) {
        StringBuilder headersString = new StringBuilder();
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            headersString.append(entry.getKey())
                    .append(": ")
                    .append(entry.getValue())
                    .append("\n");
        }
        return headersString.toString();
    }

}
+9 −1
Original line number Diff line number Diff line
@@ -168,3 +168,11 @@ flag {
    bug: "324222683"
    is_fixed_read_only: true
}

flag {
    name: "enable_dropbox_watchdog_headers"
    namespace: "dropbox"
    description: "Add watchdog-specific dropbox headers"
    bug: "330682397"
    is_fixed_read_only: true
}
Loading