Merge "Add the process oom adj score prior to the activity start"
This commit is contained in:
@@ -497,6 +497,7 @@ final class ProcessStateRecord {
|
||||
@GuardedBy({"mService", "mProcLock"})
|
||||
void setCurAdj(int curAdj) {
|
||||
mCurAdj = curAdj;
|
||||
mApp.getWindowProcessController().setCurrentAdj(curAdj);
|
||||
}
|
||||
|
||||
@GuardedBy(anyOf = {"mService", "mProcLock"})
|
||||
|
||||
@@ -70,6 +70,7 @@ import static com.android.internal.util.FrameworkStatsLog.CAMERA_COMPAT_CONTROL_
|
||||
import static com.android.internal.util.FrameworkStatsLog.CAMERA_COMPAT_CONTROL_EVENT_REPORTED__EVENT__CLICKED_REVERT_TREATMENT;
|
||||
import static com.android.server.am.MemoryStatUtil.MemoryStat;
|
||||
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem;
|
||||
import static com.android.server.am.ProcessList.INVALID_ADJ;
|
||||
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_METRICS;
|
||||
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
|
||||
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
|
||||
@@ -277,6 +278,8 @@ class ActivityMetricsLogger {
|
||||
final boolean mProcessSwitch;
|
||||
/** The process state of the launching activity prior to the launch */
|
||||
final int mProcessState;
|
||||
/** The oom adj score of the launching activity prior to the launch */
|
||||
final int mProcessOomAdj;
|
||||
/** Whether the last launched activity has reported drawn. */
|
||||
boolean mIsDrawn;
|
||||
/** The latest activity to have been launched. */
|
||||
@@ -312,7 +315,7 @@ class ActivityMetricsLogger {
|
||||
@Nullable
|
||||
static TransitionInfo create(@NonNull ActivityRecord r,
|
||||
@NonNull LaunchingState launchingState, @Nullable ActivityOptions options,
|
||||
boolean processRunning, boolean processSwitch, int processState,
|
||||
boolean processRunning, boolean processSwitch, int processState, int processOomAdj,
|
||||
boolean newActivityCreated, int startResult) {
|
||||
if (startResult != START_SUCCESS && startResult != START_TASK_TO_FRONT) {
|
||||
return null;
|
||||
@@ -328,19 +331,20 @@ class ActivityMetricsLogger {
|
||||
transitionType = TYPE_TRANSITION_COLD_LAUNCH;
|
||||
}
|
||||
return new TransitionInfo(r, launchingState, options, transitionType, processRunning,
|
||||
processSwitch, processState);
|
||||
processSwitch, processState, processOomAdj);
|
||||
}
|
||||
|
||||
/** Use {@link TransitionInfo#create} instead to ensure the transition type is valid. */
|
||||
private TransitionInfo(ActivityRecord r, LaunchingState launchingState,
|
||||
ActivityOptions options, int transitionType, boolean processRunning,
|
||||
boolean processSwitch, int processState) {
|
||||
boolean processSwitch, int processState, int processOomAdj) {
|
||||
mLaunchingState = launchingState;
|
||||
mTransitionStartTimeNs = launchingState.mCurrentTransitionStartTimeNs;
|
||||
mTransitionType = transitionType;
|
||||
mProcessRunning = processRunning;
|
||||
mProcessSwitch = processSwitch;
|
||||
mProcessState = processState;
|
||||
mProcessOomAdj = processOomAdj;
|
||||
mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs;
|
||||
setLatestLaunchedActivity(r);
|
||||
// The launching state can be reused by consecutive launch. Its original association
|
||||
@@ -644,9 +648,15 @@ class ActivityMetricsLogger {
|
||||
// interesting.
|
||||
final boolean processSwitch = !processRunning
|
||||
|| !processRecord.hasStartedActivity(launchedActivity);
|
||||
final int processState = processRunning
|
||||
? processRecord.getCurrentProcState()
|
||||
: PROCESS_STATE_NONEXISTENT;
|
||||
final int processState;
|
||||
final int processOomAdj;
|
||||
if (processRunning) {
|
||||
processState = processRecord.getCurrentProcState();
|
||||
processOomAdj = processRecord.getCurrentAdj();
|
||||
} else {
|
||||
processState = PROCESS_STATE_NONEXISTENT;
|
||||
processOomAdj = INVALID_ADJ;
|
||||
}
|
||||
|
||||
final TransitionInfo info = launchingState.mAssociatedTransitionInfo;
|
||||
if (DEBUG_METRICS) {
|
||||
@@ -654,6 +664,7 @@ class ActivityMetricsLogger {
|
||||
+ " launchedActivity=" + launchedActivity + " processRunning=" + processRunning
|
||||
+ " processSwitch=" + processSwitch
|
||||
+ " processState=" + processState
|
||||
+ " processOomAdj=" + processOomAdj
|
||||
+ " newActivityCreated=" + newActivityCreated + " info=" + info);
|
||||
}
|
||||
|
||||
@@ -689,8 +700,8 @@ class ActivityMetricsLogger {
|
||||
}
|
||||
|
||||
final TransitionInfo newInfo = TransitionInfo.create(launchedActivity, launchingState,
|
||||
options, processRunning, processSwitch, processState, newActivityCreated,
|
||||
resultCode);
|
||||
options, processRunning, processSwitch, processState, processOomAdj,
|
||||
newActivityCreated, resultCode);
|
||||
if (newInfo == null) {
|
||||
abort(launchingState, "unrecognized launch");
|
||||
return;
|
||||
@@ -1006,8 +1017,10 @@ class ActivityMetricsLogger {
|
||||
final long uptime = info.mTransitionDeviceUptimeMs;
|
||||
final int transitionDelay = info.mCurrentTransitionDelayMs;
|
||||
final int processState = info.mProcessState;
|
||||
final int processOomAdj = info.mProcessOomAdj;
|
||||
mLoggerHandler.post(() -> logAppTransition(
|
||||
timestamp, uptime, transitionDelay, infoSnapshot, isHibernating, processState));
|
||||
timestamp, uptime, transitionDelay, infoSnapshot, isHibernating,
|
||||
processState, processOomAdj));
|
||||
}
|
||||
mLoggerHandler.post(() -> logAppDisplayed(infoSnapshot));
|
||||
if (info.mPendingFullyDrawn != null) {
|
||||
@@ -1020,7 +1033,7 @@ class ActivityMetricsLogger {
|
||||
// This gets called on another thread without holding the activity manager lock.
|
||||
private void logAppTransition(long transitionStartTimeNs, long transitionDeviceUptimeMs,
|
||||
int currentTransitionDelayMs, TransitionInfoSnapshot info, boolean isHibernating,
|
||||
int processState) {
|
||||
int processState, int processOomAdj) {
|
||||
final LogMaker builder = new LogMaker(APP_TRANSITION);
|
||||
builder.setPackageName(info.packageName);
|
||||
builder.setType(info.type);
|
||||
@@ -1087,7 +1100,8 @@ class ActivityMetricsLogger {
|
||||
isLoading,
|
||||
info.launchedActivityName.hashCode(),
|
||||
TimeUnit.NANOSECONDS.toMillis(transitionStartTimeNs),
|
||||
processState);
|
||||
processState,
|
||||
processOomAdj);
|
||||
|
||||
if (DEBUG_METRICS) {
|
||||
Slog.i(TAG, String.format("APP_START_OCCURRED(%s, %s, %s, %s, %s)",
|
||||
|
||||
@@ -27,6 +27,7 @@ import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
|
||||
|
||||
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION;
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
import static com.android.server.am.ProcessList.INVALID_ADJ;
|
||||
import static com.android.server.wm.ActivityRecord.State.DESTROYED;
|
||||
import static com.android.server.wm.ActivityRecord.State.DESTROYING;
|
||||
import static com.android.server.wm.ActivityRecord.State.PAUSED;
|
||||
@@ -125,6 +126,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
private volatile int mCurProcState = PROCESS_STATE_NONEXISTENT;
|
||||
// Last reported process state;
|
||||
private volatile int mRepProcState = PROCESS_STATE_NONEXISTENT;
|
||||
// Currently computed oom adj score
|
||||
private volatile int mCurAdj = INVALID_ADJ;
|
||||
// are we in the process of crashing?
|
||||
private volatile boolean mCrashing;
|
||||
// does the app have a not responding dialog?
|
||||
@@ -319,6 +322,14 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
return mCurProcState;
|
||||
}
|
||||
|
||||
public void setCurrentAdj(int curAdj) {
|
||||
mCurAdj = curAdj;
|
||||
}
|
||||
|
||||
int getCurrentAdj() {
|
||||
return mCurAdj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the computed process state from the oom adjustment calculation. This is frequently
|
||||
* called in activity manager's lock, so don't use window manager lock here.
|
||||
|
||||
Reference in New Issue
Block a user