Merge "Fix calculation of power drain from BT and WiFi" into mnc-dev

This commit is contained in:
Adam Lesinski
2015-06-09 19:51:55 +00:00
committed by Android (Google) Code Review
4 changed files with 35 additions and 17 deletions

View File

@@ -354,9 +354,9 @@ public final class BatteryStatsHelper {
if (mBluetoothPowerCalculator == null) {
if (checkHasBluetoothPowerReporting(mStats, mPowerProfile)) {
mBluetoothPowerCalculator = new BluetoothPowerCalculator();
mBluetoothPowerCalculator = new BluetoothPowerCalculator(mPowerProfile);
} else {
mBluetoothPowerCalculator = new BluetoothPowerCalculator();
mBluetoothPowerCalculator = new BluetoothPowerCalculator(mPowerProfile);
}
}
mBluetoothPowerCalculator.reset();

View File

@@ -7814,11 +7814,13 @@ public final class BatteryStatsImpl extends BatteryStats {
mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked(
info.getControllerIdleTimeMillis());
final double opVoltage = mPowerProfile.getAveragePower(
PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE);
if (opVoltage != 0) {
// POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
final double opVolt = mPowerProfile.getAveragePower(
PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
if (opVolt != 0) {
// We store the power drain as mAms.
mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked(
(long)(info.getControllerEnergyUsed() / opVoltage));
(long)(info.getControllerEnergyUsed() / opVolt));
}
}
}
@@ -7908,11 +7910,13 @@ public final class BatteryStatsImpl extends BatteryStats {
mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked(
info.getControllerIdleTimeMillis());
final double opVoltage = mPowerProfile.getAveragePower(
PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE);
if (opVoltage != 0) {
// POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
final double opVolt = mPowerProfile.getAveragePower(
PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
if (opVolt != 0) {
// We store the power drain as mAms.
mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked(
(long) (info.getControllerEnergyUsed() / opVoltage));
(long) (info.getControllerEnergyUsed() / opVolt));
}
}
}

View File

@@ -21,6 +21,15 @@ import android.util.Log;
public class BluetoothPowerCalculator extends PowerCalculator {
private static final boolean DEBUG = BatteryStatsHelper.DEBUG;
private static final String TAG = "BluetoothPowerCalculator";
private final double mIdleMa;
private final double mRxMa;
private final double mTxMa;
public BluetoothPowerCalculator(PowerProfile profile) {
mIdleMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_IDLE);
mRxMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_RX);
mTxMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_TX);
}
@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
@@ -37,10 +46,15 @@ public class BluetoothPowerCalculator extends PowerCalculator {
BatteryStats.CONTROLLER_TX_TIME, statsType);
final long rxTimeMs = stats.getBluetoothControllerActivity(
BatteryStats.CONTROLLER_RX_TIME, statsType);
final long powerMaMs = stats.getBluetoothControllerActivity(
BatteryStats.CONTROLLER_POWER_DRAIN, statsType);
final double powerMah = powerMaMs / (double)(1000*60*60);
final long totalTimeMs = idleTimeMs + txTimeMs + rxTimeMs;
double powerMah = stats.getBluetoothControllerActivity(
BatteryStats.CONTROLLER_POWER_DRAIN, statsType) / (double)(1000*60*60);
if (powerMah == 0) {
// Some devices do not report the power, so calculate it.
powerMah = ((idleTimeMs * mIdleMa) + (rxTimeMs * mRxMa) + (txTimeMs * mTxMa))
/ (1000*60*60);
}
if (DEBUG && powerMah != 0) {
Log.d(TAG, "Bluetooth active: time=" + (totalTimeMs)

View File

@@ -70,14 +70,14 @@ public class WifiPowerCalculator extends PowerCalculator {
statsType);
app.wifiRunningTimeMs = idleTimeMs + rxTimeMs + txTimeMs;
double powerDrain = stats.getWifiControllerActivity(BatteryStats.CONTROLLER_POWER_DRAIN,
double powerDrainMah = stats.getWifiControllerActivity(BatteryStats.CONTROLLER_POWER_DRAIN,
statsType) / (double)(1000*60*60);
if (powerDrain == 0) {
if (powerDrainMah == 0) {
// Some controllers do not report power drain, so we can calculate it here.
powerDrain = ((idleTimeMs * mIdleCurrentMa) + (txTimeMs * mTxCurrentMa)
powerDrainMah = ((idleTimeMs * mIdleCurrentMa) + (txTimeMs * mTxCurrentMa)
+ (rxTimeMs * mRxCurrentMa)) / (1000*60*60);
}
app.wifiPowerMah = Math.max(0, powerDrain - mTotalAppPowerDrain);
app.wifiPowerMah = Math.max(0, powerDrainMah - mTotalAppPowerDrain);
if (DEBUG) {
Log.d(TAG, "left over WiFi power: " + BatteryStatsHelper.makemAh(app.wifiPowerMah));