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

Commit 9369efdf authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Work on issue #24403813: ANR traces are too heavyweight.

Most of the changes here are optional debugging output.

The actual functional changes:

(1) One of the ANR paths was not being dispatched on the activity
manager's handler, so it could execute concurrently with other
ANR collection, conflicting with the ANR file.
(2) Bumped up the timeout for trace collection from 200ms to
1000ms.  This should fix problems where some process were not
being included, since once one of the collections times out we
can no longer keep synchronized with anything else after and
could end up with data getting corrupt or blown away.

Change-Id: If6828d2dea1a25cd6d2334a652b1b31654d9062f
parent 8316fac9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ class ActivityManagerDebugConfig {

    // Available log categories in the activity manager package.
    static final boolean DEBUG_ADD_REMOVE = DEBUG_ALL_ACTIVITIES || false;
    static final boolean DEBUG_ANR = false;
    static final boolean DEBUG_APP = DEBUG_ALL_ACTIVITIES || false;
    static final boolean DEBUG_BACKUP = DEBUG_ALL || false;
    static final boolean DEBUG_BROADCAST = DEBUG_ALL || false;
+27 −9
Original line number Diff line number Diff line
@@ -284,6 +284,7 @@ import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
import static com.android.internal.util.XmlUtils.writeIntAttribute;
import static com.android.internal.util.XmlUtils.writeLongAttribute;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKUP;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST_BACKGROUND;
@@ -5091,8 +5092,13 @@ public final class ActivityManagerService extends ActivityManagerNative
                    int num = firstPids.size();
                    for (int i = 0; i < num; i++) {
                        synchronized (observer) {
                            if (DEBUG_ANR) Slog.d(TAG, "Collecting stacks for pid "
                                    + firstPids.get(i));
                            final long sime = SystemClock.elapsedRealtime();
                            Process.sendSignal(firstPids.get(i), Process.SIGNAL_QUIT);
                            observer.wait(200);  // Wait for write-close, give up after 200msec
                            observer.wait(1000);  // Wait for write-close, give up after 1 sec
                            if (DEBUG_ANR) Slog.d(TAG, "Done with pid " + firstPids.get(i)
                                    + " in " + (SystemClock.elapsedRealtime()-sime) + "ms");
                        }
                    }
                } catch (InterruptedException e) {
@@ -5105,7 +5111,11 @@ public final class ActivityManagerService extends ActivityManagerNative
                int[] pids = Process.getPidsForCommands(nativeProcs);
                if (pids != null) {
                    for (int pid : pids) {
                        if (DEBUG_ANR) Slog.d(TAG, "Collecting stacks for native pid " + pid);
                        final long sime = SystemClock.elapsedRealtime();
                        Debug.dumpNativeBacktraceToFile(pid, tracesPath);
                        if (DEBUG_ANR) Slog.d(TAG, "Done with native pid " + pid
                                + " in " + (SystemClock.elapsedRealtime()-sime) + "ms");
                    }
                }
            }
@@ -5132,13 +5142,20 @@ public final class ActivityManagerService extends ActivityManagerNative
                        numProcs++;
                        try {
                            synchronized (observer) {
                                if (DEBUG_ANR) Slog.d(TAG, "Collecting stacks for extra pid "
                                        + stats.pid);
                                final long stime = SystemClock.elapsedRealtime();
                                Process.sendSignal(stats.pid, Process.SIGNAL_QUIT);
                                observer.wait(200);  // Wait for write-close, give up after 200msec
                                observer.wait(1000);  // Wait for write-close, give up after 1 sec
                                if (DEBUG_ANR) Slog.d(TAG, "Done with extra pid " + stats.pid
                                        + " in " + (SystemClock.elapsedRealtime()-stime) + "ms");
                            }
                        } catch (InterruptedException e) {
                            Slog.wtf(TAG, e);
                        }
                    } else if (DEBUG_ANR) {
                        Slog.d(TAG, "Skipping next CPU consuming process, not a java proc: "
                                + stats.pid);
                    }
                }
            }
@@ -10784,12 +10801,13 @@ public final class ActivityManagerService extends ActivityManagerNative
            return;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            mAppErrors.appNotResponding(host, null, null, false, "ContentProvider not responding");
        } finally {
            Binder.restoreCallingIdentity(token);
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mAppErrors.appNotResponding(host, null, null, false,
                        "ContentProvider not responding");
            }
        });
    }
    public final void installSystemProviders() {
+3 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import java.util.HashMap;
import java.util.concurrent.Semaphore;

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.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityManagerService.MY_PID;
@@ -806,8 +807,10 @@ class AppErrors {
                    if (pid > 0 && pid != app.pid && pid != parentPid && pid != MY_PID) {
                        if (r.persistent) {
                            firstPids.add(pid);
                            if (DEBUG_ANR) Slog.i(TAG, "Adding persistent proc: " + r);
                        } else {
                            lastPids.put(pid, Boolean.TRUE);
                            if (DEBUG_ANR) Slog.i(TAG, "Adding ANR proc: " + r);
                        }
                    }
                }