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

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

Merge "Statsd atom: Power Use"

parents a3d850df 75ee6042
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
@@ -192,6 +192,9 @@ message Atom {
        NativeProcessMemoryState native_process_memory_state = 10036;
        CpuTimePerThreadFreq cpu_time_per_thread_freq = 10037;
        OnDevicePowerMeasurement on_device_power_measurement = 10038;
        DeviceCalculatedPowerUse device_calculated_power_use = 10039;
        DeviceCalculatedPowerBlameUid device_calculated_power_blame_uid = 10040;
        DeviceCalculatedPowerBlameOther device_calculated_power_blame_other = 10041;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -3198,3 +3201,63 @@ message CpuTimePerThreadFreq {
    // Time spent in frequency in milliseconds, since thread start.
    optional uint32 time_millis = 7;
}

/**
 * Pulls on-device BatteryStats power use calculations for the overall device.
 */
message DeviceCalculatedPowerUse {
    // Power used by the device in mAh, as computed by BatteryStats, since BatteryStats last reset
    // (i.e. roughly since device was last significantly charged).
    // Currently, this is BatteryStatsHelper.getComputedPower() (not getTotalPower()).
    optional float computed_power_milli_amp_hours = 1;
}

/**
 * Pulls on-device BatteryStats power use calculations broken down by uid.
 * This atom should be complemented by DeviceCalculatedPowerBlameOther, which contains the power use
 * that is attributed to non-uid items. They must all be included to get the total power use.
 */
message DeviceCalculatedPowerBlameUid {
    // Uid being blamed. Note: isolated uids have already been mapped to host uid.
    optional int32 uid = 1 [(is_uid) = true];

    // Power used by this uid in mAh, as computed by BatteryStats, since BatteryStats last reset
    // (i.e. roughly since device was last significantly charged).
    optional float power_milli_amp_hours = 2;
}

/**
 * Pulls on-device BatteryStats power use calculations that are not due to a uid, broken down by
 * drain type.
 * This atom should be complemented by DeviceCalculatedPowerBlameUid, which contains the blame that
 * is attributed uids. They must all be included to get the total power use.
 */
message DeviceCalculatedPowerBlameOther {
    // The type of item whose power use is being reported.
    enum DrainType {
        AMBIENT_DISPLAY = 0;
        // reserved 1; reserved "APP"; // Logged instead in DeviceCalculatedPowerBlameUid.
        BLUETOOTH = 2;
        CAMERA = 3;
        // Cell-standby
        CELL = 4;
        FLASHLIGHT = 5;
        IDLE = 6;
        MEMORY = 7;
        // Amount that total computed drain exceeded the drain estimated using the
        // battery level changes and capacity.
        OVERCOUNTED = 8;
        PHONE = 9;
        SCREEN = 10;
        // Amount that total computed drain was below the drain estimated using the
        // battery level changes and capacity.
        UNACCOUNTED = 11;
        // reserved 12; reserved "USER"; // Entire drain for a user. This is NOT supported.
        WIFI = 13;
    }
    optional DrainType drain_type = 1;

    // Power used by this item in mAh, as computed by BatteryStats, since BatteryStats last reset
    // (i.e. roughly since device was last significantly charged).
    optional float power_milli_amp_hours = 2;
}
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -243,6 +243,20 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
          {2, 3, 4, 5, 6},
          1 * NS_PER_SEC,
          new StatsCompanionServicePuller(android::util::CPU_TIME_PER_THREAD_FREQ)}},
        // DeviceCalculatedPowerUse.
        {android::util::DEVICE_CALCULATED_POWER_USE,
         {{}, {}, 1 * NS_PER_SEC,
          new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_USE)}},
        // DeviceCalculatedPowerBlameUid.
        {android::util::DEVICE_CALCULATED_POWER_BLAME_UID,
         {{}, {}, // BatteryStats already merged isolated with host ids so it's unnecessary here.
          1 * NS_PER_SEC,
          new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_BLAME_UID)}},
        // DeviceCalculatedPowerBlameOther.
        {android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER,
         {{}, {},
          1 * NS_PER_SEC,
          new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER)}},
};

StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
+0 −8
Original line number Diff line number Diff line
@@ -103,14 +103,6 @@ public final class StatsLogEventWrapper implements Parcelable {
        mValues.add(val);
    }

    /**
     * Write a double value.
     */
    public void writeDouble(double val) {
        mTypes.add(EVENT_TYPE_DOUBLE);
        mValues.add(val);
    }

    /**
     * Write a storage value.
     */
+4 −0
Original line number Diff line number Diff line
@@ -130,6 +130,10 @@ public class BatterySipper implements Comparable<BatterySipper> {
    public double wakeLockPowerMah;
    public double wifiPowerMah;

    //                           ****************
    // This list must be kept current with atoms.proto (frameworks/base/cmds/statsd/src/atoms.proto)
    // so the ordinal values (and therefore the order) must never change.
    //                           ****************
    public enum DrainType {
        AMBIENT_DISPLAY,
        @UnsupportedAppUsage
+31 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.format.DateUtils;
import android.util.StatsLog;

import junit.framework.TestCase;

@@ -258,6 +259,36 @@ public class BatteryStatsHelperTest extends TestCase {
        assertThat(time).isEqualTo(TIME_STATE_FOREGROUND_MS);
    }

    @Test
    public void testDrainTypesSyncedWithProto() {
        assertEquals(BatterySipper.DrainType.AMBIENT_DISPLAY.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__AMBIENT_DISPLAY);
        // AtomsProto has no "APP"
        assertEquals(BatterySipper.DrainType.BLUETOOTH.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__BLUETOOTH);
        assertEquals(BatterySipper.DrainType.CAMERA.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__CAMERA);
        assertEquals(BatterySipper.DrainType.CELL.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__CELL);
        assertEquals(BatterySipper.DrainType.FLASHLIGHT.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__FLASHLIGHT);
        assertEquals(BatterySipper.DrainType.IDLE.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__IDLE);
        assertEquals(BatterySipper.DrainType.MEMORY.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__MEMORY);
        assertEquals(BatterySipper.DrainType.OVERCOUNTED.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__OVERCOUNTED);
        assertEquals(BatterySipper.DrainType.PHONE.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__PHONE);
        assertEquals(BatterySipper.DrainType.SCREEN.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__SCREEN);
        assertEquals(BatterySipper.DrainType.UNACCOUNTED.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__UNACCOUNTED);
        // AtomsProto has no "USER"
        assertEquals(BatterySipper.DrainType.WIFI.ordinal(),
                StatsLog.DEVICE_CALCULATED_POWER_BLAME_OTHER__DRAIN_TYPE__WIFI);
    }

    private BatterySipper createTestSmearBatterySipper(long activityTime, double totalPowerMah,
            int uidCode, boolean isUidNull) {
        final BatterySipper sipper = mock(BatterySipper.class);
Loading