Loading core/java/android/os/BatteryStats.java +204 −121 Original line number Diff line number Diff line Loading @@ -578,6 +578,9 @@ public abstract class BatteryStats implements Parcelable { // The wake lock that was acquired at this point. public HistoryTag wakelockTag; // Kernel wakeup reason at this point. public HistoryTag wakeReasonTag; public static final int EVENT_FLAG_START = 0x8000; public static final int EVENT_FLAG_FINISH = 0x4000; Loading Loading @@ -612,6 +615,7 @@ public abstract class BatteryStats implements Parcelable { // Pre-allocated objects. public final HistoryTag localWakelockTag = new HistoryTag(); public final HistoryTag localWakeReasonTag = new HistoryTag(); public final HistoryTag localEventTag = new HistoryTag(); public HistoryItem() { Loading Loading @@ -645,6 +649,12 @@ public abstract class BatteryStats implements Parcelable { } else { dest.writeInt(0); } if (wakeReasonTag != null) { dest.writeInt(1); wakeReasonTag.writeToParcel(dest, flags); } else { dest.writeInt(0); } dest.writeInt(eventCode); if (eventCode != EVENT_NONE) { dest.writeInt(eventCode); Loading @@ -670,6 +680,12 @@ public abstract class BatteryStats implements Parcelable { } else { wakelockTag = null; } if (src.readInt() != 0) { wakeReasonTag = localWakeReasonTag; wakeReasonTag.readFromParcel(src); } else { wakeReasonTag = null; } eventCode = src.readInt(); if (eventCode != EVENT_NONE) { eventTag = localEventTag; Loading @@ -689,6 +705,7 @@ public abstract class BatteryStats implements Parcelable { batteryVoltage = 0; states = 0; wakelockTag = null; wakeReasonTag = null; eventCode = EVENT_NONE; eventTag = null; } Loading Loading @@ -719,6 +736,12 @@ public abstract class BatteryStats implements Parcelable { } else { wakelockTag = null; } if (o.wakeReasonTag != null) { wakeReasonTag = localWakeReasonTag; wakeReasonTag.setTo(o.wakeReasonTag); } else { wakeReasonTag = null; } eventCode = o.eventCode; if (o.eventTag != null) { eventTag = localEventTag; Loading Loading @@ -750,6 +773,14 @@ public abstract class BatteryStats implements Parcelable { return false; } } if (wakeReasonTag != o.wakeReasonTag) { if (wakeReasonTag == null || o.wakeReasonTag == null) { return false; } if (!wakeReasonTag.equals(o.wakeReasonTag)) { return false; } } if (eventTag != o.eventTag) { if (eventTag == null || o.eventTag == null) { return false; Loading Loading @@ -1916,51 +1947,6 @@ public abstract class BatteryStats implements Parcelable { long fullWakeLockTimeTotalMicros = 0; long partialWakeLockTimeTotalMicros = 0; final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { @Override public int compare(TimerEntry lhs, TimerEntry rhs) { long lhsTime = lhs.mTime; long rhsTime = rhs.mTime; if (lhsTime < rhsTime) { return 1; } if (lhsTime > rhsTime) { return -1; } return 0; } }; if (reqUid < 0) { Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); if (kernelWakelocks.size() > 0) { final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { BatteryStats.Timer timer = ent.getValue(); long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); if (totalTimeMillis > 0) { timers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); } } Collections.sort(timers, timerComparator); for (int i=0; i<timers.size(); i++) { TimerEntry timer = timers.get(i); String linePrefix = ": "; sb.setLength(0); sb.append(prefix); sb.append(" Kernel Wake lock "); sb.append(timer.mName); linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, which, linePrefix); if (!linePrefix.equals(": ")) { sb.append(" realtime"); // Only print out wake locks that were held pw.println(sb.toString()); } } } } final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); for (int iu = 0; iu < NU; iu++) { Loading Loading @@ -2292,6 +2278,55 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { @Override public int compare(TimerEntry lhs, TimerEntry rhs) { long lhsTime = lhs.mTime; long rhsTime = rhs.mTime; if (lhsTime < rhsTime) { return 1; } if (lhsTime > rhsTime) { return -1; } return 0; } }; if (reqUid < 0) { Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); if (kernelWakelocks.size() > 0) { final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>(); for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { BatteryStats.Timer timer = ent.getValue(); long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); if (totalTimeMillis > 0) { ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); } } if (ktimers.size() > 0) { Collections.sort(ktimers, timerComparator); pw.print(prefix); pw.println(" All kernel wake locks:"); for (int i=0; i<ktimers.size(); i++) { TimerEntry timer = ktimers.get(i); String linePrefix = ": "; sb.setLength(0); sb.append(prefix); sb.append(" Kernel Wake lock "); sb.append(timer.mName); linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, which, linePrefix); if (!linePrefix.equals(": ")) { sb.append(" realtime"); // Only print out wake locks that were held pw.println(sb.toString()); } } pw.println(); } } } if (timers.size() > 0) { Collections.sort(timers, timerComparator); pw.print(prefix); pw.println(" All partial wake locks:"); Loading Loading @@ -2727,14 +2762,22 @@ public abstract class BatteryStats implements Parcelable { public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin) { 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); } 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); } } else { pw.print(rec.time-lastTime); } Loading Loading @@ -2858,6 +2901,18 @@ public abstract class BatteryStats implements Parcelable { } printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, HISTORY_STATE_DESCRIPTIONS, !checkin); if (rec.wakeReasonTag != null) { if (checkin) { pw.print(",Wr="); pw.print(rec.wakeReasonTag.poolIdx); } else { pw.print(" wake_reason="); pw.print(rec.wakeReasonTag.uid); pw.print(":\""); pw.print(rec.wakeReasonTag.string); pw.print("\""); } } if (rec.eventCode != HistoryItem.EVENT_NONE) { pw.print(checkin ? "," : " "); if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { Loading Loading @@ -2918,16 +2973,24 @@ public abstract class BatteryStats implements Parcelable { pw.print(suffix); } public static final int DUMP_UNPLUGGED_ONLY = 1<<0; public static final int DUMP_CHARGED_ONLY = 1<<1; public static final int DUMP_HISTORY_ONLY = 1<<2; public static final int DUMP_INCLUDE_HISTORY = 1<<3; /** * Dumps a human-readable summary of the battery statistics to the given PrintWriter. * * @param pw a Printer to receive the dump output. */ @SuppressWarnings("unused") public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { prepareForDumpLocked(); final boolean filtering = (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); final HistoryItem rec = new HistoryItem(); Loading @@ -2947,8 +3010,15 @@ public abstract class BatteryStats implements Parcelable { printSizeValue(pw, getHistoryStringPoolBytes()); pw.println("):"); HistoryPrinter hprinter = new HistoryPrinter(); long lastTime = -1; while (getNextHistoryLocked(rec)) { hprinter.printNextItem(pw, rec, now, false); lastTime = rec.time; if (rec.time >= histStart) { hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false); } } if (histStart >= 0) { pw.print(" NEXT: "); pw.println(lastTime+1); } pw.println(); } finally { Loading @@ -2968,11 +3038,13 @@ public abstract class BatteryStats implements Parcelable { finishIteratingOldHistoryLocked(); } } } if (historyOnly) { if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { return; } if (!filtering) { SparseArray<? extends Uid> uidStats = getUidStats(); final int NU = uidStats.size(); boolean didPid = false; Loading @@ -2999,27 +3071,32 @@ public abstract class BatteryStats implements Parcelable { if (didPid) { pw.println(""); } } if (!isUnpluggedOnly) { if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { pw.println("Statistics since last charge:"); pw.println(" System starts: " + getStartCount() + ", currently on battery: " + getIsOnBattery()); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); pw.println(""); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { pw.println("Statistics since last unplugged:"); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); } } @SuppressWarnings("unused") public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly, boolean includeHistory, boolean historyOnly) { public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, int flags, long histStart) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); if (includeHistory || historyOnly) { final boolean filtering = (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { try { Loading @@ -3034,10 +3111,17 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } HistoryPrinter hprinter = new HistoryPrinter(); long lastTime = -1; while (getNextHistoryLocked(rec)) { lastTime = rec.time; if (rec.time >= histStart) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); pw.print(HISTORY_DATA); pw.print(','); hprinter.printNextItem(pw, rec, now, true); hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true); } } if (histStart >= 0) { pw.print("NEXT: "); pw.println(lastTime+1); } } finally { finishIteratingHistoryLocked(); Loading @@ -3045,7 +3129,7 @@ public abstract class BatteryStats implements Parcelable { } } if (historyOnly) { if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { return; } Loading Loading @@ -3076,11 +3160,10 @@ public abstract class BatteryStats implements Parcelable { } } } if (isUnpluggedOnly) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); } else { if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); } } Loading core/java/com/android/internal/os/BatteryStatsImpl.java +62 −16 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 97 + (USE_OLD_HISTORY ? 1000 : 0); private static final int VERSION = 98 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; Loading Loading @@ -1712,7 +1712,7 @@ public final class BatteryStatsImpl extends BatteryStats { static final int DELTA_STATE_FLAG = 0x00100000; // Flag in delta int: a new full state2 int follows. static final int DELTA_STATE2_FLAG = 0x00200000; // Flag in delta int: contains a wakelock tag. // Flag in delta int: contains a wakelock or wakeReason tag. static final int DELTA_WAKELOCK_FLAG = 0x00400000; // Flag in delta int: contains an event description. static final int DELTA_EVENT_FLAG = 0x00800000; Loading Loading @@ -1759,7 +1759,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (stateIntChanged) { firstToken |= DELTA_STATE_FLAG; } if (cur.wakelockTag != null) { if (cur.wakelockTag != null || cur.wakeReasonTag != null) { firstToken |= DELTA_WAKELOCK_FLAG; } if (cur.eventCode != HistoryItem.EVENT_NONE) { Loading Loading @@ -1795,11 +1795,24 @@ public final class BatteryStatsImpl extends BatteryStats { + " batteryPlugType=" + cur.batteryPlugType + " states=0x" + Integer.toHexString(cur.states)); } if (cur.wakelockTag != null || cur.wakeReasonTag != null) { int wakeLockIndex; int wakeReasonIndex; if (cur.wakelockTag != null) { int index = writeHistoryTag(cur.wakelockTag); dest.writeInt(index); wakeLockIndex = writeHistoryTag(cur.wakelockTag); if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); } else { wakeLockIndex = 0xffff; } if (cur.wakeReasonTag != null) { wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); } else { wakeReasonIndex = 0xffff; } dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); } if (cur.eventCode != HistoryItem.EVENT_NONE) { int index = writeHistoryTag(cur.eventTag); Loading Loading @@ -1905,15 +1918,30 @@ public final class BatteryStatsImpl extends BatteryStats { } if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { int indexes = src.readInt(); int wakeLockIndex = indexes&0xffff; int wakeReasonIndex = (indexes>>16)&0xffff; if (wakeLockIndex != 0xffff) { cur.wakelockTag = cur.localWakelockTag; int index = src.readInt(); readHistoryTag(index, cur.wakelockTag); cur.numReadInts += 1; readHistoryTag(wakeLockIndex, cur.wakelockTag); if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); } else { cur.wakelockTag = null; } if (wakeReasonIndex != 0xffff) { cur.wakeReasonTag = cur.localWakeReasonTag; readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); } else { cur.wakeReasonTag = null; } cur.numReadInts += 1; } else { cur.wakelockTag = null; cur.wakeReasonTag = null; } if ((firstToken&DELTA_EVENT_FLAG) != 0) { cur.eventTag = cur.localEventTag; Loading Loading @@ -1944,6 +1972,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 && (mHistoryLastWritten.wakelockTag == null || mHistoryCur.wakelockTag == null) && (mHistoryLastWritten.wakeReasonTag == null || mHistoryCur.wakeReasonTag == null) && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE || mHistoryCur.eventCode == HistoryItem.EVENT_NONE) && mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel Loading @@ -1968,6 +1997,13 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; mHistoryCur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); } // If the last written history had a wake reason tag, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have a wakelock tag. if (mHistoryLastWritten.wakeReasonTag != null) { mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; mHistoryCur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); } // If the last written history had an event, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have an event. Loading Loading @@ -2016,6 +2052,7 @@ public final class BatteryStatsImpl extends BatteryStats { writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); mLastHistoryTime = curTime; mHistoryCur.wakelockTag = null; mHistoryCur.wakeReasonTag = null; mHistoryCur.eventCode = HistoryItem.EVENT_NONE; mHistoryCur.eventTag = null; if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos Loading Loading @@ -2304,6 +2341,16 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void noteWakeupReasonLocked(int irq, String reason) { final long elapsedRealtime = SystemClock.elapsedRealtime(); if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason irq #" + irq + "\"" + reason +"\": " + Integer.toHexString(mHistoryCur.states)); mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; mHistoryCur.wakeReasonTag.string = reason; mHistoryCur.wakeReasonTag.uid = irq; addHistoryRecordLocked(elapsedRealtime); } public int startAddingCpuLocked() { mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); Loading Loading @@ -7219,8 +7266,7 @@ public final class BatteryStatsImpl extends BatteryStats { pullPendingStateUpdatesLocked(); } public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { if (DEBUG) { pw.println("mOnBatteryTimeBase:"); mOnBatteryTimeBase.dump(pw, " "); Loading Loading @@ -7264,6 +7310,6 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i].logState(pr, " "); } } super.dumpLocked(context, pw, isUnpluggedOnly, reqUid, historyOnly); super.dumpLocked(context, pw, flags, reqUid, histStart); } } services/core/java/com/android/server/AlarmManagerService.java +4 −1 Original line number Diff line number Diff line Loading @@ -1283,7 +1283,10 @@ class AlarmManagerService extends SystemService { setWakelockWorkSource(alarm.operation, alarm.workSource); mWakeLock.setUnimportantForLogging( alarm.operation == mTimeTickSender); mWakeLock.setHistoryTag(alarm.operation.getTag("*alarm*:")); mWakeLock.setHistoryTag(alarm.operation.getTag( alarm.type == ELAPSED_REALTIME_WAKEUP || alarm.type == RTC_WAKEUP ? "*walarm*:" : "*alarm*:")); mWakeLock.acquire(); } final InFlight inflight = new InFlight(AlarmManagerService.this, Loading services/core/java/com/android/server/am/BatteryStatsService.java +58 −14 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/jni/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ LOCAL_CFLAGS += -Wno-unused-parameter LOCAL_SRC_FILES += \ $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_am_BatteryStatsService.cpp \ $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \ $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \ $(LOCAL_REL_DIR)/com_android_server_dreams_McuHal.cpp \ Loading Loading
core/java/android/os/BatteryStats.java +204 −121 Original line number Diff line number Diff line Loading @@ -578,6 +578,9 @@ public abstract class BatteryStats implements Parcelable { // The wake lock that was acquired at this point. public HistoryTag wakelockTag; // Kernel wakeup reason at this point. public HistoryTag wakeReasonTag; public static final int EVENT_FLAG_START = 0x8000; public static final int EVENT_FLAG_FINISH = 0x4000; Loading Loading @@ -612,6 +615,7 @@ public abstract class BatteryStats implements Parcelable { // Pre-allocated objects. public final HistoryTag localWakelockTag = new HistoryTag(); public final HistoryTag localWakeReasonTag = new HistoryTag(); public final HistoryTag localEventTag = new HistoryTag(); public HistoryItem() { Loading Loading @@ -645,6 +649,12 @@ public abstract class BatteryStats implements Parcelable { } else { dest.writeInt(0); } if (wakeReasonTag != null) { dest.writeInt(1); wakeReasonTag.writeToParcel(dest, flags); } else { dest.writeInt(0); } dest.writeInt(eventCode); if (eventCode != EVENT_NONE) { dest.writeInt(eventCode); Loading @@ -670,6 +680,12 @@ public abstract class BatteryStats implements Parcelable { } else { wakelockTag = null; } if (src.readInt() != 0) { wakeReasonTag = localWakeReasonTag; wakeReasonTag.readFromParcel(src); } else { wakeReasonTag = null; } eventCode = src.readInt(); if (eventCode != EVENT_NONE) { eventTag = localEventTag; Loading @@ -689,6 +705,7 @@ public abstract class BatteryStats implements Parcelable { batteryVoltage = 0; states = 0; wakelockTag = null; wakeReasonTag = null; eventCode = EVENT_NONE; eventTag = null; } Loading Loading @@ -719,6 +736,12 @@ public abstract class BatteryStats implements Parcelable { } else { wakelockTag = null; } if (o.wakeReasonTag != null) { wakeReasonTag = localWakeReasonTag; wakeReasonTag.setTo(o.wakeReasonTag); } else { wakeReasonTag = null; } eventCode = o.eventCode; if (o.eventTag != null) { eventTag = localEventTag; Loading Loading @@ -750,6 +773,14 @@ public abstract class BatteryStats implements Parcelable { return false; } } if (wakeReasonTag != o.wakeReasonTag) { if (wakeReasonTag == null || o.wakeReasonTag == null) { return false; } if (!wakeReasonTag.equals(o.wakeReasonTag)) { return false; } } if (eventTag != o.eventTag) { if (eventTag == null || o.eventTag == null) { return false; Loading Loading @@ -1916,51 +1947,6 @@ public abstract class BatteryStats implements Parcelable { long fullWakeLockTimeTotalMicros = 0; long partialWakeLockTimeTotalMicros = 0; final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { @Override public int compare(TimerEntry lhs, TimerEntry rhs) { long lhsTime = lhs.mTime; long rhsTime = rhs.mTime; if (lhsTime < rhsTime) { return 1; } if (lhsTime > rhsTime) { return -1; } return 0; } }; if (reqUid < 0) { Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); if (kernelWakelocks.size() > 0) { final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { BatteryStats.Timer timer = ent.getValue(); long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); if (totalTimeMillis > 0) { timers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); } } Collections.sort(timers, timerComparator); for (int i=0; i<timers.size(); i++) { TimerEntry timer = timers.get(i); String linePrefix = ": "; sb.setLength(0); sb.append(prefix); sb.append(" Kernel Wake lock "); sb.append(timer.mName); linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, which, linePrefix); if (!linePrefix.equals(": ")) { sb.append(" realtime"); // Only print out wake locks that were held pw.println(sb.toString()); } } } } final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); for (int iu = 0; iu < NU; iu++) { Loading Loading @@ -2292,6 +2278,55 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { @Override public int compare(TimerEntry lhs, TimerEntry rhs) { long lhsTime = lhs.mTime; long rhsTime = rhs.mTime; if (lhsTime < rhsTime) { return 1; } if (lhsTime > rhsTime) { return -1; } return 0; } }; if (reqUid < 0) { Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); if (kernelWakelocks.size() > 0) { final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>(); for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { BatteryStats.Timer timer = ent.getValue(); long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); if (totalTimeMillis > 0) { ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); } } if (ktimers.size() > 0) { Collections.sort(ktimers, timerComparator); pw.print(prefix); pw.println(" All kernel wake locks:"); for (int i=0; i<ktimers.size(); i++) { TimerEntry timer = ktimers.get(i); String linePrefix = ": "; sb.setLength(0); sb.append(prefix); sb.append(" Kernel Wake lock "); sb.append(timer.mName); linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, which, linePrefix); if (!linePrefix.equals(": ")) { sb.append(" realtime"); // Only print out wake locks that were held pw.println(sb.toString()); } } pw.println(); } } } if (timers.size() > 0) { Collections.sort(timers, timerComparator); pw.print(prefix); pw.println(" All partial wake locks:"); Loading Loading @@ -2727,14 +2762,22 @@ public abstract class BatteryStats implements Parcelable { public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin) { 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); } 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); } } else { pw.print(rec.time-lastTime); } Loading Loading @@ -2858,6 +2901,18 @@ public abstract class BatteryStats implements Parcelable { } printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, HISTORY_STATE_DESCRIPTIONS, !checkin); if (rec.wakeReasonTag != null) { if (checkin) { pw.print(",Wr="); pw.print(rec.wakeReasonTag.poolIdx); } else { pw.print(" wake_reason="); pw.print(rec.wakeReasonTag.uid); pw.print(":\""); pw.print(rec.wakeReasonTag.string); pw.print("\""); } } if (rec.eventCode != HistoryItem.EVENT_NONE) { pw.print(checkin ? "," : " "); if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { Loading Loading @@ -2918,16 +2973,24 @@ public abstract class BatteryStats implements Parcelable { pw.print(suffix); } public static final int DUMP_UNPLUGGED_ONLY = 1<<0; public static final int DUMP_CHARGED_ONLY = 1<<1; public static final int DUMP_HISTORY_ONLY = 1<<2; public static final int DUMP_INCLUDE_HISTORY = 1<<3; /** * Dumps a human-readable summary of the battery statistics to the given PrintWriter. * * @param pw a Printer to receive the dump output. */ @SuppressWarnings("unused") public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { prepareForDumpLocked(); final boolean filtering = (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); final HistoryItem rec = new HistoryItem(); Loading @@ -2947,8 +3010,15 @@ public abstract class BatteryStats implements Parcelable { printSizeValue(pw, getHistoryStringPoolBytes()); pw.println("):"); HistoryPrinter hprinter = new HistoryPrinter(); long lastTime = -1; while (getNextHistoryLocked(rec)) { hprinter.printNextItem(pw, rec, now, false); lastTime = rec.time; if (rec.time >= histStart) { hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false); } } if (histStart >= 0) { pw.print(" NEXT: "); pw.println(lastTime+1); } pw.println(); } finally { Loading @@ -2968,11 +3038,13 @@ public abstract class BatteryStats implements Parcelable { finishIteratingOldHistoryLocked(); } } } if (historyOnly) { if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { return; } if (!filtering) { SparseArray<? extends Uid> uidStats = getUidStats(); final int NU = uidStats.size(); boolean didPid = false; Loading @@ -2999,27 +3071,32 @@ public abstract class BatteryStats implements Parcelable { if (didPid) { pw.println(""); } } if (!isUnpluggedOnly) { if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { pw.println("Statistics since last charge:"); pw.println(" System starts: " + getStartCount() + ", currently on battery: " + getIsOnBattery()); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); pw.println(""); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { pw.println("Statistics since last unplugged:"); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); } } @SuppressWarnings("unused") public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly, boolean includeHistory, boolean historyOnly) { public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, int flags, long histStart) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); if (includeHistory || historyOnly) { final boolean filtering = (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { try { Loading @@ -3034,10 +3111,17 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } HistoryPrinter hprinter = new HistoryPrinter(); long lastTime = -1; while (getNextHistoryLocked(rec)) { lastTime = rec.time; if (rec.time >= histStart) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); pw.print(HISTORY_DATA); pw.print(','); hprinter.printNextItem(pw, rec, now, true); hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true); } } if (histStart >= 0) { pw.print("NEXT: "); pw.println(lastTime+1); } } finally { finishIteratingHistoryLocked(); Loading @@ -3045,7 +3129,7 @@ public abstract class BatteryStats implements Parcelable { } } if (historyOnly) { if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { return; } Loading Loading @@ -3076,11 +3160,10 @@ public abstract class BatteryStats implements Parcelable { } } } if (isUnpluggedOnly) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); } else { if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); } } Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +62 −16 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 97 + (USE_OLD_HISTORY ? 1000 : 0); private static final int VERSION = 98 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; Loading Loading @@ -1712,7 +1712,7 @@ public final class BatteryStatsImpl extends BatteryStats { static final int DELTA_STATE_FLAG = 0x00100000; // Flag in delta int: a new full state2 int follows. static final int DELTA_STATE2_FLAG = 0x00200000; // Flag in delta int: contains a wakelock tag. // Flag in delta int: contains a wakelock or wakeReason tag. static final int DELTA_WAKELOCK_FLAG = 0x00400000; // Flag in delta int: contains an event description. static final int DELTA_EVENT_FLAG = 0x00800000; Loading Loading @@ -1759,7 +1759,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (stateIntChanged) { firstToken |= DELTA_STATE_FLAG; } if (cur.wakelockTag != null) { if (cur.wakelockTag != null || cur.wakeReasonTag != null) { firstToken |= DELTA_WAKELOCK_FLAG; } if (cur.eventCode != HistoryItem.EVENT_NONE) { Loading Loading @@ -1795,11 +1795,24 @@ public final class BatteryStatsImpl extends BatteryStats { + " batteryPlugType=" + cur.batteryPlugType + " states=0x" + Integer.toHexString(cur.states)); } if (cur.wakelockTag != null || cur.wakeReasonTag != null) { int wakeLockIndex; int wakeReasonIndex; if (cur.wakelockTag != null) { int index = writeHistoryTag(cur.wakelockTag); dest.writeInt(index); wakeLockIndex = writeHistoryTag(cur.wakelockTag); if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); } else { wakeLockIndex = 0xffff; } if (cur.wakeReasonTag != null) { wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); } else { wakeReasonIndex = 0xffff; } dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); } if (cur.eventCode != HistoryItem.EVENT_NONE) { int index = writeHistoryTag(cur.eventTag); Loading Loading @@ -1905,15 +1918,30 @@ public final class BatteryStatsImpl extends BatteryStats { } if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { int indexes = src.readInt(); int wakeLockIndex = indexes&0xffff; int wakeReasonIndex = (indexes>>16)&0xffff; if (wakeLockIndex != 0xffff) { cur.wakelockTag = cur.localWakelockTag; int index = src.readInt(); readHistoryTag(index, cur.wakelockTag); cur.numReadInts += 1; readHistoryTag(wakeLockIndex, cur.wakelockTag); if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); } else { cur.wakelockTag = null; } if (wakeReasonIndex != 0xffff) { cur.wakeReasonTag = cur.localWakeReasonTag; readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); } else { cur.wakeReasonTag = null; } cur.numReadInts += 1; } else { cur.wakelockTag = null; cur.wakeReasonTag = null; } if ((firstToken&DELTA_EVENT_FLAG) != 0) { cur.eventTag = cur.localEventTag; Loading Loading @@ -1944,6 +1972,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 && (mHistoryLastWritten.wakelockTag == null || mHistoryCur.wakelockTag == null) && (mHistoryLastWritten.wakeReasonTag == null || mHistoryCur.wakeReasonTag == null) && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE || mHistoryCur.eventCode == HistoryItem.EVENT_NONE) && mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel Loading @@ -1968,6 +1997,13 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; mHistoryCur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); } // If the last written history had a wake reason tag, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have a wakelock tag. if (mHistoryLastWritten.wakeReasonTag != null) { mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; mHistoryCur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); } // If the last written history had an event, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have an event. Loading Loading @@ -2016,6 +2052,7 @@ public final class BatteryStatsImpl extends BatteryStats { writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); mLastHistoryTime = curTime; mHistoryCur.wakelockTag = null; mHistoryCur.wakeReasonTag = null; mHistoryCur.eventCode = HistoryItem.EVENT_NONE; mHistoryCur.eventTag = null; if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos Loading Loading @@ -2304,6 +2341,16 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void noteWakeupReasonLocked(int irq, String reason) { final long elapsedRealtime = SystemClock.elapsedRealtime(); if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason irq #" + irq + "\"" + reason +"\": " + Integer.toHexString(mHistoryCur.states)); mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; mHistoryCur.wakeReasonTag.string = reason; mHistoryCur.wakeReasonTag.uid = irq; addHistoryRecordLocked(elapsedRealtime); } public int startAddingCpuLocked() { mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); Loading Loading @@ -7219,8 +7266,7 @@ public final class BatteryStatsImpl extends BatteryStats { pullPendingStateUpdatesLocked(); } public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { if (DEBUG) { pw.println("mOnBatteryTimeBase:"); mOnBatteryTimeBase.dump(pw, " "); Loading Loading @@ -7264,6 +7310,6 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i].logState(pr, " "); } } super.dumpLocked(context, pw, isUnpluggedOnly, reqUid, historyOnly); super.dumpLocked(context, pw, flags, reqUid, histStart); } }
services/core/java/com/android/server/AlarmManagerService.java +4 −1 Original line number Diff line number Diff line Loading @@ -1283,7 +1283,10 @@ class AlarmManagerService extends SystemService { setWakelockWorkSource(alarm.operation, alarm.workSource); mWakeLock.setUnimportantForLogging( alarm.operation == mTimeTickSender); mWakeLock.setHistoryTag(alarm.operation.getTag("*alarm*:")); mWakeLock.setHistoryTag(alarm.operation.getTag( alarm.type == ELAPSED_REALTIME_WAKEUP || alarm.type == RTC_WAKEUP ? "*walarm*:" : "*alarm*:")); mWakeLock.acquire(); } final InFlight inflight = new InFlight(AlarmManagerService.this, Loading
services/core/java/com/android/server/am/BatteryStatsService.java +58 −14 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/jni/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ LOCAL_CFLAGS += -Wno-unused-parameter LOCAL_SRC_FILES += \ $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_am_BatteryStatsService.cpp \ $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \ $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \ $(LOCAL_REL_DIR)/com_android_server_dreams_McuHal.cpp \ Loading