diff options
| author | 2023-05-09 04:45:39 +0000 | |
|---|---|---|
| committer | 2023-05-09 04:45:39 +0000 | |
| commit | a571b3d55742df5825b2d92e54909575c98496f4 (patch) | |
| tree | c87af69455f6f339200f859d9ba0b1b265182ba3 | |
| parent | 6db854c14e557310bddaa924f4b6eb0e8ceccea5 (diff) | |
| parent | 0284653ef86edf0cdf37a7f1f26e9c692a820291 (diff) | |
Merge "Log the process hosting component types in ProcessMemorySnapshot" into udc-dev
8 files changed, 142 insertions, 98 deletions
diff --git a/core/java/android/app/ProcessMemoryState.java b/core/java/android/app/ProcessMemoryState.java index 2c58603ecdb9..c4caa4512acc 100644 --- a/core/java/android/app/ProcessMemoryState.java +++ b/core/java/android/app/ProcessMemoryState.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.IntDef; import android.os.Parcel; import android.os.Parcelable; @@ -24,19 +25,132 @@ import android.os.Parcelable; * {@hide} */ public final class ProcessMemoryState implements Parcelable { + /** + * The type of the component this process is hosting; + * this means not hosting any components (cached). + */ + public static final int HOSTING_COMPONENT_TYPE_EMPTY = + AppProtoEnums.HOSTING_COMPONENT_TYPE_EMPTY; + + /** + * The type of the component this process is hosting; + * this means it's a system process. + */ + public static final int HOSTING_COMPONENT_TYPE_SYSTEM = + AppProtoEnums.HOSTING_COMPONENT_TYPE_SYSTEM; + + /** + * The type of the component this process is hosting; + * this means it's a persistent process. + */ + public static final int HOSTING_COMPONENT_TYPE_PERSISTENT = + AppProtoEnums.HOSTING_COMPONENT_TYPE_PERSISTENT; + + /** + * The type of the component this process is hosting; + * this means it's hosting a backup/restore agent. + */ + public static final int HOSTING_COMPONENT_TYPE_BACKUP = + AppProtoEnums.HOSTING_COMPONENT_TYPE_BACKUP; + + /** + * The type of the component this process is hosting; + * this means it's hosting an instrumentation. + */ + public static final int HOSTING_COMPONENT_TYPE_INSTRUMENTATION = + AppProtoEnums.HOSTING_COMPONENT_TYPE_INSTRUMENTATION; + + /** + * The type of the component this process is hosting; + * this means it's hosting an activity. + */ + public static final int HOSTING_COMPONENT_TYPE_ACTIVITY = + AppProtoEnums.HOSTING_COMPONENT_TYPE_ACTIVITY; + + /** + * The type of the component this process is hosting; + * this means it's hosting a broadcast receiver. + */ + public static final int HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER = + AppProtoEnums.HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER; + + /** + * The type of the component this process is hosting; + * this means it's hosting a content provider. + */ + public static final int HOSTING_COMPONENT_TYPE_PROVIDER = + AppProtoEnums.HOSTING_COMPONENT_TYPE_PROVIDER; + + /** + * The type of the component this process is hosting; + * this means it's hosting a started service. + */ + public static final int HOSTING_COMPONENT_TYPE_STARTED_SERVICE = + AppProtoEnums.HOSTING_COMPONENT_TYPE_STARTED_SERVICE; + + /** + * The type of the component this process is hosting; + * this means it's hosting a foreground service. + */ + public static final int HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE = + AppProtoEnums.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE; + + /** + * The type of the component this process is hosting; + * this means it's being bound via a service binding. + */ + public static final int HOSTING_COMPONENT_TYPE_BOUND_SERVICE = + AppProtoEnums.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; + + /** + * The type of the component this process is hosting. + * @hide + */ + @IntDef(flag = true, prefix = { "HOSTING_COMPONENT_TYPE_" }, value = { + HOSTING_COMPONENT_TYPE_EMPTY, + HOSTING_COMPONENT_TYPE_SYSTEM, + HOSTING_COMPONENT_TYPE_PERSISTENT, + HOSTING_COMPONENT_TYPE_BACKUP, + HOSTING_COMPONENT_TYPE_INSTRUMENTATION, + HOSTING_COMPONENT_TYPE_ACTIVITY, + HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER, + HOSTING_COMPONENT_TYPE_PROVIDER, + HOSTING_COMPONENT_TYPE_STARTED_SERVICE, + HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE, + HOSTING_COMPONENT_TYPE_BOUND_SERVICE, + }) + public @interface HostingComponentType {} + public final int uid; public final int pid; public final String processName; public final int oomScore; public final boolean hasForegroundServices; + /** + * The types of the components this process is hosting at the moment this snapshot is taken. + * + * Its value is the combination of {@link HostingComponentType}. + */ + public final int mHostingComponentTypes; + + /** + * The historical types of the components this process is or was hosting since it's born. + * + * Its value is the combination of {@link HostingComponentType}. + */ + public final int mHistoricalHostingComponentTypes; + public ProcessMemoryState(int uid, int pid, String processName, int oomScore, - boolean hasForegroundServices) { + boolean hasForegroundServices, int hostingComponentTypes, + int historicalHostingComponentTypes) { this.uid = uid; this.pid = pid; this.processName = processName; this.oomScore = oomScore; this.hasForegroundServices = hasForegroundServices; + this.mHostingComponentTypes = hostingComponentTypes; + this.mHistoricalHostingComponentTypes = historicalHostingComponentTypes; } private ProcessMemoryState(Parcel in) { @@ -45,6 +159,8 @@ public final class ProcessMemoryState implements Parcelable { processName = in.readString(); oomScore = in.readInt(); hasForegroundServices = in.readInt() == 1; + mHostingComponentTypes = in.readInt(); + mHistoricalHostingComponentTypes = in.readInt(); } public static final @android.annotation.NonNull Creator<ProcessMemoryState> CREATOR = new Creator<ProcessMemoryState>() { @@ -71,5 +187,7 @@ public final class ProcessMemoryState implements Parcelable { parcel.writeString(processName); parcel.writeInt(oomScore); parcel.writeInt(hasForegroundServices ? 1 : 0); + parcel.writeInt(mHostingComponentTypes); + parcel.writeInt(mHistoricalHostingComponentTypes); } } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index a4cd2780bec6..9514572e3b01 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -53,6 +53,10 @@ import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_SYSTEM_INIT; import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_UI_VISIBILITY; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.OP_NONE; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BACKUP; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_INSTRUMENTATION; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_PERSISTENT; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_SYSTEM; import static android.content.pm.ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT; import static android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES; import static android.content.pm.PackageManager.MATCH_ALL; @@ -158,10 +162,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.am.MemoryStatUtil.hasMemcg; import static com.android.server.am.ProcessList.ProcStartHandler; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BACKUP; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_INSTRUMENTATION; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_PERSISTENT; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_SYSTEM; import static com.android.server.net.NetworkPolicyManagerInternal.updateBlockedReasonsWithProcState; import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND; @@ -17696,7 +17696,9 @@ public class ActivityManagerService extends IActivityManager.Stub final ProcessRecord r = mPidsSelfLocked.valueAt(i); processMemoryStates.add(new ProcessMemoryState( r.uid, r.getPid(), r.processName, r.mState.getCurAdj(), - r.mServices.hasForegroundServices())); + r.mServices.hasForegroundServices(), + r.mProfile.getCurrentHostingComponentTypes(), + r.mProfile.getHistoricalHostingComponentTypes())); } } return processMemoryStates; diff --git a/services/core/java/com/android/server/am/ContentProviderHelper.java b/services/core/java/com/android/server/am/ContentProviderHelper.java index 6015e5f02221..e744eee8b485 100644 --- a/services/core/java/com/android/server/am/ContentProviderHelper.java +++ b/services/core/java/com/android/server/am/ContentProviderHelper.java @@ -18,6 +18,7 @@ package com.android.server.am; import static android.Manifest.permission.GET_ANY_PROVIDER_TYPE; import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_GET_PROVIDER; import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_REMOVE_PROVIDER; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_PROVIDER; import static android.content.ContentProvider.isAuthorityRedirectedForCloneProfile; import static android.os.Process.PROC_CHAR; import static android.os.Process.PROC_OUT_LONG; @@ -34,7 +35,6 @@ import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_E import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU; import static com.android.server.am.ActivityManagerService.TAG_MU; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_PROVIDER; import android.annotation.Nullable; import android.annotation.UserIdInt; diff --git a/services/core/java/com/android/server/am/ProcessProfileRecord.java b/services/core/java/com/android/server/am/ProcessProfileRecord.java index 4c15308a574e..5ad49a47a012 100644 --- a/services/core/java/com/android/server/am/ProcessProfileRecord.java +++ b/services/core/java/com/android/server/am/ProcessProfileRecord.java @@ -17,9 +17,10 @@ package com.android.server.am; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_EMPTY; -import android.annotation.IntDef; import android.app.IApplicationThread; +import android.app.ProcessMemoryState.HostingComponentType; import android.content.pm.ApplicationInfo; import android.os.Debug; import android.os.SystemClock; @@ -42,88 +43,6 @@ import java.util.concurrent.atomic.AtomicLong; * Profiling info of the process, such as PSS, cpu, etc. */ final class ProcessProfileRecord { - // Keep below types in sync with the HostingComponentType in the atoms.proto. - /** - * The type of the component this process is hosting; - * this means not hosting any components (cached). - */ - static final int HOSTING_COMPONENT_TYPE_EMPTY = 0x0; - - /** - * The type of the component this process is hosting; - * this means it's a system process. - */ - static final int HOSTING_COMPONENT_TYPE_SYSTEM = 0x00000001; - - /** - * The type of the component this process is hosting; - * this means it's a persistent process. - */ - static final int HOSTING_COMPONENT_TYPE_PERSISTENT = 0x00000002; - - /** - * The type of the component this process is hosting; - * this means it's hosting a backup/restore agent. - */ - static final int HOSTING_COMPONENT_TYPE_BACKUP = 0x00000004; - - /** - * The type of the component this process is hosting; - * this means it's hosting an instrumentation. - */ - static final int HOSTING_COMPONENT_TYPE_INSTRUMENTATION = 0x00000008; - - /** - * The type of the component this process is hosting; - * this means it's hosting an activity. - */ - static final int HOSTING_COMPONENT_TYPE_ACTIVITY = 0x00000010; - - /** - * The type of the component this process is hosting; - * this means it's hosting a broadcast receiver. - */ - static final int HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER = 0x00000020; - - /** - * The type of the component this process is hosting; - * this means it's hosting a content provider. - */ - static final int HOSTING_COMPONENT_TYPE_PROVIDER = 0x00000040; - - /** - * The type of the component this process is hosting; - * this means it's hosting a started service. - */ - static final int HOSTING_COMPONENT_TYPE_STARTED_SERVICE = 0x00000080; - - /** - * The type of the component this process is hosting; - * this means it's hosting a foreground service. - */ - static final int HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE = 0x00000100; - - /** - * The type of the component this process is hosting; - * this means it's being bound via a service binding. - */ - static final int HOSTING_COMPONENT_TYPE_BOUND_SERVICE = 0x00000200; - - @IntDef(flag = true, prefix = { "HOSTING_COMPONENT_TYPE_" }, value = { - HOSTING_COMPONENT_TYPE_EMPTY, - HOSTING_COMPONENT_TYPE_SYSTEM, - HOSTING_COMPONENT_TYPE_PERSISTENT, - HOSTING_COMPONENT_TYPE_BACKUP, - HOSTING_COMPONENT_TYPE_INSTRUMENTATION, - HOSTING_COMPONENT_TYPE_ACTIVITY, - HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER, - HOSTING_COMPONENT_TYPE_PROVIDER, - HOSTING_COMPONENT_TYPE_STARTED_SERVICE, - HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE, - HOSTING_COMPONENT_TYPE_BOUND_SERVICE, - }) - @interface HostingComponentType {} - final ProcessRecord mApp; private final ActivityManagerService mService; diff --git a/services/core/java/com/android/server/am/ProcessServiceRecord.java b/services/core/java/com/android/server/am/ProcessServiceRecord.java index 53fa4f1b2ac2..81d0b6ac700b 100644 --- a/services/core/java/com/android/server/am/ProcessServiceRecord.java +++ b/services/core/java/com/android/server/am/ProcessServiceRecord.java @@ -16,8 +16,8 @@ package com.android.server.am; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE; import android.app.ActivityManager; import android.content.Context; diff --git a/services/core/java/com/android/server/am/ProcessStateRecord.java b/services/core/java/com/android/server/am/ProcessStateRecord.java index ab71acd5f21d..db341d253818 100644 --- a/services/core/java/com/android/server/am/ProcessStateRecord.java +++ b/services/core/java/com/android/server/am/ProcessStateRecord.java @@ -19,11 +19,11 @@ package com.android.server.am; import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_UI_VISIBILITY; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_ACTIVITY; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_STARTED_SERVICE; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_OOM_ADJ; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_ACTIVITY; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_STARTED_SERVICE; import static com.android.server.am.ProcessRecord.TAG; import android.annotation.ElapsedRealtimeLong; diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 6551db9ad783..b22ece30c386 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -18,6 +18,7 @@ package com.android.server.am; import static android.app.PendingIntent.FLAG_IMMUTABLE; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; +import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; import static android.os.PowerExemptionManager.REASON_DENIED; import static android.os.Process.INVALID_UID; @@ -25,7 +26,6 @@ import static com.android.internal.util.Preconditions.checkArgument; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOREGROUND_SERVICE; import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; import android.annotation.NonNull; import android.annotation.Nullable; diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java index 6eded1a14dbf..e82521584731 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -18,6 +18,7 @@ package com.android.server.stats.pull; import static android.app.AppOpsManager.OP_FLAG_SELF; import static android.app.AppOpsManager.OP_FLAG_TRUSTED_PROXIED; +import static android.app.AppProtoEnums.HOSTING_COMPONENT_TYPE_EMPTY; import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; import static android.hardware.display.HdrConversionMode.HDR_CONVERSION_PASSTHROUGH; @@ -2350,7 +2351,8 @@ public class StatsPullAtomService extends SystemService { snapshot.rssInKilobytes, snapshot.anonRssInKilobytes, snapshot.swapInKilobytes, snapshot.anonRssInKilobytes + snapshot.swapInKilobytes, gpuMemPerPid.get(managedProcess.pid), managedProcess.hasForegroundServices, - snapshot.rssShmemKilobytes)); + snapshot.rssShmemKilobytes, managedProcess.mHostingComponentTypes, + managedProcess.mHistoricalHostingComponentTypes)); } // Complement the data with native system processes. Given these measurements can be taken // in response to LMKs happening, we want to first collect the managed app stats (to @@ -2370,7 +2372,10 @@ public class StatsPullAtomService extends SystemService { snapshot.rssInKilobytes, snapshot.anonRssInKilobytes, snapshot.swapInKilobytes, snapshot.anonRssInKilobytes + snapshot.swapInKilobytes, gpuMemPerPid.get(pid), false /* has_foreground_services */, - snapshot.rssShmemKilobytes)); + snapshot.rssShmemKilobytes, + // Native processes don't really have a hosting component type. + HOSTING_COMPONENT_TYPE_EMPTY, + HOSTING_COMPONENT_TYPE_EMPTY)); } return StatsManager.PULL_SUCCESS; } |