Merge "Log subject in ANR dump file for ANRs + watchdogs" into sc-dev

This commit is contained in:
Ben Miles
2021-05-21 10:26:48 +00:00
committed by Android (Google) Code Review
4 changed files with 35 additions and 8 deletions

View File

@@ -192,7 +192,7 @@ public final class SystemServerInitThreadPool implements Dumpable {
final ArrayList<Integer> pids = new ArrayList<>();
pids.add(Process.myPid());
ActivityManagerService.dumpStackTraces(pids, null, null,
Watchdog.getInterestingNativePids(), null);
Watchdog.getInterestingNativePids(), null, null);
}
@Override

View File

@@ -658,7 +658,7 @@ public class Watchdog {
// We've waited half the deadlock-detection interval. Pull a stack
// trace and wait another half.
ActivityManagerService.dumpStackTraces(pids, null, null,
getInterestingNativePids(), null);
getInterestingNativePids(), null, subject);
continue;
}
@@ -674,7 +674,7 @@ public class Watchdog {
StringWriter tracesFileException = new StringWriter();
final File stack = ActivityManagerService.dumpStackTraces(
pids, processCpuTracker, new SparseArray<>(), getInterestingNativePids(),
tracesFileException);
tracesFileException, subject);
// 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.
@@ -699,7 +699,8 @@ public class Watchdog {
if (mActivity != null) {
mActivity.addErrorToDropBox(
"watchdog", null, "system_server", null, null, null,
localSubject, report.toString(), stack, null, null, null, null);
null, report.toString(), stack, null, null, null, null);
}
FrameworkStatsLog.write(FrameworkStatsLog.SYSTEM_SERVER_WATCHDOG_OCCURRED,
localSubject);

View File

@@ -407,6 +407,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -3153,7 +3154,23 @@ public class ActivityManagerService extends IActivityManager.Stub
ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids,
ArrayList<Integer> nativePids, StringWriter logExceptionCreatingFile) {
return dumpStackTraces(firstPids, processCpuTracker, lastPids, nativePids,
logExceptionCreatingFile, null);
logExceptionCreatingFile, null, null);
}
/**
* If a stack trace dump file is configured, dump process stack traces.
* @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 nativePids optional list of native pids to dump stack crawls
* @param logExceptionCreatingFile optional writer to which we log errors creating the file
* @param subject optional line related to the error
*/
public static File dumpStackTraces(ArrayList<Integer> firstPids,
ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids,
ArrayList<Integer> nativePids, StringWriter logExceptionCreatingFile,
String subject) {
return dumpStackTraces(firstPids, processCpuTracker, lastPids, nativePids,
logExceptionCreatingFile, null, subject);
}
/**
@@ -3163,7 +3180,7 @@ public class ActivityManagerService extends IActivityManager.Stub
/* package */ static File dumpStackTraces(ArrayList<Integer> firstPids,
ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids,
ArrayList<Integer> nativePids, StringWriter logExceptionCreatingFile,
long[] firstPidOffsets) {
long[] firstPidOffsets, String subject) {
ArrayList<Integer> extraPids = null;
Slog.i(TAG, "dumpStackTraces pids=" + lastPids + " nativepids=" + nativePids);
@@ -3215,6 +3232,15 @@ public class ActivityManagerService extends IActivityManager.Stub
return null;
}
if (subject != null) {
try (FileOutputStream fos = new FileOutputStream(tracesFile, true)) {
String header = "Subject: " + subject + "\n";
fos.write(header.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
Slog.w(TAG, "Exception writing subject to ANR dump file:", e);
}
}
Pair<Long, Long> offsets = dumpStackTraces(
tracesFile.getAbsolutePath(), firstPids, nativePids, extraPids);
if (firstPidOffsets != null) {

View File

@@ -377,7 +377,7 @@ class ProcessErrorStateRecord {
final long[] offsets = new long[2];
File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
isSilentAnr ? null : processCpuTracker, isSilentAnr ? null : lastPids,
nativePids, tracesFileException, offsets);
nativePids, tracesFileException, offsets, annotation);
if (isMonitorCpuUsage()) {
mService.updateCpuStatsNow();
@@ -467,7 +467,7 @@ class ProcessErrorStateRecord {
final ProcessRecord parentPr = parentProcess != null
? (ProcessRecord) parentProcess.mOwner : null;
mService.addErrorToDropBox("anr", mApp, mApp.processName, activityShortComponentName,
parentShortComponentName, parentPr, annotation, report.toString(), tracesFile,
parentShortComponentName, parentPr, null, report.toString(), tracesFile,
null, new Float(loadingProgress), incrementalMetrics, errorId);
if (mApp.getWindowProcessController().appNotResponding(info.toString(),