Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 19 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 22 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 23 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 24 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 25 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 26 | import android.util.MutableBoolean; |
| 27 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.util.Printer; |
| 29 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 30 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 31 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 32 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 33 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 34 | import com.android.internal.os.BatterySipper; |
| 35 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 37 | import java.io.PrintWriter; |
| 38 | import java.util.ArrayList; |
| 39 | import java.util.Collections; |
| 40 | import java.util.Comparator; |
| 41 | import java.util.Formatter; |
| 42 | import java.util.HashMap; |
| 43 | import java.util.List; |
| 44 | import java.util.Map; |
| 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | /** |
| 47 | * A class providing access to battery usage statistics, including information on |
| 48 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 49 | * except where indicated otherwise. |
| 50 | * @hide |
| 51 | */ |
| 52 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 53 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| 55 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 56 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 57 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 58 | |
| 59 | /** @hide */ |
| 60 | public static final String SERVICE_NAME = "batterystats"; |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
| 63 | * A constant indicating a partial wake lock timer. |
| 64 | */ |
| 65 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 66 | |
| 67 | /** |
| 68 | * A constant indicating a full wake lock timer. |
| 69 | */ |
| 70 | public static final int WAKE_TYPE_FULL = 1; |
| 71 | |
| 72 | /** |
| 73 | * A constant indicating a window wake lock timer. |
| 74 | */ |
| 75 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | /** |
| 78 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | */ |
| 80 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 81 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 82 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 83 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 84 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 85 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 86 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 87 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 88 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 89 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 90 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 91 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 92 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 93 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 94 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 95 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 97 | /** |
| 98 | * A constant indicating a wifi multicast timer |
| 99 | */ |
| 100 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 103 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 104 | */ |
| 105 | public static final int VIDEO_TURNED_ON = 8; |
| 106 | |
| 107 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 108 | * A constant indicating a vibrator on timer |
| 109 | */ |
| 110 | public static final int VIBRATOR_ON = 9; |
| 111 | |
| 112 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 113 | * A constant indicating a foreground activity timer |
| 114 | */ |
| 115 | public static final int FOREGROUND_ACTIVITY = 10; |
| 116 | |
| 117 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 118 | * A constant indicating a wifi batched scan is active |
| 119 | */ |
| 120 | public static final int WIFI_BATCHED_SCAN = 11; |
| 121 | |
| 122 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 123 | * A constant indicating a process state timer |
| 124 | */ |
| 125 | public static final int PROCESS_STATE = 12; |
| 126 | |
| 127 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 128 | * A constant indicating a sync timer |
| 129 | */ |
| 130 | public static final int SYNC = 13; |
| 131 | |
| 132 | /** |
| 133 | * A constant indicating a job timer |
| 134 | */ |
| 135 | public static final int JOB = 14; |
| 136 | |
| 137 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 138 | * A constant indicating an audio turn on timer |
| 139 | */ |
| 140 | public static final int AUDIO_TURNED_ON = 15; |
| 141 | |
| 142 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 143 | * A constant indicating a flashlight turn on timer |
| 144 | */ |
| 145 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 146 | |
| 147 | /** |
| 148 | * A constant indicating a camera turn on timer |
| 149 | */ |
| 150 | public static final int CAMERA_TURNED_ON = 17; |
| 151 | |
| 152 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 153 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 154 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 155 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 158 | * A constant indicating a bluetooth scan timer. |
| 159 | */ |
| 160 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 161 | |
| 162 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 163 | * A constant indicating an aggregated partial wake lock timer. |
| 164 | */ |
| 165 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 166 | |
| 167 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 168 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 169 | */ |
| 170 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 171 | |
| 172 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 173 | * A constant indicating a foreground service timer |
| 174 | */ |
| 175 | public static final int FOREGROUND_SERVICE = 22; |
| 176 | |
| 177 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | * Include all of the data in the stats, including previously saved data. |
| 179 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 180 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
| 182 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | * Include only the current run in the stats. |
| 184 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 185 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Include only the run since the last time the device was unplugged in the stats. |
| 189 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 190 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 191 | |
| 192 | // NOTE: Update this list if you add/change any stats above. |
| 193 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 194 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 195 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 198 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 199 | * |
| 200 | * New in version 19: |
| 201 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 202 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 203 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 204 | * New in version 21: |
| 205 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 206 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 207 | * - BLE scan result count |
| 208 | * - CPU frequency time per uid |
| 209 | * New in version 22: |
| 210 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 211 | * - Background partial wakelock time & count |
| 212 | * New in version 23: |
| 213 | * - Logging smeared power model values |
| 214 | * New in version 24: |
| 215 | * - Fixed bugs in background timers and BLE scan time |
| 216 | * New in version 25: |
| 217 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 218 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 219 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 220 | * New in version 27: |
| 221 | * - Always On Display (screen doze mode) time and power |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 222 | */ |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 223 | static final String CHECKIN_VERSION = "27"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Old version, we hit 9 and ran out of room, need to remove. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 228 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 229 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 230 | private static final long BYTES_PER_KB = 1024; |
| 231 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 232 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 233 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 234 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 235 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 236 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 238 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 239 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 240 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 241 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 242 | // rpm line is: |
| 243 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 244 | // screen-off time, screen-off count |
| 245 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 246 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 247 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 248 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 249 | // fgs line is: |
| 250 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 251 | // foreground service time, count |
| 252 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 253 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 254 | // wl line is: |
| 255 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 256 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 257 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 258 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 259 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 260 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 261 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 262 | // awl line is: |
| 263 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 264 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 265 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 266 | private static final String SYNC_DATA = "sy"; |
| 267 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 268 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 269 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 270 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 271 | private static final String NETWORK_DATA = "nt"; |
| 272 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 273 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 274 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 275 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 276 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 277 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 278 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 279 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 280 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 281 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 282 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 283 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 284 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 285 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 286 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 287 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 288 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 289 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 290 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 291 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 292 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 293 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 294 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 295 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 296 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 297 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 298 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 299 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 300 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 301 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 302 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 303 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 304 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 305 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 306 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 307 | private static final String FLASHLIGHT_DATA = "fla"; |
| 308 | private static final String CAMERA_DATA = "cam"; |
| 309 | private static final String VIDEO_DATA = "vid"; |
| 310 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 312 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 313 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 314 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 316 | |
| 317 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 318 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 319 | * |
| 320 | * Other types might include times spent in foreground, background etc. |
| 321 | */ |
| 322 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 323 | |
| 324 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 325 | * State for keeping track of counting information. |
| 326 | */ |
| 327 | public static abstract class Counter { |
| 328 | |
| 329 | /** |
| 330 | * Returns the count associated with this Counter for the |
| 331 | * selected type of statistics. |
| 332 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 333 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 334 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 335 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Temporary for debugging. |
| 339 | */ |
| 340 | public abstract void logState(Printer pw, String prefix); |
| 341 | } |
| 342 | |
| 343 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 344 | * State for keeping track of long counting information. |
| 345 | */ |
| 346 | public static abstract class LongCounter { |
| 347 | |
| 348 | /** |
| 349 | * Returns the count associated with this Counter for the |
| 350 | * selected type of statistics. |
| 351 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 352 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 353 | */ |
| 354 | public abstract long getCountLocked(int which); |
| 355 | |
| 356 | /** |
| 357 | * Temporary for debugging. |
| 358 | */ |
| 359 | public abstract void logState(Printer pw, String prefix); |
| 360 | } |
| 361 | |
| 362 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 363 | * State for keeping track of array of long counting information. |
| 364 | */ |
| 365 | public static abstract class LongCounterArray { |
| 366 | /** |
| 367 | * Returns the counts associated with this Counter for the |
| 368 | * selected type of statistics. |
| 369 | * |
| 370 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 371 | */ |
| 372 | public abstract long[] getCountsLocked(int which); |
| 373 | |
| 374 | /** |
| 375 | * Temporary for debugging. |
| 376 | */ |
| 377 | public abstract void logState(Printer pw, String prefix); |
| 378 | } |
| 379 | |
| 380 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 381 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 382 | * radio controller. |
| 383 | */ |
| 384 | public static abstract class ControllerActivityCounter { |
| 385 | /** |
| 386 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 387 | * idle state. |
| 388 | */ |
| 389 | public abstract LongCounter getIdleTimeCounter(); |
| 390 | |
| 391 | /** |
| 392 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 393 | * receive state. |
| 394 | */ |
| 395 | public abstract LongCounter getRxTimeCounter(); |
| 396 | |
| 397 | /** |
| 398 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 399 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 400 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 401 | * various transmit level states. |
| 402 | */ |
| 403 | public abstract LongCounter[] getTxTimeCounters(); |
| 404 | |
| 405 | /** |
| 406 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 407 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 408 | * yield a value of 0 if the device doesn't support power calculations. |
| 409 | */ |
| 410 | public abstract LongCounter getPowerCounter(); |
| 411 | } |
| 412 | |
| 413 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | * State for keeping track of timing information. |
| 415 | */ |
| 416 | public static abstract class Timer { |
| 417 | |
| 418 | /** |
| 419 | * Returns the count associated with this Timer for the |
| 420 | * selected type of statistics. |
| 421 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 422 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 424 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | |
| 426 | /** |
| 427 | * Returns the total time in microseconds associated with this Timer for the |
| 428 | * selected type of statistics. |
| 429 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 430 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 431 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | * @return a time in microseconds |
| 433 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 434 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 437 | * Returns the total time in microseconds associated with this Timer since the |
| 438 | * 'mark' was last set. |
| 439 | * |
| 440 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 441 | * @return a time in microseconds |
| 442 | */ |
| 443 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 444 | |
| 445 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 446 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 447 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 448 | |
| 449 | */ |
| 450 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 451 | return -1; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Returns the current time the timer has been active, if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 456 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 457 | */ |
| 458 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 459 | return -1; |
| 460 | } |
| 461 | |
| 462 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 463 | * Returns the current time the timer has been active, if it is being tracked. |
| 464 | * |
| 465 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 466 | * been on since reset. |
| 467 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 468 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 469 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 470 | * the actual total time. |
| 471 | * Not all Timer subclasses track the max, total, current durations. |
| 472 | */ |
| 473 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 474 | return -1; |
| 475 | } |
| 476 | |
| 477 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 478 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 479 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 480 | * |
| 481 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 482 | */ |
| 483 | public Timer getSubTimer() { |
| 484 | return null; |
| 485 | } |
| 486 | |
| 487 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 488 | * Returns whether the timer is currently running. Some types of timers |
| 489 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 490 | * and report false. |
| 491 | */ |
| 492 | public boolean isRunningLocked() { |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | * Temporary for debugging. |
| 498 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 499 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
| 503 | * The statistics associated with a particular uid. |
| 504 | */ |
| 505 | public static abstract class Uid { |
| 506 | |
| 507 | /** |
| 508 | * Returns a mapping containing wakelock statistics. |
| 509 | * |
| 510 | * @return a Map from Strings to Uid.Wakelock objects. |
| 511 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 512 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | |
| 514 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 515 | * Returns a mapping containing sync statistics. |
| 516 | * |
| 517 | * @return a Map from Strings to Timer objects. |
| 518 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 519 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 520 | |
| 521 | /** |
| 522 | * Returns a mapping containing scheduled job statistics. |
| 523 | * |
| 524 | * @return a Map from Strings to Timer objects. |
| 525 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 526 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 527 | |
| 528 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 529 | * Returns statistics about how jobs have completed. |
| 530 | * |
| 531 | * @return A Map of String job names to completion type -> count mapping. |
| 532 | */ |
| 533 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 534 | |
| 535 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | * The statistics associated with a particular wake lock. |
| 537 | */ |
| 538 | public static abstract class Wakelock { |
| 539 | public abstract Timer getWakeTime(int type); |
| 540 | } |
| 541 | |
| 542 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 543 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 544 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 545 | * wakelocks that overlap in time (and therefore over-counts). |
| 546 | */ |
| 547 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 548 | |
| 549 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | * Returns a mapping containing sensor statistics. |
| 551 | * |
| 552 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 553 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 554 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | |
| 556 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 557 | * Returns a mapping containing active process data. |
| 558 | */ |
| 559 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 560 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 561 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | * Returns a mapping containing process statistics. |
| 563 | * |
| 564 | * @return a Map from Strings to Uid.Proc objects. |
| 565 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 566 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | |
| 568 | /** |
| 569 | * Returns a mapping containing package statistics. |
| 570 | * |
| 571 | * @return a Map from Strings to Uid.Pkg objects. |
| 572 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 573 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 574 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 575 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 576 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 577 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 578 | |
| 579 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | * {@hide} |
| 581 | */ |
| 582 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 583 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 584 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 585 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 586 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 587 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 588 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 589 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 590 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 591 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 592 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 593 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 594 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 595 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 596 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 597 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 598 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 599 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 600 | public abstract int getWifiScanBackgroundCount(int which); |
| 601 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 602 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 603 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 604 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 605 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 606 | public abstract Timer getAudioTurnedOnTimer(); |
| 607 | public abstract Timer getVideoTurnedOnTimer(); |
| 608 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 609 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 610 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * Returns the timer keeping track of Foreground Service time |
| 614 | */ |
| 615 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 616 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 617 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 618 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 619 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 620 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 621 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 622 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 623 | public abstract long[] getCpuFreqTimes(int which); |
| 624 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 625 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 626 | // Note: the following times are disjoint. They can be added together to find the |
| 627 | // total time a uid has had any processes running at all. |
| 628 | |
| 629 | /** |
| 630 | * Time this uid has any processes in the top state (or above such as persistent). |
| 631 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 632 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 633 | /** |
| 634 | * Time this uid has any process with a started out bound foreground service, but |
| 635 | * none in the "top" state. |
| 636 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 637 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 638 | /** |
| 639 | * Time this uid has any process that is top while the device is sleeping, but none |
| 640 | * in the "foreground service" or better state. |
| 641 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 642 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Time this uid has any process in an active foreground state, but none in the |
| 645 | * "top sleeping" or better state. |
| 646 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 647 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 648 | /** |
| 649 | * Time this uid has any process in an active background state, but none in the |
| 650 | * "foreground" or better state. |
| 651 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 652 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 653 | /** |
| 654 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 655 | * other active states. |
| 656 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 657 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 658 | /** |
| 659 | * Total number of process states we track. |
| 660 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 661 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 662 | |
| 663 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 664 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 668 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 669 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 670 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 672 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 673 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 674 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 675 | * Note that these must match the constants in android.os.PowerManager. |
| 676 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 677 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 678 | */ |
| 679 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 680 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 681 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 682 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 683 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 684 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 685 | public abstract void noteUserActivityLocked(int type); |
| 686 | public abstract boolean hasUserActivity(); |
| 687 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 688 | |
| 689 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 690 | public abstract long getNetworkActivityBytes(int type, int which); |
| 691 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 692 | public abstract long getMobileRadioActiveTime(int which); |
| 693 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 694 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 695 | /** |
| 696 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 697 | */ |
| 698 | public abstract long getUserCpuTimeUs(int which); |
| 699 | |
| 700 | /** |
| 701 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 702 | */ |
| 703 | public abstract long getSystemCpuTimeUs(int which); |
| 704 | |
| 705 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 706 | * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 707 | * given CPU cluster. |
| 708 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 709 | * @param step the index of the CPU speed. This is not the actual speed of the CPU. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 710 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 711 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 712 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 713 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 714 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 715 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 716 | /** |
| 717 | * Returns the number of times this UID woke up the Application Processor to |
| 718 | * process a mobile radio packet. |
| 719 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 720 | */ |
| 721 | public abstract long getMobileRadioApWakeupCount(int which); |
| 722 | |
| 723 | /** |
| 724 | * Returns the number of times this UID woke up the Application Processor to |
| 725 | * process a WiFi packet. |
| 726 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 727 | */ |
| 728 | public abstract long getWifiRadioApWakeupCount(int which); |
| 729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 731 | /* |
| 732 | * FIXME: it's not correct to use this magic value because it |
| 733 | * could clash with a sensor handle (which are defined by |
| 734 | * the sensor HAL, and therefore out of our control |
| 735 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | // Magic sensor number for the GPS. |
| 737 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 742 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 743 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 744 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 747 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 748 | public int mWakeNesting; |
| 749 | public long mWakeSumMs; |
| 750 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 751 | } |
| 752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | /** |
| 754 | * The statistics associated with a particular process. |
| 755 | */ |
| 756 | public static abstract class Proc { |
| 757 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 758 | public static class ExcessivePower { |
| 759 | public static final int TYPE_WAKE = 1; |
| 760 | public static final int TYPE_CPU = 2; |
| 761 | |
| 762 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 763 | public long overTime; |
| 764 | public long usedTime; |
| 765 | } |
| 766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 768 | * Returns true if this process is still active in the battery stats. |
| 769 | */ |
| 770 | public abstract boolean isActive(); |
| 771 | |
| 772 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 773 | * Returns the total time (in milliseconds) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 775 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | */ |
| 777 | public abstract long getUserTime(int which); |
| 778 | |
| 779 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 780 | * Returns the total time (in milliseconds) spent executing in system code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 782 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | */ |
| 784 | public abstract long getSystemTime(int which); |
| 785 | |
| 786 | /** |
| 787 | * Returns the number of times the process has been started. |
| 788 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 789 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | */ |
| 791 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 792 | |
| 793 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 794 | * Returns the number of times the process has crashed. |
| 795 | * |
| 796 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 797 | */ |
| 798 | public abstract int getNumCrashes(int which); |
| 799 | |
| 800 | /** |
| 801 | * Returns the number of times the process has ANRed. |
| 802 | * |
| 803 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 804 | */ |
| 805 | public abstract int getNumAnrs(int which); |
| 806 | |
| 807 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 808 | * Returns the cpu time (milliseconds) spent while the process was in the foreground. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 809 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 810 | * @return foreground cpu time in microseconds |
| 811 | */ |
| 812 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 813 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 814 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 815 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 816 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | /** |
| 820 | * The statistics associated with a particular package. |
| 821 | */ |
| 822 | public static abstract class Pkg { |
| 823 | |
| 824 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 825 | * Returns information about all wakeup alarms that have been triggered for this |
| 826 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 827 | * the number of times the alarm was triggered while on battery. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 829 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | |
| 831 | /** |
| 832 | * Returns a mapping containing service statistics. |
| 833 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 834 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | |
| 836 | /** |
| 837 | * The statistics associated with a particular service. |
| 838 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 839 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | |
| 841 | /** |
| 842 | * Returns the amount of time spent started. |
| 843 | * |
| 844 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 845 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | * @return |
| 847 | */ |
| 848 | public abstract long getStartTime(long batteryUptime, int which); |
| 849 | |
| 850 | /** |
| 851 | * Returns the total number of times startService() has been called. |
| 852 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 853 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | */ |
| 855 | public abstract int getStarts(int which); |
| 856 | |
| 857 | /** |
| 858 | * Returns the total number times the service has been launched. |
| 859 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 860 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | */ |
| 862 | public abstract int getLaunches(int which); |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 867 | public static final class LevelStepTracker { |
| 868 | public long mLastStepTime = -1; |
| 869 | public int mNumStepDurations; |
| 870 | public final long[] mStepDurations; |
| 871 | |
| 872 | public LevelStepTracker(int maxLevelSteps) { |
| 873 | mStepDurations = new long[maxLevelSteps]; |
| 874 | } |
| 875 | |
| 876 | public LevelStepTracker(int numSteps, long[] steps) { |
| 877 | mNumStepDurations = numSteps; |
| 878 | mStepDurations = new long[numSteps]; |
| 879 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 880 | } |
| 881 | |
| 882 | public long getDurationAt(int index) { |
| 883 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 884 | } |
| 885 | |
| 886 | public int getLevelAt(int index) { |
| 887 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 888 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 889 | } |
| 890 | |
| 891 | public int getInitModeAt(int index) { |
| 892 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 893 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 894 | } |
| 895 | |
| 896 | public int getModModeAt(int index) { |
| 897 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 898 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 899 | } |
| 900 | |
| 901 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 902 | boolean hasData = false; |
| 903 | while (topOffset >= 0) { |
| 904 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 905 | topOffset -= 4; |
| 906 | if (!hasData && digit == 0) { |
| 907 | continue; |
| 908 | } |
| 909 | hasData = true; |
| 910 | if (digit >= 0 && digit <= 9) { |
| 911 | out.append((char)('0' + digit)); |
| 912 | } else { |
| 913 | out.append((char)('a' + digit - 10)); |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | public void encodeEntryAt(int index, StringBuilder out) { |
| 919 | long item = mStepDurations[index]; |
| 920 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 921 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 922 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 923 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 924 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 925 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 926 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 927 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 928 | case Display.STATE_OFF: out.append('f'); break; |
| 929 | case Display.STATE_ON: out.append('o'); break; |
| 930 | case Display.STATE_DOZE: out.append('d'); break; |
| 931 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 932 | } |
| 933 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 934 | out.append('p'); |
| 935 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 936 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 937 | out.append('i'); |
| 938 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 939 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 940 | case Display.STATE_OFF: out.append('F'); break; |
| 941 | case Display.STATE_ON: out.append('O'); break; |
| 942 | case Display.STATE_DOZE: out.append('D'); break; |
| 943 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 944 | } |
| 945 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 946 | out.append('P'); |
| 947 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 948 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 949 | out.append('I'); |
| 950 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 951 | out.append('-'); |
| 952 | appendHex(level, 4, out); |
| 953 | out.append('-'); |
| 954 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 955 | } |
| 956 | |
| 957 | public void decodeEntryAt(int index, String value) { |
| 958 | final int N = value.length(); |
| 959 | int i = 0; |
| 960 | char c; |
| 961 | long out = 0; |
| 962 | while (i < N && (c=value.charAt(i)) != '-') { |
| 963 | i++; |
| 964 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 965 | case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 966 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 967 | case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 968 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 969 | case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 970 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 971 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 972 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 973 | break; |
| 974 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 975 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 976 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 977 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 978 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 979 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 980 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 981 | break; |
| 982 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 983 | break; |
| 984 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 985 | break; |
| 986 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 987 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 988 | break; |
| 989 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 990 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 991 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 992 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 993 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 994 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 998 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 999 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1000 | i++; |
| 1001 | level <<= 4; |
| 1002 | if (c >= '0' && c <= '9') { |
| 1003 | level += c - '0'; |
| 1004 | } else if (c >= 'a' && c <= 'f') { |
| 1005 | level += c - 'a' + 10; |
| 1006 | } else if (c >= 'A' && c <= 'F') { |
| 1007 | level += c - 'A' + 10; |
| 1008 | } |
| 1009 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1010 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1011 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1012 | long duration = 0; |
| 1013 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1014 | i++; |
| 1015 | duration <<= 4; |
| 1016 | if (c >= '0' && c <= '9') { |
| 1017 | duration += c - '0'; |
| 1018 | } else if (c >= 'a' && c <= 'f') { |
| 1019 | duration += c - 'a' + 10; |
| 1020 | } else if (c >= 'A' && c <= 'F') { |
| 1021 | duration += c - 'A' + 10; |
| 1022 | } |
| 1023 | } |
| 1024 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1025 | } |
| 1026 | |
| 1027 | public void init() { |
| 1028 | mLastStepTime = -1; |
| 1029 | mNumStepDurations = 0; |
| 1030 | } |
| 1031 | |
| 1032 | public void clearTime() { |
| 1033 | mLastStepTime = -1; |
| 1034 | } |
| 1035 | |
| 1036 | public long computeTimePerLevel() { |
| 1037 | final long[] steps = mStepDurations; |
| 1038 | final int numSteps = mNumStepDurations; |
| 1039 | |
| 1040 | // For now we'll do a simple average across all steps. |
| 1041 | if (numSteps <= 0) { |
| 1042 | return -1; |
| 1043 | } |
| 1044 | long total = 0; |
| 1045 | for (int i=0; i<numSteps; i++) { |
| 1046 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1047 | } |
| 1048 | return total / numSteps; |
| 1049 | /* |
| 1050 | long[] buckets = new long[numSteps]; |
| 1051 | int numBuckets = 0; |
| 1052 | int numToAverage = 4; |
| 1053 | int i = 0; |
| 1054 | while (i < numSteps) { |
| 1055 | long totalTime = 0; |
| 1056 | int num = 0; |
| 1057 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1058 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1059 | num++; |
| 1060 | } |
| 1061 | buckets[numBuckets] = totalTime / num; |
| 1062 | numBuckets++; |
| 1063 | numToAverage *= 2; |
| 1064 | i += num; |
| 1065 | } |
| 1066 | if (numBuckets < 1) { |
| 1067 | return -1; |
| 1068 | } |
| 1069 | long averageTime = buckets[numBuckets-1]; |
| 1070 | for (i=numBuckets-2; i>=0; i--) { |
| 1071 | averageTime = (averageTime + buckets[i]) / 2; |
| 1072 | } |
| 1073 | return averageTime; |
| 1074 | */ |
| 1075 | } |
| 1076 | |
| 1077 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1078 | int[] outNumOfInterest) { |
| 1079 | final long[] steps = mStepDurations; |
| 1080 | final int count = mNumStepDurations; |
| 1081 | if (count <= 0) { |
| 1082 | return -1; |
| 1083 | } |
| 1084 | long total = 0; |
| 1085 | int numOfInterest = 0; |
| 1086 | for (int i=0; i<count; i++) { |
| 1087 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1088 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1089 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1090 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1091 | // If the modes of interest didn't change during this step period... |
| 1092 | if ((modMode&modesOfInterest) == 0) { |
| 1093 | // And the mode values during this period match those we are measuring... |
| 1094 | if ((initMode&modesOfInterest) == modeValues) { |
| 1095 | // Then this can be used to estimate the total time! |
| 1096 | numOfInterest++; |
| 1097 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | if (numOfInterest <= 0) { |
| 1102 | return -1; |
| 1103 | } |
| 1104 | |
| 1105 | if (outNumOfInterest != null) { |
| 1106 | outNumOfInterest[0] = numOfInterest; |
| 1107 | } |
| 1108 | |
| 1109 | // The estimated time is the average time we spend in each level, multipled |
| 1110 | // by 100 -- the total number of battery levels |
| 1111 | return (total / numOfInterest) * 100; |
| 1112 | } |
| 1113 | |
| 1114 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1115 | int stepCount = mNumStepDurations; |
| 1116 | final long lastStepTime = mLastStepTime; |
| 1117 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1118 | final long[] steps = mStepDurations; |
| 1119 | long duration = elapsedRealtime - lastStepTime; |
| 1120 | for (int i=0; i<numStepLevels; i++) { |
| 1121 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1122 | long thisDuration = duration / (numStepLevels-i); |
| 1123 | duration -= thisDuration; |
| 1124 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1125 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1126 | } |
| 1127 | steps[0] = thisDuration | modeBits; |
| 1128 | } |
| 1129 | stepCount += numStepLevels; |
| 1130 | if (stepCount > steps.length) { |
| 1131 | stepCount = steps.length; |
| 1132 | } |
| 1133 | } |
| 1134 | mNumStepDurations = stepCount; |
| 1135 | mLastStepTime = elapsedRealtime; |
| 1136 | } |
| 1137 | |
| 1138 | public void readFromParcel(Parcel in) { |
| 1139 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1140 | if (N > mStepDurations.length) { |
| 1141 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1142 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1143 | mNumStepDurations = N; |
| 1144 | for (int i=0; i<N; i++) { |
| 1145 | mStepDurations[i] = in.readLong(); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | public void writeToParcel(Parcel out) { |
| 1150 | final int N = mNumStepDurations; |
| 1151 | out.writeInt(N); |
| 1152 | for (int i=0; i<N; i++) { |
| 1153 | out.writeLong(mStepDurations[i]); |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1158 | public static final class PackageChange { |
| 1159 | public String mPackageName; |
| 1160 | public boolean mUpdate; |
| 1161 | public int mVersionCode; |
| 1162 | } |
| 1163 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1164 | public static final class DailyItem { |
| 1165 | public long mStartTime; |
| 1166 | public long mEndTime; |
| 1167 | public LevelStepTracker mDischargeSteps; |
| 1168 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1169 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1173 | |
| 1174 | public abstract long getCurrentDailyStartTime(); |
| 1175 | |
| 1176 | public abstract long getNextMinDailyDeadline(); |
| 1177 | |
| 1178 | public abstract long getNextMaxDailyDeadline(); |
| 1179 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1180 | public abstract long[] getCpuFreqs(); |
| 1181 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1182 | public final static class HistoryTag { |
| 1183 | public String string; |
| 1184 | public int uid; |
| 1185 | |
| 1186 | public int poolIdx; |
| 1187 | |
| 1188 | public void setTo(HistoryTag o) { |
| 1189 | string = o.string; |
| 1190 | uid = o.uid; |
| 1191 | poolIdx = o.poolIdx; |
| 1192 | } |
| 1193 | |
| 1194 | public void setTo(String _string, int _uid) { |
| 1195 | string = _string; |
| 1196 | uid = _uid; |
| 1197 | poolIdx = -1; |
| 1198 | } |
| 1199 | |
| 1200 | public void writeToParcel(Parcel dest, int flags) { |
| 1201 | dest.writeString(string); |
| 1202 | dest.writeInt(uid); |
| 1203 | } |
| 1204 | |
| 1205 | public void readFromParcel(Parcel src) { |
| 1206 | string = src.readString(); |
| 1207 | uid = src.readInt(); |
| 1208 | poolIdx = -1; |
| 1209 | } |
| 1210 | |
| 1211 | @Override |
| 1212 | public boolean equals(Object o) { |
| 1213 | if (this == o) return true; |
| 1214 | if (o == null || getClass() != o.getClass()) return false; |
| 1215 | |
| 1216 | HistoryTag that = (HistoryTag) o; |
| 1217 | |
| 1218 | if (uid != that.uid) return false; |
| 1219 | if (!string.equals(that.string)) return false; |
| 1220 | |
| 1221 | return true; |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
| 1225 | public int hashCode() { |
| 1226 | int result = string.hashCode(); |
| 1227 | result = 31 * result + uid; |
| 1228 | return result; |
| 1229 | } |
| 1230 | } |
| 1231 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1232 | /** |
| 1233 | * Optional detailed information that can go into a history step. This is typically |
| 1234 | * generated each time the battery level changes. |
| 1235 | */ |
| 1236 | public final static class HistoryStepDetails { |
| 1237 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1238 | public int userTime; |
| 1239 | public int systemTime; |
| 1240 | |
| 1241 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1242 | public int appCpuUid1; |
| 1243 | public int appCpuUTime1; |
| 1244 | public int appCpuSTime1; |
| 1245 | public int appCpuUid2; |
| 1246 | public int appCpuUTime2; |
| 1247 | public int appCpuSTime2; |
| 1248 | public int appCpuUid3; |
| 1249 | public int appCpuUTime3; |
| 1250 | public int appCpuSTime3; |
| 1251 | |
| 1252 | // Information from /proc/stat |
| 1253 | public int statUserTime; |
| 1254 | public int statSystemTime; |
| 1255 | public int statIOWaitTime; |
| 1256 | public int statIrqTime; |
| 1257 | public int statSoftIrqTime; |
| 1258 | public int statIdlTime; |
| 1259 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1260 | // Platform-level low power state stats |
| 1261 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1262 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1263 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1264 | public HistoryStepDetails() { |
| 1265 | clear(); |
| 1266 | } |
| 1267 | |
| 1268 | public void clear() { |
| 1269 | userTime = systemTime = 0; |
| 1270 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1271 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1272 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1273 | } |
| 1274 | |
| 1275 | public void writeToParcel(Parcel out) { |
| 1276 | out.writeInt(userTime); |
| 1277 | out.writeInt(systemTime); |
| 1278 | out.writeInt(appCpuUid1); |
| 1279 | out.writeInt(appCpuUTime1); |
| 1280 | out.writeInt(appCpuSTime1); |
| 1281 | out.writeInt(appCpuUid2); |
| 1282 | out.writeInt(appCpuUTime2); |
| 1283 | out.writeInt(appCpuSTime2); |
| 1284 | out.writeInt(appCpuUid3); |
| 1285 | out.writeInt(appCpuUTime3); |
| 1286 | out.writeInt(appCpuSTime3); |
| 1287 | out.writeInt(statUserTime); |
| 1288 | out.writeInt(statSystemTime); |
| 1289 | out.writeInt(statIOWaitTime); |
| 1290 | out.writeInt(statIrqTime); |
| 1291 | out.writeInt(statSoftIrqTime); |
| 1292 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1293 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1294 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | public void readFromParcel(Parcel in) { |
| 1298 | userTime = in.readInt(); |
| 1299 | systemTime = in.readInt(); |
| 1300 | appCpuUid1 = in.readInt(); |
| 1301 | appCpuUTime1 = in.readInt(); |
| 1302 | appCpuSTime1 = in.readInt(); |
| 1303 | appCpuUid2 = in.readInt(); |
| 1304 | appCpuUTime2 = in.readInt(); |
| 1305 | appCpuSTime2 = in.readInt(); |
| 1306 | appCpuUid3 = in.readInt(); |
| 1307 | appCpuUTime3 = in.readInt(); |
| 1308 | appCpuSTime3 = in.readInt(); |
| 1309 | statUserTime = in.readInt(); |
| 1310 | statSystemTime = in.readInt(); |
| 1311 | statIOWaitTime = in.readInt(); |
| 1312 | statIrqTime = in.readInt(); |
| 1313 | statSoftIrqTime = in.readInt(); |
| 1314 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1315 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1316 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1320 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1321 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1322 | |
| 1323 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1324 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1325 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1326 | public static final byte CMD_UPDATE = 0; // These can be written as deltas |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1327 | public static final byte CMD_NULL = -1; |
| 1328 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1329 | public static final byte CMD_CURRENT_TIME = 5; |
| 1330 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1331 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1332 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1333 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1334 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1335 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1336 | /** |
| 1337 | * Return whether the command code is a delta data update. |
| 1338 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1339 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1340 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1341 | } |
| 1342 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1343 | public byte batteryLevel; |
| 1344 | public byte batteryStatus; |
| 1345 | public byte batteryHealth; |
| 1346 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1347 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1348 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1349 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1350 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1351 | // The charge of the battery in micro-Ampere-hours. |
| 1352 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1353 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1354 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1355 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1356 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1357 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1358 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1359 | public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1360 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1361 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1362 | public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1363 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1364 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1365 | public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1366 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1367 | // These states always appear directly in the first int token |
| 1368 | // of a delta change; they should be ones that change relatively |
| 1369 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1370 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1371 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1372 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1373 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1374 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1375 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1376 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1377 | // Do not use, this is used for coulomb delta count. |
| 1378 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1379 | // These are on the lower bits used for the command; if they change |
| 1380 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1381 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1382 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1383 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1384 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1385 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 1386 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1387 | // empty slot |
| 1388 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1389 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1390 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 1391 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1392 | |
| 1393 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1394 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1395 | public int states; |
| 1396 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1397 | // Constants from WIFI_SUPPL_STATE_* |
| 1398 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1399 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1400 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1401 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1402 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1403 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1404 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1405 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1406 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1407 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1408 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1409 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1410 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1411 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1412 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1413 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1414 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1415 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1416 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1417 | |
| 1418 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 1419 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1420 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1421 | |
| 1422 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1423 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1424 | public int states2; |
| 1425 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1426 | // The wake lock that was acquired at this point. |
| 1427 | public HistoryTag wakelockTag; |
| 1428 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1429 | // Kernel wakeup reason at this point. |
| 1430 | public HistoryTag wakeReasonTag; |
| 1431 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1432 | // Non-null when there is more detailed information at this step. |
| 1433 | public HistoryStepDetails stepDetails; |
| 1434 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1435 | public static final int EVENT_FLAG_START = 0x8000; |
| 1436 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1437 | |
| 1438 | // No event in this item. |
| 1439 | public static final int EVENT_NONE = 0x0000; |
| 1440 | // Event is about a process that is running. |
| 1441 | public static final int EVENT_PROC = 0x0001; |
| 1442 | // Event is about an application package that is in the foreground. |
| 1443 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1444 | // Event is about an application package that is at the top of the screen. |
| 1445 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1446 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1447 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1448 | // Events for all additional wake locks aquired/release within a wake block. |
| 1449 | // These are not generated by default. |
| 1450 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1451 | // Event is about an application executing a scheduled job. |
| 1452 | public static final int EVENT_JOB = 0x0006; |
| 1453 | // Events for users running. |
| 1454 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1455 | // Events for foreground user. |
| 1456 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1457 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1458 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1459 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1460 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1461 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1462 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1463 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1464 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1465 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1466 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1467 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1468 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1469 | // Event for a package becoming inactive due to being unused for a period of time. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1470 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1471 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1472 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1473 | // Event for a package being on the temporary whitelist. |
| 1474 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1475 | // Event for the screen waking up. |
| 1476 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1477 | // Event for the UID that woke up the application processor. |
| 1478 | // Used for wakeups coming from WiFi, modem, etc. |
| 1479 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1480 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1481 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1482 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1483 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1484 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1485 | // Mask to extract out only the type part of the event. |
| 1486 | public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1487 | |
| 1488 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1489 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1490 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1491 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1492 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1493 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1494 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1495 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1496 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1497 | public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1498 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1499 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1500 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1501 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1502 | public static final int EVENT_USER_FOREGROUND_START = |
| 1503 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1504 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1505 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1506 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1507 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1508 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1509 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1510 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1511 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1512 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1513 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1514 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1515 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1516 | |
| 1517 | // For CMD_EVENT. |
| 1518 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1519 | public HistoryTag eventTag; |
| 1520 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1521 | // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis(). |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1522 | public long currentTime; |
| 1523 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1524 | // Meta-data when reading. |
| 1525 | public int numReadInts; |
| 1526 | |
| 1527 | // Pre-allocated objects. |
| 1528 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1529 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1530 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1531 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1532 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1533 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1534 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1535 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1536 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1537 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1538 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1539 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1540 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1541 | public int describeContents() { |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | public void writeToParcel(Parcel dest, int flags) { |
| 1546 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1547 | int bat = (((int)cmd)&0xff) |
| 1548 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1549 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1550 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1551 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1552 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1553 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1554 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1555 | dest.writeInt(bat); |
| 1556 | bat = (((int)batteryTemperature)&0xffff) |
| 1557 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1558 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1559 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1560 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1561 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1562 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1563 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1564 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1565 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1566 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1567 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1568 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1569 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1570 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1571 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1572 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1573 | dest.writeLong(currentTime); |
| 1574 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1575 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1576 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1577 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1578 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1579 | int bat = src.readInt(); |
| 1580 | cmd = (byte)(bat&0xff); |
| 1581 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1582 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1583 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1584 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1585 | int bat2 = src.readInt(); |
| 1586 | batteryTemperature = (short)(bat2&0xffff); |
| 1587 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1588 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1589 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1590 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1591 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1592 | wakelockTag = localWakelockTag; |
| 1593 | wakelockTag.readFromParcel(src); |
| 1594 | } else { |
| 1595 | wakelockTag = null; |
| 1596 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1597 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1598 | wakeReasonTag = localWakeReasonTag; |
| 1599 | wakeReasonTag.readFromParcel(src); |
| 1600 | } else { |
| 1601 | wakeReasonTag = null; |
| 1602 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1603 | if ((bat&0x40000000) != 0) { |
| 1604 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1605 | eventTag = localEventTag; |
| 1606 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1607 | } else { |
| 1608 | eventCode = EVENT_NONE; |
| 1609 | eventTag = null; |
| 1610 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1611 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1612 | currentTime = src.readLong(); |
| 1613 | } else { |
| 1614 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1615 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1616 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1619 | public void clear() { |
| 1620 | time = 0; |
| 1621 | cmd = CMD_NULL; |
| 1622 | batteryLevel = 0; |
| 1623 | batteryStatus = 0; |
| 1624 | batteryHealth = 0; |
| 1625 | batteryPlugType = 0; |
| 1626 | batteryTemperature = 0; |
| 1627 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1628 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1629 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1630 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1631 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1632 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1633 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1634 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1635 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1636 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1637 | public void setTo(HistoryItem o) { |
| 1638 | time = o.time; |
| 1639 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1640 | setToCommon(o); |
| 1641 | } |
| 1642 | |
| 1643 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1644 | this.time = time; |
| 1645 | this.cmd = cmd; |
| 1646 | setToCommon(o); |
| 1647 | } |
| 1648 | |
| 1649 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1650 | batteryLevel = o.batteryLevel; |
| 1651 | batteryStatus = o.batteryStatus; |
| 1652 | batteryHealth = o.batteryHealth; |
| 1653 | batteryPlugType = o.batteryPlugType; |
| 1654 | batteryTemperature = o.batteryTemperature; |
| 1655 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1656 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1657 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1658 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1659 | if (o.wakelockTag != null) { |
| 1660 | wakelockTag = localWakelockTag; |
| 1661 | wakelockTag.setTo(o.wakelockTag); |
| 1662 | } else { |
| 1663 | wakelockTag = null; |
| 1664 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1665 | if (o.wakeReasonTag != null) { |
| 1666 | wakeReasonTag = localWakeReasonTag; |
| 1667 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1668 | } else { |
| 1669 | wakeReasonTag = null; |
| 1670 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1671 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1672 | if (o.eventTag != null) { |
| 1673 | eventTag = localEventTag; |
| 1674 | eventTag.setTo(o.eventTag); |
| 1675 | } else { |
| 1676 | eventTag = null; |
| 1677 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1678 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1681 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1682 | return batteryLevel == o.batteryLevel |
| 1683 | && batteryStatus == o.batteryStatus |
| 1684 | && batteryHealth == o.batteryHealth |
| 1685 | && batteryPlugType == o.batteryPlugType |
| 1686 | && batteryTemperature == o.batteryTemperature |
| 1687 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1688 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1689 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1690 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1691 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1692 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1693 | |
| 1694 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1695 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1696 | return false; |
| 1697 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1698 | if (wakelockTag != o.wakelockTag) { |
| 1699 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1700 | return false; |
| 1701 | } |
| 1702 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1703 | return false; |
| 1704 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1705 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1706 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1707 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1708 | return false; |
| 1709 | } |
| 1710 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1711 | return false; |
| 1712 | } |
| 1713 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1714 | if (eventTag != o.eventTag) { |
| 1715 | if (eventTag == null || o.eventTag == null) { |
| 1716 | return false; |
| 1717 | } |
| 1718 | if (!eventTag.equals(o.eventTag)) { |
| 1719 | return false; |
| 1720 | } |
| 1721 | } |
| 1722 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1723 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1724 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1725 | |
| 1726 | public final static class HistoryEventTracker { |
| 1727 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1728 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1729 | |
| 1730 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1731 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1732 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1733 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1734 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1735 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1736 | mActiveEvents[idx] = active; |
| 1737 | } |
| 1738 | SparseIntArray uids = active.get(name); |
| 1739 | if (uids == null) { |
| 1740 | uids = new SparseIntArray(); |
| 1741 | active.put(name, uids); |
| 1742 | } |
| 1743 | if (uids.indexOfKey(uid) >= 0) { |
| 1744 | // Already set, nothing to do! |
| 1745 | return false; |
| 1746 | } |
| 1747 | uids.put(uid, poolIdx); |
| 1748 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1749 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1750 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1751 | if (active == null) { |
| 1752 | // not currently active, nothing to do. |
| 1753 | return false; |
| 1754 | } |
| 1755 | SparseIntArray uids = active.get(name); |
| 1756 | if (uids == null) { |
| 1757 | // not currently active, nothing to do. |
| 1758 | return false; |
| 1759 | } |
| 1760 | idx = uids.indexOfKey(uid); |
| 1761 | if (idx < 0) { |
| 1762 | // not currently active, nothing to do. |
| 1763 | return false; |
| 1764 | } |
| 1765 | uids.removeAt(idx); |
| 1766 | if (uids.size() <= 0) { |
| 1767 | active.remove(name); |
| 1768 | } |
| 1769 | } |
| 1770 | return true; |
| 1771 | } |
| 1772 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1773 | public void removeEvents(int code) { |
| 1774 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1775 | mActiveEvents[idx] = null; |
| 1776 | } |
| 1777 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1778 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1779 | return mActiveEvents[code]; |
| 1780 | } |
| 1781 | } |
| 1782 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1783 | public static final class BitDescription { |
| 1784 | public final int mask; |
| 1785 | public final int shift; |
| 1786 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1787 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1788 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1789 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1790 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1791 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1792 | this.mask = mask; |
| 1793 | this.shift = -1; |
| 1794 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1795 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1796 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1797 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1798 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1799 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1800 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1801 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1802 | this.mask = mask; |
| 1803 | this.shift = shift; |
| 1804 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1805 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1806 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1807 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1808 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1809 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1810 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1811 | /** |
| 1812 | * Don't allow any more batching in to the current history event. This |
| 1813 | * is called when printing partial histories, so to ensure that the next |
| 1814 | * history event will go in to a new batch after what was printed in the |
| 1815 | * last partial history. |
| 1816 | */ |
| 1817 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1818 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1819 | public abstract int getHistoryTotalSize(); |
| 1820 | |
| 1821 | public abstract int getHistoryUsedSize(); |
| 1822 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1823 | public abstract boolean startIteratingHistoryLocked(); |
| 1824 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1825 | public abstract int getHistoryStringPoolSize(); |
| 1826 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1827 | public abstract int getHistoryStringPoolBytes(); |
| 1828 | |
| 1829 | public abstract String getHistoryTagPoolString(int index); |
| 1830 | |
| 1831 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1832 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1833 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1834 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1835 | public abstract void finishIteratingHistoryLocked(); |
| 1836 | |
| 1837 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1838 | |
| 1839 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1840 | |
| 1841 | public abstract void finishIteratingOldHistoryLocked(); |
| 1842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1844 | * Return the base time offset for the battery history. |
| 1845 | */ |
| 1846 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1847 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1848 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | * Returns the number of times the device has been started. |
| 1850 | */ |
| 1851 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1854 | * Returns the time in microseconds that the screen has been on while the device was |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1856 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | * {@hide} |
| 1858 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1859 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1860 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1861 | /** |
| 1862 | * Returns the number of times the screen was turned on. |
| 1863 | * |
| 1864 | * {@hide} |
| 1865 | */ |
| 1866 | public abstract int getScreenOnCount(int which); |
| 1867 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 1868 | /** |
| 1869 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1870 | * running on battery. |
| 1871 | * |
| 1872 | * {@hide} |
| 1873 | */ |
| 1874 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1875 | |
| 1876 | /** |
| 1877 | * Returns the number of times the screen was turned dozing. |
| 1878 | * |
| 1879 | * {@hide} |
| 1880 | */ |
| 1881 | public abstract int getScreenDozeCount(int which); |
| 1882 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1883 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1884 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1885 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1886 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1887 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1888 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1889 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1890 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1891 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1892 | "dark", "dim", "medium", "light", "bright" |
| 1893 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1894 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1895 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1896 | "0", "1", "2", "3", "4" |
| 1897 | }; |
| 1898 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1899 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1900 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1901 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1902 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1903 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1904 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1905 | * {@hide} |
| 1906 | */ |
| 1907 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1908 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1911 | * Returns the time in microseconds that power save mode has been enabled while the device was |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1912 | * running on battery. |
| 1913 | * |
| 1914 | * {@hide} |
| 1915 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1916 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1917 | |
| 1918 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1919 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1920 | * |
| 1921 | * {@hide} |
| 1922 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1923 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1924 | |
| 1925 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1926 | * Constant for device idle mode: not active. |
| 1927 | */ |
| 1928 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1929 | |
| 1930 | /** |
| 1931 | * Constant for device idle mode: active in lightweight mode. |
| 1932 | */ |
| 1933 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1934 | |
| 1935 | /** |
| 1936 | * Constant for device idle mode: active in full mode. |
| 1937 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1938 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1939 | |
| 1940 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1941 | * Returns the time in microseconds that device has been in idle mode while |
| 1942 | * running on battery. |
| 1943 | * |
| 1944 | * {@hide} |
| 1945 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1946 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1947 | |
| 1948 | /** |
| 1949 | * Returns the number of times that the devie has gone in to idle mode. |
| 1950 | * |
| 1951 | * {@hide} |
| 1952 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1953 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1954 | |
| 1955 | /** |
| 1956 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1957 | * mode, not in idle maintenance etc). |
| 1958 | */ |
| 1959 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1960 | |
| 1961 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1962 | * Returns the time in microseconds that device has been in idling while on |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1963 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1964 | * counts all of the time that we consider the device to be idle, whether or not |
| 1965 | * it is currently in the actual device idle mode. |
| 1966 | * |
| 1967 | * {@hide} |
| 1968 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1969 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1970 | |
| 1971 | /** |
| 1972 | * Returns the number of times that the devie has started idling. |
| 1973 | * |
| 1974 | * {@hide} |
| 1975 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1976 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1977 | |
| 1978 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1979 | * Returns the number of times that connectivity state changed. |
| 1980 | * |
| 1981 | * {@hide} |
| 1982 | */ |
| 1983 | public abstract int getNumConnectivityChange(int which); |
| 1984 | |
| 1985 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1986 | * Returns the time in microseconds that the phone has been on while the device was |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1987 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1988 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | * {@hide} |
| 1990 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1991 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1992 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1993 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1994 | * Returns the number of times a phone call was activated. |
| 1995 | * |
| 1996 | * {@hide} |
| 1997 | */ |
| 1998 | public abstract int getPhoneOnCount(int which); |
| 1999 | |
| 2000 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2001 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2002 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2003 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2004 | * {@hide} |
| 2005 | */ |
| 2006 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2007 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2008 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2009 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2010 | * Returns the time in microseconds that the phone has been trying to |
| 2011 | * acquire a signal. |
| 2012 | * |
| 2013 | * {@hide} |
| 2014 | */ |
| 2015 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2016 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2017 | |
| 2018 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2019 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2020 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2021 | * {@hide} |
| 2022 | */ |
| 2023 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2024 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2025 | /** |
| 2026 | * Returns the time in microseconds that the mobile network has been active |
| 2027 | * (in a high power state). |
| 2028 | * |
| 2029 | * {@hide} |
| 2030 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2031 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2032 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2033 | /** |
| 2034 | * Returns the number of times that the mobile network has transitioned to the |
| 2035 | * active state. |
| 2036 | * |
| 2037 | * {@hide} |
| 2038 | */ |
| 2039 | public abstract int getMobileRadioActiveCount(int which); |
| 2040 | |
| 2041 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2042 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2043 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2044 | * from the radio. |
| 2045 | * |
| 2046 | * {@hide} |
| 2047 | */ |
| 2048 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2049 | |
| 2050 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2051 | * Returns the time in microseconds that the mobile network has been active |
| 2052 | * (in a high power state) but not being able to blame on an app. |
| 2053 | * |
| 2054 | * {@hide} |
| 2055 | */ |
| 2056 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2057 | |
| 2058 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2059 | * Return count of number of times radio was up that could not be blamed on apps. |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2060 | * |
| 2061 | * {@hide} |
| 2062 | */ |
| 2063 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2064 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2065 | public static final int DATA_CONNECTION_NONE = 0; |
| 2066 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2067 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2068 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2069 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2070 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2071 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2072 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2073 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2074 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2075 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2076 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2077 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2078 | public static final int DATA_CONNECTION_LTE = 13; |
| 2079 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2080 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2081 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2082 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2083 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2084 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2085 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2086 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2087 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2088 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2089 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2090 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2091 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2092 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2093 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2094 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2095 | * {@hide} |
| 2096 | */ |
| 2097 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2098 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2101 | * Returns the number of times the phone has entered the given data |
| 2102 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2103 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2104 | * {@hide} |
| 2105 | */ |
| 2106 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2107 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2108 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2109 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2110 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2111 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2112 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2113 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2114 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2115 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2116 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2117 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2118 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2119 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2120 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2121 | |
| 2122 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2123 | |
| 2124 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2125 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2126 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2127 | "group-handshake", "completed", "dormant", "uninit" |
| 2128 | }; |
| 2129 | |
| 2130 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2131 | "inv", "dsc", "dis", "inact", "scan", |
| 2132 | "auth", "ascing", "asced", "4-way", |
| 2133 | "group", "compl", "dorm", "uninit" |
| 2134 | }; |
| 2135 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2136 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2137 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2138 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2139 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2140 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2141 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2142 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2143 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2144 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2145 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2146 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2147 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2148 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2149 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2150 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2151 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2152 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2153 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2154 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2155 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2156 | new String[] {"in", "out", "emergency", "off"}, |
| 2157 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2158 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2159 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2160 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2161 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2162 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2163 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2164 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2165 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2166 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2167 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2168 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2169 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2170 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2171 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2172 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2173 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2174 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2175 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2176 | new String[] { "off", "light", "full", "???" }, |
| 2177 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2178 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2179 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2180 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2181 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2182 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2183 | new String[] { "0", "1", "2", "3", "4" }, |
| 2184 | new String[] { "0", "1", "2", "3", "4" }), |
| 2185 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2186 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2187 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2188 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2189 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2190 | }; |
| 2191 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2192 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2193 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2194 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2195 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2196 | }; |
| 2197 | |
| 2198 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2199 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2200 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2201 | "Esw", "Ewa", "Elw", "Eec" |
| 2202 | }; |
| 2203 | |
| 2204 | @FunctionalInterface |
| 2205 | public interface IntToString { |
| 2206 | String applyAsString(int val); |
| 2207 | } |
| 2208 | |
| 2209 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2210 | private static final IntToString sIntToString = Integer::toString; |
| 2211 | |
| 2212 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2213 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2214 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2215 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2216 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2217 | }; |
| 2218 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2219 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2220 | * Returns the time in microseconds that wifi has been on while the device was |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2221 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2222 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2223 | * {@hide} |
| 2224 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2225 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2226 | |
| 2227 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2228 | * Returns the time in microseconds that wifi has been on and the driver has |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2229 | * been in the running state while the device was running on battery. |
| 2230 | * |
| 2231 | * {@hide} |
| 2232 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2233 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2234 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2235 | public static final int WIFI_STATE_OFF = 0; |
| 2236 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2237 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2238 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2239 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2240 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2241 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2242 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2243 | |
| 2244 | static final String[] WIFI_STATE_NAMES = { |
| 2245 | "off", "scanning", "no_net", "disconn", |
| 2246 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2247 | }; |
| 2248 | |
| 2249 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2250 | |
| 2251 | /** |
| 2252 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2253 | * |
| 2254 | * {@hide} |
| 2255 | */ |
| 2256 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2257 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2258 | |
| 2259 | /** |
| 2260 | * Returns the number of times that WiFi has entered the given state. |
| 2261 | * |
| 2262 | * {@hide} |
| 2263 | */ |
| 2264 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2265 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2266 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2267 | * Returns the time in microseconds that the wifi supplicant has been |
| 2268 | * in a given state. |
| 2269 | * |
| 2270 | * {@hide} |
| 2271 | */ |
| 2272 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2273 | |
| 2274 | /** |
| 2275 | * Returns the number of times that the wifi supplicant has transitioned |
| 2276 | * to a given state. |
| 2277 | * |
| 2278 | * {@hide} |
| 2279 | */ |
| 2280 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2281 | |
| 2282 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2283 | |
| 2284 | /** |
| 2285 | * Returns the time in microseconds that WIFI has been running with |
| 2286 | * the given signal strength. |
| 2287 | * |
| 2288 | * {@hide} |
| 2289 | */ |
| 2290 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2291 | long elapsedRealtimeUs, int which); |
| 2292 | |
| 2293 | /** |
| 2294 | * Returns the number of times WIFI has entered the given signal strength. |
| 2295 | * |
| 2296 | * {@hide} |
| 2297 | */ |
| 2298 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2299 | |
| 2300 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2301 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2302 | * running on battery. |
| 2303 | * |
| 2304 | * {@hide} |
| 2305 | */ |
| 2306 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2307 | |
| 2308 | /** |
| 2309 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2310 | * running on battery. |
| 2311 | * |
| 2312 | * {@hide} |
| 2313 | */ |
| 2314 | public abstract long getFlashlightOnCount(int which); |
| 2315 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2316 | /** |
| 2317 | * Returns the time in microseconds that the camera has been on while the device was |
| 2318 | * running on battery. |
| 2319 | * |
| 2320 | * {@hide} |
| 2321 | */ |
| 2322 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2323 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2324 | /** |
| 2325 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2326 | * on battery. |
| 2327 | * |
| 2328 | * {@hide} |
| 2329 | */ |
| 2330 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2331 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2332 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2333 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2334 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2335 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2336 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2337 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2338 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2339 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2340 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2341 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2342 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2343 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2344 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2345 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2346 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2347 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2348 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2349 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2350 | * actual power data. |
| 2351 | */ |
| 2352 | public abstract boolean hasWifiActivityReporting(); |
| 2353 | |
| 2354 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2355 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2356 | * in various radio controller states, such as transmit, receive, and idle. |
| 2357 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2358 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2359 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2360 | |
| 2361 | /** |
| 2362 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2363 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2364 | * actual power data. |
| 2365 | */ |
| 2366 | public abstract boolean hasBluetoothActivityReporting(); |
| 2367 | |
| 2368 | /** |
| 2369 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2370 | * in various radio controller states, such as transmit, receive, and idle. |
| 2371 | * @return non-null {@link ControllerActivityCounter} |
| 2372 | */ |
| 2373 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2374 | |
| 2375 | /** |
| 2376 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2377 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2378 | * actual power data. |
| 2379 | */ |
| 2380 | public abstract boolean hasModemActivityReporting(); |
| 2381 | |
| 2382 | /** |
| 2383 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2384 | * in various radio controller states, such as transmit, receive, and idle. |
| 2385 | * @return non-null {@link ControllerActivityCounter} |
| 2386 | */ |
| 2387 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2388 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2389 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2390 | * Return the wall clock time when battery stats data collection started. |
| 2391 | */ |
| 2392 | public abstract long getStartClockTime(); |
| 2393 | |
| 2394 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2395 | * Return platform version tag that we were running in when the battery stats started. |
| 2396 | */ |
| 2397 | public abstract String getStartPlatformVersion(); |
| 2398 | |
| 2399 | /** |
| 2400 | * Return platform version tag that we were running in when the battery stats ended. |
| 2401 | */ |
| 2402 | public abstract String getEndPlatformVersion(); |
| 2403 | |
| 2404 | /** |
| 2405 | * Return the internal version code of the parcelled format. |
| 2406 | */ |
| 2407 | public abstract int getParcelVersion(); |
| 2408 | |
| 2409 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | * Return whether we are currently running on battery. |
| 2411 | */ |
| 2412 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | /** |
| 2415 | * Returns a SparseArray containing the statistics for each uid. |
| 2416 | */ |
| 2417 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2418 | |
| 2419 | /** |
| 2420 | * Returns the current battery uptime in microseconds. |
| 2421 | * |
| 2422 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2423 | */ |
| 2424 | public abstract long getBatteryUptime(long curTime); |
| 2425 | |
| 2426 | /** |
| 2427 | * Returns the current battery realtime in microseconds. |
| 2428 | * |
| 2429 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2430 | */ |
| 2431 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2432 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2433 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2434 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2435 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2436 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2437 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2438 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2439 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2440 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2441 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2442 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2443 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | |
| 2445 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2446 | * Get the amount the battery has discharged since the stats were |
| 2447 | * last reset after charging, as a lower-end approximation. |
| 2448 | */ |
| 2449 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2450 | |
| 2451 | /** |
| 2452 | * Get the amount the battery has discharged since the stats were |
| 2453 | * last reset after charging, as an upper-end approximation. |
| 2454 | */ |
| 2455 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2456 | |
| 2457 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2458 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2459 | */ |
| 2460 | public abstract int getDischargeAmount(int which); |
| 2461 | |
| 2462 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2463 | * Get the amount the battery has discharged while the screen was on, |
| 2464 | * since the last time power was unplugged. |
| 2465 | */ |
| 2466 | public abstract int getDischargeAmountScreenOn(); |
| 2467 | |
| 2468 | /** |
| 2469 | * Get the amount the battery has discharged while the screen was on, |
| 2470 | * since the last time the device was charged. |
| 2471 | */ |
| 2472 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2473 | |
| 2474 | /** |
| 2475 | * Get the amount the battery has discharged while the screen was off, |
| 2476 | * since the last time power was unplugged. |
| 2477 | */ |
| 2478 | public abstract int getDischargeAmountScreenOff(); |
| 2479 | |
| 2480 | /** |
| 2481 | * Get the amount the battery has discharged while the screen was off, |
| 2482 | * since the last time the device was charged. |
| 2483 | */ |
| 2484 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2485 | |
| 2486 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2487 | * Get the amount the battery has discharged while the screen was doze, |
| 2488 | * since the last time power was unplugged. |
| 2489 | */ |
| 2490 | public abstract int getDischargeAmountScreenDoze(); |
| 2491 | |
| 2492 | /** |
| 2493 | * Get the amount the battery has discharged while the screen was doze, |
| 2494 | * since the last time the device was charged. |
| 2495 | */ |
| 2496 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2497 | |
| 2498 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | * Returns the total, last, or current battery uptime in microseconds. |
| 2500 | * |
| 2501 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2502 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | */ |
| 2504 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2505 | |
| 2506 | /** |
| 2507 | * Returns the total, last, or current battery realtime in microseconds. |
| 2508 | * |
| 2509 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2510 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | */ |
| 2512 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2513 | |
| 2514 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2515 | * Returns the total, last, or current battery screen off/doze uptime in microseconds. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2516 | * |
| 2517 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2518 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2519 | */ |
| 2520 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2521 | |
| 2522 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2523 | * Returns the total, last, or current battery screen off/doze realtime in microseconds. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2524 | * |
| 2525 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2526 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2527 | */ |
| 2528 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2529 | |
| 2530 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | * Returns the total, last, or current uptime in microseconds. |
| 2532 | * |
| 2533 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2534 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | */ |
| 2536 | public abstract long computeUptime(long curTime, int which); |
| 2537 | |
| 2538 | /** |
| 2539 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2540 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2542 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | */ |
| 2544 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2545 | |
| 2546 | /** |
| 2547 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2548 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2549 | * enough current data to make a decision, or the battery is currently |
| 2550 | * charging. |
| 2551 | * |
| 2552 | * @param curTime The current elepsed realtime in microseconds. |
| 2553 | */ |
| 2554 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2555 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2556 | // The part of a step duration that is the actual time. |
| 2557 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2558 | |
| 2559 | // Bits in a step duration that are the new battery level we are at. |
| 2560 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2561 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2562 | |
| 2563 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2564 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2565 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2566 | |
| 2567 | // Bits in a step duration that indicate which modes changed during that step. |
| 2568 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2569 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2570 | |
| 2571 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2572 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2573 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2574 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2575 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2576 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2577 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2578 | // Step duration mode: power save is on. |
| 2579 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2580 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2581 | // Step duration mode: device is currently in idle mode. |
| 2582 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2583 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2584 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2585 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2586 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2587 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2588 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2589 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2590 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2591 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2592 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2593 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2594 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2595 | }; |
| 2596 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2597 | (Display.STATE_OFF-1), |
| 2598 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2599 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2600 | (Display.STATE_ON-1), |
| 2601 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2602 | (Display.STATE_DOZE-1), |
| 2603 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2604 | (Display.STATE_DOZE_SUSPEND-1), |
| 2605 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2606 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2607 | }; |
| 2608 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2609 | "screen off", |
| 2610 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2611 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2612 | "screen on", |
| 2613 | "screen on power save", |
| 2614 | "screen doze", |
| 2615 | "screen doze power save", |
| 2616 | "screen doze-suspend", |
| 2617 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2618 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2619 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2620 | |
| 2621 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2622 | * Return the amount of battery discharge while the screen was off, measured in |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2623 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2624 | * a coulomb counter. |
| 2625 | */ |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 2626 | public abstract long getMahDischargeScreenOff(int which); |
| 2627 | |
| 2628 | /** |
| 2629 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2630 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2631 | * a coulomb counter. |
| 2632 | */ |
| 2633 | public abstract long getMahDischargeScreenDoze(int which); |
| 2634 | |
| 2635 | /** |
| 2636 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2637 | * non-zero only if the device's battery has a coulomb counter. |
| 2638 | */ |
| 2639 | public abstract long getMahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2640 | |
| 2641 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2642 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2643 | * declared by the PowerProfile. |
| 2644 | * @return The estimated battery capacity in mAh. |
| 2645 | */ |
| 2646 | public abstract int getEstimatedBatteryCapacity(); |
| 2647 | |
| 2648 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2649 | * @return The minimum learned battery capacity in uAh. |
| 2650 | */ |
| 2651 | public abstract int getMinLearnedBatteryCapacity(); |
| 2652 | |
| 2653 | /** |
| 2654 | * @return The maximum learned battery capacity in uAh. |
| 2655 | */ |
| 2656 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2657 | |
| 2658 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2659 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2660 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2661 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2662 | |
| 2663 | /** |
| 2664 | * Return the array of daily discharge step durations. |
| 2665 | */ |
| 2666 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2667 | |
| 2668 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2669 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2670 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2671 | * enough current data to make a decision, or the battery is currently |
| 2672 | * discharging. |
| 2673 | * |
| 2674 | * @param curTime The current elepsed realtime in microseconds. |
| 2675 | */ |
| 2676 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2677 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2678 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2679 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2680 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2681 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2682 | |
| 2683 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2684 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2685 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2686 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2687 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2688 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2689 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2690 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2691 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2692 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2693 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2694 | /** |
| 2695 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2696 | */ |
| 2697 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2698 | /** |
| 2699 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2700 | */ |
| 2701 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2702 | |
| 2703 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2704 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2705 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2706 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2707 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2708 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | long days = seconds / (60 * 60 * 24); |
| 2710 | if (days != 0) { |
| 2711 | out.append(days); |
| 2712 | out.append("d "); |
| 2713 | } |
| 2714 | long used = days * 60 * 60 * 24; |
| 2715 | |
| 2716 | long hours = (seconds - used) / (60 * 60); |
| 2717 | if (hours != 0 || used != 0) { |
| 2718 | out.append(hours); |
| 2719 | out.append("h "); |
| 2720 | } |
| 2721 | used += hours * 60 * 60; |
| 2722 | |
| 2723 | long mins = (seconds-used) / 60; |
| 2724 | if (mins != 0 || used != 0) { |
| 2725 | out.append(mins); |
| 2726 | out.append("m "); |
| 2727 | } |
| 2728 | used += mins * 60; |
| 2729 | |
| 2730 | if (seconds != 0 || used != 0) { |
| 2731 | out.append(seconds-used); |
| 2732 | out.append("s "); |
| 2733 | } |
| 2734 | } |
| 2735 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2736 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2738 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | sb.append(time - (sec * 1000)); |
| 2740 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2741 | } |
| 2742 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2743 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2744 | long sec = time / 1000; |
| 2745 | formatTimeRaw(sb, sec); |
| 2746 | sb.append(time - (sec * 1000)); |
| 2747 | sb.append("ms"); |
| 2748 | } |
| 2749 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2750 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2752 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | } |
| 2754 | float perc = ((float)num) / ((float)den) * 100; |
| 2755 | mFormatBuilder.setLength(0); |
| 2756 | mFormatter.format("%.1f%%", perc); |
| 2757 | return mFormatBuilder.toString(); |
| 2758 | } |
| 2759 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2760 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2761 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2762 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2763 | if (bytes < BYTES_PER_KB) { |
| 2764 | return bytes + "B"; |
| 2765 | } else if (bytes < BYTES_PER_MB) { |
| 2766 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2767 | return mFormatBuilder.toString(); |
| 2768 | } else if (bytes < BYTES_PER_GB){ |
| 2769 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2770 | return mFormatBuilder.toString(); |
| 2771 | } else { |
| 2772 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2773 | return mFormatBuilder.toString(); |
| 2774 | } |
| 2775 | } |
| 2776 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2777 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2778 | if (timer != null) { |
| 2779 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2780 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2781 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2782 | return totalTimeMillis; |
| 2783 | } |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | /** |
| 2788 | * |
| 2789 | * @param sb a StringBuilder object. |
| 2790 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2791 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2793 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | * @param linePrefix a String to be prepended to each line of output. |
| 2795 | * @return the line prefix |
| 2796 | */ |
| 2797 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2798 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2801 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2802 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2803 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | if (totalTimeMillis != 0) { |
| 2805 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2806 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2807 | if (name != null) { |
| 2808 | sb.append(name); |
| 2809 | sb.append(' '); |
| 2810 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | sb.append('('); |
| 2812 | sb.append(count); |
| 2813 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2814 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2815 | if (maxDurationMs >= 0) { |
| 2816 | sb.append(" max="); |
| 2817 | sb.append(maxDurationMs); |
| 2818 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2819 | // Put actual time if it is available and different from totalTimeMillis. |
| 2820 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2821 | if (totalDurMs > totalTimeMillis) { |
| 2822 | sb.append(" actual="); |
| 2823 | sb.append(totalDurMs); |
| 2824 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2825 | if (timer.isRunningLocked()) { |
| 2826 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2827 | if (currentMs >= 0) { |
| 2828 | sb.append(" (running for "); |
| 2829 | sb.append(currentMs); |
| 2830 | sb.append("ms)"); |
| 2831 | } else { |
| 2832 | sb.append(" (running)"); |
| 2833 | } |
| 2834 | } |
| 2835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | return ", "; |
| 2837 | } |
| 2838 | } |
| 2839 | return linePrefix; |
| 2840 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2841 | |
| 2842 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2843 | * Prints details about a timer, if its total time was greater than 0. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2844 | * |
| 2845 | * @param pw a PrintWriter object to print to. |
| 2846 | * @param sb a StringBuilder object. |
| 2847 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2848 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2849 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2850 | * @param prefix a String to be prepended to each line of output. |
| 2851 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2852 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2853 | */ |
| 2854 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2855 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2856 | if (timer != null) { |
| 2857 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2858 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2859 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2860 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2861 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2862 | sb.setLength(0); |
| 2863 | sb.append(prefix); |
| 2864 | sb.append(" "); |
| 2865 | sb.append(type); |
| 2866 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2867 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2868 | sb.append("realtime ("); |
| 2869 | sb.append(count); |
| 2870 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2871 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2872 | if (maxDurationMs >= 0) { |
| 2873 | sb.append(" max="); |
| 2874 | sb.append(maxDurationMs); |
| 2875 | } |
| 2876 | if (timer.isRunningLocked()) { |
| 2877 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2878 | if (currentMs >= 0) { |
| 2879 | sb.append(" (running for "); |
| 2880 | sb.append(currentMs); |
| 2881 | sb.append("ms)"); |
| 2882 | } else { |
| 2883 | sb.append(" (running)"); |
| 2884 | } |
| 2885 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2886 | pw.println(sb.toString()); |
| 2887 | return true; |
| 2888 | } |
| 2889 | } |
| 2890 | return false; |
| 2891 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | /** |
| 2894 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2895 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | * @param sb a StringBuilder object. |
| 2897 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2898 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2900 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | * @param linePrefix a String to be prepended to each line of output. |
| 2902 | * @return the line prefix |
| 2903 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2904 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2905 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | long totalTimeMicros = 0; |
| 2907 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 2908 | long max = 0; |
| 2909 | long current = 0; |
| 2910 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2912 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2913 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2914 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2915 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2916 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | } |
| 2918 | sb.append(linePrefix); |
| 2919 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2920 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2921 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2923 | sb.append(','); |
| 2924 | sb.append(current); |
| 2925 | sb.append(','); |
| 2926 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2927 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 2928 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 2929 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 2930 | if (name != null) { |
| 2931 | sb.append(','); |
| 2932 | sb.append(totalDuration); |
| 2933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2934 | return ","; |
| 2935 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2936 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2937 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2938 | String type) { |
| 2939 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2940 | pw.print(','); |
| 2941 | pw.print(uid); |
| 2942 | pw.print(','); |
| 2943 | pw.print(category); |
| 2944 | pw.print(','); |
| 2945 | pw.print(type); |
| 2946 | } |
| 2947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | /** |
| 2949 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2950 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | * @param pw the PageWriter to dump log to |
| 2952 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2953 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2954 | * @param args type-dependent data arguments |
| 2955 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2956 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2958 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2959 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2960 | pw.print(','); |
| 2961 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2963 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2965 | |
| 2966 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2967 | * Dump a given timer stat for terse checkin mode. |
| 2968 | * |
| 2969 | * @param pw the PageWriter to dump log to |
| 2970 | * @param uid the UID to log |
| 2971 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2972 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2973 | * @param timer a {@link Timer} to dump stats for |
| 2974 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2975 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2976 | */ |
| 2977 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2978 | Timer timer, long rawRealtime, int which) { |
| 2979 | if (timer != null) { |
| 2980 | // Convert from microseconds to milliseconds with rounding |
| 2981 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2982 | / 1000; |
| 2983 | final int count = timer.getCountLocked(which); |
| 2984 | if (totalTime != 0) { |
| 2985 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2991 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2992 | */ |
| 2993 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2994 | if (counter == null) { |
| 2995 | return false; |
| 2996 | } |
| 2997 | |
| 2998 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2999 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3000 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3001 | return true; |
| 3002 | } |
| 3003 | |
| 3004 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3005 | if (c.getCountLocked(which) != 0) { |
| 3006 | return true; |
| 3007 | } |
| 3008 | } |
| 3009 | return false; |
| 3010 | } |
| 3011 | |
| 3012 | /** |
| 3013 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3014 | * The order of the arguments in the final check in line is: |
| 3015 | * |
| 3016 | * idle, rx, power, tx... |
| 3017 | * |
| 3018 | * where tx... is one or more transmit level times. |
| 3019 | */ |
| 3020 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3021 | String type, |
| 3022 | ControllerActivityCounter counter, |
| 3023 | int which) { |
| 3024 | if (!controllerActivityHasData(counter, which)) { |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | dumpLineHeader(pw, uid, category, type); |
| 3029 | pw.print(","); |
| 3030 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3031 | pw.print(","); |
| 3032 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3033 | pw.print(","); |
| 3034 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3035 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3036 | pw.print(","); |
| 3037 | pw.print(c.getCountLocked(which)); |
| 3038 | } |
| 3039 | pw.println(); |
| 3040 | } |
| 3041 | |
| 3042 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3043 | String prefix, String controllerName, |
| 3044 | ControllerActivityCounter counter, |
| 3045 | int which) { |
| 3046 | if (controllerActivityHasData(counter, which)) { |
| 3047 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3052 | String controllerName, |
| 3053 | ControllerActivityCounter counter, int which) { |
| 3054 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3055 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3056 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 3057 | long totalTxTimeMs = 0; |
| 3058 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3059 | totalTxTimeMs += txState.getCountLocked(which); |
| 3060 | } |
| 3061 | |
| 3062 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 3063 | |
| 3064 | sb.setLength(0); |
| 3065 | sb.append(prefix); |
| 3066 | sb.append(" "); |
| 3067 | sb.append(controllerName); |
| 3068 | sb.append(" Idle time: "); |
| 3069 | formatTimeMs(sb, idleTimeMs); |
| 3070 | sb.append("("); |
| 3071 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 3072 | sb.append(")"); |
| 3073 | pw.println(sb.toString()); |
| 3074 | |
| 3075 | sb.setLength(0); |
| 3076 | sb.append(prefix); |
| 3077 | sb.append(" "); |
| 3078 | sb.append(controllerName); |
| 3079 | sb.append(" Rx time: "); |
| 3080 | formatTimeMs(sb, rxTimeMs); |
| 3081 | sb.append("("); |
| 3082 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 3083 | sb.append(")"); |
| 3084 | pw.println(sb.toString()); |
| 3085 | |
| 3086 | sb.setLength(0); |
| 3087 | sb.append(prefix); |
| 3088 | sb.append(" "); |
| 3089 | sb.append(controllerName); |
| 3090 | sb.append(" Tx time: "); |
| 3091 | formatTimeMs(sb, totalTxTimeMs); |
| 3092 | sb.append("("); |
| 3093 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 3094 | sb.append(")"); |
| 3095 | pw.println(sb.toString()); |
| 3096 | |
| 3097 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 3098 | if (numTxLvls > 1) { |
| 3099 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3100 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3101 | sb.setLength(0); |
| 3102 | sb.append(prefix); |
| 3103 | sb.append(" ["); |
| 3104 | sb.append(lvl); |
| 3105 | sb.append("] "); |
| 3106 | formatTimeMs(sb, txLvlTimeMs); |
| 3107 | sb.append("("); |
| 3108 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 3109 | sb.append(")"); |
| 3110 | pw.println(sb.toString()); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | sb.setLength(0); |
| 3115 | sb.append(prefix); |
| 3116 | sb.append(" "); |
| 3117 | sb.append(controllerName); |
| 3118 | sb.append(" Power drain: ").append( |
| 3119 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 3120 | sb.append("mAh"); |
| 3121 | pw.println(sb.toString()); |
| 3122 | } |
| 3123 | |
| 3124 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3125 | * Temporary for settings. |
| 3126 | */ |
| 3127 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3128 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3129 | } |
| 3130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | /** |
| 3132 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3133 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3134 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3136 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3137 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3139 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3140 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3143 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3144 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3145 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3146 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3148 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3149 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3150 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3151 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3152 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3153 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3154 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3155 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3156 | rawRealtime, which); |
| 3157 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3158 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3159 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3160 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3161 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3162 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3163 | final long dischargeCount = getMahDischarge(which); |
| 3164 | final long dischargeScreenOffCount = getMahDischargeScreenOff(which); |
| 3165 | final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3167 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3168 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3169 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3170 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3171 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3172 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3175 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3176 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3177 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3178 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3179 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3180 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3181 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3182 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3183 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3184 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3185 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3186 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3187 | long fullWakeLockTimeTotal = 0; |
| 3188 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3189 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3190 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3191 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3192 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3193 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3194 | = u.getWakelockStats(); |
| 3195 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3196 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3197 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3198 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3199 | if (fullWakeTimer != null) { |
| 3200 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3201 | which); |
| 3202 | } |
| 3203 | |
| 3204 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3205 | if (partialWakeTimer != null) { |
| 3206 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3207 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3208 | } |
| 3209 | } |
| 3210 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3211 | |
| 3212 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3213 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3214 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3215 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3216 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3217 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3218 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3219 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3220 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3221 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3222 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3223 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3224 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3225 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3226 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3227 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3228 | // Dump Modem controller stats |
| 3229 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3230 | getModemControllerActivity(), which); |
| 3231 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3232 | // Dump Wifi controller stats |
| 3233 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3234 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3235 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3236 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3237 | |
| 3238 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3239 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3240 | |
| 3241 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3242 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3243 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | // Dump misc stats |
| 3246 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3247 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3248 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3249 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3250 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3251 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3252 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3253 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3254 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3255 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3256 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3257 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3258 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3259 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3260 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3261 | // Dump screen brightness stats |
| 3262 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3263 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3264 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3265 | } |
| 3266 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3267 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3268 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3269 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3270 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3271 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3272 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3273 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3274 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3275 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3276 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3277 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3278 | } |
| 3279 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3280 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3281 | // Dump network type stats |
| 3282 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3283 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3284 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3285 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3286 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3287 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3288 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3289 | } |
| 3290 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3291 | |
| 3292 | // Dump wifi state stats |
| 3293 | args = new Object[NUM_WIFI_STATES]; |
| 3294 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3295 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3296 | } |
| 3297 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3298 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3299 | args[i] = getWifiStateCount(i, which); |
| 3300 | } |
| 3301 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3302 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3303 | // Dump wifi suppl state stats |
| 3304 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3305 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3306 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3307 | } |
| 3308 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3309 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3310 | args[i] = getWifiSupplStateCount(i, which); |
| 3311 | } |
| 3312 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3313 | |
| 3314 | // Dump wifi signal strength stats |
| 3315 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3316 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3317 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3318 | } |
| 3319 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3320 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3321 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3322 | } |
| 3323 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3324 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3325 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3326 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3327 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3328 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3329 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3330 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3331 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3332 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3333 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3334 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3335 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
| 3336 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3337 | } else { |
| 3338 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3339 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3340 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3341 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3342 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
| 3343 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3344 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3345 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3346 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3347 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3348 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3349 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3350 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3351 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3352 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3353 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3354 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3355 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3356 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3357 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3358 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3359 | // Not doing the regular wake lock formatting to remain compatible |
| 3360 | // with the old checkin format. |
| 3361 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3362 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3363 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3364 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3365 | } |
| 3366 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3367 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3368 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3369 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3370 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3371 | if (rpmStats.size() > 0) { |
| 3372 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3373 | sb.setLength(0); |
| 3374 | Timer totalTimer = ent.getValue(); |
| 3375 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3376 | int count = totalTimer.getCountLocked(which); |
| 3377 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3378 | long screenOffTimeMs = screenOffTimer != null |
| 3379 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3380 | int screenOffCount = screenOffTimer != null |
| 3381 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3382 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3383 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3384 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3385 | screenOffCount); |
| 3386 | } else { |
| 3387 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3388 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3389 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3393 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3394 | helper.create(this); |
| 3395 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3396 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3397 | if (sippers != null && sippers.size() > 0) { |
| 3398 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3399 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3400 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3401 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3402 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3403 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3404 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3405 | int uid = 0; |
| 3406 | String label; |
| 3407 | switch (bs.drainType) { |
| 3408 | case IDLE: |
| 3409 | label="idle"; |
| 3410 | break; |
| 3411 | case CELL: |
| 3412 | label="cell"; |
| 3413 | break; |
| 3414 | case PHONE: |
| 3415 | label="phone"; |
| 3416 | break; |
| 3417 | case WIFI: |
| 3418 | label="wifi"; |
| 3419 | break; |
| 3420 | case BLUETOOTH: |
| 3421 | label="blue"; |
| 3422 | break; |
| 3423 | case SCREEN: |
| 3424 | label="scrn"; |
| 3425 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3426 | case FLASHLIGHT: |
| 3427 | label="flashlight"; |
| 3428 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3429 | case APP: |
| 3430 | uid = bs.uidObj.getUid(); |
| 3431 | label = "uid"; |
| 3432 | break; |
| 3433 | case USER: |
| 3434 | uid = UserHandle.getUid(bs.userId, 0); |
| 3435 | label = "user"; |
| 3436 | break; |
| 3437 | case UNACCOUNTED: |
| 3438 | label = "unacc"; |
| 3439 | break; |
| 3440 | case OVERCOUNTED: |
| 3441 | label = "over"; |
| 3442 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3443 | case CAMERA: |
| 3444 | label = "camera"; |
| 3445 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3446 | default: |
| 3447 | label = "???"; |
| 3448 | } |
| 3449 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3450 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3451 | bs.shouldHide ? 1 : 0, |
| 3452 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3453 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3457 | final long[] cpuFreqs = getCpuFreqs(); |
| 3458 | if (cpuFreqs != null) { |
| 3459 | sb.setLength(0); |
| 3460 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3461 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3462 | } |
| 3463 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3464 | } |
| 3465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3466 | for (int iu = 0; iu < NU; iu++) { |
| 3467 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3468 | if (reqUid >= 0 && uid != reqUid) { |
| 3469 | continue; |
| 3470 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3471 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3474 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3475 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3476 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3477 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3478 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3479 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3480 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3481 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3482 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3483 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3484 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3485 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3486 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3487 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3488 | // Background data transfers |
| 3489 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3490 | which); |
| 3491 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3492 | which); |
| 3493 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3494 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3495 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3496 | which); |
| 3497 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3498 | which); |
| 3499 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3500 | which); |
| 3501 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3502 | which); |
| 3503 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3504 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3505 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3506 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3507 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3508 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3509 | || wifiBytesBgTx > 0 |
| 3510 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3511 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3512 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3513 | wifiBytesRx, wifiBytesTx, |
| 3514 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3515 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3516 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3517 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3518 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3519 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3520 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3523 | // Dump modem controller data, per UID. |
| 3524 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3525 | u.getModemControllerActivity(), which); |
| 3526 | |
| 3527 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3528 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3529 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3530 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3531 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3532 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3533 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3534 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3535 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3536 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3537 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3538 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3539 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3540 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3541 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3542 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3543 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3546 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3547 | u.getWifiControllerActivity(), which); |
| 3548 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3549 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3550 | if (bleTimer != null) { |
| 3551 | // Convert from microseconds to milliseconds with rounding |
| 3552 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3553 | / 1000; |
| 3554 | if (totalTime != 0) { |
| 3555 | final int count = bleTimer.getCountLocked(which); |
| 3556 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3557 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3558 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3559 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3560 | final long actualTimeBg = bleTimerBg != null ? |
| 3561 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3562 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3563 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3564 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3565 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3566 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3567 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3568 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3569 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3570 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3571 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3572 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3573 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3574 | final Timer unoptimizedScanTimerBg = |
| 3575 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3576 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3577 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3578 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3579 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3580 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3581 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3582 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3583 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3584 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3585 | } |
| 3586 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3587 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3588 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3589 | u.getBluetoothControllerActivity(), which); |
| 3590 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3591 | if (u.hasUserActivity()) { |
| 3592 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3593 | boolean hasData = false; |
| 3594 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3595 | int val = u.getUserActivityCount(i, which); |
| 3596 | args[i] = val; |
| 3597 | if (val != 0) hasData = true; |
| 3598 | } |
| 3599 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3600 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3601 | } |
| 3602 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3603 | |
| 3604 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3605 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3606 | // Times are since reset (regardless of 'which') |
| 3607 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3608 | final Timer bgTimer = timer.getSubTimer(); |
| 3609 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3610 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3611 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3612 | } |
| 3613 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3614 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3615 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3616 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3617 | String linePrefix = ""; |
| 3618 | sb.setLength(0); |
| 3619 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3620 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3621 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3622 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3623 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3624 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3625 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3626 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3627 | rawRealtime, "w", which, linePrefix); |
| 3628 | |
| 3629 | // Only log if we had at lease one wakelock... |
| 3630 | if (sb.length() > 0) { |
| 3631 | String name = wakelocks.keyAt(iw); |
| 3632 | if (name.indexOf(',') >= 0) { |
| 3633 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3635 | if (name.indexOf('\n') >= 0) { |
| 3636 | name = name.replace('\n', '_'); |
| 3637 | } |
| 3638 | if (name.indexOf('\r') >= 0) { |
| 3639 | name = name.replace('\r', '_'); |
| 3640 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3641 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | } |
| 3643 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3644 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3645 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3646 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3647 | final Timer timer = syncs.valueAt(isy); |
| 3648 | // Convert from microseconds to milliseconds with rounding |
| 3649 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3650 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3651 | final Timer bgTimer = timer.getSubTimer(); |
| 3652 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3653 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3654 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3655 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3656 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3657 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3661 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3662 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3663 | final Timer timer = jobs.valueAt(ij); |
| 3664 | // Convert from microseconds to milliseconds with rounding |
| 3665 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3666 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3667 | final Timer bgTimer = timer.getSubTimer(); |
| 3668 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3669 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3670 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3671 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3672 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3673 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3677 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3678 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3679 | SparseIntArray types = completions.valueAt(ic); |
| 3680 | if (types != null) { |
| 3681 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3682 | "\"" + completions.keyAt(ic) + "\"", |
| 3683 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3684 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3685 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3686 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3687 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3688 | } |
| 3689 | } |
| 3690 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3691 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3692 | rawRealtime, which); |
| 3693 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3694 | rawRealtime, which); |
| 3695 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3696 | rawRealtime, which); |
| 3697 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3698 | rawRealtime, which); |
| 3699 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3700 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3701 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3702 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3703 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3704 | final int sensorNumber = sensors.keyAt(ise); |
| 3705 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3706 | if (timer != null) { |
| 3707 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3708 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3709 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3710 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3711 | final int count = timer.getCountLocked(which); |
| 3712 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3713 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3714 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3715 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3716 | final long bgActualTime = bgTimer != null ? |
| 3717 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3718 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3719 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3724 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3725 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3726 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 3727 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 3728 | rawRealtime, which); |
| 3729 | |
| 3730 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3731 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3732 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3733 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3734 | long totalStateTime = 0; |
| 3735 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3736 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3737 | totalStateTime += time; |
| 3738 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3739 | } |
| 3740 | if (totalStateTime > 0) { |
| 3741 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3742 | } |
| 3743 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3744 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3745 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3746 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3747 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3748 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3751 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 3752 | if (cpuFreqs != null) { |
| 3753 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3754 | // If total cpuFreqTimes is null, then we don't need to check for |
| 3755 | // screenOffCpuFreqTimes. |
| 3756 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 3757 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3758 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3759 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3760 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3761 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3762 | if (screenOffCpuFreqTimeMs != null) { |
| 3763 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3764 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3765 | } |
| 3766 | } else { |
| 3767 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3768 | sb.append(",0"); |
| 3769 | } |
| 3770 | } |
| 3771 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 3772 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3773 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3776 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3777 | = u.getProcessStats(); |
| 3778 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3779 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3780 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3781 | final long userMillis = ps.getUserTime(which); |
| 3782 | final long systemMillis = ps.getSystemTime(which); |
| 3783 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3784 | final int starts = ps.getStarts(which); |
| 3785 | final int numCrashes = ps.getNumCrashes(which); |
| 3786 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3787 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3788 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3789 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3790 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3791 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3795 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3796 | = u.getPackageStats(); |
| 3797 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3798 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3799 | int wakeups = 0; |
| 3800 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3801 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3802 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3803 | wakeups += count; |
| 3804 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3805 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3806 | } |
| 3807 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3808 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3809 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3810 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3811 | final int starts = ss.getStarts(which); |
| 3812 | final int launches = ss.getLaunches(which); |
| 3813 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3814 | dumpLine(pw, uid, category, APK_DATA, |
| 3815 | wakeups, // wakeup alarms |
| 3816 | packageStats.keyAt(ipkg), // Apk |
| 3817 | serviceStats.keyAt(isvc), // service |
| 3818 | startTime / 1000, // time spent started, in ms |
| 3819 | starts, |
| 3820 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | } |
| 3826 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3827 | static final class TimerEntry { |
| 3828 | final String mName; |
| 3829 | final int mId; |
| 3830 | final BatteryStats.Timer mTimer; |
| 3831 | final long mTime; |
| 3832 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3833 | mName = name; |
| 3834 | mId = id; |
| 3835 | mTimer = timer; |
| 3836 | mTime = time; |
| 3837 | } |
| 3838 | } |
| 3839 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3840 | private void printmAh(PrintWriter printer, double power) { |
| 3841 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3842 | } |
| 3843 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3844 | private void printmAh(StringBuilder sb, double power) { |
| 3845 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3846 | } |
| 3847 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3848 | /** |
| 3849 | * Temporary for settings. |
| 3850 | */ |
| 3851 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3852 | int reqUid) { |
| 3853 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3854 | } |
| 3855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3857 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3858 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3860 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3861 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | |
| 3864 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3865 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3866 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3867 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3868 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3869 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3870 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3871 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3872 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3873 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3874 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3875 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3876 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3877 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3878 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3880 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3881 | if (estimatedBatteryCapacity > 0) { |
| 3882 | sb.setLength(0); |
| 3883 | sb.append(prefix); |
| 3884 | sb.append(" Estimated battery capacity: "); |
| 3885 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3886 | sb.append(" mAh"); |
| 3887 | pw.println(sb.toString()); |
| 3888 | } |
| 3889 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3890 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3891 | if (minLearnedBatteryCapacity > 0) { |
| 3892 | sb.setLength(0); |
| 3893 | sb.append(prefix); |
| 3894 | sb.append(" Min learned battery capacity: "); |
| 3895 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3896 | sb.append(" mAh"); |
| 3897 | pw.println(sb.toString()); |
| 3898 | } |
| 3899 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3900 | if (maxLearnedBatteryCapacity > 0) { |
| 3901 | sb.setLength(0); |
| 3902 | sb.append(prefix); |
| 3903 | sb.append(" Max learned battery capacity: "); |
| 3904 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3905 | sb.append(" mAh"); |
| 3906 | pw.println(sb.toString()); |
| 3907 | } |
| 3908 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3909 | sb.setLength(0); |
| 3910 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3911 | sb.append(" Time on battery: "); |
| 3912 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3913 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3914 | sb.append(") realtime, "); |
| 3915 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3916 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 3917 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3918 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3919 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3920 | sb.setLength(0); |
| 3921 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3922 | sb.append(" Time on battery screen off: "); |
| 3923 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3924 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 3925 | sb.append(") realtime, "); |
| 3926 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3927 | sb.append("("); |
| 3928 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 3929 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3930 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3931 | |
| 3932 | sb.setLength(0); |
| 3933 | sb.append(prefix); |
| 3934 | sb.append(" Time on battery screen doze: "); |
| 3935 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 3936 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 3937 | sb.append(")"); |
| 3938 | pw.println(sb.toString()); |
| 3939 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3940 | sb.setLength(0); |
| 3941 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3942 | sb.append(" Total run time: "); |
| 3943 | formatTimeMs(sb, totalRealtime / 1000); |
| 3944 | sb.append("realtime, "); |
| 3945 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3946 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3947 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3948 | if (batteryTimeRemaining >= 0) { |
| 3949 | sb.setLength(0); |
| 3950 | sb.append(prefix); |
| 3951 | sb.append(" Battery time remaining: "); |
| 3952 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3953 | pw.println(sb.toString()); |
| 3954 | } |
| 3955 | if (chargeTimeRemaining >= 0) { |
| 3956 | sb.setLength(0); |
| 3957 | sb.append(prefix); |
| 3958 | sb.append(" Charge time remaining: "); |
| 3959 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3960 | pw.println(sb.toString()); |
| 3961 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3962 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3963 | final long dischargeCount = getMahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3964 | if (dischargeCount >= 0) { |
| 3965 | sb.setLength(0); |
| 3966 | sb.append(prefix); |
| 3967 | sb.append(" Discharge: "); |
| 3968 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3969 | sb.append(" mAh"); |
| 3970 | pw.println(sb.toString()); |
| 3971 | } |
| 3972 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3973 | final long dischargeScreenOffCount = getMahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3974 | if (dischargeScreenOffCount >= 0) { |
| 3975 | sb.setLength(0); |
| 3976 | sb.append(prefix); |
| 3977 | sb.append(" Screen off discharge: "); |
| 3978 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3979 | sb.append(" mAh"); |
| 3980 | pw.println(sb.toString()); |
| 3981 | } |
| 3982 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 3983 | final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which); |
| 3984 | if (dischargeScreenDozeCount >= 0) { |
| 3985 | sb.setLength(0); |
| 3986 | sb.append(prefix); |
| 3987 | sb.append(" Screen doze discharge: "); |
| 3988 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 3989 | sb.append(" mAh"); |
| 3990 | pw.println(sb.toString()); |
| 3991 | } |
| 3992 | |
| 3993 | final long dischargeScreenOnCount = |
| 3994 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3995 | if (dischargeScreenOnCount >= 0) { |
| 3996 | sb.setLength(0); |
| 3997 | sb.append(prefix); |
| 3998 | sb.append(" Screen on discharge: "); |
| 3999 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4000 | sb.append(" mAh"); |
| 4001 | pw.println(sb.toString()); |
| 4002 | } |
| 4003 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4004 | pw.print(" Start clock time: "); |
| 4005 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4006 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4007 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4008 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4009 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4010 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4011 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4012 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4013 | rawRealtime, which); |
| 4014 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4015 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4016 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4017 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4018 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4019 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4020 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4021 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4022 | sb.append(prefix); |
| 4023 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4024 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4025 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4026 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4027 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4028 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4029 | pw.println(sb.toString()); |
| 4030 | sb.setLength(0); |
| 4031 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4032 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4033 | boolean didOne = false; |
| 4034 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4035 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4036 | if (time == 0) { |
| 4037 | continue; |
| 4038 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4039 | sb.append("\n "); |
| 4040 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4041 | didOne = true; |
| 4042 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4043 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4044 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4045 | sb.append("("); |
| 4046 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4047 | sb.append(")"); |
| 4048 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4049 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4050 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4051 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4052 | sb.setLength(0); |
| 4053 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4054 | sb.append(" Power save mode enabled: "); |
| 4055 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4056 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4057 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4058 | sb.append(")"); |
| 4059 | pw.println(sb.toString()); |
| 4060 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4061 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4062 | sb.setLength(0); |
| 4063 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4064 | sb.append(" Device light idling: "); |
| 4065 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4066 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4067 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4068 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4069 | sb.append("x"); |
| 4070 | pw.println(sb.toString()); |
| 4071 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4072 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4073 | sb.setLength(0); |
| 4074 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4075 | sb.append(" Idle mode light time: "); |
| 4076 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4077 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4078 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4079 | sb.append(") "); |
| 4080 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4081 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4082 | sb.append(" -- longest "); |
| 4083 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4084 | pw.println(sb.toString()); |
| 4085 | } |
| 4086 | if (deviceIdlingTime != 0) { |
| 4087 | sb.setLength(0); |
| 4088 | sb.append(prefix); |
| 4089 | sb.append(" Device full idling: "); |
| 4090 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4091 | sb.append("("); |
| 4092 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4093 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4094 | sb.append("x"); |
| 4095 | pw.println(sb.toString()); |
| 4096 | } |
| 4097 | if (deviceIdleModeFullTime != 0) { |
| 4098 | sb.setLength(0); |
| 4099 | sb.append(prefix); |
| 4100 | sb.append(" Idle mode full time: "); |
| 4101 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4102 | sb.append("("); |
| 4103 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4104 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4105 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4106 | sb.append("x"); |
| 4107 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4108 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4109 | pw.println(sb.toString()); |
| 4110 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4111 | if (phoneOnTime != 0) { |
| 4112 | sb.setLength(0); |
| 4113 | sb.append(prefix); |
| 4114 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4115 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4116 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4117 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4118 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4119 | if (connChanges != 0) { |
| 4120 | pw.print(prefix); |
| 4121 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4122 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4123 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4124 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4125 | long fullWakeLockTimeTotalMicros = 0; |
| 4126 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4127 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4128 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4129 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4130 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4131 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4132 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4133 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4134 | = u.getWakelockStats(); |
| 4135 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4136 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4137 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4138 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4139 | if (fullWakeTimer != null) { |
| 4140 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4141 | rawRealtime, which); |
| 4142 | } |
| 4143 | |
| 4144 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4145 | if (partialWakeTimer != null) { |
| 4146 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4147 | rawRealtime, which); |
| 4148 | if (totalTimeMicros > 0) { |
| 4149 | if (reqUid < 0) { |
| 4150 | // Only show the ordered list of all wake |
| 4151 | // locks if the caller is not asking for data |
| 4152 | // about a specific uid. |
| 4153 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4154 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4155 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4156 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4157 | } |
| 4158 | } |
| 4159 | } |
| 4160 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4161 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4162 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4163 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4164 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4165 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4166 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4167 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4168 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4169 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4170 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4171 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4172 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4173 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4174 | sb.setLength(0); |
| 4175 | sb.append(prefix); |
| 4176 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4177 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4178 | pw.println(sb.toString()); |
| 4179 | } |
| 4180 | |
| 4181 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4182 | sb.setLength(0); |
| 4183 | sb.append(prefix); |
| 4184 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4185 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4186 | pw.println(sb.toString()); |
| 4187 | } |
| 4188 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4189 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4190 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 4191 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 4192 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 4193 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4194 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4195 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4196 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4197 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4198 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4199 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4200 | if (time == 0) { |
| 4201 | continue; |
| 4202 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4203 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4204 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4205 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4206 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4207 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4208 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4209 | sb.append("("); |
| 4210 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4211 | sb.append(") "); |
| 4212 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 4213 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4214 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4215 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4216 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4217 | |
| 4218 | sb.setLength(0); |
| 4219 | sb.append(prefix); |
| 4220 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4221 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4222 | pw.println(sb.toString()); |
| 4223 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4224 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4225 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4226 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4227 | didOne = false; |
| 4228 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4229 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4230 | if (time == 0) { |
| 4231 | continue; |
| 4232 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4233 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4234 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4235 | didOne = true; |
| 4236 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4237 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4238 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4239 | sb.append("("); |
| 4240 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4241 | sb.append(") "); |
| 4242 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 4243 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4244 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4245 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4246 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4247 | |
| 4248 | sb.setLength(0); |
| 4249 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4250 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4251 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4252 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4253 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4254 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 4255 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4256 | pw.println(sb.toString()); |
| 4257 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4258 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 4259 | if (mobileActiveUnknownTime != 0) { |
| 4260 | sb.setLength(0); |
| 4261 | sb.append(prefix); |
| 4262 | sb.append(" Mobile radio active unknown time: "); |
| 4263 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 4264 | sb.append("("); |
| 4265 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 4266 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 4267 | sb.append("x"); |
| 4268 | pw.println(sb.toString()); |
| 4269 | } |
| 4270 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4271 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 4272 | if (mobileActiveAdjustedTime != 0) { |
| 4273 | sb.setLength(0); |
| 4274 | sb.append(prefix); |
| 4275 | sb.append(" Mobile radio active adjusted time: "); |
| 4276 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 4277 | sb.append("("); |
| 4278 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 4279 | sb.append(")"); |
| 4280 | pw.println(sb.toString()); |
| 4281 | } |
| 4282 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4283 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 4284 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4285 | pw.print(prefix); |
| 4286 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 4287 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 4288 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 4289 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4290 | sb.setLength(0); |
| 4291 | sb.append(prefix); |
| 4292 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 4293 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 4294 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 4295 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4296 | sb.append(")"); |
| 4297 | pw.println(sb.toString()); |
| 4298 | |
| 4299 | sb.setLength(0); |
| 4300 | sb.append(prefix); |
| 4301 | sb.append(" Wifi states:"); |
| 4302 | didOne = false; |
| 4303 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4304 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4305 | if (time == 0) { |
| 4306 | continue; |
| 4307 | } |
| 4308 | sb.append("\n "); |
| 4309 | didOne = true; |
| 4310 | sb.append(WIFI_STATE_NAMES[i]); |
| 4311 | sb.append(" "); |
| 4312 | formatTimeMs(sb, time/1000); |
| 4313 | sb.append("("); |
| 4314 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4315 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4316 | sb.append(getWifiStateCount(i, which)); |
| 4317 | sb.append("x"); |
| 4318 | } |
| 4319 | if (!didOne) sb.append(" (no activity)"); |
| 4320 | pw.println(sb.toString()); |
| 4321 | |
| 4322 | sb.setLength(0); |
| 4323 | sb.append(prefix); |
| 4324 | sb.append(" Wifi supplicant states:"); |
| 4325 | didOne = false; |
| 4326 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4327 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4328 | if (time == 0) { |
| 4329 | continue; |
| 4330 | } |
| 4331 | sb.append("\n "); |
| 4332 | didOne = true; |
| 4333 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4334 | sb.append(" "); |
| 4335 | formatTimeMs(sb, time/1000); |
| 4336 | sb.append("("); |
| 4337 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4338 | sb.append(") "); |
| 4339 | sb.append(getWifiSupplStateCount(i, which)); |
| 4340 | sb.append("x"); |
| 4341 | } |
| 4342 | if (!didOne) sb.append(" (no activity)"); |
| 4343 | pw.println(sb.toString()); |
| 4344 | |
| 4345 | sb.setLength(0); |
| 4346 | sb.append(prefix); |
| 4347 | sb.append(" Wifi signal levels:"); |
| 4348 | didOne = false; |
| 4349 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4350 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4351 | if (time == 0) { |
| 4352 | continue; |
| 4353 | } |
| 4354 | sb.append("\n "); |
| 4355 | sb.append(prefix); |
| 4356 | didOne = true; |
| 4357 | sb.append("level("); |
| 4358 | sb.append(i); |
| 4359 | sb.append(") "); |
| 4360 | formatTimeMs(sb, time/1000); |
| 4361 | sb.append("("); |
| 4362 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4363 | sb.append(") "); |
| 4364 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4365 | sb.append("x"); |
| 4366 | } |
| 4367 | if (!didOne) sb.append(" (no activity)"); |
| 4368 | pw.println(sb.toString()); |
| 4369 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4370 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4371 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4372 | pw.print(prefix); |
| 4373 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4374 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4375 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4376 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4377 | sb.setLength(0); |
| 4378 | sb.append(prefix); |
| 4379 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4380 | pw.println(sb.toString()); |
| 4381 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4382 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4383 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4384 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4385 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4386 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4387 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4388 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4389 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4390 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4391 | pw.println(getDischargeStartLevel()); |
| 4392 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4393 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4394 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4395 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4396 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4397 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4398 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4399 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4400 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4401 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4402 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4403 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4404 | pw.println(getDischargeAmountScreenOff()); |
| 4405 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4406 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4407 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4408 | } else { |
| 4409 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4410 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4411 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4412 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4413 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4414 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4415 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4416 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 4417 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4418 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4419 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4420 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4421 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4422 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4423 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4424 | helper.create(this); |
| 4425 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4426 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4427 | if (sippers != null && sippers.size() > 0) { |
| 4428 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4429 | pw.print(prefix); pw.print(" Capacity: "); |
| 4430 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4431 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4432 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4433 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4434 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4435 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4436 | pw.println(); |
| 4437 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4438 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4439 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4440 | switch (bs.drainType) { |
| 4441 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4442 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4443 | break; |
| 4444 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4445 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4446 | break; |
| 4447 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4448 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4449 | break; |
| 4450 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4451 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4452 | break; |
| 4453 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4454 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4455 | break; |
| 4456 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4457 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4458 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4459 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4460 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4461 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4462 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4463 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4464 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4465 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4466 | break; |
| 4467 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4468 | pw.print(" User "); pw.print(bs.userId); |
| 4469 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4470 | break; |
| 4471 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4472 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4473 | break; |
| 4474 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4475 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4476 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4477 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4478 | pw.print(" Camera: "); |
| 4479 | break; |
| 4480 | default: |
| 4481 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4482 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4483 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4484 | printmAh(pw, bs.totalPowerMah); |
| 4485 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4486 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4487 | // If the usage (generic power) isn't the whole amount, we list out |
| 4488 | // what components are involved in the calculation. |
| 4489 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4490 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4491 | if (bs.usagePowerMah != 0) { |
| 4492 | pw.print(" usage="); |
| 4493 | printmAh(pw, bs.usagePowerMah); |
| 4494 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4495 | if (bs.cpuPowerMah != 0) { |
| 4496 | pw.print(" cpu="); |
| 4497 | printmAh(pw, bs.cpuPowerMah); |
| 4498 | } |
| 4499 | if (bs.wakeLockPowerMah != 0) { |
| 4500 | pw.print(" wake="); |
| 4501 | printmAh(pw, bs.wakeLockPowerMah); |
| 4502 | } |
| 4503 | if (bs.mobileRadioPowerMah != 0) { |
| 4504 | pw.print(" radio="); |
| 4505 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4506 | } |
| 4507 | if (bs.wifiPowerMah != 0) { |
| 4508 | pw.print(" wifi="); |
| 4509 | printmAh(pw, bs.wifiPowerMah); |
| 4510 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4511 | if (bs.bluetoothPowerMah != 0) { |
| 4512 | pw.print(" bt="); |
| 4513 | printmAh(pw, bs.bluetoothPowerMah); |
| 4514 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4515 | if (bs.gpsPowerMah != 0) { |
| 4516 | pw.print(" gps="); |
| 4517 | printmAh(pw, bs.gpsPowerMah); |
| 4518 | } |
| 4519 | if (bs.sensorPowerMah != 0) { |
| 4520 | pw.print(" sensor="); |
| 4521 | printmAh(pw, bs.sensorPowerMah); |
| 4522 | } |
| 4523 | if (bs.cameraPowerMah != 0) { |
| 4524 | pw.print(" camera="); |
| 4525 | printmAh(pw, bs.cameraPowerMah); |
| 4526 | } |
| 4527 | if (bs.flashlightPowerMah != 0) { |
| 4528 | pw.print(" flash="); |
| 4529 | printmAh(pw, bs.flashlightPowerMah); |
| 4530 | } |
| 4531 | pw.print(" )"); |
| 4532 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4533 | |
| 4534 | // If there is additional smearing information, include it. |
| 4535 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4536 | pw.print(" Including smearing: "); |
| 4537 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4538 | pw.print(" ("); |
| 4539 | if (bs.screenPowerMah != 0) { |
| 4540 | pw.print(" screen="); |
| 4541 | printmAh(pw, bs.screenPowerMah); |
| 4542 | } |
| 4543 | if (bs.proportionalSmearMah != 0) { |
| 4544 | pw.print(" proportional="); |
| 4545 | printmAh(pw, bs.proportionalSmearMah); |
| 4546 | } |
| 4547 | pw.print(" )"); |
| 4548 | } |
| 4549 | if (bs.shouldHide) { |
| 4550 | pw.print(" Excluded from smearing"); |
| 4551 | } |
| 4552 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4553 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4554 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4555 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4556 | } |
| 4557 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4558 | sippers = helper.getMobilemsppList(); |
| 4559 | if (sippers != null && sippers.size() > 0) { |
| 4560 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4561 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4562 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4563 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4564 | sb.setLength(0); |
| 4565 | sb.append(prefix); sb.append(" Uid "); |
| 4566 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4567 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4568 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4569 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4570 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4571 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4572 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4573 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4574 | sb.setLength(0); |
| 4575 | sb.append(prefix); |
| 4576 | sb.append(" TOTAL TIME: "); |
| 4577 | formatTimeMs(sb, totalTime); |
| 4578 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4579 | sb.append(")"); |
| 4580 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4581 | pw.println(); |
| 4582 | } |
| 4583 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4584 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4585 | @Override |
| 4586 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4587 | long lhsTime = lhs.mTime; |
| 4588 | long rhsTime = rhs.mTime; |
| 4589 | if (lhsTime < rhsTime) { |
| 4590 | return 1; |
| 4591 | } |
| 4592 | if (lhsTime > rhsTime) { |
| 4593 | return -1; |
| 4594 | } |
| 4595 | return 0; |
| 4596 | } |
| 4597 | }; |
| 4598 | |
| 4599 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4600 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4601 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4602 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4603 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4604 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4605 | : kernelWakelocks.entrySet()) { |
| 4606 | final BatteryStats.Timer timer = ent.getValue(); |
| 4607 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4608 | if (totalTimeMillis > 0) { |
| 4609 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4610 | } |
| 4611 | } |
| 4612 | if (ktimers.size() > 0) { |
| 4613 | Collections.sort(ktimers, timerComparator); |
| 4614 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4615 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4616 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4617 | String linePrefix = ": "; |
| 4618 | sb.setLength(0); |
| 4619 | sb.append(prefix); |
| 4620 | sb.append(" Kernel Wake lock "); |
| 4621 | sb.append(timer.mName); |
| 4622 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4623 | which, linePrefix); |
| 4624 | if (!linePrefix.equals(": ")) { |
| 4625 | sb.append(" realtime"); |
| 4626 | // Only print out wake locks that were held |
| 4627 | pw.println(sb.toString()); |
| 4628 | } |
| 4629 | } |
| 4630 | pw.println(); |
| 4631 | } |
| 4632 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4633 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4634 | if (timers.size() > 0) { |
| 4635 | Collections.sort(timers, timerComparator); |
| 4636 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4637 | for (int i=0; i<timers.size(); i++) { |
| 4638 | TimerEntry timer = timers.get(i); |
| 4639 | sb.setLength(0); |
| 4640 | sb.append(" Wake lock "); |
| 4641 | UserHandle.formatUid(sb, timer.mId); |
| 4642 | sb.append(" "); |
| 4643 | sb.append(timer.mName); |
| 4644 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4645 | sb.append(" realtime"); |
| 4646 | pw.println(sb.toString()); |
| 4647 | } |
| 4648 | timers.clear(); |
| 4649 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4650 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4651 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4652 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4653 | if (wakeupReasons.size() > 0) { |
| 4654 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4655 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4656 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4657 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4658 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4659 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4660 | } |
| 4661 | Collections.sort(reasons, timerComparator); |
| 4662 | for (int i=0; i<reasons.size(); i++) { |
| 4663 | TimerEntry timer = reasons.get(i); |
| 4664 | String linePrefix = ": "; |
| 4665 | sb.setLength(0); |
| 4666 | sb.append(prefix); |
| 4667 | sb.append(" Wakeup reason "); |
| 4668 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4669 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4670 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4671 | pw.println(sb.toString()); |
| 4672 | } |
| 4673 | pw.println(); |
| 4674 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4675 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4676 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4677 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4678 | if (mMemoryStats.size() > 0) { |
| 4679 | pw.println(" Memory Stats"); |
| 4680 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4681 | sb.setLength(0); |
| 4682 | sb.append(" Bandwidth "); |
| 4683 | sb.append(mMemoryStats.keyAt(i)); |
| 4684 | sb.append(" Time "); |
| 4685 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4686 | pw.println(sb.toString()); |
| 4687 | } |
| 4688 | pw.println(); |
| 4689 | } |
| 4690 | |
| 4691 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 4692 | if (rpmStats.size() > 0) { |
| 4693 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 4694 | if (rpmStats.size() > 0) { |
| 4695 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 4696 | final String timerName = ent.getKey(); |
| 4697 | final Timer timer = ent.getValue(); |
| 4698 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4699 | } |
| 4700 | } |
| 4701 | pw.println(); |
| 4702 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4703 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 4704 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4705 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4706 | pw.print(prefix); |
| 4707 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 4708 | if (screenOffRpmStats.size() > 0) { |
| 4709 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 4710 | final String timerName = ent.getKey(); |
| 4711 | final Timer timer = ent.getValue(); |
| 4712 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4713 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4714 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4715 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4716 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4719 | final long[] cpuFreqs = getCpuFreqs(); |
| 4720 | if (cpuFreqs != null) { |
| 4721 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4722 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4723 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4724 | sb.append(" " + cpuFreqs[i]); |
| 4725 | } |
| 4726 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4727 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4728 | } |
| 4729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | for (int iu=0; iu<NU; iu++) { |
| 4731 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4732 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4733 | continue; |
| 4734 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4735 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4736 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4737 | |
| 4738 | pw.print(prefix); |
| 4739 | pw.print(" "); |
| 4740 | UserHandle.formatUid(pw, uid); |
| 4741 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4742 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4743 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4744 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4745 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4746 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4747 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4748 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4749 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4750 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4751 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4752 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4753 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4754 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4755 | |
| 4756 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4757 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4758 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4759 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4760 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4761 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4762 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4763 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4764 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4765 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4766 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4767 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4768 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4769 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4770 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4771 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4772 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4773 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4774 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4775 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4776 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4777 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4779 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4780 | sb.setLength(0); |
| 4781 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4782 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4783 | sb.append("("); |
| 4784 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4785 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4786 | long packets = mobileRxPackets + mobileTxPackets; |
| 4787 | if (packets == 0) { |
| 4788 | packets = 1; |
| 4789 | } |
| 4790 | sb.append(" @ "); |
| 4791 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4792 | sb.append(" mspp"); |
| 4793 | pw.println(sb.toString()); |
| 4794 | } |
| 4795 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4796 | if (mobileWakeup > 0) { |
| 4797 | sb.setLength(0); |
| 4798 | sb.append(prefix); |
| 4799 | sb.append(" Mobile radio AP wakeups: "); |
| 4800 | sb.append(mobileWakeup); |
| 4801 | pw.println(sb.toString()); |
| 4802 | } |
| 4803 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4804 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4805 | u.getModemControllerActivity(), which); |
| 4806 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4807 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4808 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4809 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4810 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4811 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4812 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4815 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4816 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4817 | || uidWifiRunningTime != 0) { |
| 4818 | sb.setLength(0); |
| 4819 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4820 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4821 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4822 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4823 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4824 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4825 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4826 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4827 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4828 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4829 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4830 | whichBatteryRealtime)); sb.append(") "); |
| 4831 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4832 | sb.append("x\n"); |
| 4833 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4834 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4835 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4836 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4837 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4838 | sb.append(") "); |
| 4839 | sb.append(wifiScanCount); |
| 4840 | sb.append("x\n"); |
| 4841 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4842 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4843 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4844 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4845 | sb.append(") "); |
| 4846 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4847 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4848 | pw.println(sb.toString()); |
| 4849 | } |
| 4850 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4851 | if (wifiWakeup > 0) { |
| 4852 | sb.setLength(0); |
| 4853 | sb.append(prefix); |
| 4854 | sb.append(" WiFi AP wakeups: "); |
| 4855 | sb.append(wifiWakeup); |
| 4856 | pw.println(sb.toString()); |
| 4857 | } |
| 4858 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4859 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4860 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4861 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4862 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4863 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4864 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4865 | pw.print(formatBytesLocked(btTxBytes)); |
| 4866 | pw.println(" sent"); |
| 4867 | } |
| 4868 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4869 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4870 | if (bleTimer != null) { |
| 4871 | // Convert from microseconds to milliseconds with rounding |
| 4872 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4873 | / 1000; |
| 4874 | if (totalTimeMs != 0) { |
| 4875 | final int count = bleTimer.getCountLocked(which); |
| 4876 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4877 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4878 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4879 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4880 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4881 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4882 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4883 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4884 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4885 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 4886 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 4887 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 4888 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 4889 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 4890 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4891 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 4892 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 4893 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 4894 | final Timer unoptimizedScanTimerBg = |
| 4895 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 4896 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 4897 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4898 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 4899 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4900 | |
| 4901 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4902 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4903 | sb.append(prefix); |
| 4904 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4905 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4906 | sb.append(" ("); |
| 4907 | sb.append(count); |
| 4908 | sb.append(" times)"); |
| 4909 | if (bleTimer.isRunningLocked()) { |
| 4910 | sb.append(" (currently running)"); |
| 4911 | } |
| 4912 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4913 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4914 | |
| 4915 | sb.append(prefix); |
| 4916 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 4917 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 4918 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4919 | sb.append(count); |
| 4920 | sb.append(" times)"); |
| 4921 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4922 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4923 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4924 | sb.append("\n"); |
| 4925 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 4926 | sb.append(prefix); |
| 4927 | sb.append(" Bluetooth Scan (background realtime): "); |
| 4928 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 4929 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4930 | sb.append(countBg); |
| 4931 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4932 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 4933 | sb.append(" (currently running in background)"); |
| 4934 | } |
| 4935 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4936 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4937 | |
| 4938 | sb.append(prefix); |
| 4939 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4940 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4941 | sb.append(" ("); |
| 4942 | sb.append(resultCountBg); |
| 4943 | sb.append(" in background)"); |
| 4944 | |
| 4945 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 4946 | sb.append("\n"); |
| 4947 | sb.append(prefix); |
| 4948 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 4949 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 4950 | sb.append(" (max "); |
| 4951 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 4952 | sb.append(")"); |
| 4953 | if (unoptimizedScanTimer != null |
| 4954 | && unoptimizedScanTimer.isRunningLocked()) { |
| 4955 | sb.append(" (currently running unoptimized)"); |
| 4956 | } |
| 4957 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 4958 | sb.append("\n"); |
| 4959 | sb.append(prefix); |
| 4960 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 4961 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 4962 | sb.append(" (max "); |
| 4963 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 4964 | sb.append(")"); |
| 4965 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 4966 | sb.append(" (currently running unoptimized in background)"); |
| 4967 | } |
| 4968 | } |
| 4969 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4970 | pw.println(sb.toString()); |
| 4971 | uidActivity = true; |
| 4972 | } |
| 4973 | } |
| 4974 | |
| 4975 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4976 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4977 | if (u.hasUserActivity()) { |
| 4978 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4979 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4980 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4981 | if (val != 0) { |
| 4982 | if (!hasData) { |
| 4983 | sb.setLength(0); |
| 4984 | sb.append(" User activity: "); |
| 4985 | hasData = true; |
| 4986 | } else { |
| 4987 | sb.append(", "); |
| 4988 | } |
| 4989 | sb.append(val); |
| 4990 | sb.append(" "); |
| 4991 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4992 | } |
| 4993 | } |
| 4994 | if (hasData) { |
| 4995 | pw.println(sb.toString()); |
| 4996 | } |
| 4997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4998 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4999 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5000 | = u.getWakelockStats(); |
| 5001 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5002 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5003 | int countWakelock = 0; |
| 5004 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5005 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5006 | String linePrefix = ": "; |
| 5007 | sb.setLength(0); |
| 5008 | sb.append(prefix); |
| 5009 | sb.append(" Wake lock "); |
| 5010 | sb.append(wakelocks.keyAt(iw)); |
| 5011 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5012 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5013 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5014 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5015 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5016 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5017 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5018 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5019 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5020 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5021 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5022 | sb.append(" realtime"); |
| 5023 | pw.println(sb.toString()); |
| 5024 | uidActivity = true; |
| 5025 | countWakelock++; |
| 5026 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5027 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5028 | rawRealtime, which); |
| 5029 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5030 | rawRealtime, which); |
| 5031 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5032 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5033 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5034 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5035 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5036 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5037 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5038 | // pooled and therefore just a lower bound) |
| 5039 | long actualTotalPartialWakelock = 0; |
| 5040 | long actualBgPartialWakelock = 0; |
| 5041 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5042 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5043 | // Convert from microseconds to milliseconds with rounding |
| 5044 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5045 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5046 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5047 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5048 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5052 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5053 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5054 | sb.setLength(0); |
| 5055 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5056 | sb.append(" TOTAL wake: "); |
| 5057 | boolean needComma = false; |
| 5058 | if (totalFullWakelock != 0) { |
| 5059 | needComma = true; |
| 5060 | formatTimeMs(sb, totalFullWakelock); |
| 5061 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5062 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5063 | if (totalPartialWakelock != 0) { |
| 5064 | if (needComma) { |
| 5065 | sb.append(", "); |
| 5066 | } |
| 5067 | needComma = true; |
| 5068 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5069 | sb.append("blamed partial"); |
| 5070 | } |
| 5071 | if (actualTotalPartialWakelock != 0) { |
| 5072 | if (needComma) { |
| 5073 | sb.append(", "); |
| 5074 | } |
| 5075 | needComma = true; |
| 5076 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5077 | sb.append("actual partial"); |
| 5078 | } |
| 5079 | if (actualBgPartialWakelock != 0) { |
| 5080 | if (needComma) { |
| 5081 | sb.append(", "); |
| 5082 | } |
| 5083 | needComma = true; |
| 5084 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5085 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5086 | } |
| 5087 | if (totalWindowWakelock != 0) { |
| 5088 | if (needComma) { |
| 5089 | sb.append(", "); |
| 5090 | } |
| 5091 | needComma = true; |
| 5092 | formatTimeMs(sb, totalWindowWakelock); |
| 5093 | sb.append("window"); |
| 5094 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5095 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5096 | if (needComma) { |
| 5097 | sb.append(","); |
| 5098 | } |
| 5099 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5100 | formatTimeMs(sb, totalDrawWakelock); |
| 5101 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5102 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5103 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5104 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5105 | } |
| 5106 | } |
| 5107 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5108 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5109 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5110 | final Timer timer = syncs.valueAt(isy); |
| 5111 | // Convert from microseconds to milliseconds with rounding |
| 5112 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5113 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5114 | final Timer bgTimer = timer.getSubTimer(); |
| 5115 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5116 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5117 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5118 | sb.setLength(0); |
| 5119 | sb.append(prefix); |
| 5120 | sb.append(" Sync "); |
| 5121 | sb.append(syncs.keyAt(isy)); |
| 5122 | sb.append(": "); |
| 5123 | if (totalTime != 0) { |
| 5124 | formatTimeMs(sb, totalTime); |
| 5125 | sb.append("realtime ("); |
| 5126 | sb.append(count); |
| 5127 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5128 | if (bgTime > 0) { |
| 5129 | sb.append(", "); |
| 5130 | formatTimeMs(sb, bgTime); |
| 5131 | sb.append("background ("); |
| 5132 | sb.append(bgCount); |
| 5133 | sb.append(" times)"); |
| 5134 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5135 | } else { |
| 5136 | sb.append("(not used)"); |
| 5137 | } |
| 5138 | pw.println(sb.toString()); |
| 5139 | uidActivity = true; |
| 5140 | } |
| 5141 | |
| 5142 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5143 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5144 | final Timer timer = jobs.valueAt(ij); |
| 5145 | // Convert from microseconds to milliseconds with rounding |
| 5146 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5147 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5148 | final Timer bgTimer = timer.getSubTimer(); |
| 5149 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5150 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5151 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5152 | sb.setLength(0); |
| 5153 | sb.append(prefix); |
| 5154 | sb.append(" Job "); |
| 5155 | sb.append(jobs.keyAt(ij)); |
| 5156 | sb.append(": "); |
| 5157 | if (totalTime != 0) { |
| 5158 | formatTimeMs(sb, totalTime); |
| 5159 | sb.append("realtime ("); |
| 5160 | sb.append(count); |
| 5161 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5162 | if (bgTime > 0) { |
| 5163 | sb.append(", "); |
| 5164 | formatTimeMs(sb, bgTime); |
| 5165 | sb.append("background ("); |
| 5166 | sb.append(bgCount); |
| 5167 | sb.append(" times)"); |
| 5168 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5169 | } else { |
| 5170 | sb.append("(not used)"); |
| 5171 | } |
| 5172 | pw.println(sb.toString()); |
| 5173 | uidActivity = true; |
| 5174 | } |
| 5175 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5176 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5177 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5178 | SparseIntArray types = completions.valueAt(ic); |
| 5179 | if (types != null) { |
| 5180 | pw.print(prefix); |
| 5181 | pw.print(" Job Completions "); |
| 5182 | pw.print(completions.keyAt(ic)); |
| 5183 | pw.print(":"); |
| 5184 | for (int it=0; it<types.size(); it++) { |
| 5185 | pw.print(" "); |
| 5186 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5187 | pw.print("("); |
| 5188 | pw.print(types.valueAt(it)); |
| 5189 | pw.print("x)"); |
| 5190 | } |
| 5191 | pw.println(); |
| 5192 | } |
| 5193 | } |
| 5194 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5195 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5196 | prefix, "Flashlight"); |
| 5197 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5198 | prefix, "Camera"); |
| 5199 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5200 | prefix, "Video"); |
| 5201 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5202 | prefix, "Audio"); |
| 5203 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5204 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5205 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5206 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5207 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5208 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5209 | sb.setLength(0); |
| 5210 | sb.append(prefix); |
| 5211 | sb.append(" Sensor "); |
| 5212 | int handle = se.getHandle(); |
| 5213 | if (handle == Uid.Sensor.GPS) { |
| 5214 | sb.append("GPS"); |
| 5215 | } else { |
| 5216 | sb.append(handle); |
| 5217 | } |
| 5218 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5219 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5220 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5221 | if (timer != null) { |
| 5222 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5223 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5224 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5225 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5226 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5227 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5228 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5229 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5230 | final long bgActualTime = bgTimer != null ? |
| 5231 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5232 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5233 | //timer.logState(); |
| 5234 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5235 | if (actualTime != totalTime) { |
| 5236 | formatTimeMs(sb, totalTime); |
| 5237 | sb.append("blamed realtime, "); |
| 5238 | } |
| 5239 | |
| 5240 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5241 | sb.append("realtime ("); |
| 5242 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5243 | sb.append(" times)"); |
| 5244 | |
| 5245 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5246 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5247 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5248 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5249 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5250 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | } else { |
| 5253 | sb.append("(not used)"); |
| 5254 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5255 | } else { |
| 5256 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5257 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5258 | |
| 5259 | pw.println(sb.toString()); |
| 5260 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5263 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5264 | "Vibrator"); |
| 5265 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5266 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5267 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5268 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5269 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5270 | long totalStateTime = 0; |
| 5271 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5272 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5273 | if (time > 0) { |
| 5274 | totalStateTime += time; |
| 5275 | sb.setLength(0); |
| 5276 | sb.append(prefix); |
| 5277 | sb.append(" "); |
| 5278 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5279 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5280 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5281 | pw.println(sb.toString()); |
| 5282 | uidActivity = true; |
| 5283 | } |
| 5284 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5285 | if (totalStateTime > 0) { |
| 5286 | sb.setLength(0); |
| 5287 | sb.append(prefix); |
| 5288 | sb.append(" Total running: "); |
| 5289 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5290 | pw.println(sb.toString()); |
| 5291 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5292 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5293 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5294 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5295 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5296 | sb.setLength(0); |
| 5297 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5298 | sb.append(" Total cpu time: u="); |
| 5299 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5300 | sb.append("s="); |
| 5301 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5302 | pw.println(sb.toString()); |
| 5303 | } |
| 5304 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5305 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5306 | if (cpuFreqTimes != null) { |
| 5307 | sb.setLength(0); |
| 5308 | sb.append(" Total cpu time per freq:"); |
| 5309 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5310 | sb.append(" " + cpuFreqTimes[i]); |
| 5311 | } |
| 5312 | pw.println(sb.toString()); |
| 5313 | } |
| 5314 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5315 | if (screenOffCpuFreqTimes != null) { |
| 5316 | sb.setLength(0); |
| 5317 | sb.append(" Total screen-off cpu time per freq:"); |
| 5318 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5319 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5320 | } |
| 5321 | pw.println(sb.toString()); |
| 5322 | } |
| 5323 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5324 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5325 | = u.getProcessStats(); |
| 5326 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5327 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5328 | long userTime; |
| 5329 | long systemTime; |
| 5330 | long foregroundTime; |
| 5331 | int starts; |
| 5332 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5334 | userTime = ps.getUserTime(which); |
| 5335 | systemTime = ps.getSystemTime(which); |
| 5336 | foregroundTime = ps.getForegroundTime(which); |
| 5337 | starts = ps.getStarts(which); |
| 5338 | final int numCrashes = ps.getNumCrashes(which); |
| 5339 | final int numAnrs = ps.getNumAnrs(which); |
| 5340 | numExcessive = which == STATS_SINCE_CHARGED |
| 5341 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5343 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5344 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5345 | sb.setLength(0); |
| 5346 | sb.append(prefix); sb.append(" Proc "); |
| 5347 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5348 | sb.append(prefix); sb.append(" CPU: "); |
| 5349 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5350 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5351 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5352 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5353 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5354 | boolean hasOne = false; |
| 5355 | if (starts != 0) { |
| 5356 | hasOne = true; |
| 5357 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5358 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5359 | if (numCrashes != 0) { |
| 5360 | if (hasOne) { |
| 5361 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5362 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5363 | hasOne = true; |
| 5364 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5365 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5366 | if (numAnrs != 0) { |
| 5367 | if (hasOne) { |
| 5368 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5370 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | } |
| 5372 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5373 | pw.println(sb.toString()); |
| 5374 | for (int e=0; e<numExcessive; e++) { |
| 5375 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5376 | if (ew != null) { |
| 5377 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5378 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5379 | pw.print("cpu"); |
| 5380 | } else { |
| 5381 | pw.print("unknown"); |
| 5382 | } |
| 5383 | pw.print(" use: "); |
| 5384 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5385 | pw.print(" over "); |
| 5386 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5387 | if (ew.overTime != 0) { |
| 5388 | pw.print(" ("); |
| 5389 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5390 | pw.println("%)"); |
| 5391 | } |
| 5392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | } |
| 5394 | uidActivity = true; |
| 5395 | } |
| 5396 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5397 | |
| 5398 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5399 | = u.getPackageStats(); |
| 5400 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5401 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5402 | pw.println(":"); |
| 5403 | boolean apkActivity = false; |
| 5404 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5405 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5406 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5407 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5408 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5409 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5410 | pw.println(" times"); |
| 5411 | apkActivity = true; |
| 5412 | } |
| 5413 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5414 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5415 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5416 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5417 | final int starts = ss.getStarts(which); |
| 5418 | final int launches = ss.getLaunches(which); |
| 5419 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5420 | sb.setLength(0); |
| 5421 | sb.append(prefix); sb.append(" Service "); |
| 5422 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5423 | sb.append(prefix); sb.append(" Created for: "); |
| 5424 | formatTimeMs(sb, startTime / 1000); |
| 5425 | sb.append("uptime\n"); |
| 5426 | sb.append(prefix); sb.append(" Starts: "); |
| 5427 | sb.append(starts); |
| 5428 | sb.append(", launches: "); sb.append(launches); |
| 5429 | pw.println(sb.toString()); |
| 5430 | apkActivity = true; |
| 5431 | } |
| 5432 | } |
| 5433 | if (!apkActivity) { |
| 5434 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5435 | } |
| 5436 | uidActivity = true; |
| 5437 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5439 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5444 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5445 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5446 | int diff = oldval ^ newval; |
| 5447 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5448 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5449 | for (int i=0; i<descriptions.length; i++) { |
| 5450 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5451 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5452 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5453 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5454 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5455 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5456 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5457 | didWake = true; |
| 5458 | pw.print("="); |
| 5459 | if (longNames) { |
| 5460 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5461 | pw.print(":\""); |
| 5462 | pw.print(wakelockTag.string); |
| 5463 | pw.print("\""); |
| 5464 | } else { |
| 5465 | pw.print(wakelockTag.poolIdx); |
| 5466 | } |
| 5467 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5468 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5469 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5470 | pw.print("="); |
| 5471 | int val = (newval&bd.mask)>>bd.shift; |
| 5472 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5473 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5474 | } else { |
| 5475 | pw.print(val); |
| 5476 | } |
| 5477 | } |
| 5478 | } |
| 5479 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5480 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5481 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5482 | if (longNames) { |
| 5483 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5484 | pw.print(":\""); |
| 5485 | pw.print(wakelockTag.string); |
| 5486 | pw.print("\""); |
| 5487 | } else { |
| 5488 | pw.print(wakelockTag.poolIdx); |
| 5489 | } |
| 5490 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5491 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 5492 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5493 | public void prepareForDumpLocked() { |
| 5494 | } |
| 5495 | |
| 5496 | public static class HistoryPrinter { |
| 5497 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5498 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5499 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5500 | int oldStatus = -1; |
| 5501 | int oldHealth = -1; |
| 5502 | int oldPlug = -1; |
| 5503 | int oldTemp = -1; |
| 5504 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5505 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5506 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5507 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5508 | void reset() { |
| 5509 | oldState = oldState2 = 0; |
| 5510 | oldLevel = -1; |
| 5511 | oldStatus = -1; |
| 5512 | oldHealth = -1; |
| 5513 | oldPlug = -1; |
| 5514 | oldTemp = -1; |
| 5515 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5516 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5519 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5520 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5521 | if (!checkin) { |
| 5522 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5523 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5524 | pw.print(" ("); |
| 5525 | pw.print(rec.numReadInts); |
| 5526 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5527 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5528 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5529 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5530 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5531 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5532 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5533 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5534 | } |
| 5535 | lastTime = rec.time; |
| 5536 | } |
| 5537 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5538 | if (checkin) { |
| 5539 | pw.print(":"); |
| 5540 | } |
| 5541 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5542 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5543 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5544 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5545 | if (checkin) { |
| 5546 | pw.print(":"); |
| 5547 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5548 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5549 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5550 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5551 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5552 | pw.print("TIME:"); |
| 5553 | if (checkin) { |
| 5554 | pw.println(rec.currentTime); |
| 5555 | } else { |
| 5556 | pw.print(" "); |
| 5557 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5558 | rec.currentTime).toString()); |
| 5559 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5560 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5561 | if (checkin) { |
| 5562 | pw.print(":"); |
| 5563 | } |
| 5564 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5565 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5566 | if (checkin) { |
| 5567 | pw.print(":"); |
| 5568 | } |
| 5569 | pw.println("*OVERFLOW*"); |
| 5570 | } else { |
| 5571 | if (!checkin) { |
| 5572 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5573 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5574 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5575 | if (verbose) { |
| 5576 | pw.print(" "); |
| 5577 | if (rec.states < 0) ; |
| 5578 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5579 | else if (rec.states < 0x100) pw.print("000000"); |
| 5580 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5581 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5582 | else if (rec.states < 0x100000) pw.print("000"); |
| 5583 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5584 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5585 | pw.print(Integer.toHexString(rec.states)); |
| 5586 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5587 | } else { |
| 5588 | if (oldLevel != rec.batteryLevel) { |
| 5589 | oldLevel = rec.batteryLevel; |
| 5590 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5591 | } |
| 5592 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5593 | if (oldStatus != rec.batteryStatus) { |
| 5594 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5595 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5596 | switch (oldStatus) { |
| 5597 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5598 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5599 | break; |
| 5600 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5601 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5602 | break; |
| 5603 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5604 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5605 | break; |
| 5606 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5607 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5608 | break; |
| 5609 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5610 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5611 | break; |
| 5612 | default: |
| 5613 | pw.print(oldStatus); |
| 5614 | break; |
| 5615 | } |
| 5616 | } |
| 5617 | if (oldHealth != rec.batteryHealth) { |
| 5618 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5619 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5620 | switch (oldHealth) { |
| 5621 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5622 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5623 | break; |
| 5624 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5625 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5626 | break; |
| 5627 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5628 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5629 | break; |
| 5630 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5631 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5632 | break; |
| 5633 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5634 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5635 | break; |
| 5636 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5637 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5638 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5639 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5640 | pw.print(checkin ? "c" : "cold"); |
| 5641 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5642 | default: |
| 5643 | pw.print(oldHealth); |
| 5644 | break; |
| 5645 | } |
| 5646 | } |
| 5647 | if (oldPlug != rec.batteryPlugType) { |
| 5648 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5649 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5650 | switch (oldPlug) { |
| 5651 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5652 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5653 | break; |
| 5654 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5655 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5656 | break; |
| 5657 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5658 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5659 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5660 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5661 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5662 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5663 | default: |
| 5664 | pw.print(oldPlug); |
| 5665 | break; |
| 5666 | } |
| 5667 | } |
| 5668 | if (oldTemp != rec.batteryTemperature) { |
| 5669 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5670 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5671 | pw.print(oldTemp); |
| 5672 | } |
| 5673 | if (oldVolt != rec.batteryVoltage) { |
| 5674 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5675 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5676 | pw.print(oldVolt); |
| 5677 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5678 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5679 | if (oldChargeMAh != chargeMAh) { |
| 5680 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5681 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5682 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5683 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5684 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5685 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5686 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5687 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5688 | if (rec.wakeReasonTag != null) { |
| 5689 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5690 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5691 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5692 | } else { |
| 5693 | pw.print(" wake_reason="); |
| 5694 | pw.print(rec.wakeReasonTag.uid); |
| 5695 | pw.print(":\""); |
| 5696 | pw.print(rec.wakeReasonTag.string); |
| 5697 | pw.print("\""); |
| 5698 | } |
| 5699 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5700 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5701 | pw.print(checkin ? "," : " "); |
| 5702 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5703 | pw.print("+"); |
| 5704 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5705 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5706 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5707 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5708 | : HISTORY_EVENT_NAMES; |
| 5709 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5710 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5711 | if (idx >= 0 && idx < eventNames.length) { |
| 5712 | pw.print(eventNames[idx]); |
| 5713 | } else { |
| 5714 | pw.print(checkin ? "Ev" : "event"); |
| 5715 | pw.print(idx); |
| 5716 | } |
| 5717 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5718 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5719 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5720 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5721 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5722 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5723 | pw.print(":\""); |
| 5724 | pw.print(rec.eventTag.string); |
| 5725 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5726 | } |
| 5727 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5728 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5729 | if (rec.stepDetails != null) { |
| 5730 | if (!checkin) { |
| 5731 | pw.print(" Details: cpu="); |
| 5732 | pw.print(rec.stepDetails.userTime); |
| 5733 | pw.print("u+"); |
| 5734 | pw.print(rec.stepDetails.systemTime); |
| 5735 | pw.print("s"); |
| 5736 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5737 | pw.print(" ("); |
| 5738 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5739 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5740 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5741 | pw.print(", "); |
| 5742 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5743 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5744 | } |
| 5745 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5746 | pw.print(", "); |
| 5747 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5748 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5749 | } |
| 5750 | pw.print(')'); |
| 5751 | } |
| 5752 | pw.println(); |
| 5753 | pw.print(" /proc/stat="); |
| 5754 | pw.print(rec.stepDetails.statUserTime); |
| 5755 | pw.print(" usr, "); |
| 5756 | pw.print(rec.stepDetails.statSystemTime); |
| 5757 | pw.print(" sys, "); |
| 5758 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5759 | pw.print(" io, "); |
| 5760 | pw.print(rec.stepDetails.statIrqTime); |
| 5761 | pw.print(" irq, "); |
| 5762 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5763 | pw.print(" sirq, "); |
| 5764 | pw.print(rec.stepDetails.statIdlTime); |
| 5765 | pw.print(" idle"); |
| 5766 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5767 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5768 | + rec.stepDetails.statSoftIrqTime; |
| 5769 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5770 | if (total > 0) { |
| 5771 | pw.print(" ("); |
| 5772 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5773 | pw.print(String.format("%.1f%%", perc)); |
| 5774 | pw.print(" of "); |
| 5775 | StringBuilder sb = new StringBuilder(64); |
| 5776 | formatTimeMsNoSpace(sb, total*10); |
| 5777 | pw.print(sb); |
| 5778 | pw.print(")"); |
| 5779 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5780 | pw.print(", PlatformIdleStat "); |
| 5781 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5782 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5783 | |
| 5784 | pw.print(", SubsystemPowerState "); |
| 5785 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5786 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5787 | } else { |
| 5788 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5789 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5790 | pw.print(rec.stepDetails.userTime); |
| 5791 | pw.print(":"); |
| 5792 | pw.print(rec.stepDetails.systemTime); |
| 5793 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5794 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5795 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5796 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5797 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5798 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5799 | } |
| 5800 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5801 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5802 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5803 | } |
| 5804 | } |
| 5805 | pw.println(); |
| 5806 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5807 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5808 | pw.print(rec.stepDetails.statUserTime); |
| 5809 | pw.print(','); |
| 5810 | pw.print(rec.stepDetails.statSystemTime); |
| 5811 | pw.print(','); |
| 5812 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5813 | pw.print(','); |
| 5814 | pw.print(rec.stepDetails.statIrqTime); |
| 5815 | pw.print(','); |
| 5816 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5817 | pw.print(','); |
| 5818 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5819 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5820 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5821 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 5822 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5823 | pw.print(','); |
| 5824 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5825 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5826 | |
| 5827 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5828 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5829 | } |
| 5830 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5831 | } |
| 5832 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5833 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5834 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5835 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5836 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5837 | |
| 5838 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5839 | UserHandle.formatUid(pw, uid); |
| 5840 | pw.print("="); |
| 5841 | pw.print(utime); |
| 5842 | pw.print("u+"); |
| 5843 | pw.print(stime); |
| 5844 | pw.print("s"); |
| 5845 | } |
| 5846 | |
| 5847 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5848 | pw.print('/'); |
| 5849 | pw.print(uid); |
| 5850 | pw.print(":"); |
| 5851 | pw.print(utime); |
| 5852 | pw.print(":"); |
| 5853 | pw.print(stime); |
| 5854 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5857 | private void printSizeValue(PrintWriter pw, long size) { |
| 5858 | float result = size; |
| 5859 | String suffix = ""; |
| 5860 | if (result >= 10*1024) { |
| 5861 | suffix = "KB"; |
| 5862 | result = result / 1024; |
| 5863 | } |
| 5864 | if (result >= 10*1024) { |
| 5865 | suffix = "MB"; |
| 5866 | result = result / 1024; |
| 5867 | } |
| 5868 | if (result >= 10*1024) { |
| 5869 | suffix = "GB"; |
| 5870 | result = result / 1024; |
| 5871 | } |
| 5872 | if (result >= 10*1024) { |
| 5873 | suffix = "TB"; |
| 5874 | result = result / 1024; |
| 5875 | } |
| 5876 | if (result >= 10*1024) { |
| 5877 | suffix = "PB"; |
| 5878 | result = result / 1024; |
| 5879 | } |
| 5880 | pw.print((int)result); |
| 5881 | pw.print(suffix); |
| 5882 | } |
| 5883 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5884 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5885 | String label3, long estimatedTime) { |
| 5886 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5887 | return false; |
| 5888 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5889 | pw.print(label1); |
| 5890 | pw.print(label2); |
| 5891 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5892 | StringBuilder sb = new StringBuilder(64); |
| 5893 | formatTimeMs(sb, estimatedTime); |
| 5894 | pw.print(sb); |
| 5895 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5896 | return true; |
| 5897 | } |
| 5898 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5899 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5900 | LevelStepTracker steps, boolean checkin) { |
| 5901 | if (steps == null) { |
| 5902 | return false; |
| 5903 | } |
| 5904 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5905 | if (count <= 0) { |
| 5906 | return false; |
| 5907 | } |
| 5908 | if (!checkin) { |
| 5909 | pw.println(header); |
| 5910 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5911 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5912 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5913 | long duration = steps.getDurationAt(i); |
| 5914 | int level = steps.getLevelAt(i); |
| 5915 | long initMode = steps.getInitModeAt(i); |
| 5916 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5917 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5918 | lineArgs[0] = Long.toString(duration); |
| 5919 | lineArgs[1] = Integer.toString(level); |
| 5920 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5921 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5922 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5923 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5924 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5925 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5926 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5927 | } |
| 5928 | } else { |
| 5929 | lineArgs[2] = ""; |
| 5930 | } |
| 5931 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5932 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5933 | } else { |
| 5934 | lineArgs[3] = ""; |
| 5935 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5936 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5937 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5938 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5939 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5940 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5941 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5942 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5943 | pw.print(prefix); |
| 5944 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5945 | TimeUtils.formatDuration(duration, pw); |
| 5946 | pw.print(" to "); pw.print(level); |
| 5947 | boolean haveModes = false; |
| 5948 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5949 | pw.print(" ("); |
| 5950 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5951 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5952 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5953 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5954 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5955 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5956 | } |
| 5957 | haveModes = true; |
| 5958 | } |
| 5959 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5960 | pw.print(haveModes ? ", " : " ("); |
| 5961 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5962 | ? "power-save-on" : "power-save-off"); |
| 5963 | haveModes = true; |
| 5964 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5965 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5966 | pw.print(haveModes ? ", " : " ("); |
| 5967 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5968 | ? "device-idle-on" : "device-idle-off"); |
| 5969 | haveModes = true; |
| 5970 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5971 | if (haveModes) { |
| 5972 | pw.print(")"); |
| 5973 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5974 | pw.println(); |
| 5975 | } |
| 5976 | } |
| 5977 | return true; |
| 5978 | } |
| 5979 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5980 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5981 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5982 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5983 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5984 | public static final int DUMP_VERBOSE = 1<<5; |
| 5985 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5986 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5987 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5988 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5989 | final HistoryItem rec = new HistoryItem(); |
| 5990 | long lastTime = -1; |
| 5991 | long baseTime = -1; |
| 5992 | boolean printed = false; |
| 5993 | HistoryEventTracker tracker = null; |
| 5994 | while (getNextHistoryLocked(rec)) { |
| 5995 | lastTime = rec.time; |
| 5996 | if (baseTime < 0) { |
| 5997 | baseTime = lastTime; |
| 5998 | } |
| 5999 | if (rec.time >= histStart) { |
| 6000 | if (histStart >= 0 && !printed) { |
| 6001 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6002 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6003 | || rec.cmd == HistoryItem.CMD_START |
| 6004 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6005 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6006 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6007 | (flags&DUMP_VERBOSE) != 0); |
| 6008 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6009 | } else if (rec.currentTime != 0) { |
| 6010 | printed = true; |
| 6011 | byte cmd = rec.cmd; |
| 6012 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6013 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6014 | (flags&DUMP_VERBOSE) != 0); |
| 6015 | rec.cmd = cmd; |
| 6016 | } |
| 6017 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6018 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6019 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6020 | (flags&DUMP_VERBOSE) != 0); |
| 6021 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6022 | } |
| 6023 | int oldEventCode = rec.eventCode; |
| 6024 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6025 | rec.eventTag = new HistoryTag(); |
| 6026 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6027 | HashMap<String, SparseIntArray> active |
| 6028 | = tracker.getStateForEvent(i); |
| 6029 | if (active == null) { |
| 6030 | continue; |
| 6031 | } |
| 6032 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6033 | : active.entrySet()) { |
| 6034 | SparseIntArray uids = ent.getValue(); |
| 6035 | for (int j=0; j<uids.size(); j++) { |
| 6036 | rec.eventCode = i; |
| 6037 | rec.eventTag.string = ent.getKey(); |
| 6038 | rec.eventTag.uid = uids.keyAt(j); |
| 6039 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6040 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6041 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6042 | rec.wakeReasonTag = null; |
| 6043 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6044 | } |
| 6045 | } |
| 6046 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6047 | rec.eventCode = oldEventCode; |
| 6048 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6049 | tracker = null; |
| 6050 | } |
| 6051 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6052 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6053 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6054 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6055 | // This is an attempt to aggregate the previous state and generate |
| 6056 | //Â fake events to reflect that state at the point where we start |
| 6057 | // printing real events. It doesn't really work right, so is turned off. |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6058 | if (tracker == null) { |
| 6059 | tracker = new HistoryEventTracker(); |
| 6060 | } |
| 6061 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6062 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6063 | } |
| 6064 | } |
| 6065 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6066 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6067 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6068 | } |
| 6069 | } |
| 6070 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6071 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6072 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6073 | if (steps == null) { |
| 6074 | return; |
| 6075 | } |
| 6076 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6077 | if (timeRemaining >= 0) { |
| 6078 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6079 | tmpSb.setLength(0); |
| 6080 | formatTimeMs(tmpSb, timeRemaining); |
| 6081 | pw.print(tmpSb); |
| 6082 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6083 | pw.println(" steps)"); |
| 6084 | } |
| 6085 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6086 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6087 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6088 | if (estimatedTime > 0) { |
| 6089 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6090 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6091 | pw.print(" time: "); |
| 6092 | tmpSb.setLength(0); |
| 6093 | formatTimeMs(tmpSb, estimatedTime); |
| 6094 | pw.print(tmpSb); |
| 6095 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6096 | pw.println(" steps)"); |
| 6097 | } |
| 6098 | } |
| 6099 | } |
| 6100 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6101 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6102 | ArrayList<PackageChange> changes) { |
| 6103 | if (changes == null) { |
| 6104 | return; |
| 6105 | } |
| 6106 | pw.print(prefix); pw.println("Package changes:"); |
| 6107 | for (int i=0; i<changes.size(); i++) { |
| 6108 | PackageChange pc = changes.get(i); |
| 6109 | if (pc.mUpdate) { |
| 6110 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6111 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6112 | } else { |
| 6113 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6114 | } |
| 6115 | } |
| 6116 | } |
| 6117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | /** |
| 6119 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6120 | * |
| 6121 | * @param pw a Printer to receive the dump output. |
| 6122 | */ |
| 6123 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6124 | public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6125 | prepareForDumpLocked(); |
| 6126 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6127 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6128 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6129 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6130 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6131 | final long historyTotalSize = getHistoryTotalSize(); |
| 6132 | final long historyUsedSize = getHistoryUsedSize(); |
| 6133 | if (startIteratingHistoryLocked()) { |
| 6134 | try { |
| 6135 | pw.print("Battery History ("); |
| 6136 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6137 | pw.print("% used, "); |
| 6138 | printSizeValue(pw, historyUsedSize); |
| 6139 | pw.print(" used of "); |
| 6140 | printSizeValue(pw, historyTotalSize); |
| 6141 | pw.print(", "); |
| 6142 | pw.print(getHistoryStringPoolSize()); |
| 6143 | pw.print(" strings using "); |
| 6144 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6145 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6146 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6147 | pw.println(); |
| 6148 | } finally { |
| 6149 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6150 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | if (startIteratingOldHistoryLocked()) { |
| 6154 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6155 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6156 | pw.println("Old battery History:"); |
| 6157 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6158 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6159 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6160 | if (baseTime < 0) { |
| 6161 | baseTime = rec.time; |
| 6162 | } |
| 6163 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6164 | } |
| 6165 | pw.println(); |
| 6166 | } finally { |
| 6167 | finishIteratingOldHistoryLocked(); |
| 6168 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6169 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6172 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6173 | return; |
| 6174 | } |
| 6175 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6176 | if (!filtering) { |
| 6177 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6178 | final int NU = uidStats.size(); |
| 6179 | boolean didPid = false; |
| 6180 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6181 | for (int i=0; i<NU; i++) { |
| 6182 | Uid uid = uidStats.valueAt(i); |
| 6183 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6184 | if (pids != null) { |
| 6185 | for (int j=0; j<pids.size(); j++) { |
| 6186 | Uid.Pid pid = pids.valueAt(j); |
| 6187 | if (!didPid) { |
| 6188 | pw.println("Per-PID Stats:"); |
| 6189 | didPid = true; |
| 6190 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6191 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6192 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6193 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6194 | pw.print(" wake time: "); |
| 6195 | TimeUtils.formatDuration(time, pw); |
| 6196 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6197 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6198 | } |
| 6199 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6200 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6201 | pw.println(); |
| 6202 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6206 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6207 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6208 | long timeRemaining = computeBatteryTimeRemaining( |
| 6209 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6210 | if (timeRemaining >= 0) { |
| 6211 | pw.print(" Estimated discharge time remaining: "); |
| 6212 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6213 | pw.println(); |
| 6214 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6215 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6216 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6217 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6218 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6219 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6220 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6221 | pw.println(); |
| 6222 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6223 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6224 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6225 | long timeRemaining = computeChargeTimeRemaining( |
| 6226 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6227 | if (timeRemaining >= 0) { |
| 6228 | pw.print(" Estimated charge time remaining: "); |
| 6229 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6230 | pw.println(); |
| 6231 | } |
| 6232 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6233 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6234 | } |
| 6235 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 6236 | pw.println("Daily stats:"); |
| 6237 | pw.print(" Current start time: "); |
| 6238 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6239 | getCurrentDailyStartTime()).toString()); |
| 6240 | pw.print(" Next min deadline: "); |
| 6241 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6242 | getNextMinDailyDeadline()).toString()); |
| 6243 | pw.print(" Next max deadline: "); |
| 6244 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6245 | getNextMaxDailyDeadline()).toString()); |
| 6246 | StringBuilder sb = new StringBuilder(64); |
| 6247 | int[] outInt = new int[1]; |
| 6248 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6249 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6250 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6251 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6252 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6253 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6254 | dsteps, false)) { |
| 6255 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6256 | sb, outInt); |
| 6257 | } |
| 6258 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6259 | csteps, false)) { |
| 6260 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6261 | sb, outInt); |
| 6262 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6263 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6264 | } else { |
| 6265 | pw.println(" Current daily steps:"); |
| 6266 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6267 | sb, outInt); |
| 6268 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6269 | sb, outInt); |
| 6270 | } |
| 6271 | } |
| 6272 | DailyItem dit; |
| 6273 | int curIndex = 0; |
| 6274 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6275 | curIndex++; |
| 6276 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6277 | pw.println(); |
| 6278 | } |
| 6279 | pw.print(" Daily from "); |
| 6280 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6281 | pw.print(" to "); |
| 6282 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6283 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6284 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6285 | if (dumpDurationSteps(pw, " ", |
| 6286 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6287 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6288 | sb, outInt); |
| 6289 | } |
| 6290 | if (dumpDurationSteps(pw, " ", |
| 6291 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6292 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6293 | sb, outInt); |
| 6294 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6295 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6296 | } else { |
| 6297 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6298 | sb, outInt); |
| 6299 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6300 | sb, outInt); |
| 6301 | } |
| 6302 | } |
| 6303 | pw.println(); |
| 6304 | } |
| 6305 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6306 | pw.println("Statistics since last charge:"); |
| 6307 | pw.println(" System starts: " + getStartCount() |
| 6308 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6309 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6310 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6311 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame^] | 6314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6316 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6317 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6318 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6319 | |
| 6320 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6321 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6322 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6323 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6324 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6325 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6326 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6327 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6328 | |
| 6329 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6330 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6331 | try { |
| 6332 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6333 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6334 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6335 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6336 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6337 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6338 | pw.print(",\""); |
| 6339 | String str = getHistoryTagPoolString(i); |
| 6340 | str = str.replace("\\", "\\\\"); |
| 6341 | str = str.replace("\"", "\\\""); |
| 6342 | pw.print(str); |
| 6343 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6344 | pw.println(); |
| 6345 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6346 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6347 | } finally { |
| 6348 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6349 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6350 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6351 | } |
| 6352 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6353 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6354 | return; |
| 6355 | } |
| 6356 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6357 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6358 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6359 | for (int i=0; i<apps.size(); i++) { |
| 6360 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6361 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6362 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6363 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6364 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6365 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6366 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6367 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6368 | } |
| 6369 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6370 | final int NU = uidStats.size(); |
| 6371 | String[] lineArgs = new String[2]; |
| 6372 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6373 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6374 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6375 | if (pkgs != null && !pkgs.second.value) { |
| 6376 | pkgs.second.value = true; |
| 6377 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6378 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6379 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6380 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6381 | (Object[])lineArgs); |
| 6382 | } |
| 6383 | } |
| 6384 | } |
| 6385 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6386 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6387 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6388 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6389 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6390 | if (timeRemaining >= 0) { |
| 6391 | lineArgs[0] = Long.toString(timeRemaining); |
| 6392 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6393 | (Object[])lineArgs); |
| 6394 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6395 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6396 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6397 | if (timeRemaining >= 0) { |
| 6398 | lineArgs[0] = Long.toString(timeRemaining); |
| 6399 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6400 | (Object[])lineArgs); |
| 6401 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6402 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6403 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6404 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6406 | } |