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

Commit 99009ea7 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Try to always print time stamp in battery history.

Also fix printing of string pool to quote the strings
and escape characters, and change history time stamps
to print starting at 0 and going up.

Change-Id: I2d0c080f2b5de7b27b20a7357c2c0cf481c82d8c
parent 4660c9e0
Loading
Loading
Loading
Loading
+54 −19
Original line number Diff line number Diff line
@@ -2861,27 +2861,19 @@ public abstract class BatteryStats implements Parcelable {
        int oldTemp = -1;
        int oldVolt = -1;
        long lastTime = -1;
        long firstTime = -1;

        public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin,
        public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
                boolean verbose) {
            if (!checkin) {
                pw.print("  ");
                if (now >= 0) {
                    TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
                } else {
                    TimeUtils.formatDuration(rec.time, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
                }
                TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
                pw.print(" (");
                pw.print(rec.numReadInts);
                pw.print(") ");
            } else {
                if (lastTime < 0) {
                    if (now >= 0) {
                        pw.print("@");
                        pw.print(rec.time-now);
                    } else {
                        pw.print(rec.time);
                    }
                    pw.print(rec.time - baseTime);
                } else {
                    pw.print(rec.time - lastTime);
                }
@@ -3132,10 +3124,27 @@ public abstract class BatteryStats implements Parcelable {
                    pw.println("):");
                    HistoryPrinter hprinter = new HistoryPrinter();
                    long lastTime = -1;
                    long baseTime = -1;
                    boolean printed = false;
                    while (getNextHistoryLocked(rec)) {
                        lastTime = rec.time;
                        if (baseTime < 0) {
                            baseTime = lastTime;
                        }
                        if (rec.time >= histStart) {
                            hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false,
                            if (histStart >= 0 && !printed) {
                                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME) {
                                    printed = true;
                                } else if (rec.currentTime != 0) {
                                    printed = true;
                                    byte cmd = rec.cmd;
                                    rec.cmd = HistoryItem.CMD_CURRENT_TIME;
                                    hprinter.printNextItem(pw, rec, baseTime, false,
                                            (flags&DUMP_VERBOSE) != 0);
                                    rec.cmd = cmd;
                                }
                            }
                            hprinter.printNextItem(pw, rec, baseTime, false,
                                    (flags&DUMP_VERBOSE) != 0);
                        }
                    }
@@ -3152,8 +3161,12 @@ public abstract class BatteryStats implements Parcelable {
                try {
                    pw.println("Old battery History:");
                    HistoryPrinter hprinter = new HistoryPrinter();
                    long baseTime = -1;
                    while (getNextOldHistoryLocked(rec)) {
                        hprinter.printNextItem(pw, rec, now, false, (flags&DUMP_VERBOSE) != 0);
                        if (baseTime < 0) {
                            baseTime = rec.time;
                        }
                        hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
                    }
                    pw.println();
                } finally {
@@ -3226,20 +3239,42 @@ public abstract class BatteryStats implements Parcelable {
                        pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                        pw.print(HISTORY_STRING_POOL); pw.print(',');
                        pw.print(i);
                        pw.print(',');
                        pw.print(getHistoryTagPoolString(i));
                        pw.print(',');
                        pw.print(",");
                        pw.print(getHistoryTagPoolUid(i));
                        pw.print(",\"");
                        String str = getHistoryTagPoolString(i);
                        str = str.replace("\\", "\\\\");
                        str = str.replace("\"", "\\\"");
                        pw.print(str);
                        pw.print("\"");
                        pw.println();
                    }
                    HistoryPrinter hprinter = new HistoryPrinter();
                    long lastTime = -1;
                    long baseTime = -1;
                    boolean printed = false;
                    while (getNextHistoryLocked(rec)) {
                        lastTime = rec.time;
                        if (baseTime < 0) {
                            baseTime = lastTime;
                        }
                        if (rec.time >= histStart) {
                            if (histStart >= 0 && !printed) {
                                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME) {
                                    printed = true;
                                } else if (rec.currentTime != 0) {
                                    printed = true;
                                    byte cmd = rec.cmd;
                                    rec.cmd = HistoryItem.CMD_CURRENT_TIME;
                                    pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                                    pw.print(HISTORY_DATA); pw.print(',');
                                    hprinter.printNextItem(pw, rec, baseTime, true, false);
                                    rec.cmd = cmd;
                                }
                            }
                            pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                            pw.print(HISTORY_DATA); pw.print(',');
                            hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true, false);
                            hprinter.printNextItem(pw, rec, baseTime, true, false);
                        }
                    }
                    if (histStart >= 0) {
+8 −3
Original line number Diff line number Diff line
@@ -5580,13 +5580,13 @@ public final class BatteryStatsImpl extends BatteryStats {
            if (end) {
                Slog.w(TAG, "New history ends before old history!");
            } else if (!out.same(mHistoryReadTmp)) {
                long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
                PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG));
                pw.println("Histories differ!");
                pw.println("Old history:");
                (new HistoryPrinter()).printNextItem(pw, out, now, false, true);
                (new HistoryPrinter()).printNextItem(pw, out, 0, false, true);
                pw.println("New history:");
                (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now, false, true);
                (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false,
                        true);
                pw.flush();
            }
        }
@@ -5664,7 +5664,12 @@ public final class BatteryStatsImpl extends BatteryStats {
            return false;
        }

        final long lastRealtime = out.time;
        final long lastWalltime = out.currentTime;
        readHistoryDelta(mHistoryBuffer, out);
        if (out.cmd != HistoryItem.CMD_CURRENT_TIME && lastWalltime != 0) {
            out.currentTime = lastWalltime + (out.time - lastRealtime);
        }
        return true;
    }