Merge "Added 'dumpsys activity lastanr'" into oc-dev

am: b32fecd6e0

Change-Id: I599924b33fbb137ba03607308011a8a76b524c72
This commit is contained in:
Wale Ogunwale
2017-06-10 16:07:56 +00:00
committed by android-build-merger
4 changed files with 82 additions and 3 deletions

View File

@@ -249,4 +249,15 @@ public abstract class ActivityManagerInternal {
* {@param vr2dDisplayId}. * {@param vr2dDisplayId}.
*/ */
public abstract void setVr2dDisplayId(int vr2dDisplayId); public abstract void setVr2dDisplayId(int vr2dDisplayId);
/**
* Saves the current activity manager state and includes the saved state in the next dump of
* activity manager.
*/
public abstract void saveANRState(String reason);
/**
* Clears the previously saved activity manager ANR state.
*/
public abstract void clearSavedANRState();
} }

View File

@@ -430,10 +430,12 @@ import java.io.StringWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -700,6 +702,12 @@ public class ActivityManagerService extends IActivityManager.Stub
final AppErrors mAppErrors; final AppErrors mAppErrors;
/**
* Dump of the activity state at the time of the last ANR. Cleared after
* {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS}
*/
String mLastANRState;
/** /**
* Indicates the maximum time spent waiting for the network rules to get updated. * Indicates the maximum time spent waiting for the network rules to get updated.
*/ */
@@ -14929,6 +14937,10 @@ public class ActivityManagerService extends IActivityManager.Stub
synchronized (this) { synchronized (this) {
dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, dumpPackage); dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, dumpPackage);
} }
} else if ("lastanr".equals(cmd)) {
synchronized (this) {
dumpLastANRLocked(pw);
}
} else if ("recents".equals(cmd) || "r".equals(cmd)) { } else if ("recents".equals(cmd) || "r".equals(cmd)) {
synchronized (this) { synchronized (this) {
dumpRecentsLocked(fd, pw, args, opti, true, dumpPackage); dumpRecentsLocked(fd, pw, args, opti, true, dumpPackage);
@@ -15157,6 +15169,11 @@ public class ActivityManagerService extends IActivityManager.Stub
if (dumpAll) { if (dumpAll) {
pw.println("-------------------------------------------------------------------------------"); pw.println("-------------------------------------------------------------------------------");
} }
dumpLastANRLocked(pw);
pw.println();
if (dumpAll) {
pw.println("-------------------------------------------------------------------------------");
}
dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
if (mAssociations.size() > 0) { if (mAssociations.size() > 0) {
pw.println(); pw.println();
@@ -15217,6 +15234,11 @@ public class ActivityManagerService extends IActivityManager.Stub
if (dumpAll) { if (dumpAll) {
pw.println("-------------------------------------------------------------------------------"); pw.println("-------------------------------------------------------------------------------");
} }
dumpLastANRLocked(pw);
pw.println();
if (dumpAll) {
pw.println("-------------------------------------------------------------------------------");
}
dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
if (mAssociations.size() > 0) { if (mAssociations.size() > 0) {
pw.println(); pw.println();
@@ -15235,9 +15257,24 @@ public class ActivityManagerService extends IActivityManager.Stub
Binder.restoreCallingIdentity(origId); Binder.restoreCallingIdentity(origId);
} }
private void dumpLastANRLocked(PrintWriter pw) {
if (mLastANRState == null) {
pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity lastanr)");
pw.println(" <no ANR has occurred since boot>");
} else {
pw.println(mLastANRState);
}
}
void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage,
"ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)");
}
void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) {
pw.println(header);
boolean printedAnything = mStackSupervisor.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, boolean printedAnything = mStackSupervisor.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient,
dumpPackage); dumpPackage);
@@ -23967,10 +24004,37 @@ public class ActivityManagerService extends IActivityManager.Stub
mVr2dDisplayId = vr2dDisplayId; mVr2dDisplayId = vr2dDisplayId;
} }
} }
@Override
public void saveANRState(String reason) {
synchronized (ActivityManagerService.this) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new FastPrintWriter(sw, false, 1024);
pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date()));
if (reason != null) {
pw.println(" Reason: " + reason);
}
pw.println();
dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */,
true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */,
"ACTIVITY MANAGER ACTIVITIES (dumpsys activity lastanr)");
pw.println();
pw.close();
mLastANRState = sw.toString();
}
}
@Override
public void clearSavedANRState() {
synchronized (ActivityManagerService.this) {
mLastANRState = null;
}
}
} }
/** /**
* Called by app main thread to wait for the network policy rules to get udpated. * Called by app main thread to wait for the network policy rules to get updated.
* *
* @param procStateSeq The sequence number indicating the process state change that the main * @param procStateSeq The sequence number indicating the process state change that the main
* thread is interested in. * thread is interested in.

View File

@@ -254,6 +254,9 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
mService.saveANRStateLocked(appWindowToken, windowState, reason); mService.saveANRStateLocked(appWindowToken, windowState, reason);
} }
// All the calls below need to happen without the WM lock held since they call into AM.
mService.mAmInternal.saveANRState(reason);
if (appWindowToken != null && appWindowToken.appToken != null) { if (appWindowToken != null && appWindowToken.appToken != null) {
// Notify the activity manager about the timeout and let it decide whether // Notify the activity manager about the timeout and let it decide whether
// to abort dispatching or keep waiting. // to abort dispatching or keep waiting.

View File

@@ -5116,6 +5116,7 @@ public class WindowManagerService extends IWindowManager.Stub
synchronized (mWindowMap) { synchronized (mWindowMap) {
mLastANRState = null; mLastANRState = null;
} }
mAmInternal.clearSavedANRState();
} }
break; break;
case WALLPAPER_DRAW_PENDING_TIMEOUT: { case WALLPAPER_DRAW_PENDING_TIMEOUT: {
@@ -6572,7 +6573,7 @@ public class WindowManagerService extends IWindowManager.Stub
void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState, String reason) { void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState, String reason) {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new FastPrintWriter(sw, false, 1024); PrintWriter pw = new FastPrintWriter(sw, false, 1024);
pw.println(" ANR time: " + DateFormat.getInstance().format(new Date())); pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date()));
if (appWindowToken != null) { if (appWindowToken != null) {
pw.println(" Application at fault: " + appWindowToken.stringName); pw.println(" Application at fault: " + appWindowToken.stringName);
} }