Account for all wake lock usage.

Wake locks can be held outside of what we measure in battery stats,
by things not going through the power manager.  Account for this by
computing the total wake time that is not covered by known wake locks
and screen on time, and blame this on Android OS.

Change-Id: Idf2907bc35f8c35f92155671c8dba521ae9ea804
This commit is contained in:
Dianne Hackborn
2011-10-03 18:34:27 -07:00
parent dd98ff192c
commit c174ec64f9

View File

@@ -414,6 +414,8 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
}
final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
long appWakelockTime = 0;
BatterySipper osApp = null;
mStatsPeriod = uSecTime;
SparseArray<? extends Uid> uidStats = mStats.getUidStats();
final int NU = uidStats.size();
@@ -488,6 +490,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
}
}
wakelockTime /= 1000; // convert to millis
appWakelockTime += wakelockTime;
// Add cost of holding a wake lock
power += (wakelockTime
@@ -535,7 +538,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
if (DEBUG) Log.i(TAG, "UID " + u.getUid() + ": power=" + power);
// Add the app to the list if it is consuming power
if (power != 0) {
if (power != 0 || u.getUid() == 0) {
BatterySipper app = new BatterySipper(getActivity(), mRequestQueue, mHandler,
packageWithHighestDrain, DrainType.APP, 0, u,
new double[] {power});
@@ -553,6 +556,9 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
} else {
mUsageList.add(app);
}
if (u.getUid() == 0) {
osApp = app;
}
}
if (u.getUid() == Process.WIFI_UID) {
mWifiPower += power;
@@ -564,6 +570,25 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
}
if (DEBUG) Log.i(TAG, "Added power = " + power);
}
// The device has probably been awake for longer than the screen on
// time and application wake lock time would account for. Assign
// this remainder to the OS, if possible.
if (osApp != null) {
long wakeTimeMillis = mStats.computeBatteryUptime(
SystemClock.uptimeMillis() * 1000, which) / 1000;
wakeTimeMillis -= appWakelockTime - (mStats.getScreenOnTime(
SystemClock.elapsedRealtime(), which) / 1000);
if (wakeTimeMillis > 0) {
double power = (wakeTimeMillis
* mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_AWAKE)) / 1000;
osApp.wakeLockTime += wakeTimeMillis;
osApp.value += power;
osApp.values[0] += power;
if (osApp.value > mMaxPower) mMaxPower = osApp.value;
mTotalPower += power;
}
}
}
private void addPhoneUsage(long uSecNow) {