Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a117e63 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "wifi-power-stats" into main

* changes:
  Enable PowerStatsExporter for WiFi
  Introduce PowerStatsProcessor for WiFi
  Introduce PowerStatsCollector for WiFi
parents 98b50021 72c49315
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -37,8 +37,10 @@ import java.lang.annotation.RetentionPolicy;
 * real-time.
 * @hide
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
@SystemApi
public final class WifiActivityEnergyInfo implements Parcelable {
    private static final long DEFERRED_ENERGY_ESTIMATE = -1;
    @ElapsedRealtimeLong
    private final long mTimeSinceBootMillis;
    @StackState
@@ -52,7 +54,7 @@ public final class WifiActivityEnergyInfo implements Parcelable {
    @IntRange(from = 0)
    private final long mControllerIdleDurationMillis;
    @IntRange(from = 0)
    private final long mControllerEnergyUsedMicroJoules;
    private long mControllerEnergyUsedMicroJoules;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
@@ -99,9 +101,10 @@ public final class WifiActivityEnergyInfo implements Parcelable {
                rxDurationMillis,
                scanDurationMillis,
                idleDurationMillis,
                calculateEnergyMicroJoules(txDurationMillis, rxDurationMillis, idleDurationMillis));
                DEFERRED_ENERGY_ESTIMATE);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    private static long calculateEnergyMicroJoules(
            long txDurationMillis, long rxDurationMillis, long idleDurationMillis) {
        final Context context = ActivityThread.currentActivityThread().getSystemContext();
@@ -125,6 +128,11 @@ public final class WifiActivityEnergyInfo implements Parcelable {
                * voltage);
    }

    private static long calculateEnergyMicroJoules$ravenwood(long txDurationMillis,
            long rxDurationMillis, long idleDurationMillis) {
        return 0;
    }

