Loading cmds/statsd/src/atoms.proto +63 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 cmds/statsd/src/external/StatsPullerManager.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading core/java/android/os/StatsLogEventWrapper.java +0 −8 Original line number Diff line number Diff line Loading @@ -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. */ Loading core/java/com/android/internal/os/BatterySipper.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading core/tests/coretests/src/com/android/internal/os/BatteryStatsHelperTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
cmds/statsd/src/atoms.proto +63 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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
cmds/statsd/src/external/StatsPullerManager.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
core/java/android/os/StatsLogEventWrapper.java +0 −8 Original line number Diff line number Diff line Loading @@ -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. */ Loading
core/java/com/android/internal/os/BatterySipper.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/tests/coretests/src/com/android/internal/os/BatteryStatsHelperTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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