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 | |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE_LOCATION; |
| 20 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 22 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 24 | import android.content.pm.ApplicationInfo; |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 25 | import android.server.ServerProtoEnums; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 26 | import android.service.batterystats.BatteryStatsServiceDumpHistoryProto; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 27 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 28 | import android.telephony.SignalStrength; |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 29 | import android.telephony.TelephonyManager; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 30 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 31 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 32 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 33 | import android.util.MutableBoolean; |
| 34 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.util.Printer; |
| 36 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 37 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 38 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 39 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 40 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 41 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 43 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 44 | import com.android.internal.os.BatterySipper; |
| 45 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 47 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 48 | import java.io.PrintWriter; |
| 49 | import java.util.ArrayList; |
| 50 | import java.util.Collections; |
| 51 | import java.util.Comparator; |
| 52 | import java.util.Formatter; |
| 53 | import java.util.HashMap; |
| 54 | import java.util.List; |
| 55 | import java.util.Map; |
| 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | /** |
| 58 | * A class providing access to battery usage statistics, including information on |
| 59 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 60 | * except where indicated otherwise. |
| 61 | * @hide |
| 62 | */ |
| 63 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 64 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | |
| 66 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 67 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 68 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 69 | |
| 70 | /** @hide */ |
| 71 | public static final String SERVICE_NAME = "batterystats"; |
| 72 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | /** |
| 74 | * A constant indicating a partial wake lock timer. |
| 75 | */ |
| 76 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 77 | |
| 78 | /** |
| 79 | * A constant indicating a full wake lock timer. |
| 80 | */ |
| 81 | public static final int WAKE_TYPE_FULL = 1; |
| 82 | |
| 83 | /** |
| 84 | * A constant indicating a window wake lock timer. |
| 85 | */ |
| 86 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 87 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | /** |
| 89 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | */ |
| 91 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 92 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 93 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 94 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 95 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 96 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 97 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 98 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 99 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 100 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 101 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 102 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 103 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 104 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 105 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 106 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 108 | /** |
| 109 | * A constant indicating a wifi multicast timer |
| 110 | */ |
| 111 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 114 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 115 | */ |
| 116 | public static final int VIDEO_TURNED_ON = 8; |
| 117 | |
| 118 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 119 | * A constant indicating a vibrator on timer |
| 120 | */ |
| 121 | public static final int VIBRATOR_ON = 9; |
| 122 | |
| 123 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 124 | * A constant indicating a foreground activity timer |
| 125 | */ |
| 126 | public static final int FOREGROUND_ACTIVITY = 10; |
| 127 | |
| 128 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 129 | * A constant indicating a wifi batched scan is active |
| 130 | */ |
| 131 | public static final int WIFI_BATCHED_SCAN = 11; |
| 132 | |
| 133 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 134 | * A constant indicating a process state timer |
| 135 | */ |
| 136 | public static final int PROCESS_STATE = 12; |
| 137 | |
| 138 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 139 | * A constant indicating a sync timer |
| 140 | */ |
| 141 | public static final int SYNC = 13; |
| 142 | |
| 143 | /** |
| 144 | * A constant indicating a job timer |
| 145 | */ |
| 146 | public static final int JOB = 14; |
| 147 | |
| 148 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 149 | * A constant indicating an audio turn on timer |
| 150 | */ |
| 151 | public static final int AUDIO_TURNED_ON = 15; |
| 152 | |
| 153 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 154 | * A constant indicating a flashlight turn on timer |
| 155 | */ |
| 156 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 157 | |
| 158 | /** |
| 159 | * A constant indicating a camera turn on timer |
| 160 | */ |
| 161 | public static final int CAMERA_TURNED_ON = 17; |
| 162 | |
| 163 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 164 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 165 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 166 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 169 | * A constant indicating a bluetooth scan timer. |
| 170 | */ |
| 171 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 172 | |
| 173 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 174 | * A constant indicating an aggregated partial wake lock timer. |
| 175 | */ |
| 176 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 177 | |
| 178 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 179 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 180 | */ |
| 181 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 182 | |
| 183 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 184 | * A constant indicating a foreground service timer |
| 185 | */ |
| 186 | public static final int FOREGROUND_SERVICE = 22; |
| 187 | |
| 188 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 189 | * A constant indicating an aggregate wifi multicast timer |
| 190 | */ |
| 191 | public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; |
| 192 | |
| 193 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | * Include all of the data in the stats, including previously saved data. |
| 195 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 196 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | * Include only the current run in the stats. |
| 200 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 201 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Include only the run since the last time the device was unplugged in the stats. |
| 205 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 206 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 207 | |
| 208 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 209 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 210 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 211 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 214 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 215 | * |
| 216 | * New in version 19: |
| 217 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 218 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 219 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 220 | * New in version 21: |
| 221 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 222 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 223 | * - BLE scan result count |
| 224 | * - CPU frequency time per uid |
| 225 | * New in version 22: |
| 226 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 227 | * - Background partial wakelock time & count |
| 228 | * New in version 23: |
| 229 | * - Logging smeared power model values |
| 230 | * New in version 24: |
| 231 | * - Fixed bugs in background timers and BLE scan time |
| 232 | * New in version 25: |
| 233 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 234 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 235 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 236 | * New in version 27: |
| 237 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 238 | * New in version 28: |
| 239 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 240 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 241 | * New in version 29: |
| 242 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 243 | * - CPU times per UID process state |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 244 | * New in version 30: |
| 245 | * - Uid.PROCESS_STATE_FOREGROUND_SERVICE only tracks |
| 246 | * ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE. |
Kweku Adams | b78430e | 2018-02-20 18:06:09 -0800 | [diff] [blame] | 247 | * New in version 31: |
| 248 | * - New cellular network types. |
| 249 | * - Deferred job metrics. |
Kweku Adams | 6fe1a5a | 2018-05-22 15:02:50 -0700 | [diff] [blame] | 250 | * New in version 32: |
| 251 | * - Ambient display properly output in data dump. |
zhouwenjie | d707da9 | 2018-07-06 10:23:00 -0700 | [diff] [blame] | 252 | * New in version 33: |
| 253 | * - Fixed bug in min learned capacity updating process. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 254 | */ |
zhouwenjie | d707da9 | 2018-07-06 10:23:00 -0700 | [diff] [blame] | 255 | static final int CHECKIN_VERSION = 33; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * 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] | 259 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 260 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 261 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 262 | private static final long BYTES_PER_KB = 1024; |
| 263 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 264 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 265 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 266 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 267 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 268 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 270 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 271 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 272 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 273 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 274 | // rpm line is: |
| 275 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 276 | // screen-off time, screen-off count |
| 277 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 278 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 279 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 280 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 281 | // fgs line is: |
| 282 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 283 | // foreground service time, count |
| 284 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 285 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 286 | // wl line is: |
| 287 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 288 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 289 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 290 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 291 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 292 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 293 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 294 | // awl line is: |
| 295 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 296 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 297 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 298 | private static final String SYNC_DATA = "sy"; |
| 299 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 300 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * jbd line is: |
| 304 | * BATTERY_STATS_CHECKIN_VERSION, uid, which, "jbd", |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 305 | * jobsDeferredEventCount, jobsDeferredCount, totalLatencyMillis, |
| 306 | * count at latency < 1 hr, count at latency 1 to 2 hrs, 2 to 4 hrs, 4 to 8 hrs, and past 8 hrs |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 307 | * <p> |
| 308 | * @see #JOB_FRESHNESS_BUCKETS |
| 309 | */ |
| 310 | private static final String JOBS_DEFERRED_DATA = "jbd"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 311 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 312 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 313 | private static final String NETWORK_DATA = "nt"; |
| 314 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 315 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 316 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 317 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 318 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 319 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 320 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 321 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 322 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 323 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 324 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 325 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 326 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 327 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 328 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 329 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 330 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 331 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 332 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 333 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 334 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 335 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 336 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 337 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 338 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 339 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 340 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 341 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 342 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 343 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 344 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 345 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 346 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 347 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 348 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 349 | private static final String FLASHLIGHT_DATA = "fla"; |
| 350 | private static final String CAMERA_DATA = "cam"; |
| 351 | private static final String VIDEO_DATA = "vid"; |
| 352 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 353 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 354 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 356 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 357 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 358 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 360 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 361 | private static final String CELLULAR_CONTROLLER_NAME = "Cellular"; |
| 362 | private static final String WIFI_CONTROLLER_NAME = "WiFi"; |
| 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 365 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 366 | * |
| 367 | * Other types might include times spent in foreground, background etc. |
| 368 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 369 | @VisibleForTesting |
| 370 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 371 | |
| 372 | /** |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 373 | * These are the thresholds for bucketing last time since a job was run for an app |
| 374 | * that just moved to ACTIVE due to a launch. So if the last time a job ran was less |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 375 | * than 1 hour ago, then it's reasonably fresh, 2 hours ago, not so fresh and so |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 376 | * on. |
| 377 | */ |
| 378 | public static final long[] JOB_FRESHNESS_BUCKETS = { |
| 379 | 1 * 60 * 60 * 1000L, |
| 380 | 2 * 60 * 60 * 1000L, |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 381 | 4 * 60 * 60 * 1000L, |
| 382 | 8 * 60 * 60 * 1000L, |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 383 | Long.MAX_VALUE |
| 384 | }; |
| 385 | |
| 386 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 387 | * State for keeping track of counting information. |
| 388 | */ |
| 389 | public static abstract class Counter { |
| 390 | |
| 391 | /** |
| 392 | * Returns the count associated with this Counter for the |
| 393 | * selected type of statistics. |
| 394 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 395 | * @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] | 396 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 397 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 398 | |
| 399 | /** |
| 400 | * Temporary for debugging. |
| 401 | */ |
| 402 | public abstract void logState(Printer pw, String prefix); |
| 403 | } |
| 404 | |
| 405 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 406 | * State for keeping track of long counting information. |
| 407 | */ |
| 408 | public static abstract class LongCounter { |
| 409 | |
| 410 | /** |
| 411 | * Returns the count associated with this Counter for the |
| 412 | * selected type of statistics. |
| 413 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 414 | * @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] | 415 | */ |
| 416 | public abstract long getCountLocked(int which); |
| 417 | |
| 418 | /** |
| 419 | * Temporary for debugging. |
| 420 | */ |
| 421 | public abstract void logState(Printer pw, String prefix); |
| 422 | } |
| 423 | |
| 424 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 425 | * State for keeping track of array of long counting information. |
| 426 | */ |
| 427 | public static abstract class LongCounterArray { |
| 428 | /** |
| 429 | * Returns the counts associated with this Counter for the |
| 430 | * selected type of statistics. |
| 431 | * |
| 432 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 433 | */ |
| 434 | public abstract long[] getCountsLocked(int which); |
| 435 | |
| 436 | /** |
| 437 | * Temporary for debugging. |
| 438 | */ |
| 439 | public abstract void logState(Printer pw, String prefix); |
| 440 | } |
| 441 | |
| 442 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 443 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 444 | * radio controller. |
| 445 | */ |
| 446 | public static abstract class ControllerActivityCounter { |
| 447 | /** |
| 448 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 449 | * idle state. |
| 450 | */ |
| 451 | public abstract LongCounter getIdleTimeCounter(); |
| 452 | |
| 453 | /** |
| 454 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 455 | * scan state. |
| 456 | */ |
| 457 | public abstract LongCounter getScanTimeCounter(); |
| 458 | |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 459 | /** |
| 460 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 461 | * sleep state. |
| 462 | */ |
| 463 | public abstract LongCounter getSleepTimeCounter(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 464 | |
| 465 | /** |
| 466 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 467 | * receive state. |
| 468 | */ |
| 469 | public abstract LongCounter getRxTimeCounter(); |
| 470 | |
| 471 | /** |
| 472 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 473 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 474 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 475 | * various transmit level states. |
| 476 | */ |
| 477 | public abstract LongCounter[] getTxTimeCounters(); |
| 478 | |
| 479 | /** |
| 480 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 481 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 482 | * yield a value of 0 if the device doesn't support power calculations. |
| 483 | */ |
| 484 | public abstract LongCounter getPowerCounter(); |
| 485 | } |
| 486 | |
| 487 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | * State for keeping track of timing information. |
| 489 | */ |
| 490 | public static abstract class Timer { |
| 491 | |
| 492 | /** |
| 493 | * Returns the count associated with this Timer for the |
| 494 | * selected type of statistics. |
| 495 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 496 | * @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] | 497 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 498 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | |
| 500 | /** |
| 501 | * Returns the total time in microseconds associated with this Timer for the |
| 502 | * selected type of statistics. |
| 503 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 504 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 505 | * @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] | 506 | * @return a time in microseconds |
| 507 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 508 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 511 | * Returns the total time in microseconds associated with this Timer since the |
| 512 | * 'mark' was last set. |
| 513 | * |
| 514 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 515 | * @return a time in microseconds |
| 516 | */ |
| 517 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 518 | |
| 519 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 520 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 521 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 522 | */ |
| 523 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Returns the current time the timer has been active, if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 529 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 530 | */ |
| 531 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 536 | * Returns the total time the timer has been active, if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 537 | * |
| 538 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 539 | * been on since reset. |
| 540 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 541 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 542 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 543 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 544 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 545 | */ |
| 546 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 547 | return -1; |
| 548 | } |
| 549 | |
| 550 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 551 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 552 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 553 | * |
| 554 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 555 | */ |
| 556 | public Timer getSubTimer() { |
| 557 | return null; |
| 558 | } |
| 559 | |
| 560 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 561 | * Returns whether the timer is currently running. Some types of timers |
| 562 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 563 | * and report false. |
| 564 | */ |
| 565 | public boolean isRunningLocked() { |
| 566 | return false; |
| 567 | } |
| 568 | |
| 569 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | * Temporary for debugging. |
| 571 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 572 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 576 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 577 | */ |
| 578 | public static int mapToInternalProcessState(int procState) { |
| 579 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 580 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 581 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 582 | return Uid.PROCESS_STATE_TOP; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 583 | } else if (ActivityManager.isForegroundService(procState)) { |
Dianne Hackborn | 10fc4fd | 2017-12-19 17:23:13 -0800 | [diff] [blame] | 584 | // State when app has put itself in the foreground. |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 585 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 586 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 587 | // Persistent and other foreground states go here. |
| 588 | return Uid.PROCESS_STATE_FOREGROUND; |
| 589 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 590 | return Uid.PROCESS_STATE_BACKGROUND; |
| 591 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 592 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 593 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 594 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 595 | } else { |
| 596 | return Uid.PROCESS_STATE_CACHED; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | * The statistics associated with a particular uid. |
| 602 | */ |
| 603 | public static abstract class Uid { |
| 604 | |
| 605 | /** |
| 606 | * Returns a mapping containing wakelock statistics. |
| 607 | * |
| 608 | * @return a Map from Strings to Uid.Wakelock objects. |
| 609 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 610 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | |
| 612 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 613 | * Returns the WiFi Multicast Wakelock statistics. |
| 614 | * |
| 615 | * @return a Timer Object for the per uid Multicast statistics. |
| 616 | */ |
| 617 | public abstract Timer getMulticastWakelockStats(); |
| 618 | |
| 619 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 620 | * Returns a mapping containing sync statistics. |
| 621 | * |
| 622 | * @return a Map from Strings to Timer objects. |
| 623 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 624 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 625 | |
| 626 | /** |
| 627 | * Returns a mapping containing scheduled job statistics. |
| 628 | * |
| 629 | * @return a Map from Strings to Timer objects. |
| 630 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 631 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 632 | |
| 633 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 634 | * Returns statistics about how jobs have completed. |
| 635 | * |
| 636 | * @return A Map of String job names to completion type -> count mapping. |
| 637 | */ |
| 638 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 639 | |
| 640 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | * The statistics associated with a particular wake lock. |
| 642 | */ |
| 643 | public static abstract class Wakelock { |
| 644 | public abstract Timer getWakeTime(int type); |
| 645 | } |
| 646 | |
| 647 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 648 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 649 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 650 | * wakelocks that overlap in time (and therefore over-counts). |
| 651 | */ |
| 652 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 653 | |
| 654 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | * Returns a mapping containing sensor statistics. |
| 656 | * |
| 657 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 658 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 659 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | |
| 661 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 662 | * Returns a mapping containing active process data. |
| 663 | */ |
| 664 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 665 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 666 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | * Returns a mapping containing process statistics. |
| 668 | * |
| 669 | * @return a Map from Strings to Uid.Proc objects. |
| 670 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 671 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * Returns a mapping containing package statistics. |
| 675 | * |
| 676 | * @return a Map from Strings to Uid.Pkg objects. |
| 677 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 678 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 679 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 680 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 681 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 682 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 683 | |
| 684 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | * {@hide} |
| 686 | */ |
| 687 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 688 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 689 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 690 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 691 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 692 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 693 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 694 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 695 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 696 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 697 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 698 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 699 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 700 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 701 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 702 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 703 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 704 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 705 | /** |
| 706 | * Returns the timer keeping track of wifi scans. |
| 707 | */ |
| 708 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 709 | public abstract int getWifiScanBackgroundCount(int which); |
| 710 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 711 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 712 | /** |
| 713 | * Returns the timer keeping track of background wifi scans. |
| 714 | */ |
| 715 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 716 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 717 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 718 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 719 | public abstract Timer getAudioTurnedOnTimer(); |
| 720 | public abstract Timer getVideoTurnedOnTimer(); |
| 721 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 722 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 723 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 724 | |
| 725 | /** |
| 726 | * Returns the timer keeping track of Foreground Service time |
| 727 | */ |
| 728 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 729 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 730 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 731 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 732 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 733 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 734 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 735 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 736 | public abstract long[] getCpuFreqTimes(int which); |
| 737 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 738 | /** |
| 739 | * Returns cpu active time of an uid. |
| 740 | */ |
| 741 | public abstract long getCpuActiveTime(); |
| 742 | /** |
| 743 | * Returns cpu times of an uid on each cluster |
| 744 | */ |
| 745 | public abstract long[] getCpuClusterTimes(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 746 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 747 | /** |
| 748 | * Returns cpu times of an uid at a particular process state. |
| 749 | */ |
| 750 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 751 | /** |
| 752 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 753 | */ |
| 754 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 755 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 756 | // Note: the following times are disjoint. They can be added together to find the |
| 757 | // total time a uid has had any processes running at all. |
| 758 | |
| 759 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 760 | * Time this uid has any processes in the top state. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 761 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 762 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 763 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 764 | * Time this uid has any process with a started foreground service, but |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 765 | * none in the "top" state. |
| 766 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 767 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 768 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 769 | * Time this uid has any process in an active foreground state, but none in the |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 770 | * "foreground service" or better state. Persistent and other foreground states go here. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 771 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 772 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 773 | /** |
| 774 | * Time this uid has any process in an active background state, but none in the |
| 775 | * "foreground" or better state. |
| 776 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 777 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 778 | /** |
| 779 | * Time this uid has any process that is top while the device is sleeping, but not |
| 780 | * active for any other reason. We kind-of consider it a kind of cached process |
| 781 | * for execution restrictions. |
| 782 | */ |
| 783 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 784 | /** |
| 785 | * Time this uid has any process that is in the background but it has an activity |
| 786 | * marked as "can't save state". This is essentially a cached process, though the |
| 787 | * system will try much harder than normal to avoid killing it. |
| 788 | */ |
| 789 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 790 | /** |
| 791 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 792 | * other active states. |
| 793 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 794 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 795 | /** |
| 796 | * Total number of process states we track. |
| 797 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 798 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 799 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 800 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 801 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 802 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 803 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 804 | }; |
| 805 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 806 | // Used in checkin dump |
| 807 | @VisibleForTesting |
| 808 | public static final String[] UID_PROCESS_TYPES = { |
| 809 | "T", // TOP |
| 810 | "FS", // FOREGROUND_SERVICE |
| 811 | "F", // FOREGROUND |
| 812 | "B", // BACKGROUND |
| 813 | "TS", // TOP_SLEEPING |
| 814 | "HW", // HEAVY_WEIGHT |
| 815 | "C" // CACHED |
| 816 | }; |
| 817 | |
| 818 | /** |
| 819 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 820 | * is not attributed to any non-critical process states. |
| 821 | */ |
| 822 | public static final int[] CRITICAL_PROC_STATES = { |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 823 | PROCESS_STATE_TOP, |
| 824 | PROCESS_STATE_FOREGROUND_SERVICE_LOCATION, PROCESS_STATE_FOREGROUND_SERVICE, |
| 825 | PROCESS_STATE_FOREGROUND |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 826 | }; |
| 827 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 828 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 829 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 830 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 831 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 833 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 834 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 835 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 836 | * Note that these must match the constants in android.os.PowerManager. |
| 837 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 838 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 839 | */ |
| 840 | static final String[] USER_ACTIVITY_TYPES = { |
Lucas Dupin | 0a5d797 | 2019-01-16 18:52:30 -0800 | [diff] [blame] | 841 | "other", "button", "touch", "accessibility", "attention" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 842 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 843 | |
Lucas Dupin | 0a5d797 | 2019-01-16 18:52:30 -0800 | [diff] [blame] | 844 | public static final int NUM_USER_ACTIVITY_TYPES = USER_ACTIVITY_TYPES.length; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 845 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 846 | public abstract void noteUserActivityLocked(int type); |
| 847 | public abstract boolean hasUserActivity(); |
| 848 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 849 | |
| 850 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 851 | public abstract long getNetworkActivityBytes(int type, int which); |
| 852 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 853 | public abstract long getMobileRadioActiveTime(int which); |
| 854 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 855 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 856 | /** |
| 857 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 858 | */ |
| 859 | public abstract long getUserCpuTimeUs(int which); |
| 860 | |
| 861 | /** |
| 862 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 863 | */ |
| 864 | public abstract long getSystemCpuTimeUs(int which); |
| 865 | |
| 866 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 867 | * 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] | 868 | * given CPU cluster. |
| 869 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 870 | * @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] | 871 | * @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] | 872 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 873 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 874 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 875 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 876 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 877 | /** |
| 878 | * Returns the number of times this UID woke up the Application Processor to |
| 879 | * process a mobile radio packet. |
| 880 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 881 | */ |
| 882 | public abstract long getMobileRadioApWakeupCount(int which); |
| 883 | |
| 884 | /** |
| 885 | * Returns the number of times this UID woke up the Application Processor to |
| 886 | * process a WiFi packet. |
| 887 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 888 | */ |
| 889 | public abstract long getWifiRadioApWakeupCount(int which); |
| 890 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 891 | /** |
| 892 | * Appends the deferred jobs data to the StringBuilder passed in, in checkin format |
| 893 | * @param sb StringBuilder that can be overwritten with the deferred jobs data |
| 894 | * @param which one of STATS_* |
| 895 | */ |
| 896 | public abstract void getDeferredJobsCheckinLineLocked(StringBuilder sb, int which); |
| 897 | |
| 898 | /** |
| 899 | * Appends the deferred jobs data to the StringBuilder passed in |
| 900 | * @param sb StringBuilder that can be overwritten with the deferred jobs data |
| 901 | * @param which one of STATS_* |
| 902 | */ |
| 903 | public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which); |
| 904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 906 | /* |
| 907 | * FIXME: it's not correct to use this magic value because it |
| 908 | * could clash with a sensor handle (which are defined by |
| 909 | * the sensor HAL, and therefore out of our control |
| 910 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | // Magic sensor number for the GPS. |
| 912 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 917 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 918 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 919 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | } |
| 921 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 922 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 923 | public int mWakeNesting; |
| 924 | public long mWakeSumMs; |
| 925 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 926 | } |
| 927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | /** |
| 929 | * The statistics associated with a particular process. |
| 930 | */ |
| 931 | public static abstract class Proc { |
| 932 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 933 | public static class ExcessivePower { |
| 934 | public static final int TYPE_WAKE = 1; |
| 935 | public static final int TYPE_CPU = 2; |
| 936 | |
| 937 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 938 | public long overTime; |
| 939 | public long usedTime; |
| 940 | } |
| 941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 943 | * Returns true if this process is still active in the battery stats. |
| 944 | */ |
| 945 | public abstract boolean isActive(); |
| 946 | |
| 947 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 948 | * 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] | 949 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 950 | * @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] | 951 | */ |
| 952 | public abstract long getUserTime(int which); |
| 953 | |
| 954 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 955 | * 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] | 956 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 957 | * @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] | 958 | */ |
| 959 | public abstract long getSystemTime(int which); |
| 960 | |
| 961 | /** |
| 962 | * Returns the number of times the process has been started. |
| 963 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 964 | * @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] | 965 | */ |
| 966 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 967 | |
| 968 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 969 | * Returns the number of times the process has crashed. |
| 970 | * |
| 971 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 972 | */ |
| 973 | public abstract int getNumCrashes(int which); |
| 974 | |
| 975 | /** |
| 976 | * Returns the number of times the process has ANRed. |
| 977 | * |
| 978 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 979 | */ |
| 980 | public abstract int getNumAnrs(int which); |
| 981 | |
| 982 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 983 | * 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] | 984 | * @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] | 985 | * @return foreground cpu time in microseconds |
| 986 | */ |
| 987 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 988 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 989 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 990 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 991 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
| 995 | * The statistics associated with a particular package. |
| 996 | */ |
| 997 | public static abstract class Pkg { |
| 998 | |
| 999 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1000 | * Returns information about all wakeup alarms that have been triggered for this |
| 1001 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 1002 | * 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] | 1003 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1004 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | |
| 1006 | /** |
| 1007 | * Returns a mapping containing service statistics. |
| 1008 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1009 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | |
| 1011 | /** |
| 1012 | * The statistics associated with a particular service. |
| 1013 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1014 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | |
| 1016 | /** |
| 1017 | * Returns the amount of time spent started. |
| 1018 | * |
| 1019 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1020 | * @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] | 1021 | * @return |
| 1022 | */ |
| 1023 | public abstract long getStartTime(long batteryUptime, int which); |
| 1024 | |
| 1025 | /** |
| 1026 | * Returns the total number of times startService() has been called. |
| 1027 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1028 | * @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] | 1029 | */ |
| 1030 | public abstract int getStarts(int which); |
| 1031 | |
| 1032 | /** |
| 1033 | * Returns the total number times the service has been launched. |
| 1034 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1035 | * @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] | 1036 | */ |
| 1037 | public abstract int getLaunches(int which); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1042 | public static final class LevelStepTracker { |
| 1043 | public long mLastStepTime = -1; |
| 1044 | public int mNumStepDurations; |
| 1045 | public final long[] mStepDurations; |
| 1046 | |
| 1047 | public LevelStepTracker(int maxLevelSteps) { |
| 1048 | mStepDurations = new long[maxLevelSteps]; |
| 1049 | } |
| 1050 | |
| 1051 | public LevelStepTracker(int numSteps, long[] steps) { |
| 1052 | mNumStepDurations = numSteps; |
| 1053 | mStepDurations = new long[numSteps]; |
| 1054 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 1055 | } |
| 1056 | |
| 1057 | public long getDurationAt(int index) { |
| 1058 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 1059 | } |
| 1060 | |
| 1061 | public int getLevelAt(int index) { |
| 1062 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 1063 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1064 | } |
| 1065 | |
| 1066 | public int getInitModeAt(int index) { |
| 1067 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1068 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1069 | } |
| 1070 | |
| 1071 | public int getModModeAt(int index) { |
| 1072 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1073 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1074 | } |
| 1075 | |
| 1076 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 1077 | boolean hasData = false; |
| 1078 | while (topOffset >= 0) { |
| 1079 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1080 | topOffset -= 4; |
| 1081 | if (!hasData && digit == 0) { |
| 1082 | continue; |
| 1083 | } |
| 1084 | hasData = true; |
| 1085 | if (digit >= 0 && digit <= 9) { |
| 1086 | out.append((char)('0' + digit)); |
| 1087 | } else { |
| 1088 | out.append((char)('a' + digit - 10)); |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1094 | long item = mStepDurations[index]; |
| 1095 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1096 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1097 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1098 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1099 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1100 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1101 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1102 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1103 | case Display.STATE_OFF: out.append('f'); break; |
| 1104 | case Display.STATE_ON: out.append('o'); break; |
| 1105 | case Display.STATE_DOZE: out.append('d'); break; |
| 1106 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1107 | } |
| 1108 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1109 | out.append('p'); |
| 1110 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1111 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1112 | out.append('i'); |
| 1113 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1114 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1115 | case Display.STATE_OFF: out.append('F'); break; |
| 1116 | case Display.STATE_ON: out.append('O'); break; |
| 1117 | case Display.STATE_DOZE: out.append('D'); break; |
| 1118 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1119 | } |
| 1120 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1121 | out.append('P'); |
| 1122 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1123 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1124 | out.append('I'); |
| 1125 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1126 | out.append('-'); |
| 1127 | appendHex(level, 4, out); |
| 1128 | out.append('-'); |
| 1129 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1130 | } |
| 1131 | |
| 1132 | public void decodeEntryAt(int index, String value) { |
| 1133 | final int N = value.length(); |
| 1134 | int i = 0; |
| 1135 | char c; |
| 1136 | long out = 0; |
| 1137 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1138 | i++; |
| 1139 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1140 | 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] | 1141 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1142 | 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] | 1143 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1144 | 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] | 1145 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1146 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1147 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1148 | break; |
| 1149 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1150 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1151 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1152 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1153 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1154 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1155 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1156 | break; |
| 1157 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1158 | break; |
| 1159 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1160 | break; |
| 1161 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1162 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1163 | break; |
| 1164 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1165 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1166 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1167 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1168 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1169 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1173 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1174 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1175 | i++; |
| 1176 | level <<= 4; |
| 1177 | if (c >= '0' && c <= '9') { |
| 1178 | level += c - '0'; |
| 1179 | } else if (c >= 'a' && c <= 'f') { |
| 1180 | level += c - 'a' + 10; |
| 1181 | } else if (c >= 'A' && c <= 'F') { |
| 1182 | level += c - 'A' + 10; |
| 1183 | } |
| 1184 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1185 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1186 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1187 | long duration = 0; |
| 1188 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1189 | i++; |
| 1190 | duration <<= 4; |
| 1191 | if (c >= '0' && c <= '9') { |
| 1192 | duration += c - '0'; |
| 1193 | } else if (c >= 'a' && c <= 'f') { |
| 1194 | duration += c - 'a' + 10; |
| 1195 | } else if (c >= 'A' && c <= 'F') { |
| 1196 | duration += c - 'A' + 10; |
| 1197 | } |
| 1198 | } |
| 1199 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1200 | } |
| 1201 | |
| 1202 | public void init() { |
| 1203 | mLastStepTime = -1; |
| 1204 | mNumStepDurations = 0; |
| 1205 | } |
| 1206 | |
| 1207 | public void clearTime() { |
| 1208 | mLastStepTime = -1; |
| 1209 | } |
| 1210 | |
| 1211 | public long computeTimePerLevel() { |
| 1212 | final long[] steps = mStepDurations; |
| 1213 | final int numSteps = mNumStepDurations; |
| 1214 | |
| 1215 | // For now we'll do a simple average across all steps. |
| 1216 | if (numSteps <= 0) { |
| 1217 | return -1; |
| 1218 | } |
| 1219 | long total = 0; |
| 1220 | for (int i=0; i<numSteps; i++) { |
| 1221 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1222 | } |
| 1223 | return total / numSteps; |
| 1224 | /* |
| 1225 | long[] buckets = new long[numSteps]; |
| 1226 | int numBuckets = 0; |
| 1227 | int numToAverage = 4; |
| 1228 | int i = 0; |
| 1229 | while (i < numSteps) { |
| 1230 | long totalTime = 0; |
| 1231 | int num = 0; |
| 1232 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1233 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1234 | num++; |
| 1235 | } |
| 1236 | buckets[numBuckets] = totalTime / num; |
| 1237 | numBuckets++; |
| 1238 | numToAverage *= 2; |
| 1239 | i += num; |
| 1240 | } |
| 1241 | if (numBuckets < 1) { |
| 1242 | return -1; |
| 1243 | } |
| 1244 | long averageTime = buckets[numBuckets-1]; |
| 1245 | for (i=numBuckets-2; i>=0; i--) { |
| 1246 | averageTime = (averageTime + buckets[i]) / 2; |
| 1247 | } |
| 1248 | return averageTime; |
| 1249 | */ |
| 1250 | } |
| 1251 | |
| 1252 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1253 | int[] outNumOfInterest) { |
| 1254 | final long[] steps = mStepDurations; |
| 1255 | final int count = mNumStepDurations; |
| 1256 | if (count <= 0) { |
| 1257 | return -1; |
| 1258 | } |
| 1259 | long total = 0; |
| 1260 | int numOfInterest = 0; |
| 1261 | for (int i=0; i<count; i++) { |
| 1262 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1263 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1264 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1265 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1266 | // If the modes of interest didn't change during this step period... |
| 1267 | if ((modMode&modesOfInterest) == 0) { |
| 1268 | // And the mode values during this period match those we are measuring... |
| 1269 | if ((initMode&modesOfInterest) == modeValues) { |
| 1270 | // Then this can be used to estimate the total time! |
| 1271 | numOfInterest++; |
| 1272 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | if (numOfInterest <= 0) { |
| 1277 | return -1; |
| 1278 | } |
| 1279 | |
| 1280 | if (outNumOfInterest != null) { |
| 1281 | outNumOfInterest[0] = numOfInterest; |
| 1282 | } |
| 1283 | |
| 1284 | // The estimated time is the average time we spend in each level, multipled |
| 1285 | // by 100 -- the total number of battery levels |
| 1286 | return (total / numOfInterest) * 100; |
| 1287 | } |
| 1288 | |
| 1289 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1290 | int stepCount = mNumStepDurations; |
| 1291 | final long lastStepTime = mLastStepTime; |
| 1292 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1293 | final long[] steps = mStepDurations; |
| 1294 | long duration = elapsedRealtime - lastStepTime; |
| 1295 | for (int i=0; i<numStepLevels; i++) { |
| 1296 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1297 | long thisDuration = duration / (numStepLevels-i); |
| 1298 | duration -= thisDuration; |
| 1299 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1300 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1301 | } |
| 1302 | steps[0] = thisDuration | modeBits; |
| 1303 | } |
| 1304 | stepCount += numStepLevels; |
| 1305 | if (stepCount > steps.length) { |
| 1306 | stepCount = steps.length; |
| 1307 | } |
| 1308 | } |
| 1309 | mNumStepDurations = stepCount; |
| 1310 | mLastStepTime = elapsedRealtime; |
| 1311 | } |
| 1312 | |
| 1313 | public void readFromParcel(Parcel in) { |
| 1314 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1315 | if (N > mStepDurations.length) { |
| 1316 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1317 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1318 | mNumStepDurations = N; |
| 1319 | for (int i=0; i<N; i++) { |
| 1320 | mStepDurations[i] = in.readLong(); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | public void writeToParcel(Parcel out) { |
| 1325 | final int N = mNumStepDurations; |
| 1326 | out.writeInt(N); |
| 1327 | for (int i=0; i<N; i++) { |
| 1328 | out.writeLong(mStepDurations[i]); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1333 | public static final class PackageChange { |
| 1334 | public String mPackageName; |
| 1335 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1336 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1339 | public static final class DailyItem { |
| 1340 | public long mStartTime; |
| 1341 | public long mEndTime; |
| 1342 | public LevelStepTracker mDischargeSteps; |
| 1343 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1344 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1348 | |
| 1349 | public abstract long getCurrentDailyStartTime(); |
| 1350 | |
| 1351 | public abstract long getNextMinDailyDeadline(); |
| 1352 | |
| 1353 | public abstract long getNextMaxDailyDeadline(); |
| 1354 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1355 | public abstract long[] getCpuFreqs(); |
| 1356 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1357 | public final static class HistoryTag { |
| 1358 | public String string; |
| 1359 | public int uid; |
| 1360 | |
| 1361 | public int poolIdx; |
| 1362 | |
| 1363 | public void setTo(HistoryTag o) { |
| 1364 | string = o.string; |
| 1365 | uid = o.uid; |
| 1366 | poolIdx = o.poolIdx; |
| 1367 | } |
| 1368 | |
| 1369 | public void setTo(String _string, int _uid) { |
| 1370 | string = _string; |
| 1371 | uid = _uid; |
| 1372 | poolIdx = -1; |
| 1373 | } |
| 1374 | |
| 1375 | public void writeToParcel(Parcel dest, int flags) { |
| 1376 | dest.writeString(string); |
| 1377 | dest.writeInt(uid); |
| 1378 | } |
| 1379 | |
| 1380 | public void readFromParcel(Parcel src) { |
| 1381 | string = src.readString(); |
| 1382 | uid = src.readInt(); |
| 1383 | poolIdx = -1; |
| 1384 | } |
| 1385 | |
| 1386 | @Override |
| 1387 | public boolean equals(Object o) { |
| 1388 | if (this == o) return true; |
| 1389 | if (o == null || getClass() != o.getClass()) return false; |
| 1390 | |
| 1391 | HistoryTag that = (HistoryTag) o; |
| 1392 | |
| 1393 | if (uid != that.uid) return false; |
| 1394 | if (!string.equals(that.string)) return false; |
| 1395 | |
| 1396 | return true; |
| 1397 | } |
| 1398 | |
| 1399 | @Override |
| 1400 | public int hashCode() { |
| 1401 | int result = string.hashCode(); |
| 1402 | result = 31 * result + uid; |
| 1403 | return result; |
| 1404 | } |
| 1405 | } |
| 1406 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1407 | /** |
| 1408 | * Optional detailed information that can go into a history step. This is typically |
| 1409 | * generated each time the battery level changes. |
| 1410 | */ |
| 1411 | public final static class HistoryStepDetails { |
| 1412 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1413 | public int userTime; |
| 1414 | public int systemTime; |
| 1415 | |
| 1416 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1417 | public int appCpuUid1; |
| 1418 | public int appCpuUTime1; |
| 1419 | public int appCpuSTime1; |
| 1420 | public int appCpuUid2; |
| 1421 | public int appCpuUTime2; |
| 1422 | public int appCpuSTime2; |
| 1423 | public int appCpuUid3; |
| 1424 | public int appCpuUTime3; |
| 1425 | public int appCpuSTime3; |
| 1426 | |
| 1427 | // Information from /proc/stat |
| 1428 | public int statUserTime; |
| 1429 | public int statSystemTime; |
| 1430 | public int statIOWaitTime; |
| 1431 | public int statIrqTime; |
| 1432 | public int statSoftIrqTime; |
| 1433 | public int statIdlTime; |
| 1434 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1435 | // Platform-level low power state stats |
| 1436 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1437 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1438 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1439 | public HistoryStepDetails() { |
| 1440 | clear(); |
| 1441 | } |
| 1442 | |
| 1443 | public void clear() { |
| 1444 | userTime = systemTime = 0; |
| 1445 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1446 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1447 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1448 | } |
| 1449 | |
| 1450 | public void writeToParcel(Parcel out) { |
| 1451 | out.writeInt(userTime); |
| 1452 | out.writeInt(systemTime); |
| 1453 | out.writeInt(appCpuUid1); |
| 1454 | out.writeInt(appCpuUTime1); |
| 1455 | out.writeInt(appCpuSTime1); |
| 1456 | out.writeInt(appCpuUid2); |
| 1457 | out.writeInt(appCpuUTime2); |
| 1458 | out.writeInt(appCpuSTime2); |
| 1459 | out.writeInt(appCpuUid3); |
| 1460 | out.writeInt(appCpuUTime3); |
| 1461 | out.writeInt(appCpuSTime3); |
| 1462 | out.writeInt(statUserTime); |
| 1463 | out.writeInt(statSystemTime); |
| 1464 | out.writeInt(statIOWaitTime); |
| 1465 | out.writeInt(statIrqTime); |
| 1466 | out.writeInt(statSoftIrqTime); |
| 1467 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1468 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1469 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | public void readFromParcel(Parcel in) { |
| 1473 | userTime = in.readInt(); |
| 1474 | systemTime = in.readInt(); |
| 1475 | appCpuUid1 = in.readInt(); |
| 1476 | appCpuUTime1 = in.readInt(); |
| 1477 | appCpuSTime1 = in.readInt(); |
| 1478 | appCpuUid2 = in.readInt(); |
| 1479 | appCpuUTime2 = in.readInt(); |
| 1480 | appCpuSTime2 = in.readInt(); |
| 1481 | appCpuUid3 = in.readInt(); |
| 1482 | appCpuUTime3 = in.readInt(); |
| 1483 | appCpuSTime3 = in.readInt(); |
| 1484 | statUserTime = in.readInt(); |
| 1485 | statSystemTime = in.readInt(); |
| 1486 | statIOWaitTime = in.readInt(); |
| 1487 | statIrqTime = in.readInt(); |
| 1488 | statSoftIrqTime = in.readInt(); |
| 1489 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1490 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1491 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1495 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1496 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1497 | |
| 1498 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1499 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1500 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1501 | 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] | 1502 | public static final byte CMD_NULL = -1; |
| 1503 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1504 | public static final byte CMD_CURRENT_TIME = 5; |
| 1505 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1506 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1507 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1508 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1509 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1510 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1511 | /** |
| 1512 | * Return whether the command code is a delta data update. |
| 1513 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1514 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1515 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1518 | public byte batteryLevel; |
| 1519 | public byte batteryStatus; |
| 1520 | public byte batteryHealth; |
| 1521 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1522 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1523 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1524 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1525 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1526 | // The charge of the battery in micro-Ampere-hours. |
| 1527 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1528 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1529 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1530 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1531 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1532 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1533 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1534 | 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] | 1535 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1536 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1537 | 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] | 1538 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1539 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1540 | 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] | 1541 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1542 | // These states always appear directly in the first int token |
| 1543 | // of a delta change; they should be ones that change relatively |
| 1544 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1545 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1546 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1547 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1548 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1549 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1550 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1551 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1552 | // Do not use, this is used for coulomb delta count. |
| 1553 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1554 | // These are on the lower bits used for the command; if they change |
| 1555 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1556 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1557 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1558 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1559 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1560 | 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] | 1561 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1562 | // empty slot |
| 1563 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1564 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1565 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1566 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1567 | |
| 1568 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1569 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1570 | public int states; |
| 1571 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1572 | // Constants from WIFI_SUPPL_STATE_* |
| 1573 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1574 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1575 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1576 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1577 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1578 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 1579 | // Values for NUM_GPS_SIGNAL_QUALITY_LEVELS |
| 1580 | public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7; |
| 1581 | public static final int STATE2_GPS_SIGNAL_QUALITY_MASK = |
| 1582 | 0x1 << STATE2_GPS_SIGNAL_QUALITY_SHIFT; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1583 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1584 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1585 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1586 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1587 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1588 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1589 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1590 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1591 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1592 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1593 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1594 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1595 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 1596 | public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19; |
Mike Ma | 926a97c | 2018-03-25 02:32:35 -0700 | [diff] [blame] | 1597 | public static final int STATE2_USB_DATA_LINK_FLAG = 1 << 18; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1598 | |
| 1599 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1600 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1601 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1602 | |
| 1603 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1604 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1605 | public int states2; |
| 1606 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1607 | // The wake lock that was acquired at this point. |
| 1608 | public HistoryTag wakelockTag; |
| 1609 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1610 | // Kernel wakeup reason at this point. |
| 1611 | public HistoryTag wakeReasonTag; |
| 1612 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1613 | // Non-null when there is more detailed information at this step. |
| 1614 | public HistoryStepDetails stepDetails; |
| 1615 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1616 | public static final int EVENT_FLAG_START = 0x8000; |
| 1617 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1618 | |
| 1619 | // No event in this item. |
| 1620 | public static final int EVENT_NONE = 0x0000; |
| 1621 | // Event is about a process that is running. |
| 1622 | public static final int EVENT_PROC = 0x0001; |
| 1623 | // Event is about an application package that is in the foreground. |
| 1624 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1625 | // Event is about an application package that is at the top of the screen. |
| 1626 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1627 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1628 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1629 | // Events for all additional wake locks aquired/release within a wake block. |
| 1630 | // These are not generated by default. |
| 1631 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1632 | // Event is about an application executing a scheduled job. |
| 1633 | public static final int EVENT_JOB = 0x0006; |
| 1634 | // Events for users running. |
| 1635 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1636 | // Events for foreground user. |
| 1637 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1638 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1639 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1640 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1641 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1642 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1643 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1644 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1645 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1646 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1647 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1648 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1649 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1650 | // 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] | 1651 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1652 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1653 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1654 | // Event for a package being on the temporary whitelist. |
| 1655 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1656 | // Event for the screen waking up. |
| 1657 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1658 | // Event for the UID that woke up the application processor. |
| 1659 | // Used for wakeups coming from WiFi, modem, etc. |
| 1660 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1661 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1662 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1663 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1664 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1665 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1666 | // Mask to extract out only the type part of the event. |
| 1667 | 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] | 1668 | |
| 1669 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1670 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1671 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1672 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1673 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1674 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1675 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1676 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1677 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1678 | 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] | 1679 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1680 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1681 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1682 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1683 | public static final int EVENT_USER_FOREGROUND_START = |
| 1684 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1685 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1686 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1687 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1688 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1689 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1690 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1691 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1692 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1693 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1694 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1695 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1696 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1697 | |
| 1698 | // For CMD_EVENT. |
| 1699 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1700 | public HistoryTag eventTag; |
| 1701 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1702 | // 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] | 1703 | public long currentTime; |
| 1704 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1705 | // Meta-data when reading. |
| 1706 | public int numReadInts; |
| 1707 | |
| 1708 | // Pre-allocated objects. |
| 1709 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1710 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1711 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1712 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1713 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1714 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1715 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1716 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1717 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1718 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1719 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1720 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1721 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1722 | public int describeContents() { |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | public void writeToParcel(Parcel dest, int flags) { |
| 1727 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1728 | int bat = (((int)cmd)&0xff) |
| 1729 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1730 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1731 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1732 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1733 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1734 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1735 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1736 | dest.writeInt(bat); |
| 1737 | bat = (((int)batteryTemperature)&0xffff) |
| 1738 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1739 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1740 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1741 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1742 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1743 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1744 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1745 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1746 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1747 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1748 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1749 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1750 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1751 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1752 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1753 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1754 | dest.writeLong(currentTime); |
| 1755 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1756 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1757 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1758 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1759 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1760 | int bat = src.readInt(); |
| 1761 | cmd = (byte)(bat&0xff); |
| 1762 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1763 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1764 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1765 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1766 | int bat2 = src.readInt(); |
| 1767 | batteryTemperature = (short)(bat2&0xffff); |
| 1768 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1769 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1770 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1771 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1772 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1773 | wakelockTag = localWakelockTag; |
| 1774 | wakelockTag.readFromParcel(src); |
| 1775 | } else { |
| 1776 | wakelockTag = null; |
| 1777 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1778 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1779 | wakeReasonTag = localWakeReasonTag; |
| 1780 | wakeReasonTag.readFromParcel(src); |
| 1781 | } else { |
| 1782 | wakeReasonTag = null; |
| 1783 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1784 | if ((bat&0x40000000) != 0) { |
| 1785 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1786 | eventTag = localEventTag; |
| 1787 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1788 | } else { |
| 1789 | eventCode = EVENT_NONE; |
| 1790 | eventTag = null; |
| 1791 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1792 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1793 | currentTime = src.readLong(); |
| 1794 | } else { |
| 1795 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1796 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1797 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1800 | public void clear() { |
| 1801 | time = 0; |
| 1802 | cmd = CMD_NULL; |
| 1803 | batteryLevel = 0; |
| 1804 | batteryStatus = 0; |
| 1805 | batteryHealth = 0; |
| 1806 | batteryPlugType = 0; |
| 1807 | batteryTemperature = 0; |
| 1808 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1809 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1810 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1811 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1812 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1813 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1814 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1815 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1816 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1817 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1818 | public void setTo(HistoryItem o) { |
| 1819 | time = o.time; |
| 1820 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1821 | setToCommon(o); |
| 1822 | } |
| 1823 | |
| 1824 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1825 | this.time = time; |
| 1826 | this.cmd = cmd; |
| 1827 | setToCommon(o); |
| 1828 | } |
| 1829 | |
| 1830 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1831 | batteryLevel = o.batteryLevel; |
| 1832 | batteryStatus = o.batteryStatus; |
| 1833 | batteryHealth = o.batteryHealth; |
| 1834 | batteryPlugType = o.batteryPlugType; |
| 1835 | batteryTemperature = o.batteryTemperature; |
| 1836 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1837 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1838 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1839 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1840 | if (o.wakelockTag != null) { |
| 1841 | wakelockTag = localWakelockTag; |
| 1842 | wakelockTag.setTo(o.wakelockTag); |
| 1843 | } else { |
| 1844 | wakelockTag = null; |
| 1845 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1846 | if (o.wakeReasonTag != null) { |
| 1847 | wakeReasonTag = localWakeReasonTag; |
| 1848 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1849 | } else { |
| 1850 | wakeReasonTag = null; |
| 1851 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1852 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1853 | if (o.eventTag != null) { |
| 1854 | eventTag = localEventTag; |
| 1855 | eventTag.setTo(o.eventTag); |
| 1856 | } else { |
| 1857 | eventTag = null; |
| 1858 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1859 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1862 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1863 | return batteryLevel == o.batteryLevel |
| 1864 | && batteryStatus == o.batteryStatus |
| 1865 | && batteryHealth == o.batteryHealth |
| 1866 | && batteryPlugType == o.batteryPlugType |
| 1867 | && batteryTemperature == o.batteryTemperature |
| 1868 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1869 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1870 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1871 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1872 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1873 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1874 | |
| 1875 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1876 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1877 | return false; |
| 1878 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1879 | if (wakelockTag != o.wakelockTag) { |
| 1880 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1881 | return false; |
| 1882 | } |
| 1883 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1884 | return false; |
| 1885 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1886 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1887 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1888 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1889 | return false; |
| 1890 | } |
| 1891 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1892 | return false; |
| 1893 | } |
| 1894 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1895 | if (eventTag != o.eventTag) { |
| 1896 | if (eventTag == null || o.eventTag == null) { |
| 1897 | return false; |
| 1898 | } |
| 1899 | if (!eventTag.equals(o.eventTag)) { |
| 1900 | return false; |
| 1901 | } |
| 1902 | } |
| 1903 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1904 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1905 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1906 | |
| 1907 | public final static class HistoryEventTracker { |
| 1908 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1909 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1910 | |
| 1911 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1912 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1913 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1914 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1915 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1916 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1917 | mActiveEvents[idx] = active; |
| 1918 | } |
| 1919 | SparseIntArray uids = active.get(name); |
| 1920 | if (uids == null) { |
| 1921 | uids = new SparseIntArray(); |
| 1922 | active.put(name, uids); |
| 1923 | } |
| 1924 | if (uids.indexOfKey(uid) >= 0) { |
| 1925 | // Already set, nothing to do! |
| 1926 | return false; |
| 1927 | } |
| 1928 | uids.put(uid, poolIdx); |
| 1929 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1930 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1931 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1932 | if (active == null) { |
| 1933 | // not currently active, nothing to do. |
| 1934 | return false; |
| 1935 | } |
| 1936 | SparseIntArray uids = active.get(name); |
| 1937 | if (uids == null) { |
| 1938 | // not currently active, nothing to do. |
| 1939 | return false; |
| 1940 | } |
| 1941 | idx = uids.indexOfKey(uid); |
| 1942 | if (idx < 0) { |
| 1943 | // not currently active, nothing to do. |
| 1944 | return false; |
| 1945 | } |
| 1946 | uids.removeAt(idx); |
| 1947 | if (uids.size() <= 0) { |
| 1948 | active.remove(name); |
| 1949 | } |
| 1950 | } |
| 1951 | return true; |
| 1952 | } |
| 1953 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1954 | public void removeEvents(int code) { |
| 1955 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1956 | mActiveEvents[idx] = null; |
| 1957 | } |
| 1958 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1959 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1960 | return mActiveEvents[code]; |
| 1961 | } |
| 1962 | } |
| 1963 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1964 | public static final class BitDescription { |
| 1965 | public final int mask; |
| 1966 | public final int shift; |
| 1967 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1968 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1969 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1970 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1972 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1973 | this.mask = mask; |
| 1974 | this.shift = -1; |
| 1975 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1976 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1977 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1978 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1979 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1980 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1981 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1982 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1983 | this.mask = mask; |
| 1984 | this.shift = shift; |
| 1985 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1986 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1987 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1988 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1989 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1990 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1991 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1992 | /** |
| 1993 | * Don't allow any more batching in to the current history event. This |
| 1994 | * is called when printing partial histories, so to ensure that the next |
| 1995 | * history event will go in to a new batch after what was printed in the |
| 1996 | * last partial history. |
| 1997 | */ |
| 1998 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1999 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2000 | public abstract int getHistoryTotalSize(); |
| 2001 | |
| 2002 | public abstract int getHistoryUsedSize(); |
| 2003 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2004 | public abstract boolean startIteratingHistoryLocked(); |
| 2005 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2006 | public abstract int getHistoryStringPoolSize(); |
| 2007 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2008 | public abstract int getHistoryStringPoolBytes(); |
| 2009 | |
| 2010 | public abstract String getHistoryTagPoolString(int index); |
| 2011 | |
| 2012 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2013 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2014 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 2015 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2016 | public abstract void finishIteratingHistoryLocked(); |
| 2017 | |
| 2018 | public abstract boolean startIteratingOldHistoryLocked(); |
| 2019 | |
| 2020 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 2021 | |
| 2022 | public abstract void finishIteratingOldHistoryLocked(); |
| 2023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2025 | * Return the base time offset for the battery history. |
| 2026 | */ |
| 2027 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2028 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2029 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | * Returns the number of times the device has been started. |
| 2031 | */ |
| 2032 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2035 | * 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] | 2036 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2037 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | * {@hide} |
| 2039 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2040 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2041 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2042 | /** |
| 2043 | * Returns the number of times the screen was turned on. |
| 2044 | * |
| 2045 | * {@hide} |
| 2046 | */ |
| 2047 | public abstract int getScreenOnCount(int which); |
| 2048 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2049 | /** |
| 2050 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 2051 | * running on battery. |
| 2052 | * |
| 2053 | * {@hide} |
| 2054 | */ |
| 2055 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 2056 | |
| 2057 | /** |
| 2058 | * Returns the number of times the screen was turned dozing. |
| 2059 | * |
| 2060 | * {@hide} |
| 2061 | */ |
| 2062 | public abstract int getScreenDozeCount(int which); |
| 2063 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2064 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 2065 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2066 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 2067 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 2068 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 2069 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 2070 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2071 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2072 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 2073 | "dark", "dim", "medium", "light", "bright" |
| 2074 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2075 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2076 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 2077 | "0", "1", "2", "3", "4" |
| 2078 | }; |
| 2079 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2080 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2081 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2082 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2083 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2084 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2085 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2086 | * {@hide} |
| 2087 | */ |
| 2088 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2089 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2092 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2093 | * |
| 2094 | * {@hide} |
| 2095 | */ |
| 2096 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2097 | |
| 2098 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2099 | * 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] | 2100 | * running on battery. |
| 2101 | * |
| 2102 | * {@hide} |
| 2103 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2104 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2105 | |
| 2106 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2107 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2108 | * |
| 2109 | * {@hide} |
| 2110 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2111 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2112 | |
| 2113 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2114 | * Constant for device idle mode: not active. |
| 2115 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2116 | public static final int DEVICE_IDLE_MODE_OFF = ServerProtoEnums.DEVICE_IDLE_MODE_OFF; // 0 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2117 | |
| 2118 | /** |
| 2119 | * Constant for device idle mode: active in lightweight mode. |
| 2120 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2121 | public static final int DEVICE_IDLE_MODE_LIGHT = ServerProtoEnums.DEVICE_IDLE_MODE_LIGHT; // 1 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2122 | |
| 2123 | /** |
| 2124 | * Constant for device idle mode: active in full mode. |
| 2125 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2126 | public static final int DEVICE_IDLE_MODE_DEEP = ServerProtoEnums.DEVICE_IDLE_MODE_DEEP; // 2 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2127 | |
| 2128 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2129 | * Returns the time in microseconds that device has been in idle mode while |
| 2130 | * running on battery. |
| 2131 | * |
| 2132 | * {@hide} |
| 2133 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2134 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2135 | |
| 2136 | /** |
| 2137 | * Returns the number of times that the devie has gone in to idle mode. |
| 2138 | * |
| 2139 | * {@hide} |
| 2140 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2141 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2142 | |
| 2143 | /** |
| 2144 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2145 | * mode, not in idle maintenance etc). |
| 2146 | */ |
| 2147 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2148 | |
| 2149 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2150 | * 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] | 2151 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2152 | * counts all of the time that we consider the device to be idle, whether or not |
| 2153 | * it is currently in the actual device idle mode. |
| 2154 | * |
| 2155 | * {@hide} |
| 2156 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2157 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2158 | |
| 2159 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2160 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2161 | * |
| 2162 | * {@hide} |
| 2163 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2164 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2165 | |
| 2166 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2167 | * Returns the number of times that connectivity state changed. |
| 2168 | * |
| 2169 | * {@hide} |
| 2170 | */ |
| 2171 | public abstract int getNumConnectivityChange(int which); |
| 2172 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2173 | |
| 2174 | /** |
| 2175 | * Returns the time in microseconds that the phone has been running with |
| 2176 | * the given GPS signal quality level |
| 2177 | * |
| 2178 | * {@hide} |
| 2179 | */ |
| 2180 | public abstract long getGpsSignalQualityTime(int strengthBin, |
| 2181 | long elapsedRealtimeUs, int which); |
| 2182 | |
| 2183 | /** |
| 2184 | * Returns the GPS battery drain in mA-ms |
| 2185 | * |
| 2186 | * {@hide} |
| 2187 | */ |
| 2188 | public abstract long getGpsBatteryDrainMaMs(); |
| 2189 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2190 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2191 | * 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] | 2192 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2193 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | * {@hide} |
| 2195 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2196 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2197 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2198 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2199 | * Returns the number of times a phone call was activated. |
| 2200 | * |
| 2201 | * {@hide} |
| 2202 | */ |
| 2203 | public abstract int getPhoneOnCount(int which); |
| 2204 | |
| 2205 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2206 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2207 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2208 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2209 | * {@hide} |
| 2210 | */ |
| 2211 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2212 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2213 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2214 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2215 | * Returns the time in microseconds that the phone has been trying to |
| 2216 | * acquire a signal. |
| 2217 | * |
| 2218 | * {@hide} |
| 2219 | */ |
| 2220 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2221 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2222 | |
| 2223 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2224 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2225 | * acquire a signal. |
| 2226 | * |
| 2227 | * {@hide} |
| 2228 | */ |
| 2229 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2230 | |
| 2231 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2232 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2233 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2234 | * {@hide} |
| 2235 | */ |
| 2236 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2237 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2238 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2239 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2240 | * counts. |
| 2241 | */ |
| 2242 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2243 | |
| 2244 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2245 | * Returns the time in microseconds that the mobile network has been active |
| 2246 | * (in a high power state). |
| 2247 | * |
| 2248 | * {@hide} |
| 2249 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2250 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2251 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2252 | /** |
| 2253 | * Returns the number of times that the mobile network has transitioned to the |
| 2254 | * active state. |
| 2255 | * |
| 2256 | * {@hide} |
| 2257 | */ |
| 2258 | public abstract int getMobileRadioActiveCount(int which); |
| 2259 | |
| 2260 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2261 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2262 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2263 | * from the radio. |
| 2264 | * |
| 2265 | * {@hide} |
| 2266 | */ |
| 2267 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2268 | |
| 2269 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2270 | * Returns the time in microseconds that the mobile network has been active |
| 2271 | * (in a high power state) but not being able to blame on an app. |
| 2272 | * |
| 2273 | * {@hide} |
| 2274 | */ |
| 2275 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2276 | |
| 2277 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2278 | * 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] | 2279 | * |
| 2280 | * {@hide} |
| 2281 | */ |
| 2282 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2283 | |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 2284 | public static final int DATA_CONNECTION_NONE = 0; |
| 2285 | public static final int DATA_CONNECTION_OTHER = TelephonyManager.MAX_NETWORK_TYPE + 1; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2286 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2287 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2288 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2289 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Bookatz | df6baff | 2018-12-12 19:38:11 -0800 | [diff] [blame] | 2290 | "ehrpd", "hspap", "gsm", "td_scdma", "iwlan", "lte_ca", "nr", |
| 2291 | "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2292 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2293 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2294 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2295 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2296 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2297 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2298 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2299 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2300 | * {@hide} |
| 2301 | */ |
| 2302 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2303 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2306 | * Returns the number of times the phone has entered the given data |
| 2307 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2308 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2309 | * {@hide} |
| 2310 | */ |
| 2311 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2312 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2313 | /** |
| 2314 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2315 | */ |
| 2316 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2317 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2318 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2319 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2320 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2321 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2322 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2323 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2324 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2325 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2326 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2327 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2328 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2329 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2330 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2331 | |
| 2332 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2333 | |
| 2334 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2335 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2336 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2337 | "group-handshake", "completed", "dormant", "uninit" |
| 2338 | }; |
| 2339 | |
| 2340 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2341 | "inv", "dsc", "dis", "inact", "scan", |
| 2342 | "auth", "ascing", "asced", "4-way", |
| 2343 | "group", "compl", "dorm", "uninit" |
| 2344 | }; |
| 2345 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2346 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2347 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2348 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2349 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2350 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2351 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2352 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2353 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2354 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2355 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2356 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2357 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2358 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2359 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2360 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2361 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2362 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2363 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2364 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2365 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2366 | new String[] {"in", "out", "emergency", "off"}, |
| 2367 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2368 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2369 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2370 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2371 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2372 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2373 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2374 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2375 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2376 | |
Mike Ma | 926a97c | 2018-03-25 02:32:35 -0700 | [diff] [blame] | 2377 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2378 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2379 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2380 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2381 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2382 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2383 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2384 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2385 | new String[] { "off", "light", "full", "???" }, |
| 2386 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2387 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
Mike Ma | 926a97c | 2018-03-25 02:32:35 -0700 | [diff] [blame] | 2388 | new BitDescription(HistoryItem.STATE2_USB_DATA_LINK_FLAG, "usb_data", "Ud"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2389 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2390 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2391 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2392 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2393 | new String[] { "0", "1", "2", "3", "4" }, |
| 2394 | new String[] { "0", "1", "2", "3", "4" }), |
| 2395 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2396 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2397 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2398 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2399 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2400 | new BitDescription(HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG, |
| 2401 | "cellular_high_tx_power", "Chtp"), |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2402 | new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK, |
| 2403 | HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss", |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2404 | new String[] { "poor", "good"}, new String[] { "poor", "good"}) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2405 | }; |
| 2406 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2407 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2408 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2409 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2410 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2411 | }; |
| 2412 | |
| 2413 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2414 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2415 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2416 | "Esw", "Ewa", "Elw", "Eec" |
| 2417 | }; |
| 2418 | |
| 2419 | @FunctionalInterface |
| 2420 | public interface IntToString { |
| 2421 | String applyAsString(int val); |
| 2422 | } |
| 2423 | |
| 2424 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2425 | private static final IntToString sIntToString = Integer::toString; |
| 2426 | |
| 2427 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2428 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
Hirono Shiyama | 50ea4d0 | 2018-08-27 16:41:28 +0900 | [diff] [blame] | 2429 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString, |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2430 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2431 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2432 | }; |
| 2433 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2434 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2435 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2436 | * Note that this may be different from the sum of per uid timer values. |
| 2437 | * |
| 2438 | * {@hide} |
| 2439 | */ |
| 2440 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2441 | |
| 2442 | /** |
| 2443 | * Returns total time for WiFi Multicast Wakelock timer |
| 2444 | * Note that this may be different from the sum of per uid timer values. |
| 2445 | * |
| 2446 | * {@hide} |
| 2447 | */ |
| 2448 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2449 | |
| 2450 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2451 | * 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] | 2452 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2453 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2454 | * {@hide} |
| 2455 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2456 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2457 | |
| 2458 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2459 | * Returns the time in microseconds that wifi has been active while the device was |
| 2460 | * running on battery. |
| 2461 | * |
| 2462 | * {@hide} |
| 2463 | */ |
| 2464 | public abstract long getWifiActiveTime(long elapsedRealtimeUs, int which); |
| 2465 | |
| 2466 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2467 | * 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] | 2468 | * been in the running state while the device was running on battery. |
| 2469 | * |
| 2470 | * {@hide} |
| 2471 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2472 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2473 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2474 | public static final int WIFI_STATE_OFF = 0; |
| 2475 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2476 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2477 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2478 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2479 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2480 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2481 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2482 | |
| 2483 | static final String[] WIFI_STATE_NAMES = { |
| 2484 | "off", "scanning", "no_net", "disconn", |
| 2485 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2486 | }; |
| 2487 | |
| 2488 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2489 | |
| 2490 | /** |
| 2491 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2492 | * |
| 2493 | * {@hide} |
| 2494 | */ |
| 2495 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2496 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2497 | |
| 2498 | /** |
| 2499 | * Returns the number of times that WiFi has entered the given state. |
| 2500 | * |
| 2501 | * {@hide} |
| 2502 | */ |
| 2503 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2504 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2505 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2506 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2507 | * |
| 2508 | * {@hide} |
| 2509 | */ |
| 2510 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2511 | |
| 2512 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2513 | * Returns the time in microseconds that the wifi supplicant has been |
| 2514 | * in a given state. |
| 2515 | * |
| 2516 | * {@hide} |
| 2517 | */ |
| 2518 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2519 | |
| 2520 | /** |
| 2521 | * Returns the number of times that the wifi supplicant has transitioned |
| 2522 | * to a given state. |
| 2523 | * |
| 2524 | * {@hide} |
| 2525 | */ |
| 2526 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2527 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2528 | /** |
| 2529 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2530 | * |
| 2531 | * {@hide} |
| 2532 | */ |
| 2533 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2534 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2535 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2536 | |
| 2537 | /** |
| 2538 | * Returns the time in microseconds that WIFI has been running with |
| 2539 | * the given signal strength. |
| 2540 | * |
| 2541 | * {@hide} |
| 2542 | */ |
| 2543 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2544 | long elapsedRealtimeUs, int which); |
| 2545 | |
| 2546 | /** |
| 2547 | * Returns the number of times WIFI has entered the given signal strength. |
| 2548 | * |
| 2549 | * {@hide} |
| 2550 | */ |
| 2551 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2552 | |
| 2553 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2554 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2555 | * |
| 2556 | * {@hide} |
| 2557 | */ |
| 2558 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2559 | |
| 2560 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2561 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2562 | * running on battery. |
| 2563 | * |
| 2564 | * {@hide} |
| 2565 | */ |
| 2566 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2567 | |
| 2568 | /** |
| 2569 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2570 | * running on battery. |
| 2571 | * |
| 2572 | * {@hide} |
| 2573 | */ |
| 2574 | public abstract long getFlashlightOnCount(int which); |
| 2575 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2576 | /** |
| 2577 | * Returns the time in microseconds that the camera has been on while the device was |
| 2578 | * running on battery. |
| 2579 | * |
| 2580 | * {@hide} |
| 2581 | */ |
| 2582 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2583 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2584 | /** |
| 2585 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2586 | * on battery. |
| 2587 | * |
| 2588 | * {@hide} |
| 2589 | */ |
| 2590 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2591 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2592 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2593 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2594 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2595 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2596 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2597 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2598 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2599 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2600 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2601 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2602 | 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] | 2603 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2604 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2605 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2606 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2607 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2608 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2609 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2610 | * actual power data. |
| 2611 | */ |
| 2612 | public abstract boolean hasWifiActivityReporting(); |
| 2613 | |
| 2614 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2615 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2616 | * in various radio controller states, such as transmit, receive, and idle. |
| 2617 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2618 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2619 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2620 | |
| 2621 | /** |
| 2622 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2623 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2624 | * actual power data. |
| 2625 | */ |
| 2626 | public abstract boolean hasBluetoothActivityReporting(); |
| 2627 | |
| 2628 | /** |
| 2629 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2630 | * in various radio controller states, such as transmit, receive, and idle. |
| 2631 | * @return non-null {@link ControllerActivityCounter} |
| 2632 | */ |
| 2633 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2634 | |
| 2635 | /** |
| 2636 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2637 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2638 | * actual power data. |
| 2639 | */ |
| 2640 | public abstract boolean hasModemActivityReporting(); |
| 2641 | |
| 2642 | /** |
| 2643 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2644 | * in various radio controller states, such as transmit, receive, and idle. |
| 2645 | * @return non-null {@link ControllerActivityCounter} |
| 2646 | */ |
| 2647 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2648 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2649 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2650 | * Return the wall clock time when battery stats data collection started. |
| 2651 | */ |
| 2652 | public abstract long getStartClockTime(); |
| 2653 | |
| 2654 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2655 | * Return platform version tag that we were running in when the battery stats started. |
| 2656 | */ |
| 2657 | public abstract String getStartPlatformVersion(); |
| 2658 | |
| 2659 | /** |
| 2660 | * Return platform version tag that we were running in when the battery stats ended. |
| 2661 | */ |
| 2662 | public abstract String getEndPlatformVersion(); |
| 2663 | |
| 2664 | /** |
| 2665 | * Return the internal version code of the parcelled format. |
| 2666 | */ |
| 2667 | public abstract int getParcelVersion(); |
| 2668 | |
| 2669 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | * Return whether we are currently running on battery. |
| 2671 | */ |
| 2672 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | /** |
| 2675 | * Returns a SparseArray containing the statistics for each uid. |
| 2676 | */ |
| 2677 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2678 | |
| 2679 | /** |
| 2680 | * Returns the current battery uptime in microseconds. |
| 2681 | * |
| 2682 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2683 | */ |
| 2684 | public abstract long getBatteryUptime(long curTime); |
| 2685 | |
| 2686 | /** |
| 2687 | * Returns the current battery realtime in microseconds. |
| 2688 | * |
| 2689 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2690 | */ |
| 2691 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2692 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2693 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2694 | * 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] | 2695 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2696 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2697 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2698 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2699 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2700 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2701 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2702 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2703 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | |
| 2705 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2706 | * Get the amount the battery has discharged since the stats were |
| 2707 | * last reset after charging, as a lower-end approximation. |
| 2708 | */ |
| 2709 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2710 | |
| 2711 | /** |
| 2712 | * Get the amount the battery has discharged since the stats were |
| 2713 | * last reset after charging, as an upper-end approximation. |
| 2714 | */ |
| 2715 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2716 | |
| 2717 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2718 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2719 | */ |
| 2720 | public abstract int getDischargeAmount(int which); |
| 2721 | |
| 2722 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2723 | * Get the amount the battery has discharged while the screen was on, |
| 2724 | * since the last time power was unplugged. |
| 2725 | */ |
| 2726 | public abstract int getDischargeAmountScreenOn(); |
| 2727 | |
| 2728 | /** |
| 2729 | * Get the amount the battery has discharged while the screen was on, |
| 2730 | * since the last time the device was charged. |
| 2731 | */ |
| 2732 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2733 | |
| 2734 | /** |
| 2735 | * Get the amount the battery has discharged while the screen was off, |
| 2736 | * since the last time power was unplugged. |
| 2737 | */ |
| 2738 | public abstract int getDischargeAmountScreenOff(); |
| 2739 | |
| 2740 | /** |
| 2741 | * Get the amount the battery has discharged while the screen was off, |
| 2742 | * since the last time the device was charged. |
| 2743 | */ |
| 2744 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2745 | |
| 2746 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2747 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2748 | * since the last time power was unplugged. |
| 2749 | */ |
| 2750 | public abstract int getDischargeAmountScreenDoze(); |
| 2751 | |
| 2752 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2753 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2754 | * since the last time the device was charged. |
| 2755 | */ |
| 2756 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2757 | |
| 2758 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | * Returns the total, last, or current battery uptime in microseconds. |
| 2760 | * |
| 2761 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2762 | * @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] | 2763 | */ |
| 2764 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2765 | |
| 2766 | /** |
| 2767 | * Returns the total, last, or current battery realtime in microseconds. |
| 2768 | * |
| 2769 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2770 | * @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] | 2771 | */ |
| 2772 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2773 | |
| 2774 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2775 | * 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] | 2776 | * |
| 2777 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2778 | * @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] | 2779 | */ |
| 2780 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2781 | |
| 2782 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2783 | * 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] | 2784 | * |
| 2785 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2786 | * @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] | 2787 | */ |
| 2788 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2789 | |
| 2790 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | * Returns the total, last, or current uptime in microseconds. |
| 2792 | * |
| 2793 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2794 | * @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] | 2795 | */ |
| 2796 | public abstract long computeUptime(long curTime, int which); |
| 2797 | |
| 2798 | /** |
| 2799 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2800 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2802 | * @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] | 2803 | */ |
| 2804 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2805 | |
| 2806 | /** |
| 2807 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2808 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2809 | * enough current data to make a decision, or the battery is currently |
| 2810 | * charging. |
| 2811 | * |
| 2812 | * @param curTime The current elepsed realtime in microseconds. |
| 2813 | */ |
| 2814 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2815 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2816 | // The part of a step duration that is the actual time. |
| 2817 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2818 | |
| 2819 | // Bits in a step duration that are the new battery level we are at. |
| 2820 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2821 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2822 | |
| 2823 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2824 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2825 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2826 | |
| 2827 | // Bits in a step duration that indicate which modes changed during that step. |
| 2828 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2829 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2830 | |
| 2831 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2832 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2833 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2834 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2835 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2836 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2837 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2838 | // Step duration mode: power save is on. |
| 2839 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2840 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2841 | // Step duration mode: device is currently in idle mode. |
| 2842 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2843 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2844 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2845 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2846 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2847 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2848 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2849 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2850 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2851 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2852 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2853 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2854 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2855 | }; |
| 2856 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2857 | (Display.STATE_OFF-1), |
| 2858 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2859 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2860 | (Display.STATE_ON-1), |
| 2861 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2862 | (Display.STATE_DOZE-1), |
| 2863 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2864 | (Display.STATE_DOZE_SUSPEND-1), |
| 2865 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2866 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2867 | }; |
| 2868 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2869 | "screen off", |
| 2870 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2871 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2872 | "screen on", |
| 2873 | "screen on power save", |
| 2874 | "screen doze", |
| 2875 | "screen doze power save", |
| 2876 | "screen doze-suspend", |
| 2877 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2878 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2879 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2880 | |
| 2881 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2882 | * 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] | 2883 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2884 | * a coulomb counter. |
| 2885 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2886 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2887 | |
| 2888 | /** |
| 2889 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2890 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2891 | * a coulomb counter. |
| 2892 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2893 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2894 | |
| 2895 | /** |
| 2896 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2897 | * non-zero only if the device's battery has a coulomb counter. |
| 2898 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2899 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2900 | |
| 2901 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2902 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2903 | * micro-Ampere-hours. |
| 2904 | */ |
| 2905 | public abstract long getUahDischargeLightDoze(int which); |
| 2906 | |
| 2907 | /** |
| 2908 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2909 | * micro-Ampere-hours. |
| 2910 | */ |
| 2911 | public abstract long getUahDischargeDeepDoze(int which); |
| 2912 | |
| 2913 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2914 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2915 | * declared by the PowerProfile. |
| 2916 | * @return The estimated battery capacity in mAh. |
| 2917 | */ |
| 2918 | public abstract int getEstimatedBatteryCapacity(); |
| 2919 | |
| 2920 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2921 | * @return The minimum learned battery capacity in uAh. |
| 2922 | */ |
| 2923 | public abstract int getMinLearnedBatteryCapacity(); |
| 2924 | |
| 2925 | /** |
| 2926 | * @return The maximum learned battery capacity in uAh. |
| 2927 | */ |
| 2928 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2929 | |
| 2930 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2931 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2932 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2933 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2934 | |
| 2935 | /** |
| 2936 | * Return the array of daily discharge step durations. |
| 2937 | */ |
| 2938 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2939 | |
| 2940 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2941 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2942 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2943 | * enough current data to make a decision, or the battery is currently |
| 2944 | * discharging. |
| 2945 | * |
| 2946 | * @param curTime The current elepsed realtime in microseconds. |
| 2947 | */ |
| 2948 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2949 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2950 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2951 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2952 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2953 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2954 | |
| 2955 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2956 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2957 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2958 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2959 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2960 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2961 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2962 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2963 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2964 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2966 | /** |
| 2967 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2968 | */ |
| 2969 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2970 | /** |
| 2971 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2972 | */ |
| 2973 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2974 | |
| 2975 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2976 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2977 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2978 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2979 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2980 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | long days = seconds / (60 * 60 * 24); |
| 2982 | if (days != 0) { |
| 2983 | out.append(days); |
| 2984 | out.append("d "); |
| 2985 | } |
| 2986 | long used = days * 60 * 60 * 24; |
| 2987 | |
| 2988 | long hours = (seconds - used) / (60 * 60); |
| 2989 | if (hours != 0 || used != 0) { |
| 2990 | out.append(hours); |
| 2991 | out.append("h "); |
| 2992 | } |
| 2993 | used += hours * 60 * 60; |
| 2994 | |
| 2995 | long mins = (seconds-used) / 60; |
| 2996 | if (mins != 0 || used != 0) { |
| 2997 | out.append(mins); |
| 2998 | out.append("m "); |
| 2999 | } |
| 3000 | used += mins * 60; |
| 3001 | |
| 3002 | if (seconds != 0 || used != 0) { |
| 3003 | out.append(seconds-used); |
| 3004 | out.append("s "); |
| 3005 | } |
| 3006 | } |
| 3007 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3008 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3010 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | sb.append(time - (sec * 1000)); |
| 3012 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | } |
| 3014 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3015 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3016 | long sec = time / 1000; |
| 3017 | formatTimeRaw(sb, sec); |
| 3018 | sb.append(time - (sec * 1000)); |
| 3019 | sb.append("ms"); |
| 3020 | } |
| 3021 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3022 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3024 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | } |
| 3026 | float perc = ((float)num) / ((float)den) * 100; |
| 3027 | mFormatBuilder.setLength(0); |
| 3028 | mFormatter.format("%.1f%%", perc); |
| 3029 | return mFormatBuilder.toString(); |
| 3030 | } |
| 3031 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3032 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3033 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3034 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3035 | if (bytes < BYTES_PER_KB) { |
| 3036 | return bytes + "B"; |
| 3037 | } else if (bytes < BYTES_PER_MB) { |
| 3038 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 3039 | return mFormatBuilder.toString(); |
| 3040 | } else if (bytes < BYTES_PER_GB){ |
| 3041 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 3042 | return mFormatBuilder.toString(); |
| 3043 | } else { |
| 3044 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 3045 | return mFormatBuilder.toString(); |
| 3046 | } |
| 3047 | } |
| 3048 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3049 | private static long roundUsToMs(long timeUs) { |
| 3050 | return (timeUs + 500) / 1000; |
| 3051 | } |
| 3052 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3053 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3054 | if (timer != null) { |
| 3055 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3056 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3057 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 3058 | return totalTimeMillis; |
| 3059 | } |
| 3060 | return 0; |
| 3061 | } |
| 3062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | /** |
| 3064 | * |
| 3065 | * @param sb a StringBuilder object. |
| 3066 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3067 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3069 | * @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] | 3070 | * @param linePrefix a String to be prepended to each line of output. |
| 3071 | * @return the line prefix |
| 3072 | */ |
| 3073 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3074 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3076 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3077 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3078 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3079 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | if (totalTimeMillis != 0) { |
| 3081 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3082 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3083 | if (name != null) { |
| 3084 | sb.append(name); |
| 3085 | sb.append(' '); |
| 3086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | sb.append('('); |
| 3088 | sb.append(count); |
| 3089 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3090 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 3091 | if (maxDurationMs >= 0) { |
| 3092 | sb.append(" max="); |
| 3093 | sb.append(maxDurationMs); |
| 3094 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3095 | // Put actual time if it is available and different from totalTimeMillis. |
| 3096 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 3097 | if (totalDurMs > totalTimeMillis) { |
| 3098 | sb.append(" actual="); |
| 3099 | sb.append(totalDurMs); |
| 3100 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3101 | if (timer.isRunningLocked()) { |
| 3102 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3103 | if (currentMs >= 0) { |
| 3104 | sb.append(" (running for "); |
| 3105 | sb.append(currentMs); |
| 3106 | sb.append("ms)"); |
| 3107 | } else { |
| 3108 | sb.append(" (running)"); |
| 3109 | } |
| 3110 | } |
| 3111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | return ", "; |
| 3113 | } |
| 3114 | } |
| 3115 | return linePrefix; |
| 3116 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3117 | |
| 3118 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3119 | * 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] | 3120 | * |
| 3121 | * @param pw a PrintWriter object to print to. |
| 3122 | * @param sb a StringBuilder object. |
| 3123 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3124 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3125 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3126 | * @param prefix a String to be prepended to each line of output. |
| 3127 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3128 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3129 | */ |
| 3130 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3131 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3132 | if (timer != null) { |
| 3133 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3134 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3135 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3136 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3137 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3138 | sb.setLength(0); |
| 3139 | sb.append(prefix); |
| 3140 | sb.append(" "); |
| 3141 | sb.append(type); |
| 3142 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3143 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3144 | sb.append("realtime ("); |
| 3145 | sb.append(count); |
| 3146 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3147 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3148 | if (maxDurationMs >= 0) { |
| 3149 | sb.append(" max="); |
| 3150 | sb.append(maxDurationMs); |
| 3151 | } |
| 3152 | if (timer.isRunningLocked()) { |
| 3153 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3154 | if (currentMs >= 0) { |
| 3155 | sb.append(" (running for "); |
| 3156 | sb.append(currentMs); |
| 3157 | sb.append("ms)"); |
| 3158 | } else { |
| 3159 | sb.append(" (running)"); |
| 3160 | } |
| 3161 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3162 | pw.println(sb.toString()); |
| 3163 | return true; |
| 3164 | } |
| 3165 | } |
| 3166 | return false; |
| 3167 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | /** |
| 3170 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3171 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | * @param sb a StringBuilder object. |
| 3173 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3174 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3176 | * @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] | 3177 | * @param linePrefix a String to be prepended to each line of output. |
| 3178 | * @return the line prefix |
| 3179 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3180 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3181 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | long totalTimeMicros = 0; |
| 3183 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3184 | long max = 0; |
| 3185 | long current = 0; |
| 3186 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3188 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3189 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3190 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3191 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3192 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
| 3194 | sb.append(linePrefix); |
| 3195 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3196 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3197 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3199 | sb.append(','); |
| 3200 | sb.append(current); |
| 3201 | sb.append(','); |
| 3202 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3203 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3204 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3205 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3206 | if (name != null) { |
| 3207 | sb.append(','); |
| 3208 | sb.append(totalDuration); |
| 3209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | return ","; |
| 3211 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3212 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3213 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3214 | String type) { |
| 3215 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3216 | pw.print(','); |
| 3217 | pw.print(uid); |
| 3218 | pw.print(','); |
| 3219 | pw.print(category); |
| 3220 | pw.print(','); |
| 3221 | pw.print(type); |
| 3222 | } |
| 3223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | /** |
| 3225 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3226 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | * @param pw the PageWriter to dump log to |
| 3228 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3229 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3230 | * @param args type-dependent data arguments |
| 3231 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3232 | 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] | 3233 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3234 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3235 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3236 | pw.print(','); |
| 3237 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3239 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3241 | |
| 3242 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3243 | * Dump a given timer stat for terse checkin mode. |
| 3244 | * |
| 3245 | * @param pw the PageWriter to dump log to |
| 3246 | * @param uid the UID to log |
| 3247 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3248 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3249 | * @param timer a {@link Timer} to dump stats for |
| 3250 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3251 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3252 | */ |
| 3253 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3254 | Timer timer, long rawRealtime, int which) { |
| 3255 | if (timer != null) { |
| 3256 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3257 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3258 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3259 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3260 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3261 | } |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3266 | * Dump a given timer stat to the proto stream. |
| 3267 | * |
| 3268 | * @param proto the ProtoOutputStream to log to |
| 3269 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3270 | * @param timer a {@link Timer} to dump stats for |
| 3271 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3272 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3273 | */ |
| 3274 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3275 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3276 | if (timer == null) { |
| 3277 | return; |
| 3278 | } |
| 3279 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3280 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3281 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3282 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3283 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3284 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3285 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3286 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3287 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3288 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3289 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3290 | // These values will be -1 for timers that don't implement the functionality. |
| 3291 | if (maxDurationMs != -1) { |
| 3292 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3293 | } |
| 3294 | if (curDurationMs != -1) { |
| 3295 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3296 | } |
| 3297 | if (totalDurationMs != -1) { |
| 3298 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3299 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3300 | proto.end(token); |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3305 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3306 | */ |
| 3307 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3308 | if (counter == null) { |
| 3309 | return false; |
| 3310 | } |
| 3311 | |
| 3312 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3313 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3314 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3315 | return true; |
| 3316 | } |
| 3317 | |
| 3318 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3319 | if (c.getCountLocked(which) != 0) { |
| 3320 | return true; |
| 3321 | } |
| 3322 | } |
| 3323 | return false; |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3328 | * The order of the arguments in the final check in line is: |
| 3329 | * |
| 3330 | * idle, rx, power, tx... |
| 3331 | * |
| 3332 | * where tx... is one or more transmit level times. |
| 3333 | */ |
| 3334 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3335 | String type, |
| 3336 | ControllerActivityCounter counter, |
| 3337 | int which) { |
| 3338 | if (!controllerActivityHasData(counter, which)) { |
| 3339 | return; |
| 3340 | } |
| 3341 | |
| 3342 | dumpLineHeader(pw, uid, category, type); |
| 3343 | pw.print(","); |
| 3344 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3345 | pw.print(","); |
| 3346 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3347 | pw.print(","); |
| 3348 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3349 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3350 | pw.print(","); |
| 3351 | pw.print(c.getCountLocked(which)); |
| 3352 | } |
| 3353 | pw.println(); |
| 3354 | } |
| 3355 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3356 | /** |
| 3357 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3358 | */ |
| 3359 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3360 | ControllerActivityCounter counter, |
| 3361 | int which) { |
| 3362 | if (!controllerActivityHasData(counter, which)) { |
| 3363 | return; |
| 3364 | } |
| 3365 | |
| 3366 | final long cToken = proto.start(fieldId); |
| 3367 | |
| 3368 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3369 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3370 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3371 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3372 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3373 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3374 | |
| 3375 | long tToken; |
| 3376 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3377 | for (int i = 0; i < txCounters.length; ++i) { |
| 3378 | LongCounter c = txCounters[i]; |
| 3379 | tToken = proto.start(ControllerActivityProto.TX); |
| 3380 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3381 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3382 | proto.end(tToken); |
| 3383 | } |
| 3384 | |
| 3385 | proto.end(cToken); |
| 3386 | } |
| 3387 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3388 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3389 | String prefix, String controllerName, |
| 3390 | ControllerActivityCounter counter, |
| 3391 | int which) { |
| 3392 | if (controllerActivityHasData(counter, which)) { |
| 3393 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3398 | String controllerName, |
| 3399 | ControllerActivityCounter counter, int which) { |
| 3400 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3401 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3402 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3403 | // Battery real time |
| 3404 | final long totalControllerActivityTimeMs |
| 3405 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3406 | long totalTxTimeMs = 0; |
| 3407 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3408 | totalTxTimeMs += txState.getCountLocked(which); |
| 3409 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3410 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3411 | if (controllerName.equals(WIFI_CONTROLLER_NAME)) { |
| 3412 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 3413 | sb.setLength(0); |
| 3414 | sb.append(prefix); |
| 3415 | sb.append(" "); |
| 3416 | sb.append(controllerName); |
| 3417 | sb.append(" Scan time: "); |
| 3418 | formatTimeMs(sb, scanTimeMs); |
| 3419 | sb.append("("); |
| 3420 | sb.append(formatRatioLocked(scanTimeMs, totalControllerActivityTimeMs)); |
| 3421 | sb.append(")"); |
| 3422 | pw.println(sb.toString()); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3423 | |
| 3424 | final long sleepTimeMs |
| 3425 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
| 3426 | sb.setLength(0); |
| 3427 | sb.append(prefix); |
| 3428 | sb.append(" "); |
| 3429 | sb.append(controllerName); |
| 3430 | sb.append(" Sleep time: "); |
| 3431 | formatTimeMs(sb, sleepTimeMs); |
| 3432 | sb.append("("); |
| 3433 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3434 | sb.append(")"); |
| 3435 | pw.println(sb.toString()); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3436 | } |
| 3437 | |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3438 | if (controllerName.equals(CELLULAR_CONTROLLER_NAME)) { |
| 3439 | final long sleepTimeMs = counter.getSleepTimeCounter().getCountLocked(which); |
| 3440 | sb.setLength(0); |
| 3441 | sb.append(prefix); |
| 3442 | sb.append(" "); |
| 3443 | sb.append(controllerName); |
| 3444 | sb.append(" Sleep time: "); |
| 3445 | formatTimeMs(sb, sleepTimeMs); |
| 3446 | sb.append("("); |
| 3447 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3448 | sb.append(")"); |
| 3449 | pw.println(sb.toString()); |
| 3450 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3451 | |
| 3452 | sb.setLength(0); |
| 3453 | sb.append(prefix); |
| 3454 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3455 | sb.append(controllerName); |
| 3456 | sb.append(" Idle time: "); |
| 3457 | formatTimeMs(sb, idleTimeMs); |
| 3458 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3459 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3460 | sb.append(")"); |
| 3461 | pw.println(sb.toString()); |
| 3462 | |
| 3463 | sb.setLength(0); |
| 3464 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3465 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3466 | sb.append(controllerName); |
| 3467 | sb.append(" Rx time: "); |
| 3468 | formatTimeMs(sb, rxTimeMs); |
| 3469 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3470 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3471 | sb.append(")"); |
| 3472 | pw.println(sb.toString()); |
| 3473 | |
| 3474 | sb.setLength(0); |
| 3475 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3476 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3477 | sb.append(controllerName); |
| 3478 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3479 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3480 | String [] powerLevel; |
| 3481 | switch(controllerName) { |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3482 | case CELLULAR_CONTROLLER_NAME: |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3483 | powerLevel = new String[] { |
| 3484 | " less than 0dBm: ", |
| 3485 | " 0dBm to 8dBm: ", |
| 3486 | " 8dBm to 15dBm: ", |
| 3487 | " 15dBm to 20dBm: ", |
| 3488 | " above 20dBm: "}; |
| 3489 | break; |
| 3490 | default: |
| 3491 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3492 | break; |
| 3493 | } |
| 3494 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3495 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3496 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3497 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3498 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3499 | sb.setLength(0); |
| 3500 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3501 | sb.append(" "); |
| 3502 | sb.append(powerLevel[lvl]); |
| 3503 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3504 | formatTimeMs(sb, txLvlTimeMs); |
| 3505 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3506 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3507 | sb.append(")"); |
| 3508 | pw.println(sb.toString()); |
| 3509 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3510 | } else { |
| 3511 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3512 | formatTimeMs(sb, txLvlTimeMs); |
| 3513 | sb.append("("); |
| 3514 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3515 | sb.append(")"); |
| 3516 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3517 | } |
| 3518 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3519 | if (powerDrainMaMs > 0) { |
| 3520 | sb.setLength(0); |
| 3521 | sb.append(prefix); |
| 3522 | sb.append(" "); |
| 3523 | sb.append(controllerName); |
| 3524 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3525 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3526 | sb.append("mAh"); |
| 3527 | pw.println(sb.toString()); |
| 3528 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3532 | * Temporary for settings. |
| 3533 | */ |
| 3534 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3535 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3536 | } |
| 3537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | /** |
| 3539 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3540 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3541 | * NOTE: all times are expressed in microseconds, unless specified otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3543 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3544 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3546 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3547 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3550 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3551 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3552 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3553 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3555 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3556 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3557 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3558 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3559 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3560 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3561 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3562 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3563 | rawRealtime, which); |
| 3564 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3565 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3566 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3567 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3568 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3569 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3570 | final long dischargeCount = getUahDischarge(which); |
| 3571 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3572 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3573 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3574 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3575 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3576 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3577 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3578 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3579 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3580 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3581 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3584 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3585 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3586 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3587 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3588 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3589 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3590 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3591 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3592 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3593 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3594 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3595 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3596 | long fullWakeLockTimeTotal = 0; |
| 3597 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3598 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3599 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3600 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3601 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3602 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3603 | = u.getWakelockStats(); |
| 3604 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3605 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3606 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3607 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3608 | if (fullWakeTimer != null) { |
| 3609 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3610 | which); |
| 3611 | } |
| 3612 | |
| 3613 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3614 | if (partialWakeTimer != null) { |
| 3615 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3616 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3620 | |
| 3621 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3622 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3623 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3624 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3625 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3626 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3627 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3628 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3629 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3630 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3631 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3632 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3633 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3634 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3635 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3636 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3637 | // Dump Modem controller stats |
| 3638 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3639 | getModemControllerActivity(), which); |
| 3640 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3641 | // Dump Wifi controller stats |
| 3642 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3643 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3644 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3645 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3646 | |
| 3647 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3648 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3649 | |
| 3650 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3651 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3652 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | // Dump misc stats |
| 3655 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3656 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3657 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3658 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3659 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3660 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3661 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3662 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3663 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3664 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3665 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3666 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3667 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3668 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3669 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3670 | // Dump screen brightness stats |
| 3671 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3672 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3673 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3674 | } |
| 3675 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3676 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3677 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3678 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3679 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3680 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3681 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3682 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3683 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3684 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3685 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3686 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3687 | } |
| 3688 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3689 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3690 | // Dump network type stats |
| 3691 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3692 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3693 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3694 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3695 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3696 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3697 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3698 | } |
| 3699 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3700 | |
| 3701 | // Dump wifi state stats |
| 3702 | args = new Object[NUM_WIFI_STATES]; |
| 3703 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3704 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3705 | } |
| 3706 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3707 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3708 | args[i] = getWifiStateCount(i, which); |
| 3709 | } |
| 3710 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3711 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3712 | // Dump wifi suppl state stats |
| 3713 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3714 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3715 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3716 | } |
| 3717 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3718 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3719 | args[i] = getWifiSupplStateCount(i, which); |
| 3720 | } |
| 3721 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3722 | |
| 3723 | // Dump wifi signal strength stats |
| 3724 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3725 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3726 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3727 | } |
| 3728 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3729 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3730 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3731 | } |
| 3732 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3733 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3734 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3735 | final long multicastWakeLockTimeTotalMicros = |
| 3736 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3737 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3738 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3739 | multicastWakeLockTimeTotalMicros / 1000, |
| 3740 | multicastWakeLockCountTotal); |
| 3741 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3742 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3743 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3744 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3745 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3746 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3747 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3748 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3749 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3750 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3751 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3752 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3753 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3754 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3755 | } else { |
| 3756 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3757 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3758 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3759 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3760 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3761 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3762 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3763 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3764 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3765 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3766 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3767 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3768 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3769 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3770 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3771 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3772 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3773 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3774 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3775 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3776 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3777 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3778 | // Not doing the regular wake lock formatting to remain compatible |
| 3779 | // with the old checkin format. |
| 3780 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3781 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3782 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3783 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3784 | } |
| 3785 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3786 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3787 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3788 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3789 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3790 | if (rpmStats.size() > 0) { |
| 3791 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3792 | sb.setLength(0); |
| 3793 | Timer totalTimer = ent.getValue(); |
| 3794 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3795 | int count = totalTimer.getCountLocked(which); |
| 3796 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3797 | long screenOffTimeMs = screenOffTimer != null |
| 3798 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3799 | int screenOffCount = screenOffTimer != null |
| 3800 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3801 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3802 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3803 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3804 | screenOffCount); |
| 3805 | } else { |
| 3806 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3807 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3808 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3812 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3813 | helper.create(this); |
| 3814 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3815 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3816 | if (sippers != null && sippers.size() > 0) { |
| 3817 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3818 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3819 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3820 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3821 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3822 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3823 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3824 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3825 | String label; |
| 3826 | switch (bs.drainType) { |
Kweku Adams | ef72895 | 2018-04-10 17:56:16 -0700 | [diff] [blame] | 3827 | case AMBIENT_DISPLAY: |
| 3828 | label = "ambi"; |
| 3829 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3830 | case IDLE: |
| 3831 | label="idle"; |
| 3832 | break; |
| 3833 | case CELL: |
| 3834 | label="cell"; |
| 3835 | break; |
| 3836 | case PHONE: |
| 3837 | label="phone"; |
| 3838 | break; |
| 3839 | case WIFI: |
| 3840 | label="wifi"; |
| 3841 | break; |
| 3842 | case BLUETOOTH: |
| 3843 | label="blue"; |
| 3844 | break; |
| 3845 | case SCREEN: |
| 3846 | label="scrn"; |
| 3847 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3848 | case FLASHLIGHT: |
| 3849 | label="flashlight"; |
| 3850 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3851 | case APP: |
| 3852 | uid = bs.uidObj.getUid(); |
| 3853 | label = "uid"; |
| 3854 | break; |
| 3855 | case USER: |
| 3856 | uid = UserHandle.getUid(bs.userId, 0); |
| 3857 | label = "user"; |
| 3858 | break; |
| 3859 | case UNACCOUNTED: |
| 3860 | label = "unacc"; |
| 3861 | break; |
| 3862 | case OVERCOUNTED: |
| 3863 | label = "over"; |
| 3864 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3865 | case CAMERA: |
| 3866 | label = "camera"; |
| 3867 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3868 | case MEMORY: |
| 3869 | label = "memory"; |
| 3870 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3871 | default: |
| 3872 | label = "???"; |
| 3873 | } |
| 3874 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3875 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3876 | bs.shouldHide ? 1 : 0, |
| 3877 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3878 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3879 | } |
| 3880 | } |
| 3881 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3882 | final long[] cpuFreqs = getCpuFreqs(); |
| 3883 | if (cpuFreqs != null) { |
| 3884 | sb.setLength(0); |
| 3885 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3886 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3887 | } |
| 3888 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3889 | } |
| 3890 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3891 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | for (int iu = 0; iu < NU; iu++) { |
| 3893 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3894 | if (reqUid >= 0 && uid != reqUid) { |
| 3895 | continue; |
| 3896 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3897 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3900 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3901 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3902 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3903 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3904 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3905 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3906 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3907 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3908 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3909 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3910 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3911 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3912 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3913 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3914 | // Background data transfers |
| 3915 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3916 | which); |
| 3917 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3918 | which); |
| 3919 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3920 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3921 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3922 | which); |
| 3923 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3924 | which); |
| 3925 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3926 | which); |
| 3927 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3928 | which); |
| 3929 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3930 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3931 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3932 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3933 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3934 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3935 | || wifiBytesBgTx > 0 |
| 3936 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3937 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3938 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3939 | wifiBytesRx, wifiBytesTx, |
| 3940 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3941 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3942 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3943 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3944 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3945 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3946 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3949 | // Dump modem controller data, per UID. |
| 3950 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3951 | u.getModemControllerActivity(), which); |
| 3952 | |
| 3953 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3954 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3955 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3956 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3957 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3958 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3959 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3960 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3961 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3962 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3963 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3964 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3965 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3966 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3967 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3968 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3969 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3972 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3973 | u.getWifiControllerActivity(), which); |
| 3974 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3975 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3976 | if (bleTimer != null) { |
| 3977 | // Convert from microseconds to milliseconds with rounding |
| 3978 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3979 | / 1000; |
| 3980 | if (totalTime != 0) { |
| 3981 | final int count = bleTimer.getCountLocked(which); |
| 3982 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3983 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3984 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3985 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3986 | final long actualTimeBg = bleTimerBg != null ? |
| 3987 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3988 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3989 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3990 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3991 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3992 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3993 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3994 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3995 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3996 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3997 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3998 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3999 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 4000 | final Timer unoptimizedScanTimerBg = |
| 4001 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 4002 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 4003 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4004 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 4005 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 4006 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4007 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4008 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 4009 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 4010 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4011 | } |
| 4012 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4013 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4014 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 4015 | u.getBluetoothControllerActivity(), which); |
| 4016 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4017 | if (u.hasUserActivity()) { |
| 4018 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 4019 | boolean hasData = false; |
| 4020 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 4021 | int val = u.getUserActivityCount(i, which); |
| 4022 | args[i] = val; |
| 4023 | if (val != 0) hasData = true; |
| 4024 | } |
| 4025 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 4026 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4027 | } |
| 4028 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4029 | |
| 4030 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 4031 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4032 | // Times are since reset (regardless of 'which') |
| 4033 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4034 | final Timer bgTimer = timer.getSubTimer(); |
| 4035 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4036 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4037 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 4038 | } |
| 4039 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4040 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 4041 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4042 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4043 | String linePrefix = ""; |
| 4044 | sb.setLength(0); |
| 4045 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 4046 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4047 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4048 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4049 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4050 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 4051 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4052 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4053 | rawRealtime, "w", which, linePrefix); |
| 4054 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 4055 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4056 | if (sb.length() > 0) { |
| 4057 | String name = wakelocks.keyAt(iw); |
| 4058 | if (name.indexOf(',') >= 0) { |
| 4059 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4060 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 4061 | if (name.indexOf('\n') >= 0) { |
| 4062 | name = name.replace('\n', '_'); |
| 4063 | } |
| 4064 | if (name.indexOf('\r') >= 0) { |
| 4065 | name = name.replace('\r', '_'); |
| 4066 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4067 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | } |
| 4069 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4070 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4071 | // WiFi Multicast Wakelock Statistics |
| 4072 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 4073 | if (mcTimer != null) { |
| 4074 | final long totalMcWakelockTimeMs = |
| 4075 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 4076 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 4077 | if(totalMcWakelockTimeMs > 0) { |
| 4078 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 4079 | totalMcWakelockTimeMs, countMcWakelock); |
| 4080 | } |
| 4081 | } |
| 4082 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4083 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4084 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4085 | final Timer timer = syncs.valueAt(isy); |
| 4086 | // Convert from microseconds to milliseconds with rounding |
| 4087 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4088 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4089 | final Timer bgTimer = timer.getSubTimer(); |
| 4090 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4091 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4092 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4093 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4094 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4095 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4096 | } |
| 4097 | } |
| 4098 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4099 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4100 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4101 | final Timer timer = jobs.valueAt(ij); |
| 4102 | // Convert from microseconds to milliseconds with rounding |
| 4103 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4104 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4105 | final Timer bgTimer = timer.getSubTimer(); |
| 4106 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4107 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4108 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4109 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4110 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4111 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 4114 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4115 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 4116 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 4117 | SparseIntArray types = completions.valueAt(ic); |
| 4118 | if (types != null) { |
| 4119 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 4120 | "\"" + completions.keyAt(ic) + "\"", |
| 4121 | types.get(JobParameters.REASON_CANCELED, 0), |
| 4122 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 4123 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 4124 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 4125 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 4126 | } |
| 4127 | } |
| 4128 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 4129 | // Dump deferred jobs stats |
| 4130 | u.getDeferredJobsCheckinLineLocked(sb, which); |
| 4131 | if (sb.length() > 0) { |
| 4132 | dumpLine(pw, uid, category, JOBS_DEFERRED_DATA, sb.toString()); |
| 4133 | } |
| 4134 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4135 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 4136 | rawRealtime, which); |
| 4137 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4138 | rawRealtime, which); |
| 4139 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4140 | rawRealtime, which); |
| 4141 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4142 | rawRealtime, which); |
| 4143 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4144 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4145 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4146 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4147 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4148 | final int sensorNumber = sensors.keyAt(ise); |
| 4149 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4150 | if (timer != null) { |
| 4151 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4152 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4153 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4154 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4155 | final int count = timer.getCountLocked(which); |
| 4156 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4157 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4158 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4159 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4160 | final long bgActualTime = bgTimer != null ? |
| 4161 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4162 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4163 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4168 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4169 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4170 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4171 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4172 | rawRealtime, which); |
| 4173 | |
| 4174 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4175 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4176 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4177 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4178 | long totalStateTime = 0; |
| 4179 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4180 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4181 | totalStateTime += time; |
| 4182 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4183 | } |
| 4184 | if (totalStateTime > 0) { |
| 4185 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4186 | } |
| 4187 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4188 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4189 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4190 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4191 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4192 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4195 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4196 | if (cpuFreqs != null) { |
| 4197 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4198 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4199 | // screenOffCpuFreqTimes. |
| 4200 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4201 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4202 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4203 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4204 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4205 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4206 | if (screenOffCpuFreqTimeMs != null) { |
| 4207 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4208 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4209 | } |
| 4210 | } else { |
| 4211 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4212 | sb.append(",0"); |
| 4213 | } |
| 4214 | } |
| 4215 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4216 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4217 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4218 | |
| 4219 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4220 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4221 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4222 | sb.setLength(0); |
| 4223 | for (int i = 0; i < timesMs.length; ++i) { |
| 4224 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4225 | } |
| 4226 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4227 | which, procState); |
| 4228 | if (screenOffTimesMs != null) { |
| 4229 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4230 | sb.append("," + screenOffTimesMs[i]); |
| 4231 | } |
| 4232 | } else { |
| 4233 | for (int i = 0; i < timesMs.length; ++i) { |
| 4234 | sb.append(",0"); |
| 4235 | } |
| 4236 | } |
| 4237 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4238 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4239 | } |
| 4240 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4243 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4244 | = u.getProcessStats(); |
| 4245 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4246 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4247 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4248 | final long userMillis = ps.getUserTime(which); |
| 4249 | final long systemMillis = ps.getSystemTime(which); |
| 4250 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4251 | final int starts = ps.getStarts(which); |
| 4252 | final int numCrashes = ps.getNumCrashes(which); |
| 4253 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4254 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4255 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4256 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4257 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4258 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4262 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4263 | = u.getPackageStats(); |
| 4264 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4265 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4266 | int wakeups = 0; |
| 4267 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4268 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4269 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4270 | wakeups += count; |
| 4271 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4272 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4273 | } |
| 4274 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4275 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4276 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4277 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4278 | final int starts = ss.getStarts(which); |
| 4279 | final int launches = ss.getLaunches(which); |
| 4280 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4281 | dumpLine(pw, uid, category, APK_DATA, |
| 4282 | wakeups, // wakeup alarms |
| 4283 | packageStats.keyAt(ipkg), // Apk |
| 4284 | serviceStats.keyAt(isvc), // service |
| 4285 | startTime / 1000, // time spent started, in ms |
| 4286 | starts, |
| 4287 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | } |
| 4289 | } |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4294 | static final class TimerEntry { |
| 4295 | final String mName; |
| 4296 | final int mId; |
| 4297 | final BatteryStats.Timer mTimer; |
| 4298 | final long mTime; |
| 4299 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4300 | mName = name; |
| 4301 | mId = id; |
| 4302 | mTimer = timer; |
| 4303 | mTime = time; |
| 4304 | } |
| 4305 | } |
| 4306 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4307 | private void printmAh(PrintWriter printer, double power) { |
| 4308 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4309 | } |
| 4310 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4311 | private void printmAh(StringBuilder sb, double power) { |
| 4312 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4313 | } |
| 4314 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4315 | /** |
| 4316 | * Temporary for settings. |
| 4317 | */ |
| 4318 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4319 | int reqUid) { |
| 4320 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4321 | } |
| 4322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4324 | 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] | 4325 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4327 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4328 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | |
| 4331 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4332 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4333 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4334 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4335 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4336 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4337 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4338 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4339 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4340 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4341 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4342 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4343 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4344 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4345 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4347 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4348 | if (estimatedBatteryCapacity > 0) { |
| 4349 | sb.setLength(0); |
| 4350 | sb.append(prefix); |
| 4351 | sb.append(" Estimated battery capacity: "); |
| 4352 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4353 | sb.append(" mAh"); |
| 4354 | pw.println(sb.toString()); |
| 4355 | } |
| 4356 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4357 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4358 | if (minLearnedBatteryCapacity > 0) { |
| 4359 | sb.setLength(0); |
| 4360 | sb.append(prefix); |
| 4361 | sb.append(" Min learned battery capacity: "); |
| 4362 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4363 | sb.append(" mAh"); |
| 4364 | pw.println(sb.toString()); |
| 4365 | } |
| 4366 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4367 | if (maxLearnedBatteryCapacity > 0) { |
| 4368 | sb.setLength(0); |
| 4369 | sb.append(prefix); |
| 4370 | sb.append(" Max learned battery capacity: "); |
| 4371 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4372 | sb.append(" mAh"); |
| 4373 | pw.println(sb.toString()); |
| 4374 | } |
| 4375 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4376 | sb.setLength(0); |
| 4377 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4378 | sb.append(" Time on battery: "); |
| 4379 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4380 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4381 | sb.append(") realtime, "); |
| 4382 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4383 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4384 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4385 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4386 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4387 | sb.setLength(0); |
| 4388 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4389 | sb.append(" Time on battery screen off: "); |
| 4390 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4391 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4392 | sb.append(") realtime, "); |
| 4393 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4394 | sb.append("("); |
| 4395 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4396 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4397 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4398 | |
| 4399 | sb.setLength(0); |
| 4400 | sb.append(prefix); |
| 4401 | sb.append(" Time on battery screen doze: "); |
| 4402 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4403 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4404 | sb.append(")"); |
| 4405 | pw.println(sb.toString()); |
| 4406 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4407 | sb.setLength(0); |
| 4408 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4409 | sb.append(" Total run time: "); |
| 4410 | formatTimeMs(sb, totalRealtime / 1000); |
| 4411 | sb.append("realtime, "); |
| 4412 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4413 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4414 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4415 | if (batteryTimeRemaining >= 0) { |
| 4416 | sb.setLength(0); |
| 4417 | sb.append(prefix); |
| 4418 | sb.append(" Battery time remaining: "); |
| 4419 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4420 | pw.println(sb.toString()); |
| 4421 | } |
| 4422 | if (chargeTimeRemaining >= 0) { |
| 4423 | sb.setLength(0); |
| 4424 | sb.append(prefix); |
| 4425 | sb.append(" Charge time remaining: "); |
| 4426 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4427 | pw.println(sb.toString()); |
| 4428 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4429 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4430 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4431 | if (dischargeCount >= 0) { |
| 4432 | sb.setLength(0); |
| 4433 | sb.append(prefix); |
| 4434 | sb.append(" Discharge: "); |
| 4435 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4436 | sb.append(" mAh"); |
| 4437 | pw.println(sb.toString()); |
| 4438 | } |
| 4439 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4440 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4441 | if (dischargeScreenOffCount >= 0) { |
| 4442 | sb.setLength(0); |
| 4443 | sb.append(prefix); |
| 4444 | sb.append(" Screen off discharge: "); |
| 4445 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4446 | sb.append(" mAh"); |
| 4447 | pw.println(sb.toString()); |
| 4448 | } |
| 4449 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4450 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4451 | if (dischargeScreenDozeCount >= 0) { |
| 4452 | sb.setLength(0); |
| 4453 | sb.append(prefix); |
| 4454 | sb.append(" Screen doze discharge: "); |
| 4455 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4456 | sb.append(" mAh"); |
| 4457 | pw.println(sb.toString()); |
| 4458 | } |
| 4459 | |
Mike Ma | 9090265 | 2018-04-17 14:07:24 -0700 | [diff] [blame] | 4460 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4461 | if (dischargeScreenOnCount >= 0) { |
| 4462 | sb.setLength(0); |
| 4463 | sb.append(prefix); |
| 4464 | sb.append(" Screen on discharge: "); |
| 4465 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4466 | sb.append(" mAh"); |
| 4467 | pw.println(sb.toString()); |
| 4468 | } |
| 4469 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4470 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4471 | if (dischargeLightDozeCount >= 0) { |
| 4472 | sb.setLength(0); |
| 4473 | sb.append(prefix); |
| 4474 | sb.append(" Device light doze discharge: "); |
| 4475 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4476 | sb.append(" mAh"); |
| 4477 | pw.println(sb.toString()); |
| 4478 | } |
| 4479 | |
| 4480 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4481 | if (dischargeDeepDozeCount >= 0) { |
| 4482 | sb.setLength(0); |
| 4483 | sb.append(prefix); |
| 4484 | sb.append(" Device deep doze discharge: "); |
| 4485 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4486 | sb.append(" mAh"); |
| 4487 | pw.println(sb.toString()); |
| 4488 | } |
| 4489 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4490 | pw.print(" Start clock time: "); |
| 4491 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4492 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4493 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4494 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4495 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4496 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4497 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4498 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4499 | rawRealtime, which); |
| 4500 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4501 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4502 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4503 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4504 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4505 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4506 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4507 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4508 | sb.append(prefix); |
| 4509 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4510 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4511 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4512 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4513 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4514 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4515 | pw.println(sb.toString()); |
| 4516 | sb.setLength(0); |
| 4517 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4518 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4519 | boolean didOne = false; |
| 4520 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4521 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4522 | if (time == 0) { |
| 4523 | continue; |
| 4524 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4525 | sb.append("\n "); |
| 4526 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4527 | didOne = true; |
| 4528 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4529 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4530 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4531 | sb.append("("); |
| 4532 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4533 | sb.append(")"); |
| 4534 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4535 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4536 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4537 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4538 | sb.setLength(0); |
| 4539 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4540 | sb.append(" Power save mode enabled: "); |
| 4541 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4542 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4543 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4544 | sb.append(")"); |
| 4545 | pw.println(sb.toString()); |
| 4546 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4547 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4548 | sb.setLength(0); |
| 4549 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4550 | sb.append(" Device light idling: "); |
| 4551 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4552 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4553 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4554 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4555 | sb.append("x"); |
| 4556 | pw.println(sb.toString()); |
| 4557 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4558 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4559 | sb.setLength(0); |
| 4560 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4561 | sb.append(" Idle mode light time: "); |
| 4562 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4563 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4564 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4565 | sb.append(") "); |
| 4566 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4567 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4568 | sb.append(" -- longest "); |
| 4569 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4570 | pw.println(sb.toString()); |
| 4571 | } |
| 4572 | if (deviceIdlingTime != 0) { |
| 4573 | sb.setLength(0); |
| 4574 | sb.append(prefix); |
| 4575 | sb.append(" Device full idling: "); |
| 4576 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4577 | sb.append("("); |
| 4578 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4579 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4580 | sb.append("x"); |
| 4581 | pw.println(sb.toString()); |
| 4582 | } |
| 4583 | if (deviceIdleModeFullTime != 0) { |
| 4584 | sb.setLength(0); |
| 4585 | sb.append(prefix); |
| 4586 | sb.append(" Idle mode full time: "); |
| 4587 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4588 | sb.append("("); |
| 4589 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4590 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4591 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4592 | sb.append("x"); |
| 4593 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4594 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4595 | pw.println(sb.toString()); |
| 4596 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4597 | if (phoneOnTime != 0) { |
| 4598 | sb.setLength(0); |
| 4599 | sb.append(prefix); |
| 4600 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4601 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4602 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4603 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4604 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4605 | if (connChanges != 0) { |
| 4606 | pw.print(prefix); |
| 4607 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4608 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4609 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4610 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4611 | long fullWakeLockTimeTotalMicros = 0; |
| 4612 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4613 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4614 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4615 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4616 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4617 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4618 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4619 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4620 | = u.getWakelockStats(); |
| 4621 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4622 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4623 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4624 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4625 | if (fullWakeTimer != null) { |
| 4626 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4627 | rawRealtime, which); |
| 4628 | } |
| 4629 | |
| 4630 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4631 | if (partialWakeTimer != null) { |
| 4632 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4633 | rawRealtime, which); |
| 4634 | if (totalTimeMicros > 0) { |
| 4635 | if (reqUid < 0) { |
| 4636 | // Only show the ordered list of all wake |
| 4637 | // locks if the caller is not asking for data |
| 4638 | // about a specific uid. |
| 4639 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4640 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4641 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4642 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | } |
| 4646 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4647 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4648 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4649 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4650 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4651 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4652 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4653 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4654 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4655 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4656 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4657 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4658 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4659 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4660 | sb.setLength(0); |
| 4661 | sb.append(prefix); |
| 4662 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4663 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4664 | pw.println(sb.toString()); |
| 4665 | } |
| 4666 | |
| 4667 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4668 | sb.setLength(0); |
| 4669 | sb.append(prefix); |
| 4670 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4671 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4672 | pw.println(sb.toString()); |
| 4673 | } |
| 4674 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4675 | final long multicastWakeLockTimeTotalMicros = |
| 4676 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4677 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4678 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4679 | sb.setLength(0); |
| 4680 | sb.append(prefix); |
| 4681 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4682 | sb.append(multicastWakeLockCountTotal); |
| 4683 | pw.println(sb.toString()); |
| 4684 | |
| 4685 | sb.setLength(0); |
| 4686 | sb.append(prefix); |
| 4687 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4688 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4689 | pw.println(sb.toString()); |
| 4690 | } |
| 4691 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4692 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4693 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4694 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4695 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4696 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4697 | pw.println(sb.toString()); |
| 4698 | |
| 4699 | pw.print(prefix); |
| 4700 | sb.setLength(0); |
| 4701 | sb.append(prefix); |
| 4702 | sb.append(" Logging duration for connectivity statistics: "); |
| 4703 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4704 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4705 | |
| 4706 | sb.setLength(0); |
| 4707 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4708 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4709 | pw.println(sb.toString()); |
| 4710 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4711 | pw.print(prefix); |
| 4712 | sb.setLength(0); |
| 4713 | sb.append(prefix); |
| 4714 | sb.append(" Cellular kernel active time: "); |
| 4715 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4716 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4717 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4718 | sb.append(")"); |
| 4719 | pw.println(sb.toString()); |
| 4720 | |
| 4721 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4722 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4723 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4724 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4725 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4726 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4727 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4728 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4729 | didOne = false; |
| 4730 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4731 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4732 | if (time == 0) { |
| 4733 | continue; |
| 4734 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4735 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4736 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4737 | didOne = true; |
Bookatz | df6baff | 2018-12-12 19:38:11 -0800 | [diff] [blame] | 4738 | sb.append(i < DATA_CONNECTION_NAMES.length ? DATA_CONNECTION_NAMES[i] : "ERROR"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4739 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4740 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4741 | sb.append("("); |
| 4742 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4743 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4744 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4745 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4746 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4747 | |
| 4748 | sb.setLength(0); |
| 4749 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4750 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4751 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4752 | "very poor (less than -128dBm): ", |
| 4753 | "poor (-128dBm to -118dBm): ", |
| 4754 | "moderate (-118dBm to -108dBm): ", |
| 4755 | "good (-108dBm to -98dBm): ", |
| 4756 | "great (greater than -98dBm): "}; |
| 4757 | didOne = false; |
| 4758 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4759 | cellularRxSignalStrengthDescription.length); |
| 4760 | for (int i=0; i<numCellularRxBins; i++) { |
| 4761 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4762 | if (time == 0) { |
| 4763 | continue; |
| 4764 | } |
| 4765 | sb.append("\n "); |
| 4766 | sb.append(prefix); |
| 4767 | didOne = true; |
| 4768 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4769 | sb.append(" "); |
| 4770 | formatTimeMs(sb, time/1000); |
| 4771 | sb.append("("); |
| 4772 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4773 | sb.append(") "); |
| 4774 | } |
| 4775 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4776 | pw.println(sb.toString()); |
| 4777 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4778 | printControllerActivity(pw, sb, prefix, CELLULAR_CONTROLLER_NAME, |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4779 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4780 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4781 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4782 | sb.setLength(0); |
| 4783 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4784 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4785 | pw.println(sb.toString()); |
| 4786 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4787 | pw.print(prefix); |
| 4788 | sb.setLength(0); |
| 4789 | sb.append(prefix); |
| 4790 | sb.append(" Wifi kernel active time: "); |
| 4791 | final long wifiActiveTime = getWifiActiveTime(rawRealtime, which); |
| 4792 | formatTimeMs(sb, wifiActiveTime / 1000); |
| 4793 | sb.append("("); sb.append(formatRatioLocked(wifiActiveTime, whichBatteryRealtime)); |
| 4794 | sb.append(")"); |
| 4795 | pw.println(sb.toString()); |
| 4796 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4797 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4798 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4799 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4800 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4801 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4802 | sb.setLength(0); |
| 4803 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4804 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4805 | didOne = false; |
| 4806 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4807 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4808 | if (time == 0) { |
| 4809 | continue; |
| 4810 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4811 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4812 | didOne = true; |
| 4813 | sb.append(WIFI_STATE_NAMES[i]); |
| 4814 | sb.append(" "); |
| 4815 | formatTimeMs(sb, time/1000); |
| 4816 | sb.append("("); |
| 4817 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4818 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4819 | } |
| 4820 | if (!didOne) sb.append(" (no activity)"); |
| 4821 | pw.println(sb.toString()); |
| 4822 | |
| 4823 | sb.setLength(0); |
| 4824 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4825 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4826 | didOne = false; |
| 4827 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4828 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4829 | if (time == 0) { |
| 4830 | continue; |
| 4831 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4832 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4833 | didOne = true; |
| 4834 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4835 | sb.append(" "); |
| 4836 | formatTimeMs(sb, time/1000); |
| 4837 | sb.append("("); |
| 4838 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4839 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4840 | } |
| 4841 | if (!didOne) sb.append(" (no activity)"); |
| 4842 | pw.println(sb.toString()); |
| 4843 | |
| 4844 | sb.setLength(0); |
| 4845 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4846 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4847 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4848 | "very poor (less than -88.75dBm): ", |
| 4849 | "poor (-88.75 to -77.5dBm): ", |
| 4850 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4851 | "good (-66.25dBm to -55dBm): ", |
| 4852 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4853 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4854 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4855 | wifiRxSignalStrengthDescription.length); |
| 4856 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4857 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4858 | if (time == 0) { |
| 4859 | continue; |
| 4860 | } |
| 4861 | sb.append("\n "); |
| 4862 | sb.append(prefix); |
| 4863 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4864 | sb.append(" "); |
| 4865 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4866 | formatTimeMs(sb, time/1000); |
| 4867 | sb.append("("); |
| 4868 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4869 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4870 | } |
| 4871 | if (!didOne) sb.append(" (no activity)"); |
| 4872 | pw.println(sb.toString()); |
| 4873 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4874 | printControllerActivity(pw, sb, prefix, WIFI_CONTROLLER_NAME, |
| 4875 | getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4876 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4877 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4878 | sb.setLength(0); |
| 4879 | sb.append(prefix); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4880 | sb.append(" GPS Statistics:"); |
| 4881 | pw.println(sb.toString()); |
| 4882 | |
| 4883 | sb.setLength(0); |
| 4884 | sb.append(prefix); |
| 4885 | sb.append(" GPS signal quality (Top 4 Average CN0):"); |
| 4886 | final String[] gpsSignalQualityDescription = new String[]{ |
| 4887 | "poor (less than 20 dBHz): ", |
| 4888 | "good (greater than 20 dBHz): "}; |
| 4889 | final int numGpsSignalQualityBins = Math.min(GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS, |
| 4890 | gpsSignalQualityDescription.length); |
| 4891 | for (int i=0; i<numGpsSignalQualityBins; i++) { |
| 4892 | final long time = getGpsSignalQualityTime(i, rawRealtime, which); |
| 4893 | sb.append("\n "); |
| 4894 | sb.append(prefix); |
| 4895 | sb.append(" "); |
| 4896 | sb.append(gpsSignalQualityDescription[i]); |
| 4897 | formatTimeMs(sb, time/1000); |
| 4898 | sb.append("("); |
| 4899 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4900 | sb.append(") "); |
| 4901 | } |
| 4902 | pw.println(sb.toString()); |
| 4903 | |
| 4904 | final long gpsBatteryDrainMaMs = getGpsBatteryDrainMaMs(); |
| 4905 | if (gpsBatteryDrainMaMs > 0) { |
| 4906 | pw.print(prefix); |
| 4907 | sb.setLength(0); |
| 4908 | sb.append(prefix); |
| 4909 | sb.append(" Battery Drain (mAh): "); |
| 4910 | sb.append(Double.toString(((double) gpsBatteryDrainMaMs)/(3600 * 1000))); |
| 4911 | pw.println(sb.toString()); |
| 4912 | } |
| 4913 | |
| 4914 | pw.print(prefix); |
| 4915 | sb.setLength(0); |
| 4916 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4917 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4918 | pw.println(sb.toString()); |
| 4919 | pw.println(""); |
| 4920 | |
| 4921 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4922 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4923 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4924 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4925 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4926 | sb.setLength(0); |
| 4927 | sb.append(prefix); |
| 4928 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4929 | pw.println(sb.toString()); |
| 4930 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4931 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4932 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4933 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4934 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4935 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4936 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4937 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4938 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4939 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4940 | pw.println(getDischargeStartLevel()); |
| 4941 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4942 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4943 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4944 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4945 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4946 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4947 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4948 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4949 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4950 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4951 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4952 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4953 | pw.println(getDischargeAmountScreenOff()); |
| 4954 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4955 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4956 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4957 | } else { |
| 4958 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4959 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4960 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4961 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4962 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4963 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4964 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4965 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4966 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4967 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4968 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4969 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4970 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4971 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4972 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4973 | helper.create(this); |
| 4974 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4975 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4976 | if (sippers != null && sippers.size() > 0) { |
| 4977 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4978 | pw.print(prefix); pw.print(" Capacity: "); |
| 4979 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4980 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4981 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4982 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4983 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4984 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4985 | pw.println(); |
| 4986 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4987 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4988 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4989 | switch (bs.drainType) { |
Kweku Adams | ef72895 | 2018-04-10 17:56:16 -0700 | [diff] [blame] | 4990 | case AMBIENT_DISPLAY: |
| 4991 | pw.print(" Ambient display: "); |
| 4992 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4993 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4994 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4995 | break; |
| 4996 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4997 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4998 | break; |
| 4999 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5000 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5001 | break; |
| 5002 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5003 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5004 | break; |
| 5005 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5006 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5007 | break; |
| 5008 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5009 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5010 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5011 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5012 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5013 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5014 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5015 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5016 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5017 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5018 | break; |
| 5019 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5020 | pw.print(" User "); pw.print(bs.userId); |
| 5021 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5022 | break; |
| 5023 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5024 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5025 | break; |
| 5026 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5027 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5028 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5029 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5030 | pw.print(" Camera: "); |
| 5031 | break; |
| 5032 | default: |
| 5033 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5034 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5035 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5036 | printmAh(pw, bs.totalPowerMah); |
| 5037 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 5038 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 5039 | // If the usage (generic power) isn't the whole amount, we list out |
| 5040 | // what components are involved in the calculation. |
| 5041 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5042 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 5043 | if (bs.usagePowerMah != 0) { |
| 5044 | pw.print(" usage="); |
| 5045 | printmAh(pw, bs.usagePowerMah); |
| 5046 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5047 | if (bs.cpuPowerMah != 0) { |
| 5048 | pw.print(" cpu="); |
| 5049 | printmAh(pw, bs.cpuPowerMah); |
| 5050 | } |
| 5051 | if (bs.wakeLockPowerMah != 0) { |
| 5052 | pw.print(" wake="); |
| 5053 | printmAh(pw, bs.wakeLockPowerMah); |
| 5054 | } |
| 5055 | if (bs.mobileRadioPowerMah != 0) { |
| 5056 | pw.print(" radio="); |
| 5057 | printmAh(pw, bs.mobileRadioPowerMah); |
| 5058 | } |
| 5059 | if (bs.wifiPowerMah != 0) { |
| 5060 | pw.print(" wifi="); |
| 5061 | printmAh(pw, bs.wifiPowerMah); |
| 5062 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5063 | if (bs.bluetoothPowerMah != 0) { |
| 5064 | pw.print(" bt="); |
| 5065 | printmAh(pw, bs.bluetoothPowerMah); |
| 5066 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5067 | if (bs.gpsPowerMah != 0) { |
| 5068 | pw.print(" gps="); |
| 5069 | printmAh(pw, bs.gpsPowerMah); |
| 5070 | } |
| 5071 | if (bs.sensorPowerMah != 0) { |
| 5072 | pw.print(" sensor="); |
| 5073 | printmAh(pw, bs.sensorPowerMah); |
| 5074 | } |
| 5075 | if (bs.cameraPowerMah != 0) { |
| 5076 | pw.print(" camera="); |
| 5077 | printmAh(pw, bs.cameraPowerMah); |
| 5078 | } |
| 5079 | if (bs.flashlightPowerMah != 0) { |
| 5080 | pw.print(" flash="); |
| 5081 | printmAh(pw, bs.flashlightPowerMah); |
| 5082 | } |
| 5083 | pw.print(" )"); |
| 5084 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 5085 | |
| 5086 | // If there is additional smearing information, include it. |
| 5087 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 5088 | pw.print(" Including smearing: "); |
| 5089 | printmAh(pw, bs.totalSmearedPowerMah); |
| 5090 | pw.print(" ("); |
| 5091 | if (bs.screenPowerMah != 0) { |
| 5092 | pw.print(" screen="); |
| 5093 | printmAh(pw, bs.screenPowerMah); |
| 5094 | } |
| 5095 | if (bs.proportionalSmearMah != 0) { |
| 5096 | pw.print(" proportional="); |
| 5097 | printmAh(pw, bs.proportionalSmearMah); |
| 5098 | } |
| 5099 | pw.print(" )"); |
| 5100 | } |
| 5101 | if (bs.shouldHide) { |
| 5102 | pw.print(" Excluded from smearing"); |
| 5103 | } |
| 5104 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5105 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5106 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5107 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5108 | } |
| 5109 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5110 | sippers = helper.getMobilemsppList(); |
| 5111 | if (sippers != null && sippers.size() > 0) { |
| 5112 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5113 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5114 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5115 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5116 | sb.setLength(0); |
| 5117 | sb.append(prefix); sb.append(" Uid "); |
| 5118 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 5119 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 5120 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 5121 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5122 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5123 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5124 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5125 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5126 | sb.setLength(0); |
| 5127 | sb.append(prefix); |
| 5128 | sb.append(" TOTAL TIME: "); |
| 5129 | formatTimeMs(sb, totalTime); |
| 5130 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 5131 | sb.append(")"); |
| 5132 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5133 | pw.println(); |
| 5134 | } |
| 5135 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5136 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 5137 | @Override |
| 5138 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 5139 | long lhsTime = lhs.mTime; |
| 5140 | long rhsTime = rhs.mTime; |
| 5141 | if (lhsTime < rhsTime) { |
| 5142 | return 1; |
| 5143 | } |
| 5144 | if (lhsTime > rhsTime) { |
| 5145 | return -1; |
| 5146 | } |
| 5147 | return 0; |
| 5148 | } |
| 5149 | }; |
| 5150 | |
| 5151 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5152 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 5153 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5154 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5155 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 5156 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 5157 | : kernelWakelocks.entrySet()) { |
| 5158 | final BatteryStats.Timer timer = ent.getValue(); |
| 5159 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5160 | if (totalTimeMillis > 0) { |
| 5161 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 5162 | } |
| 5163 | } |
| 5164 | if (ktimers.size() > 0) { |
| 5165 | Collections.sort(ktimers, timerComparator); |
| 5166 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 5167 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5168 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5169 | String linePrefix = ": "; |
| 5170 | sb.setLength(0); |
| 5171 | sb.append(prefix); |
| 5172 | sb.append(" Kernel Wake lock "); |
| 5173 | sb.append(timer.mName); |
| 5174 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 5175 | which, linePrefix); |
| 5176 | if (!linePrefix.equals(": ")) { |
| 5177 | sb.append(" realtime"); |
| 5178 | // Only print out wake locks that were held |
| 5179 | pw.println(sb.toString()); |
| 5180 | } |
| 5181 | } |
| 5182 | pw.println(); |
| 5183 | } |
| 5184 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5185 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5186 | if (timers.size() > 0) { |
| 5187 | Collections.sort(timers, timerComparator); |
| 5188 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5189 | for (int i=0; i<timers.size(); i++) { |
| 5190 | TimerEntry timer = timers.get(i); |
| 5191 | sb.setLength(0); |
| 5192 | sb.append(" Wake lock "); |
| 5193 | UserHandle.formatUid(sb, timer.mId); |
| 5194 | sb.append(" "); |
| 5195 | sb.append(timer.mName); |
| 5196 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5197 | sb.append(" realtime"); |
| 5198 | pw.println(sb.toString()); |
| 5199 | } |
| 5200 | timers.clear(); |
| 5201 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5202 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5203 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5204 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5205 | if (wakeupReasons.size() > 0) { |
| 5206 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5207 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5208 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5209 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5210 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5211 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5212 | } |
| 5213 | Collections.sort(reasons, timerComparator); |
| 5214 | for (int i=0; i<reasons.size(); i++) { |
| 5215 | TimerEntry timer = reasons.get(i); |
| 5216 | String linePrefix = ": "; |
| 5217 | sb.setLength(0); |
| 5218 | sb.append(prefix); |
| 5219 | sb.append(" Wakeup reason "); |
| 5220 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5221 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5222 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5223 | pw.println(sb.toString()); |
| 5224 | } |
| 5225 | pw.println(); |
| 5226 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5227 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5228 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5229 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5230 | if (mMemoryStats.size() > 0) { |
| 5231 | pw.println(" Memory Stats"); |
| 5232 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5233 | sb.setLength(0); |
| 5234 | sb.append(" Bandwidth "); |
| 5235 | sb.append(mMemoryStats.keyAt(i)); |
| 5236 | sb.append(" Time "); |
| 5237 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5238 | pw.println(sb.toString()); |
| 5239 | } |
| 5240 | pw.println(); |
| 5241 | } |
| 5242 | |
| 5243 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5244 | if (rpmStats.size() > 0) { |
| 5245 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5246 | if (rpmStats.size() > 0) { |
| 5247 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5248 | final String timerName = ent.getKey(); |
| 5249 | final Timer timer = ent.getValue(); |
| 5250 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5251 | } |
| 5252 | } |
| 5253 | pw.println(); |
| 5254 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5255 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5256 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5257 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5258 | pw.print(prefix); |
| 5259 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5260 | if (screenOffRpmStats.size() > 0) { |
| 5261 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5262 | final String timerName = ent.getKey(); |
| 5263 | final Timer timer = ent.getValue(); |
| 5264 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5265 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5266 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5267 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5268 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5271 | final long[] cpuFreqs = getCpuFreqs(); |
| 5272 | if (cpuFreqs != null) { |
| 5273 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5274 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5275 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5276 | sb.append(" " + cpuFreqs[i]); |
| 5277 | } |
| 5278 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5279 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | for (int iu=0; iu<NU; iu++) { |
| 5283 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5284 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5285 | continue; |
| 5286 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5287 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5288 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5289 | |
| 5290 | pw.print(prefix); |
| 5291 | pw.print(" "); |
| 5292 | UserHandle.formatUid(pw, uid); |
| 5293 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5294 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5295 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5296 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5297 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5298 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5299 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5300 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5301 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5302 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5303 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5304 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5305 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5306 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5307 | |
| 5308 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5309 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5310 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5311 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5312 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5313 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5314 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5315 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5316 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5317 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5318 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5319 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5320 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5321 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5322 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5323 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5324 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5325 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5326 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5327 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5328 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5329 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5330 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5331 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5332 | sb.setLength(0); |
| 5333 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5334 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5335 | sb.append("("); |
| 5336 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5337 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5338 | long packets = mobileRxPackets + mobileTxPackets; |
| 5339 | if (packets == 0) { |
| 5340 | packets = 1; |
| 5341 | } |
| 5342 | sb.append(" @ "); |
| 5343 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5344 | sb.append(" mspp"); |
| 5345 | pw.println(sb.toString()); |
| 5346 | } |
| 5347 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5348 | if (mobileWakeup > 0) { |
| 5349 | sb.setLength(0); |
| 5350 | sb.append(prefix); |
| 5351 | sb.append(" Mobile radio AP wakeups: "); |
| 5352 | sb.append(mobileWakeup); |
| 5353 | pw.println(sb.toString()); |
| 5354 | } |
| 5355 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5356 | printControllerActivityIfInteresting(pw, sb, prefix + " ", |
| 5357 | CELLULAR_CONTROLLER_NAME, u.getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5358 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5359 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5360 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5361 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5362 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5363 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5364 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5367 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5368 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5369 | || uidWifiRunningTime != 0) { |
| 5370 | sb.setLength(0); |
| 5371 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5372 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5373 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5374 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5375 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5376 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5377 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5378 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5379 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5380 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5381 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5382 | whichBatteryRealtime)); sb.append(") "); |
| 5383 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5384 | sb.append("x\n"); |
| 5385 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5386 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5387 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5388 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5389 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5390 | sb.append(") "); |
| 5391 | sb.append(wifiScanCount); |
| 5392 | sb.append("x\n"); |
| 5393 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5394 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5395 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5396 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5397 | sb.append(") "); |
| 5398 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5399 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5400 | pw.println(sb.toString()); |
| 5401 | } |
| 5402 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5403 | if (wifiWakeup > 0) { |
| 5404 | sb.setLength(0); |
| 5405 | sb.append(prefix); |
| 5406 | sb.append(" WiFi AP wakeups: "); |
| 5407 | sb.append(wifiWakeup); |
| 5408 | pw.println(sb.toString()); |
| 5409 | } |
| 5410 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5411 | printControllerActivityIfInteresting(pw, sb, prefix + " ", WIFI_CONTROLLER_NAME, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5412 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5413 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5414 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5415 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5416 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5417 | pw.print(formatBytesLocked(btTxBytes)); |
| 5418 | pw.println(" sent"); |
| 5419 | } |
| 5420 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5421 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5422 | if (bleTimer != null) { |
| 5423 | // Convert from microseconds to milliseconds with rounding |
| 5424 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5425 | / 1000; |
| 5426 | if (totalTimeMs != 0) { |
| 5427 | final int count = bleTimer.getCountLocked(which); |
| 5428 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5429 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5430 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5431 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5432 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5433 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5434 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5435 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5436 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5437 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5438 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5439 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5440 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5441 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5442 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5443 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5444 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5445 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5446 | final Timer unoptimizedScanTimerBg = |
| 5447 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5448 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5449 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5450 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5451 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5452 | |
| 5453 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5454 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5455 | sb.append(prefix); |
| 5456 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5457 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5458 | sb.append(" ("); |
| 5459 | sb.append(count); |
| 5460 | sb.append(" times)"); |
| 5461 | if (bleTimer.isRunningLocked()) { |
| 5462 | sb.append(" (currently running)"); |
| 5463 | } |
| 5464 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5465 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5466 | |
| 5467 | sb.append(prefix); |
| 5468 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5469 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5470 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5471 | sb.append(count); |
| 5472 | sb.append(" times)"); |
| 5473 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5474 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5475 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5476 | sb.append("\n"); |
| 5477 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5478 | sb.append(prefix); |
| 5479 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5480 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5481 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5482 | sb.append(countBg); |
| 5483 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5484 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5485 | sb.append(" (currently running in background)"); |
| 5486 | } |
| 5487 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5488 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5489 | |
| 5490 | sb.append(prefix); |
| 5491 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5492 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5493 | sb.append(" ("); |
| 5494 | sb.append(resultCountBg); |
| 5495 | sb.append(" in background)"); |
| 5496 | |
| 5497 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5498 | sb.append("\n"); |
| 5499 | sb.append(prefix); |
| 5500 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5501 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5502 | sb.append(" (max "); |
| 5503 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5504 | sb.append(")"); |
| 5505 | if (unoptimizedScanTimer != null |
| 5506 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5507 | sb.append(" (currently running unoptimized)"); |
| 5508 | } |
| 5509 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5510 | sb.append("\n"); |
| 5511 | sb.append(prefix); |
| 5512 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5513 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5514 | sb.append(" (max "); |
| 5515 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5516 | sb.append(")"); |
| 5517 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5518 | sb.append(" (currently running unoptimized in background)"); |
| 5519 | } |
| 5520 | } |
| 5521 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5522 | pw.println(sb.toString()); |
| 5523 | uidActivity = true; |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5528 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5529 | if (u.hasUserActivity()) { |
| 5530 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5531 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5532 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5533 | if (val != 0) { |
| 5534 | if (!hasData) { |
| 5535 | sb.setLength(0); |
| 5536 | sb.append(" User activity: "); |
| 5537 | hasData = true; |
| 5538 | } else { |
| 5539 | sb.append(", "); |
| 5540 | } |
| 5541 | sb.append(val); |
| 5542 | sb.append(" "); |
| 5543 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5544 | } |
| 5545 | } |
| 5546 | if (hasData) { |
| 5547 | pw.println(sb.toString()); |
| 5548 | } |
| 5549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5551 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5552 | = u.getWakelockStats(); |
| 5553 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5554 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5555 | int countWakelock = 0; |
| 5556 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5557 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5558 | String linePrefix = ": "; |
| 5559 | sb.setLength(0); |
| 5560 | sb.append(prefix); |
| 5561 | sb.append(" Wake lock "); |
| 5562 | sb.append(wakelocks.keyAt(iw)); |
| 5563 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5564 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5565 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5566 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5567 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5568 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5569 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5570 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5571 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5572 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5573 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5574 | sb.append(" realtime"); |
| 5575 | pw.println(sb.toString()); |
| 5576 | uidActivity = true; |
| 5577 | countWakelock++; |
| 5578 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5579 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5580 | rawRealtime, which); |
| 5581 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5582 | rawRealtime, which); |
| 5583 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5584 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5585 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5586 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5587 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5588 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5589 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5590 | // pooled and therefore just a lower bound) |
| 5591 | long actualTotalPartialWakelock = 0; |
| 5592 | long actualBgPartialWakelock = 0; |
| 5593 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5594 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5595 | // Convert from microseconds to milliseconds with rounding |
| 5596 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5597 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5598 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5599 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5600 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5604 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5605 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5606 | sb.setLength(0); |
| 5607 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5608 | sb.append(" TOTAL wake: "); |
| 5609 | boolean needComma = false; |
| 5610 | if (totalFullWakelock != 0) { |
| 5611 | needComma = true; |
| 5612 | formatTimeMs(sb, totalFullWakelock); |
| 5613 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5614 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5615 | if (totalPartialWakelock != 0) { |
| 5616 | if (needComma) { |
| 5617 | sb.append(", "); |
| 5618 | } |
| 5619 | needComma = true; |
| 5620 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5621 | sb.append("blamed partial"); |
| 5622 | } |
| 5623 | if (actualTotalPartialWakelock != 0) { |
| 5624 | if (needComma) { |
| 5625 | sb.append(", "); |
| 5626 | } |
| 5627 | needComma = true; |
| 5628 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5629 | sb.append("actual partial"); |
| 5630 | } |
| 5631 | if (actualBgPartialWakelock != 0) { |
| 5632 | if (needComma) { |
| 5633 | sb.append(", "); |
| 5634 | } |
| 5635 | needComma = true; |
| 5636 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5637 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5638 | } |
| 5639 | if (totalWindowWakelock != 0) { |
| 5640 | if (needComma) { |
| 5641 | sb.append(", "); |
| 5642 | } |
| 5643 | needComma = true; |
| 5644 | formatTimeMs(sb, totalWindowWakelock); |
| 5645 | sb.append("window"); |
| 5646 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5647 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5648 | if (needComma) { |
| 5649 | sb.append(","); |
| 5650 | } |
| 5651 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5652 | formatTimeMs(sb, totalDrawWakelock); |
| 5653 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5654 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5655 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5656 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5657 | } |
| 5658 | } |
| 5659 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5660 | // Calculate multicast wakelock stats |
| 5661 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5662 | if (mcTimer != null) { |
| 5663 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5664 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5665 | |
| 5666 | if (multicastWakeLockTimeMicros > 0) { |
| 5667 | sb.setLength(0); |
| 5668 | sb.append(prefix); |
| 5669 | sb.append(" WiFi Multicast Wakelock"); |
| 5670 | sb.append(" count = "); |
| 5671 | sb.append(multicastWakeLockCount); |
| 5672 | sb.append(" time = "); |
| 5673 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5674 | pw.println(sb.toString()); |
| 5675 | } |
| 5676 | } |
| 5677 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5678 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5679 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5680 | final Timer timer = syncs.valueAt(isy); |
| 5681 | // Convert from microseconds to milliseconds with rounding |
| 5682 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5683 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5684 | final Timer bgTimer = timer.getSubTimer(); |
| 5685 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5686 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5687 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5688 | sb.setLength(0); |
| 5689 | sb.append(prefix); |
| 5690 | sb.append(" Sync "); |
| 5691 | sb.append(syncs.keyAt(isy)); |
| 5692 | sb.append(": "); |
| 5693 | if (totalTime != 0) { |
| 5694 | formatTimeMs(sb, totalTime); |
| 5695 | sb.append("realtime ("); |
| 5696 | sb.append(count); |
| 5697 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5698 | if (bgTime > 0) { |
| 5699 | sb.append(", "); |
| 5700 | formatTimeMs(sb, bgTime); |
| 5701 | sb.append("background ("); |
| 5702 | sb.append(bgCount); |
| 5703 | sb.append(" times)"); |
| 5704 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5705 | } else { |
| 5706 | sb.append("(not used)"); |
| 5707 | } |
| 5708 | pw.println(sb.toString()); |
| 5709 | uidActivity = true; |
| 5710 | } |
| 5711 | |
| 5712 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5713 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5714 | final Timer timer = jobs.valueAt(ij); |
| 5715 | // Convert from microseconds to milliseconds with rounding |
| 5716 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5717 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5718 | final Timer bgTimer = timer.getSubTimer(); |
| 5719 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5720 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5721 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5722 | sb.setLength(0); |
| 5723 | sb.append(prefix); |
| 5724 | sb.append(" Job "); |
| 5725 | sb.append(jobs.keyAt(ij)); |
| 5726 | sb.append(": "); |
| 5727 | if (totalTime != 0) { |
| 5728 | formatTimeMs(sb, totalTime); |
| 5729 | sb.append("realtime ("); |
| 5730 | sb.append(count); |
| 5731 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5732 | if (bgTime > 0) { |
| 5733 | sb.append(", "); |
| 5734 | formatTimeMs(sb, bgTime); |
| 5735 | sb.append("background ("); |
| 5736 | sb.append(bgCount); |
| 5737 | sb.append(" times)"); |
| 5738 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5739 | } else { |
| 5740 | sb.append("(not used)"); |
| 5741 | } |
| 5742 | pw.println(sb.toString()); |
| 5743 | uidActivity = true; |
| 5744 | } |
| 5745 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5746 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5747 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5748 | SparseIntArray types = completions.valueAt(ic); |
| 5749 | if (types != null) { |
| 5750 | pw.print(prefix); |
| 5751 | pw.print(" Job Completions "); |
| 5752 | pw.print(completions.keyAt(ic)); |
| 5753 | pw.print(":"); |
| 5754 | for (int it=0; it<types.size(); it++) { |
| 5755 | pw.print(" "); |
| 5756 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5757 | pw.print("("); |
| 5758 | pw.print(types.valueAt(it)); |
| 5759 | pw.print("x)"); |
| 5760 | } |
| 5761 | pw.println(); |
| 5762 | } |
| 5763 | } |
| 5764 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 5765 | u.getDeferredJobsLineLocked(sb, which); |
| 5766 | if (sb.length() > 0) { |
| 5767 | pw.print(" Jobs deferred on launch "); pw.println(sb.toString()); |
| 5768 | } |
| 5769 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5770 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5771 | prefix, "Flashlight"); |
| 5772 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5773 | prefix, "Camera"); |
| 5774 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5775 | prefix, "Video"); |
| 5776 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5777 | prefix, "Audio"); |
| 5778 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5779 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5780 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5781 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5782 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5783 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5784 | sb.setLength(0); |
| 5785 | sb.append(prefix); |
| 5786 | sb.append(" Sensor "); |
| 5787 | int handle = se.getHandle(); |
| 5788 | if (handle == Uid.Sensor.GPS) { |
| 5789 | sb.append("GPS"); |
| 5790 | } else { |
| 5791 | sb.append(handle); |
| 5792 | } |
| 5793 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5795 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5796 | if (timer != null) { |
| 5797 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5798 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5799 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5800 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5801 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5802 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5803 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5804 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5805 | final long bgActualTime = bgTimer != null ? |
| 5806 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5807 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5808 | //timer.logState(); |
| 5809 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5810 | if (actualTime != totalTime) { |
| 5811 | formatTimeMs(sb, totalTime); |
| 5812 | sb.append("blamed realtime, "); |
| 5813 | } |
| 5814 | |
| 5815 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5816 | sb.append("realtime ("); |
| 5817 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5818 | sb.append(" times)"); |
| 5819 | |
| 5820 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5821 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5822 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5823 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5824 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5825 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | } else { |
| 5828 | sb.append("(not used)"); |
| 5829 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5830 | } else { |
| 5831 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5833 | |
| 5834 | pw.println(sb.toString()); |
| 5835 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5836 | } |
| 5837 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5838 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5839 | "Vibrator"); |
| 5840 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5841 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5842 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5843 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5844 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5845 | long totalStateTime = 0; |
| 5846 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5847 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5848 | if (time > 0) { |
| 5849 | totalStateTime += time; |
| 5850 | sb.setLength(0); |
| 5851 | sb.append(prefix); |
| 5852 | sb.append(" "); |
| 5853 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5854 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5855 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5856 | pw.println(sb.toString()); |
| 5857 | uidActivity = true; |
| 5858 | } |
| 5859 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5860 | if (totalStateTime > 0) { |
| 5861 | sb.setLength(0); |
| 5862 | sb.append(prefix); |
| 5863 | sb.append(" Total running: "); |
| 5864 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5865 | pw.println(sb.toString()); |
| 5866 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5867 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5868 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5869 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5870 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5871 | sb.setLength(0); |
| 5872 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5873 | sb.append(" Total cpu time: u="); |
| 5874 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5875 | sb.append("s="); |
| 5876 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5877 | pw.println(sb.toString()); |
| 5878 | } |
| 5879 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5880 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5881 | if (cpuFreqTimes != null) { |
| 5882 | sb.setLength(0); |
| 5883 | sb.append(" Total cpu time per freq:"); |
| 5884 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5885 | sb.append(" " + cpuFreqTimes[i]); |
| 5886 | } |
| 5887 | pw.println(sb.toString()); |
| 5888 | } |
| 5889 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5890 | if (screenOffCpuFreqTimes != null) { |
| 5891 | sb.setLength(0); |
| 5892 | sb.append(" Total screen-off cpu time per freq:"); |
| 5893 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5894 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5895 | } |
| 5896 | pw.println(sb.toString()); |
| 5897 | } |
| 5898 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5899 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5900 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5901 | if (cpuTimes != null) { |
| 5902 | sb.setLength(0); |
| 5903 | sb.append(" Cpu times per freq at state " |
| 5904 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5905 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5906 | sb.append(" " + cpuTimes[i]); |
| 5907 | } |
| 5908 | pw.println(sb.toString()); |
| 5909 | } |
| 5910 | |
| 5911 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5912 | if (screenOffCpuTimes != null) { |
| 5913 | sb.setLength(0); |
| 5914 | sb.append(" Screen-off cpu times per freq at state " |
| 5915 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5916 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5917 | sb.append(" " + screenOffCpuTimes[i]); |
| 5918 | } |
| 5919 | pw.println(sb.toString()); |
| 5920 | } |
| 5921 | } |
| 5922 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5923 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5924 | = u.getProcessStats(); |
| 5925 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5926 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5927 | long userTime; |
| 5928 | long systemTime; |
| 5929 | long foregroundTime; |
| 5930 | int starts; |
| 5931 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5933 | userTime = ps.getUserTime(which); |
| 5934 | systemTime = ps.getSystemTime(which); |
| 5935 | foregroundTime = ps.getForegroundTime(which); |
| 5936 | starts = ps.getStarts(which); |
| 5937 | final int numCrashes = ps.getNumCrashes(which); |
| 5938 | final int numAnrs = ps.getNumAnrs(which); |
| 5939 | numExcessive = which == STATS_SINCE_CHARGED |
| 5940 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5942 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5943 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5944 | sb.setLength(0); |
| 5945 | sb.append(prefix); sb.append(" Proc "); |
| 5946 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5947 | sb.append(prefix); sb.append(" CPU: "); |
| 5948 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5949 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5950 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5951 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5952 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5953 | boolean hasOne = false; |
| 5954 | if (starts != 0) { |
| 5955 | hasOne = true; |
| 5956 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5957 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5958 | if (numCrashes != 0) { |
| 5959 | if (hasOne) { |
| 5960 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5961 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5962 | hasOne = true; |
| 5963 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5964 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5965 | if (numAnrs != 0) { |
| 5966 | if (hasOne) { |
| 5967 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5969 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | } |
| 5971 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5972 | pw.println(sb.toString()); |
| 5973 | for (int e=0; e<numExcessive; e++) { |
| 5974 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5975 | if (ew != null) { |
| 5976 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5977 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5978 | pw.print("cpu"); |
| 5979 | } else { |
| 5980 | pw.print("unknown"); |
| 5981 | } |
| 5982 | pw.print(" use: "); |
| 5983 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5984 | pw.print(" over "); |
| 5985 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5986 | if (ew.overTime != 0) { |
| 5987 | pw.print(" ("); |
| 5988 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5989 | pw.println("%)"); |
| 5990 | } |
| 5991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | } |
| 5993 | uidActivity = true; |
| 5994 | } |
| 5995 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5996 | |
| 5997 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5998 | = u.getPackageStats(); |
| 5999 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 6000 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 6001 | pw.println(":"); |
| 6002 | boolean apkActivity = false; |
| 6003 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 6004 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 6005 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 6006 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 6007 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 6008 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 6009 | pw.println(" times"); |
| 6010 | apkActivity = true; |
| 6011 | } |
| 6012 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 6013 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 6014 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 6015 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 6016 | final int starts = ss.getStarts(which); |
| 6017 | final int launches = ss.getLaunches(which); |
| 6018 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 6019 | sb.setLength(0); |
| 6020 | sb.append(prefix); sb.append(" Service "); |
| 6021 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 6022 | sb.append(prefix); sb.append(" Created for: "); |
| 6023 | formatTimeMs(sb, startTime / 1000); |
| 6024 | sb.append("uptime\n"); |
| 6025 | sb.append(prefix); sb.append(" Starts: "); |
| 6026 | sb.append(starts); |
| 6027 | sb.append(", launches: "); sb.append(launches); |
| 6028 | pw.println(sb.toString()); |
| 6029 | apkActivity = true; |
| 6030 | } |
| 6031 | } |
| 6032 | if (!apkActivity) { |
| 6033 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 6034 | } |
| 6035 | uidActivity = true; |
| 6036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6038 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | } |
| 6042 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6043 | static void printBitDescriptions(StringBuilder sb, int oldval, int newval, |
| 6044 | HistoryTag wakelockTag, BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6045 | int diff = oldval ^ newval; |
| 6046 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6047 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6048 | for (int i=0; i<descriptions.length; i++) { |
| 6049 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6050 | if ((diff&bd.mask) != 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6051 | sb.append(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6052 | if (bd.shift < 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6053 | sb.append((newval & bd.mask) != 0 ? "+" : "-"); |
| 6054 | sb.append(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6055 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 6056 | didWake = true; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6057 | sb.append("="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6058 | if (longNames) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6059 | UserHandle.formatUid(sb, wakelockTag.uid); |
| 6060 | sb.append(":\""); |
| 6061 | sb.append(wakelockTag.string); |
| 6062 | sb.append("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6063 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6064 | sb.append(wakelockTag.poolIdx); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6065 | } |
| 6066 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6067 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6068 | sb.append(longNames ? bd.name : bd.shortName); |
| 6069 | sb.append("="); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6070 | int val = (newval&bd.mask)>>bd.shift; |
| 6071 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6072 | sb.append(longNames ? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6073 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6074 | sb.append(val); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6075 | } |
| 6076 | } |
| 6077 | } |
| 6078 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6079 | if (!didWake && wakelockTag != null) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6080 | sb.append(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6081 | if (longNames) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6082 | UserHandle.formatUid(sb, wakelockTag.uid); |
| 6083 | sb.append(":\""); |
| 6084 | sb.append(wakelockTag.string); |
| 6085 | sb.append("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6086 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6087 | sb.append(wakelockTag.poolIdx); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6088 | } |
| 6089 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6090 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6091 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6092 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6093 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | public static class HistoryPrinter { |
| 6097 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6098 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6099 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6100 | int oldStatus = -1; |
| 6101 | int oldHealth = -1; |
| 6102 | int oldPlug = -1; |
| 6103 | int oldTemp = -1; |
| 6104 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6105 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6106 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6107 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6108 | void reset() { |
| 6109 | oldState = oldState2 = 0; |
| 6110 | oldLevel = -1; |
| 6111 | oldStatus = -1; |
| 6112 | oldHealth = -1; |
| 6113 | oldPlug = -1; |
| 6114 | oldTemp = -1; |
| 6115 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6116 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6119 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6120 | boolean verbose) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6121 | pw.print(printNextItem(rec, baseTime, checkin, verbose)); |
| 6122 | } |
| 6123 | |
| 6124 | /** Print the next history item to proto. */ |
| 6125 | public void printNextItem(ProtoOutputStream proto, HistoryItem rec, long baseTime, |
| 6126 | boolean verbose) { |
| 6127 | String item = printNextItem(rec, baseTime, true, verbose); |
| 6128 | for (String line : item.split("\n")) { |
| 6129 | proto.write(BatteryStatsServiceDumpHistoryProto.CSV_LINES, line); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | private String printNextItem(HistoryItem rec, long baseTime, boolean checkin, |
| 6134 | boolean verbose) { |
| 6135 | StringBuilder item = new StringBuilder(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6136 | if (!checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6137 | item.append(" "); |
| 6138 | TimeUtils.formatDuration( |
| 6139 | rec.time - baseTime, item, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
| 6140 | item.append(" ("); |
| 6141 | item.append(rec.numReadInts); |
| 6142 | item.append(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6143 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6144 | item.append(BATTERY_STATS_CHECKIN_VERSION); item.append(','); |
| 6145 | item.append(HISTORY_DATA); item.append(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6146 | if (lastTime < 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6147 | item.append(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6148 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6149 | item.append(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6150 | } |
| 6151 | lastTime = rec.time; |
| 6152 | } |
| 6153 | if (rec.cmd == HistoryItem.CMD_START) { |
| 6154 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6155 | item.append(":"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6156 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6157 | item.append("START\n"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6158 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6159 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 6160 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6161 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6162 | item.append(":"); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6163 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6164 | if (rec.cmd == HistoryItem.CMD_RESET) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6165 | item.append("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6166 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6167 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6168 | item.append("TIME:"); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6169 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6170 | item.append(rec.currentTime); |
| 6171 | item.append("\n"); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6172 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6173 | item.append(" "); |
| 6174 | item.append(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6175 | rec.currentTime).toString()); |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6176 | item.append("\n"); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6177 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6178 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 6179 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6180 | item.append(":"); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6181 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6182 | item.append("SHUTDOWN\n"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6183 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 6184 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6185 | item.append(":"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6186 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6187 | item.append("*OVERFLOW*\n"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6188 | } else { |
| 6189 | if (!checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6190 | if (rec.batteryLevel < 10) item.append("00"); |
| 6191 | else if (rec.batteryLevel < 100) item.append("0"); |
| 6192 | item.append(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6193 | if (verbose) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6194 | item.append(" "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6195 | if (rec.states < 0) ; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6196 | else if (rec.states < 0x10) item.append("0000000"); |
| 6197 | else if (rec.states < 0x100) item.append("000000"); |
| 6198 | else if (rec.states < 0x1000) item.append("00000"); |
| 6199 | else if (rec.states < 0x10000) item.append("0000"); |
| 6200 | else if (rec.states < 0x100000) item.append("000"); |
| 6201 | else if (rec.states < 0x1000000) item.append("00"); |
| 6202 | else if (rec.states < 0x10000000) item.append("0"); |
| 6203 | item.append(Integer.toHexString(rec.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6204 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6205 | } else { |
| 6206 | if (oldLevel != rec.batteryLevel) { |
| 6207 | oldLevel = rec.batteryLevel; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6208 | item.append(",Bl="); item.append(rec.batteryLevel); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6209 | } |
| 6210 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6211 | if (oldStatus != rec.batteryStatus) { |
| 6212 | oldStatus = rec.batteryStatus; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6213 | item.append(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6214 | switch (oldStatus) { |
| 6215 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6216 | item.append(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6217 | break; |
| 6218 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6219 | item.append(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6220 | break; |
| 6221 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6222 | item.append(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6223 | break; |
| 6224 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6225 | item.append(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6226 | break; |
| 6227 | case BatteryManager.BATTERY_STATUS_FULL: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6228 | item.append(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6229 | break; |
| 6230 | default: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6231 | item.append(oldStatus); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6232 | break; |
| 6233 | } |
| 6234 | } |
| 6235 | if (oldHealth != rec.batteryHealth) { |
| 6236 | oldHealth = rec.batteryHealth; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6237 | item.append(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6238 | switch (oldHealth) { |
| 6239 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6240 | item.append(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6241 | break; |
| 6242 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6243 | item.append(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6244 | break; |
| 6245 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6246 | item.append(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6247 | break; |
| 6248 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6249 | item.append(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6250 | break; |
| 6251 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6252 | item.append(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6253 | break; |
| 6254 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6255 | item.append(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6256 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6257 | case BatteryManager.BATTERY_HEALTH_COLD: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6258 | item.append(checkin ? "c" : "cold"); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6259 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6260 | default: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6261 | item.append(oldHealth); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6262 | break; |
| 6263 | } |
| 6264 | } |
| 6265 | if (oldPlug != rec.batteryPlugType) { |
| 6266 | oldPlug = rec.batteryPlugType; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6267 | item.append(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6268 | switch (oldPlug) { |
| 6269 | case 0: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6270 | item.append(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6271 | break; |
| 6272 | case BatteryManager.BATTERY_PLUGGED_AC: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6273 | item.append(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6274 | break; |
| 6275 | case BatteryManager.BATTERY_PLUGGED_USB: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6276 | item.append(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6277 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6278 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6279 | item.append(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6280 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6281 | default: |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6282 | item.append(oldPlug); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6283 | break; |
| 6284 | } |
| 6285 | } |
| 6286 | if (oldTemp != rec.batteryTemperature) { |
| 6287 | oldTemp = rec.batteryTemperature; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6288 | item.append(checkin ? ",Bt=" : " temp="); |
| 6289 | item.append(oldTemp); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6290 | } |
| 6291 | if (oldVolt != rec.batteryVoltage) { |
| 6292 | oldVolt = rec.batteryVoltage; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6293 | item.append(checkin ? ",Bv=" : " volt="); |
| 6294 | item.append(oldVolt); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6295 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6296 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6297 | if (oldChargeMAh != chargeMAh) { |
| 6298 | oldChargeMAh = chargeMAh; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6299 | item.append(checkin ? ",Bcc=" : " charge="); |
| 6300 | item.append(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6301 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6302 | printBitDescriptions(item, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6303 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6304 | printBitDescriptions(item, oldState2, rec.states2, null, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6305 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6306 | if (rec.wakeReasonTag != null) { |
| 6307 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6308 | item.append(",wr="); |
| 6309 | item.append(rec.wakeReasonTag.poolIdx); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6310 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6311 | item.append(" wake_reason="); |
| 6312 | item.append(rec.wakeReasonTag.uid); |
| 6313 | item.append(":\""); |
| 6314 | item.append(rec.wakeReasonTag.string); |
| 6315 | item.append("\""); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6316 | } |
| 6317 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6318 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6319 | item.append(checkin ? "," : " "); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6320 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6321 | item.append("+"); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6322 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6323 | item.append("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6324 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6325 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6326 | : HISTORY_EVENT_NAMES; |
| 6327 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6328 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6329 | if (idx >= 0 && idx < eventNames.length) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6330 | item.append(eventNames[idx]); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6331 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6332 | item.append(checkin ? "Ev" : "event"); |
| 6333 | item.append(idx); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6334 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6335 | item.append("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6336 | if (checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6337 | item.append(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6338 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6339 | item.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6340 | .applyAsString(rec.eventTag.uid)); |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6341 | item.append(":\""); |
| 6342 | item.append(rec.eventTag.string); |
| 6343 | item.append("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6344 | } |
| 6345 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6346 | item.append("\n"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6347 | if (rec.stepDetails != null) { |
| 6348 | if (!checkin) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6349 | item.append(" Details: cpu="); |
| 6350 | item.append(rec.stepDetails.userTime); |
| 6351 | item.append("u+"); |
| 6352 | item.append(rec.stepDetails.systemTime); |
| 6353 | item.append("s"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6354 | if (rec.stepDetails.appCpuUid1 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6355 | item.append(" ("); |
| 6356 | printStepCpuUidDetails(item, rec.stepDetails.appCpuUid1, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6357 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6358 | if (rec.stepDetails.appCpuUid2 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6359 | item.append(", "); |
| 6360 | printStepCpuUidDetails(item, rec.stepDetails.appCpuUid2, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6361 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6362 | } |
| 6363 | if (rec.stepDetails.appCpuUid3 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6364 | item.append(", "); |
| 6365 | printStepCpuUidDetails(item, rec.stepDetails.appCpuUid3, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6366 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6367 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6368 | item.append(')'); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6369 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6370 | item.append("\n"); |
| 6371 | item.append(" /proc/stat="); |
| 6372 | item.append(rec.stepDetails.statUserTime); |
| 6373 | item.append(" usr, "); |
| 6374 | item.append(rec.stepDetails.statSystemTime); |
| 6375 | item.append(" sys, "); |
| 6376 | item.append(rec.stepDetails.statIOWaitTime); |
| 6377 | item.append(" io, "); |
| 6378 | item.append(rec.stepDetails.statIrqTime); |
| 6379 | item.append(" irq, "); |
| 6380 | item.append(rec.stepDetails.statSoftIrqTime); |
| 6381 | item.append(" sirq, "); |
| 6382 | item.append(rec.stepDetails.statIdlTime); |
| 6383 | item.append(" idle"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6384 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6385 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6386 | + rec.stepDetails.statSoftIrqTime; |
| 6387 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6388 | if (total > 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6389 | item.append(" ("); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6390 | float perc = ((float)totalRun) / ((float)total) * 100; |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6391 | item.append(String.format("%.1f%%", perc)); |
| 6392 | item.append(" of "); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6393 | StringBuilder sb = new StringBuilder(64); |
| 6394 | formatTimeMsNoSpace(sb, total*10); |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6395 | item.append(sb); |
| 6396 | item.append(")"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6397 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6398 | item.append(", PlatformIdleStat "); |
| 6399 | item.append(rec.stepDetails.statPlatformIdleState); |
| 6400 | item.append("\n"); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6401 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6402 | item.append(", SubsystemPowerState "); |
| 6403 | item.append(rec.stepDetails.statSubsystemPowerState); |
| 6404 | item.append("\n"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6405 | } else { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6406 | item.append(BATTERY_STATS_CHECKIN_VERSION); item.append(','); |
| 6407 | item.append(HISTORY_DATA); item.append(",0,Dcpu="); |
| 6408 | item.append(rec.stepDetails.userTime); |
| 6409 | item.append(":"); |
| 6410 | item.append(rec.stepDetails.systemTime); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6411 | if (rec.stepDetails.appCpuUid1 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6412 | printStepCpuUidCheckinDetails(item, rec.stepDetails.appCpuUid1, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6413 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6414 | if (rec.stepDetails.appCpuUid2 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6415 | printStepCpuUidCheckinDetails(item, rec.stepDetails.appCpuUid2, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6416 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6417 | } |
| 6418 | if (rec.stepDetails.appCpuUid3 >= 0) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6419 | printStepCpuUidCheckinDetails(item, rec.stepDetails.appCpuUid3, |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6420 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6421 | } |
| 6422 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6423 | item.append("\n"); |
| 6424 | item.append(BATTERY_STATS_CHECKIN_VERSION); item.append(','); |
| 6425 | item.append(HISTORY_DATA); item.append(",0,Dpst="); |
| 6426 | item.append(rec.stepDetails.statUserTime); |
| 6427 | item.append(','); |
| 6428 | item.append(rec.stepDetails.statSystemTime); |
| 6429 | item.append(','); |
| 6430 | item.append(rec.stepDetails.statIOWaitTime); |
| 6431 | item.append(','); |
| 6432 | item.append(rec.stepDetails.statIrqTime); |
| 6433 | item.append(','); |
| 6434 | item.append(rec.stepDetails.statSoftIrqTime); |
| 6435 | item.append(','); |
| 6436 | item.append(rec.stepDetails.statIdlTime); |
| 6437 | item.append(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6438 | if (rec.stepDetails.statPlatformIdleState != null) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6439 | item.append(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6440 | if (rec.stepDetails.statSubsystemPowerState != null) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6441 | item.append(','); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6442 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6443 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6444 | |
| 6445 | if (rec.stepDetails.statSubsystemPowerState != null) { |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6446 | item.append(rec.stepDetails.statSubsystemPowerState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6447 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6448 | item.append("\n"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6449 | } |
| 6450 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6451 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6452 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6453 | } |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6454 | |
| 6455 | return item.toString(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6456 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6457 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6458 | private void printStepCpuUidDetails(StringBuilder sb, int uid, int utime, int stime) { |
| 6459 | UserHandle.formatUid(sb, uid); |
| 6460 | sb.append("="); |
| 6461 | sb.append(utime); |
| 6462 | sb.append("u+"); |
| 6463 | sb.append(stime); |
| 6464 | sb.append("s"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6465 | } |
| 6466 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 6467 | private void printStepCpuUidCheckinDetails(StringBuilder sb, int uid, int utime, |
| 6468 | int stime) { |
| 6469 | sb.append('/'); |
| 6470 | sb.append(uid); |
| 6471 | sb.append(":"); |
| 6472 | sb.append(utime); |
| 6473 | sb.append(":"); |
| 6474 | sb.append(stime); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6475 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6476 | } |
| 6477 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6478 | private void printSizeValue(PrintWriter pw, long size) { |
| 6479 | float result = size; |
| 6480 | String suffix = ""; |
| 6481 | if (result >= 10*1024) { |
| 6482 | suffix = "KB"; |
| 6483 | result = result / 1024; |
| 6484 | } |
| 6485 | if (result >= 10*1024) { |
| 6486 | suffix = "MB"; |
| 6487 | result = result / 1024; |
| 6488 | } |
| 6489 | if (result >= 10*1024) { |
| 6490 | suffix = "GB"; |
| 6491 | result = result / 1024; |
| 6492 | } |
| 6493 | if (result >= 10*1024) { |
| 6494 | suffix = "TB"; |
| 6495 | result = result / 1024; |
| 6496 | } |
| 6497 | if (result >= 10*1024) { |
| 6498 | suffix = "PB"; |
| 6499 | result = result / 1024; |
| 6500 | } |
| 6501 | pw.print((int)result); |
| 6502 | pw.print(suffix); |
| 6503 | } |
| 6504 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6505 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6506 | String label3, long estimatedTime) { |
| 6507 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6508 | return false; |
| 6509 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6510 | pw.print(label1); |
| 6511 | pw.print(label2); |
| 6512 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6513 | StringBuilder sb = new StringBuilder(64); |
| 6514 | formatTimeMs(sb, estimatedTime); |
| 6515 | pw.print(sb); |
| 6516 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6517 | return true; |
| 6518 | } |
| 6519 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6520 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6521 | LevelStepTracker steps, boolean checkin) { |
| 6522 | if (steps == null) { |
| 6523 | return false; |
| 6524 | } |
| 6525 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6526 | if (count <= 0) { |
| 6527 | return false; |
| 6528 | } |
| 6529 | if (!checkin) { |
| 6530 | pw.println(header); |
| 6531 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6532 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6533 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6534 | long duration = steps.getDurationAt(i); |
| 6535 | int level = steps.getLevelAt(i); |
| 6536 | long initMode = steps.getInitModeAt(i); |
| 6537 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6538 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6539 | lineArgs[0] = Long.toString(duration); |
| 6540 | lineArgs[1] = Integer.toString(level); |
| 6541 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6542 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6543 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6544 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6545 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6546 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6547 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6548 | } |
| 6549 | } else { |
| 6550 | lineArgs[2] = ""; |
| 6551 | } |
| 6552 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6553 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6554 | } else { |
| 6555 | lineArgs[3] = ""; |
| 6556 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6557 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6558 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6559 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6560 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6561 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6562 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6563 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6564 | pw.print(prefix); |
| 6565 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6566 | TimeUtils.formatDuration(duration, pw); |
| 6567 | pw.print(" to "); pw.print(level); |
| 6568 | boolean haveModes = false; |
| 6569 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6570 | pw.print(" ("); |
| 6571 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6572 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6573 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6574 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6575 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6576 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6577 | } |
| 6578 | haveModes = true; |
| 6579 | } |
| 6580 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6581 | pw.print(haveModes ? ", " : " ("); |
| 6582 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6583 | ? "power-save-on" : "power-save-off"); |
| 6584 | haveModes = true; |
| 6585 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6586 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6587 | pw.print(haveModes ? ", " : " ("); |
| 6588 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6589 | ? "device-idle-on" : "device-idle-off"); |
| 6590 | haveModes = true; |
| 6591 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6592 | if (haveModes) { |
| 6593 | pw.print(")"); |
| 6594 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6595 | pw.println(); |
| 6596 | } |
| 6597 | } |
| 6598 | return true; |
| 6599 | } |
| 6600 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6601 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6602 | LevelStepTracker steps) { |
| 6603 | if (steps == null) { |
| 6604 | return; |
| 6605 | } |
| 6606 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6607 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6608 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6609 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6610 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6611 | |
| 6612 | final long initMode = steps.getInitModeAt(i); |
| 6613 | final long modMode = steps.getModModeAt(i); |
| 6614 | |
| 6615 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6616 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6617 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6618 | case Display.STATE_OFF: |
| 6619 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6620 | break; |
| 6621 | case Display.STATE_ON: |
| 6622 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6623 | break; |
| 6624 | case Display.STATE_DOZE: |
| 6625 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6626 | break; |
| 6627 | case Display.STATE_DOZE_SUSPEND: |
| 6628 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6629 | break; |
| 6630 | default: |
| 6631 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6632 | break; |
| 6633 | } |
| 6634 | } |
| 6635 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6636 | |
| 6637 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6638 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6639 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6640 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6641 | } |
| 6642 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6643 | |
| 6644 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6645 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6646 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6647 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6648 | } |
| 6649 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6650 | |
| 6651 | proto.end(token); |
| 6652 | } |
| 6653 | } |
| 6654 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6655 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6656 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6657 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6658 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6659 | public static final int DUMP_VERBOSE = 1<<5; |
| 6660 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6661 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6662 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6663 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6664 | final HistoryItem rec = new HistoryItem(); |
| 6665 | long lastTime = -1; |
| 6666 | long baseTime = -1; |
| 6667 | boolean printed = false; |
| 6668 | HistoryEventTracker tracker = null; |
| 6669 | while (getNextHistoryLocked(rec)) { |
| 6670 | lastTime = rec.time; |
| 6671 | if (baseTime < 0) { |
| 6672 | baseTime = lastTime; |
| 6673 | } |
| 6674 | if (rec.time >= histStart) { |
| 6675 | if (histStart >= 0 && !printed) { |
| 6676 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6677 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6678 | || rec.cmd == HistoryItem.CMD_START |
| 6679 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6680 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6681 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6682 | (flags&DUMP_VERBOSE) != 0); |
| 6683 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6684 | } else if (rec.currentTime != 0) { |
| 6685 | printed = true; |
| 6686 | byte cmd = rec.cmd; |
| 6687 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6688 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6689 | (flags&DUMP_VERBOSE) != 0); |
| 6690 | rec.cmd = cmd; |
| 6691 | } |
| 6692 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6693 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6694 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6695 | (flags&DUMP_VERBOSE) != 0); |
| 6696 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6697 | } |
| 6698 | int oldEventCode = rec.eventCode; |
| 6699 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6700 | rec.eventTag = new HistoryTag(); |
| 6701 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6702 | HashMap<String, SparseIntArray> active |
| 6703 | = tracker.getStateForEvent(i); |
| 6704 | if (active == null) { |
| 6705 | continue; |
| 6706 | } |
| 6707 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6708 | : active.entrySet()) { |
| 6709 | SparseIntArray uids = ent.getValue(); |
| 6710 | for (int j=0; j<uids.size(); j++) { |
| 6711 | rec.eventCode = i; |
| 6712 | rec.eventTag.string = ent.getKey(); |
| 6713 | rec.eventTag.uid = uids.keyAt(j); |
| 6714 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6715 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6716 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6717 | rec.wakeReasonTag = null; |
| 6718 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6719 | } |
| 6720 | } |
| 6721 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6722 | rec.eventCode = oldEventCode; |
| 6723 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6724 | tracker = null; |
| 6725 | } |
| 6726 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6727 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6728 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6729 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6730 | // This is an attempt to aggregate the previous state and generate |
| 6731 | //Â fake events to reflect that state at the point where we start |
| 6732 | // 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] | 6733 | if (tracker == null) { |
| 6734 | tracker = new HistoryEventTracker(); |
| 6735 | } |
| 6736 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6737 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6738 | } |
| 6739 | } |
| 6740 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6741 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6742 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6743 | } |
| 6744 | } |
| 6745 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6746 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6747 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6748 | if (steps == null) { |
| 6749 | return; |
| 6750 | } |
| 6751 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6752 | if (timeRemaining >= 0) { |
| 6753 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6754 | tmpSb.setLength(0); |
| 6755 | formatTimeMs(tmpSb, timeRemaining); |
| 6756 | pw.print(tmpSb); |
| 6757 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6758 | pw.println(" steps)"); |
| 6759 | } |
| 6760 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6761 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6762 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6763 | if (estimatedTime > 0) { |
| 6764 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6765 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6766 | pw.print(" time: "); |
| 6767 | tmpSb.setLength(0); |
| 6768 | formatTimeMs(tmpSb, estimatedTime); |
| 6769 | pw.print(tmpSb); |
| 6770 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6771 | pw.println(" steps)"); |
| 6772 | } |
| 6773 | } |
| 6774 | } |
| 6775 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6776 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6777 | ArrayList<PackageChange> changes) { |
| 6778 | if (changes == null) { |
| 6779 | return; |
| 6780 | } |
| 6781 | pw.print(prefix); pw.println("Package changes:"); |
| 6782 | for (int i=0; i<changes.size(); i++) { |
| 6783 | PackageChange pc = changes.get(i); |
| 6784 | if (pc.mUpdate) { |
| 6785 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6786 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6787 | } else { |
| 6788 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6789 | } |
| 6790 | } |
| 6791 | } |
| 6792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | /** |
| 6794 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6795 | * |
| 6796 | * @param pw a Printer to receive the dump output. |
| 6797 | */ |
| 6798 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6799 | 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] | 6800 | prepareForDumpLocked(); |
| 6801 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6802 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6803 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6804 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6805 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6806 | final long historyTotalSize = getHistoryTotalSize(); |
| 6807 | final long historyUsedSize = getHistoryUsedSize(); |
| 6808 | if (startIteratingHistoryLocked()) { |
| 6809 | try { |
| 6810 | pw.print("Battery History ("); |
| 6811 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6812 | pw.print("% used, "); |
| 6813 | printSizeValue(pw, historyUsedSize); |
| 6814 | pw.print(" used of "); |
| 6815 | printSizeValue(pw, historyTotalSize); |
| 6816 | pw.print(", "); |
| 6817 | pw.print(getHistoryStringPoolSize()); |
| 6818 | pw.print(" strings using "); |
| 6819 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6820 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6821 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6822 | pw.println(); |
| 6823 | } finally { |
| 6824 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6825 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | if (startIteratingOldHistoryLocked()) { |
| 6829 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6830 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6831 | pw.println("Old battery History:"); |
| 6832 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6833 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6834 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6835 | if (baseTime < 0) { |
| 6836 | baseTime = rec.time; |
| 6837 | } |
| 6838 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6839 | } |
| 6840 | pw.println(); |
| 6841 | } finally { |
| 6842 | finishIteratingOldHistoryLocked(); |
| 6843 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6844 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6845 | } |
| 6846 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6847 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6848 | return; |
| 6849 | } |
| 6850 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6851 | if (!filtering) { |
| 6852 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6853 | final int NU = uidStats.size(); |
| 6854 | boolean didPid = false; |
| 6855 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6856 | for (int i=0; i<NU; i++) { |
| 6857 | Uid uid = uidStats.valueAt(i); |
| 6858 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6859 | if (pids != null) { |
| 6860 | for (int j=0; j<pids.size(); j++) { |
| 6861 | Uid.Pid pid = pids.valueAt(j); |
| 6862 | if (!didPid) { |
| 6863 | pw.println("Per-PID Stats:"); |
| 6864 | didPid = true; |
| 6865 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6866 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6867 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6868 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6869 | pw.print(" wake time: "); |
| 6870 | TimeUtils.formatDuration(time, pw); |
| 6871 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6872 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6873 | } |
| 6874 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6875 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6876 | pw.println(); |
| 6877 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6878 | } |
| 6879 | |
| 6880 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6881 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6882 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6883 | long timeRemaining = computeBatteryTimeRemaining( |
| 6884 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6885 | if (timeRemaining >= 0) { |
| 6886 | pw.print(" Estimated discharge time remaining: "); |
| 6887 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6888 | pw.println(); |
| 6889 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6890 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6891 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6892 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6893 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6894 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6895 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6896 | pw.println(); |
| 6897 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6898 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6899 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6900 | long timeRemaining = computeChargeTimeRemaining( |
| 6901 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6902 | if (timeRemaining >= 0) { |
| 6903 | pw.print(" Estimated charge time remaining: "); |
| 6904 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6905 | pw.println(); |
| 6906 | } |
| 6907 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6908 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6909 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6910 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6911 | pw.println("Daily stats:"); |
| 6912 | pw.print(" Current start time: "); |
| 6913 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6914 | getCurrentDailyStartTime()).toString()); |
| 6915 | pw.print(" Next min deadline: "); |
| 6916 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6917 | getNextMinDailyDeadline()).toString()); |
| 6918 | pw.print(" Next max deadline: "); |
| 6919 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6920 | getNextMaxDailyDeadline()).toString()); |
| 6921 | StringBuilder sb = new StringBuilder(64); |
| 6922 | int[] outInt = new int[1]; |
| 6923 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6924 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6925 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6926 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6927 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6928 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6929 | dsteps, false)) { |
| 6930 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6931 | sb, outInt); |
| 6932 | } |
| 6933 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6934 | csteps, false)) { |
| 6935 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6936 | sb, outInt); |
| 6937 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6938 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6939 | } else { |
| 6940 | pw.println(" Current daily steps:"); |
| 6941 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6942 | sb, outInt); |
| 6943 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6944 | sb, outInt); |
| 6945 | } |
| 6946 | } |
| 6947 | DailyItem dit; |
| 6948 | int curIndex = 0; |
| 6949 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6950 | curIndex++; |
| 6951 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6952 | pw.println(); |
| 6953 | } |
| 6954 | pw.print(" Daily from "); |
| 6955 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6956 | pw.print(" to "); |
| 6957 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6958 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6959 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6960 | if (dumpDurationSteps(pw, " ", |
| 6961 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6962 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6963 | sb, outInt); |
| 6964 | } |
| 6965 | if (dumpDurationSteps(pw, " ", |
| 6966 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6967 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6968 | sb, outInt); |
| 6969 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6970 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6971 | } else { |
| 6972 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6973 | sb, outInt); |
| 6974 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6975 | sb, outInt); |
| 6976 | } |
| 6977 | } |
| 6978 | pw.println(); |
| 6979 | } |
| 6980 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6981 | pw.println("Statistics since last charge:"); |
| 6982 | pw.println(" System starts: " + getStartCount() |
| 6983 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6984 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6985 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6986 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6989 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6990 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6991 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6992 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6993 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6994 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6995 | |
| 6996 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6997 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6998 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6999 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 7000 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 7001 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7002 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 7003 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7004 | try { |
| 7005 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 7006 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 7007 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 7008 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7009 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7010 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7011 | pw.print(",\""); |
| 7012 | String str = getHistoryTagPoolString(i); |
| 7013 | str = str.replace("\\", "\\\\"); |
| 7014 | str = str.replace("\"", "\\\""); |
| 7015 | pw.print(str); |
| 7016 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7017 | pw.println(); |
| 7018 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7019 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7020 | } finally { |
| 7021 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7022 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 7023 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 7024 | } |
| 7025 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7026 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7027 | return; |
| 7028 | } |
| 7029 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7030 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7031 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7032 | for (int i=0; i<apps.size(); i++) { |
| 7033 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7034 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 7035 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7036 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7037 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 7038 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7039 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7040 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7041 | } |
| 7042 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7043 | final int NU = uidStats.size(); |
| 7044 | String[] lineArgs = new String[2]; |
| 7045 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7046 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 7047 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 7048 | if (pkgs != null && !pkgs.second.value) { |
| 7049 | pkgs.second.value = true; |
| 7050 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7051 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7052 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7053 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 7054 | (Object[])lineArgs); |
| 7055 | } |
| 7056 | } |
| 7057 | } |
| 7058 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7059 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7060 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7061 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 7062 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7063 | if (timeRemaining >= 0) { |
| 7064 | lineArgs[0] = Long.toString(timeRemaining); |
| 7065 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 7066 | (Object[])lineArgs); |
| 7067 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7068 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 7069 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7070 | if (timeRemaining >= 0) { |
| 7071 | lineArgs[0] = Long.toString(timeRemaining); |
| 7072 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 7073 | (Object[])lineArgs); |
| 7074 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7075 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 7076 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 7077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7079 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 7080 | /** |
| 7081 | * Dump #STATS_SINCE_CHARGED batterystats data to a proto. If the flags include |
| 7082 | * DUMP_INCLUDE_HISTORY or DUMP_HISTORY_ONLY, only the history will be dumped. |
| 7083 | * @hide |
| 7084 | */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7085 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 7086 | int flags, long histStart) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7087 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7088 | prepareForDumpLocked(); |
| 7089 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 7090 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
| 7091 | dumpProtoHistoryLocked(proto, flags, histStart); |
| 7092 | proto.flush(); |
| 7093 | return; |
| 7094 | } |
| 7095 | |
| 7096 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 7097 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7098 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 7099 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 7100 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 7101 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 7102 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 7103 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7104 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 7105 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 7106 | helper.create(this); |
| 7107 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 7108 | |
| 7109 | dumpProtoAppsLocked(proto, helper, apps); |
| 7110 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | proto.end(bToken); |
| 7114 | proto.flush(); |
| 7115 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7116 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7117 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 7118 | List<ApplicationInfo> apps) { |
| 7119 | final int which = STATS_SINCE_CHARGED; |
| 7120 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7121 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7122 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7123 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 7124 | |
| 7125 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 7126 | if (apps != null) { |
| 7127 | for (int i = 0; i < apps.size(); ++i) { |
| 7128 | ApplicationInfo ai = apps.get(i); |
| 7129 | int aid = UserHandle.getAppId(ai.uid); |
| 7130 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 7131 | if (pkgs == null) { |
| 7132 | pkgs = new ArrayList<String>(); |
| 7133 | aidToPackages.put(aid, pkgs); |
| 7134 | } |
| 7135 | pkgs.add(ai.packageName); |
| 7136 | } |
| 7137 | } |
| 7138 | |
| 7139 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 7140 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7141 | if (sippers != null) { |
| 7142 | for (int i = 0; i < sippers.size(); ++i) { |
| 7143 | final BatterySipper bs = sippers.get(i); |
| 7144 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 7145 | // Others are handled by dumpProtoSystemLocked() |
| 7146 | continue; |
| 7147 | } |
| 7148 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 7149 | } |
| 7150 | } |
| 7151 | |
| 7152 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7153 | final int n = uidStats.size(); |
| 7154 | for (int iu = 0; iu < n; ++iu) { |
| 7155 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 7156 | final Uid u = uidStats.valueAt(iu); |
| 7157 | |
| 7158 | final int uid = uidStats.keyAt(iu); |
| 7159 | proto.write(UidProto.UID, uid); |
| 7160 | |
| 7161 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 7162 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 7163 | if (pkgs == null) { |
| 7164 | pkgs = new ArrayList<String>(); |
| 7165 | } |
| 7166 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 7167 | u.getPackageStats(); |
| 7168 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7169 | String pkg = packageStats.keyAt(ipkg); |
| 7170 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 7171 | packageStats.valueAt(ipkg).getServiceStats(); |
| 7172 | if (serviceStats.size() == 0) { |
| 7173 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 7174 | // example, "android") may be included in the packageStats that aren't part of |
| 7175 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 7176 | // These packages won't be a part in the pkgs List. |
| 7177 | continue; |
| 7178 | } |
| 7179 | |
| 7180 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7181 | proto.write(UidProto.Package.NAME, pkg); |
| 7182 | // Remove from the packages list since we're logging it here. |
| 7183 | pkgs.remove(pkg); |
| 7184 | |
| 7185 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 7186 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
Kweku Adams | 14f3d22 | 2018-03-22 14:12:55 -0700 | [diff] [blame] | 7187 | |
| 7188 | final long startTimeMs = roundUsToMs(ss.getStartTime(batteryUptimeUs, which)); |
| 7189 | final int starts = ss.getStarts(which); |
| 7190 | final int launches = ss.getLaunches(which); |
| 7191 | if (startTimeMs == 0 && starts == 0 && launches == 0) { |
| 7192 | continue; |
| 7193 | } |
| 7194 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7195 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 7196 | |
| 7197 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
Kweku Adams | 14f3d22 | 2018-03-22 14:12:55 -0700 | [diff] [blame] | 7198 | proto.write(UidProto.Package.Service.START_DURATION_MS, startTimeMs); |
| 7199 | proto.write(UidProto.Package.Service.START_COUNT, starts); |
| 7200 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, launches); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7201 | |
| 7202 | proto.end(sToken); |
| 7203 | } |
| 7204 | proto.end(pToken); |
| 7205 | } |
| 7206 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 7207 | // from PackageManager data. Packages are only included in packageStats if there was |
| 7208 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 7209 | for (String p : pkgs) { |
| 7210 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7211 | proto.write(UidProto.Package.NAME, p); |
| 7212 | proto.end(pToken); |
| 7213 | } |
| 7214 | |
| 7215 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 7216 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 7217 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 7218 | // Times are since reset (regardless of 'which') |
| 7219 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 7220 | final Timer bgTimer = timer.getSubTimer(); |
| 7221 | final long bgTimeMs = bgTimer != null |
| 7222 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 7223 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 7224 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 7225 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 7226 | proto.end(awToken); |
| 7227 | } |
| 7228 | |
| 7229 | // Audio (AUDIO_DATA) |
| 7230 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7231 | |
| 7232 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7233 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7234 | u.getBluetoothControllerActivity(), which); |
| 7235 | |
| 7236 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7237 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7238 | if (bleTimer != null) { |
| 7239 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7240 | |
| 7241 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7242 | rawRealtimeUs, which); |
| 7243 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7244 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7245 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7246 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7247 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7248 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7249 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7250 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7251 | // Result counters |
| 7252 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7253 | u.getBluetoothScanResultCounter() != null |
| 7254 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7255 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7256 | u.getBluetoothScanResultBgCounter() != null |
| 7257 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7258 | |
| 7259 | proto.end(bmToken); |
| 7260 | } |
| 7261 | |
| 7262 | // Camera (CAMERA_DATA) |
| 7263 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7264 | |
| 7265 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7266 | final long cpuToken = proto.start(UidProto.CPU); |
| 7267 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7268 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7269 | |
| 7270 | final long[] cpuFreqs = getCpuFreqs(); |
| 7271 | if (cpuFreqs != null) { |
| 7272 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7273 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7274 | // screenOffCpuFreqTimes. |
| 7275 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7276 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7277 | if (screenOffCpuFreqTimeMs == null) { |
| 7278 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7279 | } |
| 7280 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7281 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7282 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7283 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7284 | cpuFreqTimeMs[ic]); |
| 7285 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7286 | screenOffCpuFreqTimeMs[ic]); |
| 7287 | proto.end(cToken); |
| 7288 | } |
| 7289 | } |
| 7290 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7291 | |
| 7292 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7293 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7294 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7295 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7296 | if (screenOffTimesMs == null) { |
| 7297 | screenOffTimesMs = new long[timesMs.length]; |
| 7298 | } |
| 7299 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7300 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7301 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7302 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7303 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7304 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7305 | timesMs[ic]); |
| 7306 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7307 | screenOffTimesMs[ic]); |
| 7308 | proto.end(cToken); |
| 7309 | } |
| 7310 | proto.end(procToken); |
| 7311 | } |
| 7312 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7313 | proto.end(cpuToken); |
| 7314 | |
| 7315 | // Flashlight (FLASHLIGHT_DATA) |
| 7316 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7317 | rawRealtimeUs, which); |
| 7318 | |
| 7319 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7320 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7321 | rawRealtimeUs, which); |
| 7322 | |
| 7323 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7324 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7325 | rawRealtimeUs, which); |
| 7326 | |
| 7327 | // Job completion (JOB_COMPLETION_DATA) |
| 7328 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7329 | final int[] reasons = new int[]{ |
| 7330 | JobParameters.REASON_CANCELED, |
| 7331 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7332 | JobParameters.REASON_PREEMPT, |
| 7333 | JobParameters.REASON_TIMEOUT, |
| 7334 | JobParameters.REASON_DEVICE_IDLE, |
| 7335 | }; |
| 7336 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7337 | SparseIntArray types = completions.valueAt(ic); |
| 7338 | if (types != null) { |
| 7339 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7340 | |
| 7341 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7342 | |
| 7343 | for (int r : reasons) { |
| 7344 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7345 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7346 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7347 | proto.end(rToken); |
| 7348 | } |
| 7349 | |
| 7350 | proto.end(jcToken); |
| 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | // Scheduled jobs (JOB_DATA) |
| 7355 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7356 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7357 | final Timer timer = jobs.valueAt(ij); |
| 7358 | final Timer bgTimer = timer.getSubTimer(); |
| 7359 | final long jToken = proto.start(UidProto.JOBS); |
| 7360 | |
| 7361 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7362 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7363 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7364 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7365 | |
| 7366 | proto.end(jToken); |
| 7367 | } |
| 7368 | |
| 7369 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7370 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7371 | u.getModemControllerActivity(), which); |
| 7372 | |
| 7373 | // Network stats (NETWORK_DATA) |
| 7374 | final long nToken = proto.start(UidProto.NETWORK); |
| 7375 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7376 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7377 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7378 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7379 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7380 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7381 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7382 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7383 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7384 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7385 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7386 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7387 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7388 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7389 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7390 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7391 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7392 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7393 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7394 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7395 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7396 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7397 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7398 | u.getMobileRadioActiveCount(which)); |
| 7399 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7400 | u.getMobileRadioApWakeupCount(which)); |
| 7401 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7402 | u.getWifiRadioApWakeupCount(which)); |
| 7403 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7404 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7405 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7406 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7407 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7408 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7409 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7410 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7411 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7412 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7413 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7414 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7415 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7416 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7417 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7418 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7419 | proto.end(nToken); |
| 7420 | |
| 7421 | // Power use item (POWER_USE_ITEM_DATA) |
| 7422 | BatterySipper bs = uidToSipper.get(uid); |
| 7423 | if (bs != null) { |
| 7424 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7425 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7426 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7427 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7428 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7429 | bs.proportionalSmearMah); |
| 7430 | proto.end(bsToken); |
| 7431 | } |
| 7432 | |
| 7433 | // Processes (PROCESS_DATA) |
| 7434 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7435 | u.getProcessStats(); |
| 7436 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7437 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7438 | final long prToken = proto.start(UidProto.PROCESS); |
| 7439 | |
| 7440 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7441 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7442 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7443 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7444 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7445 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7446 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7447 | |
| 7448 | proto.end(prToken); |
| 7449 | } |
| 7450 | |
| 7451 | // Sensors (SENSOR_DATA) |
| 7452 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7453 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7454 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7455 | final Timer timer = se.getSensorTime(); |
| 7456 | if (timer == null) { |
| 7457 | continue; |
| 7458 | } |
| 7459 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7460 | final int sensorNumber = sensors.keyAt(ise); |
| 7461 | final long seToken = proto.start(UidProto.SENSORS); |
| 7462 | |
| 7463 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7464 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7465 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7466 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7467 | |
| 7468 | proto.end(seToken); |
| 7469 | } |
| 7470 | |
| 7471 | // State times (STATE_TIME_DATA) |
| 7472 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7473 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7474 | if (durMs == 0) { |
| 7475 | continue; |
| 7476 | } |
| 7477 | final long stToken = proto.start(UidProto.STATES); |
| 7478 | proto.write(UidProto.StateTime.STATE, ips); |
| 7479 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7480 | proto.end(stToken); |
| 7481 | } |
| 7482 | |
| 7483 | // Syncs (SYNC_DATA) |
| 7484 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7485 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7486 | final Timer timer = syncs.valueAt(isy); |
| 7487 | final Timer bgTimer = timer.getSubTimer(); |
| 7488 | final long syToken = proto.start(UidProto.SYNCS); |
| 7489 | |
| 7490 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7491 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7492 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7493 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7494 | |
| 7495 | proto.end(syToken); |
| 7496 | } |
| 7497 | |
| 7498 | // User activity (USER_ACTIVITY_DATA) |
| 7499 | if (u.hasUserActivity()) { |
| 7500 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7501 | int val = u.getUserActivityCount(i, which); |
| 7502 | if (val != 0) { |
| 7503 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7504 | proto.write(UidProto.UserActivity.NAME, i); |
| 7505 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7506 | proto.end(uaToken); |
| 7507 | } |
| 7508 | } |
| 7509 | } |
| 7510 | |
| 7511 | // Vibrator (VIBRATOR_DATA) |
| 7512 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7513 | |
| 7514 | // Video (VIDEO_DATA) |
| 7515 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7516 | |
| 7517 | // Wakelocks (WAKELOCK_DATA) |
| 7518 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7519 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7520 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7521 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7522 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7523 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7524 | rawRealtimeUs, which); |
| 7525 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7526 | if (pTimer != null) { |
| 7527 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7528 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7529 | rawRealtimeUs, which); |
| 7530 | } |
| 7531 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7532 | rawRealtimeUs, which); |
| 7533 | proto.end(wToken); |
| 7534 | } |
| 7535 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7536 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7537 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7538 | rawRealtimeUs, which); |
| 7539 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7540 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7541 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7542 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7543 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7544 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7545 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7546 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7547 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7548 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7549 | proto.end(waToken); |
| 7550 | } |
| 7551 | } |
| 7552 | |
| 7553 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7554 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7555 | u.getWifiControllerActivity(), which); |
| 7556 | |
| 7557 | // Wifi data (WIFI_DATA) |
| 7558 | final long wToken = proto.start(UidProto.WIFI); |
| 7559 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7560 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7561 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7562 | rawRealtimeUs, which); |
| 7563 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7564 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7565 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7566 | rawRealtimeUs, which); |
| 7567 | proto.end(wToken); |
| 7568 | |
| 7569 | proto.end(uTkn); |
| 7570 | } |
| 7571 | } |
| 7572 | |
Kweku Adams | 71a9531 | 2018-04-16 16:54:24 -0700 | [diff] [blame] | 7573 | private void dumpProtoHistoryLocked(ProtoOutputStream proto, int flags, long histStart) { |
| 7574 | if (!startIteratingHistoryLocked()) { |
| 7575 | return; |
| 7576 | } |
| 7577 | |
| 7578 | proto.write(BatteryStatsServiceDumpHistoryProto.REPORT_VERSION, CHECKIN_VERSION); |
| 7579 | proto.write(BatteryStatsServiceDumpHistoryProto.PARCEL_VERSION, getParcelVersion()); |
| 7580 | proto.write(BatteryStatsServiceDumpHistoryProto.START_PLATFORM_VERSION, |
| 7581 | getStartPlatformVersion()); |
| 7582 | proto.write(BatteryStatsServiceDumpHistoryProto.END_PLATFORM_VERSION, |
| 7583 | getEndPlatformVersion()); |
| 7584 | try { |
| 7585 | long token; |
| 7586 | // History string pool (HISTORY_STRING_POOL) |
| 7587 | for (int i = 0; i < getHistoryStringPoolSize(); ++i) { |
| 7588 | token = proto.start(BatteryStatsServiceDumpHistoryProto.KEYS); |
| 7589 | proto.write(BatteryStatsServiceDumpHistoryProto.Key.INDEX, i); |
| 7590 | proto.write(BatteryStatsServiceDumpHistoryProto.Key.UID, getHistoryTagPoolUid(i)); |
| 7591 | proto.write(BatteryStatsServiceDumpHistoryProto.Key.TAG, |
| 7592 | getHistoryTagPoolString(i)); |
| 7593 | proto.end(token); |
| 7594 | } |
| 7595 | |
| 7596 | // History data (HISTORY_DATA) |
| 7597 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 7598 | final HistoryItem rec = new HistoryItem(); |
| 7599 | long lastTime = -1; |
| 7600 | long baseTime = -1; |
| 7601 | boolean printed = false; |
| 7602 | HistoryEventTracker tracker = null; |
| 7603 | while (getNextHistoryLocked(rec)) { |
| 7604 | lastTime = rec.time; |
| 7605 | if (baseTime < 0) { |
| 7606 | baseTime = lastTime; |
| 7607 | } |
| 7608 | if (rec.time >= histStart) { |
| 7609 | if (histStart >= 0 && !printed) { |
| 7610 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 7611 | || rec.cmd == HistoryItem.CMD_RESET |
| 7612 | || rec.cmd == HistoryItem.CMD_START |
| 7613 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 7614 | printed = true; |
| 7615 | hprinter.printNextItem(proto, rec, baseTime, |
| 7616 | (flags & DUMP_VERBOSE) != 0); |
| 7617 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 7618 | } else if (rec.currentTime != 0) { |
| 7619 | printed = true; |
| 7620 | byte cmd = rec.cmd; |
| 7621 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
| 7622 | hprinter.printNextItem(proto, rec, baseTime, |
| 7623 | (flags & DUMP_VERBOSE) != 0); |
| 7624 | rec.cmd = cmd; |
| 7625 | } |
| 7626 | if (tracker != null) { |
| 7627 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 7628 | hprinter.printNextItem(proto, rec, baseTime, |
| 7629 | (flags & DUMP_VERBOSE) != 0); |
| 7630 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 7631 | } |
| 7632 | int oldEventCode = rec.eventCode; |
| 7633 | HistoryTag oldEventTag = rec.eventTag; |
| 7634 | rec.eventTag = new HistoryTag(); |
| 7635 | for (int i = 0; i < HistoryItem.EVENT_COUNT; i++) { |
| 7636 | HashMap<String, SparseIntArray> active = |
| 7637 | tracker.getStateForEvent(i); |
| 7638 | if (active == null) { |
| 7639 | continue; |
| 7640 | } |
| 7641 | for (HashMap.Entry<String, SparseIntArray> ent |
| 7642 | : active.entrySet()) { |
| 7643 | SparseIntArray uids = ent.getValue(); |
| 7644 | for (int j = 0; j < uids.size(); j++) { |
| 7645 | rec.eventCode = i; |
| 7646 | rec.eventTag.string = ent.getKey(); |
| 7647 | rec.eventTag.uid = uids.keyAt(j); |
| 7648 | rec.eventTag.poolIdx = uids.valueAt(j); |
| 7649 | hprinter.printNextItem(proto, rec, baseTime, |
| 7650 | (flags & DUMP_VERBOSE) != 0); |
| 7651 | rec.wakeReasonTag = null; |
| 7652 | rec.wakelockTag = null; |
| 7653 | } |
| 7654 | } |
| 7655 | } |
| 7656 | rec.eventCode = oldEventCode; |
| 7657 | rec.eventTag = oldEventTag; |
| 7658 | tracker = null; |
| 7659 | } |
| 7660 | } |
| 7661 | hprinter.printNextItem(proto, rec, baseTime, |
| 7662 | (flags & DUMP_VERBOSE) != 0); |
| 7663 | } |
| 7664 | } |
| 7665 | if (histStart >= 0) { |
| 7666 | commitCurrentHistoryBatchLocked(); |
| 7667 | proto.write(BatteryStatsServiceDumpHistoryProto.CSV_LINES, |
| 7668 | "NEXT: " + (lastTime + 1)); |
| 7669 | } |
| 7670 | } finally { |
| 7671 | finishIteratingHistoryLocked(); |
| 7672 | } |
| 7673 | } |
| 7674 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7675 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7676 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7677 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7678 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7679 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7680 | final int which = STATS_SINCE_CHARGED; |
| 7681 | |
| 7682 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7683 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7684 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7685 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7686 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7687 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7688 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7689 | computeUptime(rawUptimeUs, which) / 1000); |
| 7690 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7691 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7692 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7693 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7694 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7695 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7696 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7697 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7698 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7699 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7700 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7701 | getEstimatedBatteryCapacity()); |
| 7702 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7703 | getMinLearnedBatteryCapacity()); |
| 7704 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7705 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7706 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7707 | |
| 7708 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7709 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7710 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7711 | getLowDischargeAmountSinceCharge()); |
| 7712 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7713 | getHighDischargeAmountSinceCharge()); |
| 7714 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7715 | getDischargeAmountScreenOnSinceCharge()); |
| 7716 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7717 | getDischargeAmountScreenOffSinceCharge()); |
| 7718 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7719 | getDischargeAmountScreenDozeSinceCharge()); |
| 7720 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7721 | getUahDischarge(which) / 1000); |
| 7722 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7723 | getUahDischargeScreenOff(which) / 1000); |
| 7724 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7725 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7726 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7727 | getUahDischargeLightDoze(which) / 1000); |
| 7728 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7729 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7730 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7731 | |
| 7732 | // Time remaining |
| 7733 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7734 | // These are part of a oneof, so we should only set one of them. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7735 | if (timeRemainingUs >= 0) { |
| 7736 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7737 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7738 | } else { |
| 7739 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7740 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7741 | if (timeRemainingUs >= 0) { |
| 7742 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7743 | } else { |
| 7744 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7745 | } |
| 7746 | } |
| 7747 | |
| 7748 | // Charge step (CHARGE_STEP_DATA) |
| 7749 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7750 | |
| 7751 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7752 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 7753 | // Map OTHER to TelephonyManager.NETWORK_TYPE_UNKNOWN and mark NONE as a boolean. |
| 7754 | boolean isNone = (i == DATA_CONNECTION_NONE); |
| 7755 | int telephonyNetworkType = i; |
| 7756 | if (i == DATA_CONNECTION_OTHER) { |
| 7757 | telephonyNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 7758 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7759 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 7760 | if (isNone) { |
| 7761 | proto.write(SystemProto.DataConnection.IS_NONE, isNone); |
| 7762 | } else { |
| 7763 | proto.write(SystemProto.DataConnection.NAME, telephonyNetworkType); |
| 7764 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7765 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7766 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7767 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7771 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7772 | |
| 7773 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7774 | final long[] cpuFreqs = getCpuFreqs(); |
| 7775 | if (cpuFreqs != null) { |
| 7776 | for (long i : cpuFreqs) { |
| 7777 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7778 | } |
| 7779 | } |
| 7780 | |
| 7781 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7782 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7783 | getBluetoothControllerActivity(), which); |
| 7784 | |
| 7785 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7786 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7787 | getModemControllerActivity(), which); |
| 7788 | |
| 7789 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7790 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7791 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7792 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7793 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7794 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7795 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7796 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7797 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7798 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7799 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7800 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7801 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7802 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7803 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7804 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7805 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7806 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7807 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7808 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7809 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7810 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7811 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7812 | |
| 7813 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7814 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7815 | getWifiControllerActivity(), which); |
| 7816 | |
| 7817 | |
| 7818 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7819 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7820 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7821 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7822 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7823 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7824 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7825 | |
| 7826 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7827 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7828 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7829 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7830 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7831 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7832 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7833 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | // Misc (MISC_DATA) |
| 7837 | // Calculate wakelock times across all uids. |
| 7838 | long fullWakeLockTimeTotalUs = 0; |
| 7839 | long partialWakeLockTimeTotalUs = 0; |
| 7840 | |
| 7841 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7842 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7843 | final Uid u = uidStats.valueAt(iu); |
| 7844 | |
| 7845 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7846 | u.getWakelockStats(); |
| 7847 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7848 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7849 | |
| 7850 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7851 | if (fullWakeTimer != null) { |
| 7852 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7853 | which); |
| 7854 | } |
| 7855 | |
| 7856 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7857 | if (partialWakeTimer != null) { |
| 7858 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7859 | rawRealtimeUs, which); |
| 7860 | } |
| 7861 | } |
| 7862 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7863 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7864 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7865 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7866 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7867 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7868 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7869 | fullWakeLockTimeTotalUs / 1000); |
| 7870 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7871 | partialWakeLockTimeTotalUs / 1000); |
| 7872 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7873 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7874 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7875 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7876 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7877 | getMobileRadioActiveCount(which)); |
| 7878 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7879 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7880 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7881 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7882 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7883 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7884 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7885 | getNumConnectivityChange(which)); |
| 7886 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7887 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7888 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7889 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7890 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7891 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7892 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7893 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7894 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7895 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7896 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7897 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7898 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7899 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7900 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7901 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7902 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7903 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7904 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7905 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7906 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7907 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7908 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7909 | final long multicastWakeLockTimeTotalUs = |
| 7910 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7911 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7912 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7913 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7914 | multicastWakeLockTimeTotalUs / 1000); |
| 7915 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7916 | multicastWakeLockCountTotal); |
| 7917 | proto.end(wmctToken); |
| 7918 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7919 | // Power use item (POWER_USE_ITEM_DATA) |
| 7920 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7921 | if (sippers != null) { |
| 7922 | for (int i = 0; i < sippers.size(); ++i) { |
| 7923 | final BatterySipper bs = sippers.get(i); |
| 7924 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7925 | int uid = 0; |
| 7926 | switch (bs.drainType) { |
Kweku Adams | ef72895 | 2018-04-10 17:56:16 -0700 | [diff] [blame] | 7927 | case AMBIENT_DISPLAY: |
| 7928 | n = SystemProto.PowerUseItem.AMBIENT_DISPLAY; |
| 7929 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7930 | case IDLE: |
| 7931 | n = SystemProto.PowerUseItem.IDLE; |
| 7932 | break; |
| 7933 | case CELL: |
| 7934 | n = SystemProto.PowerUseItem.CELL; |
| 7935 | break; |
| 7936 | case PHONE: |
| 7937 | n = SystemProto.PowerUseItem.PHONE; |
| 7938 | break; |
| 7939 | case WIFI: |
| 7940 | n = SystemProto.PowerUseItem.WIFI; |
| 7941 | break; |
| 7942 | case BLUETOOTH: |
| 7943 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7944 | break; |
| 7945 | case SCREEN: |
| 7946 | n = SystemProto.PowerUseItem.SCREEN; |
| 7947 | break; |
| 7948 | case FLASHLIGHT: |
| 7949 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7950 | break; |
| 7951 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7952 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7953 | continue; |
| 7954 | case USER: |
| 7955 | n = SystemProto.PowerUseItem.USER; |
| 7956 | uid = UserHandle.getUid(bs.userId, 0); |
| 7957 | break; |
| 7958 | case UNACCOUNTED: |
| 7959 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7960 | break; |
| 7961 | case OVERCOUNTED: |
| 7962 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7963 | break; |
| 7964 | case CAMERA: |
| 7965 | n = SystemProto.PowerUseItem.CAMERA; |
| 7966 | break; |
| 7967 | case MEMORY: |
| 7968 | n = SystemProto.PowerUseItem.MEMORY; |
| 7969 | break; |
| 7970 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7971 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7972 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7973 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7974 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7975 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7976 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7977 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7978 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7979 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7984 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7985 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7986 | helper.getPowerProfile().getBatteryCapacity()); |
| 7987 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7988 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7989 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7990 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7991 | |
| 7992 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7993 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7994 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7995 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7996 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7997 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7998 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7999 | ent.getValue(), rawRealtimeUs, which); |
| 8000 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 8001 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8002 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 8006 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8007 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8008 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 8009 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 8010 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8011 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8012 | } |
| 8013 | |
| 8014 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 8015 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 8016 | which); |
| 8017 | |
| 8018 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 8019 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8020 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8021 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 8022 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 8023 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8024 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8025 | } |
| 8026 | |
| 8027 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 8028 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 8029 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8030 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8031 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 8032 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8033 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 8037 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8038 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8039 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 8040 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 8041 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8042 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8043 | } |
| 8044 | |
| 8045 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 8046 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8047 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8048 | proto.write(SystemProto.WifiState.NAME, i); |
| 8049 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 8050 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8051 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8052 | } |
| 8053 | |
| 8054 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 8055 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8056 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8057 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 8058 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 8059 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 8060 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 8061 | } |
| 8062 | |
| 8063 | proto.end(sToken); |
| 8064 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8065 | } |