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

Commit 84fc40ad authored by Adam Bookatz's avatar Adam Bookatz Committed by Android (Google) Code Review
Browse files

Merge "MeasuredEnergyStats - remove unused accumulate parameter" into sc-dev

parents d27ed1bd 26b0a086
Loading
Loading
Loading
Loading
+8 −10
Original line number Original line Diff line number Diff line
@@ -7965,16 +7965,14 @@ public class BatteryStatsImpl extends BatteryStats {
        /** Adds the given energy to the given standard energy bucket for this uid. */
        /** Adds the given energy to the given standard energy bucket for this uid. */
        private void addEnergyToStandardBucketLocked(long energyDeltaUJ,
        private void addEnergyToStandardBucketLocked(long energyDeltaUJ,
                @StandardEnergyBucket int energyBucket, boolean accumulate) {
                @StandardEnergyBucket int energyBucket) {
            getOrCreateMeasuredEnergyStatsLocked()
            getOrCreateMeasuredEnergyStatsLocked()
                    .updateStandardBucket(energyBucket, energyDeltaUJ, accumulate);
                    .updateStandardBucket(energyBucket, energyDeltaUJ);
        }
        }
        /** Adds the given energy to the given custom energy bucket for this uid. */
        /** Adds the given energy to the given custom energy bucket for this uid. */
        private void addEnergyToCustomBucketLocked(long energyDeltaUJ, int energyBucket,
        private void addEnergyToCustomBucketLocked(long energyDeltaUJ, int energyBucket) {
                boolean accumulate) {
            getOrCreateMeasuredEnergyStatsLocked().updateCustomBucket(energyBucket, energyDeltaUJ);
            getOrCreateMeasuredEnergyStatsLocked()
                    .updateCustomBucket(energyBucket, energyDeltaUJ, accumulate);
        }
        }
        /**
        /**
@@ -12468,7 +12466,7 @@ public class BatteryStatsImpl extends BatteryStats {
            return;
            return;
        }
        }
        mGlobalMeasuredEnergyStats.updateStandardBucket(energyBucket, energyUJ, true);
        mGlobalMeasuredEnergyStats.updateStandardBucket(energyBucket, energyUJ);
        // Now we blame individual apps, but only if the display was ON.
        // Now we blame individual apps, but only if the display was ON.
        if (energyBucket != MeasuredEnergyStats.ENERGY_BUCKET_SCREEN_ON) {
        if (energyBucket != MeasuredEnergyStats.ENERGY_BUCKET_SCREEN_ON) {
@@ -12506,7 +12504,7 @@ public class BatteryStatsImpl extends BatteryStats {
            final long appDisplayEnergyMJ =
            final long appDisplayEnergyMJ =
                    (totalDisplayEnergyMJ * fgTimeMs + (totalFgTimeMs / 2))
                    (totalDisplayEnergyMJ * fgTimeMs + (totalFgTimeMs / 2))
                    / totalFgTimeMs;
                    / totalFgTimeMs;
            uid.addEnergyToStandardBucketLocked(appDisplayEnergyMJ * 1000, energyBucket, true);
            uid.addEnergyToStandardBucketLocked(appDisplayEnergyMJ * 1000, energyBucket);
            // To mitigate round-off errors, remove this app from numerator & denominator totals
            // To mitigate round-off errors, remove this app from numerator & denominator totals
            totalDisplayEnergyMJ -= appDisplayEnergyMJ;
            totalDisplayEnergyMJ -= appDisplayEnergyMJ;
@@ -12533,7 +12531,7 @@ public class BatteryStatsImpl extends BatteryStats {
        if (mGlobalMeasuredEnergyStats == null) return;
        if (mGlobalMeasuredEnergyStats == null) return;
        if (!mOnBatteryInternal || mIgnoreNextExternalStats || totalEnergyUJ <= 0) return;
        if (!mOnBatteryInternal || mIgnoreNextExternalStats || totalEnergyUJ <= 0) return;
        mGlobalMeasuredEnergyStats.updateCustomBucket(customEnergyBucket, totalEnergyUJ, true);
        mGlobalMeasuredEnergyStats.updateCustomBucket(customEnergyBucket, totalEnergyUJ);
        if (uidEnergies == null) return;
        if (uidEnergies == null) return;
        final int numUids = uidEnergies.size();
        final int numUids = uidEnergies.size();
@@ -12543,7 +12541,7 @@ public class BatteryStatsImpl extends BatteryStats {
            if (uidEnergyUJ == 0) continue;
            if (uidEnergyUJ == 0) continue;
            final Uid uidObj = getAvailableUidStatsLocked(uidInt);
            final Uid uidObj = getAvailableUidStatsLocked(uidInt);
            if (uidObj != null) {
            if (uidObj != null) {
                uidObj.addEnergyToCustomBucketLocked(uidEnergyUJ, customEnergyBucket, true);
                uidObj.addEnergyToCustomBucketLocked(uidEnergyUJ, customEnergyBucket);
            } else {
            } else {
                // Ignore any uid not already known to BatteryStats, rather than creating a new Uid.
                // Ignore any uid not already known to BatteryStats, rather than creating a new Uid.
                // Otherwise we could end up reviving dead Uids. Note that the CPU data is updated
                // Otherwise we could end up reviving dead Uids. Note that the CPU data is updated
+11 −15
Original line number Original line Diff line number Diff line
@@ -193,27 +193,24 @@ public class MeasuredEnergyStats {
        return mAccumulatedEnergiesMicroJoules.length;
        return mAccumulatedEnergiesMicroJoules.length;
    }
    }


    // TODO: Get rid of the 'accumulate' boolean. It's always true.
    /** Updates the given standard energy bucket with the given energy if accumulate is true. */
    /** Updates the given standard energy bucket with the given energy if accumulate is true. */
    public void updateStandardBucket(@StandardEnergyBucket int bucket, long energyDeltaUJ,
    public void updateStandardBucket(@StandardEnergyBucket int bucket, long energyDeltaUJ) {
            boolean accumulate) {
        checkValidStandardBucket(bucket);
        checkValidStandardBucket(bucket);
        updateEntry(bucket, energyDeltaUJ, accumulate);
        updateEntry(bucket, energyDeltaUJ);
    }
    }


    /** Updates the given custom energy bucket with the given energy if accumulate is true. */
    /** Updates the given custom energy bucket with the given energy if accumulate is true. */
    public void updateCustomBucket(int customBucket, long energyDeltaUJ, boolean accumulate) {
    public void updateCustomBucket(int customBucket, long energyDeltaUJ) {
        if (!isValidCustomBucket(customBucket)) {
        if (!isValidCustomBucket(customBucket)) {
            Slog.e(TAG, "Attempted to update invalid custom bucket " + customBucket);
            Slog.e(TAG, "Attempted to update invalid custom bucket " + customBucket);
            return;
            return;
        }
        }
        final int index = customBucketToIndex(customBucket);
        final int index = customBucketToIndex(customBucket);
        updateEntry(index, energyDeltaUJ, accumulate);
        updateEntry(index, energyDeltaUJ);
    }
    }


    /** Updates the given index with the given energy if accumulate is true. */
    /** Updates the given index with the given energy if accumulate is true. */
    private void updateEntry(int index, long energyDeltaUJ, boolean accumulate) {
    private void updateEntry(int index, long energyDeltaUJ) {
        if (accumulate) {
        if (mAccumulatedEnergiesMicroJoules[index] >= 0L) {
        if (mAccumulatedEnergiesMicroJoules[index] >= 0L) {
            mAccumulatedEnergiesMicroJoules[index] += energyDeltaUJ;
            mAccumulatedEnergiesMicroJoules[index] += energyDeltaUJ;
        } else {
        } else {
@@ -222,7 +219,6 @@ public class MeasuredEnergyStats {
                    + mAccumulatedEnergiesMicroJoules[index]);
                    + mAccumulatedEnergiesMicroJoules[index]);
        }
        }
    }
    }
    }


    /**
    /**
     * Return accumulated energy (in microjoules) for a standard energy bucket since last reset.
     * Return accumulated energy (in microjoules) for a standard energy bucket since last reset.
+55 −55
Original line number Original line Diff line number Diff line
@@ -81,11 +81,11 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        final MeasuredEnergyStats newStats = MeasuredEnergyStats.createFromTemplate(stats);
        final MeasuredEnergyStats newStats = MeasuredEnergyStats.createFromTemplate(stats);


@@ -114,11 +114,11 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        final Parcel parcel = Parcel.obtain();
        final Parcel parcel = Parcel.obtain();
        stats.writeToParcel(parcel);
        stats.writeToParcel(parcel);
@@ -149,11 +149,11 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        final Parcel parcel = Parcel.obtain();
        final Parcel parcel = Parcel.obtain();
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
@@ -185,17 +185,17 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats template
        final MeasuredEnergyStats template
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        template.updateCustomBucket(0, 50, true);
        template.updateCustomBucket(0, 50);


        final MeasuredEnergyStats stats = MeasuredEnergyStats.createFromTemplate(template);
        final MeasuredEnergyStats stats = MeasuredEnergyStats.createFromTemplate(template);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 200, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 200);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 7, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 7);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 63, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 63);
        stats.updateCustomBucket(0, 315, true);
        stats.updateCustomBucket(0, 315);
        stats.updateCustomBucket(1, 316, true);
        stats.updateCustomBucket(1, 316);


        final Parcel parcel = Parcel.obtain();
        final Parcel parcel = Parcel.obtain();
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
@@ -243,8 +243,8 @@ public class MeasuredEnergyStatsTest {
        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        // Accumulate energy in one bucket and one custom bucket, the rest should be zero
        // Accumulate energy in one bucket and one custom bucket, the rest should be zero
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 200, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 200);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        // Let's try parcelling with including zeros
        // Let's try parcelling with including zeros
        final Parcel includeZerosParcel = Parcel.obtain();
        final Parcel includeZerosParcel = Parcel.obtain();
@@ -305,11 +305,11 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        final Parcel parcel = Parcel.obtain();
        final Parcel parcel = Parcel.obtain();
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
@@ -331,14 +331,14 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats template
        final MeasuredEnergyStats template
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        template.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        template.updateCustomBucket(0, 50, true);
        template.updateCustomBucket(0, 50);


        final MeasuredEnergyStats stats = MeasuredEnergyStats.createFromTemplate(template);
        final MeasuredEnergyStats stats = MeasuredEnergyStats.createFromTemplate(template);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 0L, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 0L);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 7L, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 7L);


        final Parcel parcel = Parcel.obtain();
        final Parcel parcel = Parcel.obtain();
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
        MeasuredEnergyStats.writeSummaryToParcel(stats, parcel, false);
@@ -369,14 +369,14 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_DOZE, 30, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_DOZE, 30);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);


        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);
        stats.updateCustomBucket(0, 3, true);
        stats.updateCustomBucket(0, 3);


        assertEquals(15, stats.getAccumulatedStandardBucketEnergy(ENERGY_BUCKET_SCREEN_ON));
        assertEquals(15, stats.getAccumulatedStandardBucketEnergy(ENERGY_BUCKET_SCREEN_ON));
        assertEquals(ENERGY_DATA_UNAVAILABLE,
        assertEquals(ENERGY_DATA_UNAVAILABLE,
@@ -409,10 +409,10 @@ public class MeasuredEnergyStatsTest {
        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(new boolean[NUMBER_STANDARD_ENERGY_BUCKETS], 3);
                = new MeasuredEnergyStats(new boolean[NUMBER_STANDARD_ENERGY_BUCKETS], 3);


        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);
        stats.updateCustomBucket(2, 13, true);
        stats.updateCustomBucket(2, 13);
        stats.updateCustomBucket(1, 70, true);
        stats.updateCustomBucket(1, 70);


        final long[] output = stats.getAccumulatedCustomBucketEnergies();
        final long[] output = stats.getAccumulatedCustomBucketEnergies();
        assertEquals(3, output.length);
        assertEquals(3, output.length);
@@ -449,11 +449,11 @@ public class MeasuredEnergyStatsTest {


        final MeasuredEnergyStats stats
        final MeasuredEnergyStats stats
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
                = new MeasuredEnergyStats(supportedStandardBuckets, numCustomBuckets);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 10);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 5);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_OTHER, 40);
        stats.updateCustomBucket(0, 50, true);
        stats.updateCustomBucket(0, 50);
        stats.updateCustomBucket(1, 60, true);
        stats.updateCustomBucket(1, 60);


        MeasuredEnergyStats.resetIfNotNull(stats);
        MeasuredEnergyStats.resetIfNotNull(stats);
        // All energy should be reset to 0
        // All energy should be reset to 0
@@ -471,10 +471,10 @@ public class MeasuredEnergyStatsTest {
        }
        }


        // Values should increase as usual.
        // Values should increase as usual.
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 70, true);
        stats.updateStandardBucket(ENERGY_BUCKET_SCREEN_ON, 70);
        assertEquals(70L, stats.getAccumulatedStandardBucketEnergy(ENERGY_BUCKET_SCREEN_ON));
        assertEquals(70L, stats.getAccumulatedStandardBucketEnergy(ENERGY_BUCKET_SCREEN_ON));


        stats.updateCustomBucket(1, 12, true);
        stats.updateCustomBucket(1, 12);
        assertEquals(12L, stats.getAccumulatedCustomBucketEnergy(1));
        assertEquals(12L, stats.getAccumulatedCustomBucketEnergy(1));
    }
    }