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

Commit 6e86915e authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fixes to battery stats debug output." into gingerbread

parents 11bbe200 b5e31651
Loading
Loading
Loading
Loading
+46 −1
Original line number Diff line number Diff line
@@ -215,6 +215,11 @@ public abstract class BatteryStats implements Parcelable {
         */
        public abstract Map<Integer, ? extends Sensor> getSensorStats();

        /**
         * Returns a mapping containing active process data.
         */
        public abstract SparseArray<? extends Pid> getPidStats();
        
        /**
         * Returns a mapping containing process statistics.
         *
@@ -286,6 +291,11 @@ public abstract class BatteryStats implements Parcelable {
            public abstract Timer getSensorTime();
        }

        public class Pid {
            public long mWakeSum;
            public long mWakeStart;
        }

        /**
         * The statistics associated with a particular process.
         */
@@ -520,6 +530,11 @@ public abstract class BatteryStats implements Parcelable {
     */
    public abstract HistoryItem getHistory();
    
    /**
     * Return the base time offset for the battery history.
     */
    public abstract long getHistoryBaseTime();
    
    /**
     * Returns the number of times the device has been started.
     */
@@ -1673,6 +1688,7 @@ public abstract class BatteryStats implements Parcelable {
        HistoryItem rec = getHistory();
        if (rec != null) {
            pw.println("Battery History:");
            long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
            int oldState = 0;
            int oldStatus = -1;
            int oldHealth = -1;
@@ -1681,7 +1697,7 @@ public abstract class BatteryStats implements Parcelable {
            int oldVolt = -1;
            while (rec != null) {
                pw.print("  ");
                pw.print(rec.time);
                TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
                pw.print(" ");
                if (rec.cmd == HistoryItem.CMD_START) {
                    pw.println(" START");
@@ -1784,6 +1800,35 @@ public abstract class BatteryStats implements Parcelable {
                oldState = rec.states;
                rec = rec.next;
            }
            pw.println("");
        }
        
        SparseArray<? extends Uid> uidStats = getUidStats();
        final int NU = uidStats.size();
        boolean didPid = false;
        long nowRealtime = SystemClock.elapsedRealtime();
        StringBuilder sb = new StringBuilder(64);
        for (int i=0; i<NU; i++) {
            Uid uid = uidStats.valueAt(i);
            SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
            if (pids != null) {
                for (int j=0; j<pids.size(); j++) {
                    Uid.Pid pid = pids.valueAt(j);
                    if (!didPid) {
                        pw.println("Per-PID Stats:");
                        didPid = true;
                    }
                    long time = pid.mWakeSum + (pid.mWakeStart != 0
                            ? (nowRealtime - pid.mWakeStart) : 0);
                    pw.print("  PID "); pw.print(pids.keyAt(j));
                            pw.print(" wake time: ");
                            TimeUtils.formatDuration(time, pw);
                            pw.println("");
                }
            }
        }
        if (didPid) {
            pw.println("");
        }
        
        pw.println("Statistics since last charge:");
+103 −78
Original line number Diff line number Diff line
@@ -132,75 +132,76 @@ public class TimeUtils {
        return ZoneInfoDB.getVersion();
    }

    /** @hide Field length that can hold 999 days of time */
    public static final int HUNDRED_DAY_FIELD_LEN = 19;
    
    private static final int SECONDS_PER_MINUTE = 60;
    private static final int SECONDS_PER_HOUR = 60 * 60;
    private static final int SECONDS_PER_DAY = 24 * 60 * 60;

    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, StringBuilder builder) {
        if (duration == 0) {
            builder.append("0");
            return;
        }
        if (duration > 0) {
            builder.append("+");
        } else {
            builder.append("-");
            duration = -duration;
        }

        int millis = (int)(duration%1000);
        int seconds = (int) Math.floor(duration / 1000);
        int days = 0, hours = 0, minutes = 0;
    private static final Object sFormatSync = new Object();
    private static char[] sFormatStr = new char[HUNDRED_DAY_FIELD_LEN+5];
    
        if (seconds > SECONDS_PER_DAY) {
            days = seconds / SECONDS_PER_DAY;
            seconds -= days * SECONDS_PER_DAY;
    static private int accumField(int amt, int suffix, boolean always, int zeropad) {
        if (amt > 99 || (always && zeropad >= 3)) {
            return 3+suffix;
        }
        if (seconds > SECONDS_PER_HOUR) {
            hours = seconds / SECONDS_PER_HOUR;
            seconds -= hours * SECONDS_PER_HOUR;
        if (amt > 9 || (always && zeropad >= 2)) {
            return 2+suffix;
        }
        if (seconds > SECONDS_PER_MINUTE) {
            minutes = seconds / SECONDS_PER_MINUTE;
            seconds -= minutes * SECONDS_PER_MINUTE;
        if (always || amt > 0) {
            return 1+suffix;
        }
        return 0;
    }
    
        boolean doall = false;
        if (days > 0) {
            builder.append(days);
            builder.append('d');
            doall = true;
    static private int printField(char[] formatStr, int amt, char suffix, int pos,
            boolean always, int zeropad) {
        if (always || amt > 0) {
            if ((always && zeropad >= 3) || amt > 99) {
                int dig = amt/100;
                formatStr[pos] = (char)(dig + '0');
                pos++;
                always = true;
                amt -= (dig*100);
            }
        if (doall || hours > 0) {
            builder.append(hours);
            builder.append('h');
            doall = true;
            if ((always && zeropad >= 2) || amt > 9) {
                int dig = amt/10;
                formatStr[pos] = (char)(dig + '0');
                pos++;
                always = true;
                amt -= (dig*10);
            }
        if (doall || minutes > 0) {
            builder.append(minutes);
            builder.append('m');
            doall = true;
            formatStr[pos] = (char)(amt + '0');
            pos++;
            formatStr[pos] = suffix;
            pos++;
        }
        if (doall || seconds > 0) {
            builder.append(seconds);
            builder.append('s');
            doall = true;
        return pos;
    }
        builder.append(millis);
        builder.append("ms");
    
    private static int formatDurationLocked(long duration, int fieldLen) {
        if (sFormatStr.length < fieldLen) {
            sFormatStr = new char[fieldLen];
        }
        
    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, PrintWriter pw) {
        char[] formatStr = sFormatStr;
        
        if (duration == 0) {
            pw.print("0");
            return;
            int pos = 0;
            fieldLen -= 1;
            while (pos < fieldLen) {
                formatStr[pos] = ' ';
            }
            formatStr[pos] = '0';
            return pos+1;
        }
        
        char prefix;
        if (duration > 0) {
            pw.print("+");
            prefix = '+';
        } else {
            pw.print("-");
            prefix = '-';
            duration = -duration;
        }

@@ -221,31 +222,55 @@ public class TimeUtils {
            seconds -= minutes * SECONDS_PER_MINUTE;
        }

        boolean doall = false;
        if (days > 0) {
            pw.print(days);
            pw.print('d');
            doall = true;
        int pos = 0;
        
        if (fieldLen != 0) {
            int myLen = accumField(days, 1, false, 0);
            myLen += accumField(hours, 1, myLen > 0, 2);
            myLen += accumField(minutes, 1, myLen > 0, 2);
            myLen += accumField(seconds, 1, myLen > 0, 2);
            myLen += accumField(millis, 2, true, myLen > 0 ? 3 : 0) + 1;
            while (myLen < fieldLen) {
                formatStr[pos] = ' ';
                pos++;
                myLen++;
            }
        }
        
        formatStr[pos] = prefix;
        pos++;
        
        int start = pos;
        boolean zeropad = fieldLen != 0;
        pos = printField(formatStr, days, 'd', pos, false, 0);
        pos = printField(formatStr, hours, 'h', pos, pos != start, zeropad ? 2 : 0);
        pos = printField(formatStr, minutes, 'm', pos, pos != start, zeropad ? 2 : 0);
        pos = printField(formatStr, seconds, 's', pos, pos != start, zeropad ? 2 : 0);
        pos = printField(formatStr, millis, 'm', pos, true, (zeropad && pos != start) ? 3 : 0);
        formatStr[pos] = 's';
        return pos + 1;
    }
        if (doall || hours > 0) {
            pw.print(hours);
            pw.print('h');
            doall = true;
    
    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, StringBuilder builder) {
        synchronized (sFormatSync) {
            int len = formatDurationLocked(duration, 0);
            builder.append(sFormatStr, 0, len);
        }
        if (doall || minutes > 0) {
            pw.print(minutes);
            pw.print('m');
            doall = true;
    }
        if (doall || seconds > 0) {
            pw.print(seconds);
            pw.print('s');
            doall = true;

    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, PrintWriter pw, int fieldLen) {
        synchronized (sFormatSync) {
            int len = formatDurationLocked(duration, fieldLen);
            pw.print(new String(sFormatStr, 0, len));
        }
        pw.print(millis);
        pw.print("ms");
    }

    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, PrintWriter pw) {
        formatDuration(duration, pw, 0);
    }
    
    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long time, long now, PrintWriter pw) {
@@ -253,6 +278,6 @@ public class TimeUtils {
            pw.print("--");
            return;
        }
        formatDuration(time-now, pw);
        formatDuration(time-now, pw, 0);
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -3343,11 +3343,6 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
        }

        public class Pid {
            long mWakeSum;
            long mWakeStart;
        }

        /**
         * Retrieve the statistics object for a particular process, creating
         * if needed.
@@ -3362,6 +3357,10 @@ public final class BatteryStatsImpl extends BatteryStats {
            return ps;
        }

        public SparseArray<? extends Pid> getPidStats() {
            return mPids;
        }
        
        public Pid getPidStatsLocked(int pid) {
            Pid p = mPids.get(pid);
            if (p == null) {
@@ -3585,6 +3584,11 @@ public final class BatteryStatsImpl extends BatteryStats {
        return mHistory;
    }
    
    @Override
    public long getHistoryBaseTime() {
        return mHistoryBaseTime;
    }
    
    @Override
    public int getStartCount() {
        return mStartCount;