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

Commit b95b1a2e authored by Michael Wachenschwanz's avatar Michael Wachenschwanz Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cpuEnergyAttribution" into sc-dev

* changes:
  Accumulate charge instead of energy in BatteryStatsImpl
  Accumulate and attribute measured Cpu energy in BatteryStats
parents 7af559a6 68b8157e
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -986,26 +986,26 @@ public abstract class BatteryStats implements Parcelable {
        public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which);

        /**
         * Returns the measured energy in microjoules that the display consumed while the screen
         * was on and uid active.
         * Will return {@link #ENERGY_DATA_UNAVAILABLE} if data is unavailable
         * Returns the battery consumption (in microcoulombs) of the screen while on and uid active,
         * derived from on device power measurement data.
         * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
         *
         * {@hide}
         */
        public abstract long getScreenOnEnergy();
        public abstract long getScreenOnMeasuredBatteryConsumptionUC();

        /**
         * Returns the energies used by this uid for each
         * Returns the battery consumption (in microcoulombs) used by this uid for each
         * {@link android.hardware.power.stats.EnergyConsumer.ordinal} of (custom) energy consumer
         * type {@link android.hardware.power.stats.EnergyConsumerType#OTHER}).
         *
         * @return energies (in microjoules) used since boot for each (custom) energy consumer of
         *         type OTHER, indexed by their ordinal. Returns null if no energy reporting is
         *         supported.
         * @return charge (in microcoulombs) consumed since last reset for each (custom) energy
         *         consumer of type OTHER, indexed by their ordinal. Returns null if no energy
         *         reporting is supported.
         *
         * {@hide}
         */
        public abstract @Nullable long[] getCustomMeasuredEnergiesMicroJoules();
        public abstract @Nullable long[] getCustomConsumerMeasuredBatteryConsumptionUC();

        public static abstract class Sensor {

@@ -2496,40 +2496,41 @@ public abstract class BatteryStats implements Parcelable {
    };

    /**
     * Returned value if energy data is unavailable
     * Returned value if power data is unavailable
     *
     * {@hide}
     */
    public static final long ENERGY_DATA_UNAVAILABLE = -1;
    public static final long POWER_DATA_UNAVAILABLE = -1;

    /**
     * Returns the energy in microjoules that the screen consumed while on.
     * Will return {@link #ENERGY_DATA_UNAVAILABLE} if data is unavailable
     * Returns the battery consumption (in microcoulombs) of the screen while on, derived from on
     * device power measurement data.
     * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
     *
     * {@hide}
     */
    public abstract long getScreenOnEnergy();
    public abstract long getScreenOnMeasuredBatteryConsumptionUC();

    /**
     * Returns the energy in microjoules that the screen consumed while in doze
     * Will return {@link #ENERGY_DATA_UNAVAILABLE} if data is unavailable
     * Returns the battery consumption (in microcoulombs) of the screen in doze, derived from on
     * device power measurement data.
     * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
     *
     * {@hide}
     */
    public abstract long getScreenDozeEnergy();
    public abstract long getScreenDozeMeasuredBatteryConsumptionUC();

    /**
     * Returns the energies used for each
     * Returns the battery consumption (in microcoulombs) that each
     * {@link android.hardware.power.stats.EnergyConsumer.ordinal} of (custom) energy consumer
     * type {@link android.hardware.power.stats.EnergyConsumerType#OTHER}).
     * type {@link android.hardware.power.stats.EnergyConsumerType#OTHER}) consumed.
     *
     * @return energies (in microjoules) used since boot for each (custom) energy consumer of
     *         type OTHER, indexed by their ordinal. Returns null if no energy reporting is
     *         supported.
     * @return charge (in microcoulombs) used by each (custom) energy consumer of type OTHER,
     * indexed by their ordinal. Returns null if no energy reporting is supported.
     *
     * {@hide}
     */
    public abstract @Nullable long[] getCustomMeasuredEnergiesMicroJoules();
    public abstract @Nullable long[] getCustomConsumerMeasuredBatteryConsumptionUC();

    public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
        new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
+4 −3
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ public class AmbientDisplayPowerCalculator extends PowerCalculator {
            long rawRealtimeUs, long rawUptimeUs, BatteryUsageStatsQuery query) {
        final long durationMs = calculateDuration(batteryStats, rawRealtimeUs,
                BatteryStats.STATS_SINCE_CHARGED);
        final double powerMah = getMeasuredOrEstimatedPower(batteryStats.getScreenDozeEnergy(),
        final double powerMah = getMeasuredOrEstimatedPower(
                batteryStats.getScreenDozeMeasuredBatteryConsumptionUC(),
                mPowerEstimator, durationMs, query.shouldForceUsePowerProfileModel());
        builder.getOrCreateSystemBatteryConsumerBuilder(
                        SystemBatteryConsumer.DRAIN_TYPE_AMBIENT_DISPLAY)
@@ -64,7 +65,8 @@ public class AmbientDisplayPowerCalculator extends PowerCalculator {
    public void calculate(List<BatterySipper> sippers, BatteryStats batteryStats,
            long rawRealtimeUs, long rawUptimeUs, int statsType, SparseArray<UserHandle> asUsers) {
        final long durationMs = calculateDuration(batteryStats, rawRealtimeUs, statsType);
        final double powerMah = getMeasuredOrEstimatedPower(batteryStats.getScreenDozeEnergy(),
        final double powerMah = getMeasuredOrEstimatedPower(
                batteryStats.getScreenDozeMeasuredBatteryConsumptionUC(),
                mPowerEstimator, durationMs, false);
        if (powerMah > 0) {
            BatterySipper bs = new BatterySipper(BatterySipper.DrainType.AMBIENT_DISPLAY, null, 0);
@@ -78,5 +80,4 @@ public class AmbientDisplayPowerCalculator extends PowerCalculator {
    private long calculateDuration(BatteryStats batteryStats, long rawRealtimeUs, int statsType) {
        return batteryStats.getScreenDozeTime(rawRealtimeUs, statsType) / 1000;
    }

}
Loading