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

Commit 4365a61e authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Remove flag com.android.server.power.optimization.streamlined_battery_stats

Bug: 409609801
Test: presubmit
Flag: EXEMPT removing com.android.server.power.optimization.streamlined_battery_stats
Change-Id: I6b4a8e0c2968b9480047b115267ed4af16f7d1ba
parent 14a0162e
Loading
Loading
Loading
Loading
+12 −24
Original line number Original line Diff line number Diff line
@@ -476,11 +476,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                !Flags.extendedBatteryHistoryContinuousCollectionEnabled());
                !Flags.extendedBatteryHistoryContinuousCollectionEnabled());


        MultiStatePowerAttributor attributor = (MultiStatePowerAttributor) mPowerAttributor;
        MultiStatePowerAttributor attributor = (MultiStatePowerAttributor) mPowerAttributor;
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU,

                Flags.streamlinedBatteryStats());
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU, true);
        attributor.setPowerComponentSupported(
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CPU, true);
                BatteryConsumer.POWER_COMPONENT_CPU,
                Flags.streamlinedBatteryStats());


        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WAKELOCK,
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WAKELOCK,
                Flags.streamlinedMiscBatteryStats());
                Flags.streamlinedMiscBatteryStats());
@@ -610,7 +608,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub


    private static boolean isBatteryUsageStatsAccumulationSupported() {
    private static boolean isBatteryUsageStatsAccumulationSupported() {
        return Flags.accumulateBatteryUsageStats()
        return Flags.accumulateBatteryUsageStats()
                && Flags.streamlinedBatteryStats()
                && Flags.streamlinedConnectivityBatteryStats()
                && Flags.streamlinedConnectivityBatteryStats()
                && Flags.streamlinedMiscBatteryStats();
                && Flags.streamlinedMiscBatteryStats();
    }
    }
@@ -620,7 +617,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
     */
     */
    public void onSystemReady() {
    public void onSystemReady() {
        mStats.onSystemReady(mContext);
        mStats.onSystemReady(mContext);
        mPowerStatsScheduler.start(Flags.streamlinedBatteryStats());
        mPowerStatsScheduler.start();
    }
    }


    private final class LocalService extends BatteryStatsInternal {
    private final class LocalService extends BatteryStatsInternal {
@@ -988,10 +985,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                SystemClock.elapsedRealtime(),
                SystemClock.elapsedRealtime(),
                mWorker.getLastCollectionTimeStamp())) {
                mWorker.getLastCollectionTimeStamp())) {
            syncStats("get-stats", BatteryExternalStatsWorker.UPDATE_ALL);
            syncStats("get-stats", BatteryExternalStatsWorker.UPDATE_ALL);
            if (Flags.streamlinedBatteryStats()) {
            mStats.collectPowerStatsSamples();
            mStats.collectPowerStatsSamples();
        }
        }
        }


        return mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, queries);
        return mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, queries);
    }
    }
@@ -3011,9 +3006,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        if (isBatteryUsageStatsAccumulationSupported()) {
        if (isBatteryUsageStatsAccumulationSupported()) {
            pw.println("     --accumulated: continuously accumulated since setup or reset-all");
            pw.println("     --accumulated: continuously accumulated since setup or reset-all");
        }
        }
        if (Flags.streamlinedBatteryStats()) {
        pw.println("  --sample: collect and dump a sample of stats for debugging purpose");
        pw.println("  --sample: collect and dump a sample of stats for debugging purpose");
        }
        pw.println("  --sync: wait for delayed processing to finish (for use in tests)");
        pw.println("  --sync: wait for delayed processing to finish (for use in tests)");
        pw.println("  <package.name>: optional name of package to filter output by.");
        pw.println("  <package.name>: optional name of package to filter output by.");
        pw.println("  -h: print this help text.");
        pw.println("  -h: print this help text.");
@@ -3035,10 +3028,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        awaitCompletion();
        awaitCompletion();
        synchronized (mStats) {
        synchronized (mStats) {
            mStats.dumpConstantsLocked(pw);
            mStats.dumpConstantsLocked(pw);

            pw.println("Flags:");
            pw.println("    " + Flags.FLAG_STREAMLINED_BATTERY_STATS
                    + ": " + Flags.streamlinedBatteryStats());
        }
        }
    }
    }


