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

Commit cd734679 authored by Kevin Jeon's avatar Kevin Jeon
Browse files

Add collectRssInBackground()

This change adds collectRssInBackground() and recordRssSampleLPf(),
which are intended to be drop-in replacements for their less-efficient
PSS counterparts. These methods are only used if the
removeAppProfilerPssCollection flag is enabled.

In general, references to PSS have been kept in places where they can
apply to RSS without much friction (e.g. getLastPssTime). In places
where PSS was actually recorded for use, method names were renamed to
include "OrRss" (e.g. getInitialIdlePss -> getInitialIdlePssOrRss).

If an app has set a PSS threshold for collecting a heap dump using
ActivityManager.setWatchHeapLimit(), Debug.getPss() is called if the
build is debug or the app is debuggable. This is done _in addition_ to
the RSS read, but should be a relatively small cost compared to the
decrease in PSS reads overall.

The threshold for downgrading a service to a service B in OomAdjuster
is increased by a default 1.5 when the flag is enabled to account for
RSS > PSS. This value can be updated in device-specific configs, or on
the command line with:
device_config put activity_manager pss_to_rss_threshold_modifier <value>

This flag is still disabled, so this change will have no effect once
submitted. However, before the flag is flipped on in any capacity, we
should notify android-chatty that the PSS info in logs/dumps will
change in case these are being read for dashboards/metrics/etc.

Lastly, reportCachedKill() has been removed from ProcessProfileRecord
and ProcessState because while they seem to report AppProfiler-collected
PSS to WW, they are actually unused.

Test: - Check with test logs that collectRssInBackground() is called
        when the feature flag is enabled.
      - Check that device_config put activity_manager
	pss_to_rss_threshold_modifier <value> propagates to AM.
