Consolidate the HealthStats UI to only use milliseconds.
BatteryStats uses a mix of microseconds and milliseconds, and keeping
which one is which straight is difficult. The internal bookkeeping
is left using us where it already does, for the extra precision. But
having the API be mixed will only make it harder for developers, and
lead them to make the same mistake that I did in the API where I
missed some conversions.
Bug: 28197858
Change-Id: I99114bae259b9bdd47ce5c22e724d87bbd63336d
diff --git a/api/current.txt b/api/current.txt
index 78b8501..0ce73e1 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -29524,7 +29524,7 @@
field public static final int MEASUREMENT_BLUETOOTH_TX_MS = 10022; // 0x2726
field public static final int MEASUREMENT_BLUETOOTH_TX_PACKETS = 10059; // 0x274b
field public static final int MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT = 10046; // 0x273e
- field public static final int MEASUREMENT_CPU_POWER_MAUS = 10064; // 0x2750
+ field public static final int MEASUREMENT_CPU_POWER_MAMS = 10064; // 0x2750
field public static final int MEASUREMENT_MOBILE_IDLE_MS = 10024; // 0x2728
field public static final int MEASUREMENT_MOBILE_POWER_MAMS = 10027; // 0x272b
field public static final int MEASUREMENT_MOBILE_RX_BYTES = 10048; // 0x2740
@@ -29536,11 +29536,11 @@
field public static final int MEASUREMENT_OTHER_USER_ACTIVITY_COUNT = 10045; // 0x273d
field public static final int MEASUREMENT_REALTIME_BATTERY_MS = 10001; // 0x2711
field public static final int MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS = 10003; // 0x2713
- field public static final int MEASUREMENT_SYSTEM_CPU_TIME_US = 10063; // 0x274f
+ field public static final int MEASUREMENT_SYSTEM_CPU_TIME_MS = 10063; // 0x274f
field public static final int MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT = 10047; // 0x273f
field public static final int MEASUREMENT_UPTIME_BATTERY_MS = 10002; // 0x2712
field public static final int MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS = 10004; // 0x2714
- field public static final int MEASUREMENT_USER_CPU_TIME_US = 10062; // 0x274e
+ field public static final int MEASUREMENT_USER_CPU_TIME_MS = 10062; // 0x274e
field public static final int MEASUREMENT_WIFI_FULL_LOCK_MS = 10029; // 0x272d
field public static final int MEASUREMENT_WIFI_IDLE_MS = 10016; // 0x2720
field public static final int MEASUREMENT_WIFI_MULTICAST_MS = 10031; // 0x272f
diff --git a/api/system-current.txt b/api/system-current.txt
index 2931227..4b60cb1 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -32021,7 +32021,7 @@
field public static final int MEASUREMENT_BLUETOOTH_TX_MS = 10022; // 0x2726
field public static final int MEASUREMENT_BLUETOOTH_TX_PACKETS = 10059; // 0x274b
field public static final int MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT = 10046; // 0x273e
- field public static final int MEASUREMENT_CPU_POWER_MAUS = 10064; // 0x2750
+ field public static final int MEASUREMENT_CPU_POWER_MAMS = 10064; // 0x2750
field public static final int MEASUREMENT_MOBILE_IDLE_MS = 10024; // 0x2728
field public static final int MEASUREMENT_MOBILE_POWER_MAMS = 10027; // 0x272b
field public static final int MEASUREMENT_MOBILE_RX_BYTES = 10048; // 0x2740
@@ -32033,11 +32033,11 @@
field public static final int MEASUREMENT_OTHER_USER_ACTIVITY_COUNT = 10045; // 0x273d
field public static final int MEASUREMENT_REALTIME_BATTERY_MS = 10001; // 0x2711
field public static final int MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS = 10003; // 0x2713
- field public static final int MEASUREMENT_SYSTEM_CPU_TIME_US = 10063; // 0x274f
+ field public static final int MEASUREMENT_SYSTEM_CPU_TIME_MS = 10063; // 0x274f
field public static final int MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT = 10047; // 0x273f
field public static final int MEASUREMENT_UPTIME_BATTERY_MS = 10002; // 0x2712
field public static final int MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS = 10004; // 0x2714
- field public static final int MEASUREMENT_USER_CPU_TIME_US = 10062; // 0x274e
+ field public static final int MEASUREMENT_USER_CPU_TIME_MS = 10062; // 0x274e
field public static final int MEASUREMENT_WIFI_FULL_LOCK_MS = 10029; // 0x272d
field public static final int MEASUREMENT_WIFI_IDLE_MS = 10016; // 0x2720
field public static final int MEASUREMENT_WIFI_MULTICAST_MS = 10031; // 0x272f
diff --git a/api/test-current.txt b/api/test-current.txt
index 4e83278..838e419 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -29593,7 +29593,7 @@
field public static final int MEASUREMENT_BLUETOOTH_TX_MS = 10022; // 0x2726
field public static final int MEASUREMENT_BLUETOOTH_TX_PACKETS = 10059; // 0x274b
field public static final int MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT = 10046; // 0x273e
- field public static final int MEASUREMENT_CPU_POWER_MAUS = 10064; // 0x2750
+ field public static final int MEASUREMENT_CPU_POWER_MAMS = 10064; // 0x2750
field public static final int MEASUREMENT_MOBILE_IDLE_MS = 10024; // 0x2728
field public static final int MEASUREMENT_MOBILE_POWER_MAMS = 10027; // 0x272b
field public static final int MEASUREMENT_MOBILE_RX_BYTES = 10048; // 0x2740
@@ -29605,11 +29605,11 @@
field public static final int MEASUREMENT_OTHER_USER_ACTIVITY_COUNT = 10045; // 0x273d
field public static final int MEASUREMENT_REALTIME_BATTERY_MS = 10001; // 0x2711
field public static final int MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS = 10003; // 0x2713
- field public static final int MEASUREMENT_SYSTEM_CPU_TIME_US = 10063; // 0x274f
+ field public static final int MEASUREMENT_SYSTEM_CPU_TIME_MS = 10063; // 0x274f
field public static final int MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT = 10047; // 0x273f
field public static final int MEASUREMENT_UPTIME_BATTERY_MS = 10002; // 0x2712
field public static final int MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS = 10004; // 0x2714
- field public static final int MEASUREMENT_USER_CPU_TIME_US = 10062; // 0x274e
+ field public static final int MEASUREMENT_USER_CPU_TIME_MS = 10062; // 0x274e
field public static final int MEASUREMENT_WIFI_FULL_LOCK_MS = 10029; // 0x272d
field public static final int MEASUREMENT_WIFI_IDLE_MS = 10016; // 0x2720
field public static final int MEASUREMENT_WIFI_MULTICAST_MS = 10031; // 0x272f
diff --git a/core/java/android/os/health/UidHealthStats.java b/core/java/android/os/health/UidHealthStats.java
index c7d257f..337235a 100644
--- a/core/java/android/os/health/UidHealthStats.java
+++ b/core/java/android/os/health/UidHealthStats.java
@@ -261,16 +261,16 @@
public static final int TIMER_MOBILE_RADIO_ACTIVE = HealthKeys.BASE_UID + 61;
@HealthKeys.Constant(type=HealthKeys.TYPE_MEASUREMENT)
- public static final int MEASUREMENT_USER_CPU_TIME_US = HealthKeys.BASE_UID + 62;
+ public static final int MEASUREMENT_USER_CPU_TIME_MS = HealthKeys.BASE_UID + 62;
@HealthKeys.Constant(type=HealthKeys.TYPE_MEASUREMENT)
- public static final int MEASUREMENT_SYSTEM_CPU_TIME_US = HealthKeys.BASE_UID + 63;
+ public static final int MEASUREMENT_SYSTEM_CPU_TIME_MS = HealthKeys.BASE_UID + 63;
/**
* An estimate of the number of milliamp-microsends used by this uid.
*/
@HealthKeys.Constant(type=HealthKeys.TYPE_MEASUREMENT)
- public static final int MEASUREMENT_CPU_POWER_MAUS = HealthKeys.BASE_UID + 64;
+ public static final int MEASUREMENT_CPU_POWER_MAMS = HealthKeys.BASE_UID + 64;
/**
* @hide
diff --git a/services/core/java/com/android/server/am/HealthStatsBatteryStatsWriter.java b/services/core/java/com/android/server/am/HealthStatsBatteryStatsWriter.java
index 9fb51c1..4a87941 100644
--- a/services/core/java/com/android/server/am/HealthStatsBatteryStatsWriter.java
+++ b/services/core/java/com/android/server/am/HealthStatsBatteryStatsWriter.java
@@ -35,12 +35,12 @@
public class HealthStatsBatteryStatsWriter {
- private final long mNowRealtime;
- private final long mNowUptime;
+ private final long mNowRealtimeMs;
+ private final long mNowUptimeMs;
public HealthStatsBatteryStatsWriter() {
- mNowRealtime = SystemClock.elapsedRealtime();
- mNowUptime = SystemClock.uptimeMillis();
+ mNowRealtimeMs = SystemClock.elapsedRealtime();
+ mNowUptimeMs = SystemClock.uptimeMillis();
}
/**
@@ -62,19 +62,20 @@
// MEASUREMENT_REALTIME_BATTERY_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS,
- bs.computeBatteryRealtime(mNowRealtime*1000, STATS_SINCE_UNPLUGGED)/1000);
+ bs.computeBatteryRealtime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// MEASUREMENT_UPTIME_BATTERY_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_BATTERY_MS,
- bs.computeBatteryUptime(mNowUptime*1000, STATS_SINCE_UNPLUGGED)/1000);
+ bs.computeBatteryUptime(mNowUptimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS,
- bs.computeBatteryScreenOffRealtime(mNowRealtime*1000, STATS_SINCE_UNPLUGGED)/1000);
+ bs.computeBatteryScreenOffRealtime(
+ mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS,
- bs.computeBatteryScreenOffUptime(mNowUptime*1000, STATS_SINCE_UNPLUGGED)/1000);
+ bs.computeBatteryScreenOffUptime(mNowUptimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
//
// Now on to the real per-uid stats...
@@ -214,20 +215,20 @@
// MEASUREMENT_WIFI_RUNNING_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RUNNING_MS,
- uid.getWifiRunningTime(mNowRealtime, STATS_SINCE_UNPLUGGED));
+ uid.getWifiRunningTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// MEASUREMENT_WIFI_FULL_LOCK_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_FULL_LOCK_MS,
- uid.getFullWifiLockTime(mNowRealtime, STATS_SINCE_UNPLUGGED));
+ uid.getFullWifiLockTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// TIMER_WIFI_SCAN
uidWriter.addTimer(UidHealthStats.TIMER_WIFI_SCAN,
uid.getWifiScanCount(STATS_SINCE_UNPLUGGED),
- uid.getWifiScanTime(mNowRealtime, STATS_SINCE_UNPLUGGED));
+ uid.getWifiScanTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// MEASUREMENT_WIFI_MULTICAST_MS
uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_MULTICAST_MS,
- uid.getWifiMulticastTime(mNowRealtime, STATS_SINCE_UNPLUGGED));
+ uid.getWifiMulticastTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000);
// TIMER_AUDIO
addTimer(uidWriter, UidHealthStats.TIMER_AUDIO, uid.getAudioTurnedOnTimer());
@@ -355,17 +356,17 @@
uid.getMobileRadioActiveCount(STATS_SINCE_UNPLUGGED),
uid.getMobileRadioActiveTime(STATS_SINCE_UNPLUGGED));
- // MEASUREMENT_USER_CPU_TIME_US
- uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_US,
- uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED));
+ // MEASUREMENT_USER_CPU_TIME_MS
+ uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_MS,
+ uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED)/1000);
- // MEASUREMENT_SYSTEM_CPU_TIME_US
- uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_US,
- uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED));
+ // MEASUREMENT_SYSTEM_CPU_TIME_MS
+ uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_MS,
+ uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED)/1000);
- // MEASUREMENT_CPU_POWER_MAUS
- uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAUS,
- uid.getCpuPowerMaUs(STATS_SINCE_UNPLUGGED));
+ // MEASUREMENT_CPU_POWER_MAMS
+ uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAMS,
+ uid.getCpuPowerMaUs(STATS_SINCE_UNPLUGGED)/1000);
}
/**
@@ -457,7 +458,7 @@
private void addTimer(HealthStatsWriter writer, int key, BatteryStats.Timer timer) {
if (timer != null) {
writer.addTimer(key, timer.getCountLocked(STATS_SINCE_UNPLUGGED),
- timer.getTotalTimeLocked(mNowRealtime, STATS_SINCE_UNPLUGGED));
+ timer.getTotalTimeLocked(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED) / 1000);
}
}
@@ -468,7 +469,7 @@
BatteryStats.Timer timer) {
if (timer != null) {
writer.addTimers(key, name, new TimerStat(timer.getCountLocked(STATS_SINCE_UNPLUGGED),
- timer.getTotalTimeLocked(mNowRealtime, STATS_SINCE_UNPLUGGED)));
+ timer.getTotalTimeLocked(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED) / 1000));
}
}
}