@@ -3100,11 +3089,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
        synchronized (mStats) {
            mStats.prepareForDumpLocked();
            mStats.prepareForDumpLocked();
        }
        }
        if (Flags.streamlinedBatteryStats()) {

        // Important: perform this operation outside the mStats lock, because it will
        // Important: perform this operation outside the mStats lock, because it will
        // need to access BatteryStats from a handler thread
        // need to access BatteryStats from a handler thread
        mStats.collectPowerStatsSamples();
        mStats.collectPowerStatsSamples();
        }


        try (BatteryUsageStats batteryUsageStats =
        try (BatteryUsageStats batteryUsageStats =
                     mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, query)) {
                     mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, query)) {
@@ -3305,10 +3293,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    mCpuWakeupStats.dump(new IndentingPrintWriter(pw, "  "),
                    mCpuWakeupStats.dump(new IndentingPrintWriter(pw, "  "),
                            SystemClock.elapsedRealtime());
                            SystemClock.elapsedRealtime());
                    return;
                    return;
                } else if (Flags.streamlinedBatteryStats() && "--sample".equals(arg)) {
                } else if ("--sample".equals(arg)) {
                    dumpStatsSample(pw);
                    dumpStatsSample(pw);
                    return;
                    return;
                } else if (Flags.streamlinedBatteryStats() && "--aggregated".equals(arg)) {
                } else if ("--aggregated".equals(arg)) {
                    dumpAggregatedStats(pw);
                    dumpAggregatedStats(pw);
                    return;
                    return;
                } else if ("--store".equals(arg)) {
                } else if ("--store".equals(arg)) {
+17 −219
Original line number Original line Diff line number Diff line
@@ -1732,8 +1732,6 @@ public class BatteryStatsImpl extends BatteryStats {
    protected EnergyConsumerStats mGlobalEnergyConsumerStats;
    protected EnergyConsumerStats mGlobalEnergyConsumerStats;
    /** Bluetooth Power calculator for attributing bluetooth EnergyConsumer to uids */
    /** Bluetooth Power calculator for attributing bluetooth EnergyConsumer to uids */
    @Nullable BluetoothPowerCalculator mBluetoothPowerCalculator = null;
    @Nullable BluetoothPowerCalculator mBluetoothPowerCalculator = null;
    /** Cpu Power calculator for attributing cpu EnergyConsumer to uids */
    @Nullable CpuPowerCalculator mCpuPowerCalculator = null;
    /** Mobile Radio Power calculator for attributing radio EnergyConsumer to uids */
    /** Mobile Radio Power calculator for attributing radio EnergyConsumer to uids */
    @Nullable MobileRadioPowerCalculator mMobileRadioPowerCalculator = null;
    @Nullable MobileRadioPowerCalculator mMobileRadioPowerCalculator = null;
    /** Wifi Power calculator for attributing wifi EnergyConsumer to uids */
    /** Wifi Power calculator for attributing wifi EnergyConsumer to uids */
@@ -8802,8 +8800,6 @@ public class BatteryStatsImpl extends BatteryStats {
         * Gets the minimum of the uid's foreground activity time and its PROCESS_STATE_TOP time
         * Gets the minimum of the uid's foreground activity time and its PROCESS_STATE_TOP time
         * since last marked. Also sets the mark time for both these timers.
         * since last marked. Also sets the mark time for both these timers.
         *
         *
         * @see CpuPowerCalculator
         *
         * @param doCalc if true, then calculate the minimum; else don't bother and return 0. Either
         * @param doCalc if true, then calculate the minimum; else don't bother and return 0. Either
         *               way, the mark is set.
         *               way, the mark is set.
         */
         */
@@ -13350,87 +13346,6 @@ public class BatteryStatsImpl extends BatteryStats {
        }
        }
    }
    }
    /**
     * Accumulate Cpu charge consumption and distribute it to the correct state and the apps.
     * Only call if device is on battery.
     *
     * @param clusterChargeUC amount of charge (microcoulombs) consumed by each Cpu Cluster
     * @param accumulator collection of calculated uid cpu power consumption to smear
     *                    clusterChargeUC against.
     */
    @GuardedBy("this")
    @SuppressWarnings("GuardedBy") // errorprone false positive on u.addChargeToStandardBucketLocked
    private void updateCpuEnergyConsumerStatsLocked(@NonNull long[] clusterChargeUC,
            @NonNull CpuDeltaPowerAccumulator accumulator) {
        if (DEBUG_ENERGY) {
            Slog.d(TAG, "Updating cpu cluster stats: " + Arrays.toString(clusterChargeUC));
        }
        if (mGlobalEnergyConsumerStats == null) {
            return;
        }
        final int numClusters = clusterChargeUC.length;
        long totalCpuChargeUC = 0;
        for (int i = 0; i < numClusters; i++) {
            totalCpuChargeUC += clusterChargeUC[i];
        }
        if (totalCpuChargeUC <= 0) return;
        final long timestampMs = mClock.elapsedRealtime();
        mGlobalEnergyConsumerStats.updateStandardBucket(EnergyConsumerStats.POWER_BUCKET_CPU,
                totalCpuChargeUC, timestampMs);
        // Calculate the microcoulombs/milliamp-hour charge ratio for each
        // cluster to normalize  each uid's estimated power usage against actual power usage for
        // a given cluster.
        final double[] clusterChargeRatio = new double[numClusters];
        for (int cluster = 0; cluster < numClusters; cluster++) {
            final double totalClusterChargeMah = accumulator.totalClusterChargesMah[cluster];
            if (totalClusterChargeMah <= 0.0) {
                // This cluster did not have any work on it, since last update.
                // Avoid dividing by zero.
                clusterChargeRatio[cluster] = 0.0;
            } else {
                clusterChargeRatio[cluster] =
                        clusterChargeUC[cluster] / accumulator.totalClusterChargesMah[cluster];
            }
        }
        // Assign and distribute power usage to apps based on their calculated cpu cluster charge.
        final long uidChargeArraySize = accumulator.perUidCpuClusterChargesMah.size();
        for (int i = 0; i < uidChargeArraySize; i++) {
            final Uid uid = accumulator.perUidCpuClusterChargesMah.keyAt(i);
            final double[] uidClusterChargesMah = accumulator.perUidCpuClusterChargesMah.valueAt(i);
            // Iterate each cpu cluster and sum the proportional cpu cluster charge to
            // get the total cpu charge consumed by a uid.
            long uidCpuChargeUC = 0;
            for (int cluster = 0; cluster < numClusters; cluster++) {
                final double uidClusterChargeMah = uidClusterChargesMah[cluster];
                // Proportionally allocate the cpu cluster charge to a uid using the
                // cluster charge/charge ratio. Add 0.5 to round the proportional
                // charge double to the nearest long value.
                final long uidClusterChargeUC =
                        (long) (uidClusterChargeMah * clusterChargeRatio[cluster]
                                + 0.5);
                uidCpuChargeUC += uidClusterChargeUC;
            }
            if (uidCpuChargeUC < 0) {
                Slog.wtf(TAG, "Unexpected proportional EnergyConsumer charge "
                        + "(" + uidCpuChargeUC + ") for uid " + uid.mUid);
                continue;
            }
            uid.addChargeToStandardBucketLocked(uidCpuChargeUC,
                    EnergyConsumerStats.POWER_BUCKET_CPU, timestampMs);
        }
    }
    /**
    /**
     * Accumulate Display charge consumption and distribute it to the correct state and the apps.
     * Accumulate Display charge consumption and distribute it to the correct state and the apps.
     *
     *
@@ -13830,64 +13745,6 @@ public class BatteryStatsImpl extends BatteryStats {
        return mOnBatteryScreenOffTimeBase.isRunning();
        return mOnBatteryScreenOffTimeBase.isRunning();
    }
    }
    /**
     * Object for calculating and accumulating the estimated cpu power used while reading the
     * various cpu kernel files.
     */
    @VisibleForTesting
    public static class CpuDeltaPowerAccumulator {
        // Keeps track of total charge used per cluster.
        public final double[] totalClusterChargesMah;
        // Keeps track of charge used per cluster per uid.
        public final ArrayMap<Uid, double[]> perUidCpuClusterChargesMah;
        private final CpuPowerCalculator mCalculator;
        private Uid mCachedUid = null;
        private double[] mUidClusterCache = null;
        CpuDeltaPowerAccumulator(CpuPowerCalculator calculator, int nClusters) {
            mCalculator = calculator;
            totalClusterChargesMah = new double[nClusters];
            perUidCpuClusterChargesMah = new ArrayMap<>();
        }
        /** Add per cpu cluster durations to the currently cached uid. */
        public void addCpuClusterDurationsMs(Uid uid, long[] durationsMs) {
            final double[] uidChargesMah = getOrCreateUidCpuClusterCharges(uid);
            for (int cluster = 0; cluster < durationsMs.length; cluster++) {
                final double estimatedDeltaMah = mCalculator.calculatePerCpuClusterPowerMah(cluster,
                        durationsMs[cluster]);
                uidChargesMah[cluster] += estimatedDeltaMah;
                totalClusterChargesMah[cluster] += estimatedDeltaMah;
            }
        }
        /** Add per speed per cpu cluster durations to the currently cached uid. */
        public void addCpuClusterSpeedDurationsMs(Uid uid, int cluster, int speed,
                long durationsMs) {
            final double[] uidChargesMah = getOrCreateUidCpuClusterCharges(uid);
            final double estimatedDeltaMah = mCalculator.calculatePerCpuFreqPowerMah(cluster, speed,
                    durationsMs);
            uidChargesMah[cluster] += estimatedDeltaMah;
            totalClusterChargesMah[cluster] += estimatedDeltaMah;
        }
        private double[] getOrCreateUidCpuClusterCharges(Uid uid) {
            // Repeated additions on the same uid is very likely.
            // Skip a lookup if getting the same uid as the last get.
            if (uid == mCachedUid) return mUidClusterCache;
            double[] uidChargesMah = perUidCpuClusterChargesMah.get(uid);
            if (uidChargesMah == null) {
                uidChargesMah = new double[totalClusterChargesMah.length];
                perUidCpuClusterChargesMah.put(uid, uidChargesMah);
            }
            mCachedUid = uid;
            mUidClusterCache = uidChargesMah;
            return uidChargesMah;
        }
    }
    /**
    /**
     * Read and distribute CPU usage across apps. If their are partial wakelocks being held
     * Read and distribute CPU usage across apps. If their are partial wakelocks being held
     * and we are on battery with screen off, we give more of the cpu time to those apps holding
     * and we are on battery with screen off, we give more of the cpu time to those apps holding
@@ -13946,49 +13803,20 @@ public class BatteryStatsImpl extends BatteryStats {
        final SparseLongArray updatedUids = mCpuUidFreqTimeReader.allUidTimesAvailable()
        final SparseLongArray updatedUids = mCpuUidFreqTimeReader.allUidTimesAvailable()
                ? null : new SparseLongArray();
                ? null : new SparseLongArray();
        final CpuDeltaPowerAccumulator powerAccumulator;
        if (mGlobalEnergyConsumerStats != null
                && mGlobalEnergyConsumerStats.isStandardBucketSupported(
                EnergyConsumerStats.POWER_BUCKET_CPU)) {
            if (cpuClusterChargeUC == null) {
                Slog.wtf(TAG,
                        "POWER_BUCKET_CPU supported but no EnergyConsumer Cpu Cluster charge "
                                + "reported on updateCpuTimeLocked!");
                powerAccumulator = null;
            } else {
                if (mCpuPowerCalculator == null) {
                    mCpuPowerCalculator = new CpuPowerCalculator(mCpuScalingPolicies,
                            mPowerProfile);
                }
                // Cpu EnergyConsumer is supported, create an object to accumulate the estimated
                // charge consumption since the last cpu update
                powerAccumulator = new CpuDeltaPowerAccumulator(mCpuPowerCalculator,
                        mCpuScalingPolicies.getPolicies().length);
            }
        } else {
            powerAccumulator = null;
        }
        readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids, onBattery);
        readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids, onBattery);
        // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu
        // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu
        // freqs, so no need to approximate these values.
        // freqs, so no need to approximate these values.
        if (updatedUids != null) {
        if (updatedUids != null) {
            updateClusterSpeedTimes(updatedUids, onBattery, powerAccumulator);
            updateClusterSpeedTimes(updatedUids, onBattery);
        }
        }
        readKernelUidCpuFreqTimesLocked(partialTimersToConsider, onBattery, onBatteryScreenOff,
        readKernelUidCpuFreqTimesLocked(partialTimersToConsider, onBattery, onBatteryScreenOff
                powerAccumulator);
        );
        mNumAllUidCpuTimeReads += 2;
        mNumAllUidCpuTimeReads += 2;
        if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) {
        if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) {
            // Cpu Active times do not get any info ony how to attribute Cpu Cluster
            // charge, so not need to provide the powerAccumulator
            readKernelUidCpuActiveTimesLocked(onBattery);
            readKernelUidCpuActiveTimesLocked(onBattery);
            readKernelUidCpuClusterTimesLocked(onBattery, powerAccumulator);
            readKernelUidCpuClusterTimesLocked(onBattery);
            mNumAllUidCpuTimeReads += 2;
            mNumAllUidCpuTimeReads += 2;
        }
        }
        if (powerAccumulator != null) {
            updateCpuEnergyConsumerStatsLocked(cpuClusterChargeUC, powerAccumulator);
        }
    }
    }
    /**
    /**
@@ -14022,16 +13850,13 @@ public class BatteryStatsImpl extends BatteryStats {
    /**
    /**
     * Take snapshot of cpu times (aggregated over all uids) at different frequencies and
     * Take snapshot of cpu times (aggregated over all uids) at different frequencies and
     * calculate cpu times spent by each uid at different frequencies. Will also add estimated
     * calculate cpu times spent by each uid at different frequencies.
     * power consumptions, if powerAccumulator data structure is provided.
     *
     *
     * @param updatedUids The uids for which times spent at different frequencies are calculated.
     * @param updatedUids The uids for which times spent at different frequencies are calculated.
     * @param onBattery   whether or not this is onBattery
     * @param onBattery   whether or not this is onBattery
     * @param powerAccumulator object to accumulate the estimated cluster charge consumption.
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids, boolean onBattery,
    public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids, boolean onBattery) {
            @Nullable CpuDeltaPowerAccumulator powerAccumulator) {
        long totalCpuClustersTimeMs = 0;
        long totalCpuClustersTimeMs = 0;
        // Read the time spent for each cluster at various cpu frequencies.
        // Read the time spent for each cluster at various cpu frequencies.
        final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][];
        final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][];
@@ -14079,11 +13904,6 @@ public class BatteryStatsImpl extends BatteryStats {
                                * clusterSpeedTimesMs[cluster][speed]
                                * clusterSpeedTimesMs[cluster][speed]
                                / totalCpuClustersTimeMs;
                                / totalCpuClustersTimeMs;
                        cpuSpeeds[speed].addCountLocked(deltaSpeedCount, onBattery);
                        cpuSpeeds[speed].addCountLocked(deltaSpeedCount, onBattery);
                        if (powerAccumulator != null) {
                            powerAccumulator.addCpuClusterSpeedDurationsMs(u, cluster,
                                    speed, deltaSpeedCount);
                        }
                    }
                    }
                }
                }
            }
            }
@@ -14210,19 +14030,17 @@ public class BatteryStatsImpl extends BatteryStats {
    /**
    /**
     * Take a snapshot of the cpu times spent by each uid in each freq and update the
     * Take a snapshot of the cpu times spent by each uid in each freq and update the
     * corresponding counters.  Will also add estimated power consumptions, if powerAccumulator
     * corresponding counters.
     * data structure is provided.
     *
     *
     * @param partialTimers The wakelock holders among which the cpu freq times will be distributed.
     * @param partialTimers      The wakelock holders among which the cpu freq times will be
     *                           distributed.
     * @param onBattery          whether or not this is onBattery
     * @param onBattery          whether or not this is onBattery
     * @param onBatteryScreenOff whether or not this is onBattery with the screen off.
     * @param onBatteryScreenOff whether or not this is onBattery with the screen off.
     * @param powerAccumulator object to accumulate the estimated cluster charge consumption.
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    @SuppressWarnings("GuardedBy")    // errorprone false positive on readDelta
    @SuppressWarnings("GuardedBy")    // errorprone false positive on readDelta
    public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers,
    public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers,
            boolean onBattery, boolean onBatteryScreenOff,
            boolean onBattery, boolean onBatteryScreenOff) {
            @Nullable CpuDeltaPowerAccumulator powerAccumulator) {
        final boolean perClusterTimesAvailable =
        final boolean perClusterTimesAvailable =
                mCpuUidFreqTimeReader.perClusterTimesAvailable();
                mCpuUidFreqTimeReader.perClusterTimesAvailable();
        final int numWakelocks = partialTimers == null ? 0 : partialTimers.size();
        final int numWakelocks = partialTimers == null ? 0 : partialTimers.size();
@@ -14231,9 +14049,7 @@ public class BatteryStatsImpl extends BatteryStats {
        mWakeLockAllocationsUs = null;
        mWakeLockAllocationsUs = null;
        final long startTimeMs = mClock.uptimeMillis();
        final long startTimeMs = mClock.uptimeMillis();
        final long elapsedRealtimeMs = mClock.elapsedRealtime();
        final long elapsedRealtimeMs = mClock.elapsedRealtime();
        // If power is being accumulated for attribution, data needs to be read immediately.
        mCpuUidFreqTimeReader.readDelta(mIgnoreNextExternalStats, (uid, cpuFreqTimeMs) -> {
        final boolean forceRead = powerAccumulator != null || mIgnoreNextExternalStats;
        mCpuUidFreqTimeReader.readDelta(forceRead, (uid, cpuFreqTimeMs) -> {
            if (mIgnoreNextExternalStats) {
            if (mIgnoreNextExternalStats) {
                return;
                return;
            }
            }
@@ -14297,11 +14113,6 @@ public class BatteryStatsImpl extends BatteryStats {
                            appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000;
                            appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000;
                        }
                        }
                        cpuTimesUs[speed].addCountLocked(appAllocationUs, onBattery);
                        cpuTimesUs[speed].addCountLocked(appAllocationUs, onBattery);
                        if (powerAccumulator != null) {
                            powerAccumulator.addCpuClusterSpeedDurationsMs(u, cluster,
                                    speed, appAllocationUs / 1000);
                        }
                        freqIndex++;
                        freqIndex++;
                    }
                    }
                }
                }
@@ -14340,11 +14151,6 @@ public class BatteryStatsImpl extends BatteryStats {
                                mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i);
                                mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i);
                        cpuTimeUs[speed].addCountLocked(allocationUs, onBattery);
                        cpuTimeUs[speed].addCountLocked(allocationUs, onBattery);
                        mWakeLockAllocationsUs[cluster][speed] -= allocationUs;
                        mWakeLockAllocationsUs[cluster][speed] -= allocationUs;
                        if (powerAccumulator != null) {
                            powerAccumulator.addCpuClusterSpeedDurationsMs(u, cluster,
                                    speed, allocationUs / 1000);
                        }
                    }
                    }
                }
                }
            }
            }
@@ -14395,20 +14201,16 @@ public class BatteryStatsImpl extends BatteryStats {
    /**
    /**
     * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding
     * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding
     * counters. Will also add estimated power consumptions, if powerAccumulator data structure
     * counters.
     * is provided.
     *
     *
     * @param onBattery whether or not this is onBattery
     * @param onBattery whether or not this is onBattery
     * @param powerAccumulator object to accumulate the estimated cluster charge consumption.
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public void readKernelUidCpuClusterTimesLocked(boolean onBattery,
    public void readKernelUidCpuClusterTimesLocked(boolean onBattery) {
            @Nullable CpuDeltaPowerAccumulator powerAccumulator) {
        final long startTimeMs = mClock.uptimeMillis();
        final long startTimeMs = mClock.uptimeMillis();
        final long elapsedRealtimeMs = mClock.elapsedRealtime();
        final long elapsedRealtimeMs = mClock.elapsedRealtime();
        // If power is being accumulated for attribution, data needs to be read immediately.
        // If power is being accumulated for attribution, data needs to be read immediately.
        final boolean forceRead = powerAccumulator != null;
        mCpuUidClusterTimeReader.readDelta(false, (uid, cpuClusterTimesMs) -> {
        mCpuUidClusterTimeReader.readDelta(forceRead, (uid, cpuClusterTimesMs) -> {
            uid = mapUid(uid);
            uid = mapUid(uid);
            if (Process.isIsolated(uid)) {
            if (Process.isIsolated(uid)) {
                if (DEBUG) Slog.w(TAG, "Got cluster times for an isolated uid: " + uid);
                if (DEBUG) Slog.w(TAG, "Got cluster times for an isolated uid: " + uid);
@@ -14420,10 +14222,6 @@ public class BatteryStatsImpl extends BatteryStats {
            }
            }
            final Uid u = getUidStatsLocked(uid, elapsedRealtimeMs, startTimeMs);
            final Uid u = getUidStatsLocked(uid, elapsedRealtimeMs, startTimeMs);
            u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesMs, onBattery);
            u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesMs, onBattery);
            if (powerAccumulator != null) {
                powerAccumulator.addCpuClusterDurationsMs(u, cpuClusterTimesMs);
            }
        });
        });
        final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs;
        final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs;
+0 −5
Original line number Original line Diff line number Diff line
@@ -101,11 +101,6 @@ public class BatteryUsageStatsProvider {
                        BatteryConsumer.POWER_COMPONENT_BASE)) {
                        BatteryConsumer.POWER_COMPONENT_BASE)) {
                    mPowerCalculators.add(new BatteryChargeCalculator());
                    mPowerCalculators.add(new BatteryChargeCalculator());
                }
                }
                if (!mPowerAttributor.isPowerComponentSupported(
                        BatteryConsumer.POWER_COMPONENT_CPU)) {
                    mPowerCalculators.add(
                            new CpuPowerCalculator(mCpuScalingPolicies, mPowerProfile));
                }
                if (!mPowerAttributor.isPowerComponentSupported(
                if (!mPowerAttributor.isPowerComponentSupported(
                        BatteryConsumer.POWER_COMPONENT_MEMORY)) {
                        BatteryConsumer.POWER_COMPONENT_MEMORY)) {
                    mPowerCalculators.add(new MemoryPowerCalculator(mPowerProfile));
                    mPowerCalculators.add(new MemoryPowerCalculator(mPowerProfile));
+0 −366

File deleted.

Preview size limit exceeded, changes collapsed.

+3 −7
Original line number Original line Diff line number Diff line
@@ -41,7 +41,6 @@ public class PowerStatsScheduler {
    private static final long HOUR_IN_MILLIS = TimeUnit.HOURS.toMillis(1);
    private static final long HOUR_IN_MILLIS = TimeUnit.HOURS.toMillis(1);


    private final AlarmScheduler mAlarmScheduler;
    private final AlarmScheduler mAlarmScheduler;
    private boolean mEnablePeriodicPowerStatsCollection;
    @DurationMillisLong
    @DurationMillisLong
    private final long mAggregatedPowerStatsSpanDuration;
    private final long mAggregatedPowerStatsSpanDuration;
    @DurationMillisLong
    @DurationMillisLong
@@ -89,13 +88,10 @@ public class PowerStatsScheduler {
    /**
    /**
     * Kicks off the scheduling of power stats aggregation spans.
     * Kicks off the scheduling of power stats aggregation spans.
     */
     */
    public void start(boolean enablePeriodicPowerStatsCollection) {
    public void start() {
        mEnablePeriodicPowerStatsCollection = enablePeriodicPowerStatsCollection;
        if (mEnablePeriodicPowerStatsCollection) {
        schedulePowerStatsAggregation();
        schedulePowerStatsAggregation();
        scheduleNextPowerStatsAggregation();
        scheduleNextPowerStatsAggregation();
    }
    }
    }


    private void scheduleNextPowerStatsAggregation() {
    private void scheduleNextPowerStatsAggregation() {
        mAlarmScheduler.scheduleAlarm(mClock.elapsedRealtime() + mPowerStatsAggregationPeriod,
        mAlarmScheduler.scheduleAlarm(mClock.elapsedRealtime() + mPowerStatsAggregationPeriod,
Loading