Include important native processes in watchdog stacks.
Helps us track down deadlocks involving native service processes.
Bug: 6615693
Change-Id: I580047550772e29586195a8cf440141574e3f40c
diff --git a/services/java/com/android/server/Watchdog.java b/services/java/com/android/server/Watchdog.java
index 728fb26..c239382 100644
--- a/services/java/com/android/server/Watchdog.java
+++ b/services/java/com/android/server/Watchdog.java
@@ -67,6 +67,12 @@
static final String REBOOT_ACTION = "com.android.service.Watchdog.REBOOT";
+ static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
+ "/system/bin/mediaserver",
+ "/system/bin/sdcard",
+ "/system/bin/surfaceflinger"
+ };
+
static Watchdog sWatchdog;
/* This handler will be used to post message back onto the main thread */
@@ -414,7 +420,8 @@
// trace and wait another half.
ArrayList<Integer> pids = new ArrayList<Integer>();
pids.add(Process.myPid());
- ActivityManagerService.dumpStackTraces(true, pids, null, null);
+ ActivityManagerService.dumpStackTraces(true, pids, null, null,
+ NATIVE_STACKS_OF_INTEREST);
waitedHalf = true;
continue;
}
@@ -434,7 +441,7 @@
// Pass !waitedHalf so that just in case we somehow wind up here without having
// dumped the halfway stacks, we properly re-initialize the trace file.
final File stack = ActivityManagerService.dumpStackTraces(
- !waitedHalf, pids, null, null);
+ !waitedHalf, pids, null, null, NATIVE_STACKS_OF_INTEREST);
// 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.
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 63d6fa3..63455ee 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -3019,10 +3019,11 @@
* appended to any existing file content.
* @param firstPids of dalvik VM processes to dump stack traces for first
* @param lastPids of dalvik VM processes to dump stack traces for last
+ * @param nativeProcs optional list of native process names to dump stack crawls
* @return file containing stack traces, or null if no dump file is configured
*/
public static File dumpStackTraces(boolean clearTraces, ArrayList<Integer> firstPids,
- ProcessStats processStats, SparseArray<Boolean> lastPids) {
+ ProcessStats processStats, SparseArray<Boolean> lastPids, String[] nativeProcs) {
String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
if (tracesPath == null || tracesPath.length() == 0) {
return null;
@@ -3042,12 +3043,12 @@
return null;
}
- dumpStackTraces(tracesPath, firstPids, processStats, lastPids);
+ dumpStackTraces(tracesPath, firstPids, processStats, lastPids, nativeProcs);
return tracesFile;
}
private static void dumpStackTraces(String tracesPath, ArrayList<Integer> firstPids,
- ProcessStats processStats, SparseArray<Boolean> lastPids) {
+ ProcessStats processStats, SparseArray<Boolean> lastPids, String[] nativeProcs) {
// Use a FileObserver to detect when traces finish writing.
// The order of traces is considered important to maintain for legibility.
FileObserver observer = new FileObserver(tracesPath, FileObserver.CLOSE_WRITE) {
@@ -3108,6 +3109,15 @@
} finally {
observer.stopWatching();
}
+
+ if (nativeProcs != null) {
+ int[] pids = Process.getPidsForCommands(nativeProcs);
+ if (pids != null) {
+ for (int pid : pids) {
+ Debug.dumpNativeBacktraceToFile(pid, tracesPath);
+ }
+ }
+ }
}
final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
@@ -3156,7 +3166,7 @@
if (app != null) {
ArrayList<Integer> firstPids = new ArrayList<Integer>();
firstPids.add(app.pid);
- dumpStackTraces(tracesPath, firstPids, null, null);
+ dumpStackTraces(tracesPath, firstPids, null, null, null);
}
File lastTracesFile = null;
@@ -3264,7 +3274,7 @@
final ProcessStats processStats = new ProcessStats(true);
- File tracesFile = dumpStackTraces(true, firstPids, processStats, lastPids);
+ File tracesFile = dumpStackTraces(true, firstPids, processStats, lastPids, null);
String cpuInfo = null;
if (MONITOR_CPU_USAGE) {