1713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato/* 2713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Copyright (C) 2016 The Android Open Source Project 3713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * 4713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Licensed under the Apache License, Version 2.0 (the "License"); 5713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * you may not use this file except in compliance with the License. 6713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * You may obtain a copy of the License at 7713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * 8713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * http://www.apache.org/licenses/LICENSE-2.0 9713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * 10713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Unless required by applicable law or agreed to in writing, software 11713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * distributed under the License is distributed on an "AS IS" BASIS, 12713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * See the License for the specific language governing permissions and 14713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * limitations under the License. 15713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 16713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 17713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratopackage com.android.server.am; 18713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 19713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.BatteryStats; 20713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport static android.os.BatteryStats.STATS_SINCE_UNPLUGGED; 21713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.PowerManager; 22713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.SystemClock; 23713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.HealthKeys; 24713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.HealthStatsParceler; 25713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.HealthStatsWriter; 26713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.PackageHealthStats; 27713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.ProcessHealthStats; 28713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.PidHealthStats; 29713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.ServiceHealthStats; 30713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.TimerStat; 31713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.health.UidHealthStats; 32713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.util.SparseArray; 33713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 34713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport java.util.Map; 35713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 36713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratopublic class HealthStatsBatteryStatsWriter { 37713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 38bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato private final long mNowRealtimeMs; 39bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato private final long mNowUptimeMs; 40713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 41713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public HealthStatsBatteryStatsWriter() { 42bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato mNowRealtimeMs = SystemClock.elapsedRealtime(); 43bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato mNowUptimeMs = SystemClock.uptimeMillis(); 44713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 45713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 46713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 47713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Writes the contents of a BatteryStats.Uid into a HealthStatsWriter. 48713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 49d4abd1eeb01187fa2ef78b64ae4f493a7bb3563fAdam Lesinski @SuppressWarnings("deprecation") 50713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public void writeUid(HealthStatsWriter uidWriter, BatteryStats bs, BatteryStats.Uid uid) { 51713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato int N; 52713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato BatteryStats.Timer timer; 53713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato SparseArray<? extends BatteryStats.Uid.Sensor> sensors; 54713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato SparseArray<? extends BatteryStats.Uid.Pid> pids; 55713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato BatteryStats.ControllerActivityCounter controller; 56713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato long sum; 57713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 58713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // 59713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // It's a little odd for these first four to be here but it's not the end of the 60713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // world. It would be easy enough to duplicate them somewhere else if this API 61713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // grows. 62713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // 63713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 64713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_REALTIME_BATTERY_MS 65713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 66bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato bs.computeBatteryRealtime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 67713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 68713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_UPTIME_BATTERY_MS 69713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_BATTERY_MS, 70bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato bs.computeBatteryUptime(mNowUptimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 71713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 72713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS 73713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS, 74bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato bs.computeBatteryScreenOffRealtime( 75bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 76713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 77713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS 78713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS, 79bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato bs.computeBatteryScreenOffUptime(mNowUptimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 80713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 81713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // 82713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // Now on to the real per-uid stats... 83713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // 84713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 85713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Uid.Wakelock> entry: 86713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getWakelockStats().entrySet()) { 87713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final String key = entry.getKey(); 88713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final BatteryStats.Uid.Wakelock wakelock = entry.getValue(); 89713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 90713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_WAKELOCKS_FULL 91713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_FULL); 92713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_FULL, key, timer); 93713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 94713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_WAKELOCKS_PARTIAL 95713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL); 96713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_PARTIAL, key, timer); 97713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 98713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_WAKELOCKS_WINDOW 99713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_WINDOW); 100713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_WINDOW, key, timer); 101713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 102713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_WAKELOCKS_DRAW 103713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_DRAW); 104713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_DRAW, key, timer); 105713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 106713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 107713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_SYNCS 108713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Timer> entry: 109713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getSyncStats().entrySet()) { 110713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_SYNCS, entry.getKey(), entry.getValue()); 111713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 112713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 113713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_JOBS 114713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Timer> entry: 115713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getJobStats().entrySet()) { 116713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_JOBS, entry.getKey(), entry.getValue()); 117713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 118713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 119713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMERS_SENSORS 120713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sensors = uid.getSensorStats(); 121713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato N = sensors.size(); 122713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (int i=0; i<N; i++) { 123713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato int sensorId = sensors.keyAt(i); 124713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // Battery Stats stores the GPS sensors with a bogus key in this API. Pull it out 125713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // as a separate metric here so as to not expose that in the API. 126713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (sensorId == BatteryStats.Uid.Sensor.GPS) { 127a2f003bc3cbc916660921b3bb3aee93307c3ce7eJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_GPS_SENSOR, 128a2f003bc3cbc916660921b3bb3aee93307c3ce7eJoe Onorato sensors.valueAt(i).getSensorTime()); 129713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } else { 130713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimers(uidWriter, UidHealthStats.TIMERS_SENSORS, Integer.toString(sensorId), 131713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sensors.valueAt(i).getSensorTime()); 132713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 133713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 134713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 135713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // STATS_PIDS 136713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pids = uid.getPidStats(); 137a2f003bc3cbc916660921b3bb3aee93307c3ce7eJoe Onorato N = pids.size(); 138713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (int i=0; i<N; i++) { 139713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final HealthStatsWriter writer = new HealthStatsWriter(PidHealthStats.CONSTANTS); 140713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writePid(writer, pids.valueAt(i)); 141713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addStats(UidHealthStats.STATS_PIDS, Integer.toString(pids.keyAt(i)), writer); 142713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 143713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 144713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // STATS_PROCESSES 145713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Uid.Proc> entry: 146713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStats().entrySet()) { 147713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final HealthStatsWriter writer = new HealthStatsWriter(ProcessHealthStats.CONSTANTS); 148713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writeProc(writer, entry.getValue()); 149713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addStats(UidHealthStats.STATS_PROCESSES, entry.getKey(), writer); 150713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 151713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 152713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // STATS_PACKAGES 153713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Uid.Pkg> entry: 154713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getPackageStats().entrySet()) { 155713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final HealthStatsWriter writer = new HealthStatsWriter(PackageHealthStats.CONSTANTS); 156713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writePkg(writer, entry.getValue()); 157713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addStats(UidHealthStats.STATS_PACKAGES, entry.getKey(), writer); 158713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 159713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 160713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller = uid.getWifiControllerActivity(); 161713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (controller != null) { 162713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_IDLE_MS 163713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_IDLE_MS, 164713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 165713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_RX_MS 166713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_MS, 167713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 168713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_TX_MS 169713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum = 0; 170713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final BatteryStats.LongCounter counter: controller.getTxTimeCounters()) { 171713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED); 172713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 173713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_MS, sum); 174713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_POWER_MAMS 175713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_POWER_MAMS, 176713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 177713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 178713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 179713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller = uid.getBluetoothControllerActivity(); 180713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (controller != null) { 181713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_IDLE_MS 182713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_IDLE_MS, 183713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 184713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_RX_MS 185713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_MS, 186713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 187713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_TX_MS 188713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum = 0; 189713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final BatteryStats.LongCounter counter: controller.getTxTimeCounters()) { 190713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED); 191713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 192713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_MS, sum); 193713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_POWER_MAMS 194713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_POWER_MAMS, 195713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 196713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 197713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 198713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller = uid.getModemControllerActivity(); 199713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (controller != null) { 200713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_IDLE_MS 201713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_IDLE_MS, 202713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 203713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_RX_MS 204713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_MS, 205713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 206713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_TX_MS 207713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum = 0; 208713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final BatteryStats.LongCounter counter: controller.getTxTimeCounters()) { 209713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED); 210713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 211713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_MS, sum); 212713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_POWER_MAMS 213713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_POWER_MAMS, 214713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED)); 215713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 216713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 217713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_RUNNING_MS 218713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RUNNING_MS, 219bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getWifiRunningTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 220713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 221713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_FULL_LOCK_MS 222713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_FULL_LOCK_MS, 223bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getFullWifiLockTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 224713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 225713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_WIFI_SCAN 226713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addTimer(UidHealthStats.TIMER_WIFI_SCAN, 227713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getWifiScanCount(STATS_SINCE_UNPLUGGED), 228bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getWifiScanTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 229713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 230713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_MULTICAST_MS 231713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_MULTICAST_MS, 232bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getWifiMulticastTime(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED)/1000); 233713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 234713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_AUDIO 235713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_AUDIO, uid.getAudioTurnedOnTimer()); 236713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 237713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_VIDEO 238713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_VIDEO, uid.getVideoTurnedOnTimer()); 239713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 240713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_FLASHLIGHT 241713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_FLASHLIGHT, uid.getFlashlightTurnedOnTimer()); 242713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 243713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_CAMERA 244713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_CAMERA, uid.getCameraTurnedOnTimer()); 245713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 246713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_FOREGROUND_ACTIVITY 247a2f003bc3cbc916660921b3bb3aee93307c3ce7eJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_FOREGROUND_ACTIVITY, 248a2f003bc3cbc916660921b3bb3aee93307c3ce7eJoe Onorato uid.getForegroundActivityTimer()); 249713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 250713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_BLUETOOTH_SCAN 251713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_BLUETOOTH_SCAN, uid.getBluetoothScanTimer()); 252713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 253713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_TOP_MS 254713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_MS, 255713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP)); 256713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 257713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS 258713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS, 259713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE)); 260713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 261713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_TOP_SLEEPING_MS 262713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_SLEEPING_MS, 263713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING)); 264713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 265713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_FOREGROUND_MS 266713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_MS, 267713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND)); 268713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 269713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_BACKGROUND_MS 270713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_BACKGROUND_MS, 271713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_BACKGROUND)); 272713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 273713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_PROCESS_STATE_CACHED_MS 274713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_CACHED_MS, 275713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_CACHED)); 276713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 277713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_VIBRATOR 278713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato addTimer(uidWriter, UidHealthStats.TIMER_VIBRATOR, uid.getVibratorOnTimer()); 279713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 280713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_OTHER_USER_ACTIVITY_COUNT 281713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_OTHER_USER_ACTIVITY_COUNT, 282713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_OTHER, 283713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 284713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 285713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT 286713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT, 287713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_BUTTON, 288713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 289713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 290713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT 291713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT, 292713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_TOUCH, 293713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 294713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 295713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_RX_BYTES 296713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_BYTES, 297713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_RX_DATA, 298713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 299713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 300713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_TX_BYTES 301713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_BYTES, 302713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_TX_DATA, 303713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 304713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 305713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_RX_BYTES 306713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_BYTES, 307713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_RX_DATA, 308713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 309713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 310713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_TX_BYTES 311713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_BYTES, 312713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_TX_DATA, 313713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 314713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 315713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_RX_BYTES 316713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_BYTES, 317713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_RX_DATA, 318713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 319713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 320713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_TX_BYTES 321713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_BYTES, 322713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_TX_DATA, 323713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 324713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 325713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_RX_PACKETS 326713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS, 327713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_RX_DATA, 328713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 329713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 330713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_MOBILE_TX_PACKETS 331713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_PACKETS, 332713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_TX_DATA, 333713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 334713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 335713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_RX_PACKETS 336713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_PACKETS, 337713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_RX_DATA, 338713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 339713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 340713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WIFI_TX_PACKETS 341713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_PACKETS, 342713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_TX_DATA, 343713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 344713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 345713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_RX_PACKETS 346713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_PACKETS, 347713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_RX_DATA, 348713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 349713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 350713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_BLUETOOTH_TX_PACKETS 351713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_PACKETS, 352713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_TX_DATA, 353713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato STATS_SINCE_UNPLUGGED)); 354713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 355713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // TIMER_MOBILE_RADIO_ACTIVE 356713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uidWriter.addTimer(UidHealthStats.TIMER_MOBILE_RADIO_ACTIVE, 357713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getMobileRadioActiveCount(STATS_SINCE_UNPLUGGED), 358713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato uid.getMobileRadioActiveTime(STATS_SINCE_UNPLUGGED)); 359713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 360bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato // MEASUREMENT_USER_CPU_TIME_MS 361bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_MS, 362bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED)/1000); 363713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 364bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato // MEASUREMENT_SYSTEM_CPU_TIME_MS 365bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_MS, 366bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED)/1000); 367713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 368bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato // MEASUREMENT_CPU_POWER_MAMS 369d4abd1eeb01187fa2ef78b64ae4f493a7bb3563fAdam Lesinski uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAMS, 0); 370713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 371713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 372713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 373713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Writes the contents of a BatteryStats.Uid.Pid into a HealthStatsWriter. 374713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 375713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public void writePid(HealthStatsWriter pidWriter, BatteryStats.Uid.Pid pid) { 376713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (pid == null) { 377713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato return; 378713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 379713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 380713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WAKE_NESTING_COUNT 381713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pidWriter.addMeasurement(PidHealthStats.MEASUREMENT_WAKE_NESTING_COUNT, pid.mWakeNesting); 382713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 383713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WAKE_SUM_MS 384713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pidWriter.addMeasurement(PidHealthStats.MEASUREMENT_WAKE_SUM_MS, pid.mWakeSumMs); 385713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 386713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_WAKE_START_MS 387713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pidWriter.addMeasurement(PidHealthStats.MEASUREMENT_WAKE_SUM_MS, pid.mWakeStartMs); 388713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 389713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 390713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 391713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Writes the contents of a BatteryStats.Uid.Proc into a HealthStatsWriter. 392713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 393713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public void writeProc(HealthStatsWriter procWriter, BatteryStats.Uid.Proc proc) { 394713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_USER_TIME_MS 395713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_USER_TIME_MS, 396713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getUserTime(STATS_SINCE_UNPLUGGED)); 397713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 398713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_SYSTEM_TIME_MS 399713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_SYSTEM_TIME_MS, 400713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getSystemTime(STATS_SINCE_UNPLUGGED)); 401713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 402713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_STARTS_COUNT 403713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_STARTS_COUNT, 404713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getStarts(STATS_SINCE_UNPLUGGED)); 405713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 406713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_CRASHES_COUNT 407713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_CRASHES_COUNT, 408713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getNumCrashes(STATS_SINCE_UNPLUGGED)); 409713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 410713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_ANR_COUNT 411713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_ANR_COUNT, 412713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getNumAnrs(STATS_SINCE_UNPLUGGED)); 413713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 414713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_FOREGROUND_MS 415713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato procWriter.addMeasurement(ProcessHealthStats.MEASUREMENT_FOREGROUND_MS, 416713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato proc.getForegroundTime(STATS_SINCE_UNPLUGGED)); 417713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 418713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 419713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 420713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Writes the contents of a BatteryStats.Uid.Pkg into a HealthStatsWriter. 421713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 422713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public void writePkg(HealthStatsWriter pkgWriter, BatteryStats.Uid.Pkg pkg) { 423713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // STATS_SERVICES 424713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Uid.Pkg.Serv> entry: 425713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pkg.getServiceStats().entrySet()) { 426713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final HealthStatsWriter writer = new HealthStatsWriter(ServiceHealthStats.CONSTANTS); 427713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writeServ(writer, entry.getValue()); 428713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pkgWriter.addStats(PackageHealthStats.STATS_SERVICES, entry.getKey(), writer); 429713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 430713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 431713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENTS_WAKEUP_ALARMS_COUNT 432713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato for (final Map.Entry<String,? extends BatteryStats.Counter> entry: 433713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pkg.getWakeupAlarmStats().entrySet()) { 434713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato final BatteryStats.Counter counter = entry.getValue(); 435713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (counter != null) { 436713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato pkgWriter.addMeasurements(PackageHealthStats.MEASUREMENTS_WAKEUP_ALARMS_COUNT, 437713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato entry.getKey(), counter.getCountLocked(STATS_SINCE_UNPLUGGED)); 438713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 439713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 440713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 441713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 442713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 443713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Writes the contents of a BatteryStats.Uid.Pkg.Serv into a HealthStatsWriter. 444713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 445713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato public void writeServ(HealthStatsWriter servWriter, BatteryStats.Uid.Pkg.Serv serv) { 446713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_START_SERVICE_COUNT 447713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato servWriter.addMeasurement(ServiceHealthStats.MEASUREMENT_START_SERVICE_COUNT, 448713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato serv.getStarts(STATS_SINCE_UNPLUGGED)); 449713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 450713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato // MEASUREMENT_LAUNCH_COUNT 451713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato servWriter.addMeasurement(ServiceHealthStats.MEASUREMENT_LAUNCH_COUNT, 452713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato serv.getLaunches(STATS_SINCE_UNPLUGGED)); 453713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 454713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 455713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 456713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Adds a BatteryStats.Timer into a HealthStatsWriter. Safe to pass a null timer. 457713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 458713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato private void addTimer(HealthStatsWriter writer, int key, BatteryStats.Timer timer) { 459713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (timer != null) { 460713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writer.addTimer(key, timer.getCountLocked(STATS_SINCE_UNPLUGGED), 461bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato timer.getTotalTimeLocked(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED) / 1000); 462713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 463713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 464713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 465713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato /** 466713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Adds a named BatteryStats.Timer into a HealthStatsWriter. Safe to pass a null timer. 467713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */ 468713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato private void addTimers(HealthStatsWriter writer, int key, String name, 469713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato BatteryStats.Timer timer) { 470713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato if (timer != null) { 471713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato writer.addTimers(key, name, new TimerStat(timer.getCountLocked(STATS_SINCE_UNPLUGGED), 472bee44ae8e5da109cd8273a057b566dc6925d6a71Joe Onorato timer.getTotalTimeLocked(mNowRealtimeMs*1000, STATS_SINCE_UNPLUGGED) / 1000)); 473713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 474713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato } 475713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato} 476713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato 477