Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 800a3c47 authored by Kevin Jeon's avatar Kevin Jeon
Browse files

Add a global setting for forcing PSS collection

The flag for replacing PSS collection in AppProfiler with RSS will make
numbers in the "Memory use" UI in developer settings incorrect, as the
numbers presented there are gathered from AppProfiler. This change adds
a global setting that can be toggled from that page to resume collecting
PSS information.

Test: Build+flash, verify using test logs that PSS is collected in
      AppProfiler instead of RSS when the new toggle in Settings is
      enabled while the flag is enabled.
Bug: 296454553
Change-Id: Ic821a6fc9dbb6bd2c1a5d2c66805d8e9be70fae7
parent 0a2ebeab
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -14964,6 +14964,16 @@ public final class Settings {
        public static final String FOREGROUND_SERVICE_STARTS_LOGGING_ENABLED =
                "foreground_service_starts_logging_enabled";
        /**
         * Describes whether AM's AppProfiler should collect PSS even if RSS is the default. This
         * can be set by a user in developer settings.
         * Default: 0
         * @hide
         */
        @Readable
        public static final String FORCE_ENABLE_PSS_PROFILING =
                "force_enable_pss_profiling";
        /**
         * @hide
         * @see com.android.server.appbinding.AppBindingConstants
+1 −0
Original line number Diff line number Diff line
@@ -112,5 +112,6 @@ public class GlobalSettings {
        Settings.Global.Wearable.SCREENSHOT_ENABLED,
        Settings.Global.Wearable.SCREEN_UNLOCK_SOUND_ENABLED,
        Settings.Global.Wearable.CHARGING_SOUNDS_ENABLED,
        Settings.Global.FORCE_ENABLE_PSS_PROFILING,
    };
}
+1 −0
Original line number Diff line number Diff line
@@ -446,5 +446,6 @@ public class GlobalSettingsValidators {
        VALIDATORS.put(Global.Wearable.WEAR_LAUNCHER_UI_MODE, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(Global.Wearable.WEAR_POWER_ANOMALY_SERVICE_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Global.Wearable.CONNECTIVITY_KEEP_DATA_ON, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Global.FORCE_ENABLE_PSS_PROFILING, BOOLEAN_VALIDATOR);
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -629,6 +629,10 @@ final class ActivityManagerConstants extends ContentObserver {
    // foreground service background start restriction.
    volatile boolean mFgsStartRestrictionNotificationEnabled = false;

    // Indicates whether PSS profiling in AppProfiler is force-enabled, even if RSS is used by
    // default. Controlled by Settings.Global.FORCE_ENABLE_PSS_PROFILING
    volatile boolean mForceEnablePssProfiling = false;

    /**
     * Indicates whether the foreground service background start restriction is enabled for
     * caller app that is targeting S+.
@@ -958,6 +962,9 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final Uri ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI =
            Settings.Global.getUriFor(Settings.Global.ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS);

    private static final Uri FORCE_ENABLE_PSS_PROFILING_URI =
            Settings.Global.getUriFor(Settings.Global.FORCE_ENABLE_PSS_PROFILING);

    /**
     * The threshold to decide if a given association should be dumped into metrics.
     */
@@ -1368,6 +1375,7 @@ final class ActivityManagerConstants extends ContentObserver {
            mResolver.registerContentObserver(ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI,
                    false, this);
        }
        mResolver.registerContentObserver(FORCE_ENABLE_PSS_PROFILING_URI, false, this);
        updateConstants();
        if (mSystemServerAutomaticHeapDumpEnabled) {
            updateEnableAutomaticSystemServerHeapDumps();
@@ -1383,6 +1391,7 @@ final class ActivityManagerConstants extends ContentObserver {
        // The following read from Settings.
        updateActivityStartsLoggingEnabled();
        updateForegroundServiceStartsLoggingEnabled();
        updateForceEnablePssProfiling();
        // Read DropboxRateLimiter params from flags.
        mService.initDropboxRateLimiter();
    }
@@ -1424,6 +1433,8 @@ final class ActivityManagerConstants extends ContentObserver {
            updateForegroundServiceStartsLoggingEnabled();
        } else if (ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI.equals(uri)) {
            updateEnableAutomaticSystemServerHeapDumps();
        } else if (FORCE_ENABLE_PSS_PROFILING_URI.equals(uri)) {
            updateForceEnablePssProfiling();
        }
    }

@@ -1536,6 +1547,11 @@ final class ActivityManagerConstants extends ContentObserver {
                Settings.Global.ACTIVITY_STARTS_LOGGING_ENABLED, 1) == 1;
    }

    private void updateForceEnablePssProfiling() {
        mForceEnablePssProfiling = Settings.Global.getInt(mResolver,
                Settings.Global.FORCE_ENABLE_PSS_PROFILING, 0) == 1;
    }

    private void updateBackgroundActivityStarts() {
        mFlagBackgroundActivityStartsEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+4 −5
Original line number Diff line number Diff line
@@ -326,7 +326,6 @@ import android.os.Debug;
import android.os.DropBoxManager;
import android.os.FactoryTest;
import android.os.FileUtils;
import android.os.Flags;
import android.os.Handler;
import android.os.IBinder;
import android.os.IDeviceIdentifiersPolicyService;
@@ -8563,7 +8562,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        final long initialIdlePssOrRss, lastPssOrRss, lastSwapPss;
                        synchronized (mAppProfiler.mProfilerLock) {
                            initialIdlePssOrRss = pr.getInitialIdlePssOrRss();
                            lastPssOrRss = !Flags.removeAppProfilerPssCollection()
                            lastPssOrRss = mAppProfiler.isProfilingPss()
                                    ? pr.getLastPss() : pr.getLastRss();
                            lastSwapPss = pr.getLastSwapPss();
                        }
@@ -8573,14 +8572,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                            final StringBuilder sb2 = new StringBuilder(128);
                            sb2.append("Kill");
                            sb2.append(proc.processName);
                            if (!Flags.removeAppProfilerPssCollection()) {
                            if (mAppProfiler.isProfilingPss()) {
                                sb2.append(" in idle maint: pss=");
                            } else {
                                sb2.append(" in idle maint: rss=");
                            }
                            sb2.append(lastPssOrRss);
                            if (!Flags.removeAppProfilerPssCollection()) {
                            if (mAppProfiler.isProfilingPss()) {
                                sb2.append(", swapPss=");
                                sb2.append(lastSwapPss);
                                sb2.append(", initialPss=");
@@ -8595,7 +8594,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                            Slog.wtfQuiet(TAG, sb2.toString());
                            mHandler.post(() -> {
                                synchronized (ActivityManagerService.this) {
                                    proc.killLocked(!Flags.removeAppProfilerPssCollection()
                                    proc.killLocked(mAppProfiler.isProfilingPss()
                                            ? "idle maint (pss " : "idle maint (rss " + lastPssOrRss
                                            + " from " + initialIdlePssOrRss + ")",
                                            ApplicationExitInfo.REASON_OTHER,
Loading