    /** @hide */
    public WifiActivityEnergyInfo(
            @ElapsedRealtimeLong long timeSinceBootMillis,
@@ -152,7 +160,7 @@ public final class WifiActivityEnergyInfo implements Parcelable {
                + " mControllerRxDurationMillis=" + mControllerRxDurationMillis
                + " mControllerScanDurationMillis=" + mControllerScanDurationMillis
                + " mControllerIdleDurationMillis=" + mControllerIdleDurationMillis
                + " mControllerEnergyUsedMicroJoules=" + mControllerEnergyUsedMicroJoules
                + " mControllerEnergyUsedMicroJoules=" + getControllerEnergyUsedMicroJoules()
                + " }";
    }

@@ -231,6 +239,11 @@ public final class WifiActivityEnergyInfo implements Parcelable {
    /** Get the energy consumed by Wifi, in microjoules. */
    @IntRange(from = 0)
    public long getControllerEnergyUsedMicroJoules() {
        if (mControllerEnergyUsedMicroJoules == DEFERRED_ENERGY_ESTIMATE) {
            mControllerEnergyUsedMicroJoules = calculateEnergyMicroJoules(
                    mControllerTxDurationMillis, mControllerRxDurationMillis,
                    mControllerIdleDurationMillis);
        }
        return mControllerEnergyUsedMicroJoules;
    }

+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@
    <!-- Mobile Radio power stats collection throttle period in milliseconds. -->
    <integer name="config_defaultPowerStatsThrottlePeriodMobileRadio">3600000</integer>

    <!-- Mobile Radio power stats collection throttle period in milliseconds. -->
    <integer name="config_defaultPowerStatsThrottlePeriodWifi">3600000</integer>

    <!-- PowerStats aggregation period in milliseconds. This is the interval at which the power
    stats aggregation procedure is performed and the results stored in PowerStatsStore. -->
    <integer name="config_powerStatsAggregationPeriod">14400000</integer>
+1 −0
Original line number Diff line number Diff line
@@ -5218,6 +5218,7 @@
  <java-symbol type="bool" name="config_batteryStatsResetOnUnplugAfterSignificantCharge" />
  <java-symbol type="integer" name="config_defaultPowerStatsThrottlePeriodCpu" />
  <java-symbol type="integer" name="config_defaultPowerStatsThrottlePeriodMobileRadio" />
  <java-symbol type="integer" name="config_defaultPowerStatsThrottlePeriodWifi" />
  <java-symbol type="integer" name="config_powerStatsAggregationPeriod" />
  <java-symbol type="integer" name="config_aggregatedPowerStatsSpanDuration" />

+2 −0
Original line number Diff line number Diff line
@@ -266,6 +266,8 @@ android.telephony.CellSignalStrength
android.telephony.ModemActivityInfo
android.telephony.ServiceState

android.os.connectivity.WifiActivityEnergyInfo

com.android.server.LocalServices

com.android.internal.util.BitUtils
+29 −2
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ import com.android.server.power.stats.PowerStatsScheduler;
import com.android.server.power.stats.PowerStatsStore;
import com.android.server.power.stats.PowerStatsUidResolver;
import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes;
import com.android.server.power.stats.WifiPowerStatsProcessor;
import com.android.server.power.stats.wakeups.CpuWakeupStats;

import java.io.File;
@@ -412,6 +413,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                com.android.internal.R.integer.config_defaultPowerStatsThrottlePeriodCpu);
        final long powerStatsThrottlePeriodMobileRadio = context.getResources().getInteger(
                com.android.internal.R.integer.config_defaultPowerStatsThrottlePeriodMobileRadio);
        final long powerStatsThrottlePeriodWifi = context.getResources().getInteger(
                com.android.internal.R.integer.config_defaultPowerStatsThrottlePeriodWifi);
        mBatteryStatsConfig =
                new BatteryStatsImpl.BatteryStatsConfig.Builder()
                        .setResetOnUnplugHighBatteryLevel(resetOnUnplugHighBatteryLevel)
@@ -422,6 +425,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        .setPowerStatsThrottlePeriodMillis(
                                BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                                powerStatsThrottlePeriodMobileRadio)
                        .setPowerStatsThrottlePeriodMillis(
                                BatteryConsumer.POWER_COMPONENT_WIFI,
                                powerStatsThrottlePeriodWifi)
                        .build();
        mPowerStatsUidResolver = new PowerStatsUidResolver();
        mStats = new BatteryStatsImpl(mBatteryStatsConfig, Clock.SYSTEM_CLOCK, mMonotonicClock,
@@ -480,6 +486,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        AggregatedPowerStatsConfig.STATE_PROCESS_STATE)
                .setProcessor(
                        new CpuPowerStatsProcessor(mPowerProfile, mCpuScalingPolicies));

        config.trackPowerComponent(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO)
                .trackDeviceStates(
                        AggregatedPowerStatsConfig.STATE_POWER,
@@ -490,9 +497,21 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        AggregatedPowerStatsConfig.STATE_PROCESS_STATE)
                .setProcessor(
                        new MobileRadioPowerStatsProcessor(mPowerProfile));

        config.trackPowerComponent(BatteryConsumer.POWER_COMPONENT_PHONE,
                        BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO)
                .setProcessor(new PhoneCallPowerStatsProcessor());

        config.trackPowerComponent(BatteryConsumer.POWER_COMPONENT_WIFI)
                .trackDeviceStates(
                        AggregatedPowerStatsConfig.STATE_POWER,
                        AggregatedPowerStatsConfig.STATE_SCREEN)
                .trackUidStates(
                        AggregatedPowerStatsConfig.STATE_POWER,
                        AggregatedPowerStatsConfig.STATE_SCREEN,
                        AggregatedPowerStatsConfig.STATE_PROCESS_STATE)
                .setProcessor(
                        new WifiPowerStatsProcessor(mPowerProfile));
        return config;
    }

@@ -518,14 +537,22 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    public void systemServicesReady() {
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU,
                Flags.streamlinedBatteryStats());
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                Flags.streamlinedConnectivityBatteryStats());
        mBatteryUsageStatsProvider.setPowerStatsExporterEnabled(
                BatteryConsumer.POWER_COMPONENT_CPU,
                Flags.streamlinedBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                Flags.streamlinedConnectivityBatteryStats());
        mBatteryUsageStatsProvider.setPowerStatsExporterEnabled(
                BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                Flags.streamlinedConnectivityBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WIFI,
                Flags.streamlinedConnectivityBatteryStats());
        mBatteryUsageStatsProvider.setPowerStatsExporterEnabled(
                BatteryConsumer.POWER_COMPONENT_WIFI,
                Flags.streamlinedConnectivityBatteryStats());

        mWorker.systemServicesReady();
        mStats.systemServicesReady(mContext);
        mCpuWakeupStats.systemServicesReady();
Loading