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

Commit 0db0328f authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Add CpuPowerStatsCollector for reading power-related CPU stats from kernel

Bug: 285646152
Bug: 285042200
Test: atest FrameworksServicesTests:BatteryStatsTests
Change-Id: I1cd64b8b1c5e1ffd58bc475507393c21f13f32fd
parent 2c00da4e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ per-file BatteryUsageStats* = file:/BATTERY_STATS_OWNERS
per-file *ChargeCalculator* = file:/BATTERY_STATS_OWNERS
per-file *PowerCalculator* = file:/BATTERY_STATS_OWNERS
per-file *PowerEstimator* = file:/BATTERY_STATS_OWNERS
per-file *PowerStats* = file:/BATTERY_STATS_OWNERS
per-file *Kernel* = file:/BATTERY_STATS_OWNERS
per-file *MultiState* = file:/BATTERY_STATS_OWNERS
per-file *PowerProfile* = file:/BATTERY_STATS_OWNERS
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.os;

import android.os.BatteryConsumer;
import android.util.IndentingPrintWriter;
import android.util.SparseArray;

import java.util.Arrays;

/**
 * Container for power stats, acquired by various PowerStatsCollector classes. See subclasses for
 * details.
 */
public final class PowerStats {
    /**
     * Power component (e.g. CPU, WIFI etc) that this snapshot relates to.
     */
    public @BatteryConsumer.PowerComponent int powerComponentId;

    /**
     * Duration, in milliseconds, covered by this snapshot.
     */
    public long durationMs;

    /**
     * Device-wide stats.
     */
    public long[] stats;

    /**
     * Per-UID CPU stats.
     */
    public final SparseArray<long[]> uidStats = new SparseArray<>();

    /**
     * Prints the contents of the stats snapshot.
     */
    public void dump(IndentingPrintWriter pw) {
        pw.print("PowerStats: ");
        pw.println(BatteryConsumer.powerComponentIdToString(powerComponentId));
        pw.increaseIndent();
        pw.print("duration", durationMs).println();
        for (int i = 0; i < uidStats.size(); i++) {
            pw.print("UID ");
            pw.print(uidStats.keyAt(i));
            pw.print(": ");
            pw.print(Arrays.toString(uidStats.valueAt(i)));
            pw.println();
        }
        pw.decreaseIndent();
    }
}
+0 −5
Original line number Diff line number Diff line
@@ -6559,11 +6559,6 @@
    <!-- Whether to show weather on the lock screen by default. -->
    <bool name="config_lockscreenWeatherEnabledByDefault">false</bool>

    <!-- Whether to reset Battery Stats on unplug when the battery level is high. -->
    <bool name="config_batteryStatsResetOnUnplugHighBatteryLevel">true</bool>
    <!-- Whether to reset Battery Stats on unplug if the battery was significantly charged -->
    <bool name="config_batteryStatsResetOnUnplugAfterSignificantCharge">true</bool>

    <!-- Whether we should persist the brightness value in nits for the default display even if
         the underlying display device changes. -->
    <bool name="config_persistBrightnessNitsForDefaultDisplay">false</bool>
+34 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2023 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<!-- These resources are around just to allow their values to be customized
     for different hardware and product builds.  Do not translate.

     NOTE: The naming convention is "config_camelCaseValue". -->

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <!-- Whether to reset Battery Stats on unplug when the battery level is high. -->
    <bool name="config_batteryStatsResetOnUnplugHighBatteryLevel">true</bool>
    <!-- Whether to reset Battery Stats on unplug if the battery was significantly charged -->
    <bool name="config_batteryStatsResetOnUnplugAfterSignificantCharge">true</bool>

    <!-- CPU power stats collection throttle period in milliseconds.  Since power stats collection
    is a relatively expensive operation, this throttle period may need to be adjusted for low-power
    devices-->
    <integer name="config_defaultPowerStatsThrottlePeriodCpu">60000</integer>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -5074,6 +5074,7 @@

  <java-symbol type="bool" name="config_batteryStatsResetOnUnplugHighBatteryLevel" />
  <java-symbol type="bool" name="config_batteryStatsResetOnUnplugAfterSignificantCharge" />
  <java-symbol type="integer" name="config_defaultPowerStatsThrottlePeriodCpu" />

  <java-symbol name="materialColorOnSecondaryFixedVariant" type="attr"/>
  <java-symbol name="materialColorOnTertiaryFixedVariant" type="attr"/>
Loading