Merge "Only collect PSS one time after an app has been frozen."

This commit is contained in:
Mark Fasheh
2022-11-17 20:49:30 +00:00
committed by Android (Google) Code Review
3 changed files with 35 additions and 5 deletions

View File

@@ -506,10 +506,14 @@ public class AppProfiler {
}
if (profile != null) {
long startTime = SystemClock.currentThreadTimeMillis();
// skip background PSS calculation of apps that are capturing
// camera imagery
final boolean usingCamera = mService.isCameraActiveForUid(profile.mApp.uid);
long pss = usingCamera ? 0 : Debug.getPss(pid, tmp, null);
// skip background PSS calculation under the following situations:
// - app is capturing camera imagery
// - app is frozen and we have already collected PSS once.
final boolean skipPSSCollection =
(profile.mApp.mOptRecord != null
&& profile.mApp.mOptRecord.skipPSSCollectionBecauseFrozen())
|| mService.isCameraActiveForUid(profile.mApp.uid);
long pss = skipPSSCollection ? 0 : Debug.getPss(pid, tmp, null);
long endTime = SystemClock.currentThreadTimeMillis();
synchronized (mProfilerLock) {
if (pss != 0 && profile.getThread() != null
@@ -524,7 +528,7 @@ public class AppProfiler {
if (DEBUG_PSS) {
Slog.d(TAG_PSS, "Skipped pss collection of " + pid
+ ": " + (profile.getThread() == null ? "NO_THREAD " : "")
+ (usingCamera ? "CAMERA " : "")
+ (skipPSSCollection ? "SKIP_PSS_COLLECTION " : "")
+ (profile.getPid() != pid ? "PID_CHANGED " : "")
+ " initState=" + procState + " curState="
+ profile.getSetProcState() + " "

View File

@@ -2004,6 +2004,7 @@ public final class CachedAppOptimizer {
opt.setFreezeUnfreezeTime(SystemClock.uptimeMillis());
opt.setFrozen(true);
opt.setHasCollectedFrozenPSS(false);
mFrozenProcesses.put(pid, proc);
} catch (Exception e) {
Slog.w(TAG_AM, "Unable to freeze " + pid + " " + name);

View File

@@ -72,6 +72,12 @@ final class ProcessCachedOptimizerRecord {
@GuardedBy("mProcLock")
private boolean mFrozen;
/**
* Set to false after the process has been frozen.
* Set to true after we have collected PSS for the frozen process.
*/
private boolean mHasCollectedFrozenPSS;
/**
* An override on the freeze state is in progress.
*/
@@ -188,6 +194,25 @@ final class ProcessCachedOptimizerRecord {
mFrozen = frozen;
}
boolean skipPSSCollectionBecauseFrozen() {
boolean collected = mHasCollectedFrozenPSS;
// This check is racy but it isn't critical to PSS collection that we have the most up to
// date idea of whether a task is frozen.
if (!mFrozen) {
// not frozen == always ask to collect PSS
return false;
}
// We don't want to count PSS for a frozen process more than once.
mHasCollectedFrozenPSS = true;
return collected;
}
void setHasCollectedFrozenPSS(boolean collected) {
mHasCollectedFrozenPSS = collected;
}
@GuardedBy("mProcLock")
boolean hasFreezerOverride() {
return mFreezerOverride;