Merge "Refactor Watchdog to dump interesting Java process stacks" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5a1a4f2241
@@ -69,21 +69,21 @@ public class Watchdog extends Thread {
|
|||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
|
|
||||||
// Set this to true to use debug default values.
|
// Set this to true to use debug default values.
|
||||||
static final boolean DB = false;
|
private static final boolean DB = false;
|
||||||
|
|
||||||
// Note 1: Do not lower this value below thirty seconds without tightening the invoke-with
|
// Note 1: Do not lower this value below thirty seconds without tightening the invoke-with
|
||||||
// timeout in com.android.internal.os.ZygoteConnection, or wrapped applications
|
// timeout in com.android.internal.os.ZygoteConnection, or wrapped applications
|
||||||
// can trigger the watchdog.
|
// can trigger the watchdog.
|
||||||
// Note 2: The debug value is already below the wait time in ZygoteConnection. Wrapped
|
// Note 2: The debug value is already below the wait time in ZygoteConnection. Wrapped
|
||||||
// applications may not work with a debug build. CTS will fail.
|
// applications may not work with a debug build. CTS will fail.
|
||||||
static final long DEFAULT_TIMEOUT = DB ? 10*1000 : 60*1000;
|
private static final long DEFAULT_TIMEOUT = DB ? 10 * 1000 : 60 * 1000;
|
||||||
static final long CHECK_INTERVAL = DEFAULT_TIMEOUT / 2;
|
private static final long CHECK_INTERVAL = DEFAULT_TIMEOUT / 2;
|
||||||
|
|
||||||
// These are temporally ordered: larger values as lateness increases
|
// These are temporally ordered: larger values as lateness increases
|
||||||
static final int COMPLETED = 0;
|
private static final int COMPLETED = 0;
|
||||||
static final int WAITING = 1;
|
private static final int WAITING = 1;
|
||||||
static final int WAITED_HALF = 2;
|
private static final int WAITED_HALF = 2;
|
||||||
static final int OVERDUE = 3;
|
private static final int OVERDUE = 3;
|
||||||
|
|
||||||
// Which native processes to dump into dropbox's stack traces
|
// Which native processes to dump into dropbox's stack traces
|
||||||
public static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
|
public static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
|
||||||
@@ -125,17 +125,17 @@ public class Watchdog extends Thread {
|
|||||||
"android.system.suspend@1.0::ISystemSuspend"
|
"android.system.suspend@1.0::ISystemSuspend"
|
||||||
);
|
);
|
||||||
|
|
||||||
static Watchdog sWatchdog;
|
private static Watchdog sWatchdog;
|
||||||
|
|
||||||
/* This handler will be used to post message back onto the main thread */
|
/* This handler will be used to post message back onto the main thread */
|
||||||
final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<>();
|
private final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<>();
|
||||||
final HandlerChecker mMonitorChecker;
|
private final HandlerChecker mMonitorChecker;
|
||||||
ActivityManagerService mActivity;
|
private ActivityManagerService mActivity;
|
||||||
|
|
||||||
int mPhonePid;
|
private IActivityController mController;
|
||||||
IActivityController mController;
|
private boolean mAllowRestart = true;
|
||||||
boolean mAllowRestart = true;
|
private final OpenFdMonitor mOpenFdMonitor;
|
||||||
final OpenFdMonitor mOpenFdMonitor;
|
private final List<Integer> mInterestingJavaPids = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for checking status of handle threads and scheduling monitor callbacks.
|
* Used for checking status of handle threads and scheduling monitor callbacks.
|
||||||
@@ -342,6 +342,8 @@ public class Watchdog extends Thread {
|
|||||||
|
|
||||||
mOpenFdMonitor = OpenFdMonitor.create();
|
mOpenFdMonitor = OpenFdMonitor.create();
|
||||||
|
|
||||||
|
mInterestingJavaPids.add(Process.myPid());
|
||||||
|
|
||||||
// See the notes on DEFAULT_TIMEOUT.
|
// See the notes on DEFAULT_TIMEOUT.
|
||||||
assert DB ||
|
assert DB ||
|
||||||
DEFAULT_TIMEOUT > ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
|
DEFAULT_TIMEOUT > ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
|
||||||
@@ -359,10 +361,31 @@ public class Watchdog extends Thread {
|
|||||||
android.Manifest.permission.REBOOT, null);
|
android.Manifest.permission.REBOOT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processStarted(String name, int pid) {
|
private static boolean isInterestingJavaProcess(String processName) {
|
||||||
synchronized (this) {
|
return processName.equals("com.android.phone");
|
||||||
if ("com.android.phone".equals(name)) {
|
}
|
||||||
mPhonePid = pid;
|
|
||||||
|
/**
|
||||||
|
* Notifies the watchdog when a Java process with {@code pid} is started.
|
||||||
|
* This process may have its stack trace dumped during an ANR.
|
||||||
|
*/
|
||||||
|
public void processStarted(String processName, int pid) {
|
||||||
|
if (isInterestingJavaProcess(processName)) {
|
||||||
|
Slog.i(TAG, "Interesting Java process " + processName + " started. Pid " + pid);
|
||||||
|
synchronized (this) {
|
||||||
|
mInterestingJavaPids.add(pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies the watchdog when a Java process with {@code pid} dies.
|
||||||
|
*/
|
||||||
|
public void processDied(String processName, int pid) {
|
||||||
|
if (isInterestingJavaProcess(processName)) {
|
||||||
|
Slog.i(TAG, "Interesting Java process " + processName + " died. Pid " + pid);
|
||||||
|
synchronized (this) {
|
||||||
|
mInterestingJavaPids.remove(Integer.valueOf(pid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,8 +605,7 @@ public class Watchdog extends Thread {
|
|||||||
Slog.i(TAG, "WAITED_HALF");
|
Slog.i(TAG, "WAITED_HALF");
|
||||||
// We've waited half the deadlock-detection interval. Pull a stack
|
// We've waited half the deadlock-detection interval. Pull a stack
|
||||||
// trace and wait another half.
|
// trace and wait another half.
|
||||||
ArrayList<Integer> pids = new ArrayList<Integer>();
|
ArrayList<Integer> pids = new ArrayList<>(mInterestingJavaPids);
|
||||||
pids.add(Process.myPid());
|
|
||||||
ActivityManagerService.dumpStackTraces(pids, null, null,
|
ActivityManagerService.dumpStackTraces(pids, null, null,
|
||||||
getInterestingNativePids(), null);
|
getInterestingNativePids(), null);
|
||||||
waitedHalf = true;
|
waitedHalf = true;
|
||||||
@@ -606,9 +628,7 @@ public class Watchdog extends Thread {
|
|||||||
// Then kill this process so that the system will restart.
|
// Then kill this process so that the system will restart.
|
||||||
EventLog.writeEvent(EventLogTags.WATCHDOG, subject);
|
EventLog.writeEvent(EventLogTags.WATCHDOG, subject);
|
||||||
|
|
||||||
ArrayList<Integer> pids = new ArrayList<>();
|
ArrayList<Integer> pids = new ArrayList<>(mInterestingJavaPids);
|
||||||
pids.add(Process.myPid());
|
|
||||||
if (mPhonePid > 0) pids.add(mPhonePid);
|
|
||||||
|
|
||||||
long anrTime = SystemClock.uptimeMillis();
|
long anrTime = SystemClock.uptimeMillis();
|
||||||
StringBuilder report = new StringBuilder();
|
StringBuilder report = new StringBuilder();
|
||||||
|
|||||||
@@ -2396,9 +2396,7 @@ public final class ProcessList {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.isPersistent()) {
|
Watchdog.getInstance().processStarted(app.processName, pid);
|
||||||
Watchdog.getInstance().processStarted(app.processName, pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkSlow(app.startTime, "startProcess: building log message");
|
checkSlow(app.startTime, "startProcess: building log message");
|
||||||
StringBuilder buf = mStringBuilder;
|
StringBuilder buf = mStringBuilder;
|
||||||
@@ -3769,6 +3767,7 @@ public final class ProcessList {
|
|||||||
Slog.i(TAG, "note: " + app + " died, saving the exit info");
|
Slog.i(TAG, "note: " + app + " died, saving the exit info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Watchdog.getInstance().processDied(app.processName, app.pid);
|
||||||
mAppExitInfoTracker.scheduleNoteProcessDiedLocked(app);
|
mAppExitInfoTracker.scheduleNoteProcessDiedLocked(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user