Merge changes from topic "multiDisplayPowerProfile" into sc-v2-dev
* changes: Update PowerProfile to support multidisplay devices Collect data from multiple DISPLAY EnergyConsumers
This commit is contained in:
committed by
Android (Google) Code Review
commit
71f8cf24e2
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_AMBIENT;
|
||||||
|
|
||||||
import android.os.BatteryConsumer;
|
import android.os.BatteryConsumer;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.BatteryUsageStats;
|
import android.os.BatteryUsageStats;
|
||||||
@@ -32,8 +34,9 @@ public class AmbientDisplayPowerCalculator extends PowerCalculator {
|
|||||||
private final UsageBasedPowerEstimator mPowerEstimator;
|
private final UsageBasedPowerEstimator mPowerEstimator;
|
||||||
|
|
||||||
public AmbientDisplayPowerCalculator(PowerProfile powerProfile) {
|
public AmbientDisplayPowerCalculator(PowerProfile powerProfile) {
|
||||||
|
// TODO(b/200239964): update to support multidisplay.
|
||||||
mPowerEstimator = new UsageBasedPowerEstimator(
|
mPowerEstimator = new UsageBasedPowerEstimator(
|
||||||
powerProfile.getAveragePower(PowerProfile.POWER_AMBIENT_DISPLAY));
|
powerProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_AMBIENT, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,10 +17,12 @@
|
|||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
|
||||||
|
import android.annotation.StringDef;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.util.Slog;
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -30,6 +32,8 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@@ -40,6 +44,8 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class PowerProfile {
|
public class PowerProfile {
|
||||||
|
|
||||||
|
public static final String TAG = "PowerProfile";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode.
|
* POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode.
|
||||||
* POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should
|
* POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should
|
||||||
@@ -145,12 +151,18 @@ public class PowerProfile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Power consumption when screen is in doze/ambient/always-on mode, including backlight power.
|
* Power consumption when screen is in doze/ambient/always-on mode, including backlight power.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #POWER_GROUP_DISPLAY_AMBIENT} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String POWER_AMBIENT_DISPLAY = "ambient.on";
|
public static final String POWER_AMBIENT_DISPLAY = "ambient.on";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Power consumption when screen is on, not including the backlight power.
|
* Power consumption when screen is on, not including the backlight power.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #POWER_GROUP_DISPLAY_SCREEN_ON} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public static final String POWER_SCREEN_ON = "screen.on";
|
public static final String POWER_SCREEN_ON = "screen.on";
|
||||||
|
|
||||||
@@ -175,7 +187,10 @@ public class PowerProfile {
|
|||||||
/**
|
/**
|
||||||
* Power consumption at full backlight brightness. If the backlight is at
|
* Power consumption at full backlight brightness. If the backlight is at
|
||||||
* 50% brightness, then this should be multiplied by 0.5
|
* 50% brightness, then this should be multiplied by 0.5
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #POWER_GROUP_DISPLAY_SCREEN_FULL} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public static final String POWER_SCREEN_FULL = "screen.full";
|
public static final String POWER_SCREEN_FULL = "screen.full";
|
||||||
|
|
||||||
@@ -220,6 +235,29 @@ public class PowerProfile {
|
|||||||
*/
|
*/
|
||||||
public static final String POWER_BATTERY_CAPACITY = "battery.capacity";
|
public static final String POWER_BATTERY_CAPACITY = "battery.capacity";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Power consumption when a screen is in doze/ambient/always-on mode, including backlight power.
|
||||||
|
*/
|
||||||
|
public static final String POWER_GROUP_DISPLAY_AMBIENT = "ambient.on.display";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Power consumption when a screen is on, not including the backlight power.
|
||||||
|
*/
|
||||||
|
public static final String POWER_GROUP_DISPLAY_SCREEN_ON = "screen.on.display";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Power consumption of a screen at full backlight brightness.
|
||||||
|
*/
|
||||||
|
public static final String POWER_GROUP_DISPLAY_SCREEN_FULL = "screen.full.display";
|
||||||
|
|
||||||
|
@StringDef(prefix = { "POWER_GROUP_" }, value = {
|
||||||
|
POWER_GROUP_DISPLAY_AMBIENT,
|
||||||
|
POWER_GROUP_DISPLAY_SCREEN_ON,
|
||||||
|
POWER_GROUP_DISPLAY_SCREEN_FULL,
|
||||||
|
})
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
public @interface PowerGroup {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map from Power Use Item to its power consumption.
|
* A map from Power Use Item to its power consumption.
|
||||||
*/
|
*/
|
||||||
@@ -255,6 +293,7 @@ public class PowerProfile {
|
|||||||
readPowerValuesFromXml(context, forTest);
|
readPowerValuesFromXml(context, forTest);
|
||||||
}
|
}
|
||||||
initCpuClusters();
|
initCpuClusters();
|
||||||
|
initDisplays();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +463,58 @@ public class PowerProfile {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int mNumDisplays;
|
||||||
|
|
||||||
|
private void initDisplays() {
|
||||||
|
// Figure out how many displays are listed in the power profile.
|
||||||
|
mNumDisplays = 0;
|
||||||
|
while (!Double.isNaN(
|
||||||
|
getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_AMBIENT, mNumDisplays, Double.NaN))
|
||||||
|
|| !Double.isNaN(
|
||||||
|
getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_ON, mNumDisplays, Double.NaN))
|
||||||
|
|| !Double.isNaN(
|
||||||
|
getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_FULL, mNumDisplays,
|
||||||
|
Double.NaN))) {
|
||||||
|
mNumDisplays++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle legacy display power constants.
|
||||||
|
final Double deprecatedAmbientDisplay = sPowerItemMap.get(POWER_AMBIENT_DISPLAY);
|
||||||
|
boolean legacy = false;
|
||||||
|
if (deprecatedAmbientDisplay != null && mNumDisplays == 0) {
|
||||||
|
final String key = getOrdinalPowerType(POWER_GROUP_DISPLAY_AMBIENT, 0);
|
||||||
|
Slog.w(TAG, POWER_AMBIENT_DISPLAY + " is deprecated! Use " + key + " instead.");
|
||||||
|
sPowerItemMap.put(key, deprecatedAmbientDisplay);
|
||||||
|
legacy = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Double deprecatedScreenOn = sPowerItemMap.get(POWER_SCREEN_ON);
|
||||||
|
if (deprecatedScreenOn != null && mNumDisplays == 0) {
|
||||||
|
final String key = getOrdinalPowerType(POWER_GROUP_DISPLAY_SCREEN_ON, 0);
|
||||||
|
Slog.w(TAG, POWER_SCREEN_ON + " is deprecated! Use " + key + " instead.");
|
||||||
|
sPowerItemMap.put(key, deprecatedScreenOn);
|
||||||
|
legacy = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Double deprecatedScreenFull = sPowerItemMap.get(POWER_SCREEN_FULL);
|
||||||
|
if (deprecatedScreenFull != null && mNumDisplays == 0) {
|
||||||
|
final String key = getOrdinalPowerType(POWER_GROUP_DISPLAY_SCREEN_FULL, 0);
|
||||||
|
Slog.w(TAG, POWER_SCREEN_FULL + " is deprecated! Use " + key + " instead.");
|
||||||
|
sPowerItemMap.put(key, deprecatedScreenFull);
|
||||||
|
legacy = true;
|
||||||
|
}
|
||||||
|
if (legacy) {
|
||||||
|
mNumDisplays = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number built in displays on the device as defined in the power_profile.xml.
|
||||||
|
*/
|
||||||
|
public int getNumDisplays() {
|
||||||
|
return mNumDisplays;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of memory bandwidth buckets defined in power_profile.xml, or a
|
* Returns the number of memory bandwidth buckets defined in power_profile.xml, or a
|
||||||
* default value if the subsystem has no recorded value.
|
* default value if the subsystem has no recorded value.
|
||||||
@@ -495,6 +586,32 @@ public class PowerProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the average current in mA consumed by an ordinaled subsystem, or the given
|
||||||
|
* default value if the subsystem has no recorded value.
|
||||||
|
*
|
||||||
|
* @param group the subsystem {@link PowerGroup}.
|
||||||
|
* @param ordinal which entity in the {@link PowerGroup}.
|
||||||
|
* @param defaultValue the value to return if the subsystem has no recorded value.
|
||||||
|
* @return the average current in milliAmps.
|
||||||
|
*/
|
||||||
|
public double getAveragePowerForOrdinal(@PowerGroup String group, int ordinal,
|
||||||
|
double defaultValue) {
|
||||||
|
final String type = getOrdinalPowerType(group, ordinal);
|
||||||
|
return getAveragePowerOrDefault(type, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the average current in mA consumed by an ordinaled subsystem.
|
||||||
|
*
|
||||||
|
* @param group the subsystem {@link PowerGroup}.
|
||||||
|
* @param ordinal which entity in the {@link PowerGroup}.
|
||||||
|
* @return the average current in milliAmps.
|
||||||
|
*/
|
||||||
|
public double getAveragePowerForOrdinal(@PowerGroup String group, int ordinal) {
|
||||||
|
return getAveragePowerForOrdinal(group, ordinal, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the battery capacity, if available, in milli Amp Hours. If not available,
|
* Returns the battery capacity, if available, in milli Amp Hours. If not available,
|
||||||
* it returns zero.
|
* it returns zero.
|
||||||
@@ -682,4 +799,9 @@ public class PowerProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates the key for an ordinaled power constant from the group and ordinal.
|
||||||
|
private static String getOrdinalPowerType(@PowerGroup String group, int ordinal) {
|
||||||
|
return group + ordinal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_FULL;
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_ON;
|
||||||
|
|
||||||
import android.os.BatteryConsumer;
|
import android.os.BatteryConsumer;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.BatteryUsageStats;
|
import android.os.BatteryUsageStats;
|
||||||
@@ -50,10 +53,11 @@ public class ScreenPowerCalculator extends PowerCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ScreenPowerCalculator(PowerProfile powerProfile) {
|
public ScreenPowerCalculator(PowerProfile powerProfile) {
|
||||||
|
// TODO(b/200239964): update to support multidisplay.
|
||||||
mScreenOnPowerEstimator = new UsageBasedPowerEstimator(
|
mScreenOnPowerEstimator = new UsageBasedPowerEstimator(
|
||||||
powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_ON));
|
powerProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_ON, 0));
|
||||||
mScreenFullPowerEstimator = new UsageBasedPowerEstimator(
|
mScreenFullPowerEstimator = new UsageBasedPowerEstimator(
|
||||||
powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL));
|
powerProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_FULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,9 +27,33 @@
|
|||||||
are totally dependent on the platform and can vary
|
are totally dependent on the platform and can vary
|
||||||
significantly, so should be measured on the shipping platform
|
significantly, so should be measured on the shipping platform
|
||||||
with a power meter. -->
|
with a power meter. -->
|
||||||
<item name="ambient.on">0.1</item> <!-- ~100mA -->
|
|
||||||
<item name="screen.on">0.1</item> <!-- ~100mA -->
|
<!-- Display related values. -->
|
||||||
<item name="screen.full">0.1</item> <!-- ~100mA -->
|
<!-- Average battery current draw of display0 while in ambient mode, including backlight.
|
||||||
|
There must be one of these for each display, labeled:
|
||||||
|
ambient.on.display0, ambient.on.display1, etc...
|
||||||
|
|
||||||
|
Each display suffix number should match it's ordinal in its display device config.
|
||||||
|
-->
|
||||||
|
<item name="ambient.on.display0">0.1</item> <!-- ~100mA -->
|
||||||
|
<!-- Average battery current draw of display0 while on without backlight.
|
||||||
|
There must be one of these for each display, labeled:
|
||||||
|
screen.on.display0, screen.on.display1, etc...
|
||||||
|
|
||||||
|
Each display suffix number should match it's ordinal in its display device config.
|
||||||
|
-->
|
||||||
|
<item name="screen.on.display0">0.1</item> <!-- ~100mA -->
|
||||||
|
<!-- Average battery current draw of the backlight at full brightness.
|
||||||
|
The full current draw of display N at full brightness should be the sum of screen.on.displayN
|
||||||
|
and screen.full.displayN
|
||||||
|
|
||||||
|
There must be one of these for each display, labeled:
|
||||||
|
screen.full.display0, screen.full.display1, etc...
|
||||||
|
|
||||||
|
Each display suffix number should match it's ordinal in its display device config.
|
||||||
|
-->
|
||||||
|
<item name="screen.full.display0">0.1</item> <!-- ~100mA -->
|
||||||
|
|
||||||
<item name="bluetooth.active">0.1</item> <!-- Bluetooth data transfer, ~10mA -->
|
<item name="bluetooth.active">0.1</item> <!-- Bluetooth data transfer, ~10mA -->
|
||||||
<item name="bluetooth.on">0.1</item> <!-- Bluetooth on & connectable, but not connected, ~0.1mA -->
|
<item name="bluetooth.on">0.1</item> <!-- Bluetooth on & connectable, but not connected, ~0.1mA -->
|
||||||
<item name="wifi.on">0.1</item> <!-- ~3mA -->
|
<item name="wifi.on">0.1</item> <!-- ~3mA -->
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_AMBIENT;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.os.BatteryConsumer;
|
import android.os.BatteryConsumer;
|
||||||
@@ -36,7 +38,7 @@ public class AmbientDisplayPowerCalculatorTest {
|
|||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final BatteryUsageStatsRule mStatsRule = new BatteryUsageStatsRule()
|
public final BatteryUsageStatsRule mStatsRule = new BatteryUsageStatsRule()
|
||||||
.setAveragePower(PowerProfile.POWER_AMBIENT_DISPLAY, 10.0);
|
.setAveragePowerForOrdinal(POWER_GROUP_DISPLAY_AMBIENT, 0, 10.0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMeasuredEnergyBasedModel() {
|
public void testMeasuredEnergyBasedModel() {
|
||||||
|
|||||||
@@ -110,6 +110,14 @@ public class BatteryUsageStatsRule implements TestRule {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BatteryUsageStatsRule setAveragePowerForOrdinal(String group, int ordinal,
|
||||||
|
double value) {
|
||||||
|
when(mPowerProfile.getAveragePowerForOrdinal(group, ordinal)).thenReturn(value);
|
||||||
|
when(mPowerProfile.getAveragePowerForOrdinal(eq(group), eq(ordinal),
|
||||||
|
anyDouble())).thenReturn(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Call only after setting the power profile information. */
|
/** Call only after setting the power profile information. */
|
||||||
public BatteryUsageStatsRule initMeasuredEnergyStatsLocked() {
|
public BatteryUsageStatsRule initMeasuredEnergyStatsLocked() {
|
||||||
return initMeasuredEnergyStatsLocked(new String[0]);
|
return initMeasuredEnergyStatsLocked(new String[0]);
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_AMBIENT;
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_FULL;
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_ON;
|
||||||
|
|
||||||
import androidx.test.InstrumentationRegistry;
|
import androidx.test.InstrumentationRegistry;
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
@@ -53,7 +57,12 @@ public class PowerProfileTest extends TestCase {
|
|||||||
assertEquals(4, mProfile.getNumSpeedStepsInCpuCluster(1));
|
assertEquals(4, mProfile.getNumSpeedStepsInCpuCluster(1));
|
||||||
assertEquals(60.0, mProfile.getAveragePowerForCpuCore(1, 3));
|
assertEquals(60.0, mProfile.getAveragePowerForCpuCore(1, 3));
|
||||||
assertEquals(3000.0, mProfile.getBatteryCapacity());
|
assertEquals(3000.0, mProfile.getBatteryCapacity());
|
||||||
assertEquals(0.5, mProfile.getAveragePower(PowerProfile.POWER_AMBIENT_DISPLAY));
|
assertEquals(0.5,
|
||||||
|
mProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_AMBIENT, 0));
|
||||||
|
assertEquals(100.0,
|
||||||
|
mProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_ON, 0));
|
||||||
|
assertEquals(800.0,
|
||||||
|
mProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_FULL, 0));
|
||||||
assertEquals(100.0, mProfile.getAveragePower(PowerProfile.POWER_AUDIO));
|
assertEquals(100.0, mProfile.getAveragePower(PowerProfile.POWER_AUDIO));
|
||||||
assertEquals(150.0, mProfile.getAveragePower(PowerProfile.POWER_VIDEO));
|
assertEquals(150.0, mProfile.getAveragePower(PowerProfile.POWER_VIDEO));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_FULL;
|
||||||
|
import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_SCREEN_ON;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
@@ -42,8 +45,8 @@ public class ScreenPowerCalculatorTest {
|
|||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final BatteryUsageStatsRule mStatsRule = new BatteryUsageStatsRule()
|
public final BatteryUsageStatsRule mStatsRule = new BatteryUsageStatsRule()
|
||||||
.setAveragePower(PowerProfile.POWER_SCREEN_ON, 36.0)
|
.setAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_ON, 0, 36.0)
|
||||||
.setAveragePower(PowerProfile.POWER_SCREEN_FULL, 48.0);
|
.setAveragePowerForOrdinal(POWER_GROUP_DISPLAY_SCREEN_FULL, 0, 48.0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMeasuredEnergyBasedModel() {
|
public void testMeasuredEnergyBasedModel() {
|
||||||
|
|||||||
@@ -659,11 +659,13 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
|
|||||||
|
|
||||||
// Inform mStats about each applicable measured energy (unless addressed elsewhere).
|
// Inform mStats about each applicable measured energy (unless addressed elsewhere).
|
||||||
if (measuredEnergyDeltas != null) {
|
if (measuredEnergyDeltas != null) {
|
||||||
final long displayChargeUC = measuredEnergyDeltas.displayChargeUC;
|
final long[] displayChargeUC = measuredEnergyDeltas.displayChargeUC;
|
||||||
if (displayChargeUC != MeasuredEnergySnapshot.UNAVAILABLE) {
|
if (displayChargeUC != null && displayChargeUC.length > 0) {
|
||||||
|
// TODO (b/194107383): pass all display ordinals to mStats.
|
||||||
|
final long primaryDisplayChargeUC = displayChargeUC[0];
|
||||||
// If updating, pass in what BatteryExternalStatsWorker thinks screenState is.
|
// If updating, pass in what BatteryExternalStatsWorker thinks screenState is.
|
||||||
mStats.updateDisplayMeasuredEnergyStatsLocked(displayChargeUC, screenState,
|
mStats.updateDisplayMeasuredEnergyStatsLocked(primaryDisplayChargeUC,
|
||||||
elapsedRealtime);
|
screenState, elapsedRealtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
final long gnssChargeUC = measuredEnergyDeltas.gnssChargeUC;
|
final long gnssChargeUC = measuredEnergyDeltas.gnssChargeUC;
|
||||||
@@ -948,6 +950,7 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
|
|||||||
switch (consumer.type) {
|
switch (consumer.type) {
|
||||||
case EnergyConsumerType.OTHER:
|
case EnergyConsumerType.OTHER:
|
||||||
case EnergyConsumerType.CPU_CLUSTER:
|
case EnergyConsumerType.CPU_CLUSTER:
|
||||||
|
case EnergyConsumerType.DISPLAY:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Slog.w(TAG, "EnergyConsumer '" + consumer.name + "' has unexpected ordinal "
|
Slog.w(TAG, "EnergyConsumer '" + consumer.name + "' has unexpected ordinal "
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ public class MeasuredEnergySnapshot {
|
|||||||
/** Number of ordinals for {@link EnergyConsumerType#CPU_CLUSTER}. */
|
/** Number of ordinals for {@link EnergyConsumerType#CPU_CLUSTER}. */
|
||||||
private final int mNumCpuClusterOrdinals;
|
private final int mNumCpuClusterOrdinals;
|
||||||
|
|
||||||
|
/** Number of ordinals for {@link EnergyConsumerType#DISPLAY}. */
|
||||||
|
private final int mNumDisplayOrdinals;
|
||||||
|
|
||||||
/** Number of ordinals for {@link EnergyConsumerType#OTHER}. */
|
/** Number of ordinals for {@link EnergyConsumerType#OTHER}. */
|
||||||
private final int mNumOtherOrdinals;
|
private final int mNumOtherOrdinals;
|
||||||
|
|
||||||
@@ -95,6 +98,7 @@ public class MeasuredEnergySnapshot {
|
|||||||
|
|
||||||
mNumCpuClusterOrdinals = calculateNumOrdinals(EnergyConsumerType.CPU_CLUSTER,
|
mNumCpuClusterOrdinals = calculateNumOrdinals(EnergyConsumerType.CPU_CLUSTER,
|
||||||
idToConsumerMap);
|
idToConsumerMap);
|
||||||
|
mNumDisplayOrdinals = calculateNumOrdinals(EnergyConsumerType.DISPLAY, idToConsumerMap);
|
||||||
mNumOtherOrdinals = calculateNumOrdinals(EnergyConsumerType.OTHER, idToConsumerMap);
|
mNumOtherOrdinals = calculateNumOrdinals(EnergyConsumerType.OTHER, idToConsumerMap);
|
||||||
mAttributionSnapshots = new SparseArray<>(mNumOtherOrdinals);
|
mAttributionSnapshots = new SparseArray<>(mNumOtherOrdinals);
|
||||||
}
|
}
|
||||||
@@ -108,7 +112,7 @@ public class MeasuredEnergySnapshot {
|
|||||||
public long[] cpuClusterChargeUC = null;
|
public long[] cpuClusterChargeUC = null;
|
||||||
|
|
||||||
/** The chargeUC for {@link EnergyConsumerType#DISPLAY}. */
|
/** The chargeUC for {@link EnergyConsumerType#DISPLAY}. */
|
||||||
public long displayChargeUC = UNAVAILABLE;
|
public long[] displayChargeUC = null;
|
||||||
|
|
||||||
/** The chargeUC for {@link EnergyConsumerType#GNSS}. */
|
/** The chargeUC for {@link EnergyConsumerType#GNSS}. */
|
||||||
public long gnssChargeUC = UNAVAILABLE;
|
public long gnssChargeUC = UNAVAILABLE;
|
||||||
@@ -212,7 +216,10 @@ public class MeasuredEnergySnapshot {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EnergyConsumerType.DISPLAY:
|
case EnergyConsumerType.DISPLAY:
|
||||||
output.displayChargeUC = deltaChargeUC;
|
if (output.displayChargeUC == null) {
|
||||||
|
output.displayChargeUC = new long[mNumDisplayOrdinals];
|
||||||
|
}
|
||||||
|
output.displayChargeUC[ordinal] = deltaChargeUC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EnergyConsumerType.GNSS:
|
case EnergyConsumerType.GNSS:
|
||||||
|
|||||||
@@ -74,15 +74,20 @@ public class BatteryExternalStatsWorkerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testTargetedEnergyConsumerQuerying() {
|
public void testTargetedEnergyConsumerQuerying() {
|
||||||
final int numCpuClusters = 4;
|
final int numCpuClusters = 4;
|
||||||
|
final int numDisplays = 5;
|
||||||
final int numOther = 3;
|
final int numOther = 3;
|
||||||
|
|
||||||
// Add some energy consumers used by BatteryExternalStatsWorker.
|
// Add some energy consumers used by BatteryExternalStatsWorker.
|
||||||
final IntArray tempAllIds = new IntArray();
|
final IntArray tempAllIds = new IntArray();
|
||||||
|
|
||||||
final int displayId = mPowerStatsInternal.addEnergyConsumer(EnergyConsumerType.DISPLAY, 0,
|
final int[] displayIds = new int[numDisplays];
|
||||||
"display");
|
for (int i = 0; i < numDisplays; i++) {
|
||||||
tempAllIds.add(displayId);
|
displayIds[i] = mPowerStatsInternal.addEnergyConsumer(
|
||||||
mPowerStatsInternal.incrementEnergyConsumption(displayId, 12345);
|
EnergyConsumerType.DISPLAY, i, "display" + i);
|
||||||
|
tempAllIds.add(displayIds[i]);
|
||||||
|
mPowerStatsInternal.incrementEnergyConsumption(displayIds[i], 12345 + i);
|
||||||
|
}
|
||||||
|
Arrays.sort(displayIds);
|
||||||
|
|
||||||
final int wifiId = mPowerStatsInternal.addEnergyConsumer(EnergyConsumerType.WIFI, 0,
|
final int wifiId = mPowerStatsInternal.addEnergyConsumer(EnergyConsumerType.WIFI, 0,
|
||||||
"wifi");
|
"wifi");
|
||||||
@@ -130,9 +135,13 @@ public class BatteryExternalStatsWorkerTest {
|
|||||||
|
|
||||||
final EnergyConsumerResult[] displayResults =
|
final EnergyConsumerResult[] displayResults =
|
||||||
mBatteryExternalStatsWorker.getMeasuredEnergyLocked(UPDATE_DISPLAY).getNow(null);
|
mBatteryExternalStatsWorker.getMeasuredEnergyLocked(UPDATE_DISPLAY).getNow(null);
|
||||||
// Results should only have the display energy consumer
|
// Results should only have the cpu cluster energy consumers
|
||||||
assertEquals(1, displayResults.length);
|
final int[] receivedDisplayIds = new int[displayResults.length];
|
||||||
assertEquals(displayId, displayResults[0].id);
|
for (int i = 0; i < displayResults.length; i++) {
|
||||||
|
receivedDisplayIds[i] = displayResults[i].id;
|
||||||
|
}
|
||||||
|
Arrays.sort(receivedDisplayIds);
|
||||||
|
assertArrayEquals(displayIds, receivedDisplayIds);
|
||||||
|
|
||||||
final EnergyConsumerResult[] wifiResults =
|
final EnergyConsumerResult[] wifiResults =
|
||||||
mBatteryExternalStatsWorker.getMeasuredEnergyLocked(UPDATE_WIFI).getNow(null);
|
mBatteryExternalStatsWorker.getMeasuredEnergyLocked(UPDATE_WIFI).getNow(null);
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.server.am;
|
package com.android.server.am;
|
||||||
|
|
||||||
import static com.android.server.am.MeasuredEnergySnapshot.UNAVAILABLE;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -120,7 +118,7 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
// results0
|
// results0
|
||||||
MeasuredEnergyDeltaData delta = snapshot.updateAndGetDelta(RESULTS_0, VOLTAGE_0);
|
MeasuredEnergyDeltaData delta = snapshot.updateAndGetDelta(RESULTS_0, VOLTAGE_0);
|
||||||
if (delta != null) { // null is fine here. If non-null, it better be uninteresting though.
|
if (delta != null) { // null is fine here. If non-null, it better be uninteresting though.
|
||||||
assertEquals(UNAVAILABLE, delta.displayChargeUC);
|
assertNull(delta.displayChargeUC);
|
||||||
assertNull(delta.otherTotalChargeUC);
|
assertNull(delta.otherTotalChargeUC);
|
||||||
assertNull(delta.otherUidChargesUC);
|
assertNull(delta.otherUidChargesUC);
|
||||||
}
|
}
|
||||||
@@ -130,7 +128,7 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
assertNotNull(delta);
|
assertNotNull(delta);
|
||||||
long expectedChargeUC;
|
long expectedChargeUC;
|
||||||
expectedChargeUC = calculateChargeConsumedUC(14_000, VOLTAGE_0, 24_000, VOLTAGE_1);
|
expectedChargeUC = calculateChargeConsumedUC(14_000, VOLTAGE_0, 24_000, VOLTAGE_1);
|
||||||
assertEquals(expectedChargeUC, delta.displayChargeUC);
|
assertEquals(expectedChargeUC, delta.displayChargeUC[0]);
|
||||||
|
|
||||||
assertNotNull(delta.otherTotalChargeUC);
|
assertNotNull(delta.otherTotalChargeUC);
|
||||||
|
|
||||||
@@ -149,14 +147,14 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
delta = snapshot.updateAndGetDelta(RESULTS_2, VOLTAGE_2);
|
delta = snapshot.updateAndGetDelta(RESULTS_2, VOLTAGE_2);
|
||||||
assertNotNull(delta);
|
assertNotNull(delta);
|
||||||
expectedChargeUC = calculateChargeConsumedUC(24_000, VOLTAGE_1, 36_000, VOLTAGE_2);
|
expectedChargeUC = calculateChargeConsumedUC(24_000, VOLTAGE_1, 36_000, VOLTAGE_2);
|
||||||
assertEquals(expectedChargeUC, delta.displayChargeUC);
|
assertEquals(expectedChargeUC, delta.displayChargeUC[0]);
|
||||||
assertNull(delta.otherUidChargesUC);
|
assertNull(delta.otherUidChargesUC);
|
||||||
assertNull(delta.otherTotalChargeUC);
|
assertNull(delta.otherTotalChargeUC);
|
||||||
|
|
||||||
// results3
|
// results3
|
||||||
delta = snapshot.updateAndGetDelta(RESULTS_3, VOLTAGE_3);
|
delta = snapshot.updateAndGetDelta(RESULTS_3, VOLTAGE_3);
|
||||||
assertNotNull(delta);
|
assertNotNull(delta);
|
||||||
assertEquals(UNAVAILABLE, delta.displayChargeUC);
|
assertNull(delta.displayChargeUC);
|
||||||
|
|
||||||
assertNotNull(delta.otherTotalChargeUC);
|
assertNotNull(delta.otherTotalChargeUC);
|
||||||
|
|
||||||
@@ -183,7 +181,7 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
delta = snapshot.updateAndGetDelta(RESULTS_4, VOLTAGE_4);
|
delta = snapshot.updateAndGetDelta(RESULTS_4, VOLTAGE_4);
|
||||||
assertNotNull(delta);
|
assertNotNull(delta);
|
||||||
expectedChargeUC = calculateChargeConsumedUC(36_000, VOLTAGE_2, 43_000, VOLTAGE_4);
|
expectedChargeUC = calculateChargeConsumedUC(36_000, VOLTAGE_2, 43_000, VOLTAGE_4);
|
||||||
assertEquals(expectedChargeUC, delta.displayChargeUC);
|
assertEquals(expectedChargeUC, delta.displayChargeUC[0]);
|
||||||
|
|
||||||
assertNotNull(delta.otherTotalChargeUC);
|
assertNotNull(delta.otherTotalChargeUC);
|
||||||
expectedChargeUC = calculateChargeConsumedUC(190_000, VOLTAGE_3, 290_000, VOLTAGE_4);
|
expectedChargeUC = calculateChargeConsumedUC(190_000, VOLTAGE_3, 290_000, VOLTAGE_4);
|
||||||
@@ -210,7 +208,7 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
// results0
|
// results0
|
||||||
MeasuredEnergyDeltaData delta = snapshot.updateAndGetDelta(RESULTS_0, VOLTAGE_0);
|
MeasuredEnergyDeltaData delta = snapshot.updateAndGetDelta(RESULTS_0, VOLTAGE_0);
|
||||||
if (delta != null) { // null is fine here. If non-null, it better be uninteresting though.
|
if (delta != null) { // null is fine here. If non-null, it better be uninteresting though.
|
||||||
assertEquals(UNAVAILABLE, delta.displayChargeUC);
|
assertNull(delta.displayChargeUC);
|
||||||
assertNull(delta.otherTotalChargeUC);
|
assertNull(delta.otherTotalChargeUC);
|
||||||
assertNull(delta.otherUidChargesUC);
|
assertNull(delta.otherUidChargesUC);
|
||||||
}
|
}
|
||||||
@@ -220,7 +218,7 @@ public final class MeasuredEnergySnapshotTest {
|
|||||||
assertNotNull(delta);
|
assertNotNull(delta);
|
||||||
final long expectedChargeUC =
|
final long expectedChargeUC =
|
||||||
calculateChargeConsumedUC(14_000, VOLTAGE_0, 24_000, VOLTAGE_1);
|
calculateChargeConsumedUC(14_000, VOLTAGE_0, 24_000, VOLTAGE_1);
|
||||||
assertEquals(expectedChargeUC, delta.displayChargeUC);
|
assertEquals(expectedChargeUC, delta.displayChargeUC[0]);
|
||||||
assertNull(delta.otherTotalChargeUC); // Although in the results, they're not in the idMap
|
assertNull(delta.otherTotalChargeUC); // Although in the results, they're not in the idMap
|
||||||
assertNull(delta.otherUidChargesUC);
|
assertNull(delta.otherUidChargesUC);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user