Merge "BatteryStatsHelper: Include screen on baseline power draw" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c708cf6340
@@ -94,14 +94,14 @@ public final class BatteryStatsHelper {
|
|||||||
|
|
||||||
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
|
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
|
||||||
|
|
||||||
long mRawRealtime;
|
long mRawRealtimeUs;
|
||||||
long mRawUptime;
|
long mRawUptimeUs;
|
||||||
long mBatteryRealtime;
|
long mBatteryRealtimeUs;
|
||||||
long mBatteryUptime;
|
long mBatteryUptimeUs;
|
||||||
long mTypeBatteryRealtime;
|
long mTypeBatteryRealtimeUs;
|
||||||
long mTypeBatteryUptime;
|
long mTypeBatteryUptimeUs;
|
||||||
long mBatteryTimeRemaining;
|
long mBatteryTimeRemainingUs;
|
||||||
long mChargeTimeRemaining;
|
long mChargeTimeRemainingUs;
|
||||||
|
|
||||||
private long mStatsPeriod = 0;
|
private long mStatsPeriod = 0;
|
||||||
|
|
||||||
@@ -389,22 +389,22 @@ public final class BatteryStatsHelper {
|
|||||||
mFlashlightPowerCalculator.reset();
|
mFlashlightPowerCalculator.reset();
|
||||||
|
|
||||||
mStatsType = statsType;
|
mStatsType = statsType;
|
||||||
mRawUptime = rawUptimeUs;
|
mRawUptimeUs = rawUptimeUs;
|
||||||
mRawRealtime = rawRealtimeUs;
|
mRawRealtimeUs = rawRealtimeUs;
|
||||||
mBatteryUptime = mStats.getBatteryUptime(rawUptimeUs);
|
mBatteryUptimeUs = mStats.getBatteryUptime(rawUptimeUs);
|
||||||
mBatteryRealtime = mStats.getBatteryRealtime(rawRealtimeUs);
|
mBatteryRealtimeUs = mStats.getBatteryRealtime(rawRealtimeUs);
|
||||||
mTypeBatteryUptime = mStats.computeBatteryUptime(rawUptimeUs, mStatsType);
|
mTypeBatteryUptimeUs = mStats.computeBatteryUptime(rawUptimeUs, mStatsType);
|
||||||
mTypeBatteryRealtime = mStats.computeBatteryRealtime(rawRealtimeUs, mStatsType);
|
mTypeBatteryRealtimeUs = mStats.computeBatteryRealtime(rawRealtimeUs, mStatsType);
|
||||||
mBatteryTimeRemaining = mStats.computeBatteryTimeRemaining(rawRealtimeUs);
|
mBatteryTimeRemainingUs = mStats.computeBatteryTimeRemaining(rawRealtimeUs);
|
||||||
mChargeTimeRemaining = mStats.computeChargeTimeRemaining(rawRealtimeUs);
|
mChargeTimeRemainingUs = mStats.computeChargeTimeRemaining(rawRealtimeUs);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Raw time: realtime=" + (rawRealtimeUs/1000) + " uptime="
|
Log.d(TAG, "Raw time: realtime=" + (rawRealtimeUs/1000) + " uptime="
|
||||||
+ (rawUptimeUs/1000));
|
+ (rawUptimeUs/1000));
|
||||||
Log.d(TAG, "Battery time: realtime=" + (mBatteryRealtime/1000) + " uptime="
|
Log.d(TAG, "Battery time: realtime=" + (mBatteryRealtimeUs /1000) + " uptime="
|
||||||
+ (mBatteryUptime/1000));
|
+ (mBatteryUptimeUs /1000));
|
||||||
Log.d(TAG, "Battery type time: realtime=" + (mTypeBatteryRealtime/1000) + " uptime="
|
Log.d(TAG, "Battery type time: realtime=" + (mTypeBatteryRealtimeUs /1000) + " uptime="
|
||||||
+ (mTypeBatteryUptime/1000));
|
+ (mTypeBatteryUptimeUs /1000));
|
||||||
}
|
}
|
||||||
mMinDrainedPower = (mStats.getLowDischargeAmountSinceCharge()
|
mMinDrainedPower = (mStats.getLowDischargeAmountSinceCharge()
|
||||||
* mPowerProfile.getBatteryCapacity()) / 100;
|
* mPowerProfile.getBatteryCapacity()) / 100;
|
||||||
@@ -489,7 +489,7 @@ public final class BatteryStatsHelper {
|
|||||||
|
|
||||||
private void processAppUsage(SparseArray<UserHandle> asUsers) {
|
private void processAppUsage(SparseArray<UserHandle> asUsers) {
|
||||||
final boolean forAllUsers = (asUsers.get(UserHandle.USER_ALL) != null);
|
final boolean forAllUsers = (asUsers.get(UserHandle.USER_ALL) != null);
|
||||||
mStatsPeriod = mTypeBatteryRealtime;
|
mStatsPeriod = mTypeBatteryRealtimeUs;
|
||||||
|
|
||||||
BatterySipper osSipper = null;
|
BatterySipper osSipper = null;
|
||||||
final SparseArray<? extends Uid> uidStats = mStats.getUidStats();
|
final SparseArray<? extends Uid> uidStats = mStats.getUidStats();
|
||||||
@@ -498,14 +498,14 @@ public final class BatteryStatsHelper {
|
|||||||
final Uid u = uidStats.valueAt(iu);
|
final Uid u = uidStats.valueAt(iu);
|
||||||
final BatterySipper app = new BatterySipper(BatterySipper.DrainType.APP, u, 0);
|
final BatterySipper app = new BatterySipper(BatterySipper.DrainType.APP, u, 0);
|
||||||
|
|
||||||
mCpuPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mCpuPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mWakelockPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mWakelockPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mMobileRadioPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mMobileRadioPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mWifiPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mWifiPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mBluetoothPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mBluetoothPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mSensorPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mSensorPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mCameraPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
|
|
||||||
final double totalPower = app.sumPower();
|
final double totalPower = app.sumPower();
|
||||||
if (DEBUG && totalPower != 0) {
|
if (DEBUG && totalPower != 0) {
|
||||||
@@ -547,14 +547,14 @@ public final class BatteryStatsHelper {
|
|||||||
// The device has probably been awake for longer than the screen on
|
// The device has probably been awake for longer than the screen on
|
||||||
// time and application wake lock time would account for. Assign
|
// time and application wake lock time would account for. Assign
|
||||||
// this remainder to the OS, if possible.
|
// this remainder to the OS, if possible.
|
||||||
mWakelockPowerCalculator.calculateRemaining(osSipper, mStats, mRawRealtime,
|
mWakelockPowerCalculator.calculateRemaining(osSipper, mStats, mRawRealtimeUs,
|
||||||
mRawUptime, mStatsType);
|
mRawUptimeUs, mStatsType);
|
||||||
osSipper.sumPower();
|
osSipper.sumPower();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPhoneUsage() {
|
private void addPhoneUsage() {
|
||||||
long phoneOnTimeMs = mStats.getPhoneOnTime(mRawRealtime, mStatsType) / 1000;
|
long phoneOnTimeMs = mStats.getPhoneOnTime(mRawRealtimeUs, mStatsType) / 1000;
|
||||||
double phoneOnPower = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE)
|
double phoneOnPower = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE)
|
||||||
* phoneOnTimeMs / (60*60*1000);
|
* phoneOnTimeMs / (60*60*1000);
|
||||||
if (phoneOnPower != 0) {
|
if (phoneOnPower != 0) {
|
||||||
@@ -562,16 +562,19 @@ public final class BatteryStatsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Screen power is the additional power the screen takes while the device is running.
|
||||||
|
*/
|
||||||
private void addScreenUsage() {
|
private void addScreenUsage() {
|
||||||
double power = 0;
|
double power = 0;
|
||||||
long screenOnTimeMs = mStats.getScreenOnTime(mRawRealtime, mStatsType) / 1000;
|
long screenOnTimeMs = mStats.getScreenOnTime(mRawRealtimeUs, mStatsType) / 1000;
|
||||||
power += screenOnTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_ON);
|
power += screenOnTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_ON);
|
||||||
final double screenFullPower =
|
final double screenFullPower =
|
||||||
mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
|
mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
|
||||||
for (int i = 0; i < BatteryStats.NUM_SCREEN_BRIGHTNESS_BINS; i++) {
|
for (int i = 0; i < BatteryStats.NUM_SCREEN_BRIGHTNESS_BINS; i++) {
|
||||||
double screenBinPower = screenFullPower * (i + 0.5f)
|
double screenBinPower = screenFullPower * (i + 0.5f)
|
||||||
/ BatteryStats.NUM_SCREEN_BRIGHTNESS_BINS;
|
/ BatteryStats.NUM_SCREEN_BRIGHTNESS_BINS;
|
||||||
long brightnessTime = mStats.getScreenBrightnessTime(i, mRawRealtime, mStatsType)
|
long brightnessTime = mStats.getScreenBrightnessTime(i, mRawRealtimeUs, mStatsType)
|
||||||
/ 1000;
|
/ 1000;
|
||||||
double p = screenBinPower*brightnessTime;
|
double p = screenBinPower*brightnessTime;
|
||||||
if (DEBUG && p != 0) {
|
if (DEBUG && p != 0) {
|
||||||
@@ -588,7 +591,7 @@ public final class BatteryStatsHelper {
|
|||||||
|
|
||||||
private void addRadioUsage() {
|
private void addRadioUsage() {
|
||||||
BatterySipper radio = new BatterySipper(BatterySipper.DrainType.CELL, null, 0);
|
BatterySipper radio = new BatterySipper(BatterySipper.DrainType.CELL, null, 0);
|
||||||
mMobileRadioPowerCalculator.calculateRemaining(radio, mStats, mRawRealtime, mRawUptime,
|
mMobileRadioPowerCalculator.calculateRemaining(radio, mStats, mRawRealtimeUs, mRawUptimeUs,
|
||||||
mStatsType);
|
mStatsType);
|
||||||
radio.sumPower();
|
radio.sumPower();
|
||||||
if (radio.totalPowerMah > 0) {
|
if (radio.totalPowerMah > 0) {
|
||||||
@@ -606,16 +609,26 @@ public final class BatteryStatsHelper {
|
|||||||
bs.sumPower();
|
bs.sumPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the baseline power usage for the device when it is in suspend and idle.
|
||||||
|
* The device is drawing POWER_CPU_IDLE power at its lowest power state.
|
||||||
|
* The device is drawing POWER_CPU_IDLE + POWER_CPU_AWAKE power when a wakelock is held.
|
||||||
|
*/
|
||||||
private void addIdleUsage() {
|
private void addIdleUsage() {
|
||||||
long idleTimeMs = (mTypeBatteryRealtime
|
final double suspendPowerMaMs = (mTypeBatteryRealtimeUs / 1000) *
|
||||||
- mStats.getScreenOnTime(mRawRealtime, mStatsType)) / 1000;
|
mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_IDLE);
|
||||||
double idlePower = (idleTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_IDLE))
|
final double idlePowerMaMs = (mTypeBatteryUptimeUs / 1000) *
|
||||||
/ (60*60*1000);
|
mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_AWAKE);
|
||||||
if (DEBUG && idlePower != 0) {
|
final double totalPowerMah = (suspendPowerMaMs + idlePowerMaMs) / (60 * 60 * 1000);
|
||||||
Log.d(TAG, "Idle: time=" + idleTimeMs + " power=" + makemAh(idlePower));
|
if (DEBUG && totalPowerMah != 0) {
|
||||||
|
Log.d(TAG, "Suspend: time=" + (mTypeBatteryRealtimeUs / 1000)
|
||||||
|
+ " power=" + makemAh(suspendPowerMaMs / (60 * 60 * 1000)));
|
||||||
|
Log.d(TAG, "Idle: time=" + (mTypeBatteryUptimeUs / 1000)
|
||||||
|
+ " power=" + makemAh(idlePowerMaMs / (60 * 60 * 1000)));
|
||||||
}
|
}
|
||||||
if (idlePower != 0) {
|
|
||||||
addEntry(BatterySipper.DrainType.IDLE, idleTimeMs, idlePower);
|
if (totalPowerMah != 0) {
|
||||||
|
addEntry(BatterySipper.DrainType.IDLE, mTypeBatteryRealtimeUs / 1000, totalPowerMah);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,7 +641,7 @@ public final class BatteryStatsHelper {
|
|||||||
*/
|
*/
|
||||||
private void addWiFiUsage() {
|
private void addWiFiUsage() {
|
||||||
BatterySipper bs = new BatterySipper(DrainType.WIFI, null, 0);
|
BatterySipper bs = new BatterySipper(DrainType.WIFI, null, 0);
|
||||||
mWifiPowerCalculator.calculateRemaining(bs, mStats, mRawRealtime, mRawUptime, mStatsType);
|
mWifiPowerCalculator.calculateRemaining(bs, mStats, mRawRealtimeUs, mRawUptimeUs, mStatsType);
|
||||||
aggregateSippers(bs, mWifiSippers, "WIFI");
|
aggregateSippers(bs, mWifiSippers, "WIFI");
|
||||||
if (bs.totalPowerMah > 0) {
|
if (bs.totalPowerMah > 0) {
|
||||||
mUsageList.add(bs);
|
mUsageList.add(bs);
|
||||||
@@ -641,7 +654,7 @@ public final class BatteryStatsHelper {
|
|||||||
*/
|
*/
|
||||||
private void addBluetoothUsage() {
|
private void addBluetoothUsage() {
|
||||||
BatterySipper bs = new BatterySipper(BatterySipper.DrainType.BLUETOOTH, null, 0);
|
BatterySipper bs = new BatterySipper(BatterySipper.DrainType.BLUETOOTH, null, 0);
|
||||||
mBluetoothPowerCalculator.calculateRemaining(bs, mStats, mRawRealtime, mRawUptime,
|
mBluetoothPowerCalculator.calculateRemaining(bs, mStats, mRawRealtimeUs, mRawUptimeUs,
|
||||||
mStatsType);
|
mStatsType);
|
||||||
aggregateSippers(bs, mBluetoothSippers, "Bluetooth");
|
aggregateSippers(bs, mBluetoothSippers, "Bluetooth");
|
||||||
if (bs.totalPowerMah > 0) {
|
if (bs.totalPowerMah > 0) {
|
||||||
@@ -709,10 +722,6 @@ public final class BatteryStatsHelper {
|
|||||||
return mMaxDrainedPower;
|
return mMaxDrainedPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getBatteryTimeRemaining() { return mBatteryTimeRemaining; }
|
|
||||||
|
|
||||||
public long getChargeTimeRemaining() { return mChargeTimeRemaining; }
|
|
||||||
|
|
||||||
public static byte[] readFully(FileInputStream stream) throws java.io.IOException {
|
public static byte[] readFully(FileInputStream stream) throws java.io.IOException {
|
||||||
return readFully(stream, stream.available());
|
return readFully(stream, stream.available());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class PowerProfile {
|
|||||||
* Power consumption when CPU is awake (when a wake lock is held). This
|
* Power consumption when CPU is awake (when a wake lock is held). This
|
||||||
* should be 0 on devices that can go into full CPU power collapse even
|
* should be 0 on devices that can go into full CPU power collapse even
|
||||||
* when a wake lock is held. Otherwise, this is the power consumption in
|
* when a wake lock is held. Otherwise, this is the power consumption in
|
||||||
* addition to POWERR_CPU_IDLE due to a wake lock being held but with no
|
* addition to POWER_CPU_IDLE due to a wake lock being held but with no
|
||||||
* CPU activity.
|
* CPU activity.
|
||||||
*/
|
*/
|
||||||
public static final String POWER_CPU_AWAKE = "cpu.awake";
|
public static final String POWER_CPU_AWAKE = "cpu.awake";
|
||||||
|
|||||||
Reference in New Issue
Block a user