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

Commit 203c1de0 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by The Android Automerger
Browse files

Fix recording of wake_lock_in.

There was a bug that would allow the nesting count
to get off.  Also better documentation of times in
HistoryItem, and new option to disable resetting of
the stats when unplugging.

Change-Id: If1b39a02475c5b620c67b700a323a6d0462d5c61
parent b694cfa8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -532,6 +532,7 @@ public abstract class BatteryStats implements Parcelable {
    public final static class HistoryItem implements Parcelable {
        public HistoryItem next;

        // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
        public long time;

        public static final byte CMD_UPDATE = 0;        // These can be written as deltas
@@ -645,7 +646,7 @@ public abstract class BatteryStats implements Parcelable {
        public int eventCode;
        public HistoryTag eventTag;

        // Only set for CMD_CURRENT_TIME.
        // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
        public long currentTime;

        // Meta-data when reading.
+12 −6
Original line number Diff line number Diff line
@@ -235,7 +235,8 @@ public final class BatteryStatsImpl extends BatteryStats {

    int mWakeLockNesting;
    boolean mWakeLockImportant;
    public boolean mRecordAllWakeLocks;
    boolean mRecordAllWakeLocks;
    boolean mNoAutoReset;

    int mScreenState = Display.STATE_UNKNOWN;
    StopwatchTimer mScreenOnTimer;
@@ -2314,9 +2315,6 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
    }

    private String mInitialAcquireWakeName;
    private int mInitialAcquireWakeUid = -1;

    public void setRecordAllWakeLocksLocked(boolean enabled) {
        mRecordAllWakeLocks = enabled;
        if (!enabled) {
@@ -2325,6 +2323,13 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
    }

    public void setNoAutoReset(boolean enabled) {
        mNoAutoReset = enabled;
    }

    private String mInitialAcquireWakeName;
    private int mInitialAcquireWakeUid = -1;

    public void noteStartWakeLocked(int uid, int pid, String name, String historyName, int type,
            boolean unimportantForLogging, long elapsedRealtime, long uptime) {
        uid = mapUid(uid);
@@ -2355,6 +2360,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            } else if (mRecordAllWakeLocks) {
                if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName,
                        uid, 0)) {
                    mWakeLockNesting++;
                    return;
                }
                addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_WAKE_LOCK_START,
@@ -5942,9 +5948,9 @@ public final class BatteryStatsImpl extends BatteryStats {
            // we have gone through a significant charge (from a very low
            // level to a now very high level).
            boolean reset = false;
            if (oldStatus == BatteryManager.BATTERY_STATUS_FULL
            if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL
                    || level >= 90
                    || (mDischargeCurrentLevel < 20 && level >= 80)) {
                    || (mDischargeCurrentLevel < 20 && level >= 80))) {
                doWrite = true;
                resetAllStatsLocked();
                mDischargeStartLevel = level;
+6 −2
Original line number Diff line number Diff line
@@ -623,8 +623,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        pw.println("  --charged: only output data since last charged.");
        pw.println("  --reset: reset the stats, clearing all current data.");
        pw.println("  --write: force write current collected stats to disk.");
        pw.println("  --enable: enable an option: full-wake-history.");
        pw.println("  --disable: disable an option: full-wake-history.");
        pw.println("  --enable: enable an option: full-wake-history, no-auto-reset.");
        pw.println("  --disable: disable an option: full-wake-history, no-auto-reset.");
        pw.println("  -h: print this help text.");
        pw.println("  <package.name>: optional name of package to filter output by.");
    }
@@ -640,6 +640,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            synchronized (mStats) {
                mStats.setRecordAllWakeLocksLocked(enable);
            }
        } else if ("no-auto-reset".equals(args[i])) {
            synchronized (mStats) {
                mStats.setNoAutoReset(enable);
            }
        } else {
            pw.println("Unknown enable/disable option: " + args[i]);
            dumpHelp(pw);