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

Commit e8c88e6f authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #5163456: logspam/tight loop in BatteryStatsImpl

No longer use the old history code.

Change-Id: I878ffe16e0014453c46db6a4f7228a81468d8cb9
parent 9f550e91
Loading
Loading
Loading
Loading
+23 −7
Original line number Original line Diff line number Diff line
@@ -67,12 +67,13 @@ public final class BatteryStatsImpl extends BatteryStats {
    private static final String TAG = "BatteryStatsImpl";
    private static final String TAG = "BatteryStatsImpl";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;
    private static final boolean DEBUG_HISTORY = false;
    private static final boolean DEBUG_HISTORY = false;
    private static final boolean USE_OLD_HISTORY = false;   // for debugging.


    // In-memory Parcel magic number, used to detect attempts to unmarshall bad data
    // In-memory Parcel magic number, used to detect attempts to unmarshall bad data
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'


    // Current on-disk Parcel version
    // Current on-disk Parcel version
    private static final int VERSION = 60;
    private static final int VERSION = 61 + (USE_OLD_HISTORY ? 1000 : 0);


    // Maximum number of items we will record in the history.
    // Maximum number of items we will record in the history.
    private static final int MAX_HISTORY_ITEMS = 2000;
    private static final int MAX_HISTORY_ITEMS = 2000;
@@ -1285,6 +1286,10 @@ public final class BatteryStatsImpl extends BatteryStats {
    void addHistoryRecordLocked(long curTime) {
    void addHistoryRecordLocked(long curTime) {
        addHistoryBufferLocked(curTime);
        addHistoryBufferLocked(curTime);


        if (!USE_OLD_HISTORY) {
            return;
        }

        if (!mHaveBatteryLevel || !mRecordingHistory) {
        if (!mHaveBatteryLevel || !mRecordingHistory) {
            return;
            return;
        }
        }
@@ -1363,12 +1368,15 @@ public final class BatteryStatsImpl extends BatteryStats {


    void clearHistoryLocked() {
    void clearHistoryLocked() {
        if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!");
        if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!");
        if (USE_OLD_HISTORY) {
            if (mHistory != null) {
            if (mHistory != null) {
                mHistoryEnd.next = mHistoryCache;
                mHistoryEnd.next = mHistoryCache;
                mHistoryCache = mHistory;
                mHistoryCache = mHistory;
                mHistory = mHistoryLastEnd = mHistoryEnd = null;
                mHistory = mHistoryLastEnd = mHistoryEnd = null;
            }
            }
            mNumHistoryItems = 0;
            mNumHistoryItems = 0;
        }

        mHistoryBaseTime = 0;
        mHistoryBaseTime = 0;
        mLastHistoryTime = 0;
        mLastHistoryTime = 0;


@@ -4863,7 +4871,9 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }


        long now = SystemClock.elapsedRealtime();
        long now = SystemClock.elapsedRealtime();
        if (USE_OLD_HISTORY) {
            addHistoryRecordLocked(now, HistoryItem.CMD_START);
            addHistoryRecordLocked(now, HistoryItem.CMD_START);
        }
        addHistoryBufferLocked(now, HistoryItem.CMD_START);
        addHistoryBufferLocked(now, HistoryItem.CMD_START);
    }
    }


@@ -4923,6 +4933,9 @@ public final class BatteryStatsImpl extends BatteryStats {
    }
    }


    void readOldHistory(Parcel in) {
    void readOldHistory(Parcel in) {
        if (!USE_OLD_HISTORY) {
            return;
        }
        mHistory = mHistoryEnd = mHistoryCache = null;
        mHistory = mHistoryEnd = mHistoryCache = null;
        long time;
        long time;
        while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) {
        while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) {
@@ -4952,6 +4965,9 @@ public final class BatteryStatsImpl extends BatteryStats {
    }
    }


    void writeOldHistory(Parcel out) {
    void writeOldHistory(Parcel out) {
        if (!USE_OLD_HISTORY) {
            return;
        }
        HistoryItem rec = mHistory;
        HistoryItem rec = mHistory;
        while (rec != null) {
        while (rec != null) {
            if (rec.time >= 0) rec.writeToParcel(out, 0);
            if (rec.time >= 0) rec.writeToParcel(out, 0);
+0 −1
Original line number Original line Diff line number Diff line
@@ -2699,7 +2699,6 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                }
                
                
                if (!haveBg) {
                if (!haveBg) {
                    Slog.i(TAG, "Low Memory: No more background processes.");
                    EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLruProcesses.size());
                    EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLruProcesses.size());
                    long now = SystemClock.uptimeMillis();
                    long now = SystemClock.uptimeMillis();
                    for (int i=mLruProcesses.size()-1; i>=0; i--) {
                    for (int i=mLruProcesses.size()-1; i>=0; i--) {