diff options
29 files changed, 376 insertions, 360 deletions
diff --git a/services/core/java/com/android/server/power/stats/BluetoothPowerStatsCollector.java b/services/core/java/com/android/server/power/stats/BluetoothPowerStatsCollector.java index 1d7843877390..622cc1630e69 100644 --- a/services/core/java/com/android/server/power/stats/BluetoothPowerStatsCollector.java +++ b/services/core/java/com/android/server/power/stats/BluetoothPowerStatsCollector.java @@ -131,13 +131,7 @@ public class BluetoothPowerStatsCollector extends PowerStatsCollector { mLastConsumedEnergyUws = new long[mEnergyConsumerIds.length]; Arrays.fill(mLastConsumedEnergyUws, ENERGY_UNSPECIFIED); - mLayout = new BluetoothPowerStatsLayout(); - mLayout.addDeviceBluetoothControllerActivity(); - mLayout.addDeviceSectionEnergyConsumers(mEnergyConsumerIds.length); - mLayout.addDeviceSectionUsageDuration(); - mLayout.addDeviceSectionPowerEstimate(); - mLayout.addUidTrafficStats(); - mLayout.addUidSectionPowerEstimate(); + mLayout = new BluetoothPowerStatsLayout(mEnergyConsumerIds.length); PersistableBundle extras = new PersistableBundle(); mLayout.toExtras(extras); diff --git a/services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java b/services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java index 2be01b81c9b8..7b006f0af84a 100644 --- a/services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java +++ b/services/core/java/com/android/server/power/stats/CpuPowerStatsCollector.java @@ -133,14 +133,8 @@ public class CpuPowerStatsCollector extends PowerStatsCollector { mTempCpuTimeByScalingStep = new long[cpuScalingStepCount]; int[] scalingStepToPowerBracketMap = initPowerBrackets(); - mLayout = new CpuPowerStatsLayout(); - mLayout.addDeviceSectionCpuTimeByScalingStep(cpuScalingStepCount); - mLayout.addDeviceSectionCpuTimeByCluster(mCpuScalingPolicies.getPolicies().length); - mLayout.addDeviceSectionUsageDuration(); - mLayout.addDeviceSectionEnergyConsumers(mCpuEnergyConsumerIds.length); - mLayout.addDeviceSectionPowerEstimate(); - mLayout.addUidSectionCpuTimeByPowerBracket(scalingStepToPowerBracketMap); - mLayout.addUidSectionPowerEstimate(); + mLayout = new CpuPowerStatsLayout(mCpuEnergyConsumerIds.length, + mCpuScalingPolicies.getPolicies().length, scalingStepToPowerBracketMap); PersistableBundle extras = new PersistableBundle(); mLayout.toExtras(extras); diff --git a/services/core/java/com/android/server/power/stats/MobileRadioPowerStatsCollector.java b/services/core/java/com/android/server/power/stats/MobileRadioPowerStatsCollector.java index e785e1ec8f54..506c072dd0ed 100644 --- a/services/core/java/com/android/server/power/stats/MobileRadioPowerStatsCollector.java +++ b/services/core/java/com/android/server/power/stats/MobileRadioPowerStatsCollector.java @@ -158,14 +158,7 @@ public class MobileRadioPowerStatsCollector extends PowerStatsCollector { mLastConsumedEnergyUws = new long[mEnergyConsumerIds.length]; Arrays.fill(mLastConsumedEnergyUws, ENERGY_UNSPECIFIED); - mLayout = new MobileRadioPowerStatsLayout(); - mLayout.addDeviceMobileActivity(); - mLayout.addDeviceSectionEnergyConsumers(mEnergyConsumerIds.length); - mLayout.addStateStats(); - mLayout.addUidNetworkStats(); - mLayout.addDeviceSectionUsageDuration(); - mLayout.addDeviceSectionPowerEstimate(); - mLayout.addUidSectionPowerEstimate(); + mLayout = new MobileRadioPowerStatsLayout(mEnergyConsumerIds.length); SparseArray<String> stateLabels = new SparseArray<>(); for (int rat = 0; rat < BatteryStats.RADIO_ACCESS_TECHNOLOGY_COUNT; rat++) { diff --git a/services/core/java/com/android/server/power/stats/ScreenPowerStatsCollector.java b/services/core/java/com/android/server/power/stats/ScreenPowerStatsCollector.java index 9c60a3ff4553..4b5d89907f84 100644 --- a/services/core/java/com/android/server/power/stats/ScreenPowerStatsCollector.java +++ b/services/core/java/com/android/server/power/stats/ScreenPowerStatsCollector.java @@ -104,13 +104,8 @@ public class ScreenPowerStatsCollector extends PowerStatsCollector { mLastConsumedEnergyUws = new long[mEnergyConsumerIds.length]; Arrays.fill(mLastConsumedEnergyUws, ENERGY_UNSPECIFIED); - mLayout = new ScreenPowerStatsLayout(); - mLayout.addDeviceScreenUsageDurationSection(mInjector.getDisplayCount()); - mLayout.addDeviceSectionEnergyConsumers(mEnergyConsumerIds.length); - mLayout.addDeviceSectionUsageDuration(); - mLayout.addDeviceSectionPowerEstimate(); - mLayout.addUidTopActivitiyDuration(); - mLayout.addUidSectionPowerEstimate(); + mLayout = new ScreenPowerStatsLayout(mEnergyConsumerIds.length, + mInjector.getDisplayCount()); PersistableBundle extras = new PersistableBundle(); mLayout.toExtras(extras); diff --git a/services/core/java/com/android/server/power/stats/WifiPowerStatsCollector.java b/services/core/java/com/android/server/power/stats/WifiPowerStatsCollector.java index 5039b07288fb..45bf5739cddb 100644 --- a/services/core/java/com/android/server/power/stats/WifiPowerStatsCollector.java +++ b/services/core/java/com/android/server/power/stats/WifiPowerStatsCollector.java @@ -141,13 +141,7 @@ public class WifiPowerStatsCollector extends PowerStatsCollector { mLastConsumedEnergyUws = new long[mEnergyConsumerIds.length]; Arrays.fill(mLastConsumedEnergyUws, ENERGY_UNSPECIFIED); - mLayout = new WifiPowerStatsLayout(); - mLayout.addDeviceWifiActivity(mPowerReportingSupported); - mLayout.addDeviceSectionEnergyConsumers(mEnergyConsumerIds.length); - mLayout.addUidNetworkStats(); - mLayout.addDeviceSectionUsageDuration(); - mLayout.addDeviceSectionPowerEstimate(); - mLayout.addUidSectionPowerEstimate(); + mLayout = new WifiPowerStatsLayout(mEnergyConsumerIds.length, mPowerReportingSupported); PersistableBundle extras = new PersistableBundle(); mLayout.toExtras(extras); diff --git a/services/core/java/com/android/server/power/stats/format/AmbientDisplayPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/AmbientDisplayPowerStatsLayout.java new file mode 100644 index 000000000000..1b99b0d2eb86 --- /dev/null +++ b/services/core/java/com/android/server/power/stats/format/AmbientDisplayPowerStatsLayout.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.power.stats.format; + +public class AmbientDisplayPowerStatsLayout extends PowerStatsLayout { + public AmbientDisplayPowerStatsLayout() { + addDeviceSectionPowerEstimate(); + } +} diff --git a/services/core/java/com/android/server/power/stats/format/BinaryStatePowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/BinaryStatePowerStatsLayout.java index 09d175948477..4a26d83175fa 100644 --- a/services/core/java/com/android/server/power/stats/format/BinaryStatePowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/BinaryStatePowerStatsLayout.java @@ -16,9 +16,15 @@ package com.android.server.power.stats.format; +import com.android.internal.os.PowerStats; + public class BinaryStatePowerStatsLayout extends EnergyConsumerPowerStatsLayout { public BinaryStatePowerStatsLayout() { addDeviceSectionUsageDuration(); addUidSectionUsageDuration(); } + + public BinaryStatePowerStatsLayout(PowerStats.Descriptor descriptor) { + super(descriptor); + } } diff --git a/services/core/java/com/android/server/power/stats/format/BluetoothPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/BluetoothPowerStatsLayout.java index 35d2bce978f5..534a9f701019 100644 --- a/services/core/java/com/android/server/power/stats/format/BluetoothPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/BluetoothPowerStatsLayout.java @@ -37,21 +37,49 @@ public class BluetoothPowerStatsLayout extends PowerStatsLayout { private int mUidTxBytesPosition; private int mUidScanTimePosition; - public BluetoothPowerStatsLayout() { + public BluetoothPowerStatsLayout(int energyConsumerCount) { + addDeviceBluetoothControllerActivity(); + addDeviceSectionEnergyConsumers(energyConsumerCount); + addDeviceSectionUsageDuration(); + addDeviceSectionPowerEstimate(); + addUidTrafficStats(); + addUidSectionPowerEstimate(); } public BluetoothPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { super(descriptor); + PersistableBundle extras = descriptor.extras; + mDeviceRxTimePosition = extras.getInt(EXTRA_DEVICE_RX_TIME_POSITION); + mDeviceTxTimePosition = extras.getInt(EXTRA_DEVICE_TX_TIME_POSITION); + mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); + mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); + mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); + mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); + mUidScanTimePosition = extras.getInt(EXTRA_UID_SCAN_TIME_POSITION); } - public void addDeviceBluetoothControllerActivity() { + /** + * Copies the elements of the stats array layout into <code>extras</code> + */ + public void toExtras(PersistableBundle extras) { + super.toExtras(extras); + extras.putInt(EXTRA_DEVICE_RX_TIME_POSITION, mDeviceRxTimePosition); + extras.putInt(EXTRA_DEVICE_TX_TIME_POSITION, mDeviceTxTimePosition); + extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); + extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); + extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); + extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); + extras.putInt(EXTRA_UID_SCAN_TIME_POSITION, mUidScanTimePosition); + } + + private void addDeviceBluetoothControllerActivity() { mDeviceRxTimePosition = addDeviceSection(1, "rx"); mDeviceTxTimePosition = addDeviceSection(1, "tx"); mDeviceIdleTimePosition = addDeviceSection(1, "idle"); mDeviceScanTimePosition = addDeviceSection(1, "scan", FLAG_OPTIONAL); } - public void addUidTrafficStats() { + private void addUidTrafficStats() { mUidRxBytesPosition = addUidSection(1, "rx-B"); mUidTxBytesPosition = addUidSection(1, "tx-B"); mUidScanTimePosition = addUidSection(1, "scan", FLAG_OPTIONAL); @@ -112,32 +140,4 @@ public class BluetoothPowerStatsLayout extends PowerStatsLayout { public long getUidScanTime(long[] stats) { return stats[mUidScanTimePosition]; } - - /** - * Copies the elements of the stats array layout into <code>extras</code> - */ - public void toExtras(PersistableBundle extras) { - super.toExtras(extras); - extras.putInt(EXTRA_DEVICE_RX_TIME_POSITION, mDeviceRxTimePosition); - extras.putInt(EXTRA_DEVICE_TX_TIME_POSITION, mDeviceTxTimePosition); - extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); - extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); - extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); - extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); - extras.putInt(EXTRA_UID_SCAN_TIME_POSITION, mUidScanTimePosition); - } - - /** - * Retrieves elements of the stats array layout from <code>extras</code> - */ - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); - mDeviceRxTimePosition = extras.getInt(EXTRA_DEVICE_RX_TIME_POSITION); - mDeviceTxTimePosition = extras.getInt(EXTRA_DEVICE_TX_TIME_POSITION); - mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); - mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); - mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); - mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); - mUidScanTimePosition = extras.getInt(EXTRA_UID_SCAN_TIME_POSITION); - } } diff --git a/services/core/java/com/android/server/power/stats/format/CpuPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/CpuPowerStatsLayout.java index 5e49977d5cb3..3186d7da6cb4 100644 --- a/services/core/java/com/android/server/power/stats/format/CpuPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/CpuPowerStatsLayout.java @@ -16,8 +16,11 @@ package com.android.server.power.stats.format; +import android.annotation.NonNull; import android.os.PersistableBundle; +import com.android.internal.os.PowerStats; + /** * Captures the positions and lengths of sections of the stats array, such as time-in-state, * power usage estimates etc. @@ -40,10 +43,59 @@ public class CpuPowerStatsLayout extends PowerStatsLayout { private int[] mScalingStepToPowerBracketMap; + public CpuPowerStatsLayout(int energyConsumerCount, int cpuScalingPolicyCount, + int[] scalingStepToPowerBracketMap) { + addDeviceSectionCpuTimeByScalingStep(scalingStepToPowerBracketMap.length); + addDeviceSectionCpuTimeByCluster(cpuScalingPolicyCount); + addDeviceSectionUsageDuration(); + addDeviceSectionEnergyConsumers(energyConsumerCount); + addDeviceSectionPowerEstimate(); + addUidSectionCpuTimeByPowerBracket(scalingStepToPowerBracketMap); + addUidSectionPowerEstimate(); + } + + public CpuPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { + super(descriptor); + PersistableBundle extras = descriptor.extras; + mDeviceCpuTimeByScalingStepPosition = + extras.getInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_POSITION); + mDeviceCpuTimeByScalingStepCount = + extras.getInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_COUNT); + mDeviceCpuTimeByClusterPosition = + extras.getInt(EXTRA_DEVICE_TIME_BY_CLUSTER_POSITION); + mDeviceCpuTimeByClusterCount = + extras.getInt(EXTRA_DEVICE_TIME_BY_CLUSTER_COUNT); + mUidPowerBracketsPosition = extras.getInt(EXTRA_UID_BRACKETS_POSITION); + mScalingStepToPowerBracketMap = + getIntArray(extras, EXTRA_UID_STATS_SCALING_STEP_TO_POWER_BRACKET); + if (mScalingStepToPowerBracketMap == null) { + mScalingStepToPowerBracketMap = new int[mDeviceCpuTimeByScalingStepCount]; + } + updatePowerBracketCount(); + } + + /** + * Copies the elements of the stats array layout into <code>extras</code> + */ + public void toExtras(PersistableBundle extras) { + super.toExtras(extras); + extras.putInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_POSITION, + mDeviceCpuTimeByScalingStepPosition); + extras.putInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_COUNT, + mDeviceCpuTimeByScalingStepCount); + extras.putInt(EXTRA_DEVICE_TIME_BY_CLUSTER_POSITION, + mDeviceCpuTimeByClusterPosition); + extras.putInt(EXTRA_DEVICE_TIME_BY_CLUSTER_COUNT, + mDeviceCpuTimeByClusterCount); + extras.putInt(EXTRA_UID_BRACKETS_POSITION, mUidPowerBracketsPosition); + putIntArray(extras, EXTRA_UID_STATS_SCALING_STEP_TO_POWER_BRACKET, + mScalingStepToPowerBracketMap); + } + /** * Declare that the stats array has a section capturing CPU time per scaling step */ - public void addDeviceSectionCpuTimeByScalingStep(int scalingStepCount) { + private void addDeviceSectionCpuTimeByScalingStep(int scalingStepCount) { mDeviceCpuTimeByScalingStepPosition = addDeviceSection(scalingStepCount, "steps"); mDeviceCpuTimeByScalingStepCount = scalingStepCount; } @@ -71,7 +123,7 @@ public class CpuPowerStatsLayout extends PowerStatsLayout { /** * Declare that the stats array has a section capturing CPU time in each cluster */ - public void addDeviceSectionCpuTimeByCluster(int clusterCount) { + private void addDeviceSectionCpuTimeByCluster(int clusterCount) { mDeviceCpuTimeByClusterPosition = addDeviceSection(clusterCount, "clusters"); mDeviceCpuTimeByClusterCount = clusterCount; } @@ -99,7 +151,7 @@ public class CpuPowerStatsLayout extends PowerStatsLayout { /** * Declare that the UID stats array has a section capturing CPU time per power bracket. */ - public void addUidSectionCpuTimeByPowerBracket(int[] scalingStepToPowerBracketMap) { + private void addUidSectionCpuTimeByPowerBracket(int[] scalingStepToPowerBracketMap) { mScalingStepToPowerBracketMap = scalingStepToPowerBracketMap; updatePowerBracketCount(); mUidPowerBracketsPosition = addUidSection(mUidPowerBracketCount, "time"); @@ -135,44 +187,4 @@ public class CpuPowerStatsLayout extends PowerStatsLayout { public long getUidTimeByPowerBracket(long[] stats, int bracket) { return stats[mUidPowerBracketsPosition + bracket]; } - - /** - * Copies the elements of the stats array layout into <code>extras</code> - */ - public void toExtras(PersistableBundle extras) { - super.toExtras(extras); - extras.putInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_POSITION, - mDeviceCpuTimeByScalingStepPosition); - extras.putInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_COUNT, - mDeviceCpuTimeByScalingStepCount); - extras.putInt(EXTRA_DEVICE_TIME_BY_CLUSTER_POSITION, - mDeviceCpuTimeByClusterPosition); - extras.putInt(EXTRA_DEVICE_TIME_BY_CLUSTER_COUNT, - mDeviceCpuTimeByClusterCount); - extras.putInt(EXTRA_UID_BRACKETS_POSITION, mUidPowerBracketsPosition); - putIntArray(extras, EXTRA_UID_STATS_SCALING_STEP_TO_POWER_BRACKET, - mScalingStepToPowerBracketMap); - } - - /** - * Retrieves elements of the stats array layout from <code>extras</code> - */ - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); - mDeviceCpuTimeByScalingStepPosition = - extras.getInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_POSITION); - mDeviceCpuTimeByScalingStepCount = - extras.getInt(EXTRA_DEVICE_TIME_BY_SCALING_STEP_COUNT); - mDeviceCpuTimeByClusterPosition = - extras.getInt(EXTRA_DEVICE_TIME_BY_CLUSTER_POSITION); - mDeviceCpuTimeByClusterCount = - extras.getInt(EXTRA_DEVICE_TIME_BY_CLUSTER_COUNT); - mUidPowerBracketsPosition = extras.getInt(EXTRA_UID_BRACKETS_POSITION); - mScalingStepToPowerBracketMap = - getIntArray(extras, EXTRA_UID_STATS_SCALING_STEP_TO_POWER_BRACKET); - if (mScalingStepToPowerBracketMap == null) { - mScalingStepToPowerBracketMap = new int[mDeviceCpuTimeByScalingStepCount]; - } - updatePowerBracketCount(); - } } diff --git a/services/core/java/com/android/server/power/stats/format/EnergyConsumerPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/EnergyConsumerPowerStatsLayout.java index 4d3ce8a67ab7..e7a4822cf41d 100644 --- a/services/core/java/com/android/server/power/stats/format/EnergyConsumerPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/EnergyConsumerPowerStatsLayout.java @@ -16,6 +16,8 @@ package com.android.server.power.stats.format; +import com.android.internal.os.PowerStats; + public class EnergyConsumerPowerStatsLayout extends PowerStatsLayout { public EnergyConsumerPowerStatsLayout() { // Add a section for consumed energy, even if the specific device does not @@ -30,4 +32,8 @@ public class EnergyConsumerPowerStatsLayout extends PowerStatsLayout { addUidSectionEnergyConsumers(1); addUidSectionPowerEstimate(); } + + public EnergyConsumerPowerStatsLayout(PowerStats.Descriptor descriptor) { + super(descriptor); + } } diff --git a/services/core/java/com/android/server/power/stats/format/GnssPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/GnssPowerStatsLayout.java index 4da493bb471b..b70b17397e12 100644 --- a/services/core/java/com/android/server/power/stats/format/GnssPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/GnssPowerStatsLayout.java @@ -16,15 +16,18 @@ package com.android.server.power.stats.format; +import android.annotation.NonNull; import android.location.GnssSignalQuality; import android.os.PersistableBundle; +import com.android.internal.os.PowerStats; + public class GnssPowerStatsLayout extends BinaryStatePowerStatsLayout { private static final String EXTRA_DEVICE_TIME_SIGNAL_LEVEL_POSITION = "dt-sig"; private static final String EXTRA_UID_TIME_SIGNAL_LEVEL_POSITION = "ut-sig"; - private int mDeviceSignalLevelTimePosition; - private int mUidSignalLevelTimePosition; + private final int mDeviceSignalLevelTimePosition; + private final int mUidSignalLevelTimePosition; public GnssPowerStatsLayout() { mDeviceSignalLevelTimePosition = addDeviceSection( @@ -33,9 +36,9 @@ public class GnssPowerStatsLayout extends BinaryStatePowerStatsLayout { GnssSignalQuality.NUM_GNSS_SIGNAL_QUALITY_LEVELS, "level"); } - @Override - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); + public GnssPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { + super(descriptor); + PersistableBundle extras = descriptor.extras; mDeviceSignalLevelTimePosition = extras.getInt(EXTRA_DEVICE_TIME_SIGNAL_LEVEL_POSITION); mUidSignalLevelTimePosition = extras.getInt(EXTRA_UID_TIME_SIGNAL_LEVEL_POSITION); } diff --git a/services/core/java/com/android/server/power/stats/format/MobileRadioPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/MobileRadioPowerStatsLayout.java index f51a21ee70af..da6fc4115701 100644 --- a/services/core/java/com/android/server/power/stats/format/MobileRadioPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/MobileRadioPowerStatsLayout.java @@ -58,11 +58,50 @@ public class MobileRadioPowerStatsLayout extends PowerStatsLayout { private int mUidRxPacketsPosition; private int mUidTxPacketsPosition; - public MobileRadioPowerStatsLayout() { + public MobileRadioPowerStatsLayout(int energyConsumerCount) { + addDeviceMobileActivity(); + addDeviceSectionEnergyConsumers(energyConsumerCount); + addStateStats(); + addUidNetworkStats(); + addDeviceSectionUsageDuration(); + addDeviceSectionPowerEstimate(); + addUidSectionPowerEstimate(); } public MobileRadioPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { super(descriptor); + PersistableBundle extras = descriptor.extras; + mDeviceSleepTimePosition = extras.getInt(EXTRA_DEVICE_SLEEP_TIME_POSITION); + mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); + mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); + mDeviceCallTimePosition = extras.getInt(EXTRA_DEVICE_CALL_TIME_POSITION); + mDeviceCallPowerPosition = extras.getInt(EXTRA_DEVICE_CALL_POWER_POSITION); + mStateRxTimePosition = extras.getInt(EXTRA_STATE_RX_TIME_POSITION); + mStateTxTimesPosition = extras.getInt(EXTRA_STATE_TX_TIMES_POSITION); + mStateTxTimesCount = extras.getInt(EXTRA_STATE_TX_TIMES_COUNT); + mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); + mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); + mUidRxPacketsPosition = extras.getInt(EXTRA_UID_RX_PACKETS_POSITION); + mUidTxPacketsPosition = extras.getInt(EXTRA_UID_TX_PACKETS_POSITION); + } + + /** + * Copies the elements of the stats array layout into <code>extras</code> + */ + public void toExtras(PersistableBundle extras) { + super.toExtras(extras); + extras.putInt(EXTRA_DEVICE_SLEEP_TIME_POSITION, mDeviceSleepTimePosition); + extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); + extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); + extras.putInt(EXTRA_DEVICE_CALL_TIME_POSITION, mDeviceCallTimePosition); + extras.putInt(EXTRA_DEVICE_CALL_POWER_POSITION, mDeviceCallPowerPosition); + extras.putInt(EXTRA_STATE_RX_TIME_POSITION, mStateRxTimePosition); + extras.putInt(EXTRA_STATE_TX_TIMES_POSITION, mStateTxTimesPosition); + extras.putInt(EXTRA_STATE_TX_TIMES_COUNT, mStateTxTimesCount); + extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); + extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); + extras.putInt(EXTRA_UID_RX_PACKETS_POSITION, mUidRxPacketsPosition); + extras.putInt(EXTRA_UID_TX_PACKETS_POSITION, mUidTxPacketsPosition); } public static int makeStateKey(int rat, int freqRange) { @@ -94,20 +133,20 @@ public class MobileRadioPowerStatsLayout extends PowerStatsLayout { } } - public void addDeviceMobileActivity() { + private void addDeviceMobileActivity() { mDeviceSleepTimePosition = addDeviceSection(1, "sleep"); mDeviceIdleTimePosition = addDeviceSection(1, "idle"); mDeviceScanTimePosition = addDeviceSection(1, "scan"); mDeviceCallTimePosition = addDeviceSection(1, "call", FLAG_OPTIONAL); } - public void addStateStats() { + private void addStateStats() { mStateRxTimePosition = addStateSection(1, "rx"); mStateTxTimesCount = ModemActivityInfo.getNumTxPowerLevels(); mStateTxTimesPosition = addStateSection(mStateTxTimesCount, "tx"); } - public void addUidNetworkStats() { + private void addUidNetworkStats() { mUidRxPacketsPosition = addUidSection(1, "rx-pkts"); mUidRxBytesPosition = addUidSection(1, "rx-B"); mUidTxPacketsPosition = addUidSection(1, "tx-pkts"); @@ -115,7 +154,7 @@ public class MobileRadioPowerStatsLayout extends PowerStatsLayout { } @Override - public void addDeviceSectionPowerEstimate() { + protected void addDeviceSectionPowerEstimate() { super.addDeviceSectionPowerEstimate(); // Printed as part of the PhoneCallPowerStatsProcessor mDeviceCallPowerPosition = addDeviceSection(1, "call-power", FLAG_HIDDEN); @@ -209,44 +248,6 @@ public class MobileRadioPowerStatsLayout extends PowerStatsLayout { return stats[mUidTxPacketsPosition]; } - /** - * Copies the elements of the stats array layout into <code>extras</code> - */ - public void toExtras(PersistableBundle extras) { - super.toExtras(extras); - extras.putInt(EXTRA_DEVICE_SLEEP_TIME_POSITION, mDeviceSleepTimePosition); - extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); - extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); - extras.putInt(EXTRA_DEVICE_CALL_TIME_POSITION, mDeviceCallTimePosition); - extras.putInt(EXTRA_DEVICE_CALL_POWER_POSITION, mDeviceCallPowerPosition); - extras.putInt(EXTRA_STATE_RX_TIME_POSITION, mStateRxTimePosition); - extras.putInt(EXTRA_STATE_TX_TIMES_POSITION, mStateTxTimesPosition); - extras.putInt(EXTRA_STATE_TX_TIMES_COUNT, mStateTxTimesCount); - extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); - extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); - extras.putInt(EXTRA_UID_RX_PACKETS_POSITION, mUidRxPacketsPosition); - extras.putInt(EXTRA_UID_TX_PACKETS_POSITION, mUidTxPacketsPosition); - } - - /** - * Retrieves elements of the stats array layout from <code>extras</code> - */ - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); - mDeviceSleepTimePosition = extras.getInt(EXTRA_DEVICE_SLEEP_TIME_POSITION); - mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); - mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); - mDeviceCallTimePosition = extras.getInt(EXTRA_DEVICE_CALL_TIME_POSITION); - mDeviceCallPowerPosition = extras.getInt(EXTRA_DEVICE_CALL_POWER_POSITION); - mStateRxTimePosition = extras.getInt(EXTRA_STATE_RX_TIME_POSITION); - mStateTxTimesPosition = extras.getInt(EXTRA_STATE_TX_TIMES_POSITION); - mStateTxTimesCount = extras.getInt(EXTRA_STATE_TX_TIMES_COUNT); - mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); - mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); - mUidRxPacketsPosition = extras.getInt(EXTRA_UID_RX_PACKETS_POSITION); - mUidTxPacketsPosition = extras.getInt(EXTRA_UID_TX_PACKETS_POSITION); - } - public void addRxTxTimesForRat(SparseArray<long[]> stateStats, int networkType, int freqRange, long rxTime, int[] txTime) { if (txTime.length != mStateTxTimesCount) { diff --git a/services/core/java/com/android/server/power/stats/format/PhoneCallPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/PhoneCallPowerStatsLayout.java new file mode 100644 index 000000000000..5a341486072b --- /dev/null +++ b/services/core/java/com/android/server/power/stats/format/PhoneCallPowerStatsLayout.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.power.stats.format; + +public class PhoneCallPowerStatsLayout extends PowerStatsLayout { + public PhoneCallPowerStatsLayout() { + addDeviceSectionPowerEstimate(); + } +} diff --git a/services/core/java/com/android/server/power/stats/format/PowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/PowerStatsLayout.java index e3e7098ea745..d070919f4c18 100644 --- a/services/core/java/com/android/server/power/stats/format/PowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/PowerStatsLayout.java @@ -63,7 +63,32 @@ public class PowerStatsLayout { } public PowerStatsLayout(PowerStats.Descriptor descriptor) { - fromExtras(descriptor.extras); + PersistableBundle extras = descriptor.extras; + mDeviceDurationPosition = extras.getInt(EXTRA_DEVICE_DURATION_POSITION); + mDeviceEnergyConsumerPosition = extras.getInt(EXTRA_DEVICE_ENERGY_CONSUMERS_POSITION); + mDeviceEnergyConsumerCount = extras.getInt(EXTRA_DEVICE_ENERGY_CONSUMERS_COUNT); + mDevicePowerEstimatePosition = extras.getInt(EXTRA_DEVICE_POWER_POSITION); + mUidDurationPosition = extras.getInt(EXTRA_UID_DURATION_POSITION); + mUidEnergyConsumerPosition = extras.getInt(EXTRA_UID_ENERGY_CONSUMERS_POSITION); + mUidEnergyConsumerCount = extras.getInt(EXTRA_UID_ENERGY_CONSUMERS_COUNT); + mUidPowerEstimatePosition = extras.getInt(EXTRA_UID_POWER_POSITION); + } + + /** + * Copies the elements of the stats array layout into <code>extras</code> + */ + public void toExtras(PersistableBundle extras) { + extras.putInt(EXTRA_DEVICE_DURATION_POSITION, mDeviceDurationPosition); + extras.putInt(EXTRA_DEVICE_ENERGY_CONSUMERS_POSITION, mDeviceEnergyConsumerPosition); + extras.putInt(EXTRA_DEVICE_ENERGY_CONSUMERS_COUNT, mDeviceEnergyConsumerCount); + extras.putInt(EXTRA_DEVICE_POWER_POSITION, mDevicePowerEstimatePosition); + extras.putInt(EXTRA_UID_DURATION_POSITION, mUidDurationPosition); + extras.putInt(EXTRA_UID_ENERGY_CONSUMERS_POSITION, mUidEnergyConsumerPosition); + extras.putInt(EXTRA_UID_ENERGY_CONSUMERS_COUNT, mUidEnergyConsumerCount); + extras.putInt(EXTRA_UID_POWER_POSITION, mUidPowerEstimatePosition); + extras.putString(PowerStats.Descriptor.EXTRA_DEVICE_STATS_FORMAT, mDeviceFormat.toString()); + extras.putString(PowerStats.Descriptor.EXTRA_STATE_STATS_FORMAT, mStateFormat.toString()); + extras.putString(PowerStats.Descriptor.EXTRA_UID_STATS_FORMAT, mUidFormat.toString()); } public int getDeviceStatsArrayLength() { @@ -141,7 +166,7 @@ public class PowerStatsLayout { /** * Declare that the stats array has a section capturing usage duration */ - public void addDeviceSectionUsageDuration() { + protected void addDeviceSectionUsageDuration() { mDeviceDurationPosition = addDeviceSection(1, "usage", FLAG_OPTIONAL); } @@ -163,7 +188,7 @@ public class PowerStatsLayout { * Declares that the stats array has a section capturing EnergyConsumer data from * PowerStatsService. */ - public void addDeviceSectionEnergyConsumers(int energyConsumerCount) { + protected void addDeviceSectionEnergyConsumers(int energyConsumerCount) { mDeviceEnergyConsumerPosition = addDeviceSection(energyConsumerCount, "energy", FLAG_OPTIONAL); mDeviceEnergyConsumerCount = energyConsumerCount; @@ -192,7 +217,7 @@ public class PowerStatsLayout { /** * Declare that the stats array has a section capturing a power estimate */ - public void addDeviceSectionPowerEstimate() { + protected void addDeviceSectionPowerEstimate() { mDevicePowerEstimatePosition = addDeviceSection(1, "power", FLAG_FORMAT_AS_POWER | FLAG_OPTIONAL); } @@ -215,14 +240,14 @@ public class PowerStatsLayout { /** * Declare that the UID stats array has a section capturing usage duration */ - public void addUidSectionUsageDuration() { + protected void addUidSectionUsageDuration() { mUidDurationPosition = addUidSection(1, "time"); } /** * Declare that the UID stats array has a section capturing a power estimate */ - public void addUidSectionPowerEstimate() { + protected void addUidSectionPowerEstimate() { mUidPowerEstimatePosition = addUidSection(1, "power", FLAG_FORMAT_AS_POWER | FLAG_OPTIONAL); } @@ -251,7 +276,7 @@ public class PowerStatsLayout { * Declares that the UID stats array has a section capturing EnergyConsumer data from * PowerStatsService. */ - public void addUidSectionEnergyConsumers(int energyConsumerCount) { + protected void addUidSectionEnergyConsumers(int energyConsumerCount) { mUidEnergyConsumerPosition = addUidSection(energyConsumerCount, "energy", FLAG_OPTIONAL); mUidEnergyConsumerCount = energyConsumerCount; @@ -292,39 +317,6 @@ public class PowerStatsLayout { return stats[mUidPowerEstimatePosition] / MILLI_TO_NANO_MULTIPLIER; } - /** - * Copies the elements of the stats array layout into <code>extras</code> - */ - public void toExtras(PersistableBundle extras) { - extras.putInt(EXTRA_DEVICE_DURATION_POSITION, mDeviceDurationPosition); - extras.putInt(EXTRA_DEVICE_ENERGY_CONSUMERS_POSITION, - mDeviceEnergyConsumerPosition); - extras.putInt(EXTRA_DEVICE_ENERGY_CONSUMERS_COUNT, - mDeviceEnergyConsumerCount); - extras.putInt(EXTRA_DEVICE_POWER_POSITION, mDevicePowerEstimatePosition); - extras.putInt(EXTRA_UID_DURATION_POSITION, mUidDurationPosition); - extras.putInt(EXTRA_UID_ENERGY_CONSUMERS_POSITION, mUidEnergyConsumerPosition); - extras.putInt(EXTRA_UID_ENERGY_CONSUMERS_COUNT, mUidEnergyConsumerCount); - extras.putInt(EXTRA_UID_POWER_POSITION, mUidPowerEstimatePosition); - extras.putString(PowerStats.Descriptor.EXTRA_DEVICE_STATS_FORMAT, mDeviceFormat.toString()); - extras.putString(PowerStats.Descriptor.EXTRA_STATE_STATS_FORMAT, mStateFormat.toString()); - extras.putString(PowerStats.Descriptor.EXTRA_UID_STATS_FORMAT, mUidFormat.toString()); - } - - /** - * Retrieves elements of the stats array layout from <code>extras</code> - */ - public void fromExtras(PersistableBundle extras) { - mDeviceDurationPosition = extras.getInt(EXTRA_DEVICE_DURATION_POSITION); - mDeviceEnergyConsumerPosition = extras.getInt(EXTRA_DEVICE_ENERGY_CONSUMERS_POSITION); - mDeviceEnergyConsumerCount = extras.getInt(EXTRA_DEVICE_ENERGY_CONSUMERS_COUNT); - mDevicePowerEstimatePosition = extras.getInt(EXTRA_DEVICE_POWER_POSITION); - mUidDurationPosition = extras.getInt(EXTRA_UID_DURATION_POSITION); - mUidEnergyConsumerPosition = extras.getInt(EXTRA_UID_ENERGY_CONSUMERS_POSITION); - mUidEnergyConsumerCount = extras.getInt(EXTRA_UID_ENERGY_CONSUMERS_COUNT); - mUidPowerEstimatePosition = extras.getInt(EXTRA_UID_POWER_POSITION); - } - protected void putIntArray(PersistableBundle extras, String key, int[] array) { if (array == null) { return; diff --git a/services/core/java/com/android/server/power/stats/format/ScreenPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/ScreenPowerStatsLayout.java index a49c2a40dfc4..6f6a7ff5064a 100644 --- a/services/core/java/com/android/server/power/stats/format/ScreenPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/ScreenPowerStatsLayout.java @@ -41,14 +41,40 @@ public class ScreenPowerStatsLayout extends PowerStatsLayout { private int mDeviceScreenDozePowerPosition; private int mUidTopActivityTimePosition; - public ScreenPowerStatsLayout() { + public ScreenPowerStatsLayout(int energyConsumerCount, int displayCount) { + addDeviceScreenUsageDurationSection(displayCount); + addDeviceSectionEnergyConsumers(energyConsumerCount); + addDeviceSectionUsageDuration(); + addDeviceSectionPowerEstimate(); + addUidTopActivitiyDuration(); + addUidSectionPowerEstimate(); } public ScreenPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { super(descriptor); + PersistableBundle extras = descriptor.extras; + mDisplayCount = extras.getInt(EXTRA_DEVICE_SCREEN_COUNT, 1); + mDeviceScreenOnDurationPosition = extras.getInt(EXTRA_DEVICE_SCREEN_ON_DURATION_POSITION); + mDeviceBrightnessDurationPositions = extras.getIntArray( + EXTRA_DEVICE_BRIGHTNESS_DURATION_POSITIONS); + mDeviceScreenDozeDurationPosition = extras.getInt(EXTRA_DEVICE_DOZE_DURATION_POSITION); + mDeviceScreenDozePowerPosition = extras.getInt(EXTRA_DEVICE_DOZE_POWER_POSITION); + mUidTopActivityTimePosition = extras.getInt(EXTRA_UID_FOREGROUND_DURATION); } - public void addDeviceScreenUsageDurationSection(int displayCount) { + @Override + public void toExtras(PersistableBundle extras) { + super.toExtras(extras); + extras.putInt(EXTRA_DEVICE_SCREEN_COUNT, mDisplayCount); + extras.putInt(EXTRA_DEVICE_SCREEN_ON_DURATION_POSITION, mDeviceScreenOnDurationPosition); + extras.putIntArray(EXTRA_DEVICE_BRIGHTNESS_DURATION_POSITIONS, + mDeviceBrightnessDurationPositions); + extras.putInt(EXTRA_DEVICE_DOZE_DURATION_POSITION, mDeviceScreenDozeDurationPosition); + extras.putInt(EXTRA_DEVICE_DOZE_POWER_POSITION, mDeviceScreenDozePowerPosition); + extras.putInt(EXTRA_UID_FOREGROUND_DURATION, mUidTopActivityTimePosition); + } + + private void addDeviceScreenUsageDurationSection(int displayCount) { mDisplayCount = displayCount; mDeviceScreenOnDurationPosition = addDeviceSection(displayCount, "on"); mDeviceBrightnessDurationPositions = new int[BatteryStats.NUM_SCREEN_BRIGHTNESS_BINS]; @@ -60,7 +86,7 @@ public class ScreenPowerStatsLayout extends PowerStatsLayout { } @Override - public void addDeviceSectionPowerEstimate() { + protected void addDeviceSectionPowerEstimate() { super.addDeviceSectionPowerEstimate(); // Used by AmbientDisplayPowerStatsProcessor mDeviceScreenDozePowerPosition = addDeviceSection(1, "doze-power", FLAG_HIDDEN); @@ -127,7 +153,7 @@ public class ScreenPowerStatsLayout extends PowerStatsLayout { return stats[mDeviceScreenDozePowerPosition] / MILLI_TO_NANO_MULTIPLIER; } - public void addUidTopActivitiyDuration() { + private void addUidTopActivitiyDuration() { mUidTopActivityTimePosition = addUidSection(1, "top"); } @@ -144,28 +170,4 @@ public class ScreenPowerStatsLayout extends PowerStatsLayout { public long getUidTopActivityDuration(long[] stats) { return stats[mUidTopActivityTimePosition]; } - - @Override - public void toExtras(PersistableBundle extras) { - super.toExtras(extras); - extras.putInt(EXTRA_DEVICE_SCREEN_COUNT, mDisplayCount); - extras.putInt(EXTRA_DEVICE_SCREEN_ON_DURATION_POSITION, mDeviceScreenOnDurationPosition); - extras.putIntArray(EXTRA_DEVICE_BRIGHTNESS_DURATION_POSITIONS, - mDeviceBrightnessDurationPositions); - extras.putInt(EXTRA_DEVICE_DOZE_DURATION_POSITION, mDeviceScreenDozeDurationPosition); - extras.putInt(EXTRA_DEVICE_DOZE_POWER_POSITION, mDeviceScreenDozePowerPosition); - extras.putInt(EXTRA_UID_FOREGROUND_DURATION, mUidTopActivityTimePosition); - } - - @Override - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); - mDisplayCount = extras.getInt(EXTRA_DEVICE_SCREEN_COUNT, 1); - mDeviceScreenOnDurationPosition = extras.getInt(EXTRA_DEVICE_SCREEN_ON_DURATION_POSITION); - mDeviceBrightnessDurationPositions = extras.getIntArray( - EXTRA_DEVICE_BRIGHTNESS_DURATION_POSITIONS); - mDeviceScreenDozeDurationPosition = extras.getInt(EXTRA_DEVICE_DOZE_DURATION_POSITION); - mDeviceScreenDozePowerPosition = extras.getInt(EXTRA_DEVICE_DOZE_POWER_POSITION); - mUidTopActivityTimePosition = extras.getInt(EXTRA_UID_FOREGROUND_DURATION); - } } diff --git a/services/core/java/com/android/server/power/stats/format/SensorPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/SensorPowerStatsLayout.java index fb62bb3d80ad..e8df3ddfe5e8 100644 --- a/services/core/java/com/android/server/power/stats/format/SensorPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/SensorPowerStatsLayout.java @@ -20,6 +20,11 @@ import android.os.PersistableBundle; import android.util.Slog; import android.util.SparseIntArray; +import com.android.internal.os.PowerStats; + +import java.util.Arrays; +import java.util.Map; + public class SensorPowerStatsLayout extends PowerStatsLayout { private static final String TAG = "SensorPowerStatsLayout"; private static final String EXTRA_DEVICE_SENSOR_HANDLES = "dsh"; @@ -27,28 +32,29 @@ public class SensorPowerStatsLayout extends PowerStatsLayout { private final SparseIntArray mSensorPositions = new SparseIntArray(); - public void addUidSensorSection(int handle, String label) { - mSensorPositions.put(handle, addUidSection(1, label, FLAG_OPTIONAL)); + public SensorPowerStatsLayout(Map<Integer, String> idToLabelMap) { + Integer[] keys = new Integer[idToLabelMap.size()]; + idToLabelMap.keySet().toArray(keys); + Arrays.sort(keys); + for (int i = 0; i < keys.length; i++) { + addUidSensorSection(keys[i], idToLabelMap.get(keys[i])); + } + addUidSectionPowerEstimate(); + addDeviceSectionPowerEstimate(); } - /** - * Returns the position in the uid stats array of the duration element corresponding - * to the specified sensor identified by its handle. - */ - public int getUidSensorDurationPosition(int handle) { - return mSensorPositions.get(handle, UNSUPPORTED); - } + public SensorPowerStatsLayout(PowerStats.Descriptor descriptor) { + super(descriptor); - /** - * Adds the specified duration to the accumulated timer for the specified sensor. - */ - public void addUidSensorDuration(long[] stats, int handle, long durationMs) { - int position = mSensorPositions.get(handle, UNSUPPORTED); - if (position == UNSUPPORTED) { - Slog.e(TAG, "Unknown sensor: " + handle); - return; + PersistableBundle extras = descriptor.extras; + int[] handlers = extras.getIntArray(EXTRA_DEVICE_SENSOR_HANDLES); + int[] uidDurationPositions = extras.getIntArray(EXTRA_UID_SENSOR_POSITIONS); + + if (handlers != null && uidDurationPositions != null) { + for (int i = 0; i < handlers.length; i++) { + mSensorPositions.put(handlers[i], uidDurationPositions[i]); + } } - stats[position] += durationMs; } @Override @@ -67,15 +73,27 @@ public class SensorPowerStatsLayout extends PowerStatsLayout { extras.putIntArray(EXTRA_UID_SENSOR_POSITIONS, uidDurationPositions); } - @Override - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); + private void addUidSensorSection(int handle, String label) { + mSensorPositions.put(handle, addUidSection(1, label, FLAG_OPTIONAL)); + } - int[] handlers = extras.getIntArray(EXTRA_DEVICE_SENSOR_HANDLES); - int[] uidDurationPositions = extras.getIntArray(EXTRA_UID_SENSOR_POSITIONS); + /** + * Returns the position in the uid stats array of the duration element corresponding + * to the specified sensor identified by its handle. + */ + public int getUidSensorDurationPosition(int handle) { + return mSensorPositions.get(handle, UNSUPPORTED); + } - for (int i = 0; i < handlers.length; i++) { - mSensorPositions.put(handlers[i], uidDurationPositions[i]); + /** + * Adds the specified duration to the accumulated timer for the specified sensor. + */ + public void addUidSensorDuration(long[] stats, int handle, long durationMs) { + int position = mSensorPositions.get(handle, UNSUPPORTED); + if (position == UNSUPPORTED) { + Slog.e(TAG, "Unknown sensor: " + handle); + return; } + stats[position] += durationMs; } } diff --git a/services/core/java/com/android/server/power/stats/format/WifiPowerStatsLayout.java b/services/core/java/com/android/server/power/stats/format/WifiPowerStatsLayout.java index d8582e1b765c..ce7ef12878e2 100644 --- a/services/core/java/com/android/server/power/stats/format/WifiPowerStatsLayout.java +++ b/services/core/java/com/android/server/power/stats/format/WifiPowerStatsLayout.java @@ -22,7 +22,6 @@ import android.os.PersistableBundle; import com.android.internal.os.PowerStats; public class WifiPowerStatsLayout extends PowerStatsLayout { - private static final String TAG = "WifiPowerStatsLayout"; private static final int UNSPECIFIED = -1; private static final String EXTRA_POWER_REPORTING_SUPPORTED = "prs"; private static final String EXTRA_DEVICE_RX_TIME_POSITION = "dt-rx"; @@ -54,14 +53,56 @@ public class WifiPowerStatsLayout extends PowerStatsLayout { private int mUidScanTimePosition; private int mUidBatchScanTimePosition; - public WifiPowerStatsLayout() { + public WifiPowerStatsLayout(int energyConsumerCount, boolean powerReportingSupported) { + addDeviceWifiActivity(powerReportingSupported); + addDeviceSectionEnergyConsumers(energyConsumerCount); + addUidNetworkStats(); + addDeviceSectionUsageDuration(); + addDeviceSectionPowerEstimate(); + addUidSectionPowerEstimate(); } public WifiPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { super(descriptor); + PersistableBundle extras = descriptor.extras; + mPowerReportingSupported = extras.getBoolean(EXTRA_POWER_REPORTING_SUPPORTED); + mDeviceRxTimePosition = extras.getInt(EXTRA_DEVICE_RX_TIME_POSITION); + mDeviceTxTimePosition = extras.getInt(EXTRA_DEVICE_TX_TIME_POSITION); + mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); + mDeviceBasicScanTimePosition = extras.getInt(EXTRA_DEVICE_BASIC_SCAN_TIME_POSITION); + mDeviceBatchedScanTimePosition = extras.getInt(EXTRA_DEVICE_BATCHED_SCAN_TIME_POSITION); + mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); + mDeviceActiveTimePosition = extras.getInt(EXTRA_DEVICE_ACTIVE_TIME_POSITION); + mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); + mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); + mUidRxPacketsPosition = extras.getInt(EXTRA_UID_RX_PACKETS_POSITION); + mUidTxPacketsPosition = extras.getInt(EXTRA_UID_TX_PACKETS_POSITION); + mUidScanTimePosition = extras.getInt(EXTRA_UID_SCAN_TIME_POSITION); + mUidBatchScanTimePosition = extras.getInt(EXTRA_UID_BATCH_SCAN_TIME_POSITION); } - public void addDeviceWifiActivity(boolean powerReportingSupported) { + /** + * Copies the elements of the stats array layout into <code>extras</code> + */ + public void toExtras(PersistableBundle extras) { + super.toExtras(extras); + extras.putBoolean(EXTRA_POWER_REPORTING_SUPPORTED, mPowerReportingSupported); + extras.putInt(EXTRA_DEVICE_RX_TIME_POSITION, mDeviceRxTimePosition); + extras.putInt(EXTRA_DEVICE_TX_TIME_POSITION, mDeviceTxTimePosition); + extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); + extras.putInt(EXTRA_DEVICE_BASIC_SCAN_TIME_POSITION, mDeviceBasicScanTimePosition); + extras.putInt(EXTRA_DEVICE_BATCHED_SCAN_TIME_POSITION, mDeviceBatchedScanTimePosition); + extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); + extras.putInt(EXTRA_DEVICE_ACTIVE_TIME_POSITION, mDeviceActiveTimePosition); + extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); + extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); + extras.putInt(EXTRA_UID_RX_PACKETS_POSITION, mUidRxPacketsPosition); + extras.putInt(EXTRA_UID_TX_PACKETS_POSITION, mUidTxPacketsPosition); + extras.putInt(EXTRA_UID_SCAN_TIME_POSITION, mUidScanTimePosition); + extras.putInt(EXTRA_UID_BATCH_SCAN_TIME_POSITION, mUidBatchScanTimePosition); + } + + private void addDeviceWifiActivity(boolean powerReportingSupported) { mPowerReportingSupported = powerReportingSupported; if (mPowerReportingSupported) { mDeviceActiveTimePosition = UNSPECIFIED; @@ -80,7 +121,7 @@ public class WifiPowerStatsLayout extends PowerStatsLayout { mDeviceBatchedScanTimePosition = addDeviceSection(1, "batched-scan", FLAG_OPTIONAL); } - public void addUidNetworkStats() { + private void addUidNetworkStats() { mUidRxPacketsPosition = addUidSection(1, "rx-pkts"); mUidRxBytesPosition = addUidSection(1, "rx-B"); mUidTxPacketsPosition = addUidSection(1, "tx-pkts"); @@ -196,46 +237,4 @@ public class WifiPowerStatsLayout extends PowerStatsLayout { public long getUidBatchedScanTime(long[] stats) { return stats[mUidBatchScanTimePosition]; } - - /** - * Copies the elements of the stats array layout into <code>extras</code> - */ - public void toExtras(PersistableBundle extras) { - super.toExtras(extras); - extras.putBoolean(EXTRA_POWER_REPORTING_SUPPORTED, mPowerReportingSupported); - extras.putInt(EXTRA_DEVICE_RX_TIME_POSITION, mDeviceRxTimePosition); - extras.putInt(EXTRA_DEVICE_TX_TIME_POSITION, mDeviceTxTimePosition); - extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); - extras.putInt(EXTRA_DEVICE_BASIC_SCAN_TIME_POSITION, mDeviceBasicScanTimePosition); - extras.putInt(EXTRA_DEVICE_BATCHED_SCAN_TIME_POSITION, mDeviceBatchedScanTimePosition); - extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); - extras.putInt(EXTRA_DEVICE_ACTIVE_TIME_POSITION, mDeviceActiveTimePosition); - extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); - extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); - extras.putInt(EXTRA_UID_RX_PACKETS_POSITION, mUidRxPacketsPosition); - extras.putInt(EXTRA_UID_TX_PACKETS_POSITION, mUidTxPacketsPosition); - extras.putInt(EXTRA_UID_SCAN_TIME_POSITION, mUidScanTimePosition); - extras.putInt(EXTRA_UID_BATCH_SCAN_TIME_POSITION, mUidBatchScanTimePosition); - } - - /** - * Retrieves elements of the stats array layout from <code>extras</code> - */ - public void fromExtras(PersistableBundle extras) { - super.fromExtras(extras); - mPowerReportingSupported = extras.getBoolean(EXTRA_POWER_REPORTING_SUPPORTED); - mDeviceRxTimePosition = extras.getInt(EXTRA_DEVICE_RX_TIME_POSITION); - mDeviceTxTimePosition = extras.getInt(EXTRA_DEVICE_TX_TIME_POSITION); - mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); - mDeviceBasicScanTimePosition = extras.getInt(EXTRA_DEVICE_BASIC_SCAN_TIME_POSITION); - mDeviceBatchedScanTimePosition = extras.getInt(EXTRA_DEVICE_BATCHED_SCAN_TIME_POSITION); - mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); - mDeviceActiveTimePosition = extras.getInt(EXTRA_DEVICE_ACTIVE_TIME_POSITION); - mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); - mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); - mUidRxPacketsPosition = extras.getInt(EXTRA_UID_RX_PACKETS_POSITION); - mUidTxPacketsPosition = extras.getInt(EXTRA_UID_TX_PACKETS_POSITION); - mUidScanTimePosition = extras.getInt(EXTRA_UID_SCAN_TIME_POSITION); - mUidBatchScanTimePosition = extras.getInt(EXTRA_UID_BATCH_SCAN_TIME_POSITION); - } } diff --git a/services/core/java/com/android/server/power/stats/processor/AmbientDisplayPowerStatsProcessor.java b/services/core/java/com/android/server/power/stats/processor/AmbientDisplayPowerStatsProcessor.java index d5a570ad7b21..32dfdf915bca 100644 --- a/services/core/java/com/android/server/power/stats/processor/AmbientDisplayPowerStatsProcessor.java +++ b/services/core/java/com/android/server/power/stats/processor/AmbientDisplayPowerStatsProcessor.java @@ -19,11 +19,11 @@ import android.os.BatteryConsumer; import android.os.PersistableBundle; import com.android.internal.os.PowerStats; -import com.android.server.power.stats.format.PowerStatsLayout; +import com.android.server.power.stats.format.AmbientDisplayPowerStatsLayout; import com.android.server.power.stats.format.ScreenPowerStatsLayout; class AmbientDisplayPowerStatsProcessor extends PowerStatsProcessor { - private final PowerStatsLayout mStatsLayout; + private final AmbientDisplayPowerStatsLayout mStatsLayout; private final PowerStats.Descriptor mDescriptor; private final long[] mTmpDeviceStats; private PowerStats.Descriptor mScreenPowerStatsDescriptor; @@ -31,8 +31,7 @@ class AmbientDisplayPowerStatsProcessor extends PowerStatsProcessor { private long[] mTmpScreenStats; AmbientDisplayPowerStatsProcessor() { - mStatsLayout = new PowerStatsLayout(); - mStatsLayout.addDeviceSectionPowerEstimate(); + mStatsLayout = new AmbientDisplayPowerStatsLayout(); PersistableBundle extras = new PersistableBundle(); mStatsLayout.toExtras(extras); mDescriptor = new PowerStats.Descriptor(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY, diff --git a/services/core/java/com/android/server/power/stats/processor/CpuPowerStatsProcessor.java b/services/core/java/com/android/server/power/stats/processor/CpuPowerStatsProcessor.java index fa1898f4b22e..5f7a3dad99e8 100644 --- a/services/core/java/com/android/server/power/stats/processor/CpuPowerStatsProcessor.java +++ b/services/core/java/com/android/server/power/stats/processor/CpuPowerStatsProcessor.java @@ -105,8 +105,7 @@ class CpuPowerStatsProcessor extends PowerStatsProcessor { } mLastUsedDescriptor = descriptor; - mStatsLayout = new CpuPowerStatsLayout(); - mStatsLayout.fromExtras(descriptor.extras); + mStatsLayout = new CpuPowerStatsLayout(descriptor); mTmpDeviceStatsArray = new long[descriptor.statsArrayLength]; mTmpUidStatsArray = new long[descriptor.uidStatsArrayLength]; diff --git a/services/core/java/com/android/server/power/stats/processor/PhoneCallPowerStatsProcessor.java b/services/core/java/com/android/server/power/stats/processor/PhoneCallPowerStatsProcessor.java index ba87e1cb27d8..3957ae0862dc 100644 --- a/services/core/java/com/android/server/power/stats/processor/PhoneCallPowerStatsProcessor.java +++ b/services/core/java/com/android/server/power/stats/processor/PhoneCallPowerStatsProcessor.java @@ -20,10 +20,10 @@ import android.os.PersistableBundle; import com.android.internal.os.PowerStats; import com.android.server.power.stats.format.MobileRadioPowerStatsLayout; -import com.android.server.power.stats.format.PowerStatsLayout; +import com.android.server.power.stats.format.PhoneCallPowerStatsLayout; class PhoneCallPowerStatsProcessor extends PowerStatsProcessor { - private final PowerStatsLayout mStatsLayout; + private final PhoneCallPowerStatsLayout mStatsLayout; private final PowerStats.Descriptor mDescriptor; private final long[] mTmpDeviceStats; private PowerStats.Descriptor mMobileRadioStatsDescriptor; @@ -31,8 +31,7 @@ class PhoneCallPowerStatsProcessor extends PowerStatsProcessor { private long[] mTmpMobileRadioDeviceStats; PhoneCallPowerStatsProcessor() { - mStatsLayout = new PowerStatsLayout(); - mStatsLayout.addDeviceSectionPowerEstimate(); + mStatsLayout = new PhoneCallPowerStatsLayout(); PersistableBundle extras = new PersistableBundle(); mStatsLayout.toExtras(extras); mDescriptor = new PowerStats.Descriptor(BatteryConsumer.POWER_COMPONENT_PHONE, diff --git a/services/core/java/com/android/server/power/stats/processor/PowerStatsExporter.java b/services/core/java/com/android/server/power/stats/processor/PowerStatsExporter.java index cd7b858ba7f8..fab87d6684e1 100644 --- a/services/core/java/com/android/server/power/stats/processor/PowerStatsExporter.java +++ b/services/core/java/com/android/server/power/stats/processor/PowerStatsExporter.java @@ -143,9 +143,7 @@ class PowerStatsExporter { return; } - PowerStatsLayout layout = new PowerStatsLayout(); - layout.fromExtras(descriptor.extras); - + PowerStatsLayout layout = new PowerStatsLayout(descriptor); long[] deviceStats = new long[descriptor.statsArrayLength]; for (int screenState = 0; screenState < BatteryConsumer.SCREEN_STATE_COUNT; screenState++) { if (batteryUsageStatsBuilder.isScreenStateDataNeeded()) { diff --git a/services/core/java/com/android/server/power/stats/processor/SensorPowerStatsProcessor.java b/services/core/java/com/android/server/power/stats/processor/SensorPowerStatsProcessor.java index 9716624b40ea..67013ea65aa3 100644 --- a/services/core/java/com/android/server/power/stats/processor/SensorPowerStatsProcessor.java +++ b/services/core/java/com/android/server/power/stats/processor/SensorPowerStatsProcessor.java @@ -30,9 +30,9 @@ import com.android.server.power.stats.format.SensorPowerStatsLayout; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.function.Supplier; +import java.util.stream.Collectors; class SensorPowerStatsProcessor extends PowerStatsProcessor { private static final String TAG = "SensorPowerStatsProcessor"; @@ -80,16 +80,9 @@ class SensorPowerStatsProcessor extends PowerStatsProcessor { return false; } - mStatsLayout = new SensorPowerStatsLayout(); - List<Sensor> sensorList = new ArrayList<>(mSensorManager.getSensorList(Sensor.TYPE_ALL)); - sensorList.sort(Comparator.comparingInt(Sensor::getId)); - for (int i = 0; i < sensorList.size(); i++) { - Sensor sensor = sensorList.get(i); - String label = makeLabel(sensor, sensorList); - mStatsLayout.addUidSensorSection(sensor.getHandle(), label); - } - mStatsLayout.addUidSectionPowerEstimate(); - mStatsLayout.addDeviceSectionPowerEstimate(); + List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); + mStatsLayout = new SensorPowerStatsLayout(sensorList.stream().collect( + Collectors.toMap(Sensor::getHandle, sensor -> makeLabel(sensor, sensorList)))); PersistableBundle extras = new PersistableBundle(); mStatsLayout.toExtras(extras); diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/CpuPowerStatsCollectorTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/CpuPowerStatsCollectorTest.java index 3197e1eb24a0..d995227cfec3 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/CpuPowerStatsCollectorTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/CpuPowerStatsCollectorTest.java @@ -229,8 +229,7 @@ public class CpuPowerStatsCollectorTest { assertThat(descriptor.name).isEqualTo("cpu"); assertThat(descriptor.statsArrayLength).isEqualTo(13); assertThat(descriptor.uidStatsArrayLength).isEqualTo(5); - CpuPowerStatsLayout layout = new CpuPowerStatsLayout(); - layout.fromExtras(descriptor.extras); + CpuPowerStatsLayout layout = new CpuPowerStatsLayout(descriptor); long[] deviceStats = new long[descriptor.statsArrayLength]; layout.setTimeByScalingStep(deviceStats, 2, 42); @@ -267,8 +266,7 @@ public class CpuPowerStatsCollectorTest { mockEnergyConsumers(); CpuPowerStatsCollector collector = createCollector(8, 0); - CpuPowerStatsLayout layout = new CpuPowerStatsLayout(); - layout.fromExtras(collector.getPowerStatsDescriptor().extras); + CpuPowerStatsLayout layout = new CpuPowerStatsLayout(collector.getPowerStatsDescriptor()); mockKernelCpuStats(new long[]{1111, 2222, 3333}, new SparseArray<>() {{ @@ -338,8 +336,7 @@ public class CpuPowerStatsCollectorTest { mockEnergyConsumers(); CpuPowerStatsCollector collector = createCollector(8, 0); - CpuPowerStatsLayout layout = new CpuPowerStatsLayout(); - layout.fromExtras(collector.getPowerStatsDescriptor().extras); + CpuPowerStatsLayout layout = new CpuPowerStatsLayout(collector.getPowerStatsDescriptor()); mockKernelCpuStats(new long[]{1111, 2222, 3333}, new SparseArray<>() {{ @@ -470,8 +467,7 @@ public class CpuPowerStatsCollectorTest { } private static int[] getScalingStepToPowerBracketMap(CpuPowerStatsCollector collector) { - CpuPowerStatsLayout layout = new CpuPowerStatsLayout(); - layout.fromExtras(collector.getPowerStatsDescriptor().extras); + CpuPowerStatsLayout layout = new CpuPowerStatsLayout(collector.getPowerStatsDescriptor()); return layout.getScalingStepToPowerBracketMap(); } diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/ScreenPowerStatsCollectorTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/ScreenPowerStatsCollectorTest.java index d56e3e27c921..8fd3f4dd00a1 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/ScreenPowerStatsCollectorTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/ScreenPowerStatsCollectorTest.java @@ -172,8 +172,7 @@ public class ScreenPowerStatsCollectorTest { PowerStats powerStats = collector.collectStats(); - ScreenPowerStatsLayout layout = new ScreenPowerStatsLayout(); - layout.fromExtras(powerStats.descriptor.extras); + ScreenPowerStatsLayout layout = new ScreenPowerStatsLayout(powerStats.descriptor); // (45000 - 10000) / 3500 assertThat(layout.getConsumedEnergy(powerStats.stats, 0)) diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CameraPowerStatsTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CameraPowerStatsTest.java index 7348e831664a..4c60e0af4ba6 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CameraPowerStatsTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CameraPowerStatsTest.java @@ -167,8 +167,7 @@ public class CameraPowerStatsTest { stats.finish(11_000); PowerStats.Descriptor descriptor = stats.getPowerStatsDescriptor(); - BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(); - statsLayout.fromExtras(descriptor.extras); + BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(descriptor); // Total estimated power = 3,600,000 uC = 1.0 mAh // of which 3,000,000 is distributed: diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CpuPowerStatsProcessorTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CpuPowerStatsProcessorTest.java index 84b68d8958ae..693861539922 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CpuPowerStatsProcessorTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/CpuPowerStatsProcessorTest.java @@ -213,17 +213,8 @@ public class CpuPowerStatsProcessorTest { AggregatedPowerStatsConfig.PowerComponent config, boolean useEnergyConsumers) { super(new AggregatedPowerStats(new AggregatedPowerStatsConfig()), config); - mStatsLayout = new CpuPowerStatsLayout(); - mStatsLayout.addDeviceSectionCpuTimeByScalingStep(3); - mStatsLayout.addDeviceSectionCpuTimeByCluster(2); - mStatsLayout.addDeviceSectionUsageDuration(); - if (useEnergyConsumers) { - mStatsLayout.addDeviceSectionEnergyConsumers(2); - } - mStatsLayout.addDeviceSectionPowerEstimate(); - mStatsLayout.addUidSectionCpuTimeByPowerBracket(new int[]{0, 1, 2}); - mStatsLayout.addUidSectionPowerEstimate(); - + mStatsLayout = new CpuPowerStatsLayout(useEnergyConsumers ? 2 : 0, 2, + new int[]{0, 1, 2}); PersistableBundle extras = new PersistableBundle(); mStatsLayout.toExtras(extras); mDescriptor = new PowerStats.Descriptor(BatteryConsumer.POWER_COMPONENT_CPU, diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/GnssPowerStatsTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/GnssPowerStatsTest.java index 7ea34f50950f..2440287739bc 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/GnssPowerStatsTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/GnssPowerStatsTest.java @@ -171,8 +171,7 @@ public class GnssPowerStatsTest { stats.finish(START_TIME + 11_000); PowerStats.Descriptor descriptor = stats.getPowerStatsDescriptor(); - BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(); - statsLayout.fromExtras(descriptor.extras); + BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(descriptor); // scr-on, GNSS-good: 2500 * 100 = 250000 mA-ms = 0.06944 mAh // scr-off GNSS=good: 4500 * 100 = 0.12500 mAh @@ -251,8 +250,7 @@ public class GnssPowerStatsTest { stats.finish(START_TIME + 11_000); PowerStats.Descriptor descriptor = stats.getPowerStatsDescriptor(); - BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(); - statsLayout.fromExtras(descriptor.extras); + BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(descriptor); // scr-on, GNSS-good: 2500 * 100 = 250000 mA-ms = 0.06944 mAh // scr-off GNSS=good: 4500 * 100 = 0.12500 mAh @@ -345,8 +343,7 @@ public class GnssPowerStatsTest { stats.finish(START_TIME + 11_000); PowerStats.Descriptor descriptor = stats.getPowerStatsDescriptor(); - BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(); - statsLayout.fromExtras(descriptor.extras); + BinaryStatePowerStatsLayout statsLayout = new BinaryStatePowerStatsLayout(descriptor); // Total estimated power = 3,600,000 uC = 1.0 mAh // of which 3,000,000 is distributed: diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/PowerStatsExporterTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/PowerStatsExporterTest.java index e18421aeeffc..024743d9e098 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/PowerStatsExporterTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/PowerStatsExporterTest.java @@ -123,13 +123,7 @@ public class PowerStatsExporterTest { mMonotonicClock, null, null); mPowerStatsAggregator = new PowerStatsAggregator(config); - mCpuStatsArrayLayout = new CpuPowerStatsLayout(); - mCpuStatsArrayLayout.addDeviceSectionCpuTimeByScalingStep(1); - mCpuStatsArrayLayout.addDeviceSectionCpuTimeByCluster(1); - mCpuStatsArrayLayout.addDeviceSectionUsageDuration(); - mCpuStatsArrayLayout.addDeviceSectionPowerEstimate(); - mCpuStatsArrayLayout.addUidSectionCpuTimeByPowerBracket(new int[]{0}); - mCpuStatsArrayLayout.addUidSectionPowerEstimate(); + mCpuStatsArrayLayout = new CpuPowerStatsLayout(0, 1, new int[]{0}); PersistableBundle extras = new PersistableBundle(); mCpuStatsArrayLayout.toExtras(extras); diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/SensorPowerStatsProcessorTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/SensorPowerStatsProcessorTest.java index e2520a4b05d7..d97260455bdd 100644 --- a/services/tests/powerstatstests/src/com/android/server/power/stats/processor/SensorPowerStatsProcessorTest.java +++ b/services/tests/powerstatstests/src/com/android/server/power/stats/processor/SensorPowerStatsProcessorTest.java @@ -111,8 +111,7 @@ public class SensorPowerStatsProcessorTest { stats.finish(10000); PowerStats.Descriptor descriptor = stats.getPowerStatsDescriptor(); - SensorPowerStatsLayout statsLayout = new SensorPowerStatsLayout(); - statsLayout.fromExtras(descriptor.extras); + SensorPowerStatsLayout statsLayout = new SensorPowerStatsLayout(descriptor); String dump = stats.toString(); assertThat(dump).contains(" step_counter: "); |