From 3d658bf20e2d56e36941e7407deebeec1276fbcf Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 5 Feb 2014 13:38:56 -0800 Subject: Improve logging of first wake lock, history size. We now try to have a better label for the first wake lock that is acquired in the log. This is done in two ways: - The alarm manager now sorts the alarms it is going to execute so that wakeup alarms are first, which are more important w.r.t. which one should be logged. - There is a new power manager facility to make a wake lock as "unimportant for logging," which just means in battery stats that a wake lock acquired after that can be considered the actual one to log. This is only used by the alarm manager to mark its TIME_TICK alarms as unimportant for logging. Also reworked the battery history code to be cleaner and a bit smaller. There is no longer a separate EVENT command, instead the event code and tag are just another thing that can be included in an UPDATE command. The bits used in the first history int are also re-arrange, so that only the ones that really change a fair amount in the state bits are up at the top and there is no longer space used for the command code (since now it is always just UPDATE). This allows us to have more room for the time delta at the bottom, to better avoid situations where we need to write an int delta. Change-Id: I1bb860ae5b558a248800b090b03a84fbf7acd68a --- core/java/android/os/BatteryStats.java | 117 +++++-------- core/java/android/os/PowerManager.java | 22 ++- .../com/android/internal/app/IBatteryStats.aidl | 5 +- .../com/android/internal/os/BatteryStatsImpl.java | 149 +++++++++++------ .../com/android/server/AlarmManagerService.java | 186 ++++++++++++++------- .../com/android/server/am/BatteryStatsService.java | 12 +- .../server/power/DisplayPowerController.java | 8 + .../java/com/android/server/power/Notifier.java | 9 +- 8 files changed, 313 insertions(+), 195 deletions(-) diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index 27c0f5da99c9..4879be663792 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -507,28 +507,18 @@ public abstract class BatteryStats implements Parcelable { public long time; - // The command codes 0-3 can be written with delta updates; all others require - // that a full entry be written. - public static final byte CMD_UPDATE = 0; - public static final byte CMD_EVENT = 1; + public static final byte CMD_UPDATE = 0; // These can be written as deltas public static final byte CMD_NULL = -1; public static final byte CMD_START = 4; public static final byte CMD_OVERFLOW = 5; public byte cmd = CMD_NULL; - /** - * Return whether the command code is a delta data update. - */ - public static boolean isDeltaData(byte cmd) { - return cmd >= 0 && cmd <= 3; - } - /** * Return whether the command code is a delta data update. */ public boolean isDeltaData() { - return cmd >= 0 && cmd <= 3; + return cmd == CMD_UPDATE; } public byte batteryLevel; @@ -555,16 +545,16 @@ public abstract class BatteryStats implements Parcelable { // These states always appear directly in the first int token // of a delta change; they should be ones that change relatively // frequently. - public static final int STATE_WAKE_LOCK_FLAG = 1<<30; - public static final int STATE_SENSOR_ON_FLAG = 1<<29; - public static final int STATE_GPS_ON_FLAG = 1<<28; - public static final int STATE_PHONE_SCANNING_FLAG = 1<<27; - public static final int STATE_WIFI_RUNNING_FLAG = 1<<26; - public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25; - public static final int STATE_WIFI_SCAN_FLAG = 1<<24; - public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23; + public static final int STATE_WAKE_LOCK_FLAG = 1<<31; + public static final int STATE_SENSOR_ON_FLAG = 1<<30; + public static final int STATE_GPS_ON_FLAG = 1<<29; + public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; + public static final int STATE_WIFI_SCAN_FLAG = 1<<29; + public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26; // These are on the lower bits used for the command; if they change // we need to write another int of data. + public static final int STATE_WIFI_RUNNING_FLAG = 1<<24; + public static final int STATE_PHONE_SCANNING_FLAG = 1<<23; public static final int STATE_AUDIO_ON_FLAG = 1<<22; public static final int STATE_VIDEO_ON_FLAG = 1<<21; public static final int STATE_SCREEN_ON_FLAG = 1<<20; @@ -628,7 +618,8 @@ public abstract class BatteryStats implements Parcelable { } else { dest.writeInt(0); } - if (cmd == CMD_EVENT) { + dest.writeInt(eventCode); + if (eventCode != EVENT_NONE) { dest.writeInt(eventCode); eventTag.writeToParcel(dest, flags); } @@ -652,13 +643,10 @@ public abstract class BatteryStats implements Parcelable { } else { wakelockTag = null; } - if (cmd == CMD_EVENT) { - eventCode = src.readInt(); + eventCode = src.readInt(); + if (eventCode != EVENT_NONE) { eventTag = localEventTag; eventTag.readFromParcel(src); - } else { - eventCode = EVENT_NONE; - eventTag = null; } numReadInts += (src.dataPosition()-start)/4; } @@ -681,6 +669,16 @@ public abstract class BatteryStats implements Parcelable { public void setTo(HistoryItem o) { time = o.time; cmd = o.cmd; + setToCommon(o); + } + + public void setTo(long time, byte cmd, HistoryItem o) { + this.time = time; + this.cmd = cmd; + setToCommon(o); + } + + private void setToCommon(HistoryItem o) { batteryLevel = o.batteryLevel; batteryStatus = o.batteryStatus; batteryHealth = o.batteryHealth; @@ -703,32 +701,6 @@ public abstract class BatteryStats implements Parcelable { } } - public void setTo(long time, byte cmd, int eventCode, int eventUid, String eventName, - HistoryItem o) { - this.time = time; - this.cmd = cmd; - this.eventCode = eventCode; - if (eventCode != EVENT_NONE) { - eventTag = localEventTag; - eventTag.setTo(eventName, eventUid); - } else { - eventTag = null; - } - batteryLevel = o.batteryLevel; - batteryStatus = o.batteryStatus; - batteryHealth = o.batteryHealth; - batteryPlugType = o.batteryPlugType; - batteryTemperature = o.batteryTemperature; - batteryVoltage = o.batteryVoltage; - states = o.states; - if (o.wakelockTag != null) { - wakelockTag = localWakelockTag; - wakelockTag.setTo(o.wakelockTag); - } else { - wakelockTag = null; - } - } - public boolean sameNonEvent(HistoryItem o) { return batteryLevel == o.batteryLevel && batteryStatus == o.batteryStatus @@ -938,36 +910,36 @@ public abstract class BatteryStats implements Parcelable { public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { - new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), - new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), + new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), + new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), - new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), - new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), - new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"), - new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), - new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"), + new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), + new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video", "v"), - new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), - new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), - new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, - HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", - SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), + new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), + new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), + new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), + new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"), + new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"), + new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, + HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", + DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), + new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, + HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", + new String[] {"in", "out", "emergency", "off"}, + new String[] {"in", "out", "em", "off"}), new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK, HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", "Pss", SignalStrength.SIGNAL_STRENGTH_NAMES, new String[] { "0", "1", "2", "3", "4" }), - new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, - HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", - new String[] {"in", "out", "emergency", "off"}, - new String[] {"in", "out", "em", "off"}), - new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, - HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", - DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), + new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, + HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", + SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), }; /** @@ -2464,7 +2436,8 @@ public abstract class BatteryStats implements Parcelable { else if (rec.batteryLevel < 100) pw.print("0"); pw.print(rec.batteryLevel); pw.print(" "); - if (rec.states < 0x10) pw.print("0000000"); + if (rec.states < 0) ; + else if (rec.states < 0x10) pw.print("0000000"); else if (rec.states < 0x100) pw.print("000000"); else if (rec.states < 0x1000) pw.print("00000"); else if (rec.states < 0x10000) pw.print("0000"); diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 3a9611e4fcd9..0439eeb16c4c 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -222,6 +222,13 @@ public final class PowerManager { */ public static final int ON_AFTER_RELEASE = 0x20000000; + /** + * Wake lock flag: This wake lock is not important for logging events. If a later + * wake lock is acquired that is important, it will be considered the one to log. + * @hide + */ + public static final int UNIMPORTANT_FOR_LOGGING = 0x40000000; + /** * Flag for {@link WakeLock#release release(int)} to defer releasing a * {@link #PROXIMITY_SCREEN_OFF_WAKE_LOCK} wake lock until the proximity sensor returns @@ -634,8 +641,8 @@ public final class PowerManager { *

*/ public final class WakeLock { - private final int mFlags; - private final String mTag; + private int mFlags; + private String mTag; private final String mPackageName; private final IBinder mToken; private int mCount; @@ -829,6 +836,17 @@ public final class PowerManager { } } + /** @hide */ + public void setTag(String tag) { + mTag = tag; + } + + /** @hide */ + public void setUnimportantForLogging(boolean state) { + if (state) mFlags |= UNIMPORTANT_FOR_LOGGING; + else mFlags &= ~UNIMPORTANT_FOR_LOGGING; + } + @Override public String toString() { synchronized (mToken) { diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl index 1946d86d8668..9a047607d9ff 100644 --- a/core/java/com/android/internal/app/IBatteryStats.aidl +++ b/core/java/com/android/internal/app/IBatteryStats.aidl @@ -35,10 +35,11 @@ interface IBatteryStats { void noteEvent(int code, String name, int uid); - void noteStartWakelock(int uid, int pid, String name, int type); + void noteStartWakelock(int uid, int pid, String name, int type, boolean unimportantForLogging); void noteStopWakelock(int uid, int pid, String name, int type); - void noteStartWakelockFromSource(in WorkSource ws, int pid, String name, int type); + void noteStartWakelockFromSource(in WorkSource ws, int pid, String name, int type, + boolean unimportantForLogging); void noteStopWakelockFromSource(in WorkSource ws, int pid, String name, int type); void noteVibratorOn(int uid, long durationMillis); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 68c41fa581f9..21d2e524b3a7 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -77,7 +77,7 @@ import java.util.concurrent.locks.ReentrantLock; */ public final class BatteryStatsImpl extends BatteryStats { private static final String TAG = "BatteryStatsImpl"; - private static final boolean DEBUG = false; + private static final boolean DEBUG = true; private static final boolean DEBUG_HISTORY = false; private static final boolean USE_OLD_HISTORY = false; // for debugging. @@ -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 = 75 + (USE_OLD_HISTORY ? 1000 : 0); + private static final int VERSION = 77 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; @@ -226,6 +226,9 @@ public final class BatteryStatsImpl extends BatteryStats { long mRealtimeStart; long mLastRealtime; + int mWakeLockNesting; + boolean mWakeLockImportant; + boolean mScreenOn; StopwatchTimer mScreenOnTimer; @@ -1513,23 +1516,23 @@ public final class BatteryStatsImpl extends BatteryStats { } // Part of initial delta int that specifies the time delta. - static final int DELTA_TIME_MASK = 0x1ffff; - static final int DELTA_TIME_LONG = 0x1ffff; // The delta is a following long - static final int DELTA_TIME_INT = 0x1fffe; // The delta is a following int - static final int DELTA_TIME_ABS = 0x1fffd; // Following is an entire abs update. - // Part of initial delta int holding the command code. - static final int DELTA_CMD_MASK = 0x3; - static final int DELTA_CMD_SHIFT = 17; + static final int DELTA_TIME_MASK = 0xfffff; + static final int DELTA_TIME_LONG = 0xfffff; // The delta is a following long + static final int DELTA_TIME_INT = 0xffffe; // The delta is a following int + static final int DELTA_TIME_ABS = 0xffffd; // Following is an entire abs update. // Flag in delta int: a new battery level int follows. - static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; + static final int DELTA_BATTERY_LEVEL_FLAG = 0x00400000; // Flag in delta int: a new full state and battery status int follows. - static final int DELTA_STATE_FLAG = 0x00100000; + static final int DELTA_STATE_FLAG = 0x00800000; // Flag in delta int: contains a wakelock tag. - static final int DELTA_WAKELOCK_FLAG = 0x00200000; - static final int DELTA_STATE_MASK = 0xffc00000; + static final int DELTA_WAKELOCK_FLAG = 0x01000000; + // Flag in delta int: contains an event description. + static final int DELTA_EVENT_FLAG = 0x02000000; + // These upper bits are the frequently changing state bits. + static final int DELTA_STATE_MASK = 0xfc000000; public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { - if (last == null || !last.isDeltaData() || !cur.isDeltaData()) { + if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { dest.writeInt(DELTA_TIME_ABS); cur.writeToParcel(dest, 0); return; @@ -1547,9 +1550,7 @@ public final class BatteryStatsImpl extends BatteryStats { } else { deltaTimeToken = (int)deltaTime; } - int firstToken = deltaTimeToken - | (cur.cmd<>DELTA_CMD_SHIFT)&DELTA_CMD_MASK); + cur.cmd = HistoryItem.CMD_UPDATE; cur.numReadInts = 1; if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) + " deltaTimeToken=" + deltaTimeToken); @@ -1691,7 +1695,7 @@ public final class BatteryStatsImpl extends BatteryStats { cur.wakelockTag = null; } - if (cur.cmd == HistoryItem.CMD_EVENT) { + if ((firstToken&DELTA_EVENT_FLAG) != 0) { cur.eventTag = cur.localEventTag; final int codeAndIndex = src.readInt(); cur.eventCode = (codeAndIndex&0xffff); @@ -1720,6 +1724,8 @@ 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.eventCode == HistoryItem.EVENT_NONE + || mHistoryCur.eventCode == HistoryItem.EVENT_NONE) && mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel && mHistoryLastWritten.batteryStatus == mHistoryCur.batteryStatus && mHistoryLastWritten.batteryHealth == mHistoryCur.batteryHealth @@ -1742,6 +1748,14 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; mHistoryCur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); } + // 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. + if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { + mHistoryCur.eventCode = mHistoryLastWritten.eventCode; + mHistoryCur.eventTag = mHistoryCur.localEventTag; + mHistoryCur.eventTag.setTo(mHistoryLastWritten.eventTag); + } mHistoryLastWritten.setTo(mHistoryLastLastWritten); } @@ -1772,26 +1786,18 @@ public final class BatteryStatsImpl extends BatteryStats { addHistoryBufferLocked(curTime, HistoryItem.CMD_UPDATE); } - void addHistoryBufferLocked(long curTime, byte cmd) { - addHistoryBufferLocked(curTime, cmd, HistoryItem.EVENT_NONE, null, 0); - } - - void addHistoryBufferEventLocked(long curTime, int eventCode, String eventName, int eventUid) { - addHistoryBufferLocked(curTime, HistoryItem.CMD_EVENT, eventCode, eventName, eventUid); - } - - private void addHistoryBufferLocked(long curTime, byte cmd, - int eventCode, String eventName, int eventUid) { + private void addHistoryBufferLocked(long curTime, byte cmd) { if (mIteratingHistory) { throw new IllegalStateException("Can't do this while iterating history!"); } mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); mHistoryLastLastWritten.setTo(mHistoryLastWritten); - mHistoryLastWritten.setTo(mHistoryBaseTime + curTime, cmd, - eventCode, eventUid, eventName, mHistoryCur); + mHistoryLastWritten.setTo(mHistoryBaseTime + curTime, cmd, mHistoryCur); writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); mLastHistoryTime = curTime; mHistoryCur.wakelockTag = null; + mHistoryCur.eventCode = HistoryItem.EVENT_NONE; + mHistoryCur.eventTag = null; if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos + " now " + mHistoryBuffer.dataPosition() + " size is now " + mHistoryBuffer.dataSize()); @@ -1829,8 +1835,7 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryLastEnd = null; } else { mChangedStates |= mHistoryEnd.states^mHistoryCur.states; - mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, - HistoryItem.EVENT_NONE, 0, null, mHistoryCur); + mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, mHistoryCur); } return; } @@ -1860,7 +1865,11 @@ public final class BatteryStatsImpl extends BatteryStats { } void addHistoryEventLocked(long curTime, int code, String name, int uid) { - addHistoryBufferEventLocked(curTime, code, name, uid); + mHistoryCur.eventCode = code; + mHistoryCur.eventTag = mHistoryCur.localEventTag; + mHistoryCur.eventTag.string = name; + mHistoryCur.eventTag.uid = uid; + addHistoryBufferLocked(curTime); } void addHistoryRecordLocked(long curTime, byte cmd) { @@ -1870,8 +1879,7 @@ public final class BatteryStatsImpl extends BatteryStats { } else { rec = new HistoryItem(); } - rec.setTo(mHistoryBaseTime + curTime, cmd, - HistoryItem.EVENT_NONE, 0, null, mHistoryCur); + rec.setTo(mHistoryBaseTime + curTime, cmd, mHistoryCur); addHistoryRecordLocked(rec); } @@ -1905,8 +1913,8 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryBuffer.setDataSize(0); mHistoryBuffer.setDataPosition(0); mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); - mHistoryLastLastWritten.cmd = HistoryItem.CMD_NULL; - mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; + mHistoryLastLastWritten.clear(); + mHistoryLastWritten.clear(); mHistoryTagPool.clear(); mNextHistoryTagIdx = 0; mNumHistoryTagChars = 0; @@ -1942,8 +1950,6 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothPingStart = -1; } - int mWakeLockNesting; - public void addIsolatedUidLocked(int isolatedUid, int appUid) { mIsolatedUids.put(isolatedUid, appUid); } @@ -1965,7 +1971,8 @@ public final class BatteryStatsImpl extends BatteryStats { addHistoryEventLocked(SystemClock.elapsedRealtime(), code, name, uid); } - public void noteStartWakeLocked(int uid, int pid, String name, int type) { + public void noteStartWakeLocked(int uid, int pid, String name, int type, + boolean unimportantForLogging) { uid = mapUid(uid); if (type == WAKE_TYPE_PARTIAL) { // Only care about partial wake locks, since full wake locks @@ -1977,7 +1984,18 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; mHistoryCur.wakelockTag.string = name; mHistoryCur.wakelockTag.uid = uid; + mWakeLockImportant = !unimportantForLogging; addHistoryRecordLocked(SystemClock.elapsedRealtime()); + } else if (!mWakeLockImportant && !unimportantForLogging) { + if (mHistoryLastWritten.wakelockTag != null) { + // We'll try to update the last tag. + mHistoryLastWritten.wakelockTag = null; + mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; + mHistoryCur.wakelockTag.string = name; + mHistoryCur.wakelockTag.uid = uid; + addHistoryRecordLocked(SystemClock.elapsedRealtime()); + } + mWakeLockImportant = true; } mWakeLockNesting++; } @@ -2010,10 +2028,11 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, int type) { + public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, int type, + boolean unimportantForLogging) { int N = ws.size(); for (int i=0; i be : mBroadcastStats.entrySet()) { - BroadcastStats bs = be.getValue(); - for (Map.Entry, FilterStats> fe - : bs.filterStats.entrySet()) { - FilterStats fs = fe.getValue(); - int pos = len > 0 - ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0; - if (pos < 0) { - pos = -pos - 1; - } - if (pos < topFilters.length) { - int copylen = topFilters.length - pos - 1; - if (copylen > 0) { - System.arraycopy(topFilters, pos, topFilters, pos+1, copylen); + for (int iu=0; iu uidStats = mBroadcastStats.valueAt(iu); + for (int ip=0; ip 0 + ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0; + if (pos < 0) { + pos = -pos - 1; } - topFilters[pos] = fs; - if (len < topFilters.length) { - len++; + if (pos < topFilters.length) { + int copylen = topFilters.length - pos - 1; + if (copylen > 0) { + System.arraycopy(topFilters, pos, topFilters, pos+1, copylen); + } + topFilters[pos] = fs; + if (len < topFilters.length) { + len++; + } } } } @@ -774,7 +793,8 @@ class AlarmManagerService extends SystemService { TimeUtils.formatDuration(fs.aggregateTime, pw); pw.print(" running, "); pw.print(fs.numWakeup); pw.print(" wakeups, "); pw.print(fs.count); - pw.print(" alarms: "); pw.print(fs.mBroadcastStats.mPackageName); + pw.print(" alarms: "); UserHandle.formatUid(pw, fs.mBroadcastStats.mUid); + pw.print(":"); pw.print(fs.mBroadcastStats.mPackageName); pw.println(); pw.print(" "); if (fs.mTarget.first != null) { @@ -790,35 +810,39 @@ class AlarmManagerService extends SystemService { pw.println(" "); pw.println(" Alarm Stats:"); final ArrayList tmpFilters = new ArrayList(); - for (Map.Entry be : mBroadcastStats.entrySet()) { - BroadcastStats bs = be.getValue(); - pw.print(" "); - if (bs.nesting > 0) pw.print("*ACTIVE* "); - pw.print(be.getKey()); - pw.print(" "); TimeUtils.formatDuration(bs.aggregateTime, pw); - pw.print(" running, "); pw.print(bs.numWakeup); - pw.println(" wakeups:"); - tmpFilters.clear(); - for (Map.Entry, FilterStats> fe - : bs.filterStats.entrySet()) { - tmpFilters.add(fe.getValue()); - } - Collections.sort(tmpFilters, comparator); - for (int i=0; i 0) pw.print("*ACTIVE* "); - TimeUtils.formatDuration(fs.aggregateTime, pw); - pw.print(" "); pw.print(fs.numWakeup); - pw.print(" wakes " ); pw.print(fs.count); - pw.print(" alarms:"); - if (fs.mTarget.first != null) { - pw.print(" act="); pw.print(fs.mTarget.first); - } - if (fs.mTarget.second != null) { - pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString()); - } - pw.println(); + for (int iu=0; iu uidStats = mBroadcastStats.valueAt(iu); + for (int ip=0; ip 0) pw.print("*ACTIVE* "); + UserHandle.formatUid(pw, bs.mUid); + pw.print(":"); + pw.print(bs.mPackageName); + pw.print(" "); TimeUtils.formatDuration(bs.aggregateTime, pw); + pw.print(" running, "); pw.print(bs.numWakeup); + pw.println(" wakeups:"); + tmpFilters.clear(); + for (int is=0; is 0) pw.print("*ACTIVE* "); + TimeUtils.formatDuration(fs.aggregateTime, pw); + pw.print(" "); pw.print(fs.numWakeup); + pw.print(" wakes " ); pw.print(fs.count); + pw.print(" alarms:"); + if (fs.mTarget.first != null) { + pw.print(" act="); pw.print(fs.mTarget.first); + } + if (fs.mTarget.second != null) { + pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString()); + } + pw.println(); + } } } @@ -1037,7 +1061,8 @@ class AlarmManagerService extends SystemService { private native int waitForAlarm(long nativeData); private native int setKernelTimezone(long nativeData, int minuteswest); - void triggerAlarmsLocked(ArrayList triggerList, long nowELAPSED, long nowRTC) { + void triggerAlarmsLocked(ArrayList triggerList, final long nowELAPSED, + final long nowRTC) { // batches are temporally sorted, so we need only pull from the // start of the list until we either empty it or hit a batch // that is not yet deliverable @@ -1076,6 +1101,14 @@ class AlarmManagerService extends SystemService { } } + + Collections.sort(triggerList, mAlarmDispatchComparator); + + if (localLOGV) { + for (int i=0; i 0)) { for (String pkg : pkgList) { removeLocked(pkg); - mBroadcastStats.remove(pkg); + for (int i=mBroadcastStats.size()-1; i>=0; i--) { + ArrayMap uidStats = mBroadcastStats.valueAt(i); + if (uidStats.remove(pkg) != null) { + if (uidStats.size() <= 0) { + mBroadcastStats.removeAt(i); + } + } + } } } } @@ -1458,11 +1512,17 @@ class AlarmManagerService extends SystemService { } private final BroadcastStats getStatsLocked(PendingIntent pi) { - String pkg = pi.getTargetPackage(); - BroadcastStats bs = mBroadcastStats.get(pkg); + String pkg = pi.getCreatorPackage(); + int uid = pi.getCreatorUid(); + ArrayMap uidStats = mBroadcastStats.get(uid); + if (uidStats == null) { + uidStats = new ArrayMap(); + mBroadcastStats.put(uid, uidStats); + } + BroadcastStats bs = uidStats.get(pkg); if (bs == null) { - bs = new BroadcastStats(pkg); - mBroadcastStats.put(pkg, bs); + bs = new BroadcastStats(uid, pkg); + uidStats.put(pkg, bs); } return bs; } diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index eda08a92aa38..8a29ac75570d 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -126,10 +126,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } - public void noteStartWakelock(int uid, int pid, String name, int type) { + public void noteStartWakelock(int uid, int pid, String name, int type, + boolean unimportantForLogging) { enforceCallingPermission(); synchronized (mStats) { - mStats.noteStartWakeLocked(uid, pid, name, type); + mStats.noteStartWakeLocked(uid, pid, name, type, unimportantForLogging); } } @@ -140,10 +141,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } - public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type) { + public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type, + boolean unimportantForLogging) { enforceCallingPermission(); synchronized (mStats) { - mStats.noteStartWakeFromSourceLocked(ws, pid, name, type); + mStats.noteStartWakeFromSourceLocked(ws, pid, name, type, unimportantForLogging); } } @@ -557,7 +559,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub { isUnpluggedOnly = true; } else if ("--reset".equals(arg)) { synchronized (mStats) { - mStats.resetAllStatsLocked(); + mStats.resetAllStatsCmdLocked(); pw.println("Battery stats reset."); noOutput = true; } diff --git a/services/core/java/com/android/server/power/DisplayPowerController.java b/services/core/java/com/android/server/power/DisplayPowerController.java index f1be504e5549..b63f625596f5 100644 --- a/services/core/java/com/android/server/power/DisplayPowerController.java +++ b/services/core/java/com/android/server/power/DisplayPowerController.java @@ -536,6 +536,14 @@ final class DisplayPowerController { mScreenBrightnessRampAnimator = new RampAnimator( mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS); + + // Initialize screen on state. + if (mPowerState.isScreenOn()) { + mNotifier.onScreenOn(); + } else { + mNotifier.onScreenOff(); + } + mNotifier.onScreenBrightness(mPowerState.getScreenBrightness()); } private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() { diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java index 264e2e9c3b15..09be3a8c2aae 100644 --- a/services/core/java/com/android/server/power/Notifier.java +++ b/services/core/java/com/android/server/power/Notifier.java @@ -34,6 +34,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.PowerManager; +import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; @@ -139,10 +140,14 @@ final class Notifier { try { final int monitorType = getBatteryStatsWakeLockMonitorType(flags); + boolean unimportantForLogging = (flags&PowerManager.UNIMPORTANT_FOR_LOGGING) != 0 + && ownerUid == Process.SYSTEM_UID; if (workSource != null) { - mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag, monitorType); + mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag, monitorType, + unimportantForLogging); } else { - mBatteryStats.noteStartWakelock(ownerUid, ownerPid, tag, monitorType); + mBatteryStats.noteStartWakelock(ownerUid, ownerPid, tag, monitorType, + unimportantForLogging); // XXX need to deal with disabled operations. mAppOps.startOperation(AppOpsManager.getToken(mAppOps), AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName); -- cgit v1.2.3-59-g8ed1b