Bug: 296454553
Change-Id: Ia4c4e14d7fb116e75857ea92c9fa2d2f534355f1
parent 03c93942
Loading
Loading
Loading
Loading
+0 −12
Original line number Original line Diff line number Diff line
@@ -690,18 +690,6 @@ public final class ProcessState {
        }
        }
    }
    }


    public void reportCachedKill(ArrayMap<String, ProcessStateHolder> pkgList, long pss) {
        ensureNotDead();
        mCommonProcess.addCachedKill(1, pss, pss, pss);
        if (!mCommonProcess.mMultiPackage) {
            return;
        }

        for (int ip=pkgList.size()-1; ip>=0; ip--) {
            pullFixedProc(pkgList, ip).addCachedKill(1, pss, pss, pss);
        }
    }

    public ProcessState pullFixedProc(String pkgName) {
    public ProcessState pullFixedProc(String pkgName) {
        if (mMultiPackage) {
        if (mMultiPackage) {
            // The array map is still pointing to a common process state
            // The array map is still pointing to a common process state
+4 −0
Original line number Original line Diff line number Diff line
@@ -6806,6 +6806,10 @@
    <!-- Whether or not ActivityManager PSS profiling is disabled. -->
    <!-- Whether or not ActivityManager PSS profiling is disabled. -->
    <bool name="config_am_disablePssProfiling">false</bool>
    <bool name="config_am_disablePssProfiling">false</bool>


    <!-- The modifier used to adjust AM's PSS threshold for downgrading services to service B if
         RSS is being collected instead. -->
    <item name="config_am_pssToRssThresholdModifier" format="float" type="dimen">1.5</item>

    <!-- Whether unlocking and waking a device are sequenced -->
    <!-- Whether unlocking and waking a device are sequenced -->
    <bool name="config_orderUnlockAndWake">false</bool>
    <bool name="config_orderUnlockAndWake">false</bool>


+1 −0
Original line number Original line Diff line number Diff line
@@ -5262,6 +5262,7 @@


  <!-- For ActivityManager PSS profiling configurability -->
  <!-- For ActivityManager PSS profiling configurability -->
  <java-symbol type="bool" name="config_am_disablePssProfiling" />
  <java-symbol type="bool" name="config_am_disablePssProfiling" />
  <java-symbol type="dimen" name="config_am_pssToRssThresholdModifier" />


  <java-symbol type="raw" name="default_ringtone_vibration_effect" />
  <java-symbol type="raw" name="default_ringtone_vibration_effect" />


+26 −0
Original line number Original line Diff line number Diff line
@@ -1076,6 +1076,16 @@ final class ActivityManagerConstants extends ContentObserver {


    public boolean APP_PROFILER_PSS_PROFILING_DISABLED;
    public boolean APP_PROFILER_PSS_PROFILING_DISABLED;


    /**
     * The modifier used to adjust PSS thresholds in OomAdjuster when RSS is collected instead.
     */
    static final String KEY_PSS_TO_RSS_THRESHOLD_MODIFIER =
            "pss_to_rss_threshold_modifier";

    private final float mDefaultPssToRssThresholdModifier;

    public float PSS_TO_RSS_THRESHOLD_MODIFIER;

    private final OnPropertiesChangedListener mOnDeviceConfigChangedListener =
    private final OnPropertiesChangedListener mOnDeviceConfigChangedListener =
            new OnPropertiesChangedListener() {
            new OnPropertiesChangedListener() {
                @Override
                @Override
@@ -1254,6 +1264,9 @@ final class ActivityManagerConstants extends ContentObserver {
                            case KEY_DISABLE_APP_PROFILER_PSS_PROFILING:
                            case KEY_DISABLE_APP_PROFILER_PSS_PROFILING:
                                updateDisableAppProfilerPssProfiling();
                                updateDisableAppProfilerPssProfiling();
                                break;
                                break;
                            case KEY_PSS_TO_RSS_THRESHOLD_MODIFIER:
                                updatePssToRssThresholdModifier();
                                break;
                            default:
                            default:
                                updateFGSPermissionEnforcementFlagsIfNecessary(name);
                                updateFGSPermissionEnforcementFlagsIfNecessary(name);
                                break;
                                break;
@@ -1339,6 +1352,10 @@ final class ActivityManagerConstants extends ContentObserver {
        mDefaultDisableAppProfilerPssProfiling = context.getResources().getBoolean(
        mDefaultDisableAppProfilerPssProfiling = context.getResources().getBoolean(
                R.bool.config_am_disablePssProfiling);
                R.bool.config_am_disablePssProfiling);
        APP_PROFILER_PSS_PROFILING_DISABLED = mDefaultDisableAppProfilerPssProfiling;
        APP_PROFILER_PSS_PROFILING_DISABLED = mDefaultDisableAppProfilerPssProfiling;

        mDefaultPssToRssThresholdModifier = context.getResources().getFloat(
                com.android.internal.R.dimen.config_am_pssToRssThresholdModifier);
        PSS_TO_RSS_THRESHOLD_MODIFIER = mDefaultPssToRssThresholdModifier;
    }
    }


    public void start(ContentResolver resolver) {
    public void start(ContentResolver resolver) {
@@ -2051,6 +2068,12 @@ final class ActivityManagerConstants extends ContentObserver {
                mDefaultDisableAppProfilerPssProfiling);
                mDefaultDisableAppProfilerPssProfiling);
    }
    }


    private void updatePssToRssThresholdModifier() {
        PSS_TO_RSS_THRESHOLD_MODIFIER = DeviceConfig.getFloat(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_PSS_TO_RSS_THRESHOLD_MODIFIER,
                mDefaultPssToRssThresholdModifier);
    }

    @NeverCompile // Avoid size overhead of debugging code.
    @NeverCompile // Avoid size overhead of debugging code.
    void dump(PrintWriter pw) {
    void dump(PrintWriter pw) {
        pw.println("ACTIVITY MANAGER SETTINGS (dumpsys activity settings) "
        pw.println("ACTIVITY MANAGER SETTINGS (dumpsys activity settings) "
@@ -2242,6 +2265,9 @@ final class ActivityManagerConstants extends ContentObserver {
        pw.print("  "); pw.print(KEY_DISABLE_APP_PROFILER_PSS_PROFILING);
        pw.print("  "); pw.print(KEY_DISABLE_APP_PROFILER_PSS_PROFILING);
        pw.print("="); pw.println(APP_PROFILER_PSS_PROFILING_DISABLED);
        pw.print("="); pw.println(APP_PROFILER_PSS_PROFILING_DISABLED);


        pw.print("  "); pw.print(KEY_PSS_TO_RSS_THRESHOLD_MODIFIER);
        pw.print("="); pw.println(PSS_TO_RSS_THRESHOLD_MODIFIER);

        pw.println();
        pw.println();
        if (mOverrideMaxCachedProcesses >= 0) {
        if (mOverrideMaxCachedProcesses >= 0) {
            pw.print("  mOverrideMaxCachedProcesses="); pw.println(mOverrideMaxCachedProcesses);
            pw.print("  mOverrideMaxCachedProcesses="); pw.println(mOverrideMaxCachedProcesses);
+2 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,7 @@ class ActivityManagerDebugConfig {
    static final boolean DEBUG_PROCESSES = DEBUG_ALL || false;
    static final boolean DEBUG_PROCESSES = DEBUG_ALL || false;
    static final boolean DEBUG_PROVIDER = DEBUG_ALL || false;
    static final boolean DEBUG_PROVIDER = DEBUG_ALL || false;
    static final boolean DEBUG_PSS = DEBUG_ALL || false;
    static final boolean DEBUG_PSS = DEBUG_ALL || false;
    static final boolean DEBUG_RSS = DEBUG_ALL || false;
    static final boolean DEBUG_SERVICE = DEBUG_ALL || false;
    static final boolean DEBUG_SERVICE = DEBUG_ALL || false;
    static final boolean DEBUG_FOREGROUND_SERVICE = DEBUG_ALL || false;
    static final boolean DEBUG_FOREGROUND_SERVICE = DEBUG_ALL || false;
    static final boolean DEBUG_SERVICE_EXECUTING = DEBUG_ALL || false;
    static final boolean DEBUG_SERVICE_EXECUTING = DEBUG_ALL || false;
@@ -91,6 +92,7 @@ class ActivityManagerDebugConfig {
            ? "_ProcessObservers" : "";
            ? "_ProcessObservers" : "";
    static final String POSTFIX_PROCESSES = (APPEND_CATEGORY_NAME) ? "_Processes" : "";
    static final String POSTFIX_PROCESSES = (APPEND_CATEGORY_NAME) ? "_Processes" : "";
    static final String POSTFIX_PSS = (APPEND_CATEGORY_NAME) ? "_Pss" : "";
    static final String POSTFIX_PSS = (APPEND_CATEGORY_NAME) ? "_Pss" : "";
    static final String POSTFIX_RSS = (APPEND_CATEGORY_NAME) ? "_Rss" : "";
    static final String POSTFIX_SERVICE = (APPEND_CATEGORY_NAME) ? "_Service" : "";
    static final String POSTFIX_SERVICE = (APPEND_CATEGORY_NAME) ? "_Service" : "";
    static final String POSTFIX_SERVICE_EXECUTING =
    static final String POSTFIX_SERVICE_EXECUTING =
            (APPEND_CATEGORY_NAME) ? "_ServiceExecuting" : "";
            (APPEND_CATEGORY_NAME) ? "_ServiceExecuting" : "";
Loading