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

Commit dfc56be7 authored by Simon MacMullen's avatar Simon MacMullen
Browse files

Add CPU usage data to system server watchdog events.

We already do this for regular ANRs so we might as well do it for system server watchdog.

Test: added code to make the watchdog trigger when system server did nothing wrong, observed the results.

Change-Id: I1e6aa41539b909b5b5cb12dfec22245900616b91
parent f8ac43ed
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -39,8 +39,10 @@ import android.system.StructRlimit;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.StatsLog;

import com.android.internal.os.ProcessCpuTracker;
import com.android.internal.os.ZygoteConnectionConstants;
import com.android.server.am.ActivityManagerService;
import com.android.server.wm.SurfaceAnimationThread;
@@ -606,13 +608,18 @@ public class Watchdog extends Thread {
            pids.add(Process.myPid());
            if (mPhonePid > 0) pids.add(mPhonePid);

            long anrTime = SystemClock.uptimeMillis();
            ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(false);
            final File stack = ActivityManagerService.dumpStackTraces(
                    pids, null, null, getInterestingNativePids());
                    pids, processCpuTracker, new SparseArray<>(), getInterestingNativePids());

            // Give some extra time to make sure the stack traces get written.
            // The system's been hanging for a minute, another second or two won't hurt much.
            SystemClock.sleep(5000);

            processCpuTracker.update();
            String cpuInfo = processCpuTracker.printCurrentState(anrTime);

            // Trigger the kernel to dump all blocked threads, and backtraces on all CPUs to the kernel log
            doSysRq('w');
            doSysRq('l');
@@ -627,7 +634,7 @@ public class Watchdog extends Thread {
                        if (mActivity != null) {
                            mActivity.addErrorToDropBox(
                                    "watchdog", null, "system_server", null, null, null,
                                    subject, null, stack, null);
                                    subject, cpuInfo, stack, null);
                        }
                        StatsLog.write(StatsLog.SYSTEM_SERVER_WATCHDOG_OCCURRED, subject);
                    }