[am] move incremental manager calls to post dumpStackTraces

To make sure we do not delay taking the thread dump

BUG: 186858453
Test: atest android.cts.statsdatom.statsd.UidAtomTests#testANROccurred
Change-Id: Ia076c72d0b9763f05ddf733dbd6ff73c7fa4c614
This commit is contained in:
Songchun Fan
2021-04-30 14:55:13 -07:00
parent f4d9213903
commit 1af4840b3d

View File

@@ -299,32 +299,6 @@ class ProcessErrorStateRecord {
}
}
// Check if package is still being loaded
float loadingProgress = 1;
IncrementalMetrics incrementalMetrics = null;
final PackageManagerInternal packageManagerInternal = mService.getPackageManagerInternal();
if (mApp.info != null && mApp.info.packageName != null) {
IncrementalStatesInfo incrementalStatesInfo =
packageManagerInternal.getIncrementalStatesInfo(
mApp.info.packageName, mApp.uid, mApp.userId);
if (incrementalStatesInfo != null) {
loadingProgress = incrementalStatesInfo.getProgress();
}
final String codePath = mApp.info.getCodePath();
if (IncrementalManager.isIncrementalPath(codePath)) {
// Report in the main log that the incremental package is still loading
Slog.e(TAG, "App ANR on incremental package " + mApp.info.packageName
+ " which is " + ((int) (loadingProgress * 100)) + "% loaded.");
final IBinder incrementalService = ServiceManager.getService(
Context.INCREMENTAL_SERVICE);
if (incrementalService != null) {
final IncrementalManager incrementalManager = new IncrementalManager(
IIncrementalService.Stub.asInterface(incrementalService));
incrementalMetrics = incrementalManager.getMetrics(codePath);
}
}
}
// Log the ANR to the main log.
StringBuilder info = new StringBuilder();
info.setLength(0);
@@ -342,11 +316,6 @@ class ProcessErrorStateRecord {
info.append("Parent: ").append(parentShortComponentName).append("\n");
}
if (incrementalMetrics != null) {
// Report in the main log about the incremental package
info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n");
}
// Retrieve controller with max ANR delay from AnrControllers
// Note that we retrieve the controller before dumping stacks because dumping stacks can
// take a few seconds, after which the cause of the ANR delay might have completed and
@@ -418,6 +387,37 @@ class ProcessErrorStateRecord {
mService.mProcessList.mAppExitInfoTracker.scheduleLogAnrTrace(
pid, mApp.uid, mApp.getPackageList(), tracesFile, offsets[0], offsets[1]);
}
// Check if package is still being loaded
float loadingProgress = 1;
IncrementalMetrics incrementalMetrics = null;
final PackageManagerInternal packageManagerInternal = mService.getPackageManagerInternal();
if (mApp.info != null && mApp.info.packageName != null) {
IncrementalStatesInfo incrementalStatesInfo =
packageManagerInternal.getIncrementalStatesInfo(
mApp.info.packageName, mApp.uid, mApp.userId);
if (incrementalStatesInfo != null) {
loadingProgress = incrementalStatesInfo.getProgress();
}
final String codePath = mApp.info.getCodePath();
if (IncrementalManager.isIncrementalPath(codePath)) {
// Report in the main log that the incremental package is still loading
Slog.e(TAG, "App ANR on incremental package " + mApp.info.packageName
+ " which is " + ((int) (loadingProgress * 100)) + "% loaded.");
final IBinder incrementalService = ServiceManager.getService(
Context.INCREMENTAL_SERVICE);
if (incrementalService != null) {
final IncrementalManager incrementalManager = new IncrementalManager(
IIncrementalService.Stub.asInterface(incrementalService));
incrementalMetrics = incrementalManager.getMetrics(codePath);
}
}
}
if (incrementalMetrics != null) {
// Report in the main log about the incremental package
info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n");
}
FrameworkStatsLog.write(FrameworkStatsLog.ANR_OCCURRED, mApp.uid, mApp.processName,
activityShortComponentName == null ? "unknown" : activityShortComponentName,
annotation,