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

Commit 671985f4 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Read cpu freq data only when needed.

Bug: 34133340
Test: cts-tradefed run singleCommand cts-dev -m ctsIncidentHostTestCases -t \
      com.android.server.cts.BatteryStatsValidationTest

Change-Id: Ib235e166820b95b5cd0a496b6146ea353abdf844
parent 01d5b3d2
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ public class BatteryStatsImpl extends BatteryStats {
            switch (msg.what) {
                case MSG_UPDATE_WAKELOCKS:
                    synchronized (BatteryStatsImpl.this) {
                        updateCpuTimeLocked();
                        updateCpuTimeLocked(false /* updateCpuFreqData */);
                    }
                    if (cb != null) {
                        cb.batteryNeedsCpuUpdate();
@@ -3480,7 +3480,7 @@ public class BatteryStatsImpl extends BatteryStats {
                Slog.d(TAG, "Updating cpu time because screen is now " +
                        (unpluggedScreenOff ? "off" : "on"));
            }
            updateCpuTimeLocked();
            updateCpuTimeLocked(true /* updateCpuFreqData */);
            mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime);
        }
    }
@@ -9936,7 +9936,7 @@ public class BatteryStatsImpl extends BatteryStats {
     * and we are on battery with screen off, we give more of the cpu time to those apps holding
     * wakelocks. If the screen is on, we just assign the actual cpu time an app used.
     */
    public void updateCpuTimeLocked() {
    public void updateCpuTimeLocked(boolean updateCpuFreqData) {
        if (mPowerProfile == null) {
            return;
        }
@@ -10051,7 +10051,9 @@ public class BatteryStatsImpl extends BatteryStats {
                    }
                });

        if (updateCpuFreqData) {
            readKernelUidCpuFreqTimesLocked();
        }

        final long elapse = (mClocks.elapsedRealtime() - startTimeMs);
        if (DEBUG_ENERGY_CPU || (elapse >= 100)) {
+5 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.am;

import static com.android.internal.os.BatteryStatsImpl.ExternalStatsSync.UPDATE_CPU;

import android.annotation.Nullable;
import android.bluetooth.BluetoothActivityEnergyInfo;
import android.bluetooth.BluetoothAdapter;
@@ -1549,7 +1551,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS,
                        reason, 0);

                mStats.updateCpuTimeLocked();
                if ((updateFlags & UPDATE_CPU) != 0) {
                    mStats.updateCpuTimeLocked(true /* updateCpuFreqData */);
                }
                mStats.updateKernelWakelocksLocked();
                mStats.updateKernelMemoryBandwidthLocked();