Merge "[incremental] expose duration metrics to activity manager" into sc-dev
This commit is contained in:
@@ -421,6 +421,18 @@ public final class IncrementalManager {
|
||||
storage.unregisterStorageHealthListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metrics of an Incremental Storage.
|
||||
*/
|
||||
public IncrementalMetrics getMetrics(@NonNull String codePath) {
|
||||
final IncrementalStorage storage = openStorage(codePath);
|
||||
if (storage == null) {
|
||||
// storage does not exist, package not installed
|
||||
return null;
|
||||
}
|
||||
return new IncrementalMetrics(storage.getMetrics());
|
||||
}
|
||||
|
||||
/* Native methods */
|
||||
private static native boolean nativeIsEnabled();
|
||||
private static native boolean nativeIsV2Available();
|
||||
|
||||
39
core/java/android/os/incremental/IncrementalMetrics.java
Normal file
39
core/java/android/os/incremental/IncrementalMetrics.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os.incremental;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
/**
|
||||
* Provides methods to access metrics about an app installed via Incremental
|
||||
* @hide
|
||||
*/
|
||||
public class IncrementalMetrics {
|
||||
@NonNull private final PersistableBundle mData;
|
||||
|
||||
public IncrementalMetrics(@NonNull PersistableBundle data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Milliseconds between now and when the oldest pending read happened
|
||||
*/
|
||||
public long getMillisSinceOldestPendingRead() {
|
||||
return mData.getLong(IIncrementalService.METRICS_MILLIS_SINCE_OLDEST_PENDING_READ, -1);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.pm.DataLoaderParams;
|
||||
import android.content.pm.IDataLoaderStatusListener;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -601,4 +602,17 @@ public final class IncrementalStorage {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metrics of the current storage.
|
||||
* {@see IIncrementalService} for metrics keys.
|
||||
*/
|
||||
public PersistableBundle getMetrics() {
|
||||
try {
|
||||
return mService.getMetrics(mId);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.os.FactoryTest.FACTORY_TEST_OFF;
|
||||
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PROTO;
|
||||
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
|
||||
import static android.os.PowerWhitelistManager.REASON_SYSTEM_ALLOW_LISTED;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
|
||||
import static android.os.Process.BLUETOOTH_UID;
|
||||
@@ -273,6 +273,9 @@ import android.os.TransactionTooLargeException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.WorkSource;
|
||||
import android.os.incremental.IIncrementalService;
|
||||
import android.os.incremental.IncrementalManager;
|
||||
import android.os.incremental.IncrementalMetrics;
|
||||
import android.os.storage.IStorageManager;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.provider.DeviceConfig;
|
||||
@@ -7697,18 +7700,32 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
*/
|
||||
void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
|
||||
ApplicationErrorReport.CrashInfo crashInfo) {
|
||||
boolean isPackageLoading = false;
|
||||
boolean isIncremental = false;
|
||||
float loadingProgress = 1;
|
||||
long millisSinceOldestPendingRead = 0;
|
||||
// Notify package manager service to possibly update package state
|
||||
if (r != null && r.info != null && r.info.packageName != null) {
|
||||
final String codePath = r.info.getCodePath();
|
||||
mPackageManagerInt.notifyPackageCrashOrAnr(r.info.packageName);
|
||||
IncrementalStatesInfo incrementalStatesInfo =
|
||||
mPackageManagerInt.getIncrementalStatesInfo(r.info.packageName, r.uid,
|
||||
r.userId);
|
||||
isPackageLoading = incrementalStatesInfo.isLoading();
|
||||
if (isPackageLoading) {
|
||||
// Report in the main log that the package is still loading
|
||||
Slog.e(TAG, "App crashed when package " + r.info.packageName + " is "
|
||||
+ ((int) (incrementalStatesInfo.getProgress() * 100)) + "% loaded.");
|
||||
if (incrementalStatesInfo != null) {
|
||||
loadingProgress = incrementalStatesInfo.getProgress();
|
||||
}
|
||||
isIncremental = IncrementalManager.isIncrementalPath(codePath);
|
||||
if (isIncremental) {
|
||||
// Report in the main log about the incremental package
|
||||
Slog.e(TAG, "App crashed on incremental package " + r.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 metrics = incrementalManager.getMetrics(codePath);
|
||||
millisSinceOldestPendingRead = metrics.getMillisSinceOldestPendingRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7737,7 +7754,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
processName.equals("system_server") ? ServerProtoEnums.SYSTEM_SERVER
|
||||
: (r != null) ? r.getProcessClassEnum()
|
||||
: ServerProtoEnums.ERROR_SOURCE_UNKNOWN,
|
||||
isPackageLoading
|
||||
isIncremental, loadingProgress, millisSinceOldestPendingRead
|
||||
);
|
||||
|
||||
final int relaunchReason = r == null ? RELAUNCH_REASON_NONE
|
||||
|
||||
@@ -26,12 +26,18 @@ import android.app.AnrController;
|
||||
import android.app.ApplicationErrorReport;
|
||||
import android.app.ApplicationExitInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IncrementalStatesInfo;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.incremental.IIncrementalService;
|
||||
import android.os.incremental.IncrementalManager;
|
||||
import android.os.incremental.IncrementalMetrics;
|
||||
import android.provider.Settings;
|
||||
import android.util.EventLog;
|
||||
import android.util.Slog;
|
||||
@@ -294,14 +300,31 @@ class ProcessErrorStateRecord {
|
||||
}
|
||||
|
||||
// Check if package is still being loaded
|
||||
boolean isPackageLoading = false;
|
||||
boolean isIncremental = false;
|
||||
float loadingProgress = 1;
|
||||
long millisSinceOldestPendingRead = 0;
|
||||
final PackageManagerInternal packageManagerInternal = mService.getPackageManagerInternal();
|
||||
if (aInfo != null && aInfo.packageName != null) {
|
||||
IncrementalStatesInfo incrementalStatesInfo =
|
||||
packageManagerInternal.getIncrementalStatesInfo(
|
||||
aInfo.packageName, mApp.uid, mApp.userId);
|
||||
if (incrementalStatesInfo != null) {
|
||||
isPackageLoading = incrementalStatesInfo.isLoading();
|
||||
loadingProgress = incrementalStatesInfo.getProgress();
|
||||
}
|
||||
final String codePath = aInfo.getCodePath();
|
||||
isIncremental = IncrementalManager.isIncrementalPath(codePath);
|
||||
if (isIncremental) {
|
||||
// Report in the main log that the incremental package is still loading
|
||||
Slog.e(TAG, "App crashed on incremental package " + aInfo.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 metrics = incrementalManager.getMetrics(codePath);
|
||||
millisSinceOldestPendingRead = metrics.getMillisSinceOldestPendingRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,10 +345,8 @@ class ProcessErrorStateRecord {
|
||||
info.append("Parent: ").append(parentShortComponentName).append("\n");
|
||||
}
|
||||
|
||||
if (isPackageLoading) {
|
||||
// Report in the main log that the package is still loading
|
||||
final float loadingProgress = packageManagerInternal.getIncrementalStatesInfo(
|
||||
aInfo.packageName, mApp.uid, mApp.userId).getProgress();
|
||||
if (isIncremental) {
|
||||
// Report in the main log about the incremental package
|
||||
info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n");
|
||||
}
|
||||
|
||||
@@ -412,7 +433,8 @@ class ProcessErrorStateRecord {
|
||||
? FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
|
||||
: FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
|
||||
mApp.getProcessClassEnum(),
|
||||
(mApp.info != null) ? mApp.info.packageName : "", isPackageLoading);
|
||||
(mApp.info != null) ? mApp.info.packageName : "",
|
||||
isIncremental, loadingProgress, millisSinceOldestPendingRead);
|
||||
final ProcessRecord parentPr = parentProcess != null
|
||||
? (ProcessRecord) parentProcess.mOwner : null;
|
||||
mService.addErrorToDropBox("anr", mApp, mApp.processName, activityShortComponentName,
|
||||
|
||||
Reference in New Issue
Block a user