Merge "Revert^2: Log the process hosting component types in ProcessMemorySnapshot" into udc-dev

This commit is contained in:
Jing Ji
2023-05-10 17:11:58 +00:00
committed by Android (Google) Code Review
8 changed files with 142 additions and 98 deletions

View File

@@ -16,6 +16,7 @@
package android.app; package android.app;
import android.annotation.IntDef;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -24,19 +25,132 @@ import android.os.Parcelable;
* {@hide} * {@hide}
*/ */
public final class ProcessMemoryState implements Parcelable { 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 uid;
public final int pid; public final int pid;
public final String processName; public final String processName;
public final int oomScore; public final int oomScore;
public final boolean hasForegroundServices; 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, public ProcessMemoryState(int uid, int pid, String processName, int oomScore,
boolean hasForegroundServices) { boolean hasForegroundServices, int hostingComponentTypes,
int historicalHostingComponentTypes) {
this.uid = uid; this.uid = uid;
this.pid = pid; this.pid = pid;
this.processName = processName; this.processName = processName;
this.oomScore = oomScore; this.oomScore = oomScore;
this.hasForegroundServices = hasForegroundServices; this.hasForegroundServices = hasForegroundServices;
this.mHostingComponentTypes = hostingComponentTypes;
this.mHistoricalHostingComponentTypes = historicalHostingComponentTypes;
} }
private ProcessMemoryState(Parcel in) { private ProcessMemoryState(Parcel in) {
@@ -45,6 +159,8 @@ public final class ProcessMemoryState implements Parcelable {
processName = in.readString(); processName = in.readString();
oomScore = in.readInt(); oomScore = in.readInt();
hasForegroundServices = in.readInt() == 1; hasForegroundServices = in.readInt() == 1;
mHostingComponentTypes = in.readInt();
mHistoricalHostingComponentTypes = in.readInt();
} }
public static final @android.annotation.NonNull Creator<ProcessMemoryState> CREATOR = new Creator<ProcessMemoryState>() { 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.writeString(processName);
parcel.writeInt(oomScore); parcel.writeInt(oomScore);
parcel.writeInt(hasForegroundServices ? 1 : 0); parcel.writeInt(hasForegroundServices ? 1 : 0);
parcel.writeInt(mHostingComponentTypes);
parcel.writeInt(mHistoricalHostingComponentTypes);
} }
} }

View File

@@ -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.ActivityManagerInternal.OOM_ADJ_REASON_UI_VISIBILITY;
import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.OP_NONE; 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.ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT;
import static android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES; import static android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES;
import static android.content.pm.PackageManager.MATCH_ALL; 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.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.MemoryStatUtil.hasMemcg; import static com.android.server.am.MemoryStatUtil.hasMemcg;
import static com.android.server.am.ProcessList.ProcStartHandler; 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.net.NetworkPolicyManagerInternal.updateBlockedReasonsWithProcState;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND; 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); final ProcessRecord r = mPidsSelfLocked.valueAt(i);
processMemoryStates.add(new ProcessMemoryState( processMemoryStates.add(new ProcessMemoryState(
r.uid, r.getPid(), r.processName, r.mState.getCurAdj(), r.uid, r.getPid(), r.processName, r.mState.getCurAdj(),
r.mServices.hasForegroundServices())); r.mServices.hasForegroundServices(),
r.mProfile.getCurrentHostingComponentTypes(),
r.mProfile.getHistoricalHostingComponentTypes()));
} }
} }
return processMemoryStates; return processMemoryStates;

View File

@@ -18,6 +18,7 @@ package com.android.server.am;
import static android.Manifest.permission.GET_ANY_PROVIDER_TYPE; 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_GET_PROVIDER;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_REMOVE_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.content.ContentProvider.isAuthorityRedirectedForCloneProfile;
import static android.os.Process.PROC_CHAR; import static android.os.Process.PROC_CHAR;
import static android.os.Process.PROC_OUT_LONG; 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.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.ActivityManagerDebugConfig.DEBUG_MU;
import static com.android.server.am.ActivityManagerService.TAG_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.Nullable;
import android.annotation.UserIdInt; import android.annotation.UserIdInt;

View File

@@ -17,9 +17,10 @@
package com.android.server.am; package com.android.server.am;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; 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.IApplicationThread;
import android.app.ProcessMemoryState.HostingComponentType;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.os.Debug; import android.os.Debug;
import android.os.SystemClock; import android.os.SystemClock;
@@ -42,88 +43,6 @@ import java.util.concurrent.atomic.AtomicLong;
* Profiling info of the process, such as PSS, cpu, etc. * Profiling info of the process, such as PSS, cpu, etc.
*/ */
final class ProcessProfileRecord { 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; final ProcessRecord mApp;
private final ActivityManagerService mService; private final ActivityManagerService mService;

View File

@@ -16,8 +16,8 @@
package com.android.server.am; package com.android.server.am;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; import static android.app.ProcessMemoryState.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_FOREGROUND_SERVICE;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.Context; import android.content.Context;

View File

@@ -19,11 +19,11 @@ package com.android.server.am;
import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE; import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_UI_VISIBILITY; 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.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 static com.android.server.am.ProcessRecord.TAG;
import android.annotation.ElapsedRealtimeLong; import android.annotation.ElapsedRealtimeLong;

View File

@@ -18,6 +18,7 @@ package com.android.server.am;
import static android.app.PendingIntent.FLAG_IMMUTABLE; import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; 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.PowerExemptionManager.REASON_DENIED;
import static android.os.Process.INVALID_UID; 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.DEBUG_FOREGROUND_SERVICE;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; 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.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BOUND_SERVICE;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;

View File

@@ -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_SELF;
import static android.app.AppOpsManager.OP_FLAG_TRUSTED_PROXIED; 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.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS;
import static android.hardware.display.HdrConversionMode.HDR_CONVERSION_PASSTHROUGH; 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.rssInKilobytes, snapshot.anonRssInKilobytes, snapshot.swapInKilobytes,
snapshot.anonRssInKilobytes + snapshot.swapInKilobytes, snapshot.anonRssInKilobytes + snapshot.swapInKilobytes,
gpuMemPerPid.get(managedProcess.pid), managedProcess.hasForegroundServices, 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 // 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 // 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.rssInKilobytes, snapshot.anonRssInKilobytes, snapshot.swapInKilobytes,
snapshot.anonRssInKilobytes + snapshot.swapInKilobytes, snapshot.anonRssInKilobytes + snapshot.swapInKilobytes,
gpuMemPerPid.get(pid), false /* has_foreground_services */, 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; return StatsManager.PULL_SUCCESS;
} }