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

Commit 82b34117 authored by Bookatz's avatar Bookatz Committed by Adam Bookatz
Browse files

Disable screen-off RPM timing in BatteryStats

RPM = resource power manager.
Fetching the rpm stats (specifically, the subsystem low power stats) is
slow... too slow to reasonably do each time the screen state changes.
Therefore, it is disabled until fetching this information can be done
more quickly. Consequently, the screen-off RPM values will be incorrect
until it is re-enabled; they are therefore not printed.

Bug: 65164435
Bug: 62549421
Test: manual
Change-Id: I54d54f244c69ee372f22ecd99f32570db4aeb222
parent 50df711a
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public abstract class BatteryStats implements Parcelable {
    private static final String TAG = "BatteryStats";

    private static final boolean LOCAL_LOGV = false;
    /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */
    protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false;

    /** @hide */
    public static final String SERVICE_NAME = "batterystats";
@@ -214,7 +216,7 @@ public abstract class BatteryStats implements Parcelable {
     * New in version 25:
     *   - Package wakeup alarms are now on screen-off timebase
     * New in version 26:
     *   - Resource power manager (rpm) states
     *   - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
     */
    static final String CHECKIN_VERSION = "26";

@@ -3338,8 +3340,14 @@ public abstract class BatteryStats implements Parcelable {
                        ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
                int screenOffCount = screenOffTimer != null
                        ? screenOffTimer.getCountLocked(which) : 0;
                if (SCREEN_OFF_RPM_STATS_ENABLED) {
                    dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
                        "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, screenOffCount);
                            "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
                            screenOffCount);
                } else {
                    dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
                            "\"" + ent.getKey() + "\"", timeMs, count);
                }
            }
        }

@@ -4629,6 +4637,7 @@ public abstract class BatteryStats implements Parcelable {
            }
            pw.println();
        }
        if (SCREEN_OFF_RPM_STATS_ENABLED) {
            final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
            if (screenOffRpmStats.size() > 0) {
                pw.print(prefix);
@@ -4642,6 +4651,7 @@ public abstract class BatteryStats implements Parcelable {
                }
                pw.println();
            }
        }

        final long[] cpuFreqs = getCpuFreqs();
        if (cpuFreqs != null) {
+16 −4
Original line number Diff line number Diff line
@@ -626,6 +626,7 @@ public class BatteryStatsImpl extends BatteryStats {
        return mRpmStats;
    }
    // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED.
    @Override
    public Map<String, ? extends Timer> getScreenOffRpmStats() {
        return mScreenOffRpmStats;
@@ -3559,7 +3560,12 @@ public class BatteryStatsImpl extends BatteryStats {
                updateKernelWakelocksLocked();
                updateBatteryPropertiesLocked();
            }
            // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because
            // updateRpmStatsLocked is too slow to run each screen change. When the speed is
            // improved, remove the surrounding if{}.
            if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) {
                updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes.
            }
            if (DEBUG_ENERGY_CPU) {
                Slog.d(TAG, "Updating cpu time because screen is now " + (screenOff ? "off" : "on")
                        + " and battery is " + (unplugged ? "on" : "off"));
@@ -10254,7 +10260,9 @@ public class BatteryStatsImpl extends BatteryStats {
            final long pTimeUs = pstate.getValue().mTimeMs * 1000;
            final int pCount = pstate.getValue().mCount;
            getRpmTimerLocked(pName).update(pTimeUs, pCount);
            if (SCREEN_OFF_RPM_STATS_ENABLED) {
                getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount);
            }
            // Update values for each voter of this platform state.
            for (Map.Entry<String, RpmStats.PowerStateElement> voter
@@ -10263,9 +10271,11 @@ public class BatteryStatsImpl extends BatteryStats {
                final long vTimeUs = voter.getValue().mTimeMs * 1000;
                final int vCount = voter.getValue().mCount;
                getRpmTimerLocked(vName).update(vTimeUs, vCount);
                if (SCREEN_OFF_RPM_STATS_ENABLED) {
                    getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount);
                }
            }
        }
        for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys
                : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) {
@@ -10277,10 +10287,12 @@ public class BatteryStatsImpl extends BatteryStats {
                final long timeUs = sstate.getValue().mTimeMs * 1000;
                final int count = sstate.getValue().mCount;
                getRpmTimerLocked(name).update(timeUs, count);
                if (SCREEN_OFF_RPM_STATS_ENABLED) {
                    getScreenOffRpmTimerLocked(name).update(timeUs, count);
                }
            }
        }
    }
    /**
     * Read and distribute kernel wake lock use across apps.