Loading core/java/android/os/BatteryStats.java +60 −10 Original line number Diff line number Diff line Loading @@ -458,6 +458,20 @@ public abstract class BatteryStats implements Parcelable { */ public abstract int getStarts(int which); /** * Returns the number of times the process has crashed. * * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getNumCrashes(int which); /** * Returns the number of times the process has ANRed. * * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getNumAnrs(int which); /** * Returns the cpu time spent in microseconds while the process was in the foreground. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. Loading Loading @@ -694,8 +708,10 @@ public abstract class BatteryStats implements Parcelable { public static final int EVENT_USER_RUNNING = 0x0007; // Events for foreground user. public static final int EVENT_USER_FOREGROUND = 0x0008; // Events for connectivity changed. public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; // Number of event types. public static final int EVENT_COUNT = 0x0009; public static final int EVENT_COUNT = 0x000a; // Mask to extract out only the type part of the event. public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH); Loading Loading @@ -1106,6 +1122,13 @@ public abstract class BatteryStats implements Parcelable { */ public abstract int getLowPowerModeEnabledCount(int which); /** * Returns the number of times that connectivity state changed. * * {@hide} */ public abstract int getNumConnectivityChange(int which); /** * Returns the time in microseconds that the phone has been on while the device was * running on battery. Loading Loading @@ -1306,11 +1329,11 @@ public abstract class BatteryStats implements Parcelable { }; public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg" "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn" }; public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf" "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn" }; /** Loading Loading @@ -1871,6 +1894,7 @@ public abstract class BatteryStats implements Parcelable { final long screenOnTime = getScreenOnTime(rawRealtime, which); final long interactiveTime = getInteractiveTime(rawRealtime, which); final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which); final int connChanges = getNumConnectivityChange(which); final long phoneOnTime = getPhoneOnTime(rawRealtime, which); final long wifiOnTime = getWifiOnTime(rawRealtime, which); final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); Loading Loading @@ -1941,7 +1965,7 @@ public abstract class BatteryStats implements Parcelable { fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000, getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, lowPowerModeEnabledTime / 1000); lowPowerModeEnabledTime / 1000, connChanges); // Dump screen brightness stats Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; Loading Loading @@ -2271,12 +2295,14 @@ public abstract class BatteryStats implements Parcelable { final long userMillis = ps.getUserTime(which) * 10; final long systemMillis = ps.getSystemTime(which) * 10; final long foregroundMillis = ps.getForegroundTime(which) * 10; final long starts = ps.getStarts(which); final int starts = ps.getStarts(which); final int numCrashes = ps.getNumCrashes(which); final int numAnrs = ps.getNumAnrs(which); if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 || starts != 0) { || starts != 0 || numAnrs != 0 || numCrashes != 0) { dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis, systemMillis, foregroundMillis, starts); systemMillis, foregroundMillis, starts, numAnrs, numCrashes); } } } Loading Loading @@ -2457,6 +2483,11 @@ public abstract class BatteryStats implements Parcelable { sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); sb.append(") "); sb.append(getPhoneOnCount(which)); } int connChanges = getNumConnectivityChange(which); if (connChanges != 0) { pw.print(prefix); pw.print(" Connectivity changes: "); pw.println(connChanges); } // Calculate wakelock times across all uids. long fullWakeLockTimeTotalMicros = 0; Loading Loading @@ -3273,11 +3304,13 @@ public abstract class BatteryStats implements Parcelable { systemTime = ps.getSystemTime(which); foregroundTime = ps.getForegroundTime(which); starts = ps.getStarts(which); final int numCrashes = ps.getNumCrashes(which); final int numAnrs = ps.getNumAnrs(which); numExcessive = which == STATS_SINCE_CHARGED ? ps.countExcessivePowers() : 0; if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 || numExcessive != 0) { || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { sb.setLength(0); sb.append(prefix); sb.append(" Proc "); sb.append(ent.getKey()); sb.append(":\n"); Loading @@ -3285,9 +3318,26 @@ public abstract class BatteryStats implements Parcelable { formatTime(sb, userTime); sb.append("usr + "); formatTime(sb, systemTime); sb.append("krn ; "); formatTime(sb, foregroundTime); sb.append("fg"); if (starts != 0) { if (starts != 0 || numCrashes != 0 || numAnrs != 0) { sb.append("\n"); sb.append(prefix); sb.append(" "); sb.append(starts); sb.append(" proc starts"); boolean hasOne = false; if (starts != 0) { hasOne = true; sb.append(starts); sb.append(" starts"); } if (numCrashes != 0) { if (hasOne) { sb.append(", "); } hasOne = true; sb.append(numCrashes); sb.append(" crashes"); } if (numAnrs != 0) { if (hasOne) { sb.append(", "); } sb.append(numAnrs); sb.append(" anrs"); } } pw.println(sb.toString()); for (int e=0; e<numExcessive; e++) { Loading core/java/android/util/Log.java +5 −0 Original line number Diff line number Diff line Loading @@ -295,6 +295,11 @@ public final class Log { return bytes; } static void wtfQuiet(int logId, String tag, String msg, boolean system) { TerribleFailure what = new TerribleFailure(msg, null); sWtfHandler.onTerribleFailure(tag, what, system); } /** * Sets the terrible failure handler, for testing. * Loading core/java/android/util/Slog.java +7 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,13 @@ public final class Slog { return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, false, true); } /** * Like {@link #wtf(String, String)}, but does not output anything to the log. */ public static void wtfQuiet(String tag, String msg) { Log.wtfQuiet(Log.LOG_ID_SYSTEM, tag, msg, true); } /** * Like {@link Log#wtfStack(String, String)}, but will never cause the caller to crash, and * will always be handled asynchronously. Primarily for use by coding running within Loading core/java/com/android/internal/app/IBatteryStats.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ interface IBatteryStats { void noteScreenBrightness(int brightness); void noteUserActivity(int uid, int event); void noteInteractive(boolean interactive); void noteConnectivityChanged(int type, String extra); void noteMobileRadioPowerState(int powerState, long timestampNs); void notePhoneOn(); void notePhoneOff(); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +123 −24 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 115 + (USE_OLD_HISTORY ? 1000 : 0); private static final int VERSION = 116 + (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 @@ -374,6 +374,10 @@ public final class BatteryStatsImpl extends BatteryStats { private int mPhoneServiceStateRaw = -1; private int mPhoneSimStateRaw = -1; private int mNumConnectivityChange; private int mLoadedNumConnectivityChange; private int mUnpluggedNumConnectivityChange; /* * Holds a SamplingTimer associated with each kernel wakelock name being tracked. */ Loading Loading @@ -2540,6 +2544,22 @@ public final class BatteryStatsImpl extends BatteryStats { addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); } public void noteProcessCrashLocked(String name, int uid) { uid = mapUid(uid); if (isOnBattery()) { Uid u = getUidStatsLocked(uid); u.getProcessStatsLocked(name).incNumCrashesLocked(); } } public void noteProcessAnrLocked(String name, int uid) { uid = mapUid(uid); if (isOnBattery()) { Uid u = getUidStatsLocked(uid); u.getProcessStatsLocked(name).incNumAnrsLocked(); } } public void noteProcessStateLocked(String name, int uid, int state) { uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); Loading Loading @@ -3109,6 +3129,14 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void noteConnectivityChangedLocked(int type, String extra) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, extra, type); mNumConnectivityChange++; } public void noteMobileRadioPowerState(int powerState, long timestampNs) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); Loading Loading @@ -3965,6 +3993,16 @@ public final class BatteryStatsImpl extends BatteryStats { return mLowPowerModeEnabledTimer.getCountLocked(which); } @Override public int getNumConnectivityChange(int which) { int val = mNumConnectivityChange; if (which == STATS_CURRENT) { val -= mLoadedNumConnectivityChange; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumConnectivityChange; } return val; } @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); } Loading Loading @@ -5373,6 +5411,16 @@ public final class BatteryStatsImpl extends BatteryStats { */ int mStarts; /** * Number of times the process has crashed. */ int mNumCrashes; /** * Number of times the process has had an ANR. */ int mNumAnrs; /** * The amount of user time loaded from a previous save. */ Loading @@ -5394,24 +5442,14 @@ public final class BatteryStatsImpl extends BatteryStats { int mLoadedStarts; /** * The amount of user time loaded from the previous run. */ long mLastUserTime; /** * The amount of system time loaded from the previous run. */ long mLastSystemTime; /** * The amount of foreground time loaded from the previous run * Number of times the process has crashed from a previous save. */ long mLastForegroundTime; int mLoadedNumCrashes; /** * The number of times the process has started from the previous run. * Number of times the process has had an ANR from a previous save. */ int mLastStarts; int mLoadedNumAnrs; /** * The amount of user time when last unplugged. Loading @@ -5433,6 +5471,16 @@ public final class BatteryStatsImpl extends BatteryStats { */ int mUnpluggedStarts; /** * Number of times the process has crashed before unplugged. */ int mUnpluggedNumCrashes; /** * Number of times the process has had an ANR before unplugged. */ int mUnpluggedNumAnrs; /** * Current process state. */ Loading @@ -5453,6 +5501,8 @@ public final class BatteryStatsImpl extends BatteryStats { mUnpluggedSystemTime = mSystemTime; mUnpluggedForegroundTime = mForegroundTime; mUnpluggedStarts = mStarts; mUnpluggedNumCrashes = mNumCrashes; mUnpluggedNumAnrs = mNumAnrs; } public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { Loading @@ -5460,13 +5510,11 @@ public final class BatteryStatsImpl extends BatteryStats { void reset() { mUserTime = mSystemTime = mForegroundTime = 0; mStarts = 0; mStarts = mNumCrashes = mNumAnrs = 0; mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; mLoadedStarts = 0; mLastUserTime = mLastSystemTime = mLastForegroundTime = 0; mLastStarts = 0; mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; mUnpluggedStarts = 0; mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; for (int i = 0; i < mSpeedBins.length; i++) { SamplingCounter c = mSpeedBins[i]; if (c != null) { Loading Loading @@ -5565,14 +5613,20 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mSystemTime); out.writeLong(mForegroundTime); out.writeInt(mStarts); out.writeInt(mNumCrashes); out.writeInt(mNumAnrs); out.writeLong(mLoadedUserTime); out.writeLong(mLoadedSystemTime); out.writeLong(mLoadedForegroundTime); out.writeInt(mLoadedStarts); out.writeInt(mLoadedNumCrashes); out.writeInt(mLoadedNumAnrs); out.writeLong(mUnpluggedUserTime); out.writeLong(mUnpluggedSystemTime); out.writeLong(mUnpluggedForegroundTime); out.writeInt(mUnpluggedStarts); out.writeInt(mUnpluggedNumCrashes); out.writeInt(mUnpluggedNumAnrs); out.writeInt(mSpeedBins.length); for (int i = 0; i < mSpeedBins.length; i++) { Loading @@ -5593,18 +5647,20 @@ public final class BatteryStatsImpl extends BatteryStats { mSystemTime = in.readLong(); mForegroundTime = in.readLong(); mStarts = in.readInt(); mNumCrashes = in.readInt(); mNumAnrs = in.readInt(); mLoadedUserTime = in.readLong(); mLoadedSystemTime = in.readLong(); mLoadedForegroundTime = in.readLong(); mLoadedStarts = in.readInt(); mLastUserTime = 0; mLastSystemTime = 0; mLastForegroundTime = 0; mLastStarts = 0; mLoadedNumCrashes = in.readInt(); mLoadedNumAnrs = in.readInt(); mUnpluggedUserTime = in.readLong(); mUnpluggedSystemTime = in.readLong(); mUnpluggedForegroundTime = in.readLong(); mUnpluggedStarts = in.readInt(); mUnpluggedNumCrashes = in.readInt(); mUnpluggedNumAnrs = in.readInt(); int bins = in.readInt(); int steps = getCpuSpeedSteps(); Loading Loading @@ -5635,6 +5691,14 @@ public final class BatteryStatsImpl extends BatteryStats { mStarts++; } public void incNumCrashesLocked() { mNumCrashes++; } public void incNumAnrsLocked() { mNumAnrs++; } @Override public boolean isActive() { return mActive; Loading Loading @@ -5684,6 +5748,28 @@ public final class BatteryStatsImpl extends BatteryStats { return val; } @Override public int getNumCrashes(int which) { int val = mNumCrashes; if (which == STATS_CURRENT) { val -= mLoadedNumCrashes; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumCrashes; } return val; } @Override public int getNumAnrs(int which) { int val = mNumAnrs; if (which == STATS_CURRENT) { val -= mLoadedNumAnrs; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumAnrs; } return val; } /* Called by ActivityManagerService when CPU times are updated. */ public void addSpeedStepTimes(long[] values) { for (int i = 0; i < mSpeedBins.length && i < values.length; i++) { Loading Loading @@ -6647,6 +6733,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].reset(false); } mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; for (int i=0; i<mUidStats.size(); i++) { if (mUidStats.valueAt(i).reset()) { Loading Loading @@ -7861,6 +7948,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].readSummaryFromParcelLocked(in); } mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); mFlashlightOn = false; mFlashlightOnTimer.readSummaryFromParcelLocked(in); Loading Loading @@ -8022,6 +8110,8 @@ public final class BatteryStatsImpl extends BatteryStats { p.mSystemTime = p.mLoadedSystemTime = in.readLong(); p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); p.mStarts = p.mLoadedStarts = in.readInt(); p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); int NSB = in.readInt(); if (NSB > 100) { Slog.w(TAG, "File corrupt: too many speed bins " + NSB); Loading Loading @@ -8143,6 +8233,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); } out.writeInt(mNumConnectivityChange); mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); out.writeInt(mKernelWakelockStats.size()); Loading Loading @@ -8326,6 +8417,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(ps.mSystemTime); out.writeLong(ps.mForegroundTime); out.writeInt(ps.mStarts); out.writeInt(ps.mNumCrashes); out.writeInt(ps.mNumAnrs); final int N = ps.mSpeedBins.length; out.writeInt(N); for (int i=0; i<N; i++) { Loading Loading @@ -8444,6 +8537,9 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase, in); } mNumConnectivityChange = in.readInt(); mLoadedNumConnectivityChange = in.readInt(); mUnpluggedNumConnectivityChange = in.readInt(); mAudioOnNesting = 0; mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mVideoOnNesting = 0; Loading Loading @@ -8588,6 +8684,9 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime); } out.writeInt(mNumConnectivityChange); out.writeInt(mLoadedNumConnectivityChange); out.writeInt(mUnpluggedNumConnectivityChange); mFlashlightOnTimer.writeToParcel(out, uSecRealtime); out.writeInt(mDischargeUnplugLevel); out.writeInt(mDischargePlugLevel); Loading Loading
core/java/android/os/BatteryStats.java +60 −10 Original line number Diff line number Diff line Loading @@ -458,6 +458,20 @@ public abstract class BatteryStats implements Parcelable { */ public abstract int getStarts(int which); /** * Returns the number of times the process has crashed. * * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getNumCrashes(int which); /** * Returns the number of times the process has ANRed. * * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getNumAnrs(int which); /** * Returns the cpu time spent in microseconds while the process was in the foreground. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. Loading Loading @@ -694,8 +708,10 @@ public abstract class BatteryStats implements Parcelable { public static final int EVENT_USER_RUNNING = 0x0007; // Events for foreground user. public static final int EVENT_USER_FOREGROUND = 0x0008; // Events for connectivity changed. public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; // Number of event types. public static final int EVENT_COUNT = 0x0009; public static final int EVENT_COUNT = 0x000a; // Mask to extract out only the type part of the event. public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH); Loading Loading @@ -1106,6 +1122,13 @@ public abstract class BatteryStats implements Parcelable { */ public abstract int getLowPowerModeEnabledCount(int which); /** * Returns the number of times that connectivity state changed. * * {@hide} */ public abstract int getNumConnectivityChange(int which); /** * Returns the time in microseconds that the phone has been on while the device was * running on battery. Loading Loading @@ -1306,11 +1329,11 @@ public abstract class BatteryStats implements Parcelable { }; public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg" "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn" }; public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf" "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn" }; /** Loading Loading @@ -1871,6 +1894,7 @@ public abstract class BatteryStats implements Parcelable { final long screenOnTime = getScreenOnTime(rawRealtime, which); final long interactiveTime = getInteractiveTime(rawRealtime, which); final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which); final int connChanges = getNumConnectivityChange(which); final long phoneOnTime = getPhoneOnTime(rawRealtime, which); final long wifiOnTime = getWifiOnTime(rawRealtime, which); final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); Loading Loading @@ -1941,7 +1965,7 @@ public abstract class BatteryStats implements Parcelable { fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000, getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, lowPowerModeEnabledTime / 1000); lowPowerModeEnabledTime / 1000, connChanges); // Dump screen brightness stats Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; Loading Loading @@ -2271,12 +2295,14 @@ public abstract class BatteryStats implements Parcelable { final long userMillis = ps.getUserTime(which) * 10; final long systemMillis = ps.getSystemTime(which) * 10; final long foregroundMillis = ps.getForegroundTime(which) * 10; final long starts = ps.getStarts(which); final int starts = ps.getStarts(which); final int numCrashes = ps.getNumCrashes(which); final int numAnrs = ps.getNumAnrs(which); if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 || starts != 0) { || starts != 0 || numAnrs != 0 || numCrashes != 0) { dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis, systemMillis, foregroundMillis, starts); systemMillis, foregroundMillis, starts, numAnrs, numCrashes); } } } Loading Loading @@ -2457,6 +2483,11 @@ public abstract class BatteryStats implements Parcelable { sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); sb.append(") "); sb.append(getPhoneOnCount(which)); } int connChanges = getNumConnectivityChange(which); if (connChanges != 0) { pw.print(prefix); pw.print(" Connectivity changes: "); pw.println(connChanges); } // Calculate wakelock times across all uids. long fullWakeLockTimeTotalMicros = 0; Loading Loading @@ -3273,11 +3304,13 @@ public abstract class BatteryStats implements Parcelable { systemTime = ps.getSystemTime(which); foregroundTime = ps.getForegroundTime(which); starts = ps.getStarts(which); final int numCrashes = ps.getNumCrashes(which); final int numAnrs = ps.getNumAnrs(which); numExcessive = which == STATS_SINCE_CHARGED ? ps.countExcessivePowers() : 0; if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 || numExcessive != 0) { || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { sb.setLength(0); sb.append(prefix); sb.append(" Proc "); sb.append(ent.getKey()); sb.append(":\n"); Loading @@ -3285,9 +3318,26 @@ public abstract class BatteryStats implements Parcelable { formatTime(sb, userTime); sb.append("usr + "); formatTime(sb, systemTime); sb.append("krn ; "); formatTime(sb, foregroundTime); sb.append("fg"); if (starts != 0) { if (starts != 0 || numCrashes != 0 || numAnrs != 0) { sb.append("\n"); sb.append(prefix); sb.append(" "); sb.append(starts); sb.append(" proc starts"); boolean hasOne = false; if (starts != 0) { hasOne = true; sb.append(starts); sb.append(" starts"); } if (numCrashes != 0) { if (hasOne) { sb.append(", "); } hasOne = true; sb.append(numCrashes); sb.append(" crashes"); } if (numAnrs != 0) { if (hasOne) { sb.append(", "); } sb.append(numAnrs); sb.append(" anrs"); } } pw.println(sb.toString()); for (int e=0; e<numExcessive; e++) { Loading
core/java/android/util/Log.java +5 −0 Original line number Diff line number Diff line Loading @@ -295,6 +295,11 @@ public final class Log { return bytes; } static void wtfQuiet(int logId, String tag, String msg, boolean system) { TerribleFailure what = new TerribleFailure(msg, null); sWtfHandler.onTerribleFailure(tag, what, system); } /** * Sets the terrible failure handler, for testing. * Loading
core/java/android/util/Slog.java +7 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,13 @@ public final class Slog { return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, false, true); } /** * Like {@link #wtf(String, String)}, but does not output anything to the log. */ public static void wtfQuiet(String tag, String msg) { Log.wtfQuiet(Log.LOG_ID_SYSTEM, tag, msg, true); } /** * Like {@link Log#wtfStack(String, String)}, but will never cause the caller to crash, and * will always be handled asynchronously. Primarily for use by coding running within Loading
core/java/com/android/internal/app/IBatteryStats.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ interface IBatteryStats { void noteScreenBrightness(int brightness); void noteUserActivity(int uid, int event); void noteInteractive(boolean interactive); void noteConnectivityChanged(int type, String extra); void noteMobileRadioPowerState(int powerState, long timestampNs); void notePhoneOn(); void notePhoneOff(); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +123 −24 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 115 + (USE_OLD_HISTORY ? 1000 : 0); private static final int VERSION = 116 + (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 @@ -374,6 +374,10 @@ public final class BatteryStatsImpl extends BatteryStats { private int mPhoneServiceStateRaw = -1; private int mPhoneSimStateRaw = -1; private int mNumConnectivityChange; private int mLoadedNumConnectivityChange; private int mUnpluggedNumConnectivityChange; /* * Holds a SamplingTimer associated with each kernel wakelock name being tracked. */ Loading Loading @@ -2540,6 +2544,22 @@ public final class BatteryStatsImpl extends BatteryStats { addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); } public void noteProcessCrashLocked(String name, int uid) { uid = mapUid(uid); if (isOnBattery()) { Uid u = getUidStatsLocked(uid); u.getProcessStatsLocked(name).incNumCrashesLocked(); } } public void noteProcessAnrLocked(String name, int uid) { uid = mapUid(uid); if (isOnBattery()) { Uid u = getUidStatsLocked(uid); u.getProcessStatsLocked(name).incNumAnrsLocked(); } } public void noteProcessStateLocked(String name, int uid, int state) { uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); Loading Loading @@ -3109,6 +3129,14 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void noteConnectivityChangedLocked(int type, String extra) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, extra, type); mNumConnectivityChange++; } public void noteMobileRadioPowerState(int powerState, long timestampNs) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); Loading Loading @@ -3965,6 +3993,16 @@ public final class BatteryStatsImpl extends BatteryStats { return mLowPowerModeEnabledTimer.getCountLocked(which); } @Override public int getNumConnectivityChange(int which) { int val = mNumConnectivityChange; if (which == STATS_CURRENT) { val -= mLoadedNumConnectivityChange; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumConnectivityChange; } return val; } @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); } Loading Loading @@ -5373,6 +5411,16 @@ public final class BatteryStatsImpl extends BatteryStats { */ int mStarts; /** * Number of times the process has crashed. */ int mNumCrashes; /** * Number of times the process has had an ANR. */ int mNumAnrs; /** * The amount of user time loaded from a previous save. */ Loading @@ -5394,24 +5442,14 @@ public final class BatteryStatsImpl extends BatteryStats { int mLoadedStarts; /** * The amount of user time loaded from the previous run. */ long mLastUserTime; /** * The amount of system time loaded from the previous run. */ long mLastSystemTime; /** * The amount of foreground time loaded from the previous run * Number of times the process has crashed from a previous save. */ long mLastForegroundTime; int mLoadedNumCrashes; /** * The number of times the process has started from the previous run. * Number of times the process has had an ANR from a previous save. */ int mLastStarts; int mLoadedNumAnrs; /** * The amount of user time when last unplugged. Loading @@ -5433,6 +5471,16 @@ public final class BatteryStatsImpl extends BatteryStats { */ int mUnpluggedStarts; /** * Number of times the process has crashed before unplugged. */ int mUnpluggedNumCrashes; /** * Number of times the process has had an ANR before unplugged. */ int mUnpluggedNumAnrs; /** * Current process state. */ Loading @@ -5453,6 +5501,8 @@ public final class BatteryStatsImpl extends BatteryStats { mUnpluggedSystemTime = mSystemTime; mUnpluggedForegroundTime = mForegroundTime; mUnpluggedStarts = mStarts; mUnpluggedNumCrashes = mNumCrashes; mUnpluggedNumAnrs = mNumAnrs; } public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { Loading @@ -5460,13 +5510,11 @@ public final class BatteryStatsImpl extends BatteryStats { void reset() { mUserTime = mSystemTime = mForegroundTime = 0; mStarts = 0; mStarts = mNumCrashes = mNumAnrs = 0; mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; mLoadedStarts = 0; mLastUserTime = mLastSystemTime = mLastForegroundTime = 0; mLastStarts = 0; mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; mUnpluggedStarts = 0; mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; for (int i = 0; i < mSpeedBins.length; i++) { SamplingCounter c = mSpeedBins[i]; if (c != null) { Loading Loading @@ -5565,14 +5613,20 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mSystemTime); out.writeLong(mForegroundTime); out.writeInt(mStarts); out.writeInt(mNumCrashes); out.writeInt(mNumAnrs); out.writeLong(mLoadedUserTime); out.writeLong(mLoadedSystemTime); out.writeLong(mLoadedForegroundTime); out.writeInt(mLoadedStarts); out.writeInt(mLoadedNumCrashes); out.writeInt(mLoadedNumAnrs); out.writeLong(mUnpluggedUserTime); out.writeLong(mUnpluggedSystemTime); out.writeLong(mUnpluggedForegroundTime); out.writeInt(mUnpluggedStarts); out.writeInt(mUnpluggedNumCrashes); out.writeInt(mUnpluggedNumAnrs); out.writeInt(mSpeedBins.length); for (int i = 0; i < mSpeedBins.length; i++) { Loading @@ -5593,18 +5647,20 @@ public final class BatteryStatsImpl extends BatteryStats { mSystemTime = in.readLong(); mForegroundTime = in.readLong(); mStarts = in.readInt(); mNumCrashes = in.readInt(); mNumAnrs = in.readInt(); mLoadedUserTime = in.readLong(); mLoadedSystemTime = in.readLong(); mLoadedForegroundTime = in.readLong(); mLoadedStarts = in.readInt(); mLastUserTime = 0; mLastSystemTime = 0; mLastForegroundTime = 0; mLastStarts = 0; mLoadedNumCrashes = in.readInt(); mLoadedNumAnrs = in.readInt(); mUnpluggedUserTime = in.readLong(); mUnpluggedSystemTime = in.readLong(); mUnpluggedForegroundTime = in.readLong(); mUnpluggedStarts = in.readInt(); mUnpluggedNumCrashes = in.readInt(); mUnpluggedNumAnrs = in.readInt(); int bins = in.readInt(); int steps = getCpuSpeedSteps(); Loading Loading @@ -5635,6 +5691,14 @@ public final class BatteryStatsImpl extends BatteryStats { mStarts++; } public void incNumCrashesLocked() { mNumCrashes++; } public void incNumAnrsLocked() { mNumAnrs++; } @Override public boolean isActive() { return mActive; Loading Loading @@ -5684,6 +5748,28 @@ public final class BatteryStatsImpl extends BatteryStats { return val; } @Override public int getNumCrashes(int which) { int val = mNumCrashes; if (which == STATS_CURRENT) { val -= mLoadedNumCrashes; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumCrashes; } return val; } @Override public int getNumAnrs(int which) { int val = mNumAnrs; if (which == STATS_CURRENT) { val -= mLoadedNumAnrs; } else if (which == STATS_SINCE_UNPLUGGED) { val -= mUnpluggedNumAnrs; } return val; } /* Called by ActivityManagerService when CPU times are updated. */ public void addSpeedStepTimes(long[] values) { for (int i = 0; i < mSpeedBins.length && i < values.length; i++) { Loading Loading @@ -6647,6 +6733,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].reset(false); } mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; for (int i=0; i<mUidStats.size(); i++) { if (mUidStats.valueAt(i).reset()) { Loading Loading @@ -7861,6 +7948,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].readSummaryFromParcelLocked(in); } mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); mFlashlightOn = false; mFlashlightOnTimer.readSummaryFromParcelLocked(in); Loading Loading @@ -8022,6 +8110,8 @@ public final class BatteryStatsImpl extends BatteryStats { p.mSystemTime = p.mLoadedSystemTime = in.readLong(); p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); p.mStarts = p.mLoadedStarts = in.readInt(); p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); int NSB = in.readInt(); if (NSB > 100) { Slog.w(TAG, "File corrupt: too many speed bins " + NSB); Loading Loading @@ -8143,6 +8233,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); } out.writeInt(mNumConnectivityChange); mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); out.writeInt(mKernelWakelockStats.size()); Loading Loading @@ -8326,6 +8417,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(ps.mSystemTime); out.writeLong(ps.mForegroundTime); out.writeInt(ps.mStarts); out.writeInt(ps.mNumCrashes); out.writeInt(ps.mNumAnrs); final int N = ps.mSpeedBins.length; out.writeInt(N); for (int i=0; i<N; i++) { Loading Loading @@ -8444,6 +8537,9 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase, in); } mNumConnectivityChange = in.readInt(); mLoadedNumConnectivityChange = in.readInt(); mUnpluggedNumConnectivityChange = in.readInt(); mAudioOnNesting = 0; mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mVideoOnNesting = 0; Loading Loading @@ -8588,6 +8684,9 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime); } out.writeInt(mNumConnectivityChange); out.writeInt(mLoadedNumConnectivityChange); out.writeInt(mUnpluggedNumConnectivityChange); mFlashlightOnTimer.writeToParcel(out, uSecRealtime); out.writeInt(mDischargeUnplugLevel); out.writeInt(mDischargePlugLevel); Loading