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 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 20 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 22 | import android.content.pm.ApplicationInfo; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 23 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 24 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 25 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 26 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 27 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 28 | import android.util.MutableBoolean; |
| 29 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.util.Printer; |
| 31 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 32 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 33 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 34 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 35 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 36 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 37 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 38 | import com.android.internal.os.BatterySipper; |
| 39 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 41 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 42 | import java.io.PrintWriter; |
| 43 | import java.util.ArrayList; |
| 44 | import java.util.Collections; |
| 45 | import java.util.Comparator; |
| 46 | import java.util.Formatter; |
| 47 | import java.util.HashMap; |
| 48 | import java.util.List; |
| 49 | import java.util.Map; |
| 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | /** |
| 52 | * A class providing access to battery usage statistics, including information on |
| 53 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 54 | * except where indicated otherwise. |
| 55 | * @hide |
| 56 | */ |
| 57 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 58 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 61 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 62 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 63 | |
| 64 | /** @hide */ |
| 65 | public static final String SERVICE_NAME = "batterystats"; |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | /** |
| 68 | * A constant indicating a partial wake lock timer. |
| 69 | */ |
| 70 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 71 | |
| 72 | /** |
| 73 | * A constant indicating a full wake lock timer. |
| 74 | */ |
| 75 | public static final int WAKE_TYPE_FULL = 1; |
| 76 | |
| 77 | /** |
| 78 | * A constant indicating a window wake lock timer. |
| 79 | */ |
| 80 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | /** |
| 83 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | */ |
| 85 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 86 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 87 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 88 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 89 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 90 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 91 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 92 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 93 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 94 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 95 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 96 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 97 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 98 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 99 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 100 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 102 | /** |
| 103 | * A constant indicating a wifi multicast timer |
| 104 | */ |
| 105 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 108 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 109 | */ |
| 110 | public static final int VIDEO_TURNED_ON = 8; |
| 111 | |
| 112 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 113 | * A constant indicating a vibrator on timer |
| 114 | */ |
| 115 | public static final int VIBRATOR_ON = 9; |
| 116 | |
| 117 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 118 | * A constant indicating a foreground activity timer |
| 119 | */ |
| 120 | public static final int FOREGROUND_ACTIVITY = 10; |
| 121 | |
| 122 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 123 | * A constant indicating a wifi batched scan is active |
| 124 | */ |
| 125 | public static final int WIFI_BATCHED_SCAN = 11; |
| 126 | |
| 127 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 128 | * A constant indicating a process state timer |
| 129 | */ |
| 130 | public static final int PROCESS_STATE = 12; |
| 131 | |
| 132 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 133 | * A constant indicating a sync timer |
| 134 | */ |
| 135 | public static final int SYNC = 13; |
| 136 | |
| 137 | /** |
| 138 | * A constant indicating a job timer |
| 139 | */ |
| 140 | public static final int JOB = 14; |
| 141 | |
| 142 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 143 | * A constant indicating an audio turn on timer |
| 144 | */ |
| 145 | public static final int AUDIO_TURNED_ON = 15; |
| 146 | |
| 147 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 148 | * A constant indicating a flashlight turn on timer |
| 149 | */ |
| 150 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 151 | |
| 152 | /** |
| 153 | * A constant indicating a camera turn on timer |
| 154 | */ |
| 155 | public static final int CAMERA_TURNED_ON = 17; |
| 156 | |
| 157 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 158 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 159 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 160 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 163 | * A constant indicating a bluetooth scan timer. |
| 164 | */ |
| 165 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 166 | |
| 167 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 168 | * A constant indicating an aggregated partial wake lock timer. |
| 169 | */ |
| 170 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 171 | |
| 172 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 173 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 174 | */ |
| 175 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 176 | |
| 177 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 178 | * A constant indicating a foreground service timer |
| 179 | */ |
| 180 | public static final int FOREGROUND_SERVICE = 22; |
| 181 | |
| 182 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 183 | * A constant indicating an aggregate wifi multicast timer |
| 184 | */ |
| 185 | public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; |
| 186 | |
| 187 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | * Include all of the data in the stats, including previously saved data. |
| 189 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 190 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | |
| 192 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | * Include only the current run in the stats. |
| 194 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 195 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Include only the run since the last time the device was unplugged in the stats. |
| 199 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 200 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 201 | |
| 202 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 203 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 204 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 205 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 208 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 209 | * |
| 210 | * New in version 19: |
| 211 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 212 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 213 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 214 | * New in version 21: |
| 215 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 216 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 217 | * - BLE scan result count |
| 218 | * - CPU frequency time per uid |
| 219 | * New in version 22: |
| 220 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 221 | * - Background partial wakelock time & count |
| 222 | * New in version 23: |
| 223 | * - Logging smeared power model values |
| 224 | * New in version 24: |
| 225 | * - Fixed bugs in background timers and BLE scan time |
| 226 | * New in version 25: |
| 227 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 228 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 229 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 230 | * New in version 27: |
| 231 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 232 | * New in version 28: |
| 233 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 234 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 235 | * New in version 29: |
| 236 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 237 | * - CPU times per UID process state |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame^] | 238 | * New in version 30: |
| 239 | * - Uid.PROCESS_STATE_FOREGROUND_SERVICE only tracks |
| 240 | * ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 241 | */ |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame^] | 242 | static final int CHECKIN_VERSION = 30; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * 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] | 246 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 247 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 248 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 249 | private static final long BYTES_PER_KB = 1024; |
| 250 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 251 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 252 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 253 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 254 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 255 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 257 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 258 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 259 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 260 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 261 | // rpm line is: |
| 262 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 263 | // screen-off time, screen-off count |
| 264 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 265 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 266 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 267 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 268 | // fgs line is: |
| 269 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 270 | // foreground service time, count |
| 271 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 272 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 273 | // wl line is: |
| 274 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 275 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 276 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 277 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 278 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 279 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 280 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 281 | // awl line is: |
| 282 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 283 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 284 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 285 | private static final String SYNC_DATA = "sy"; |
| 286 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 287 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 288 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 289 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 290 | private static final String NETWORK_DATA = "nt"; |
| 291 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 292 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 293 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 294 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 295 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 296 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 297 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 298 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 299 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 300 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 301 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 302 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 303 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 304 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 305 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 306 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 307 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 308 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 309 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 310 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 311 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 312 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 313 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 314 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 315 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 316 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 317 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 318 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 319 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 320 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 321 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 322 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 323 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 324 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 325 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 326 | private static final String FLASHLIGHT_DATA = "fla"; |
| 327 | private static final String CAMERA_DATA = "cam"; |
| 328 | private static final String VIDEO_DATA = "vid"; |
| 329 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 330 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 331 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 333 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 334 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 335 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 337 | |
| 338 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 339 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 340 | * |
| 341 | * Other types might include times spent in foreground, background etc. |
| 342 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 343 | @VisibleForTesting |
| 344 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 345 | |
| 346 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 347 | * State for keeping track of counting information. |
| 348 | */ |
| 349 | public static abstract class Counter { |
| 350 | |
| 351 | /** |
| 352 | * Returns the count associated with this Counter for the |
| 353 | * selected type of statistics. |
| 354 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 355 | * @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] | 356 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 357 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 358 | |
| 359 | /** |
| 360 | * Temporary for debugging. |
| 361 | */ |
| 362 | public abstract void logState(Printer pw, String prefix); |
| 363 | } |
| 364 | |
| 365 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 366 | * State for keeping track of long counting information. |
| 367 | */ |
| 368 | public static abstract class LongCounter { |
| 369 | |
| 370 | /** |
| 371 | * Returns the count associated with this Counter for the |
| 372 | * selected type of statistics. |
| 373 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 374 | * @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] | 375 | */ |
| 376 | public abstract long getCountLocked(int which); |
| 377 | |
| 378 | /** |
| 379 | * Temporary for debugging. |
| 380 | */ |
| 381 | public abstract void logState(Printer pw, String prefix); |
| 382 | } |
| 383 | |
| 384 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 385 | * State for keeping track of array of long counting information. |
| 386 | */ |
| 387 | public static abstract class LongCounterArray { |
| 388 | /** |
| 389 | * Returns the counts associated with this Counter for the |
| 390 | * selected type of statistics. |
| 391 | * |
| 392 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 393 | */ |
| 394 | public abstract long[] getCountsLocked(int which); |
| 395 | |
| 396 | /** |
| 397 | * Temporary for debugging. |
| 398 | */ |
| 399 | public abstract void logState(Printer pw, String prefix); |
| 400 | } |
| 401 | |
| 402 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 403 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 404 | * radio controller. |
| 405 | */ |
| 406 | public static abstract class ControllerActivityCounter { |
| 407 | /** |
| 408 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 409 | * idle state. |
| 410 | */ |
| 411 | public abstract LongCounter getIdleTimeCounter(); |
| 412 | |
| 413 | /** |
| 414 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 415 | * receive state. |
| 416 | */ |
| 417 | public abstract LongCounter getRxTimeCounter(); |
| 418 | |
| 419 | /** |
| 420 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 421 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 422 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 423 | * various transmit level states. |
| 424 | */ |
| 425 | public abstract LongCounter[] getTxTimeCounters(); |
| 426 | |
| 427 | /** |
| 428 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 429 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 430 | * yield a value of 0 if the device doesn't support power calculations. |
| 431 | */ |
| 432 | public abstract LongCounter getPowerCounter(); |
| 433 | } |
| 434 | |
| 435 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | * State for keeping track of timing information. |
| 437 | */ |
| 438 | public static abstract class Timer { |
| 439 | |
| 440 | /** |
| 441 | * Returns the count associated with this Timer for the |
| 442 | * selected type of statistics. |
| 443 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 444 | * @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] | 445 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 446 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | |
| 448 | /** |
| 449 | * Returns the total time in microseconds associated with this Timer for the |
| 450 | * selected type of statistics. |
| 451 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 452 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 453 | * @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] | 454 | * @return a time in microseconds |
| 455 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 456 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 459 | * Returns the total time in microseconds associated with this Timer since the |
| 460 | * 'mark' was last set. |
| 461 | * |
| 462 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 463 | * @return a time in microseconds |
| 464 | */ |
| 465 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 466 | |
| 467 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 468 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 469 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 470 | */ |
| 471 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 472 | return -1; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * 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] | 477 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 478 | */ |
| 479 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 480 | return -1; |
| 481 | } |
| 482 | |
| 483 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 484 | * 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] | 485 | * |
| 486 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 487 | * been on since reset. |
| 488 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 489 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 490 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 491 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 492 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 493 | */ |
| 494 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 495 | return -1; |
| 496 | } |
| 497 | |
| 498 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 499 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 500 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 501 | * |
| 502 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 503 | */ |
| 504 | public Timer getSubTimer() { |
| 505 | return null; |
| 506 | } |
| 507 | |
| 508 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 509 | * Returns whether the timer is currently running. Some types of timers |
| 510 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 511 | * and report false. |
| 512 | */ |
| 513 | public boolean isRunningLocked() { |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | * Temporary for debugging. |
| 519 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 520 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 524 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 525 | */ |
| 526 | public static int mapToInternalProcessState(int procState) { |
| 527 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 528 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 529 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 530 | return Uid.PROCESS_STATE_TOP; |
Dianne Hackborn | 10fc4fd | 2017-12-19 17:23:13 -0800 | [diff] [blame] | 531 | } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 532 | // State when app has put itself in the foreground. |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 533 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 534 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 535 | // Persistent and other foreground states go here. |
| 536 | return Uid.PROCESS_STATE_FOREGROUND; |
| 537 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 538 | return Uid.PROCESS_STATE_BACKGROUND; |
| 539 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 540 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 541 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 542 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 543 | } else { |
| 544 | return Uid.PROCESS_STATE_CACHED; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | * The statistics associated with a particular uid. |
| 550 | */ |
| 551 | public static abstract class Uid { |
| 552 | |
| 553 | /** |
| 554 | * Returns a mapping containing wakelock statistics. |
| 555 | * |
| 556 | * @return a Map from Strings to Uid.Wakelock objects. |
| 557 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 558 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | |
| 560 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 561 | * Returns the WiFi Multicast Wakelock statistics. |
| 562 | * |
| 563 | * @return a Timer Object for the per uid Multicast statistics. |
| 564 | */ |
| 565 | public abstract Timer getMulticastWakelockStats(); |
| 566 | |
| 567 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 568 | * Returns a mapping containing sync statistics. |
| 569 | * |
| 570 | * @return a Map from Strings to Timer objects. |
| 571 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 572 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * Returns a mapping containing scheduled job statistics. |
| 576 | * |
| 577 | * @return a Map from Strings to Timer objects. |
| 578 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 579 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 580 | |
| 581 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 582 | * Returns statistics about how jobs have completed. |
| 583 | * |
| 584 | * @return A Map of String job names to completion type -> count mapping. |
| 585 | */ |
| 586 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 587 | |
| 588 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | * The statistics associated with a particular wake lock. |
| 590 | */ |
| 591 | public static abstract class Wakelock { |
| 592 | public abstract Timer getWakeTime(int type); |
| 593 | } |
| 594 | |
| 595 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 596 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 597 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 598 | * wakelocks that overlap in time (and therefore over-counts). |
| 599 | */ |
| 600 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 601 | |
| 602 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | * Returns a mapping containing sensor statistics. |
| 604 | * |
| 605 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 606 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 607 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | |
| 609 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 610 | * Returns a mapping containing active process data. |
| 611 | */ |
| 612 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 613 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 614 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | * Returns a mapping containing process statistics. |
| 616 | * |
| 617 | * @return a Map from Strings to Uid.Proc objects. |
| 618 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 619 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | |
| 621 | /** |
| 622 | * Returns a mapping containing package statistics. |
| 623 | * |
| 624 | * @return a Map from Strings to Uid.Pkg objects. |
| 625 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 626 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 627 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 628 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 629 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 630 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 631 | |
| 632 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | * {@hide} |
| 634 | */ |
| 635 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 636 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 637 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 638 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 639 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 640 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 641 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 642 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 643 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 644 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 645 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 646 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 647 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 648 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 649 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 650 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 651 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 652 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 653 | /** |
| 654 | * Returns the timer keeping track of wifi scans. |
| 655 | */ |
| 656 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 657 | public abstract int getWifiScanBackgroundCount(int which); |
| 658 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 659 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 660 | /** |
| 661 | * Returns the timer keeping track of background wifi scans. |
| 662 | */ |
| 663 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 664 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 665 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 666 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 667 | public abstract Timer getAudioTurnedOnTimer(); |
| 668 | public abstract Timer getVideoTurnedOnTimer(); |
| 669 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 670 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 671 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * Returns the timer keeping track of Foreground Service time |
| 675 | */ |
| 676 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 677 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 678 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 679 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 680 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 681 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 682 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 683 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 684 | public abstract long[] getCpuFreqTimes(int which); |
| 685 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 686 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 687 | /** |
| 688 | * Returns cpu times of an uid at a particular process state. |
| 689 | */ |
| 690 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 691 | /** |
| 692 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 693 | */ |
| 694 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 695 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 696 | // Note: the following times are disjoint. They can be added together to find the |
| 697 | // total time a uid has had any processes running at all. |
| 698 | |
| 699 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame^] | 700 | * Time this uid has any processes in the top state. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 701 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 702 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 703 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame^] | 704 | * Time this uid has any process with a started foreground service, but |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 705 | * none in the "top" state. |
| 706 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 707 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 708 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 709 | * 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^] | 710 | * "foreground service" or better state. Persistent and other foreground states go here. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 711 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 712 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 713 | /** |
| 714 | * Time this uid has any process in an active background state, but none in the |
| 715 | * "foreground" or better state. |
| 716 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 717 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 718 | /** |
| 719 | * Time this uid has any process that is top while the device is sleeping, but not |
| 720 | * active for any other reason. We kind-of consider it a kind of cached process |
| 721 | * for execution restrictions. |
| 722 | */ |
| 723 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 724 | /** |
| 725 | * Time this uid has any process that is in the background but it has an activity |
| 726 | * marked as "can't save state". This is essentially a cached process, though the |
| 727 | * system will try much harder than normal to avoid killing it. |
| 728 | */ |
| 729 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 730 | /** |
| 731 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 732 | * other active states. |
| 733 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 734 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 735 | /** |
| 736 | * Total number of process states we track. |
| 737 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 738 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 739 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 740 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 741 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 742 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 743 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 744 | }; |
| 745 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 746 | // Used in checkin dump |
| 747 | @VisibleForTesting |
| 748 | public static final String[] UID_PROCESS_TYPES = { |
| 749 | "T", // TOP |
| 750 | "FS", // FOREGROUND_SERVICE |
| 751 | "F", // FOREGROUND |
| 752 | "B", // BACKGROUND |
| 753 | "TS", // TOP_SLEEPING |
| 754 | "HW", // HEAVY_WEIGHT |
| 755 | "C" // CACHED |
| 756 | }; |
| 757 | |
| 758 | /** |
| 759 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 760 | * is not attributed to any non-critical process states. |
| 761 | */ |
| 762 | public static final int[] CRITICAL_PROC_STATES = { |
| 763 | PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND |
| 764 | }; |
| 765 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 766 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 767 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 768 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 769 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 771 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 772 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 773 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 774 | * Note that these must match the constants in android.os.PowerManager. |
| 775 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 776 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 777 | */ |
| 778 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 779 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 780 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 781 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 782 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 783 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 784 | public abstract void noteUserActivityLocked(int type); |
| 785 | public abstract boolean hasUserActivity(); |
| 786 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 787 | |
| 788 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 789 | public abstract long getNetworkActivityBytes(int type, int which); |
| 790 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 791 | public abstract long getMobileRadioActiveTime(int which); |
| 792 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 793 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 794 | /** |
| 795 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 796 | */ |
| 797 | public abstract long getUserCpuTimeUs(int which); |
| 798 | |
| 799 | /** |
| 800 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 801 | */ |
| 802 | public abstract long getSystemCpuTimeUs(int which); |
| 803 | |
| 804 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 805 | * 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] | 806 | * given CPU cluster. |
| 807 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 808 | * @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] | 809 | * @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] | 810 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 811 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 812 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 813 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 814 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 815 | /** |
| 816 | * Returns the number of times this UID woke up the Application Processor to |
| 817 | * process a mobile radio packet. |
| 818 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 819 | */ |
| 820 | public abstract long getMobileRadioApWakeupCount(int which); |
| 821 | |
| 822 | /** |
| 823 | * Returns the number of times this UID woke up the Application Processor to |
| 824 | * process a WiFi packet. |
| 825 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 826 | */ |
| 827 | public abstract long getWifiRadioApWakeupCount(int which); |
| 828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 830 | /* |
| 831 | * FIXME: it's not correct to use this magic value because it |
| 832 | * could clash with a sensor handle (which are defined by |
| 833 | * the sensor HAL, and therefore out of our control |
| 834 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | // Magic sensor number for the GPS. |
| 836 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 841 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 842 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 843 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 846 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 847 | public int mWakeNesting; |
| 848 | public long mWakeSumMs; |
| 849 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 850 | } |
| 851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | /** |
| 853 | * The statistics associated with a particular process. |
| 854 | */ |
| 855 | public static abstract class Proc { |
| 856 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 857 | public static class ExcessivePower { |
| 858 | public static final int TYPE_WAKE = 1; |
| 859 | public static final int TYPE_CPU = 2; |
| 860 | |
| 861 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 862 | public long overTime; |
| 863 | public long usedTime; |
| 864 | } |
| 865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 867 | * Returns true if this process is still active in the battery stats. |
| 868 | */ |
| 869 | public abstract boolean isActive(); |
| 870 | |
| 871 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 872 | * 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] | 873 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 874 | * @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] | 875 | */ |
| 876 | public abstract long getUserTime(int which); |
| 877 | |
| 878 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 879 | * 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] | 880 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 881 | * @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] | 882 | */ |
| 883 | public abstract long getSystemTime(int which); |
| 884 | |
| 885 | /** |
| 886 | * Returns the number of times the process has been started. |
| 887 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 888 | * @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] | 889 | */ |
| 890 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 891 | |
| 892 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 893 | * Returns the number of times the process has crashed. |
| 894 | * |
| 895 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 896 | */ |
| 897 | public abstract int getNumCrashes(int which); |
| 898 | |
| 899 | /** |
| 900 | * Returns the number of times the process has ANRed. |
| 901 | * |
| 902 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 903 | */ |
| 904 | public abstract int getNumAnrs(int which); |
| 905 | |
| 906 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 907 | * 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] | 908 | * @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] | 909 | * @return foreground cpu time in microseconds |
| 910 | */ |
| 911 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 912 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 913 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 914 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 915 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
| 919 | * The statistics associated with a particular package. |
| 920 | */ |
| 921 | public static abstract class Pkg { |
| 922 | |
| 923 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 924 | * Returns information about all wakeup alarms that have been triggered for this |
| 925 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 926 | * 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] | 927 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 928 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | |
| 930 | /** |
| 931 | * Returns a mapping containing service statistics. |
| 932 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 933 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | |
| 935 | /** |
| 936 | * The statistics associated with a particular service. |
| 937 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 938 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | |
| 940 | /** |
| 941 | * Returns the amount of time spent started. |
| 942 | * |
| 943 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 944 | * @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] | 945 | * @return |
| 946 | */ |
| 947 | public abstract long getStartTime(long batteryUptime, int which); |
| 948 | |
| 949 | /** |
| 950 | * Returns the total number of times startService() has been called. |
| 951 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 952 | * @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] | 953 | */ |
| 954 | public abstract int getStarts(int which); |
| 955 | |
| 956 | /** |
| 957 | * Returns the total number times the service has been launched. |
| 958 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 959 | * @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] | 960 | */ |
| 961 | public abstract int getLaunches(int which); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 966 | public static final class LevelStepTracker { |
| 967 | public long mLastStepTime = -1; |
| 968 | public int mNumStepDurations; |
| 969 | public final long[] mStepDurations; |
| 970 | |
| 971 | public LevelStepTracker(int maxLevelSteps) { |
| 972 | mStepDurations = new long[maxLevelSteps]; |
| 973 | } |
| 974 | |
| 975 | public LevelStepTracker(int numSteps, long[] steps) { |
| 976 | mNumStepDurations = numSteps; |
| 977 | mStepDurations = new long[numSteps]; |
| 978 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 979 | } |
| 980 | |
| 981 | public long getDurationAt(int index) { |
| 982 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 983 | } |
| 984 | |
| 985 | public int getLevelAt(int index) { |
| 986 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 987 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 988 | } |
| 989 | |
| 990 | public int getInitModeAt(int index) { |
| 991 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 992 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 993 | } |
| 994 | |
| 995 | public int getModModeAt(int index) { |
| 996 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 997 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 998 | } |
| 999 | |
| 1000 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 1001 | boolean hasData = false; |
| 1002 | while (topOffset >= 0) { |
| 1003 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1004 | topOffset -= 4; |
| 1005 | if (!hasData && digit == 0) { |
| 1006 | continue; |
| 1007 | } |
| 1008 | hasData = true; |
| 1009 | if (digit >= 0 && digit <= 9) { |
| 1010 | out.append((char)('0' + digit)); |
| 1011 | } else { |
| 1012 | out.append((char)('a' + digit - 10)); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1018 | long item = mStepDurations[index]; |
| 1019 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1020 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1021 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1022 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1023 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1024 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1025 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1026 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1027 | case Display.STATE_OFF: out.append('f'); break; |
| 1028 | case Display.STATE_ON: out.append('o'); break; |
| 1029 | case Display.STATE_DOZE: out.append('d'); break; |
| 1030 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1031 | } |
| 1032 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1033 | out.append('p'); |
| 1034 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1035 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1036 | out.append('i'); |
| 1037 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1038 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1039 | case Display.STATE_OFF: out.append('F'); break; |
| 1040 | case Display.STATE_ON: out.append('O'); break; |
| 1041 | case Display.STATE_DOZE: out.append('D'); break; |
| 1042 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1043 | } |
| 1044 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1045 | out.append('P'); |
| 1046 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1047 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1048 | out.append('I'); |
| 1049 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1050 | out.append('-'); |
| 1051 | appendHex(level, 4, out); |
| 1052 | out.append('-'); |
| 1053 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1054 | } |
| 1055 | |
| 1056 | public void decodeEntryAt(int index, String value) { |
| 1057 | final int N = value.length(); |
| 1058 | int i = 0; |
| 1059 | char c; |
| 1060 | long out = 0; |
| 1061 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1062 | i++; |
| 1063 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1064 | 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] | 1065 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1066 | 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] | 1067 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1068 | 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] | 1069 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1070 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1071 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1072 | break; |
| 1073 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1074 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1075 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1076 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1077 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1078 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1079 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1080 | break; |
| 1081 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1082 | break; |
| 1083 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1084 | break; |
| 1085 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1086 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1087 | break; |
| 1088 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1089 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1090 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1091 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1092 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1093 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1097 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1098 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1099 | i++; |
| 1100 | level <<= 4; |
| 1101 | if (c >= '0' && c <= '9') { |
| 1102 | level += c - '0'; |
| 1103 | } else if (c >= 'a' && c <= 'f') { |
| 1104 | level += c - 'a' + 10; |
| 1105 | } else if (c >= 'A' && c <= 'F') { |
| 1106 | level += c - 'A' + 10; |
| 1107 | } |
| 1108 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1109 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1110 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1111 | long duration = 0; |
| 1112 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1113 | i++; |
| 1114 | duration <<= 4; |
| 1115 | if (c >= '0' && c <= '9') { |
| 1116 | duration += c - '0'; |
| 1117 | } else if (c >= 'a' && c <= 'f') { |
| 1118 | duration += c - 'a' + 10; |
| 1119 | } else if (c >= 'A' && c <= 'F') { |
| 1120 | duration += c - 'A' + 10; |
| 1121 | } |
| 1122 | } |
| 1123 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1124 | } |
| 1125 | |
| 1126 | public void init() { |
| 1127 | mLastStepTime = -1; |
| 1128 | mNumStepDurations = 0; |
| 1129 | } |
| 1130 | |
| 1131 | public void clearTime() { |
| 1132 | mLastStepTime = -1; |
| 1133 | } |
| 1134 | |
| 1135 | public long computeTimePerLevel() { |
| 1136 | final long[] steps = mStepDurations; |
| 1137 | final int numSteps = mNumStepDurations; |
| 1138 | |
| 1139 | // For now we'll do a simple average across all steps. |
| 1140 | if (numSteps <= 0) { |
| 1141 | return -1; |
| 1142 | } |
| 1143 | long total = 0; |
| 1144 | for (int i=0; i<numSteps; i++) { |
| 1145 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1146 | } |
| 1147 | return total / numSteps; |
| 1148 | /* |
| 1149 | long[] buckets = new long[numSteps]; |
| 1150 | int numBuckets = 0; |
| 1151 | int numToAverage = 4; |
| 1152 | int i = 0; |
| 1153 | while (i < numSteps) { |
| 1154 | long totalTime = 0; |
| 1155 | int num = 0; |
| 1156 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1157 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1158 | num++; |
| 1159 | } |
| 1160 | buckets[numBuckets] = totalTime / num; |
| 1161 | numBuckets++; |
| 1162 | numToAverage *= 2; |
| 1163 | i += num; |
| 1164 | } |
| 1165 | if (numBuckets < 1) { |
| 1166 | return -1; |
| 1167 | } |
| 1168 | long averageTime = buckets[numBuckets-1]; |
| 1169 | for (i=numBuckets-2; i>=0; i--) { |
| 1170 | averageTime = (averageTime + buckets[i]) / 2; |
| 1171 | } |
| 1172 | return averageTime; |
| 1173 | */ |
| 1174 | } |
| 1175 | |
| 1176 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1177 | int[] outNumOfInterest) { |
| 1178 | final long[] steps = mStepDurations; |
| 1179 | final int count = mNumStepDurations; |
| 1180 | if (count <= 0) { |
| 1181 | return -1; |
| 1182 | } |
| 1183 | long total = 0; |
| 1184 | int numOfInterest = 0; |
| 1185 | for (int i=0; i<count; i++) { |
| 1186 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1187 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1188 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1189 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1190 | // If the modes of interest didn't change during this step period... |
| 1191 | if ((modMode&modesOfInterest) == 0) { |
| 1192 | // And the mode values during this period match those we are measuring... |
| 1193 | if ((initMode&modesOfInterest) == modeValues) { |
| 1194 | // Then this can be used to estimate the total time! |
| 1195 | numOfInterest++; |
| 1196 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | if (numOfInterest <= 0) { |
| 1201 | return -1; |
| 1202 | } |
| 1203 | |
| 1204 | if (outNumOfInterest != null) { |
| 1205 | outNumOfInterest[0] = numOfInterest; |
| 1206 | } |
| 1207 | |
| 1208 | // The estimated time is the average time we spend in each level, multipled |
| 1209 | // by 100 -- the total number of battery levels |
| 1210 | return (total / numOfInterest) * 100; |
| 1211 | } |
| 1212 | |
| 1213 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1214 | int stepCount = mNumStepDurations; |
| 1215 | final long lastStepTime = mLastStepTime; |
| 1216 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1217 | final long[] steps = mStepDurations; |
| 1218 | long duration = elapsedRealtime - lastStepTime; |
| 1219 | for (int i=0; i<numStepLevels; i++) { |
| 1220 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1221 | long thisDuration = duration / (numStepLevels-i); |
| 1222 | duration -= thisDuration; |
| 1223 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1224 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1225 | } |
| 1226 | steps[0] = thisDuration | modeBits; |
| 1227 | } |
| 1228 | stepCount += numStepLevels; |
| 1229 | if (stepCount > steps.length) { |
| 1230 | stepCount = steps.length; |
| 1231 | } |
| 1232 | } |
| 1233 | mNumStepDurations = stepCount; |
| 1234 | mLastStepTime = elapsedRealtime; |
| 1235 | } |
| 1236 | |
| 1237 | public void readFromParcel(Parcel in) { |
| 1238 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1239 | if (N > mStepDurations.length) { |
| 1240 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1241 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1242 | mNumStepDurations = N; |
| 1243 | for (int i=0; i<N; i++) { |
| 1244 | mStepDurations[i] = in.readLong(); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | public void writeToParcel(Parcel out) { |
| 1249 | final int N = mNumStepDurations; |
| 1250 | out.writeInt(N); |
| 1251 | for (int i=0; i<N; i++) { |
| 1252 | out.writeLong(mStepDurations[i]); |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1257 | public static final class PackageChange { |
| 1258 | public String mPackageName; |
| 1259 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1260 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1263 | public static final class DailyItem { |
| 1264 | public long mStartTime; |
| 1265 | public long mEndTime; |
| 1266 | public LevelStepTracker mDischargeSteps; |
| 1267 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1268 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1272 | |
| 1273 | public abstract long getCurrentDailyStartTime(); |
| 1274 | |
| 1275 | public abstract long getNextMinDailyDeadline(); |
| 1276 | |
| 1277 | public abstract long getNextMaxDailyDeadline(); |
| 1278 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1279 | public abstract long[] getCpuFreqs(); |
| 1280 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1281 | public final static class HistoryTag { |
| 1282 | public String string; |
| 1283 | public int uid; |
| 1284 | |
| 1285 | public int poolIdx; |
| 1286 | |
| 1287 | public void setTo(HistoryTag o) { |
| 1288 | string = o.string; |
| 1289 | uid = o.uid; |
| 1290 | poolIdx = o.poolIdx; |
| 1291 | } |
| 1292 | |
| 1293 | public void setTo(String _string, int _uid) { |
| 1294 | string = _string; |
| 1295 | uid = _uid; |
| 1296 | poolIdx = -1; |
| 1297 | } |
| 1298 | |
| 1299 | public void writeToParcel(Parcel dest, int flags) { |
| 1300 | dest.writeString(string); |
| 1301 | dest.writeInt(uid); |
| 1302 | } |
| 1303 | |
| 1304 | public void readFromParcel(Parcel src) { |
| 1305 | string = src.readString(); |
| 1306 | uid = src.readInt(); |
| 1307 | poolIdx = -1; |
| 1308 | } |
| 1309 | |
| 1310 | @Override |
| 1311 | public boolean equals(Object o) { |
| 1312 | if (this == o) return true; |
| 1313 | if (o == null || getClass() != o.getClass()) return false; |
| 1314 | |
| 1315 | HistoryTag that = (HistoryTag) o; |
| 1316 | |
| 1317 | if (uid != that.uid) return false; |
| 1318 | if (!string.equals(that.string)) return false; |
| 1319 | |
| 1320 | return true; |
| 1321 | } |
| 1322 | |
| 1323 | @Override |
| 1324 | public int hashCode() { |
| 1325 | int result = string.hashCode(); |
| 1326 | result = 31 * result + uid; |
| 1327 | return result; |
| 1328 | } |
| 1329 | } |
| 1330 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1331 | /** |
| 1332 | * Optional detailed information that can go into a history step. This is typically |
| 1333 | * generated each time the battery level changes. |
| 1334 | */ |
| 1335 | public final static class HistoryStepDetails { |
| 1336 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1337 | public int userTime; |
| 1338 | public int systemTime; |
| 1339 | |
| 1340 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1341 | public int appCpuUid1; |
| 1342 | public int appCpuUTime1; |
| 1343 | public int appCpuSTime1; |
| 1344 | public int appCpuUid2; |
| 1345 | public int appCpuUTime2; |
| 1346 | public int appCpuSTime2; |
| 1347 | public int appCpuUid3; |
| 1348 | public int appCpuUTime3; |
| 1349 | public int appCpuSTime3; |
| 1350 | |
| 1351 | // Information from /proc/stat |
| 1352 | public int statUserTime; |
| 1353 | public int statSystemTime; |
| 1354 | public int statIOWaitTime; |
| 1355 | public int statIrqTime; |
| 1356 | public int statSoftIrqTime; |
| 1357 | public int statIdlTime; |
| 1358 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1359 | // Platform-level low power state stats |
| 1360 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1361 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1362 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1363 | public HistoryStepDetails() { |
| 1364 | clear(); |
| 1365 | } |
| 1366 | |
| 1367 | public void clear() { |
| 1368 | userTime = systemTime = 0; |
| 1369 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1370 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1371 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1372 | } |
| 1373 | |
| 1374 | public void writeToParcel(Parcel out) { |
| 1375 | out.writeInt(userTime); |
| 1376 | out.writeInt(systemTime); |
| 1377 | out.writeInt(appCpuUid1); |
| 1378 | out.writeInt(appCpuUTime1); |
| 1379 | out.writeInt(appCpuSTime1); |
| 1380 | out.writeInt(appCpuUid2); |
| 1381 | out.writeInt(appCpuUTime2); |
| 1382 | out.writeInt(appCpuSTime2); |
| 1383 | out.writeInt(appCpuUid3); |
| 1384 | out.writeInt(appCpuUTime3); |
| 1385 | out.writeInt(appCpuSTime3); |
| 1386 | out.writeInt(statUserTime); |
| 1387 | out.writeInt(statSystemTime); |
| 1388 | out.writeInt(statIOWaitTime); |
| 1389 | out.writeInt(statIrqTime); |
| 1390 | out.writeInt(statSoftIrqTime); |
| 1391 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1392 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1393 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | public void readFromParcel(Parcel in) { |
| 1397 | userTime = in.readInt(); |
| 1398 | systemTime = in.readInt(); |
| 1399 | appCpuUid1 = in.readInt(); |
| 1400 | appCpuUTime1 = in.readInt(); |
| 1401 | appCpuSTime1 = in.readInt(); |
| 1402 | appCpuUid2 = in.readInt(); |
| 1403 | appCpuUTime2 = in.readInt(); |
| 1404 | appCpuSTime2 = in.readInt(); |
| 1405 | appCpuUid3 = in.readInt(); |
| 1406 | appCpuUTime3 = in.readInt(); |
| 1407 | appCpuSTime3 = in.readInt(); |
| 1408 | statUserTime = in.readInt(); |
| 1409 | statSystemTime = in.readInt(); |
| 1410 | statIOWaitTime = in.readInt(); |
| 1411 | statIrqTime = in.readInt(); |
| 1412 | statSoftIrqTime = in.readInt(); |
| 1413 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1414 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1415 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1419 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1420 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1421 | |
| 1422 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1423 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1424 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1425 | 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] | 1426 | public static final byte CMD_NULL = -1; |
| 1427 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1428 | public static final byte CMD_CURRENT_TIME = 5; |
| 1429 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1430 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1431 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1432 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1433 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1434 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1435 | /** |
| 1436 | * Return whether the command code is a delta data update. |
| 1437 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1438 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1439 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1442 | public byte batteryLevel; |
| 1443 | public byte batteryStatus; |
| 1444 | public byte batteryHealth; |
| 1445 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1446 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1447 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1448 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1449 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1450 | // The charge of the battery in micro-Ampere-hours. |
| 1451 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1452 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1453 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1454 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1455 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1456 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1457 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1458 | 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] | 1459 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1460 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1461 | 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] | 1462 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1463 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1464 | 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] | 1465 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1466 | // These states always appear directly in the first int token |
| 1467 | // of a delta change; they should be ones that change relatively |
| 1468 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1469 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1470 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1471 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1472 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1473 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1474 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1475 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1476 | // Do not use, this is used for coulomb delta count. |
| 1477 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1478 | // These are on the lower bits used for the command; if they change |
| 1479 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1480 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1481 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1482 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1483 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1484 | 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] | 1485 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1486 | // empty slot |
| 1487 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1488 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1489 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1490 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1491 | |
| 1492 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1493 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1494 | public int states; |
| 1495 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1496 | // Constants from WIFI_SUPPL_STATE_* |
| 1497 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1498 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1499 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1500 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1501 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1502 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1503 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1504 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1505 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1506 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1507 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1508 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1509 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1510 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1511 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1512 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1513 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1514 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1515 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1516 | |
| 1517 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1518 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1519 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1520 | |
| 1521 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1522 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1523 | public int states2; |
| 1524 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1525 | // The wake lock that was acquired at this point. |
| 1526 | public HistoryTag wakelockTag; |
| 1527 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1528 | // Kernel wakeup reason at this point. |
| 1529 | public HistoryTag wakeReasonTag; |
| 1530 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1531 | // Non-null when there is more detailed information at this step. |
| 1532 | public HistoryStepDetails stepDetails; |
| 1533 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1534 | public static final int EVENT_FLAG_START = 0x8000; |
| 1535 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1536 | |
| 1537 | // No event in this item. |
| 1538 | public static final int EVENT_NONE = 0x0000; |
| 1539 | // Event is about a process that is running. |
| 1540 | public static final int EVENT_PROC = 0x0001; |
| 1541 | // Event is about an application package that is in the foreground. |
| 1542 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1543 | // Event is about an application package that is at the top of the screen. |
| 1544 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1545 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1546 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1547 | // Events for all additional wake locks aquired/release within a wake block. |
| 1548 | // These are not generated by default. |
| 1549 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1550 | // Event is about an application executing a scheduled job. |
| 1551 | public static final int EVENT_JOB = 0x0006; |
| 1552 | // Events for users running. |
| 1553 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1554 | // Events for foreground user. |
| 1555 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1556 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1557 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1558 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1559 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1560 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1561 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1562 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1563 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1564 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1565 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1566 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1567 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1568 | // 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] | 1569 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1570 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1571 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1572 | // Event for a package being on the temporary whitelist. |
| 1573 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1574 | // Event for the screen waking up. |
| 1575 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1576 | // Event for the UID that woke up the application processor. |
| 1577 | // Used for wakeups coming from WiFi, modem, etc. |
| 1578 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1579 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1580 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1581 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1582 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1583 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1584 | // Mask to extract out only the type part of the event. |
| 1585 | 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] | 1586 | |
| 1587 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1588 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1589 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1590 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1591 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1592 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1593 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1594 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1595 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1596 | 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] | 1597 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1598 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1599 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1600 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1601 | public static final int EVENT_USER_FOREGROUND_START = |
| 1602 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1603 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1604 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1605 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1606 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1607 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1608 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1609 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1610 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1611 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1612 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1613 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1614 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1615 | |
| 1616 | // For CMD_EVENT. |
| 1617 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1618 | public HistoryTag eventTag; |
| 1619 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1620 | // 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] | 1621 | public long currentTime; |
| 1622 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1623 | // Meta-data when reading. |
| 1624 | public int numReadInts; |
| 1625 | |
| 1626 | // Pre-allocated objects. |
| 1627 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1628 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1629 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1630 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1631 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1632 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1633 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1634 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1635 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1636 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1637 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1638 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1639 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1640 | public int describeContents() { |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | public void writeToParcel(Parcel dest, int flags) { |
| 1645 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1646 | int bat = (((int)cmd)&0xff) |
| 1647 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1648 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1649 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1650 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1651 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1652 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1653 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1654 | dest.writeInt(bat); |
| 1655 | bat = (((int)batteryTemperature)&0xffff) |
| 1656 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1657 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1658 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1659 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1660 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1661 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1662 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1663 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1664 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1665 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1666 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1667 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1668 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1669 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1670 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1671 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1672 | dest.writeLong(currentTime); |
| 1673 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1674 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1675 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1676 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1677 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1678 | int bat = src.readInt(); |
| 1679 | cmd = (byte)(bat&0xff); |
| 1680 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1681 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1682 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1683 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1684 | int bat2 = src.readInt(); |
| 1685 | batteryTemperature = (short)(bat2&0xffff); |
| 1686 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1687 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1688 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1689 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1690 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1691 | wakelockTag = localWakelockTag; |
| 1692 | wakelockTag.readFromParcel(src); |
| 1693 | } else { |
| 1694 | wakelockTag = null; |
| 1695 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1696 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1697 | wakeReasonTag = localWakeReasonTag; |
| 1698 | wakeReasonTag.readFromParcel(src); |
| 1699 | } else { |
| 1700 | wakeReasonTag = null; |
| 1701 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1702 | if ((bat&0x40000000) != 0) { |
| 1703 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1704 | eventTag = localEventTag; |
| 1705 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1706 | } else { |
| 1707 | eventCode = EVENT_NONE; |
| 1708 | eventTag = null; |
| 1709 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1710 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1711 | currentTime = src.readLong(); |
| 1712 | } else { |
| 1713 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1714 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1715 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1718 | public void clear() { |
| 1719 | time = 0; |
| 1720 | cmd = CMD_NULL; |
| 1721 | batteryLevel = 0; |
| 1722 | batteryStatus = 0; |
| 1723 | batteryHealth = 0; |
| 1724 | batteryPlugType = 0; |
| 1725 | batteryTemperature = 0; |
| 1726 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1727 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1728 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1729 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1730 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1731 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1732 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1733 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1734 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1735 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1736 | public void setTo(HistoryItem o) { |
| 1737 | time = o.time; |
| 1738 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1739 | setToCommon(o); |
| 1740 | } |
| 1741 | |
| 1742 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1743 | this.time = time; |
| 1744 | this.cmd = cmd; |
| 1745 | setToCommon(o); |
| 1746 | } |
| 1747 | |
| 1748 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1749 | batteryLevel = o.batteryLevel; |
| 1750 | batteryStatus = o.batteryStatus; |
| 1751 | batteryHealth = o.batteryHealth; |
| 1752 | batteryPlugType = o.batteryPlugType; |
| 1753 | batteryTemperature = o.batteryTemperature; |
| 1754 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1755 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1756 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1757 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1758 | if (o.wakelockTag != null) { |
| 1759 | wakelockTag = localWakelockTag; |
| 1760 | wakelockTag.setTo(o.wakelockTag); |
| 1761 | } else { |
| 1762 | wakelockTag = null; |
| 1763 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1764 | if (o.wakeReasonTag != null) { |
| 1765 | wakeReasonTag = localWakeReasonTag; |
| 1766 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1767 | } else { |
| 1768 | wakeReasonTag = null; |
| 1769 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1770 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1771 | if (o.eventTag != null) { |
| 1772 | eventTag = localEventTag; |
| 1773 | eventTag.setTo(o.eventTag); |
| 1774 | } else { |
| 1775 | eventTag = null; |
| 1776 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1777 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1780 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1781 | return batteryLevel == o.batteryLevel |
| 1782 | && batteryStatus == o.batteryStatus |
| 1783 | && batteryHealth == o.batteryHealth |
| 1784 | && batteryPlugType == o.batteryPlugType |
| 1785 | && batteryTemperature == o.batteryTemperature |
| 1786 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1787 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1788 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1789 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1790 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1791 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1792 | |
| 1793 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1794 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1795 | return false; |
| 1796 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1797 | if (wakelockTag != o.wakelockTag) { |
| 1798 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1799 | return false; |
| 1800 | } |
| 1801 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1802 | return false; |
| 1803 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1804 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1805 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1806 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1807 | return false; |
| 1808 | } |
| 1809 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1810 | return false; |
| 1811 | } |
| 1812 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1813 | if (eventTag != o.eventTag) { |
| 1814 | if (eventTag == null || o.eventTag == null) { |
| 1815 | return false; |
| 1816 | } |
| 1817 | if (!eventTag.equals(o.eventTag)) { |
| 1818 | return false; |
| 1819 | } |
| 1820 | } |
| 1821 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1822 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1823 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1824 | |
| 1825 | public final static class HistoryEventTracker { |
| 1826 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1827 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1828 | |
| 1829 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1830 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1831 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1832 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1833 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1834 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1835 | mActiveEvents[idx] = active; |
| 1836 | } |
| 1837 | SparseIntArray uids = active.get(name); |
| 1838 | if (uids == null) { |
| 1839 | uids = new SparseIntArray(); |
| 1840 | active.put(name, uids); |
| 1841 | } |
| 1842 | if (uids.indexOfKey(uid) >= 0) { |
| 1843 | // Already set, nothing to do! |
| 1844 | return false; |
| 1845 | } |
| 1846 | uids.put(uid, poolIdx); |
| 1847 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1848 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1849 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1850 | if (active == null) { |
| 1851 | // not currently active, nothing to do. |
| 1852 | return false; |
| 1853 | } |
| 1854 | SparseIntArray uids = active.get(name); |
| 1855 | if (uids == null) { |
| 1856 | // not currently active, nothing to do. |
| 1857 | return false; |
| 1858 | } |
| 1859 | idx = uids.indexOfKey(uid); |
| 1860 | if (idx < 0) { |
| 1861 | // not currently active, nothing to do. |
| 1862 | return false; |
| 1863 | } |
| 1864 | uids.removeAt(idx); |
| 1865 | if (uids.size() <= 0) { |
| 1866 | active.remove(name); |
| 1867 | } |
| 1868 | } |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1872 | public void removeEvents(int code) { |
| 1873 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1874 | mActiveEvents[idx] = null; |
| 1875 | } |
| 1876 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1877 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1878 | return mActiveEvents[code]; |
| 1879 | } |
| 1880 | } |
| 1881 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1882 | public static final class BitDescription { |
| 1883 | public final int mask; |
| 1884 | public final int shift; |
| 1885 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1886 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1887 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1888 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1889 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1890 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1891 | this.mask = mask; |
| 1892 | this.shift = -1; |
| 1893 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1894 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1895 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1896 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1897 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1898 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1899 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1900 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1901 | this.mask = mask; |
| 1902 | this.shift = shift; |
| 1903 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1904 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1905 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1906 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1907 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1908 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1909 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1910 | /** |
| 1911 | * Don't allow any more batching in to the current history event. This |
| 1912 | * is called when printing partial histories, so to ensure that the next |
| 1913 | * history event will go in to a new batch after what was printed in the |
| 1914 | * last partial history. |
| 1915 | */ |
| 1916 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1917 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1918 | public abstract int getHistoryTotalSize(); |
| 1919 | |
| 1920 | public abstract int getHistoryUsedSize(); |
| 1921 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1922 | public abstract boolean startIteratingHistoryLocked(); |
| 1923 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1924 | public abstract int getHistoryStringPoolSize(); |
| 1925 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1926 | public abstract int getHistoryStringPoolBytes(); |
| 1927 | |
| 1928 | public abstract String getHistoryTagPoolString(int index); |
| 1929 | |
| 1930 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1931 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1932 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1933 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1934 | public abstract void finishIteratingHistoryLocked(); |
| 1935 | |
| 1936 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1937 | |
| 1938 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1939 | |
| 1940 | public abstract void finishIteratingOldHistoryLocked(); |
| 1941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1943 | * Return the base time offset for the battery history. |
| 1944 | */ |
| 1945 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1946 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1947 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | * Returns the number of times the device has been started. |
| 1949 | */ |
| 1950 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1953 | * 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] | 1954 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1955 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | * {@hide} |
| 1957 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1958 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1959 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1960 | /** |
| 1961 | * Returns the number of times the screen was turned on. |
| 1962 | * |
| 1963 | * {@hide} |
| 1964 | */ |
| 1965 | public abstract int getScreenOnCount(int which); |
| 1966 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1967 | /** |
| 1968 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1969 | * running on battery. |
| 1970 | * |
| 1971 | * {@hide} |
| 1972 | */ |
| 1973 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1974 | |
| 1975 | /** |
| 1976 | * Returns the number of times the screen was turned dozing. |
| 1977 | * |
| 1978 | * {@hide} |
| 1979 | */ |
| 1980 | public abstract int getScreenDozeCount(int which); |
| 1981 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1982 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1983 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1984 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1985 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1986 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1987 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1988 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1989 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1990 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1991 | "dark", "dim", "medium", "light", "bright" |
| 1992 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1993 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1994 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1995 | "0", "1", "2", "3", "4" |
| 1996 | }; |
| 1997 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1998 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1999 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2000 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2001 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2002 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2003 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2004 | * {@hide} |
| 2005 | */ |
| 2006 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2007 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2010 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2011 | * |
| 2012 | * {@hide} |
| 2013 | */ |
| 2014 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2015 | |
| 2016 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2017 | * 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] | 2018 | * running on battery. |
| 2019 | * |
| 2020 | * {@hide} |
| 2021 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2022 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2023 | |
| 2024 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2025 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2026 | * |
| 2027 | * {@hide} |
| 2028 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2029 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2030 | |
| 2031 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2032 | * Constant for device idle mode: not active. |
| 2033 | */ |
| 2034 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 2035 | |
| 2036 | /** |
| 2037 | * Constant for device idle mode: active in lightweight mode. |
| 2038 | */ |
| 2039 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 2040 | |
| 2041 | /** |
| 2042 | * Constant for device idle mode: active in full mode. |
| 2043 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2044 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2045 | |
| 2046 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2047 | * Returns the time in microseconds that device has been in idle mode while |
| 2048 | * running on battery. |
| 2049 | * |
| 2050 | * {@hide} |
| 2051 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2052 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2053 | |
| 2054 | /** |
| 2055 | * Returns the number of times that the devie has gone in to idle mode. |
| 2056 | * |
| 2057 | * {@hide} |
| 2058 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2059 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2060 | |
| 2061 | /** |
| 2062 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2063 | * mode, not in idle maintenance etc). |
| 2064 | */ |
| 2065 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2066 | |
| 2067 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2068 | * 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] | 2069 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2070 | * counts all of the time that we consider the device to be idle, whether or not |
| 2071 | * it is currently in the actual device idle mode. |
| 2072 | * |
| 2073 | * {@hide} |
| 2074 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2075 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2076 | |
| 2077 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2078 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2079 | * |
| 2080 | * {@hide} |
| 2081 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2082 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2083 | |
| 2084 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2085 | * Returns the number of times that connectivity state changed. |
| 2086 | * |
| 2087 | * {@hide} |
| 2088 | */ |
| 2089 | public abstract int getNumConnectivityChange(int which); |
| 2090 | |
| 2091 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2092 | * 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] | 2093 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2094 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | * {@hide} |
| 2096 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2097 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2098 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2099 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2100 | * Returns the number of times a phone call was activated. |
| 2101 | * |
| 2102 | * {@hide} |
| 2103 | */ |
| 2104 | public abstract int getPhoneOnCount(int which); |
| 2105 | |
| 2106 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2107 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2108 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2109 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2110 | * {@hide} |
| 2111 | */ |
| 2112 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2113 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2114 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2115 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2116 | * Returns the time in microseconds that the phone has been trying to |
| 2117 | * acquire a signal. |
| 2118 | * |
| 2119 | * {@hide} |
| 2120 | */ |
| 2121 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2122 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2123 | |
| 2124 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2125 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2126 | * acquire a signal. |
| 2127 | * |
| 2128 | * {@hide} |
| 2129 | */ |
| 2130 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2131 | |
| 2132 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2133 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2134 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2135 | * {@hide} |
| 2136 | */ |
| 2137 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2138 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2139 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2140 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2141 | * counts. |
| 2142 | */ |
| 2143 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2144 | |
| 2145 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2146 | * Returns the time in microseconds that the mobile network has been active |
| 2147 | * (in a high power state). |
| 2148 | * |
| 2149 | * {@hide} |
| 2150 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2151 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2152 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2153 | /** |
| 2154 | * Returns the number of times that the mobile network has transitioned to the |
| 2155 | * active state. |
| 2156 | * |
| 2157 | * {@hide} |
| 2158 | */ |
| 2159 | public abstract int getMobileRadioActiveCount(int which); |
| 2160 | |
| 2161 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2162 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2163 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2164 | * from the radio. |
| 2165 | * |
| 2166 | * {@hide} |
| 2167 | */ |
| 2168 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2169 | |
| 2170 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2171 | * Returns the time in microseconds that the mobile network has been active |
| 2172 | * (in a high power state) but not being able to blame on an app. |
| 2173 | * |
| 2174 | * {@hide} |
| 2175 | */ |
| 2176 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2177 | |
| 2178 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2179 | * 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] | 2180 | * |
| 2181 | * {@hide} |
| 2182 | */ |
| 2183 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2184 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2185 | public static final int DATA_CONNECTION_NONE = 0; |
| 2186 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2187 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2188 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2189 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2190 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2191 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2192 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2193 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2194 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2195 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2196 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2197 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2198 | public static final int DATA_CONNECTION_LTE = 13; |
| 2199 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2200 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2201 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2202 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2203 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2204 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2205 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2206 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2207 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2208 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2209 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2210 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2211 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2212 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2213 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2214 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2215 | * {@hide} |
| 2216 | */ |
| 2217 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2218 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2221 | * Returns the number of times the phone has entered the given data |
| 2222 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2223 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2224 | * {@hide} |
| 2225 | */ |
| 2226 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2227 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2228 | /** |
| 2229 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2230 | */ |
| 2231 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2232 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2233 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2234 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2235 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2236 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2237 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2238 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2239 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2240 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2241 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2242 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2243 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2244 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2245 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2246 | |
| 2247 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2248 | |
| 2249 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2250 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2251 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2252 | "group-handshake", "completed", "dormant", "uninit" |
| 2253 | }; |
| 2254 | |
| 2255 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2256 | "inv", "dsc", "dis", "inact", "scan", |
| 2257 | "auth", "ascing", "asced", "4-way", |
| 2258 | "group", "compl", "dorm", "uninit" |
| 2259 | }; |
| 2260 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2261 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2262 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2263 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2264 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2265 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2266 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2267 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2268 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2269 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2270 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2271 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2272 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2273 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2274 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2275 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2276 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2277 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2278 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2279 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2280 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2281 | new String[] {"in", "out", "emergency", "off"}, |
| 2282 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2283 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2284 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2285 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2286 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2287 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2288 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2289 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2290 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2291 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2292 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2293 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2294 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2295 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2296 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2297 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2298 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2299 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2300 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2301 | new String[] { "off", "light", "full", "???" }, |
| 2302 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2303 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2304 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2305 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2306 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2307 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2308 | new String[] { "0", "1", "2", "3", "4" }, |
| 2309 | new String[] { "0", "1", "2", "3", "4" }), |
| 2310 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2311 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2312 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2313 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2314 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2315 | }; |
| 2316 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2317 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2318 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2319 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2320 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2321 | }; |
| 2322 | |
| 2323 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2324 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2325 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2326 | "Esw", "Ewa", "Elw", "Eec" |
| 2327 | }; |
| 2328 | |
| 2329 | @FunctionalInterface |
| 2330 | public interface IntToString { |
| 2331 | String applyAsString(int val); |
| 2332 | } |
| 2333 | |
| 2334 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2335 | private static final IntToString sIntToString = Integer::toString; |
| 2336 | |
| 2337 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2338 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2339 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2340 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2341 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2342 | }; |
| 2343 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2344 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2345 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2346 | * Note that this may be different from the sum of per uid timer values. |
| 2347 | * |
| 2348 | * {@hide} |
| 2349 | */ |
| 2350 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2351 | |
| 2352 | /** |
| 2353 | * Returns total time for WiFi Multicast Wakelock timer |
| 2354 | * Note that this may be different from the sum of per uid timer values. |
| 2355 | * |
| 2356 | * {@hide} |
| 2357 | */ |
| 2358 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2359 | |
| 2360 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2361 | * 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] | 2362 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2363 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2364 | * {@hide} |
| 2365 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2366 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2367 | |
| 2368 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2369 | * 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] | 2370 | * been in the running state while the device was running on battery. |
| 2371 | * |
| 2372 | * {@hide} |
| 2373 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2374 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2375 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2376 | public static final int WIFI_STATE_OFF = 0; |
| 2377 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2378 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2379 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2380 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2381 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2382 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2383 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2384 | |
| 2385 | static final String[] WIFI_STATE_NAMES = { |
| 2386 | "off", "scanning", "no_net", "disconn", |
| 2387 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2388 | }; |
| 2389 | |
| 2390 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2391 | |
| 2392 | /** |
| 2393 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2394 | * |
| 2395 | * {@hide} |
| 2396 | */ |
| 2397 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2398 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2399 | |
| 2400 | /** |
| 2401 | * Returns the number of times that WiFi has entered the given state. |
| 2402 | * |
| 2403 | * {@hide} |
| 2404 | */ |
| 2405 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2406 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2407 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2408 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2409 | * |
| 2410 | * {@hide} |
| 2411 | */ |
| 2412 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2413 | |
| 2414 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2415 | * Returns the time in microseconds that the wifi supplicant has been |
| 2416 | * in a given state. |
| 2417 | * |
| 2418 | * {@hide} |
| 2419 | */ |
| 2420 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2421 | |
| 2422 | /** |
| 2423 | * Returns the number of times that the wifi supplicant has transitioned |
| 2424 | * to a given state. |
| 2425 | * |
| 2426 | * {@hide} |
| 2427 | */ |
| 2428 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2429 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2430 | /** |
| 2431 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2432 | * |
| 2433 | * {@hide} |
| 2434 | */ |
| 2435 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2436 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2437 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2438 | |
| 2439 | /** |
| 2440 | * Returns the time in microseconds that WIFI has been running with |
| 2441 | * the given signal strength. |
| 2442 | * |
| 2443 | * {@hide} |
| 2444 | */ |
| 2445 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2446 | long elapsedRealtimeUs, int which); |
| 2447 | |
| 2448 | /** |
| 2449 | * Returns the number of times WIFI has entered the given signal strength. |
| 2450 | * |
| 2451 | * {@hide} |
| 2452 | */ |
| 2453 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2454 | |
| 2455 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2456 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2457 | * |
| 2458 | * {@hide} |
| 2459 | */ |
| 2460 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2461 | |
| 2462 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2463 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2464 | * running on battery. |
| 2465 | * |
| 2466 | * {@hide} |
| 2467 | */ |
| 2468 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2469 | |
| 2470 | /** |
| 2471 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2472 | * running on battery. |
| 2473 | * |
| 2474 | * {@hide} |
| 2475 | */ |
| 2476 | public abstract long getFlashlightOnCount(int which); |
| 2477 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2478 | /** |
| 2479 | * Returns the time in microseconds that the camera has been on while the device was |
| 2480 | * running on battery. |
| 2481 | * |
| 2482 | * {@hide} |
| 2483 | */ |
| 2484 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2485 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2486 | /** |
| 2487 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2488 | * on battery. |
| 2489 | * |
| 2490 | * {@hide} |
| 2491 | */ |
| 2492 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2493 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2494 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2495 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2496 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2497 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2498 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2499 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2500 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2501 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2502 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2503 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2504 | 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] | 2505 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2506 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2507 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2508 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2509 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2510 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2511 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2512 | * actual power data. |
| 2513 | */ |
| 2514 | public abstract boolean hasWifiActivityReporting(); |
| 2515 | |
| 2516 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2517 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2518 | * in various radio controller states, such as transmit, receive, and idle. |
| 2519 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2520 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2521 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2522 | |
| 2523 | /** |
| 2524 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2525 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2526 | * actual power data. |
| 2527 | */ |
| 2528 | public abstract boolean hasBluetoothActivityReporting(); |
| 2529 | |
| 2530 | /** |
| 2531 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2532 | * in various radio controller states, such as transmit, receive, and idle. |
| 2533 | * @return non-null {@link ControllerActivityCounter} |
| 2534 | */ |
| 2535 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2536 | |
| 2537 | /** |
| 2538 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2539 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2540 | * actual power data. |
| 2541 | */ |
| 2542 | public abstract boolean hasModemActivityReporting(); |
| 2543 | |
| 2544 | /** |
| 2545 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2546 | * in various radio controller states, such as transmit, receive, and idle. |
| 2547 | * @return non-null {@link ControllerActivityCounter} |
| 2548 | */ |
| 2549 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2550 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2551 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2552 | * Return the wall clock time when battery stats data collection started. |
| 2553 | */ |
| 2554 | public abstract long getStartClockTime(); |
| 2555 | |
| 2556 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2557 | * Return platform version tag that we were running in when the battery stats started. |
| 2558 | */ |
| 2559 | public abstract String getStartPlatformVersion(); |
| 2560 | |
| 2561 | /** |
| 2562 | * Return platform version tag that we were running in when the battery stats ended. |
| 2563 | */ |
| 2564 | public abstract String getEndPlatformVersion(); |
| 2565 | |
| 2566 | /** |
| 2567 | * Return the internal version code of the parcelled format. |
| 2568 | */ |
| 2569 | public abstract int getParcelVersion(); |
| 2570 | |
| 2571 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | * Return whether we are currently running on battery. |
| 2573 | */ |
| 2574 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | /** |
| 2577 | * Returns a SparseArray containing the statistics for each uid. |
| 2578 | */ |
| 2579 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2580 | |
| 2581 | /** |
| 2582 | * Returns the current battery uptime in microseconds. |
| 2583 | * |
| 2584 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2585 | */ |
| 2586 | public abstract long getBatteryUptime(long curTime); |
| 2587 | |
| 2588 | /** |
| 2589 | * Returns the current battery realtime in microseconds. |
| 2590 | * |
| 2591 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2592 | */ |
| 2593 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2594 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2595 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2596 | * 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] | 2597 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2598 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2599 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2600 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2601 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2602 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2603 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2604 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2605 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | |
| 2607 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2608 | * Get the amount the battery has discharged since the stats were |
| 2609 | * last reset after charging, as a lower-end approximation. |
| 2610 | */ |
| 2611 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2612 | |
| 2613 | /** |
| 2614 | * Get the amount the battery has discharged since the stats were |
| 2615 | * last reset after charging, as an upper-end approximation. |
| 2616 | */ |
| 2617 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2618 | |
| 2619 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2620 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2621 | */ |
| 2622 | public abstract int getDischargeAmount(int which); |
| 2623 | |
| 2624 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2625 | * Get the amount the battery has discharged while the screen was on, |
| 2626 | * since the last time power was unplugged. |
| 2627 | */ |
| 2628 | public abstract int getDischargeAmountScreenOn(); |
| 2629 | |
| 2630 | /** |
| 2631 | * Get the amount the battery has discharged while the screen was on, |
| 2632 | * since the last time the device was charged. |
| 2633 | */ |
| 2634 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2635 | |
| 2636 | /** |
| 2637 | * Get the amount the battery has discharged while the screen was off, |
| 2638 | * since the last time power was unplugged. |
| 2639 | */ |
| 2640 | public abstract int getDischargeAmountScreenOff(); |
| 2641 | |
| 2642 | /** |
| 2643 | * Get the amount the battery has discharged while the screen was off, |
| 2644 | * since the last time the device was charged. |
| 2645 | */ |
| 2646 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2647 | |
| 2648 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2649 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2650 | * since the last time power was unplugged. |
| 2651 | */ |
| 2652 | public abstract int getDischargeAmountScreenDoze(); |
| 2653 | |
| 2654 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2655 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2656 | * since the last time the device was charged. |
| 2657 | */ |
| 2658 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2659 | |
| 2660 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | * Returns the total, last, or current battery uptime in microseconds. |
| 2662 | * |
| 2663 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2664 | * @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] | 2665 | */ |
| 2666 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2667 | |
| 2668 | /** |
| 2669 | * Returns the total, last, or current battery realtime in microseconds. |
| 2670 | * |
| 2671 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2672 | * @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] | 2673 | */ |
| 2674 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2675 | |
| 2676 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2677 | * 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] | 2678 | * |
| 2679 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2680 | * @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] | 2681 | */ |
| 2682 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2683 | |
| 2684 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2685 | * 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] | 2686 | * |
| 2687 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2688 | * @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] | 2689 | */ |
| 2690 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2691 | |
| 2692 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2693 | * Returns the total, last, or current uptime in microseconds. |
| 2694 | * |
| 2695 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2696 | * @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] | 2697 | */ |
| 2698 | public abstract long computeUptime(long curTime, int which); |
| 2699 | |
| 2700 | /** |
| 2701 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2702 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2704 | * @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] | 2705 | */ |
| 2706 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2707 | |
| 2708 | /** |
| 2709 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2710 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2711 | * enough current data to make a decision, or the battery is currently |
| 2712 | * charging. |
| 2713 | * |
| 2714 | * @param curTime The current elepsed realtime in microseconds. |
| 2715 | */ |
| 2716 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2717 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2718 | // The part of a step duration that is the actual time. |
| 2719 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2720 | |
| 2721 | // Bits in a step duration that are the new battery level we are at. |
| 2722 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2723 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2724 | |
| 2725 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2726 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2727 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2728 | |
| 2729 | // Bits in a step duration that indicate which modes changed during that step. |
| 2730 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2731 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2732 | |
| 2733 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2734 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2735 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2736 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2737 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2738 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2739 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2740 | // Step duration mode: power save is on. |
| 2741 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2742 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2743 | // Step duration mode: device is currently in idle mode. |
| 2744 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2745 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2746 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2747 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2748 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2749 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2750 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2751 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2752 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2753 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2754 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2755 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2756 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2757 | }; |
| 2758 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2759 | (Display.STATE_OFF-1), |
| 2760 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2761 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2762 | (Display.STATE_ON-1), |
| 2763 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2764 | (Display.STATE_DOZE-1), |
| 2765 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2766 | (Display.STATE_DOZE_SUSPEND-1), |
| 2767 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2768 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2769 | }; |
| 2770 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2771 | "screen off", |
| 2772 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2773 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2774 | "screen on", |
| 2775 | "screen on power save", |
| 2776 | "screen doze", |
| 2777 | "screen doze power save", |
| 2778 | "screen doze-suspend", |
| 2779 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2780 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2781 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2782 | |
| 2783 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2784 | * 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] | 2785 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2786 | * a coulomb counter. |
| 2787 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2788 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2789 | |
| 2790 | /** |
| 2791 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2792 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2793 | * a coulomb counter. |
| 2794 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2795 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2796 | |
| 2797 | /** |
| 2798 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2799 | * non-zero only if the device's battery has a coulomb counter. |
| 2800 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2801 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2802 | |
| 2803 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2804 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2805 | * micro-Ampere-hours. |
| 2806 | */ |
| 2807 | public abstract long getUahDischargeLightDoze(int which); |
| 2808 | |
| 2809 | /** |
| 2810 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2811 | * micro-Ampere-hours. |
| 2812 | */ |
| 2813 | public abstract long getUahDischargeDeepDoze(int which); |
| 2814 | |
| 2815 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2816 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2817 | * declared by the PowerProfile. |
| 2818 | * @return The estimated battery capacity in mAh. |
| 2819 | */ |
| 2820 | public abstract int getEstimatedBatteryCapacity(); |
| 2821 | |
| 2822 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2823 | * @return The minimum learned battery capacity in uAh. |
| 2824 | */ |
| 2825 | public abstract int getMinLearnedBatteryCapacity(); |
| 2826 | |
| 2827 | /** |
| 2828 | * @return The maximum learned battery capacity in uAh. |
| 2829 | */ |
| 2830 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2831 | |
| 2832 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2833 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2834 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2835 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2836 | |
| 2837 | /** |
| 2838 | * Return the array of daily discharge step durations. |
| 2839 | */ |
| 2840 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2841 | |
| 2842 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2843 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2844 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2845 | * enough current data to make a decision, or the battery is currently |
| 2846 | * discharging. |
| 2847 | * |
| 2848 | * @param curTime The current elepsed realtime in microseconds. |
| 2849 | */ |
| 2850 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2851 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2852 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2853 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2854 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2855 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2856 | |
| 2857 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2858 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2859 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2860 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2861 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2862 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2863 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2864 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2865 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2866 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2868 | /** |
| 2869 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2870 | */ |
| 2871 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2872 | /** |
| 2873 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2874 | */ |
| 2875 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2876 | |
| 2877 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2878 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2879 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2880 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2881 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2882 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | long days = seconds / (60 * 60 * 24); |
| 2884 | if (days != 0) { |
| 2885 | out.append(days); |
| 2886 | out.append("d "); |
| 2887 | } |
| 2888 | long used = days * 60 * 60 * 24; |
| 2889 | |
| 2890 | long hours = (seconds - used) / (60 * 60); |
| 2891 | if (hours != 0 || used != 0) { |
| 2892 | out.append(hours); |
| 2893 | out.append("h "); |
| 2894 | } |
| 2895 | used += hours * 60 * 60; |
| 2896 | |
| 2897 | long mins = (seconds-used) / 60; |
| 2898 | if (mins != 0 || used != 0) { |
| 2899 | out.append(mins); |
| 2900 | out.append("m "); |
| 2901 | } |
| 2902 | used += mins * 60; |
| 2903 | |
| 2904 | if (seconds != 0 || used != 0) { |
| 2905 | out.append(seconds-used); |
| 2906 | out.append("s "); |
| 2907 | } |
| 2908 | } |
| 2909 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2910 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2912 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | sb.append(time - (sec * 1000)); |
| 2914 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | } |
| 2916 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2917 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2918 | long sec = time / 1000; |
| 2919 | formatTimeRaw(sb, sec); |
| 2920 | sb.append(time - (sec * 1000)); |
| 2921 | sb.append("ms"); |
| 2922 | } |
| 2923 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2924 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2926 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
| 2928 | float perc = ((float)num) / ((float)den) * 100; |
| 2929 | mFormatBuilder.setLength(0); |
| 2930 | mFormatter.format("%.1f%%", perc); |
| 2931 | return mFormatBuilder.toString(); |
| 2932 | } |
| 2933 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2934 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2935 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2936 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2937 | if (bytes < BYTES_PER_KB) { |
| 2938 | return bytes + "B"; |
| 2939 | } else if (bytes < BYTES_PER_MB) { |
| 2940 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2941 | return mFormatBuilder.toString(); |
| 2942 | } else if (bytes < BYTES_PER_GB){ |
| 2943 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2944 | return mFormatBuilder.toString(); |
| 2945 | } else { |
| 2946 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2947 | return mFormatBuilder.toString(); |
| 2948 | } |
| 2949 | } |
| 2950 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 2951 | private static long roundUsToMs(long timeUs) { |
| 2952 | return (timeUs + 500) / 1000; |
| 2953 | } |
| 2954 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2955 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2956 | if (timer != null) { |
| 2957 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2958 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2959 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2960 | return totalTimeMillis; |
| 2961 | } |
| 2962 | return 0; |
| 2963 | } |
| 2964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | /** |
| 2966 | * |
| 2967 | * @param sb a StringBuilder object. |
| 2968 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2969 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2971 | * @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] | 2972 | * @param linePrefix a String to be prepended to each line of output. |
| 2973 | * @return the line prefix |
| 2974 | */ |
| 2975 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2976 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2979 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2980 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2981 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | if (totalTimeMillis != 0) { |
| 2983 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2984 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2985 | if (name != null) { |
| 2986 | sb.append(name); |
| 2987 | sb.append(' '); |
| 2988 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | sb.append('('); |
| 2990 | sb.append(count); |
| 2991 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2992 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2993 | if (maxDurationMs >= 0) { |
| 2994 | sb.append(" max="); |
| 2995 | sb.append(maxDurationMs); |
| 2996 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2997 | // Put actual time if it is available and different from totalTimeMillis. |
| 2998 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2999 | if (totalDurMs > totalTimeMillis) { |
| 3000 | sb.append(" actual="); |
| 3001 | sb.append(totalDurMs); |
| 3002 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3003 | if (timer.isRunningLocked()) { |
| 3004 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3005 | if (currentMs >= 0) { |
| 3006 | sb.append(" (running for "); |
| 3007 | sb.append(currentMs); |
| 3008 | sb.append("ms)"); |
| 3009 | } else { |
| 3010 | sb.append(" (running)"); |
| 3011 | } |
| 3012 | } |
| 3013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3014 | return ", "; |
| 3015 | } |
| 3016 | } |
| 3017 | return linePrefix; |
| 3018 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3019 | |
| 3020 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3021 | * 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] | 3022 | * |
| 3023 | * @param pw a PrintWriter object to print to. |
| 3024 | * @param sb a StringBuilder object. |
| 3025 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3026 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3027 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3028 | * @param prefix a String to be prepended to each line of output. |
| 3029 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3030 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3031 | */ |
| 3032 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3033 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3034 | if (timer != null) { |
| 3035 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3036 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3037 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3038 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3039 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3040 | sb.setLength(0); |
| 3041 | sb.append(prefix); |
| 3042 | sb.append(" "); |
| 3043 | sb.append(type); |
| 3044 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3045 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3046 | sb.append("realtime ("); |
| 3047 | sb.append(count); |
| 3048 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3049 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3050 | if (maxDurationMs >= 0) { |
| 3051 | sb.append(" max="); |
| 3052 | sb.append(maxDurationMs); |
| 3053 | } |
| 3054 | if (timer.isRunningLocked()) { |
| 3055 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3056 | if (currentMs >= 0) { |
| 3057 | sb.append(" (running for "); |
| 3058 | sb.append(currentMs); |
| 3059 | sb.append("ms)"); |
| 3060 | } else { |
| 3061 | sb.append(" (running)"); |
| 3062 | } |
| 3063 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3064 | pw.println(sb.toString()); |
| 3065 | return true; |
| 3066 | } |
| 3067 | } |
| 3068 | return false; |
| 3069 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | /** |
| 3072 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3073 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | * @param sb a StringBuilder object. |
| 3075 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3076 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3078 | * @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] | 3079 | * @param linePrefix a String to be prepended to each line of output. |
| 3080 | * @return the line prefix |
| 3081 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3082 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3083 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | long totalTimeMicros = 0; |
| 3085 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3086 | long max = 0; |
| 3087 | long current = 0; |
| 3088 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3090 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3091 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3092 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3093 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3094 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3095 | } |
| 3096 | sb.append(linePrefix); |
| 3097 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3098 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3099 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3101 | sb.append(','); |
| 3102 | sb.append(current); |
| 3103 | sb.append(','); |
| 3104 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3105 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3106 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3107 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3108 | if (name != null) { |
| 3109 | sb.append(','); |
| 3110 | sb.append(totalDuration); |
| 3111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | return ","; |
| 3113 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3114 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3115 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3116 | String type) { |
| 3117 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3118 | pw.print(','); |
| 3119 | pw.print(uid); |
| 3120 | pw.print(','); |
| 3121 | pw.print(category); |
| 3122 | pw.print(','); |
| 3123 | pw.print(type); |
| 3124 | } |
| 3125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | /** |
| 3127 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3128 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3129 | * @param pw the PageWriter to dump log to |
| 3130 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3131 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3132 | * @param args type-dependent data arguments |
| 3133 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3134 | 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] | 3135 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3136 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3137 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3138 | pw.print(','); |
| 3139 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3141 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3143 | |
| 3144 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3145 | * Dump a given timer stat for terse checkin mode. |
| 3146 | * |
| 3147 | * @param pw the PageWriter to dump log to |
| 3148 | * @param uid the UID to log |
| 3149 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3150 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3151 | * @param timer a {@link Timer} to dump stats for |
| 3152 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3153 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3154 | */ |
| 3155 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3156 | Timer timer, long rawRealtime, int which) { |
| 3157 | if (timer != null) { |
| 3158 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3159 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3160 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3161 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3162 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3168 | * Dump a given timer stat to the proto stream. |
| 3169 | * |
| 3170 | * @param proto the ProtoOutputStream to log to |
| 3171 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3172 | * @param timer a {@link Timer} to dump stats for |
| 3173 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3174 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3175 | */ |
| 3176 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3177 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3178 | if (timer == null) { |
| 3179 | return; |
| 3180 | } |
| 3181 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3182 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3183 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3184 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3185 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3186 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3187 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3188 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3189 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3190 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3191 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3192 | // These values will be -1 for timers that don't implement the functionality. |
| 3193 | if (maxDurationMs != -1) { |
| 3194 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3195 | } |
| 3196 | if (curDurationMs != -1) { |
| 3197 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3198 | } |
| 3199 | if (totalDurationMs != -1) { |
| 3200 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3201 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3202 | proto.end(token); |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3207 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3208 | */ |
| 3209 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3210 | if (counter == null) { |
| 3211 | return false; |
| 3212 | } |
| 3213 | |
| 3214 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3215 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3216 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3217 | return true; |
| 3218 | } |
| 3219 | |
| 3220 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3221 | if (c.getCountLocked(which) != 0) { |
| 3222 | return true; |
| 3223 | } |
| 3224 | } |
| 3225 | return false; |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3230 | * The order of the arguments in the final check in line is: |
| 3231 | * |
| 3232 | * idle, rx, power, tx... |
| 3233 | * |
| 3234 | * where tx... is one or more transmit level times. |
| 3235 | */ |
| 3236 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3237 | String type, |
| 3238 | ControllerActivityCounter counter, |
| 3239 | int which) { |
| 3240 | if (!controllerActivityHasData(counter, which)) { |
| 3241 | return; |
| 3242 | } |
| 3243 | |
| 3244 | dumpLineHeader(pw, uid, category, type); |
| 3245 | pw.print(","); |
| 3246 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3247 | pw.print(","); |
| 3248 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3249 | pw.print(","); |
| 3250 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3251 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3252 | pw.print(","); |
| 3253 | pw.print(c.getCountLocked(which)); |
| 3254 | } |
| 3255 | pw.println(); |
| 3256 | } |
| 3257 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3258 | /** |
| 3259 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3260 | */ |
| 3261 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3262 | ControllerActivityCounter counter, |
| 3263 | int which) { |
| 3264 | if (!controllerActivityHasData(counter, which)) { |
| 3265 | return; |
| 3266 | } |
| 3267 | |
| 3268 | final long cToken = proto.start(fieldId); |
| 3269 | |
| 3270 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3271 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3272 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3273 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3274 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3275 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3276 | |
| 3277 | long tToken; |
| 3278 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3279 | for (int i = 0; i < txCounters.length; ++i) { |
| 3280 | LongCounter c = txCounters[i]; |
| 3281 | tToken = proto.start(ControllerActivityProto.TX); |
| 3282 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3283 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3284 | proto.end(tToken); |
| 3285 | } |
| 3286 | |
| 3287 | proto.end(cToken); |
| 3288 | } |
| 3289 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3290 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3291 | String prefix, String controllerName, |
| 3292 | ControllerActivityCounter counter, |
| 3293 | int which) { |
| 3294 | if (controllerActivityHasData(counter, which)) { |
| 3295 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3300 | String controllerName, |
| 3301 | ControllerActivityCounter counter, int which) { |
| 3302 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3303 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3304 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3305 | // Battery real time |
| 3306 | final long totalControllerActivityTimeMs |
| 3307 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3308 | long totalTxTimeMs = 0; |
| 3309 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3310 | totalTxTimeMs += txState.getCountLocked(which); |
| 3311 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3312 | final long sleepTimeMs |
| 3313 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3314 | |
| 3315 | sb.setLength(0); |
| 3316 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3317 | sb.append(" "); |
| 3318 | sb.append(controllerName); |
| 3319 | sb.append(" Sleep time: "); |
| 3320 | formatTimeMs(sb, sleepTimeMs); |
| 3321 | sb.append("("); |
| 3322 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3323 | sb.append(")"); |
| 3324 | pw.println(sb.toString()); |
| 3325 | |
| 3326 | sb.setLength(0); |
| 3327 | sb.append(prefix); |
| 3328 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3329 | sb.append(controllerName); |
| 3330 | sb.append(" Idle time: "); |
| 3331 | formatTimeMs(sb, idleTimeMs); |
| 3332 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3333 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3334 | sb.append(")"); |
| 3335 | pw.println(sb.toString()); |
| 3336 | |
| 3337 | sb.setLength(0); |
| 3338 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3339 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3340 | sb.append(controllerName); |
| 3341 | sb.append(" Rx time: "); |
| 3342 | formatTimeMs(sb, rxTimeMs); |
| 3343 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3344 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3345 | sb.append(")"); |
| 3346 | pw.println(sb.toString()); |
| 3347 | |
| 3348 | sb.setLength(0); |
| 3349 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3350 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3351 | sb.append(controllerName); |
| 3352 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3353 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3354 | String [] powerLevel; |
| 3355 | switch(controllerName) { |
| 3356 | case "Cellular": |
| 3357 | powerLevel = new String[] { |
| 3358 | " less than 0dBm: ", |
| 3359 | " 0dBm to 8dBm: ", |
| 3360 | " 8dBm to 15dBm: ", |
| 3361 | " 15dBm to 20dBm: ", |
| 3362 | " above 20dBm: "}; |
| 3363 | break; |
| 3364 | default: |
| 3365 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3366 | break; |
| 3367 | } |
| 3368 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3369 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3370 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3371 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3372 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3373 | sb.setLength(0); |
| 3374 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3375 | sb.append(" "); |
| 3376 | sb.append(powerLevel[lvl]); |
| 3377 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3378 | formatTimeMs(sb, txLvlTimeMs); |
| 3379 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3380 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3381 | sb.append(")"); |
| 3382 | pw.println(sb.toString()); |
| 3383 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3384 | } else { |
| 3385 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3386 | formatTimeMs(sb, txLvlTimeMs); |
| 3387 | sb.append("("); |
| 3388 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3389 | sb.append(")"); |
| 3390 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3391 | } |
| 3392 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3393 | if (powerDrainMaMs > 0) { |
| 3394 | sb.setLength(0); |
| 3395 | sb.append(prefix); |
| 3396 | sb.append(" "); |
| 3397 | sb.append(controllerName); |
| 3398 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3399 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3400 | sb.append("mAh"); |
| 3401 | pw.println(sb.toString()); |
| 3402 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3406 | * Temporary for settings. |
| 3407 | */ |
| 3408 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3409 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3410 | } |
| 3411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | /** |
| 3413 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3414 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3415 | * 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] | 3416 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3417 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3418 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3420 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3421 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3424 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3425 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3426 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3427 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3429 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3430 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3431 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3432 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3433 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3434 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3435 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3436 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3437 | rawRealtime, which); |
| 3438 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3439 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3440 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3441 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3442 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3443 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3444 | final long dischargeCount = getUahDischarge(which); |
| 3445 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3446 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3447 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3448 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3449 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3450 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3451 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3452 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3453 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3454 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3455 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3458 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3459 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3460 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3461 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3462 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3463 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3464 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3465 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3466 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3467 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3468 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3469 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3470 | long fullWakeLockTimeTotal = 0; |
| 3471 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3472 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3473 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3474 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3475 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3476 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3477 | = u.getWakelockStats(); |
| 3478 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3479 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3480 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3481 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3482 | if (fullWakeTimer != null) { |
| 3483 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3484 | which); |
| 3485 | } |
| 3486 | |
| 3487 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3488 | if (partialWakeTimer != null) { |
| 3489 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3490 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3494 | |
| 3495 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3496 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3497 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3498 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3499 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3500 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3501 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3502 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3503 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3504 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3505 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3506 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3507 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3508 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3509 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3510 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3511 | // Dump Modem controller stats |
| 3512 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3513 | getModemControllerActivity(), which); |
| 3514 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3515 | // Dump Wifi controller stats |
| 3516 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3517 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3518 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3519 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3520 | |
| 3521 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3522 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3523 | |
| 3524 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3525 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3526 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | // Dump misc stats |
| 3529 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3530 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3531 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3532 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3533 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3534 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3535 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3536 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3537 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3538 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3539 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3540 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3541 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3542 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3543 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3544 | // Dump screen brightness stats |
| 3545 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3546 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3547 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3548 | } |
| 3549 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3550 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3551 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3552 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3553 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3554 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3555 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3556 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3557 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3558 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3559 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3560 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3561 | } |
| 3562 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3563 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3564 | // Dump network type stats |
| 3565 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3566 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3567 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3568 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3569 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3570 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3571 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3572 | } |
| 3573 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3574 | |
| 3575 | // Dump wifi state stats |
| 3576 | args = new Object[NUM_WIFI_STATES]; |
| 3577 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3578 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3579 | } |
| 3580 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3581 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3582 | args[i] = getWifiStateCount(i, which); |
| 3583 | } |
| 3584 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3585 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3586 | // Dump wifi suppl state stats |
| 3587 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3588 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3589 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3590 | } |
| 3591 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3592 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3593 | args[i] = getWifiSupplStateCount(i, which); |
| 3594 | } |
| 3595 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3596 | |
| 3597 | // Dump wifi signal strength stats |
| 3598 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3599 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3600 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3601 | } |
| 3602 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3603 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3604 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3605 | } |
| 3606 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3607 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3608 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3609 | final long multicastWakeLockTimeTotalMicros = |
| 3610 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3611 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3612 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3613 | multicastWakeLockTimeTotalMicros / 1000, |
| 3614 | multicastWakeLockCountTotal); |
| 3615 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3616 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3617 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3618 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3619 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3620 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3621 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3622 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3623 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3624 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3625 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3626 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3627 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3628 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3629 | } else { |
| 3630 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3631 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3632 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3633 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3634 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3635 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3636 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3637 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3638 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3639 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3640 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3641 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3642 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3643 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3644 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3645 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3646 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3647 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3648 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3649 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3650 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3651 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3652 | // Not doing the regular wake lock formatting to remain compatible |
| 3653 | // with the old checkin format. |
| 3654 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3655 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3656 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3657 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3658 | } |
| 3659 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3660 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3661 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3662 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3663 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3664 | if (rpmStats.size() > 0) { |
| 3665 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3666 | sb.setLength(0); |
| 3667 | Timer totalTimer = ent.getValue(); |
| 3668 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3669 | int count = totalTimer.getCountLocked(which); |
| 3670 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3671 | long screenOffTimeMs = screenOffTimer != null |
| 3672 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3673 | int screenOffCount = screenOffTimer != null |
| 3674 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3675 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3676 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3677 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3678 | screenOffCount); |
| 3679 | } else { |
| 3680 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3681 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3682 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3686 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3687 | helper.create(this); |
| 3688 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3689 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3690 | if (sippers != null && sippers.size() > 0) { |
| 3691 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3692 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3693 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3694 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3695 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3696 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3697 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3698 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3699 | String label; |
| 3700 | switch (bs.drainType) { |
| 3701 | case IDLE: |
| 3702 | label="idle"; |
| 3703 | break; |
| 3704 | case CELL: |
| 3705 | label="cell"; |
| 3706 | break; |
| 3707 | case PHONE: |
| 3708 | label="phone"; |
| 3709 | break; |
| 3710 | case WIFI: |
| 3711 | label="wifi"; |
| 3712 | break; |
| 3713 | case BLUETOOTH: |
| 3714 | label="blue"; |
| 3715 | break; |
| 3716 | case SCREEN: |
| 3717 | label="scrn"; |
| 3718 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3719 | case FLASHLIGHT: |
| 3720 | label="flashlight"; |
| 3721 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3722 | case APP: |
| 3723 | uid = bs.uidObj.getUid(); |
| 3724 | label = "uid"; |
| 3725 | break; |
| 3726 | case USER: |
| 3727 | uid = UserHandle.getUid(bs.userId, 0); |
| 3728 | label = "user"; |
| 3729 | break; |
| 3730 | case UNACCOUNTED: |
| 3731 | label = "unacc"; |
| 3732 | break; |
| 3733 | case OVERCOUNTED: |
| 3734 | label = "over"; |
| 3735 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3736 | case CAMERA: |
| 3737 | label = "camera"; |
| 3738 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3739 | case MEMORY: |
| 3740 | label = "memory"; |
| 3741 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3742 | default: |
| 3743 | label = "???"; |
| 3744 | } |
| 3745 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3746 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3747 | bs.shouldHide ? 1 : 0, |
| 3748 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3749 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3750 | } |
| 3751 | } |
| 3752 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3753 | final long[] cpuFreqs = getCpuFreqs(); |
| 3754 | if (cpuFreqs != null) { |
| 3755 | sb.setLength(0); |
| 3756 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3757 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3758 | } |
| 3759 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3760 | } |
| 3761 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3762 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | for (int iu = 0; iu < NU; iu++) { |
| 3764 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3765 | if (reqUid >= 0 && uid != reqUid) { |
| 3766 | continue; |
| 3767 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3768 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3771 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3772 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3773 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3774 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3775 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3776 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3777 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3778 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3779 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3780 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3781 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3782 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3783 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3784 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3785 | // Background data transfers |
| 3786 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3787 | which); |
| 3788 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3789 | which); |
| 3790 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3791 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3792 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3793 | which); |
| 3794 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3795 | which); |
| 3796 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3797 | which); |
| 3798 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3799 | which); |
| 3800 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3801 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3802 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3803 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3804 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3805 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3806 | || wifiBytesBgTx > 0 |
| 3807 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3808 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3809 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3810 | wifiBytesRx, wifiBytesTx, |
| 3811 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3812 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3813 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3814 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3815 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3816 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3817 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3820 | // Dump modem controller data, per UID. |
| 3821 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3822 | u.getModemControllerActivity(), which); |
| 3823 | |
| 3824 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3825 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3826 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3827 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3828 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3829 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3830 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3831 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3832 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3833 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3834 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3835 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3836 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3837 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3838 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3839 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3840 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3841 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3843 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3844 | u.getWifiControllerActivity(), which); |
| 3845 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3846 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3847 | if (bleTimer != null) { |
| 3848 | // Convert from microseconds to milliseconds with rounding |
| 3849 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3850 | / 1000; |
| 3851 | if (totalTime != 0) { |
| 3852 | final int count = bleTimer.getCountLocked(which); |
| 3853 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3854 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3855 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3856 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3857 | final long actualTimeBg = bleTimerBg != null ? |
| 3858 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3859 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3860 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3861 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3862 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3863 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3864 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3865 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3866 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3867 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3868 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3869 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3870 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3871 | final Timer unoptimizedScanTimerBg = |
| 3872 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3873 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3874 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3875 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3876 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3877 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3878 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3879 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3880 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3881 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3882 | } |
| 3883 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3884 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3885 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3886 | u.getBluetoothControllerActivity(), which); |
| 3887 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3888 | if (u.hasUserActivity()) { |
| 3889 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3890 | boolean hasData = false; |
| 3891 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3892 | int val = u.getUserActivityCount(i, which); |
| 3893 | args[i] = val; |
| 3894 | if (val != 0) hasData = true; |
| 3895 | } |
| 3896 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3897 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3898 | } |
| 3899 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3900 | |
| 3901 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3902 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3903 | // Times are since reset (regardless of 'which') |
| 3904 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3905 | final Timer bgTimer = timer.getSubTimer(); |
| 3906 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3907 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3908 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3909 | } |
| 3910 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3911 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3912 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3913 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3914 | String linePrefix = ""; |
| 3915 | sb.setLength(0); |
| 3916 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3917 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3918 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3919 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3920 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3921 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3922 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3923 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3924 | rawRealtime, "w", which, linePrefix); |
| 3925 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3926 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3927 | if (sb.length() > 0) { |
| 3928 | String name = wakelocks.keyAt(iw); |
| 3929 | if (name.indexOf(',') >= 0) { |
| 3930 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3932 | if (name.indexOf('\n') >= 0) { |
| 3933 | name = name.replace('\n', '_'); |
| 3934 | } |
| 3935 | if (name.indexOf('\r') >= 0) { |
| 3936 | name = name.replace('\r', '_'); |
| 3937 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3938 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | } |
| 3940 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3941 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3942 | // WiFi Multicast Wakelock Statistics |
| 3943 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3944 | if (mcTimer != null) { |
| 3945 | final long totalMcWakelockTimeMs = |
| 3946 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 3947 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 3948 | if(totalMcWakelockTimeMs > 0) { |
| 3949 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 3950 | totalMcWakelockTimeMs, countMcWakelock); |
| 3951 | } |
| 3952 | } |
| 3953 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3954 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3955 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3956 | final Timer timer = syncs.valueAt(isy); |
| 3957 | // Convert from microseconds to milliseconds with rounding |
| 3958 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3959 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3960 | final Timer bgTimer = timer.getSubTimer(); |
| 3961 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3962 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3963 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3964 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3965 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3966 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3967 | } |
| 3968 | } |
| 3969 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3970 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3971 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3972 | final Timer timer = jobs.valueAt(ij); |
| 3973 | // Convert from microseconds to milliseconds with rounding |
| 3974 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3975 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3976 | final Timer bgTimer = timer.getSubTimer(); |
| 3977 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3978 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3979 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3980 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3981 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3982 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3986 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3987 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3988 | SparseIntArray types = completions.valueAt(ic); |
| 3989 | if (types != null) { |
| 3990 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3991 | "\"" + completions.keyAt(ic) + "\"", |
| 3992 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3993 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3994 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3995 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3996 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3997 | } |
| 3998 | } |
| 3999 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4000 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 4001 | rawRealtime, which); |
| 4002 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4003 | rawRealtime, which); |
| 4004 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4005 | rawRealtime, which); |
| 4006 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4007 | rawRealtime, which); |
| 4008 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4009 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4010 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4011 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4012 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4013 | final int sensorNumber = sensors.keyAt(ise); |
| 4014 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4015 | if (timer != null) { |
| 4016 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4017 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4018 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4019 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4020 | final int count = timer.getCountLocked(which); |
| 4021 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4022 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4023 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4024 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4025 | final long bgActualTime = bgTimer != null ? |
| 4026 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4027 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4028 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4029 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | } |
| 4031 | } |
| 4032 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4033 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4034 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4035 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4036 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4037 | rawRealtime, which); |
| 4038 | |
| 4039 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4040 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4041 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4042 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4043 | long totalStateTime = 0; |
| 4044 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4045 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4046 | totalStateTime += time; |
| 4047 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4048 | } |
| 4049 | if (totalStateTime > 0) { |
| 4050 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4051 | } |
| 4052 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4053 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4054 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4055 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4056 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4057 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4060 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4061 | if (cpuFreqs != null) { |
| 4062 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4063 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4064 | // screenOffCpuFreqTimes. |
| 4065 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4066 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4067 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4068 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4069 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4070 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4071 | if (screenOffCpuFreqTimeMs != null) { |
| 4072 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4073 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4074 | } |
| 4075 | } else { |
| 4076 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4077 | sb.append(",0"); |
| 4078 | } |
| 4079 | } |
| 4080 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4081 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4082 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4083 | |
| 4084 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4085 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4086 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4087 | sb.setLength(0); |
| 4088 | for (int i = 0; i < timesMs.length; ++i) { |
| 4089 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4090 | } |
| 4091 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4092 | which, procState); |
| 4093 | if (screenOffTimesMs != null) { |
| 4094 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4095 | sb.append("," + screenOffTimesMs[i]); |
| 4096 | } |
| 4097 | } else { |
| 4098 | for (int i = 0; i < timesMs.length; ++i) { |
| 4099 | sb.append(",0"); |
| 4100 | } |
| 4101 | } |
| 4102 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4103 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4104 | } |
| 4105 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4108 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4109 | = u.getProcessStats(); |
| 4110 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4111 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4112 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4113 | final long userMillis = ps.getUserTime(which); |
| 4114 | final long systemMillis = ps.getSystemTime(which); |
| 4115 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4116 | final int starts = ps.getStarts(which); |
| 4117 | final int numCrashes = ps.getNumCrashes(which); |
| 4118 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4119 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4120 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4121 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4122 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4123 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | } |
| 4125 | } |
| 4126 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4127 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4128 | = u.getPackageStats(); |
| 4129 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4130 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4131 | int wakeups = 0; |
| 4132 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4133 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4134 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4135 | wakeups += count; |
| 4136 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4137 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4138 | } |
| 4139 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4140 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4141 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4142 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4143 | final int starts = ss.getStarts(which); |
| 4144 | final int launches = ss.getLaunches(which); |
| 4145 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4146 | dumpLine(pw, uid, category, APK_DATA, |
| 4147 | wakeups, // wakeup alarms |
| 4148 | packageStats.keyAt(ipkg), // Apk |
| 4149 | serviceStats.keyAt(isvc), // service |
| 4150 | startTime / 1000, // time spent started, in ms |
| 4151 | starts, |
| 4152 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | } |
| 4156 | } |
| 4157 | } |
| 4158 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4159 | static final class TimerEntry { |
| 4160 | final String mName; |
| 4161 | final int mId; |
| 4162 | final BatteryStats.Timer mTimer; |
| 4163 | final long mTime; |
| 4164 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4165 | mName = name; |
| 4166 | mId = id; |
| 4167 | mTimer = timer; |
| 4168 | mTime = time; |
| 4169 | } |
| 4170 | } |
| 4171 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4172 | private void printmAh(PrintWriter printer, double power) { |
| 4173 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4174 | } |
| 4175 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4176 | private void printmAh(StringBuilder sb, double power) { |
| 4177 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4178 | } |
| 4179 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4180 | /** |
| 4181 | * Temporary for settings. |
| 4182 | */ |
| 4183 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4184 | int reqUid) { |
| 4185 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4186 | } |
| 4187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4189 | 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] | 4190 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4192 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4193 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | |
| 4196 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4197 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4198 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4199 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4200 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4201 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4202 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4203 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4204 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4205 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4206 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4207 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4208 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4209 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4210 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4212 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4213 | if (estimatedBatteryCapacity > 0) { |
| 4214 | sb.setLength(0); |
| 4215 | sb.append(prefix); |
| 4216 | sb.append(" Estimated battery capacity: "); |
| 4217 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4218 | sb.append(" mAh"); |
| 4219 | pw.println(sb.toString()); |
| 4220 | } |
| 4221 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4222 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4223 | if (minLearnedBatteryCapacity > 0) { |
| 4224 | sb.setLength(0); |
| 4225 | sb.append(prefix); |
| 4226 | sb.append(" Min learned battery capacity: "); |
| 4227 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4228 | sb.append(" mAh"); |
| 4229 | pw.println(sb.toString()); |
| 4230 | } |
| 4231 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4232 | if (maxLearnedBatteryCapacity > 0) { |
| 4233 | sb.setLength(0); |
| 4234 | sb.append(prefix); |
| 4235 | sb.append(" Max learned battery capacity: "); |
| 4236 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4237 | sb.append(" mAh"); |
| 4238 | pw.println(sb.toString()); |
| 4239 | } |
| 4240 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4241 | sb.setLength(0); |
| 4242 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4243 | sb.append(" Time on battery: "); |
| 4244 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4245 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4246 | sb.append(") realtime, "); |
| 4247 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4248 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4249 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4250 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4251 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4252 | sb.setLength(0); |
| 4253 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4254 | sb.append(" Time on battery screen off: "); |
| 4255 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4256 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4257 | sb.append(") realtime, "); |
| 4258 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4259 | sb.append("("); |
| 4260 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4261 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4262 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4263 | |
| 4264 | sb.setLength(0); |
| 4265 | sb.append(prefix); |
| 4266 | sb.append(" Time on battery screen doze: "); |
| 4267 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4268 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4269 | sb.append(")"); |
| 4270 | pw.println(sb.toString()); |
| 4271 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4272 | sb.setLength(0); |
| 4273 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4274 | sb.append(" Total run time: "); |
| 4275 | formatTimeMs(sb, totalRealtime / 1000); |
| 4276 | sb.append("realtime, "); |
| 4277 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4278 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4279 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4280 | if (batteryTimeRemaining >= 0) { |
| 4281 | sb.setLength(0); |
| 4282 | sb.append(prefix); |
| 4283 | sb.append(" Battery time remaining: "); |
| 4284 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4285 | pw.println(sb.toString()); |
| 4286 | } |
| 4287 | if (chargeTimeRemaining >= 0) { |
| 4288 | sb.setLength(0); |
| 4289 | sb.append(prefix); |
| 4290 | sb.append(" Charge time remaining: "); |
| 4291 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4292 | pw.println(sb.toString()); |
| 4293 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4294 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4295 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4296 | if (dischargeCount >= 0) { |
| 4297 | sb.setLength(0); |
| 4298 | sb.append(prefix); |
| 4299 | sb.append(" Discharge: "); |
| 4300 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4301 | sb.append(" mAh"); |
| 4302 | pw.println(sb.toString()); |
| 4303 | } |
| 4304 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4305 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4306 | if (dischargeScreenOffCount >= 0) { |
| 4307 | sb.setLength(0); |
| 4308 | sb.append(prefix); |
| 4309 | sb.append(" Screen off discharge: "); |
| 4310 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4311 | sb.append(" mAh"); |
| 4312 | pw.println(sb.toString()); |
| 4313 | } |
| 4314 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4315 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4316 | if (dischargeScreenDozeCount >= 0) { |
| 4317 | sb.setLength(0); |
| 4318 | sb.append(prefix); |
| 4319 | sb.append(" Screen doze discharge: "); |
| 4320 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4321 | sb.append(" mAh"); |
| 4322 | pw.println(sb.toString()); |
| 4323 | } |
| 4324 | |
| 4325 | final long dischargeScreenOnCount = |
| 4326 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4327 | if (dischargeScreenOnCount >= 0) { |
| 4328 | sb.setLength(0); |
| 4329 | sb.append(prefix); |
| 4330 | sb.append(" Screen on discharge: "); |
| 4331 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4332 | sb.append(" mAh"); |
| 4333 | pw.println(sb.toString()); |
| 4334 | } |
| 4335 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4336 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4337 | if (dischargeLightDozeCount >= 0) { |
| 4338 | sb.setLength(0); |
| 4339 | sb.append(prefix); |
| 4340 | sb.append(" Device light doze discharge: "); |
| 4341 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4342 | sb.append(" mAh"); |
| 4343 | pw.println(sb.toString()); |
| 4344 | } |
| 4345 | |
| 4346 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4347 | if (dischargeDeepDozeCount >= 0) { |
| 4348 | sb.setLength(0); |
| 4349 | sb.append(prefix); |
| 4350 | sb.append(" Device deep doze discharge: "); |
| 4351 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4352 | sb.append(" mAh"); |
| 4353 | pw.println(sb.toString()); |
| 4354 | } |
| 4355 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4356 | pw.print(" Start clock time: "); |
| 4357 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4358 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4359 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4360 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4361 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4362 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4363 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4364 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4365 | rawRealtime, which); |
| 4366 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4367 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4368 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4369 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4370 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4371 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4372 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4373 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4374 | sb.append(prefix); |
| 4375 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4376 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4377 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4378 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4379 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4380 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4381 | pw.println(sb.toString()); |
| 4382 | sb.setLength(0); |
| 4383 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4384 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4385 | boolean didOne = false; |
| 4386 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4387 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4388 | if (time == 0) { |
| 4389 | continue; |
| 4390 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4391 | sb.append("\n "); |
| 4392 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4393 | didOne = true; |
| 4394 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4395 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4396 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4397 | sb.append("("); |
| 4398 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4399 | sb.append(")"); |
| 4400 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4401 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4402 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4403 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4404 | sb.setLength(0); |
| 4405 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4406 | sb.append(" Power save mode enabled: "); |
| 4407 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4408 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4409 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4410 | sb.append(")"); |
| 4411 | pw.println(sb.toString()); |
| 4412 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4413 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4414 | sb.setLength(0); |
| 4415 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4416 | sb.append(" Device light idling: "); |
| 4417 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4418 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4419 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4420 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4421 | sb.append("x"); |
| 4422 | pw.println(sb.toString()); |
| 4423 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4424 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4425 | sb.setLength(0); |
| 4426 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4427 | sb.append(" Idle mode light time: "); |
| 4428 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4429 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4430 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4431 | sb.append(") "); |
| 4432 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4433 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4434 | sb.append(" -- longest "); |
| 4435 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4436 | pw.println(sb.toString()); |
| 4437 | } |
| 4438 | if (deviceIdlingTime != 0) { |
| 4439 | sb.setLength(0); |
| 4440 | sb.append(prefix); |
| 4441 | sb.append(" Device full idling: "); |
| 4442 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4443 | sb.append("("); |
| 4444 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4445 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4446 | sb.append("x"); |
| 4447 | pw.println(sb.toString()); |
| 4448 | } |
| 4449 | if (deviceIdleModeFullTime != 0) { |
| 4450 | sb.setLength(0); |
| 4451 | sb.append(prefix); |
| 4452 | sb.append(" Idle mode full time: "); |
| 4453 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4454 | sb.append("("); |
| 4455 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4456 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4457 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4458 | sb.append("x"); |
| 4459 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4460 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4461 | pw.println(sb.toString()); |
| 4462 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4463 | if (phoneOnTime != 0) { |
| 4464 | sb.setLength(0); |
| 4465 | sb.append(prefix); |
| 4466 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4467 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4468 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4469 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4470 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4471 | if (connChanges != 0) { |
| 4472 | pw.print(prefix); |
| 4473 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4474 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4475 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4476 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4477 | long fullWakeLockTimeTotalMicros = 0; |
| 4478 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4479 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4480 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4481 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4482 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4483 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4484 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4485 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4486 | = u.getWakelockStats(); |
| 4487 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4488 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4489 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4490 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4491 | if (fullWakeTimer != null) { |
| 4492 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4493 | rawRealtime, which); |
| 4494 | } |
| 4495 | |
| 4496 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4497 | if (partialWakeTimer != null) { |
| 4498 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4499 | rawRealtime, which); |
| 4500 | if (totalTimeMicros > 0) { |
| 4501 | if (reqUid < 0) { |
| 4502 | // Only show the ordered list of all wake |
| 4503 | // locks if the caller is not asking for data |
| 4504 | // about a specific uid. |
| 4505 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4506 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4507 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4508 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | } |
| 4512 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4513 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4514 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4515 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4516 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4517 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4518 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4519 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4520 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4521 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4522 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4523 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4524 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4525 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4526 | sb.setLength(0); |
| 4527 | sb.append(prefix); |
| 4528 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4529 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4530 | pw.println(sb.toString()); |
| 4531 | } |
| 4532 | |
| 4533 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4534 | sb.setLength(0); |
| 4535 | sb.append(prefix); |
| 4536 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4537 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4538 | pw.println(sb.toString()); |
| 4539 | } |
| 4540 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4541 | final long multicastWakeLockTimeTotalMicros = |
| 4542 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4543 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4544 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4545 | sb.setLength(0); |
| 4546 | sb.append(prefix); |
| 4547 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4548 | sb.append(multicastWakeLockCountTotal); |
| 4549 | pw.println(sb.toString()); |
| 4550 | |
| 4551 | sb.setLength(0); |
| 4552 | sb.append(prefix); |
| 4553 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4554 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4555 | pw.println(sb.toString()); |
| 4556 | } |
| 4557 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4558 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4559 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4560 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4561 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4562 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4563 | pw.println(sb.toString()); |
| 4564 | |
| 4565 | pw.print(prefix); |
| 4566 | sb.setLength(0); |
| 4567 | sb.append(prefix); |
| 4568 | sb.append(" Logging duration for connectivity statistics: "); |
| 4569 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4570 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4571 | |
| 4572 | sb.setLength(0); |
| 4573 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4574 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4575 | pw.println(sb.toString()); |
| 4576 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4577 | pw.print(prefix); |
| 4578 | sb.setLength(0); |
| 4579 | sb.append(prefix); |
| 4580 | sb.append(" Cellular kernel active time: "); |
| 4581 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4582 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4583 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4584 | sb.append(")"); |
| 4585 | pw.println(sb.toString()); |
| 4586 | |
| 4587 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4588 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4589 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4590 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4591 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4592 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4593 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4594 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4595 | didOne = false; |
| 4596 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4597 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4598 | if (time == 0) { |
| 4599 | continue; |
| 4600 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4601 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4602 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4603 | didOne = true; |
| 4604 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4605 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4606 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4607 | sb.append("("); |
| 4608 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4609 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4610 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4611 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4612 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4613 | |
| 4614 | sb.setLength(0); |
| 4615 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4616 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4617 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4618 | "very poor (less than -128dBm): ", |
| 4619 | "poor (-128dBm to -118dBm): ", |
| 4620 | "moderate (-118dBm to -108dBm): ", |
| 4621 | "good (-108dBm to -98dBm): ", |
| 4622 | "great (greater than -98dBm): "}; |
| 4623 | didOne = false; |
| 4624 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4625 | cellularRxSignalStrengthDescription.length); |
| 4626 | for (int i=0; i<numCellularRxBins; i++) { |
| 4627 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4628 | if (time == 0) { |
| 4629 | continue; |
| 4630 | } |
| 4631 | sb.append("\n "); |
| 4632 | sb.append(prefix); |
| 4633 | didOne = true; |
| 4634 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4635 | sb.append(" "); |
| 4636 | formatTimeMs(sb, time/1000); |
| 4637 | sb.append("("); |
| 4638 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4639 | sb.append(") "); |
| 4640 | } |
| 4641 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4642 | pw.println(sb.toString()); |
| 4643 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4644 | printControllerActivity(pw, sb, prefix, "Cellular", |
| 4645 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4646 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4647 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4648 | sb.setLength(0); |
| 4649 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4650 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4651 | pw.println(sb.toString()); |
| 4652 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4653 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4654 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4655 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4656 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4657 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4658 | sb.setLength(0); |
| 4659 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4660 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4661 | didOne = false; |
| 4662 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4663 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4664 | if (time == 0) { |
| 4665 | continue; |
| 4666 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4667 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4668 | didOne = true; |
| 4669 | sb.append(WIFI_STATE_NAMES[i]); |
| 4670 | sb.append(" "); |
| 4671 | formatTimeMs(sb, time/1000); |
| 4672 | sb.append("("); |
| 4673 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4674 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4675 | } |
| 4676 | if (!didOne) sb.append(" (no activity)"); |
| 4677 | pw.println(sb.toString()); |
| 4678 | |
| 4679 | sb.setLength(0); |
| 4680 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4681 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4682 | didOne = false; |
| 4683 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4684 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4685 | if (time == 0) { |
| 4686 | continue; |
| 4687 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4688 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4689 | didOne = true; |
| 4690 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4691 | sb.append(" "); |
| 4692 | formatTimeMs(sb, time/1000); |
| 4693 | sb.append("("); |
| 4694 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4695 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4696 | } |
| 4697 | if (!didOne) sb.append(" (no activity)"); |
| 4698 | pw.println(sb.toString()); |
| 4699 | |
| 4700 | sb.setLength(0); |
| 4701 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4702 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4703 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4704 | "very poor (less than -88.75dBm): ", |
| 4705 | "poor (-88.75 to -77.5dBm): ", |
| 4706 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4707 | "good (-66.25dBm to -55dBm): ", |
| 4708 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4709 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4710 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4711 | wifiRxSignalStrengthDescription.length); |
| 4712 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4713 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4714 | if (time == 0) { |
| 4715 | continue; |
| 4716 | } |
| 4717 | sb.append("\n "); |
| 4718 | sb.append(prefix); |
| 4719 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4720 | sb.append(" "); |
| 4721 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4722 | formatTimeMs(sb, time/1000); |
| 4723 | sb.append("("); |
| 4724 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4725 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4726 | } |
| 4727 | if (!didOne) sb.append(" (no activity)"); |
| 4728 | pw.println(sb.toString()); |
| 4729 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4730 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4731 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4732 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4733 | sb.setLength(0); |
| 4734 | sb.append(prefix); |
| 4735 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4736 | pw.println(sb.toString()); |
| 4737 | pw.println(""); |
| 4738 | |
| 4739 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4740 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4741 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4742 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4743 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4744 | sb.setLength(0); |
| 4745 | sb.append(prefix); |
| 4746 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4747 | pw.println(sb.toString()); |
| 4748 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4749 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4750 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4751 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4752 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4753 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4754 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4755 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4756 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4757 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4758 | pw.println(getDischargeStartLevel()); |
| 4759 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4760 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4761 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4762 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4763 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4764 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4765 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4766 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4767 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4768 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4769 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4770 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4771 | pw.println(getDischargeAmountScreenOff()); |
| 4772 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4773 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4774 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4775 | } else { |
| 4776 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4777 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4778 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4779 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4780 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4781 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4782 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4783 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4784 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4785 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4786 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4787 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4788 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4789 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4790 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4791 | helper.create(this); |
| 4792 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4793 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4794 | if (sippers != null && sippers.size() > 0) { |
| 4795 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4796 | pw.print(prefix); pw.print(" Capacity: "); |
| 4797 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4798 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4799 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4800 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4801 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4802 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4803 | pw.println(); |
| 4804 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4805 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4806 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4807 | switch (bs.drainType) { |
| 4808 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4809 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4810 | break; |
| 4811 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4812 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4813 | break; |
| 4814 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4815 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4816 | break; |
| 4817 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4818 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4819 | break; |
| 4820 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4821 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4822 | break; |
| 4823 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4824 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4825 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4826 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4827 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4828 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4829 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4830 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4831 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4832 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4833 | break; |
| 4834 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4835 | pw.print(" User "); pw.print(bs.userId); |
| 4836 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4837 | break; |
| 4838 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4839 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4840 | break; |
| 4841 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4842 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4843 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4844 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4845 | pw.print(" Camera: "); |
| 4846 | break; |
| 4847 | default: |
| 4848 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4849 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4850 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4851 | printmAh(pw, bs.totalPowerMah); |
| 4852 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4853 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4854 | // If the usage (generic power) isn't the whole amount, we list out |
| 4855 | // what components are involved in the calculation. |
| 4856 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4857 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4858 | if (bs.usagePowerMah != 0) { |
| 4859 | pw.print(" usage="); |
| 4860 | printmAh(pw, bs.usagePowerMah); |
| 4861 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4862 | if (bs.cpuPowerMah != 0) { |
| 4863 | pw.print(" cpu="); |
| 4864 | printmAh(pw, bs.cpuPowerMah); |
| 4865 | } |
| 4866 | if (bs.wakeLockPowerMah != 0) { |
| 4867 | pw.print(" wake="); |
| 4868 | printmAh(pw, bs.wakeLockPowerMah); |
| 4869 | } |
| 4870 | if (bs.mobileRadioPowerMah != 0) { |
| 4871 | pw.print(" radio="); |
| 4872 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4873 | } |
| 4874 | if (bs.wifiPowerMah != 0) { |
| 4875 | pw.print(" wifi="); |
| 4876 | printmAh(pw, bs.wifiPowerMah); |
| 4877 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4878 | if (bs.bluetoothPowerMah != 0) { |
| 4879 | pw.print(" bt="); |
| 4880 | printmAh(pw, bs.bluetoothPowerMah); |
| 4881 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4882 | if (bs.gpsPowerMah != 0) { |
| 4883 | pw.print(" gps="); |
| 4884 | printmAh(pw, bs.gpsPowerMah); |
| 4885 | } |
| 4886 | if (bs.sensorPowerMah != 0) { |
| 4887 | pw.print(" sensor="); |
| 4888 | printmAh(pw, bs.sensorPowerMah); |
| 4889 | } |
| 4890 | if (bs.cameraPowerMah != 0) { |
| 4891 | pw.print(" camera="); |
| 4892 | printmAh(pw, bs.cameraPowerMah); |
| 4893 | } |
| 4894 | if (bs.flashlightPowerMah != 0) { |
| 4895 | pw.print(" flash="); |
| 4896 | printmAh(pw, bs.flashlightPowerMah); |
| 4897 | } |
| 4898 | pw.print(" )"); |
| 4899 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4900 | |
| 4901 | // If there is additional smearing information, include it. |
| 4902 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4903 | pw.print(" Including smearing: "); |
| 4904 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4905 | pw.print(" ("); |
| 4906 | if (bs.screenPowerMah != 0) { |
| 4907 | pw.print(" screen="); |
| 4908 | printmAh(pw, bs.screenPowerMah); |
| 4909 | } |
| 4910 | if (bs.proportionalSmearMah != 0) { |
| 4911 | pw.print(" proportional="); |
| 4912 | printmAh(pw, bs.proportionalSmearMah); |
| 4913 | } |
| 4914 | pw.print(" )"); |
| 4915 | } |
| 4916 | if (bs.shouldHide) { |
| 4917 | pw.print(" Excluded from smearing"); |
| 4918 | } |
| 4919 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4920 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4921 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4922 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4923 | } |
| 4924 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4925 | sippers = helper.getMobilemsppList(); |
| 4926 | if (sippers != null && sippers.size() > 0) { |
| 4927 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4928 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4929 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4930 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4931 | sb.setLength(0); |
| 4932 | sb.append(prefix); sb.append(" Uid "); |
| 4933 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4934 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4935 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4936 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4937 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4938 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4939 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4940 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4941 | sb.setLength(0); |
| 4942 | sb.append(prefix); |
| 4943 | sb.append(" TOTAL TIME: "); |
| 4944 | formatTimeMs(sb, totalTime); |
| 4945 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4946 | sb.append(")"); |
| 4947 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4948 | pw.println(); |
| 4949 | } |
| 4950 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4951 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4952 | @Override |
| 4953 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4954 | long lhsTime = lhs.mTime; |
| 4955 | long rhsTime = rhs.mTime; |
| 4956 | if (lhsTime < rhsTime) { |
| 4957 | return 1; |
| 4958 | } |
| 4959 | if (lhsTime > rhsTime) { |
| 4960 | return -1; |
| 4961 | } |
| 4962 | return 0; |
| 4963 | } |
| 4964 | }; |
| 4965 | |
| 4966 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4967 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4968 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4969 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4970 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4971 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4972 | : kernelWakelocks.entrySet()) { |
| 4973 | final BatteryStats.Timer timer = ent.getValue(); |
| 4974 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4975 | if (totalTimeMillis > 0) { |
| 4976 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4977 | } |
| 4978 | } |
| 4979 | if (ktimers.size() > 0) { |
| 4980 | Collections.sort(ktimers, timerComparator); |
| 4981 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4982 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4983 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4984 | String linePrefix = ": "; |
| 4985 | sb.setLength(0); |
| 4986 | sb.append(prefix); |
| 4987 | sb.append(" Kernel Wake lock "); |
| 4988 | sb.append(timer.mName); |
| 4989 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4990 | which, linePrefix); |
| 4991 | if (!linePrefix.equals(": ")) { |
| 4992 | sb.append(" realtime"); |
| 4993 | // Only print out wake locks that were held |
| 4994 | pw.println(sb.toString()); |
| 4995 | } |
| 4996 | } |
| 4997 | pw.println(); |
| 4998 | } |
| 4999 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5000 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5001 | if (timers.size() > 0) { |
| 5002 | Collections.sort(timers, timerComparator); |
| 5003 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5004 | for (int i=0; i<timers.size(); i++) { |
| 5005 | TimerEntry timer = timers.get(i); |
| 5006 | sb.setLength(0); |
| 5007 | sb.append(" Wake lock "); |
| 5008 | UserHandle.formatUid(sb, timer.mId); |
| 5009 | sb.append(" "); |
| 5010 | sb.append(timer.mName); |
| 5011 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5012 | sb.append(" realtime"); |
| 5013 | pw.println(sb.toString()); |
| 5014 | } |
| 5015 | timers.clear(); |
| 5016 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5017 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5018 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5019 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5020 | if (wakeupReasons.size() > 0) { |
| 5021 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5022 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5023 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5024 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5025 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5026 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5027 | } |
| 5028 | Collections.sort(reasons, timerComparator); |
| 5029 | for (int i=0; i<reasons.size(); i++) { |
| 5030 | TimerEntry timer = reasons.get(i); |
| 5031 | String linePrefix = ": "; |
| 5032 | sb.setLength(0); |
| 5033 | sb.append(prefix); |
| 5034 | sb.append(" Wakeup reason "); |
| 5035 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5036 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5037 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5038 | pw.println(sb.toString()); |
| 5039 | } |
| 5040 | pw.println(); |
| 5041 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5042 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5043 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5044 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5045 | if (mMemoryStats.size() > 0) { |
| 5046 | pw.println(" Memory Stats"); |
| 5047 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5048 | sb.setLength(0); |
| 5049 | sb.append(" Bandwidth "); |
| 5050 | sb.append(mMemoryStats.keyAt(i)); |
| 5051 | sb.append(" Time "); |
| 5052 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5053 | pw.println(sb.toString()); |
| 5054 | } |
| 5055 | pw.println(); |
| 5056 | } |
| 5057 | |
| 5058 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5059 | if (rpmStats.size() > 0) { |
| 5060 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5061 | if (rpmStats.size() > 0) { |
| 5062 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5063 | final String timerName = ent.getKey(); |
| 5064 | final Timer timer = ent.getValue(); |
| 5065 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5066 | } |
| 5067 | } |
| 5068 | pw.println(); |
| 5069 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5070 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5071 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5072 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5073 | pw.print(prefix); |
| 5074 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5075 | if (screenOffRpmStats.size() > 0) { |
| 5076 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5077 | final String timerName = ent.getKey(); |
| 5078 | final Timer timer = ent.getValue(); |
| 5079 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5080 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5081 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5082 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5083 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5086 | final long[] cpuFreqs = getCpuFreqs(); |
| 5087 | if (cpuFreqs != null) { |
| 5088 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5089 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5090 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5091 | sb.append(" " + cpuFreqs[i]); |
| 5092 | } |
| 5093 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5094 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | for (int iu=0; iu<NU; iu++) { |
| 5098 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5099 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5100 | continue; |
| 5101 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5102 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5103 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5104 | |
| 5105 | pw.print(prefix); |
| 5106 | pw.print(" "); |
| 5107 | UserHandle.formatUid(pw, uid); |
| 5108 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5109 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5110 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5111 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5112 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5113 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5114 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5115 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5116 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5117 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5118 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5119 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5120 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5121 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5122 | |
| 5123 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5124 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5125 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5126 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5127 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5128 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5129 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5130 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5131 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5132 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5133 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5134 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5135 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5136 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5137 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5138 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5139 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5140 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5141 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5142 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5143 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5144 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5145 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5146 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5147 | sb.setLength(0); |
| 5148 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5149 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5150 | sb.append("("); |
| 5151 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5152 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5153 | long packets = mobileRxPackets + mobileTxPackets; |
| 5154 | if (packets == 0) { |
| 5155 | packets = 1; |
| 5156 | } |
| 5157 | sb.append(" @ "); |
| 5158 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5159 | sb.append(" mspp"); |
| 5160 | pw.println(sb.toString()); |
| 5161 | } |
| 5162 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5163 | if (mobileWakeup > 0) { |
| 5164 | sb.setLength(0); |
| 5165 | sb.append(prefix); |
| 5166 | sb.append(" Mobile radio AP wakeups: "); |
| 5167 | sb.append(mobileWakeup); |
| 5168 | pw.println(sb.toString()); |
| 5169 | } |
| 5170 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5171 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 5172 | u.getModemControllerActivity(), which); |
| 5173 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5174 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5175 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5176 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5177 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5178 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5179 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5182 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5183 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5184 | || uidWifiRunningTime != 0) { |
| 5185 | sb.setLength(0); |
| 5186 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5187 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5188 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5189 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5190 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5191 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5192 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5193 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5194 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5195 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5196 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5197 | whichBatteryRealtime)); sb.append(") "); |
| 5198 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5199 | sb.append("x\n"); |
| 5200 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5201 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5202 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5203 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5204 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5205 | sb.append(") "); |
| 5206 | sb.append(wifiScanCount); |
| 5207 | sb.append("x\n"); |
| 5208 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5209 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5210 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5211 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5212 | sb.append(") "); |
| 5213 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5214 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5215 | pw.println(sb.toString()); |
| 5216 | } |
| 5217 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5218 | if (wifiWakeup > 0) { |
| 5219 | sb.setLength(0); |
| 5220 | sb.append(prefix); |
| 5221 | sb.append(" WiFi AP wakeups: "); |
| 5222 | sb.append(wifiWakeup); |
| 5223 | pw.println(sb.toString()); |
| 5224 | } |
| 5225 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5226 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 5227 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5228 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5229 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5230 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5231 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5232 | pw.print(formatBytesLocked(btTxBytes)); |
| 5233 | pw.println(" sent"); |
| 5234 | } |
| 5235 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5236 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5237 | if (bleTimer != null) { |
| 5238 | // Convert from microseconds to milliseconds with rounding |
| 5239 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5240 | / 1000; |
| 5241 | if (totalTimeMs != 0) { |
| 5242 | final int count = bleTimer.getCountLocked(which); |
| 5243 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5244 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5245 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5246 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5247 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5248 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5249 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5250 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5251 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5252 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5253 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5254 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5255 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5256 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5257 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5258 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5259 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5260 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5261 | final Timer unoptimizedScanTimerBg = |
| 5262 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5263 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5264 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5265 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5266 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5267 | |
| 5268 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5269 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5270 | sb.append(prefix); |
| 5271 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5272 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5273 | sb.append(" ("); |
| 5274 | sb.append(count); |
| 5275 | sb.append(" times)"); |
| 5276 | if (bleTimer.isRunningLocked()) { |
| 5277 | sb.append(" (currently running)"); |
| 5278 | } |
| 5279 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5280 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5281 | |
| 5282 | sb.append(prefix); |
| 5283 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5284 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5285 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5286 | sb.append(count); |
| 5287 | sb.append(" times)"); |
| 5288 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5289 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5290 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5291 | sb.append("\n"); |
| 5292 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5293 | sb.append(prefix); |
| 5294 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5295 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5296 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5297 | sb.append(countBg); |
| 5298 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5299 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5300 | sb.append(" (currently running in background)"); |
| 5301 | } |
| 5302 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5303 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5304 | |
| 5305 | sb.append(prefix); |
| 5306 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5307 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5308 | sb.append(" ("); |
| 5309 | sb.append(resultCountBg); |
| 5310 | sb.append(" in background)"); |
| 5311 | |
| 5312 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5313 | sb.append("\n"); |
| 5314 | sb.append(prefix); |
| 5315 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5316 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5317 | sb.append(" (max "); |
| 5318 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5319 | sb.append(")"); |
| 5320 | if (unoptimizedScanTimer != null |
| 5321 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5322 | sb.append(" (currently running unoptimized)"); |
| 5323 | } |
| 5324 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5325 | sb.append("\n"); |
| 5326 | sb.append(prefix); |
| 5327 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5328 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5329 | sb.append(" (max "); |
| 5330 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5331 | sb.append(")"); |
| 5332 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5333 | sb.append(" (currently running unoptimized in background)"); |
| 5334 | } |
| 5335 | } |
| 5336 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5337 | pw.println(sb.toString()); |
| 5338 | uidActivity = true; |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5343 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5344 | if (u.hasUserActivity()) { |
| 5345 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5346 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5347 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5348 | if (val != 0) { |
| 5349 | if (!hasData) { |
| 5350 | sb.setLength(0); |
| 5351 | sb.append(" User activity: "); |
| 5352 | hasData = true; |
| 5353 | } else { |
| 5354 | sb.append(", "); |
| 5355 | } |
| 5356 | sb.append(val); |
| 5357 | sb.append(" "); |
| 5358 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5359 | } |
| 5360 | } |
| 5361 | if (hasData) { |
| 5362 | pw.println(sb.toString()); |
| 5363 | } |
| 5364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5365 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5366 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5367 | = u.getWakelockStats(); |
| 5368 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5369 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5370 | int countWakelock = 0; |
| 5371 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5372 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5373 | String linePrefix = ": "; |
| 5374 | sb.setLength(0); |
| 5375 | sb.append(prefix); |
| 5376 | sb.append(" Wake lock "); |
| 5377 | sb.append(wakelocks.keyAt(iw)); |
| 5378 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5379 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5380 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5381 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5382 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5383 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5384 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5385 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5386 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5387 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5388 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5389 | sb.append(" realtime"); |
| 5390 | pw.println(sb.toString()); |
| 5391 | uidActivity = true; |
| 5392 | countWakelock++; |
| 5393 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5394 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5395 | rawRealtime, which); |
| 5396 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5397 | rawRealtime, which); |
| 5398 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5399 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5400 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5401 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5402 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5403 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5404 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5405 | // pooled and therefore just a lower bound) |
| 5406 | long actualTotalPartialWakelock = 0; |
| 5407 | long actualBgPartialWakelock = 0; |
| 5408 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5409 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5410 | // Convert from microseconds to milliseconds with rounding |
| 5411 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5412 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5413 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5414 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5415 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5419 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5420 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5421 | sb.setLength(0); |
| 5422 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5423 | sb.append(" TOTAL wake: "); |
| 5424 | boolean needComma = false; |
| 5425 | if (totalFullWakelock != 0) { |
| 5426 | needComma = true; |
| 5427 | formatTimeMs(sb, totalFullWakelock); |
| 5428 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5429 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5430 | if (totalPartialWakelock != 0) { |
| 5431 | if (needComma) { |
| 5432 | sb.append(", "); |
| 5433 | } |
| 5434 | needComma = true; |
| 5435 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5436 | sb.append("blamed partial"); |
| 5437 | } |
| 5438 | if (actualTotalPartialWakelock != 0) { |
| 5439 | if (needComma) { |
| 5440 | sb.append(", "); |
| 5441 | } |
| 5442 | needComma = true; |
| 5443 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5444 | sb.append("actual partial"); |
| 5445 | } |
| 5446 | if (actualBgPartialWakelock != 0) { |
| 5447 | if (needComma) { |
| 5448 | sb.append(", "); |
| 5449 | } |
| 5450 | needComma = true; |
| 5451 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5452 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5453 | } |
| 5454 | if (totalWindowWakelock != 0) { |
| 5455 | if (needComma) { |
| 5456 | sb.append(", "); |
| 5457 | } |
| 5458 | needComma = true; |
| 5459 | formatTimeMs(sb, totalWindowWakelock); |
| 5460 | sb.append("window"); |
| 5461 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5462 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5463 | if (needComma) { |
| 5464 | sb.append(","); |
| 5465 | } |
| 5466 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5467 | formatTimeMs(sb, totalDrawWakelock); |
| 5468 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5469 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5470 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5471 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5475 | // Calculate multicast wakelock stats |
| 5476 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5477 | if (mcTimer != null) { |
| 5478 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5479 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5480 | |
| 5481 | if (multicastWakeLockTimeMicros > 0) { |
| 5482 | sb.setLength(0); |
| 5483 | sb.append(prefix); |
| 5484 | sb.append(" WiFi Multicast Wakelock"); |
| 5485 | sb.append(" count = "); |
| 5486 | sb.append(multicastWakeLockCount); |
| 5487 | sb.append(" time = "); |
| 5488 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5489 | pw.println(sb.toString()); |
| 5490 | } |
| 5491 | } |
| 5492 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5493 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5494 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5495 | final Timer timer = syncs.valueAt(isy); |
| 5496 | // Convert from microseconds to milliseconds with rounding |
| 5497 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5498 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5499 | final Timer bgTimer = timer.getSubTimer(); |
| 5500 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5501 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5502 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5503 | sb.setLength(0); |
| 5504 | sb.append(prefix); |
| 5505 | sb.append(" Sync "); |
| 5506 | sb.append(syncs.keyAt(isy)); |
| 5507 | sb.append(": "); |
| 5508 | if (totalTime != 0) { |
| 5509 | formatTimeMs(sb, totalTime); |
| 5510 | sb.append("realtime ("); |
| 5511 | sb.append(count); |
| 5512 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5513 | if (bgTime > 0) { |
| 5514 | sb.append(", "); |
| 5515 | formatTimeMs(sb, bgTime); |
| 5516 | sb.append("background ("); |
| 5517 | sb.append(bgCount); |
| 5518 | sb.append(" times)"); |
| 5519 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5520 | } else { |
| 5521 | sb.append("(not used)"); |
| 5522 | } |
| 5523 | pw.println(sb.toString()); |
| 5524 | uidActivity = true; |
| 5525 | } |
| 5526 | |
| 5527 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5528 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5529 | final Timer timer = jobs.valueAt(ij); |
| 5530 | // Convert from microseconds to milliseconds with rounding |
| 5531 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5532 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5533 | final Timer bgTimer = timer.getSubTimer(); |
| 5534 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5535 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5536 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5537 | sb.setLength(0); |
| 5538 | sb.append(prefix); |
| 5539 | sb.append(" Job "); |
| 5540 | sb.append(jobs.keyAt(ij)); |
| 5541 | sb.append(": "); |
| 5542 | if (totalTime != 0) { |
| 5543 | formatTimeMs(sb, totalTime); |
| 5544 | sb.append("realtime ("); |
| 5545 | sb.append(count); |
| 5546 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5547 | if (bgTime > 0) { |
| 5548 | sb.append(", "); |
| 5549 | formatTimeMs(sb, bgTime); |
| 5550 | sb.append("background ("); |
| 5551 | sb.append(bgCount); |
| 5552 | sb.append(" times)"); |
| 5553 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5554 | } else { |
| 5555 | sb.append("(not used)"); |
| 5556 | } |
| 5557 | pw.println(sb.toString()); |
| 5558 | uidActivity = true; |
| 5559 | } |
| 5560 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5561 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5562 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5563 | SparseIntArray types = completions.valueAt(ic); |
| 5564 | if (types != null) { |
| 5565 | pw.print(prefix); |
| 5566 | pw.print(" Job Completions "); |
| 5567 | pw.print(completions.keyAt(ic)); |
| 5568 | pw.print(":"); |
| 5569 | for (int it=0; it<types.size(); it++) { |
| 5570 | pw.print(" "); |
| 5571 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5572 | pw.print("("); |
| 5573 | pw.print(types.valueAt(it)); |
| 5574 | pw.print("x)"); |
| 5575 | } |
| 5576 | pw.println(); |
| 5577 | } |
| 5578 | } |
| 5579 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5580 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5581 | prefix, "Flashlight"); |
| 5582 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5583 | prefix, "Camera"); |
| 5584 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5585 | prefix, "Video"); |
| 5586 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5587 | prefix, "Audio"); |
| 5588 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5589 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5590 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5591 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5592 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5593 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5594 | sb.setLength(0); |
| 5595 | sb.append(prefix); |
| 5596 | sb.append(" Sensor "); |
| 5597 | int handle = se.getHandle(); |
| 5598 | if (handle == Uid.Sensor.GPS) { |
| 5599 | sb.append("GPS"); |
| 5600 | } else { |
| 5601 | sb.append(handle); |
| 5602 | } |
| 5603 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5604 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5605 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5606 | if (timer != null) { |
| 5607 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5608 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5609 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5610 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5611 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5612 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5613 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5614 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5615 | final long bgActualTime = bgTimer != null ? |
| 5616 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5617 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5618 | //timer.logState(); |
| 5619 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5620 | if (actualTime != totalTime) { |
| 5621 | formatTimeMs(sb, totalTime); |
| 5622 | sb.append("blamed realtime, "); |
| 5623 | } |
| 5624 | |
| 5625 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5626 | sb.append("realtime ("); |
| 5627 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5628 | sb.append(" times)"); |
| 5629 | |
| 5630 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5631 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5632 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5633 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5634 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5635 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | } else { |
| 5638 | sb.append("(not used)"); |
| 5639 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5640 | } else { |
| 5641 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5643 | |
| 5644 | pw.println(sb.toString()); |
| 5645 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5646 | } |
| 5647 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5648 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5649 | "Vibrator"); |
| 5650 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5651 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5652 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5653 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5654 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5655 | long totalStateTime = 0; |
| 5656 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5657 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5658 | if (time > 0) { |
| 5659 | totalStateTime += time; |
| 5660 | sb.setLength(0); |
| 5661 | sb.append(prefix); |
| 5662 | sb.append(" "); |
| 5663 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5664 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5665 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5666 | pw.println(sb.toString()); |
| 5667 | uidActivity = true; |
| 5668 | } |
| 5669 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5670 | if (totalStateTime > 0) { |
| 5671 | sb.setLength(0); |
| 5672 | sb.append(prefix); |
| 5673 | sb.append(" Total running: "); |
| 5674 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5675 | pw.println(sb.toString()); |
| 5676 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5677 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5678 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5679 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5680 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5681 | sb.setLength(0); |
| 5682 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5683 | sb.append(" Total cpu time: u="); |
| 5684 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5685 | sb.append("s="); |
| 5686 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5687 | pw.println(sb.toString()); |
| 5688 | } |
| 5689 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5690 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5691 | if (cpuFreqTimes != null) { |
| 5692 | sb.setLength(0); |
| 5693 | sb.append(" Total cpu time per freq:"); |
| 5694 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5695 | sb.append(" " + cpuFreqTimes[i]); |
| 5696 | } |
| 5697 | pw.println(sb.toString()); |
| 5698 | } |
| 5699 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5700 | if (screenOffCpuFreqTimes != null) { |
| 5701 | sb.setLength(0); |
| 5702 | sb.append(" Total screen-off cpu time per freq:"); |
| 5703 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5704 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5705 | } |
| 5706 | pw.println(sb.toString()); |
| 5707 | } |
| 5708 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5709 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5710 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5711 | if (cpuTimes != null) { |
| 5712 | sb.setLength(0); |
| 5713 | sb.append(" Cpu times per freq at state " |
| 5714 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5715 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5716 | sb.append(" " + cpuTimes[i]); |
| 5717 | } |
| 5718 | pw.println(sb.toString()); |
| 5719 | } |
| 5720 | |
| 5721 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5722 | if (screenOffCpuTimes != null) { |
| 5723 | sb.setLength(0); |
| 5724 | sb.append(" Screen-off cpu times per freq at state " |
| 5725 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5726 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5727 | sb.append(" " + screenOffCpuTimes[i]); |
| 5728 | } |
| 5729 | pw.println(sb.toString()); |
| 5730 | } |
| 5731 | } |
| 5732 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5733 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5734 | = u.getProcessStats(); |
| 5735 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5736 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5737 | long userTime; |
| 5738 | long systemTime; |
| 5739 | long foregroundTime; |
| 5740 | int starts; |
| 5741 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5742 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5743 | userTime = ps.getUserTime(which); |
| 5744 | systemTime = ps.getSystemTime(which); |
| 5745 | foregroundTime = ps.getForegroundTime(which); |
| 5746 | starts = ps.getStarts(which); |
| 5747 | final int numCrashes = ps.getNumCrashes(which); |
| 5748 | final int numAnrs = ps.getNumAnrs(which); |
| 5749 | numExcessive = which == STATS_SINCE_CHARGED |
| 5750 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5752 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5753 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5754 | sb.setLength(0); |
| 5755 | sb.append(prefix); sb.append(" Proc "); |
| 5756 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5757 | sb.append(prefix); sb.append(" CPU: "); |
| 5758 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5759 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5760 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5761 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5762 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5763 | boolean hasOne = false; |
| 5764 | if (starts != 0) { |
| 5765 | hasOne = true; |
| 5766 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5767 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5768 | if (numCrashes != 0) { |
| 5769 | if (hasOne) { |
| 5770 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5771 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5772 | hasOne = true; |
| 5773 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5774 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5775 | if (numAnrs != 0) { |
| 5776 | if (hasOne) { |
| 5777 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5779 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | } |
| 5781 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5782 | pw.println(sb.toString()); |
| 5783 | for (int e=0; e<numExcessive; e++) { |
| 5784 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5785 | if (ew != null) { |
| 5786 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5787 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5788 | pw.print("cpu"); |
| 5789 | } else { |
| 5790 | pw.print("unknown"); |
| 5791 | } |
| 5792 | pw.print(" use: "); |
| 5793 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5794 | pw.print(" over "); |
| 5795 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5796 | if (ew.overTime != 0) { |
| 5797 | pw.print(" ("); |
| 5798 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5799 | pw.println("%)"); |
| 5800 | } |
| 5801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | } |
| 5803 | uidActivity = true; |
| 5804 | } |
| 5805 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5806 | |
| 5807 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5808 | = u.getPackageStats(); |
| 5809 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5810 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5811 | pw.println(":"); |
| 5812 | boolean apkActivity = false; |
| 5813 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5814 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5815 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5816 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5817 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5818 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5819 | pw.println(" times"); |
| 5820 | apkActivity = true; |
| 5821 | } |
| 5822 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5823 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5824 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5825 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5826 | final int starts = ss.getStarts(which); |
| 5827 | final int launches = ss.getLaunches(which); |
| 5828 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5829 | sb.setLength(0); |
| 5830 | sb.append(prefix); sb.append(" Service "); |
| 5831 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5832 | sb.append(prefix); sb.append(" Created for: "); |
| 5833 | formatTimeMs(sb, startTime / 1000); |
| 5834 | sb.append("uptime\n"); |
| 5835 | sb.append(prefix); sb.append(" Starts: "); |
| 5836 | sb.append(starts); |
| 5837 | sb.append(", launches: "); sb.append(launches); |
| 5838 | pw.println(sb.toString()); |
| 5839 | apkActivity = true; |
| 5840 | } |
| 5841 | } |
| 5842 | if (!apkActivity) { |
| 5843 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5844 | } |
| 5845 | uidActivity = true; |
| 5846 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5847 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5848 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5853 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5854 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5855 | int diff = oldval ^ newval; |
| 5856 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5857 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5858 | for (int i=0; i<descriptions.length; i++) { |
| 5859 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5860 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5861 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5862 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5863 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5864 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5865 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5866 | didWake = true; |
| 5867 | pw.print("="); |
| 5868 | if (longNames) { |
| 5869 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5870 | pw.print(":\""); |
| 5871 | pw.print(wakelockTag.string); |
| 5872 | pw.print("\""); |
| 5873 | } else { |
| 5874 | pw.print(wakelockTag.poolIdx); |
| 5875 | } |
| 5876 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5877 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5878 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5879 | pw.print("="); |
| 5880 | int val = (newval&bd.mask)>>bd.shift; |
| 5881 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5882 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5883 | } else { |
| 5884 | pw.print(val); |
| 5885 | } |
| 5886 | } |
| 5887 | } |
| 5888 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5889 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5890 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5891 | if (longNames) { |
| 5892 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5893 | pw.print(":\""); |
| 5894 | pw.print(wakelockTag.string); |
| 5895 | pw.print("\""); |
| 5896 | } else { |
| 5897 | pw.print(wakelockTag.poolIdx); |
| 5898 | } |
| 5899 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5900 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5901 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5902 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 5903 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | public static class HistoryPrinter { |
| 5907 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5908 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5909 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5910 | int oldStatus = -1; |
| 5911 | int oldHealth = -1; |
| 5912 | int oldPlug = -1; |
| 5913 | int oldTemp = -1; |
| 5914 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5915 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5916 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5917 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5918 | void reset() { |
| 5919 | oldState = oldState2 = 0; |
| 5920 | oldLevel = -1; |
| 5921 | oldStatus = -1; |
| 5922 | oldHealth = -1; |
| 5923 | oldPlug = -1; |
| 5924 | oldTemp = -1; |
| 5925 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5926 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5929 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5930 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5931 | if (!checkin) { |
| 5932 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5933 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5934 | pw.print(" ("); |
| 5935 | pw.print(rec.numReadInts); |
| 5936 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5937 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5938 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5939 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5940 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5941 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5942 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5943 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5944 | } |
| 5945 | lastTime = rec.time; |
| 5946 | } |
| 5947 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5948 | if (checkin) { |
| 5949 | pw.print(":"); |
| 5950 | } |
| 5951 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5952 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5953 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5954 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5955 | if (checkin) { |
| 5956 | pw.print(":"); |
| 5957 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5958 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5959 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5960 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5961 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5962 | pw.print("TIME:"); |
| 5963 | if (checkin) { |
| 5964 | pw.println(rec.currentTime); |
| 5965 | } else { |
| 5966 | pw.print(" "); |
| 5967 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5968 | rec.currentTime).toString()); |
| 5969 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5970 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5971 | if (checkin) { |
| 5972 | pw.print(":"); |
| 5973 | } |
| 5974 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5975 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5976 | if (checkin) { |
| 5977 | pw.print(":"); |
| 5978 | } |
| 5979 | pw.println("*OVERFLOW*"); |
| 5980 | } else { |
| 5981 | if (!checkin) { |
| 5982 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5983 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5984 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5985 | if (verbose) { |
| 5986 | pw.print(" "); |
| 5987 | if (rec.states < 0) ; |
| 5988 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5989 | else if (rec.states < 0x100) pw.print("000000"); |
| 5990 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5991 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5992 | else if (rec.states < 0x100000) pw.print("000"); |
| 5993 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5994 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5995 | pw.print(Integer.toHexString(rec.states)); |
| 5996 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5997 | } else { |
| 5998 | if (oldLevel != rec.batteryLevel) { |
| 5999 | oldLevel = rec.batteryLevel; |
| 6000 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 6001 | } |
| 6002 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6003 | if (oldStatus != rec.batteryStatus) { |
| 6004 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6005 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6006 | switch (oldStatus) { |
| 6007 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6008 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6009 | break; |
| 6010 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6011 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6012 | break; |
| 6013 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6014 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6015 | break; |
| 6016 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6017 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6018 | break; |
| 6019 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6020 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6021 | break; |
| 6022 | default: |
| 6023 | pw.print(oldStatus); |
| 6024 | break; |
| 6025 | } |
| 6026 | } |
| 6027 | if (oldHealth != rec.batteryHealth) { |
| 6028 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6029 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6030 | switch (oldHealth) { |
| 6031 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6032 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6033 | break; |
| 6034 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6035 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6036 | break; |
| 6037 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6038 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6039 | break; |
| 6040 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6041 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6042 | break; |
| 6043 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6044 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6045 | break; |
| 6046 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6047 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6048 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6049 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 6050 | pw.print(checkin ? "c" : "cold"); |
| 6051 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6052 | default: |
| 6053 | pw.print(oldHealth); |
| 6054 | break; |
| 6055 | } |
| 6056 | } |
| 6057 | if (oldPlug != rec.batteryPlugType) { |
| 6058 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6059 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6060 | switch (oldPlug) { |
| 6061 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6062 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6063 | break; |
| 6064 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6065 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6066 | break; |
| 6067 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6068 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6069 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6070 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6071 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6072 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6073 | default: |
| 6074 | pw.print(oldPlug); |
| 6075 | break; |
| 6076 | } |
| 6077 | } |
| 6078 | if (oldTemp != rec.batteryTemperature) { |
| 6079 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6080 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6081 | pw.print(oldTemp); |
| 6082 | } |
| 6083 | if (oldVolt != rec.batteryVoltage) { |
| 6084 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6085 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6086 | pw.print(oldVolt); |
| 6087 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6088 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6089 | if (oldChargeMAh != chargeMAh) { |
| 6090 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6091 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6092 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6093 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6094 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6095 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6096 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 6097 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6098 | if (rec.wakeReasonTag != null) { |
| 6099 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6100 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6101 | pw.print(rec.wakeReasonTag.poolIdx); |
| 6102 | } else { |
| 6103 | pw.print(" wake_reason="); |
| 6104 | pw.print(rec.wakeReasonTag.uid); |
| 6105 | pw.print(":\""); |
| 6106 | pw.print(rec.wakeReasonTag.string); |
| 6107 | pw.print("\""); |
| 6108 | } |
| 6109 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6110 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6111 | pw.print(checkin ? "," : " "); |
| 6112 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 6113 | pw.print("+"); |
| 6114 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6115 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6116 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6117 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6118 | : HISTORY_EVENT_NAMES; |
| 6119 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6120 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6121 | if (idx >= 0 && idx < eventNames.length) { |
| 6122 | pw.print(eventNames[idx]); |
| 6123 | } else { |
| 6124 | pw.print(checkin ? "Ev" : "event"); |
| 6125 | pw.print(idx); |
| 6126 | } |
| 6127 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6128 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6129 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6130 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6131 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6132 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6133 | pw.print(":\""); |
| 6134 | pw.print(rec.eventTag.string); |
| 6135 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6136 | } |
| 6137 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6138 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6139 | if (rec.stepDetails != null) { |
| 6140 | if (!checkin) { |
| 6141 | pw.print(" Details: cpu="); |
| 6142 | pw.print(rec.stepDetails.userTime); |
| 6143 | pw.print("u+"); |
| 6144 | pw.print(rec.stepDetails.systemTime); |
| 6145 | pw.print("s"); |
| 6146 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6147 | pw.print(" ("); |
| 6148 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6149 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6150 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6151 | pw.print(", "); |
| 6152 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6153 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6154 | } |
| 6155 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6156 | pw.print(", "); |
| 6157 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6158 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6159 | } |
| 6160 | pw.print(')'); |
| 6161 | } |
| 6162 | pw.println(); |
| 6163 | pw.print(" /proc/stat="); |
| 6164 | pw.print(rec.stepDetails.statUserTime); |
| 6165 | pw.print(" usr, "); |
| 6166 | pw.print(rec.stepDetails.statSystemTime); |
| 6167 | pw.print(" sys, "); |
| 6168 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6169 | pw.print(" io, "); |
| 6170 | pw.print(rec.stepDetails.statIrqTime); |
| 6171 | pw.print(" irq, "); |
| 6172 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6173 | pw.print(" sirq, "); |
| 6174 | pw.print(rec.stepDetails.statIdlTime); |
| 6175 | pw.print(" idle"); |
| 6176 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6177 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6178 | + rec.stepDetails.statSoftIrqTime; |
| 6179 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6180 | if (total > 0) { |
| 6181 | pw.print(" ("); |
| 6182 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6183 | pw.print(String.format("%.1f%%", perc)); |
| 6184 | pw.print(" of "); |
| 6185 | StringBuilder sb = new StringBuilder(64); |
| 6186 | formatTimeMsNoSpace(sb, total*10); |
| 6187 | pw.print(sb); |
| 6188 | pw.print(")"); |
| 6189 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6190 | pw.print(", PlatformIdleStat "); |
| 6191 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6192 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6193 | |
| 6194 | pw.print(", SubsystemPowerState "); |
| 6195 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6196 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6197 | } else { |
| 6198 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6199 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6200 | pw.print(rec.stepDetails.userTime); |
| 6201 | pw.print(":"); |
| 6202 | pw.print(rec.stepDetails.systemTime); |
| 6203 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6204 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6205 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6206 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6207 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6208 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6209 | } |
| 6210 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6211 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6212 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6213 | } |
| 6214 | } |
| 6215 | pw.println(); |
| 6216 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6217 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6218 | pw.print(rec.stepDetails.statUserTime); |
| 6219 | pw.print(','); |
| 6220 | pw.print(rec.stepDetails.statSystemTime); |
| 6221 | pw.print(','); |
| 6222 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6223 | pw.print(','); |
| 6224 | pw.print(rec.stepDetails.statIrqTime); |
| 6225 | pw.print(','); |
| 6226 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6227 | pw.print(','); |
| 6228 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6229 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6230 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6231 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6232 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6233 | pw.print(','); |
| 6234 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6235 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6236 | |
| 6237 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6238 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6239 | } |
| 6240 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6241 | } |
| 6242 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6243 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6244 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6245 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6246 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6247 | |
| 6248 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6249 | UserHandle.formatUid(pw, uid); |
| 6250 | pw.print("="); |
| 6251 | pw.print(utime); |
| 6252 | pw.print("u+"); |
| 6253 | pw.print(stime); |
| 6254 | pw.print("s"); |
| 6255 | } |
| 6256 | |
| 6257 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6258 | pw.print('/'); |
| 6259 | pw.print(uid); |
| 6260 | pw.print(":"); |
| 6261 | pw.print(utime); |
| 6262 | pw.print(":"); |
| 6263 | pw.print(stime); |
| 6264 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6265 | } |
| 6266 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6267 | private void printSizeValue(PrintWriter pw, long size) { |
| 6268 | float result = size; |
| 6269 | String suffix = ""; |
| 6270 | if (result >= 10*1024) { |
| 6271 | suffix = "KB"; |
| 6272 | result = result / 1024; |
| 6273 | } |
| 6274 | if (result >= 10*1024) { |
| 6275 | suffix = "MB"; |
| 6276 | result = result / 1024; |
| 6277 | } |
| 6278 | if (result >= 10*1024) { |
| 6279 | suffix = "GB"; |
| 6280 | result = result / 1024; |
| 6281 | } |
| 6282 | if (result >= 10*1024) { |
| 6283 | suffix = "TB"; |
| 6284 | result = result / 1024; |
| 6285 | } |
| 6286 | if (result >= 10*1024) { |
| 6287 | suffix = "PB"; |
| 6288 | result = result / 1024; |
| 6289 | } |
| 6290 | pw.print((int)result); |
| 6291 | pw.print(suffix); |
| 6292 | } |
| 6293 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6294 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6295 | String label3, long estimatedTime) { |
| 6296 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6297 | return false; |
| 6298 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6299 | pw.print(label1); |
| 6300 | pw.print(label2); |
| 6301 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6302 | StringBuilder sb = new StringBuilder(64); |
| 6303 | formatTimeMs(sb, estimatedTime); |
| 6304 | pw.print(sb); |
| 6305 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6306 | return true; |
| 6307 | } |
| 6308 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6309 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6310 | LevelStepTracker steps, boolean checkin) { |
| 6311 | if (steps == null) { |
| 6312 | return false; |
| 6313 | } |
| 6314 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6315 | if (count <= 0) { |
| 6316 | return false; |
| 6317 | } |
| 6318 | if (!checkin) { |
| 6319 | pw.println(header); |
| 6320 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6321 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6322 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6323 | long duration = steps.getDurationAt(i); |
| 6324 | int level = steps.getLevelAt(i); |
| 6325 | long initMode = steps.getInitModeAt(i); |
| 6326 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6327 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6328 | lineArgs[0] = Long.toString(duration); |
| 6329 | lineArgs[1] = Integer.toString(level); |
| 6330 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6331 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6332 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6333 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6334 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6335 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6336 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6337 | } |
| 6338 | } else { |
| 6339 | lineArgs[2] = ""; |
| 6340 | } |
| 6341 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6342 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6343 | } else { |
| 6344 | lineArgs[3] = ""; |
| 6345 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6346 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6347 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6348 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6349 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6350 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6351 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6352 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6353 | pw.print(prefix); |
| 6354 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6355 | TimeUtils.formatDuration(duration, pw); |
| 6356 | pw.print(" to "); pw.print(level); |
| 6357 | boolean haveModes = false; |
| 6358 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6359 | pw.print(" ("); |
| 6360 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6361 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6362 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6363 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6364 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6365 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6366 | } |
| 6367 | haveModes = true; |
| 6368 | } |
| 6369 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6370 | pw.print(haveModes ? ", " : " ("); |
| 6371 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6372 | ? "power-save-on" : "power-save-off"); |
| 6373 | haveModes = true; |
| 6374 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6375 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6376 | pw.print(haveModes ? ", " : " ("); |
| 6377 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6378 | ? "device-idle-on" : "device-idle-off"); |
| 6379 | haveModes = true; |
| 6380 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6381 | if (haveModes) { |
| 6382 | pw.print(")"); |
| 6383 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6384 | pw.println(); |
| 6385 | } |
| 6386 | } |
| 6387 | return true; |
| 6388 | } |
| 6389 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6390 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6391 | LevelStepTracker steps) { |
| 6392 | if (steps == null) { |
| 6393 | return; |
| 6394 | } |
| 6395 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6396 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6397 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6398 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6399 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6400 | |
| 6401 | final long initMode = steps.getInitModeAt(i); |
| 6402 | final long modMode = steps.getModModeAt(i); |
| 6403 | |
| 6404 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6405 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6406 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6407 | case Display.STATE_OFF: |
| 6408 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6409 | break; |
| 6410 | case Display.STATE_ON: |
| 6411 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6412 | break; |
| 6413 | case Display.STATE_DOZE: |
| 6414 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6415 | break; |
| 6416 | case Display.STATE_DOZE_SUSPEND: |
| 6417 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6418 | break; |
| 6419 | default: |
| 6420 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6421 | break; |
| 6422 | } |
| 6423 | } |
| 6424 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6425 | |
| 6426 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6427 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6428 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6429 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6430 | } |
| 6431 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6432 | |
| 6433 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6434 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6435 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6436 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6437 | } |
| 6438 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6439 | |
| 6440 | proto.end(token); |
| 6441 | } |
| 6442 | } |
| 6443 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6444 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6445 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6446 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6447 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6448 | public static final int DUMP_VERBOSE = 1<<5; |
| 6449 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6450 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6451 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6452 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6453 | final HistoryItem rec = new HistoryItem(); |
| 6454 | long lastTime = -1; |
| 6455 | long baseTime = -1; |
| 6456 | boolean printed = false; |
| 6457 | HistoryEventTracker tracker = null; |
| 6458 | while (getNextHistoryLocked(rec)) { |
| 6459 | lastTime = rec.time; |
| 6460 | if (baseTime < 0) { |
| 6461 | baseTime = lastTime; |
| 6462 | } |
| 6463 | if (rec.time >= histStart) { |
| 6464 | if (histStart >= 0 && !printed) { |
| 6465 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6466 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6467 | || rec.cmd == HistoryItem.CMD_START |
| 6468 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6469 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6470 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6471 | (flags&DUMP_VERBOSE) != 0); |
| 6472 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6473 | } else if (rec.currentTime != 0) { |
| 6474 | printed = true; |
| 6475 | byte cmd = rec.cmd; |
| 6476 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6477 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6478 | (flags&DUMP_VERBOSE) != 0); |
| 6479 | rec.cmd = cmd; |
| 6480 | } |
| 6481 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6482 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6483 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6484 | (flags&DUMP_VERBOSE) != 0); |
| 6485 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6486 | } |
| 6487 | int oldEventCode = rec.eventCode; |
| 6488 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6489 | rec.eventTag = new HistoryTag(); |
| 6490 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6491 | HashMap<String, SparseIntArray> active |
| 6492 | = tracker.getStateForEvent(i); |
| 6493 | if (active == null) { |
| 6494 | continue; |
| 6495 | } |
| 6496 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6497 | : active.entrySet()) { |
| 6498 | SparseIntArray uids = ent.getValue(); |
| 6499 | for (int j=0; j<uids.size(); j++) { |
| 6500 | rec.eventCode = i; |
| 6501 | rec.eventTag.string = ent.getKey(); |
| 6502 | rec.eventTag.uid = uids.keyAt(j); |
| 6503 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6504 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6505 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6506 | rec.wakeReasonTag = null; |
| 6507 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6508 | } |
| 6509 | } |
| 6510 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6511 | rec.eventCode = oldEventCode; |
| 6512 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6513 | tracker = null; |
| 6514 | } |
| 6515 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6516 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6517 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6518 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6519 | // This is an attempt to aggregate the previous state and generate |
| 6520 | //Â fake events to reflect that state at the point where we start |
| 6521 | // 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] | 6522 | if (tracker == null) { |
| 6523 | tracker = new HistoryEventTracker(); |
| 6524 | } |
| 6525 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6526 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6527 | } |
| 6528 | } |
| 6529 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6530 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6531 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6532 | } |
| 6533 | } |
| 6534 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6535 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6536 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6537 | if (steps == null) { |
| 6538 | return; |
| 6539 | } |
| 6540 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6541 | if (timeRemaining >= 0) { |
| 6542 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6543 | tmpSb.setLength(0); |
| 6544 | formatTimeMs(tmpSb, timeRemaining); |
| 6545 | pw.print(tmpSb); |
| 6546 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6547 | pw.println(" steps)"); |
| 6548 | } |
| 6549 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6550 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6551 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6552 | if (estimatedTime > 0) { |
| 6553 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6554 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6555 | pw.print(" time: "); |
| 6556 | tmpSb.setLength(0); |
| 6557 | formatTimeMs(tmpSb, estimatedTime); |
| 6558 | pw.print(tmpSb); |
| 6559 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6560 | pw.println(" steps)"); |
| 6561 | } |
| 6562 | } |
| 6563 | } |
| 6564 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6565 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6566 | ArrayList<PackageChange> changes) { |
| 6567 | if (changes == null) { |
| 6568 | return; |
| 6569 | } |
| 6570 | pw.print(prefix); pw.println("Package changes:"); |
| 6571 | for (int i=0; i<changes.size(); i++) { |
| 6572 | PackageChange pc = changes.get(i); |
| 6573 | if (pc.mUpdate) { |
| 6574 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6575 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6576 | } else { |
| 6577 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6578 | } |
| 6579 | } |
| 6580 | } |
| 6581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6582 | /** |
| 6583 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6584 | * |
| 6585 | * @param pw a Printer to receive the dump output. |
| 6586 | */ |
| 6587 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6588 | 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] | 6589 | prepareForDumpLocked(); |
| 6590 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6591 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6592 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6593 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6594 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6595 | final long historyTotalSize = getHistoryTotalSize(); |
| 6596 | final long historyUsedSize = getHistoryUsedSize(); |
| 6597 | if (startIteratingHistoryLocked()) { |
| 6598 | try { |
| 6599 | pw.print("Battery History ("); |
| 6600 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6601 | pw.print("% used, "); |
| 6602 | printSizeValue(pw, historyUsedSize); |
| 6603 | pw.print(" used of "); |
| 6604 | printSizeValue(pw, historyTotalSize); |
| 6605 | pw.print(", "); |
| 6606 | pw.print(getHistoryStringPoolSize()); |
| 6607 | pw.print(" strings using "); |
| 6608 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6609 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6610 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6611 | pw.println(); |
| 6612 | } finally { |
| 6613 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6614 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | if (startIteratingOldHistoryLocked()) { |
| 6618 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6619 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6620 | pw.println("Old battery History:"); |
| 6621 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6622 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6623 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6624 | if (baseTime < 0) { |
| 6625 | baseTime = rec.time; |
| 6626 | } |
| 6627 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6628 | } |
| 6629 | pw.println(); |
| 6630 | } finally { |
| 6631 | finishIteratingOldHistoryLocked(); |
| 6632 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6633 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6634 | } |
| 6635 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6636 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6637 | return; |
| 6638 | } |
| 6639 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6640 | if (!filtering) { |
| 6641 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6642 | final int NU = uidStats.size(); |
| 6643 | boolean didPid = false; |
| 6644 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6645 | for (int i=0; i<NU; i++) { |
| 6646 | Uid uid = uidStats.valueAt(i); |
| 6647 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6648 | if (pids != null) { |
| 6649 | for (int j=0; j<pids.size(); j++) { |
| 6650 | Uid.Pid pid = pids.valueAt(j); |
| 6651 | if (!didPid) { |
| 6652 | pw.println("Per-PID Stats:"); |
| 6653 | didPid = true; |
| 6654 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6655 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6656 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6657 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6658 | pw.print(" wake time: "); |
| 6659 | TimeUtils.formatDuration(time, pw); |
| 6660 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6661 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6662 | } |
| 6663 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6664 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6665 | pw.println(); |
| 6666 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6670 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6671 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6672 | long timeRemaining = computeBatteryTimeRemaining( |
| 6673 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6674 | if (timeRemaining >= 0) { |
| 6675 | pw.print(" Estimated discharge time remaining: "); |
| 6676 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6677 | pw.println(); |
| 6678 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6679 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6680 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6681 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6682 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6683 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6684 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6685 | pw.println(); |
| 6686 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6687 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6688 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6689 | long timeRemaining = computeChargeTimeRemaining( |
| 6690 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6691 | if (timeRemaining >= 0) { |
| 6692 | pw.print(" Estimated charge time remaining: "); |
| 6693 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6694 | pw.println(); |
| 6695 | } |
| 6696 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6697 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6698 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6699 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6700 | pw.println("Daily stats:"); |
| 6701 | pw.print(" Current start time: "); |
| 6702 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6703 | getCurrentDailyStartTime()).toString()); |
| 6704 | pw.print(" Next min deadline: "); |
| 6705 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6706 | getNextMinDailyDeadline()).toString()); |
| 6707 | pw.print(" Next max deadline: "); |
| 6708 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6709 | getNextMaxDailyDeadline()).toString()); |
| 6710 | StringBuilder sb = new StringBuilder(64); |
| 6711 | int[] outInt = new int[1]; |
| 6712 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6713 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6714 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6715 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6716 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6717 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6718 | dsteps, false)) { |
| 6719 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6720 | sb, outInt); |
| 6721 | } |
| 6722 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6723 | csteps, false)) { |
| 6724 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6725 | sb, outInt); |
| 6726 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6727 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6728 | } else { |
| 6729 | pw.println(" Current daily steps:"); |
| 6730 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6731 | sb, outInt); |
| 6732 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6733 | sb, outInt); |
| 6734 | } |
| 6735 | } |
| 6736 | DailyItem dit; |
| 6737 | int curIndex = 0; |
| 6738 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6739 | curIndex++; |
| 6740 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6741 | pw.println(); |
| 6742 | } |
| 6743 | pw.print(" Daily from "); |
| 6744 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6745 | pw.print(" to "); |
| 6746 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6747 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6748 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6749 | if (dumpDurationSteps(pw, " ", |
| 6750 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6751 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6752 | sb, outInt); |
| 6753 | } |
| 6754 | if (dumpDurationSteps(pw, " ", |
| 6755 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6756 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6757 | sb, outInt); |
| 6758 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6759 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6760 | } else { |
| 6761 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6762 | sb, outInt); |
| 6763 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6764 | sb, outInt); |
| 6765 | } |
| 6766 | } |
| 6767 | pw.println(); |
| 6768 | } |
| 6769 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6770 | pw.println("Statistics since last charge:"); |
| 6771 | pw.println(" System starts: " + getStartCount() |
| 6772 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6773 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6774 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6775 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6778 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6779 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6781 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6782 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6783 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6784 | |
| 6785 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6786 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6787 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6788 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6789 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6790 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6791 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6792 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6793 | try { |
| 6794 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6795 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6796 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6797 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6798 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6799 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6800 | pw.print(",\""); |
| 6801 | String str = getHistoryTagPoolString(i); |
| 6802 | str = str.replace("\\", "\\\\"); |
| 6803 | str = str.replace("\"", "\\\""); |
| 6804 | pw.print(str); |
| 6805 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6806 | pw.println(); |
| 6807 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6808 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6809 | } finally { |
| 6810 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6811 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6812 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6813 | } |
| 6814 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6815 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6816 | return; |
| 6817 | } |
| 6818 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6819 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6820 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6821 | for (int i=0; i<apps.size(); i++) { |
| 6822 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6823 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6824 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6825 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6826 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6827 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6828 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6829 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6830 | } |
| 6831 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6832 | final int NU = uidStats.size(); |
| 6833 | String[] lineArgs = new String[2]; |
| 6834 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6835 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6836 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6837 | if (pkgs != null && !pkgs.second.value) { |
| 6838 | pkgs.second.value = true; |
| 6839 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6840 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6841 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6842 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6843 | (Object[])lineArgs); |
| 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6848 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6849 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6850 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6851 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6852 | if (timeRemaining >= 0) { |
| 6853 | lineArgs[0] = Long.toString(timeRemaining); |
| 6854 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6855 | (Object[])lineArgs); |
| 6856 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6857 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6858 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6859 | if (timeRemaining >= 0) { |
| 6860 | lineArgs[0] = Long.toString(timeRemaining); |
| 6861 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6862 | (Object[])lineArgs); |
| 6863 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6864 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6865 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6868 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6869 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6870 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6871 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6872 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6873 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6874 | prepareForDumpLocked(); |
| 6875 | |
| 6876 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6877 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6878 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6879 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6880 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6881 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6882 | |
| 6883 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6884 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 6885 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 6886 | helper.create(this); |
| 6887 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 6888 | |
| 6889 | dumpProtoAppsLocked(proto, helper, apps); |
| 6890 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | proto.end(bToken); |
| 6894 | proto.flush(); |
| 6895 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6896 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6897 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 6898 | List<ApplicationInfo> apps) { |
| 6899 | final int which = STATS_SINCE_CHARGED; |
| 6900 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 6901 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 6902 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 6903 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 6904 | |
| 6905 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 6906 | if (apps != null) { |
| 6907 | for (int i = 0; i < apps.size(); ++i) { |
| 6908 | ApplicationInfo ai = apps.get(i); |
| 6909 | int aid = UserHandle.getAppId(ai.uid); |
| 6910 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 6911 | if (pkgs == null) { |
| 6912 | pkgs = new ArrayList<String>(); |
| 6913 | aidToPackages.put(aid, pkgs); |
| 6914 | } |
| 6915 | pkgs.add(ai.packageName); |
| 6916 | } |
| 6917 | } |
| 6918 | |
| 6919 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 6920 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 6921 | if (sippers != null) { |
| 6922 | for (int i = 0; i < sippers.size(); ++i) { |
| 6923 | final BatterySipper bs = sippers.get(i); |
| 6924 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 6925 | // Others are handled by dumpProtoSystemLocked() |
| 6926 | continue; |
| 6927 | } |
| 6928 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 6929 | } |
| 6930 | } |
| 6931 | |
| 6932 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6933 | final int n = uidStats.size(); |
| 6934 | for (int iu = 0; iu < n; ++iu) { |
| 6935 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 6936 | final Uid u = uidStats.valueAt(iu); |
| 6937 | |
| 6938 | final int uid = uidStats.keyAt(iu); |
| 6939 | proto.write(UidProto.UID, uid); |
| 6940 | |
| 6941 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 6942 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 6943 | if (pkgs == null) { |
| 6944 | pkgs = new ArrayList<String>(); |
| 6945 | } |
| 6946 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 6947 | u.getPackageStats(); |
| 6948 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 6949 | String pkg = packageStats.keyAt(ipkg); |
| 6950 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 6951 | packageStats.valueAt(ipkg).getServiceStats(); |
| 6952 | if (serviceStats.size() == 0) { |
| 6953 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 6954 | // example, "android") may be included in the packageStats that aren't part of |
| 6955 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 6956 | // These packages won't be a part in the pkgs List. |
| 6957 | continue; |
| 6958 | } |
| 6959 | |
| 6960 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6961 | proto.write(UidProto.Package.NAME, pkg); |
| 6962 | // Remove from the packages list since we're logging it here. |
| 6963 | pkgs.remove(pkg); |
| 6964 | |
| 6965 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 6966 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 6967 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 6968 | |
| 6969 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 6970 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 6971 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 6972 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 6973 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 6974 | |
| 6975 | proto.end(sToken); |
| 6976 | } |
| 6977 | proto.end(pToken); |
| 6978 | } |
| 6979 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 6980 | // from PackageManager data. Packages are only included in packageStats if there was |
| 6981 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 6982 | for (String p : pkgs) { |
| 6983 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6984 | proto.write(UidProto.Package.NAME, p); |
| 6985 | proto.end(pToken); |
| 6986 | } |
| 6987 | |
| 6988 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 6989 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 6990 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 6991 | // Times are since reset (regardless of 'which') |
| 6992 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 6993 | final Timer bgTimer = timer.getSubTimer(); |
| 6994 | final long bgTimeMs = bgTimer != null |
| 6995 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 6996 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 6997 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 6998 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 6999 | proto.end(awToken); |
| 7000 | } |
| 7001 | |
| 7002 | // Audio (AUDIO_DATA) |
| 7003 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7004 | |
| 7005 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7006 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7007 | u.getBluetoothControllerActivity(), which); |
| 7008 | |
| 7009 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7010 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7011 | if (bleTimer != null) { |
| 7012 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7013 | |
| 7014 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7015 | rawRealtimeUs, which); |
| 7016 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7017 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7018 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7019 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7020 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7021 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7022 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7023 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7024 | // Result counters |
| 7025 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7026 | u.getBluetoothScanResultCounter() != null |
| 7027 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7028 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7029 | u.getBluetoothScanResultBgCounter() != null |
| 7030 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7031 | |
| 7032 | proto.end(bmToken); |
| 7033 | } |
| 7034 | |
| 7035 | // Camera (CAMERA_DATA) |
| 7036 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7037 | |
| 7038 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7039 | final long cpuToken = proto.start(UidProto.CPU); |
| 7040 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7041 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7042 | |
| 7043 | final long[] cpuFreqs = getCpuFreqs(); |
| 7044 | if (cpuFreqs != null) { |
| 7045 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7046 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7047 | // screenOffCpuFreqTimes. |
| 7048 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7049 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7050 | if (screenOffCpuFreqTimeMs == null) { |
| 7051 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7052 | } |
| 7053 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7054 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7055 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7056 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7057 | cpuFreqTimeMs[ic]); |
| 7058 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7059 | screenOffCpuFreqTimeMs[ic]); |
| 7060 | proto.end(cToken); |
| 7061 | } |
| 7062 | } |
| 7063 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7064 | |
| 7065 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7066 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7067 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7068 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7069 | if (screenOffTimesMs == null) { |
| 7070 | screenOffTimesMs = new long[timesMs.length]; |
| 7071 | } |
| 7072 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7073 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7074 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7075 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7076 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7077 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7078 | timesMs[ic]); |
| 7079 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7080 | screenOffTimesMs[ic]); |
| 7081 | proto.end(cToken); |
| 7082 | } |
| 7083 | proto.end(procToken); |
| 7084 | } |
| 7085 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7086 | proto.end(cpuToken); |
| 7087 | |
| 7088 | // Flashlight (FLASHLIGHT_DATA) |
| 7089 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7090 | rawRealtimeUs, which); |
| 7091 | |
| 7092 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7093 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7094 | rawRealtimeUs, which); |
| 7095 | |
| 7096 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7097 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7098 | rawRealtimeUs, which); |
| 7099 | |
| 7100 | // Job completion (JOB_COMPLETION_DATA) |
| 7101 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7102 | final int[] reasons = new int[]{ |
| 7103 | JobParameters.REASON_CANCELED, |
| 7104 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7105 | JobParameters.REASON_PREEMPT, |
| 7106 | JobParameters.REASON_TIMEOUT, |
| 7107 | JobParameters.REASON_DEVICE_IDLE, |
| 7108 | }; |
| 7109 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7110 | SparseIntArray types = completions.valueAt(ic); |
| 7111 | if (types != null) { |
| 7112 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7113 | |
| 7114 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7115 | |
| 7116 | for (int r : reasons) { |
| 7117 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7118 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7119 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7120 | proto.end(rToken); |
| 7121 | } |
| 7122 | |
| 7123 | proto.end(jcToken); |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | // Scheduled jobs (JOB_DATA) |
| 7128 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7129 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7130 | final Timer timer = jobs.valueAt(ij); |
| 7131 | final Timer bgTimer = timer.getSubTimer(); |
| 7132 | final long jToken = proto.start(UidProto.JOBS); |
| 7133 | |
| 7134 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7135 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7136 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7137 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7138 | |
| 7139 | proto.end(jToken); |
| 7140 | } |
| 7141 | |
| 7142 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7143 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7144 | u.getModemControllerActivity(), which); |
| 7145 | |
| 7146 | // Network stats (NETWORK_DATA) |
| 7147 | final long nToken = proto.start(UidProto.NETWORK); |
| 7148 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7149 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7150 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7151 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7152 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7153 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7154 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7155 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7156 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7157 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7158 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7159 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7160 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7161 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7162 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7163 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7164 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7165 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7166 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7167 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7168 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7169 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7170 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7171 | u.getMobileRadioActiveCount(which)); |
| 7172 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7173 | u.getMobileRadioApWakeupCount(which)); |
| 7174 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7175 | u.getWifiRadioApWakeupCount(which)); |
| 7176 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7177 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7178 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7179 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7180 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7181 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7182 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7183 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7184 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7185 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7186 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7187 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7188 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7189 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7190 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7191 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7192 | proto.end(nToken); |
| 7193 | |
| 7194 | // Power use item (POWER_USE_ITEM_DATA) |
| 7195 | BatterySipper bs = uidToSipper.get(uid); |
| 7196 | if (bs != null) { |
| 7197 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7198 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7199 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7200 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7201 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7202 | bs.proportionalSmearMah); |
| 7203 | proto.end(bsToken); |
| 7204 | } |
| 7205 | |
| 7206 | // Processes (PROCESS_DATA) |
| 7207 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7208 | u.getProcessStats(); |
| 7209 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7210 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7211 | final long prToken = proto.start(UidProto.PROCESS); |
| 7212 | |
| 7213 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7214 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7215 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7216 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7217 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7218 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7219 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7220 | |
| 7221 | proto.end(prToken); |
| 7222 | } |
| 7223 | |
| 7224 | // Sensors (SENSOR_DATA) |
| 7225 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7226 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7227 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7228 | final Timer timer = se.getSensorTime(); |
| 7229 | if (timer == null) { |
| 7230 | continue; |
| 7231 | } |
| 7232 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7233 | final int sensorNumber = sensors.keyAt(ise); |
| 7234 | final long seToken = proto.start(UidProto.SENSORS); |
| 7235 | |
| 7236 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7237 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7238 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7239 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7240 | |
| 7241 | proto.end(seToken); |
| 7242 | } |
| 7243 | |
| 7244 | // State times (STATE_TIME_DATA) |
| 7245 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7246 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7247 | if (durMs == 0) { |
| 7248 | continue; |
| 7249 | } |
| 7250 | final long stToken = proto.start(UidProto.STATES); |
| 7251 | proto.write(UidProto.StateTime.STATE, ips); |
| 7252 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7253 | proto.end(stToken); |
| 7254 | } |
| 7255 | |
| 7256 | // Syncs (SYNC_DATA) |
| 7257 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7258 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7259 | final Timer timer = syncs.valueAt(isy); |
| 7260 | final Timer bgTimer = timer.getSubTimer(); |
| 7261 | final long syToken = proto.start(UidProto.SYNCS); |
| 7262 | |
| 7263 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7264 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7265 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7266 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7267 | |
| 7268 | proto.end(syToken); |
| 7269 | } |
| 7270 | |
| 7271 | // User activity (USER_ACTIVITY_DATA) |
| 7272 | if (u.hasUserActivity()) { |
| 7273 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7274 | int val = u.getUserActivityCount(i, which); |
| 7275 | if (val != 0) { |
| 7276 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7277 | proto.write(UidProto.UserActivity.NAME, i); |
| 7278 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7279 | proto.end(uaToken); |
| 7280 | } |
| 7281 | } |
| 7282 | } |
| 7283 | |
| 7284 | // Vibrator (VIBRATOR_DATA) |
| 7285 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7286 | |
| 7287 | // Video (VIDEO_DATA) |
| 7288 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7289 | |
| 7290 | // Wakelocks (WAKELOCK_DATA) |
| 7291 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7292 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7293 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7294 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7295 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7296 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7297 | rawRealtimeUs, which); |
| 7298 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7299 | if (pTimer != null) { |
| 7300 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7301 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7302 | rawRealtimeUs, which); |
| 7303 | } |
| 7304 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7305 | rawRealtimeUs, which); |
| 7306 | proto.end(wToken); |
| 7307 | } |
| 7308 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7309 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7310 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7311 | rawRealtimeUs, which); |
| 7312 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7313 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7314 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7315 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7316 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7317 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7318 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7319 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7320 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7321 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7322 | proto.end(waToken); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7327 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7328 | u.getWifiControllerActivity(), which); |
| 7329 | |
| 7330 | // Wifi data (WIFI_DATA) |
| 7331 | final long wToken = proto.start(UidProto.WIFI); |
| 7332 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7333 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7334 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7335 | rawRealtimeUs, which); |
| 7336 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7337 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7338 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7339 | rawRealtimeUs, which); |
| 7340 | proto.end(wToken); |
| 7341 | |
| 7342 | proto.end(uTkn); |
| 7343 | } |
| 7344 | } |
| 7345 | |
| 7346 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7347 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7348 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7349 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7350 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7351 | final int which = STATS_SINCE_CHARGED; |
| 7352 | |
| 7353 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7354 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7355 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7356 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7357 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7358 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7359 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7360 | computeUptime(rawUptimeUs, which) / 1000); |
| 7361 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7362 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7363 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7364 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7365 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7366 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7367 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7368 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7369 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7370 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7371 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7372 | getEstimatedBatteryCapacity()); |
| 7373 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7374 | getMinLearnedBatteryCapacity()); |
| 7375 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7376 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7377 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7378 | |
| 7379 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7380 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7381 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7382 | getLowDischargeAmountSinceCharge()); |
| 7383 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7384 | getHighDischargeAmountSinceCharge()); |
| 7385 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7386 | getDischargeAmountScreenOnSinceCharge()); |
| 7387 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7388 | getDischargeAmountScreenOffSinceCharge()); |
| 7389 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7390 | getDischargeAmountScreenDozeSinceCharge()); |
| 7391 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7392 | getUahDischarge(which) / 1000); |
| 7393 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7394 | getUahDischargeScreenOff(which) / 1000); |
| 7395 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7396 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7397 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7398 | getUahDischargeLightDoze(which) / 1000); |
| 7399 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7400 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7401 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7402 | |
| 7403 | // Time remaining |
| 7404 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7405 | // 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] | 7406 | if (timeRemainingUs >= 0) { |
| 7407 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7408 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7409 | } else { |
| 7410 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7411 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7412 | if (timeRemainingUs >= 0) { |
| 7413 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7414 | } else { |
| 7415 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7416 | } |
| 7417 | } |
| 7418 | |
| 7419 | // Charge step (CHARGE_STEP_DATA) |
| 7420 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7421 | |
| 7422 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7423 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7424 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7425 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7426 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7427 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7428 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7432 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7433 | |
| 7434 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7435 | final long[] cpuFreqs = getCpuFreqs(); |
| 7436 | if (cpuFreqs != null) { |
| 7437 | for (long i : cpuFreqs) { |
| 7438 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7443 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7444 | getBluetoothControllerActivity(), which); |
| 7445 | |
| 7446 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7447 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7448 | getModemControllerActivity(), which); |
| 7449 | |
| 7450 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7451 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7452 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7453 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7454 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7455 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7456 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7457 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7458 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7459 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7460 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7461 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7462 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7463 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7464 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7465 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7466 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7467 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7468 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7469 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7470 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7471 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7472 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7473 | |
| 7474 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7475 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7476 | getWifiControllerActivity(), which); |
| 7477 | |
| 7478 | |
| 7479 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7480 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7481 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7482 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7483 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7484 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7485 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7486 | |
| 7487 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7488 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7489 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7490 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7491 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7492 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7493 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7494 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7495 | } |
| 7496 | |
| 7497 | // Misc (MISC_DATA) |
| 7498 | // Calculate wakelock times across all uids. |
| 7499 | long fullWakeLockTimeTotalUs = 0; |
| 7500 | long partialWakeLockTimeTotalUs = 0; |
| 7501 | |
| 7502 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7503 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7504 | final Uid u = uidStats.valueAt(iu); |
| 7505 | |
| 7506 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7507 | u.getWakelockStats(); |
| 7508 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7509 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7510 | |
| 7511 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7512 | if (fullWakeTimer != null) { |
| 7513 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7514 | which); |
| 7515 | } |
| 7516 | |
| 7517 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7518 | if (partialWakeTimer != null) { |
| 7519 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7520 | rawRealtimeUs, which); |
| 7521 | } |
| 7522 | } |
| 7523 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7524 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7525 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7526 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7527 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7528 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7529 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7530 | fullWakeLockTimeTotalUs / 1000); |
| 7531 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7532 | partialWakeLockTimeTotalUs / 1000); |
| 7533 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7534 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7535 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7536 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7537 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7538 | getMobileRadioActiveCount(which)); |
| 7539 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7540 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7541 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7542 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7543 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7544 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7545 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7546 | getNumConnectivityChange(which)); |
| 7547 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7548 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7549 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7550 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7551 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7552 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7553 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7554 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7555 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7556 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7557 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7558 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7559 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7560 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7561 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7562 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7563 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7564 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7565 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7566 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7567 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7568 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7569 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7570 | final long multicastWakeLockTimeTotalUs = |
| 7571 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7572 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7573 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7574 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7575 | multicastWakeLockTimeTotalUs / 1000); |
| 7576 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7577 | multicastWakeLockCountTotal); |
| 7578 | proto.end(wmctToken); |
| 7579 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7580 | // Power use item (POWER_USE_ITEM_DATA) |
| 7581 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7582 | if (sippers != null) { |
| 7583 | for (int i = 0; i < sippers.size(); ++i) { |
| 7584 | final BatterySipper bs = sippers.get(i); |
| 7585 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7586 | int uid = 0; |
| 7587 | switch (bs.drainType) { |
| 7588 | case IDLE: |
| 7589 | n = SystemProto.PowerUseItem.IDLE; |
| 7590 | break; |
| 7591 | case CELL: |
| 7592 | n = SystemProto.PowerUseItem.CELL; |
| 7593 | break; |
| 7594 | case PHONE: |
| 7595 | n = SystemProto.PowerUseItem.PHONE; |
| 7596 | break; |
| 7597 | case WIFI: |
| 7598 | n = SystemProto.PowerUseItem.WIFI; |
| 7599 | break; |
| 7600 | case BLUETOOTH: |
| 7601 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7602 | break; |
| 7603 | case SCREEN: |
| 7604 | n = SystemProto.PowerUseItem.SCREEN; |
| 7605 | break; |
| 7606 | case FLASHLIGHT: |
| 7607 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7608 | break; |
| 7609 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7610 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7611 | continue; |
| 7612 | case USER: |
| 7613 | n = SystemProto.PowerUseItem.USER; |
| 7614 | uid = UserHandle.getUid(bs.userId, 0); |
| 7615 | break; |
| 7616 | case UNACCOUNTED: |
| 7617 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7618 | break; |
| 7619 | case OVERCOUNTED: |
| 7620 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7621 | break; |
| 7622 | case CAMERA: |
| 7623 | n = SystemProto.PowerUseItem.CAMERA; |
| 7624 | break; |
| 7625 | case MEMORY: |
| 7626 | n = SystemProto.PowerUseItem.MEMORY; |
| 7627 | break; |
| 7628 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7629 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7630 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7631 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7632 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7633 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7634 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7635 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7636 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7637 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7638 | } |
| 7639 | } |
| 7640 | |
| 7641 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7642 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7643 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7644 | helper.getPowerProfile().getBatteryCapacity()); |
| 7645 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7646 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7647 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7648 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7649 | |
| 7650 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7651 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7652 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7653 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7654 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7655 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7656 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7657 | ent.getValue(), rawRealtimeUs, which); |
| 7658 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7659 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7660 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7661 | } |
| 7662 | |
| 7663 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7664 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7665 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7666 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7667 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7668 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7669 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7673 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7674 | which); |
| 7675 | |
| 7676 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7677 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7678 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7679 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7680 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7681 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7682 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7683 | } |
| 7684 | |
| 7685 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7686 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7687 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7688 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7689 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7690 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7691 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
| 7694 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7695 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7696 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7697 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7698 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7699 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7700 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7704 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7705 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7706 | proto.write(SystemProto.WifiState.NAME, i); |
| 7707 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7708 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7709 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7710 | } |
| 7711 | |
| 7712 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7713 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7714 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7715 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7716 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7717 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7718 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7719 | } |
| 7720 | |
| 7721 | proto.end(sToken); |
| 7722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } |