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

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

Merge "Reduce the size of PowerStats object for custom power components" into main

parents b4022be7 ceed2ab2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -124,8 +124,8 @@ public final class BatteryUsageStats implements Parcelable, Closeable {
    static final String XML_ATTR_TIME_IN_BACKGROUND = "time_in_background";
    static final String XML_ATTR_TIME_IN_FOREGROUND_SERVICE = "time_in_foreground_service";

    // We need about 700 bytes per UID
    private static final long BATTERY_CONSUMER_CURSOR_WINDOW_SIZE = 5_000 * 700;
    // Max window size. CursorWindow uses only as much memory as needed.
    private static final long BATTERY_CONSUMER_CURSOR_WINDOW_SIZE = 20_000_000; // bytes

    private static final int STATSD_PULL_ATOM_MAX_BYTES = 45000;

+5 −0
Original line number Diff line number Diff line
@@ -16393,6 +16393,10 @@ public class BatteryStatsImpl extends BatteryStats {
     * Callers will need to wait for the collection to complete on the handler thread.
     */
    public void schedulePowerStatsSampleCollection() {
        if (!mSystemReady) {
            return;
        }
        mCpuPowerStatsCollector.forceSchedule();
        mScreenPowerStatsCollector.forceSchedule();
        mMobileRadioPowerStatsCollector.forceSchedule();
@@ -16400,6 +16404,7 @@ public class BatteryStatsImpl extends BatteryStats {
        mBluetoothPowerStatsCollector.forceSchedule();
        mCameraPowerStatsCollector.forceSchedule();
        mGnssPowerStatsCollector.forceSchedule();
        mCustomEnergyConsumerPowerStatsCollector.forceSchedule();
    }
    /**
+10 −0
Original line number Diff line number Diff line
@@ -67,6 +67,16 @@ public class CustomEnergyConsumerPowerStatsCollector extends PowerStatsCollector
        return success;
    }

    @Override
    public boolean forceSchedule() {
        ensureInitialized();
        boolean success = false;
        for (int i = 0; i < mCollectors.size(); i++) {
            success |= mCollectors.get(i).forceSchedule();
        }
        return success;
    }

    @Override
    public void collectAndDump(PrintWriter pw) {
        ensureInitialized();
+1 −4
Original line number Diff line number Diff line
@@ -163,10 +163,7 @@ public class EnergyConsumerPowerStatsCollector extends PowerStatsCollector {

        mLayout.setConsumedEnergy(mPowerStats.stats, 0, uJtoUc(energyDelta, averageVoltage));

        for (int i = mPowerStats.uidStats.size() - 1; i >= 0; i--) {
            mLayout.setUidConsumedEnergy(mPowerStats.uidStats.valueAt(i), 0, 0);
        }

        mPowerStats.uidStats.clear();
        if (energy != null) {
            for (int i = energy.length - 1; i >= 0; i--) {
                EnergyConsumerAttribution[] perUid = energy[i].attribution;
+4 −2
Original line number Diff line number Diff line
@@ -216,6 +216,8 @@ public class PowerStatsExporter {
            PowerStatsLayout layout) {
        AggregatedPowerStatsConfig.PowerComponent powerComponent = powerComponentStats.getConfig();
        int powerComponentId = powerComponent.getPowerComponentId();
        boolean isCustomComponent =
                powerComponentId >= BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID;
        PowerStats.Descriptor descriptor = powerComponentStats.getPowerStatsDescriptor();
        long[] uidStats = new long[descriptor.uidStatsArrayLength];

@@ -223,7 +225,7 @@ public class PowerStatsExporter {
        boolean breakDownByProcState = batteryUsageStatsBuilder.isProcessStateDataNeeded()
                && powerComponent
                .getUidStateConfig()[AggregatedPowerStatsConfig.STATE_PROCESS_STATE].isTracked()
                && powerComponentId < BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID;
                && !isCustomComponent;

        ArrayList<Integer> uids = new ArrayList<>();
        powerComponentStats.collectUids(uids);
@@ -237,7 +239,7 @@ public class PowerStatsExporter {
            }

            for (int powerState = 0; powerState < BatteryConsumer.POWER_STATE_COUNT; powerState++) {
                if (batteryUsageStatsBuilder.isPowerStateDataNeeded()) {
                if (batteryUsageStatsBuilder.isPowerStateDataNeeded() && !isCustomComponent) {
                    if (powerState == BatteryConsumer.POWER_STATE_UNSPECIFIED) {
                        continue;
                    }