Merge \"BatteryStats: Record fine grained battery discharge\" into nyc-dev
am: 094c40b2cc
Change-Id: Ie85fcfc2fa7aec5e7c15f57d605840c563c0e993
This commit is contained in:
@@ -2370,6 +2370,20 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
"screen doze-suspend device idle",
|
"screen doze-suspend device idle",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the counter keeping track of the amount of battery discharge while the screen was off,
|
||||||
|
* measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
|
||||||
|
* a coulomb counter.
|
||||||
|
*/
|
||||||
|
public abstract LongCounter getDischargeScreenOffCoulombCounter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the counter keeping track of the amount of battery discharge measured in
|
||||||
|
* micro-Ampere-hours. This will be non-zero only if the device's battery has
|
||||||
|
* a coulomb counter.
|
||||||
|
*/
|
||||||
|
public abstract LongCounter getDischargeCoulombCounter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the array of discharge step durations.
|
* Return the array of discharge step durations.
|
||||||
*/
|
*/
|
||||||
@@ -2805,6 +2819,9 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
rawRealtime, which);
|
rawRealtime, which);
|
||||||
final int connChanges = getNumConnectivityChange(which);
|
final int connChanges = getNumConnectivityChange(which);
|
||||||
final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
|
final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
|
||||||
|
final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
|
||||||
|
final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
|
||||||
|
.getCountLocked(which);
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder(128);
|
final StringBuilder sb = new StringBuilder(128);
|
||||||
|
|
||||||
@@ -2819,7 +2836,8 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
|
whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
|
||||||
totalRealtime / 1000, totalUptime / 1000,
|
totalRealtime / 1000, totalUptime / 1000,
|
||||||
getStartClockTime(),
|
getStartClockTime(),
|
||||||
whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
|
whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
|
||||||
|
dischargeCount / 1000, dischargeScreenOffCount / 1000);
|
||||||
|
|
||||||
// Calculate wakelock times across all uids.
|
// Calculate wakelock times across all uids.
|
||||||
long fullWakeLockTimeTotal = 0;
|
long fullWakeLockTimeTotal = 0;
|
||||||
@@ -3371,6 +3389,39 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
formatTimeMs(sb, chargeTimeRemaining / 1000);
|
formatTimeMs(sb, chargeTimeRemaining / 1000);
|
||||||
pw.println(sb.toString());
|
pw.println(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final LongCounter dischargeCounter = getDischargeCoulombCounter();
|
||||||
|
final long dischargeCount = dischargeCounter.getCountLocked(which);
|
||||||
|
if (dischargeCount >= 0) {
|
||||||
|
sb.setLength(0);
|
||||||
|
sb.append(prefix);
|
||||||
|
sb.append(" Discharge: ");
|
||||||
|
sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
|
||||||
|
sb.append(" mAh");
|
||||||
|
pw.println(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
|
||||||
|
final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
|
||||||
|
if (dischargeScreenOffCount >= 0) {
|
||||||
|
sb.setLength(0);
|
||||||
|
sb.append(prefix);
|
||||||
|
sb.append(" Screen off discharge: ");
|
||||||
|
sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
|
||||||
|
sb.append(" mAh");
|
||||||
|
pw.println(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
|
||||||
|
if (dischargeScreenOnCount >= 0) {
|
||||||
|
sb.setLength(0);
|
||||||
|
sb.append(prefix);
|
||||||
|
sb.append(" Screen on discharge: ");
|
||||||
|
sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
|
||||||
|
sb.append(" mAh");
|
||||||
|
pw.println(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
pw.print(" Start clock time: ");
|
pw.print(" Start clock time: ");
|
||||||
pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
|
pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
||||||
|
|
||||||
// Current on-disk Parcel version
|
// Current on-disk Parcel version
|
||||||
private static final int VERSION = 144 + (USE_OLD_HISTORY ? 1000 : 0);
|
private static final int VERSION = 145 + (USE_OLD_HISTORY ? 1000 : 0);
|
||||||
|
|
||||||
// Maximum number of items we will record in the history.
|
// Maximum number of items we will record in the history.
|
||||||
private static final int MAX_HISTORY_ITEMS = 2000;
|
private static final int MAX_HISTORY_ITEMS = 2000;
|
||||||
@@ -509,6 +509,9 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
int mDischargeAmountScreenOff;
|
int mDischargeAmountScreenOff;
|
||||||
int mDischargeAmountScreenOffSinceCharge;
|
int mDischargeAmountScreenOffSinceCharge;
|
||||||
|
|
||||||
|
private LongSamplingCounter mDischargeScreenOffCounter;
|
||||||
|
private LongSamplingCounter mDischargeCounter;
|
||||||
|
|
||||||
static final int MAX_LEVEL_STEPS = 200;
|
static final int MAX_LEVEL_STEPS = 200;
|
||||||
|
|
||||||
int mInitStepMode = 0;
|
int mInitStepMode = 0;
|
||||||
@@ -565,6 +568,16 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
return mWakeupReasonStats;
|
return mWakeupReasonStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LongCounter getDischargeScreenOffCoulombCounter() {
|
||||||
|
return mDischargeScreenOffCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LongCounter getDischargeCoulombCounter() {
|
||||||
|
return mDischargeCounter;
|
||||||
|
}
|
||||||
|
|
||||||
public BatteryStatsImpl() {
|
public BatteryStatsImpl() {
|
||||||
this(new SystemClocks());
|
this(new SystemClocks());
|
||||||
}
|
}
|
||||||
@@ -912,7 +925,6 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
final TimeBase mTimeBase;
|
final TimeBase mTimeBase;
|
||||||
long mCount;
|
long mCount;
|
||||||
long mLoadedCount;
|
long mLoadedCount;
|
||||||
long mLastCount;
|
|
||||||
long mUnpluggedCount;
|
long mUnpluggedCount;
|
||||||
long mPluggedCount;
|
long mPluggedCount;
|
||||||
|
|
||||||
@@ -921,7 +933,6 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mPluggedCount = in.readLong();
|
mPluggedCount = in.readLong();
|
||||||
mCount = mPluggedCount;
|
mCount = mPluggedCount;
|
||||||
mLoadedCount = in.readLong();
|
mLoadedCount = in.readLong();
|
||||||
mLastCount = 0;
|
|
||||||
mUnpluggedCount = in.readLong();
|
mUnpluggedCount = in.readLong();
|
||||||
timeBase.add(this);
|
timeBase.add(this);
|
||||||
}
|
}
|
||||||
@@ -949,20 +960,19 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getCountLocked(int which) {
|
public long getCountLocked(int which) {
|
||||||
long val = mCount;
|
long val = mTimeBase.isRunning() ? mCount : mPluggedCount;
|
||||||
if (which == STATS_SINCE_UNPLUGGED) {
|
if (which == STATS_SINCE_UNPLUGGED) {
|
||||||
val -= mUnpluggedCount;
|
val -= mUnpluggedCount;
|
||||||
} else if (which != STATS_SINCE_CHARGED) {
|
} else if (which != STATS_SINCE_CHARGED) {
|
||||||
val -= mLoadedCount;
|
val -= mLoadedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logState(Printer pw, String prefix) {
|
public void logState(Printer pw, String prefix) {
|
||||||
pw.println(prefix + "mCount=" + mCount
|
pw.println(prefix + "mCount=" + mCount
|
||||||
+ " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount
|
+ " mLoadedCount=" + mLoadedCount
|
||||||
+ " mUnpluggedCount=" + mUnpluggedCount
|
+ " mUnpluggedCount=" + mUnpluggedCount
|
||||||
+ " mPluggedCount=" + mPluggedCount);
|
+ " mPluggedCount=" + mPluggedCount);
|
||||||
}
|
}
|
||||||
@@ -976,7 +986,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
*/
|
*/
|
||||||
void reset(boolean detachIfReset) {
|
void reset(boolean detachIfReset) {
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0;
|
mLoadedCount = mPluggedCount = mUnpluggedCount = 0;
|
||||||
if (detachIfReset) {
|
if (detachIfReset) {
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
@@ -993,7 +1003,6 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
void readSummaryFromParcelLocked(Parcel in) {
|
void readSummaryFromParcelLocked(Parcel in) {
|
||||||
mLoadedCount = in.readLong();
|
mLoadedCount = in.readLong();
|
||||||
mCount = mLoadedCount;
|
mCount = mLoadedCount;
|
||||||
mLastCount = 0;
|
|
||||||
mUnpluggedCount = mPluggedCount = mLoadedCount;
|
mUnpluggedCount = mPluggedCount = mLoadedCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7566,6 +7575,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase);
|
mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase);
|
||||||
mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase);
|
mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase);
|
||||||
mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase);
|
mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase);
|
||||||
|
mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase);
|
||||||
|
mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase);
|
||||||
mOnBattery = mOnBatteryInternal = false;
|
mOnBattery = mOnBatteryInternal = false;
|
||||||
long uptime = mClocks.uptimeMillis() * 1000;
|
long uptime = mClocks.uptimeMillis() * 1000;
|
||||||
long realtime = mClocks.elapsedRealtime() * 1000;
|
long realtime = mClocks.elapsedRealtime() * 1000;
|
||||||
@@ -8123,6 +8134,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mDischargeAmountScreenOffSinceCharge = 0;
|
mDischargeAmountScreenOffSinceCharge = 0;
|
||||||
mDischargeStepTracker.init();
|
mDischargeStepTracker.init();
|
||||||
mChargeStepTracker.init();
|
mChargeStepTracker.init();
|
||||||
|
mDischargeScreenOffCounter.reset(false);
|
||||||
|
mDischargeCounter.reset(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetAllStatsCmdLocked() {
|
public void resetAllStatsCmdLocked() {
|
||||||
@@ -9327,6 +9340,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG;
|
mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG;
|
||||||
mHistoryCur.batteryStatus = (byte)status;
|
mHistoryCur.batteryStatus = (byte)status;
|
||||||
mHistoryCur.batteryLevel = (byte)level;
|
mHistoryCur.batteryLevel = (byte)level;
|
||||||
|
mHistoryCur.batteryChargeUAh = chargeUAh;
|
||||||
mMaxChargeStepLevel = mMinDischargeStepLevel =
|
mMaxChargeStepLevel = mMinDischargeStepLevel =
|
||||||
mLastChargeStepLevel = mLastDischargeStepLevel = level;
|
mLastChargeStepLevel = mLastDischargeStepLevel = level;
|
||||||
mLastChargingStateLevel = level;
|
mLastChargingStateLevel = level;
|
||||||
@@ -9358,6 +9372,12 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mHistoryCur.batteryPlugType = (byte)plugType;
|
mHistoryCur.batteryPlugType = (byte)plugType;
|
||||||
mHistoryCur.batteryTemperature = (short)temp;
|
mHistoryCur.batteryTemperature = (short)temp;
|
||||||
mHistoryCur.batteryVoltage = (char)volt;
|
mHistoryCur.batteryVoltage = (char)volt;
|
||||||
|
if (chargeUAh < mHistoryCur.batteryChargeUAh) {
|
||||||
|
// Only record discharges
|
||||||
|
final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh;
|
||||||
|
mDischargeCounter.addCountLocked(chargeDiff);
|
||||||
|
mDischargeScreenOffCounter.addCountLocked(chargeDiff);
|
||||||
|
}
|
||||||
mHistoryCur.batteryChargeUAh = chargeUAh;
|
mHistoryCur.batteryChargeUAh = chargeUAh;
|
||||||
setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level);
|
setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level);
|
||||||
} else {
|
} else {
|
||||||
@@ -9394,6 +9414,12 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
}
|
}
|
||||||
if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10)
|
if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10)
|
||||||
|| chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) {
|
|| chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) {
|
||||||
|
if (chargeUAh < mHistoryCur.batteryChargeUAh) {
|
||||||
|
// Only record discharges
|
||||||
|
final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh;
|
||||||
|
mDischargeCounter.addCountLocked(chargeDiff);
|
||||||
|
mDischargeScreenOffCounter.addCountLocked(chargeDiff);
|
||||||
|
}
|
||||||
mHistoryCur.batteryChargeUAh = chargeUAh;
|
mHistoryCur.batteryChargeUAh = chargeUAh;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@@ -10075,6 +10101,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mChargeStepTracker.readFromParcel(in);
|
mChargeStepTracker.readFromParcel(in);
|
||||||
mDailyDischargeStepTracker.readFromParcel(in);
|
mDailyDischargeStepTracker.readFromParcel(in);
|
||||||
mDailyChargeStepTracker.readFromParcel(in);
|
mDailyChargeStepTracker.readFromParcel(in);
|
||||||
|
mDischargeCounter.readSummaryFromParcelLocked(in);
|
||||||
|
mDischargeScreenOffCounter.readSummaryFromParcelLocked(in);
|
||||||
int NPKG = in.readInt();
|
int NPKG = in.readInt();
|
||||||
if (NPKG > 0) {
|
if (NPKG > 0) {
|
||||||
mDailyPackageChanges = new ArrayList<>(NPKG);
|
mDailyPackageChanges = new ArrayList<>(NPKG);
|
||||||
@@ -10423,6 +10451,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
out.writeInt(getDischargeAmountScreenOffSinceCharge());
|
out.writeInt(getDischargeAmountScreenOffSinceCharge());
|
||||||
mDischargeStepTracker.writeToParcel(out);
|
mDischargeStepTracker.writeToParcel(out);
|
||||||
mChargeStepTracker.writeToParcel(out);
|
mChargeStepTracker.writeToParcel(out);
|
||||||
|
mDischargeCounter.writeSummaryFromParcelLocked(out);
|
||||||
|
mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out);
|
||||||
mDailyDischargeStepTracker.writeToParcel(out);
|
mDailyDischargeStepTracker.writeToParcel(out);
|
||||||
mDailyChargeStepTracker.writeToParcel(out);
|
mDailyChargeStepTracker.writeToParcel(out);
|
||||||
if (mDailyPackageChanges != null) {
|
if (mDailyPackageChanges != null) {
|
||||||
@@ -10880,6 +10910,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mDischargeAmountScreenOffSinceCharge = in.readInt();
|
mDischargeAmountScreenOffSinceCharge = in.readInt();
|
||||||
mDischargeStepTracker.readFromParcel(in);
|
mDischargeStepTracker.readFromParcel(in);
|
||||||
mChargeStepTracker.readFromParcel(in);
|
mChargeStepTracker.readFromParcel(in);
|
||||||
|
mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in);
|
||||||
|
mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryTimeBase, in);
|
||||||
mLastWriteTime = in.readLong();
|
mLastWriteTime = in.readLong();
|
||||||
|
|
||||||
mKernelWakelockStats.clear();
|
mKernelWakelockStats.clear();
|
||||||
@@ -11028,6 +11060,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
out.writeInt(mDischargeAmountScreenOffSinceCharge);
|
out.writeInt(mDischargeAmountScreenOffSinceCharge);
|
||||||
mDischargeStepTracker.writeToParcel(out);
|
mDischargeStepTracker.writeToParcel(out);
|
||||||
mChargeStepTracker.writeToParcel(out);
|
mChargeStepTracker.writeToParcel(out);
|
||||||
|
mDischargeCounter.writeToParcel(out);
|
||||||
|
mDischargeScreenOffCounter.writeToParcel(out);
|
||||||
out.writeLong(mLastWriteTime);
|
out.writeLong(mLastWriteTime);
|
||||||
|
|
||||||
if (inclUids) {
|
if (inclUids) {
|
||||||
|
|||||||
Reference in New Issue
Block a user