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 |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 238 | */ |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 239 | static final int CHECKIN_VERSION = 29; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * 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] | 243 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 244 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 245 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 246 | private static final long BYTES_PER_KB = 1024; |
| 247 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 248 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 249 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 250 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 251 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 252 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 254 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 255 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 256 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 257 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 258 | // rpm line is: |
| 259 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 260 | // screen-off time, screen-off count |
| 261 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 262 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 263 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 264 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 265 | // fgs line is: |
| 266 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 267 | // foreground service time, count |
| 268 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 269 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 270 | // wl line is: |
| 271 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 272 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 273 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 274 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 275 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 276 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 277 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 278 | // awl line is: |
| 279 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 280 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 281 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 282 | private static final String SYNC_DATA = "sy"; |
| 283 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 284 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 285 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 286 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 287 | private static final String NETWORK_DATA = "nt"; |
| 288 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 289 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 290 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 291 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 292 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 293 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 294 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 295 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 296 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 297 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 298 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 299 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 300 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 301 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 302 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 303 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 304 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 305 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 306 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 307 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 308 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 309 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 310 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 311 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 312 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 313 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 314 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 315 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 316 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 317 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 318 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 319 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 320 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 321 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 322 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 323 | private static final String FLASHLIGHT_DATA = "fla"; |
| 324 | private static final String CAMERA_DATA = "cam"; |
| 325 | private static final String VIDEO_DATA = "vid"; |
| 326 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 327 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 328 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 330 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 331 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 332 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 334 | |
| 335 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 336 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 337 | * |
| 338 | * Other types might include times spent in foreground, background etc. |
| 339 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 340 | @VisibleForTesting |
| 341 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 342 | |
| 343 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 344 | * State for keeping track of counting information. |
| 345 | */ |
| 346 | public static abstract class Counter { |
| 347 | |
| 348 | /** |
| 349 | * Returns the count associated with this Counter for the |
| 350 | * selected type of statistics. |
| 351 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 352 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 353 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 354 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 355 | |
| 356 | /** |
| 357 | * Temporary for debugging. |
| 358 | */ |
| 359 | public abstract void logState(Printer pw, String prefix); |
| 360 | } |
| 361 | |
| 362 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 363 | * State for keeping track of long counting information. |
| 364 | */ |
| 365 | public static abstract class LongCounter { |
| 366 | |
| 367 | /** |
| 368 | * Returns the count associated with this Counter for the |
| 369 | * selected type of statistics. |
| 370 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 371 | * @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] | 372 | */ |
| 373 | public abstract long getCountLocked(int which); |
| 374 | |
| 375 | /** |
| 376 | * Temporary for debugging. |
| 377 | */ |
| 378 | public abstract void logState(Printer pw, String prefix); |
| 379 | } |
| 380 | |
| 381 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 382 | * State for keeping track of array of long counting information. |
| 383 | */ |
| 384 | public static abstract class LongCounterArray { |
| 385 | /** |
| 386 | * Returns the counts associated with this Counter for the |
| 387 | * selected type of statistics. |
| 388 | * |
| 389 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 390 | */ |
| 391 | public abstract long[] getCountsLocked(int which); |
| 392 | |
| 393 | /** |
| 394 | * Temporary for debugging. |
| 395 | */ |
| 396 | public abstract void logState(Printer pw, String prefix); |
| 397 | } |
| 398 | |
| 399 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 400 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 401 | * radio controller. |
| 402 | */ |
| 403 | public static abstract class ControllerActivityCounter { |
| 404 | /** |
| 405 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 406 | * idle state. |
| 407 | */ |
| 408 | public abstract LongCounter getIdleTimeCounter(); |
| 409 | |
| 410 | /** |
| 411 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 412 | * receive state. |
| 413 | */ |
| 414 | public abstract LongCounter getRxTimeCounter(); |
| 415 | |
| 416 | /** |
| 417 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 418 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 419 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 420 | * various transmit level states. |
| 421 | */ |
| 422 | public abstract LongCounter[] getTxTimeCounters(); |
| 423 | |
| 424 | /** |
| 425 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 426 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 427 | * yield a value of 0 if the device doesn't support power calculations. |
| 428 | */ |
| 429 | public abstract LongCounter getPowerCounter(); |
| 430 | } |
| 431 | |
| 432 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | * State for keeping track of timing information. |
| 434 | */ |
| 435 | public static abstract class Timer { |
| 436 | |
| 437 | /** |
| 438 | * Returns the count associated with this Timer for the |
| 439 | * selected type of statistics. |
| 440 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 441 | * @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] | 442 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 443 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * Returns the total time in microseconds associated with this Timer for the |
| 447 | * selected type of statistics. |
| 448 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 449 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 450 | * @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] | 451 | * @return a time in microseconds |
| 452 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 453 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 456 | * Returns the total time in microseconds associated with this Timer since the |
| 457 | * 'mark' was last set. |
| 458 | * |
| 459 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 460 | * @return a time in microseconds |
| 461 | */ |
| 462 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 463 | |
| 464 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 465 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 466 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 467 | */ |
| 468 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 469 | return -1; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * 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] | 474 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 475 | */ |
| 476 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 477 | return -1; |
| 478 | } |
| 479 | |
| 480 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 481 | * 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] | 482 | * |
| 483 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 484 | * been on since reset. |
| 485 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 486 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 487 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 488 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 489 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 490 | */ |
| 491 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 496 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 497 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 498 | * |
| 499 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 500 | */ |
| 501 | public Timer getSubTimer() { |
| 502 | return null; |
| 503 | } |
| 504 | |
| 505 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 506 | * Returns whether the timer is currently running. Some types of timers |
| 507 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 508 | * and report false. |
| 509 | */ |
| 510 | public boolean isRunningLocked() { |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | * Temporary for debugging. |
| 516 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 517 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 521 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 522 | */ |
| 523 | public static int mapToInternalProcessState(int procState) { |
| 524 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 525 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 526 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 527 | return Uid.PROCESS_STATE_TOP; |
Dianne Hackborn | 10fc4fd | 2017-12-19 17:23:13 -0800 | [diff] [blame^] | 528 | } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 529 | // State when app has put itself in the foreground. |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 530 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 531 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 532 | // Persistent and other foreground states go here. |
| 533 | return Uid.PROCESS_STATE_FOREGROUND; |
| 534 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 535 | return Uid.PROCESS_STATE_BACKGROUND; |
| 536 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 537 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 538 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 539 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 540 | } else { |
| 541 | return Uid.PROCESS_STATE_CACHED; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | * The statistics associated with a particular uid. |
| 547 | */ |
| 548 | public static abstract class Uid { |
| 549 | |
| 550 | /** |
| 551 | * Returns a mapping containing wakelock statistics. |
| 552 | * |
| 553 | * @return a Map from Strings to Uid.Wakelock objects. |
| 554 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 555 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | |
| 557 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 558 | * Returns the WiFi Multicast Wakelock statistics. |
| 559 | * |
| 560 | * @return a Timer Object for the per uid Multicast statistics. |
| 561 | */ |
| 562 | public abstract Timer getMulticastWakelockStats(); |
| 563 | |
| 564 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 565 | * Returns a mapping containing sync statistics. |
| 566 | * |
| 567 | * @return a Map from Strings to Timer objects. |
| 568 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 569 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 570 | |
| 571 | /** |
| 572 | * Returns a mapping containing scheduled job statistics. |
| 573 | * |
| 574 | * @return a Map from Strings to Timer objects. |
| 575 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 576 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 577 | |
| 578 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 579 | * Returns statistics about how jobs have completed. |
| 580 | * |
| 581 | * @return A Map of String job names to completion type -> count mapping. |
| 582 | */ |
| 583 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 584 | |
| 585 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | * The statistics associated with a particular wake lock. |
| 587 | */ |
| 588 | public static abstract class Wakelock { |
| 589 | public abstract Timer getWakeTime(int type); |
| 590 | } |
| 591 | |
| 592 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 593 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 594 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 595 | * wakelocks that overlap in time (and therefore over-counts). |
| 596 | */ |
| 597 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 598 | |
| 599 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | * Returns a mapping containing sensor statistics. |
| 601 | * |
| 602 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 603 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 604 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | |
| 606 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 607 | * Returns a mapping containing active process data. |
| 608 | */ |
| 609 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 610 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 611 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | * Returns a mapping containing process statistics. |
| 613 | * |
| 614 | * @return a Map from Strings to Uid.Proc objects. |
| 615 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 616 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | |
| 618 | /** |
| 619 | * Returns a mapping containing package statistics. |
| 620 | * |
| 621 | * @return a Map from Strings to Uid.Pkg objects. |
| 622 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 623 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 624 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 625 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 626 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 627 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 628 | |
| 629 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | * {@hide} |
| 631 | */ |
| 632 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 633 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 634 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 635 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 636 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 637 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 638 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 639 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 640 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 641 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 642 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 643 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 644 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 645 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 646 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 647 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 648 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 649 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 650 | /** |
| 651 | * Returns the timer keeping track of wifi scans. |
| 652 | */ |
| 653 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 654 | public abstract int getWifiScanBackgroundCount(int which); |
| 655 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 656 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 657 | /** |
| 658 | * Returns the timer keeping track of background wifi scans. |
| 659 | */ |
| 660 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 661 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 662 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 663 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 664 | public abstract Timer getAudioTurnedOnTimer(); |
| 665 | public abstract Timer getVideoTurnedOnTimer(); |
| 666 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 667 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 668 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Returns the timer keeping track of Foreground Service time |
| 672 | */ |
| 673 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 674 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 675 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 676 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 677 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 678 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 679 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 680 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 681 | public abstract long[] getCpuFreqTimes(int which); |
| 682 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 683 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 684 | /** |
| 685 | * Returns cpu times of an uid at a particular process state. |
| 686 | */ |
| 687 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 688 | /** |
| 689 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 690 | */ |
| 691 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 692 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 693 | // Note: the following times are disjoint. They can be added together to find the |
| 694 | // total time a uid has had any processes running at all. |
| 695 | |
| 696 | /** |
| 697 | * Time this uid has any processes in the top state (or above such as persistent). |
| 698 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 699 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 700 | /** |
| 701 | * Time this uid has any process with a started out bound foreground service, but |
| 702 | * none in the "top" state. |
| 703 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 704 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 705 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 706 | * Time this uid has any process in an active foreground state, but none in the |
| 707 | * "top sleeping" or better state. |
| 708 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 709 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 710 | /** |
| 711 | * Time this uid has any process in an active background state, but none in the |
| 712 | * "foreground" or better state. |
| 713 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 714 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 715 | /** |
| 716 | * Time this uid has any process that is top while the device is sleeping, but not |
| 717 | * active for any other reason. We kind-of consider it a kind of cached process |
| 718 | * for execution restrictions. |
| 719 | */ |
| 720 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 721 | /** |
| 722 | * Time this uid has any process that is in the background but it has an activity |
| 723 | * marked as "can't save state". This is essentially a cached process, though the |
| 724 | * system will try much harder than normal to avoid killing it. |
| 725 | */ |
| 726 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 727 | /** |
| 728 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 729 | * other active states. |
| 730 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 731 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 732 | /** |
| 733 | * Total number of process states we track. |
| 734 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 735 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 736 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 737 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 738 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 739 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 740 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 741 | }; |
| 742 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 743 | // Used in checkin dump |
| 744 | @VisibleForTesting |
| 745 | public static final String[] UID_PROCESS_TYPES = { |
| 746 | "T", // TOP |
| 747 | "FS", // FOREGROUND_SERVICE |
| 748 | "F", // FOREGROUND |
| 749 | "B", // BACKGROUND |
| 750 | "TS", // TOP_SLEEPING |
| 751 | "HW", // HEAVY_WEIGHT |
| 752 | "C" // CACHED |
| 753 | }; |
| 754 | |
| 755 | /** |
| 756 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 757 | * is not attributed to any non-critical process states. |
| 758 | */ |
| 759 | public static final int[] CRITICAL_PROC_STATES = { |
| 760 | PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND |
| 761 | }; |
| 762 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 763 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 764 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 765 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 766 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 768 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 769 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 770 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 771 | * Note that these must match the constants in android.os.PowerManager. |
| 772 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 773 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 774 | */ |
| 775 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 776 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 777 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 778 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 779 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 780 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 781 | public abstract void noteUserActivityLocked(int type); |
| 782 | public abstract boolean hasUserActivity(); |
| 783 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 784 | |
| 785 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 786 | public abstract long getNetworkActivityBytes(int type, int which); |
| 787 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 788 | public abstract long getMobileRadioActiveTime(int which); |
| 789 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 790 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 791 | /** |
| 792 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 793 | */ |
| 794 | public abstract long getUserCpuTimeUs(int which); |
| 795 | |
| 796 | /** |
| 797 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 798 | */ |
| 799 | public abstract long getSystemCpuTimeUs(int which); |
| 800 | |
| 801 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 802 | * 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] | 803 | * given CPU cluster. |
| 804 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 805 | * @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] | 806 | * @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] | 807 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 808 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 809 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 810 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 811 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 812 | /** |
| 813 | * Returns the number of times this UID woke up the Application Processor to |
| 814 | * process a mobile radio packet. |
| 815 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 816 | */ |
| 817 | public abstract long getMobileRadioApWakeupCount(int which); |
| 818 | |
| 819 | /** |
| 820 | * Returns the number of times this UID woke up the Application Processor to |
| 821 | * process a WiFi packet. |
| 822 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 823 | */ |
| 824 | public abstract long getWifiRadioApWakeupCount(int which); |
| 825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 827 | /* |
| 828 | * FIXME: it's not correct to use this magic value because it |
| 829 | * could clash with a sensor handle (which are defined by |
| 830 | * the sensor HAL, and therefore out of our control |
| 831 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | // Magic sensor number for the GPS. |
| 833 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 838 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 839 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 840 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 843 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 844 | public int mWakeNesting; |
| 845 | public long mWakeSumMs; |
| 846 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 847 | } |
| 848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | /** |
| 850 | * The statistics associated with a particular process. |
| 851 | */ |
| 852 | public static abstract class Proc { |
| 853 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 854 | public static class ExcessivePower { |
| 855 | public static final int TYPE_WAKE = 1; |
| 856 | public static final int TYPE_CPU = 2; |
| 857 | |
| 858 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 859 | public long overTime; |
| 860 | public long usedTime; |
| 861 | } |
| 862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 864 | * Returns true if this process is still active in the battery stats. |
| 865 | */ |
| 866 | public abstract boolean isActive(); |
| 867 | |
| 868 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 869 | * 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] | 870 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 871 | * @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] | 872 | */ |
| 873 | public abstract long getUserTime(int which); |
| 874 | |
| 875 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 876 | * 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] | 877 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 878 | * @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] | 879 | */ |
| 880 | public abstract long getSystemTime(int which); |
| 881 | |
| 882 | /** |
| 883 | * Returns the number of times the process has been started. |
| 884 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 885 | * @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] | 886 | */ |
| 887 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 888 | |
| 889 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 890 | * Returns the number of times the process has crashed. |
| 891 | * |
| 892 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 893 | */ |
| 894 | public abstract int getNumCrashes(int which); |
| 895 | |
| 896 | /** |
| 897 | * Returns the number of times the process has ANRed. |
| 898 | * |
| 899 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 900 | */ |
| 901 | public abstract int getNumAnrs(int which); |
| 902 | |
| 903 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 904 | * 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] | 905 | * @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] | 906 | * @return foreground cpu time in microseconds |
| 907 | */ |
| 908 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 909 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 910 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 911 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 912 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /** |
| 916 | * The statistics associated with a particular package. |
| 917 | */ |
| 918 | public static abstract class Pkg { |
| 919 | |
| 920 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 921 | * Returns information about all wakeup alarms that have been triggered for this |
| 922 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 923 | * 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] | 924 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 925 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | |
| 927 | /** |
| 928 | * Returns a mapping containing service statistics. |
| 929 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 930 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | |
| 932 | /** |
| 933 | * The statistics associated with a particular service. |
| 934 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 935 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | |
| 937 | /** |
| 938 | * Returns the amount of time spent started. |
| 939 | * |
| 940 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 941 | * @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] | 942 | * @return |
| 943 | */ |
| 944 | public abstract long getStartTime(long batteryUptime, int which); |
| 945 | |
| 946 | /** |
| 947 | * Returns the total number of times startService() has been called. |
| 948 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 949 | * @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] | 950 | */ |
| 951 | public abstract int getStarts(int which); |
| 952 | |
| 953 | /** |
| 954 | * Returns the total number times the service has been launched. |
| 955 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 956 | * @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] | 957 | */ |
| 958 | public abstract int getLaunches(int which); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 963 | public static final class LevelStepTracker { |
| 964 | public long mLastStepTime = -1; |
| 965 | public int mNumStepDurations; |
| 966 | public final long[] mStepDurations; |
| 967 | |
| 968 | public LevelStepTracker(int maxLevelSteps) { |
| 969 | mStepDurations = new long[maxLevelSteps]; |
| 970 | } |
| 971 | |
| 972 | public LevelStepTracker(int numSteps, long[] steps) { |
| 973 | mNumStepDurations = numSteps; |
| 974 | mStepDurations = new long[numSteps]; |
| 975 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 976 | } |
| 977 | |
| 978 | public long getDurationAt(int index) { |
| 979 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 980 | } |
| 981 | |
| 982 | public int getLevelAt(int index) { |
| 983 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 984 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 985 | } |
| 986 | |
| 987 | public int getInitModeAt(int index) { |
| 988 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 989 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 990 | } |
| 991 | |
| 992 | public int getModModeAt(int index) { |
| 993 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 994 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 995 | } |
| 996 | |
| 997 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 998 | boolean hasData = false; |
| 999 | while (topOffset >= 0) { |
| 1000 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1001 | topOffset -= 4; |
| 1002 | if (!hasData && digit == 0) { |
| 1003 | continue; |
| 1004 | } |
| 1005 | hasData = true; |
| 1006 | if (digit >= 0 && digit <= 9) { |
| 1007 | out.append((char)('0' + digit)); |
| 1008 | } else { |
| 1009 | out.append((char)('a' + digit - 10)); |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1015 | long item = mStepDurations[index]; |
| 1016 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1017 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1018 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1019 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1020 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1021 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1022 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1023 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1024 | case Display.STATE_OFF: out.append('f'); break; |
| 1025 | case Display.STATE_ON: out.append('o'); break; |
| 1026 | case Display.STATE_DOZE: out.append('d'); break; |
| 1027 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1028 | } |
| 1029 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1030 | out.append('p'); |
| 1031 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1032 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1033 | out.append('i'); |
| 1034 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1035 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1036 | case Display.STATE_OFF: out.append('F'); break; |
| 1037 | case Display.STATE_ON: out.append('O'); break; |
| 1038 | case Display.STATE_DOZE: out.append('D'); break; |
| 1039 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1040 | } |
| 1041 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1042 | out.append('P'); |
| 1043 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1044 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1045 | out.append('I'); |
| 1046 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1047 | out.append('-'); |
| 1048 | appendHex(level, 4, out); |
| 1049 | out.append('-'); |
| 1050 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1051 | } |
| 1052 | |
| 1053 | public void decodeEntryAt(int index, String value) { |
| 1054 | final int N = value.length(); |
| 1055 | int i = 0; |
| 1056 | char c; |
| 1057 | long out = 0; |
| 1058 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1059 | i++; |
| 1060 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1061 | 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] | 1062 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1063 | 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] | 1064 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1065 | 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] | 1066 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1067 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1068 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1069 | break; |
| 1070 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1071 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1072 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1073 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1074 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1075 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1076 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1077 | break; |
| 1078 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1079 | break; |
| 1080 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1081 | break; |
| 1082 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1083 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1084 | break; |
| 1085 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1086 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1087 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1088 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1089 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1090 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1094 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1095 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1096 | i++; |
| 1097 | level <<= 4; |
| 1098 | if (c >= '0' && c <= '9') { |
| 1099 | level += c - '0'; |
| 1100 | } else if (c >= 'a' && c <= 'f') { |
| 1101 | level += c - 'a' + 10; |
| 1102 | } else if (c >= 'A' && c <= 'F') { |
| 1103 | level += c - 'A' + 10; |
| 1104 | } |
| 1105 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1106 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1107 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1108 | long duration = 0; |
| 1109 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1110 | i++; |
| 1111 | duration <<= 4; |
| 1112 | if (c >= '0' && c <= '9') { |
| 1113 | duration += c - '0'; |
| 1114 | } else if (c >= 'a' && c <= 'f') { |
| 1115 | duration += c - 'a' + 10; |
| 1116 | } else if (c >= 'A' && c <= 'F') { |
| 1117 | duration += c - 'A' + 10; |
| 1118 | } |
| 1119 | } |
| 1120 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1121 | } |
| 1122 | |
| 1123 | public void init() { |
| 1124 | mLastStepTime = -1; |
| 1125 | mNumStepDurations = 0; |
| 1126 | } |
| 1127 | |
| 1128 | public void clearTime() { |
| 1129 | mLastStepTime = -1; |
| 1130 | } |
| 1131 | |
| 1132 | public long computeTimePerLevel() { |
| 1133 | final long[] steps = mStepDurations; |
| 1134 | final int numSteps = mNumStepDurations; |
| 1135 | |
| 1136 | // For now we'll do a simple average across all steps. |
| 1137 | if (numSteps <= 0) { |
| 1138 | return -1; |
| 1139 | } |
| 1140 | long total = 0; |
| 1141 | for (int i=0; i<numSteps; i++) { |
| 1142 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1143 | } |
| 1144 | return total / numSteps; |
| 1145 | /* |
| 1146 | long[] buckets = new long[numSteps]; |
| 1147 | int numBuckets = 0; |
| 1148 | int numToAverage = 4; |
| 1149 | int i = 0; |
| 1150 | while (i < numSteps) { |
| 1151 | long totalTime = 0; |
| 1152 | int num = 0; |
| 1153 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1154 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1155 | num++; |
| 1156 | } |
| 1157 | buckets[numBuckets] = totalTime / num; |
| 1158 | numBuckets++; |
| 1159 | numToAverage *= 2; |
| 1160 | i += num; |
| 1161 | } |
| 1162 | if (numBuckets < 1) { |
| 1163 | return -1; |
| 1164 | } |
| 1165 | long averageTime = buckets[numBuckets-1]; |
| 1166 | for (i=numBuckets-2; i>=0; i--) { |
| 1167 | averageTime = (averageTime + buckets[i]) / 2; |
| 1168 | } |
| 1169 | return averageTime; |
| 1170 | */ |
| 1171 | } |
| 1172 | |
| 1173 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1174 | int[] outNumOfInterest) { |
| 1175 | final long[] steps = mStepDurations; |
| 1176 | final int count = mNumStepDurations; |
| 1177 | if (count <= 0) { |
| 1178 | return -1; |
| 1179 | } |
| 1180 | long total = 0; |
| 1181 | int numOfInterest = 0; |
| 1182 | for (int i=0; i<count; i++) { |
| 1183 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1184 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1185 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1186 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1187 | // If the modes of interest didn't change during this step period... |
| 1188 | if ((modMode&modesOfInterest) == 0) { |
| 1189 | // And the mode values during this period match those we are measuring... |
| 1190 | if ((initMode&modesOfInterest) == modeValues) { |
| 1191 | // Then this can be used to estimate the total time! |
| 1192 | numOfInterest++; |
| 1193 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | if (numOfInterest <= 0) { |
| 1198 | return -1; |
| 1199 | } |
| 1200 | |
| 1201 | if (outNumOfInterest != null) { |
| 1202 | outNumOfInterest[0] = numOfInterest; |
| 1203 | } |
| 1204 | |
| 1205 | // The estimated time is the average time we spend in each level, multipled |
| 1206 | // by 100 -- the total number of battery levels |
| 1207 | return (total / numOfInterest) * 100; |
| 1208 | } |
| 1209 | |
| 1210 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1211 | int stepCount = mNumStepDurations; |
| 1212 | final long lastStepTime = mLastStepTime; |
| 1213 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1214 | final long[] steps = mStepDurations; |
| 1215 | long duration = elapsedRealtime - lastStepTime; |
| 1216 | for (int i=0; i<numStepLevels; i++) { |
| 1217 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1218 | long thisDuration = duration / (numStepLevels-i); |
| 1219 | duration -= thisDuration; |
| 1220 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1221 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1222 | } |
| 1223 | steps[0] = thisDuration | modeBits; |
| 1224 | } |
| 1225 | stepCount += numStepLevels; |
| 1226 | if (stepCount > steps.length) { |
| 1227 | stepCount = steps.length; |
| 1228 | } |
| 1229 | } |
| 1230 | mNumStepDurations = stepCount; |
| 1231 | mLastStepTime = elapsedRealtime; |
| 1232 | } |
| 1233 | |
| 1234 | public void readFromParcel(Parcel in) { |
| 1235 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1236 | if (N > mStepDurations.length) { |
| 1237 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1238 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1239 | mNumStepDurations = N; |
| 1240 | for (int i=0; i<N; i++) { |
| 1241 | mStepDurations[i] = in.readLong(); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | public void writeToParcel(Parcel out) { |
| 1246 | final int N = mNumStepDurations; |
| 1247 | out.writeInt(N); |
| 1248 | for (int i=0; i<N; i++) { |
| 1249 | out.writeLong(mStepDurations[i]); |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1254 | public static final class PackageChange { |
| 1255 | public String mPackageName; |
| 1256 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1257 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1260 | public static final class DailyItem { |
| 1261 | public long mStartTime; |
| 1262 | public long mEndTime; |
| 1263 | public LevelStepTracker mDischargeSteps; |
| 1264 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1265 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1269 | |
| 1270 | public abstract long getCurrentDailyStartTime(); |
| 1271 | |
| 1272 | public abstract long getNextMinDailyDeadline(); |
| 1273 | |
| 1274 | public abstract long getNextMaxDailyDeadline(); |
| 1275 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1276 | public abstract long[] getCpuFreqs(); |
| 1277 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1278 | public final static class HistoryTag { |
| 1279 | public String string; |
| 1280 | public int uid; |
| 1281 | |
| 1282 | public int poolIdx; |
| 1283 | |
| 1284 | public void setTo(HistoryTag o) { |
| 1285 | string = o.string; |
| 1286 | uid = o.uid; |
| 1287 | poolIdx = o.poolIdx; |
| 1288 | } |
| 1289 | |
| 1290 | public void setTo(String _string, int _uid) { |
| 1291 | string = _string; |
| 1292 | uid = _uid; |
| 1293 | poolIdx = -1; |
| 1294 | } |
| 1295 | |
| 1296 | public void writeToParcel(Parcel dest, int flags) { |
| 1297 | dest.writeString(string); |
| 1298 | dest.writeInt(uid); |
| 1299 | } |
| 1300 | |
| 1301 | public void readFromParcel(Parcel src) { |
| 1302 | string = src.readString(); |
| 1303 | uid = src.readInt(); |
| 1304 | poolIdx = -1; |
| 1305 | } |
| 1306 | |
| 1307 | @Override |
| 1308 | public boolean equals(Object o) { |
| 1309 | if (this == o) return true; |
| 1310 | if (o == null || getClass() != o.getClass()) return false; |
| 1311 | |
| 1312 | HistoryTag that = (HistoryTag) o; |
| 1313 | |
| 1314 | if (uid != that.uid) return false; |
| 1315 | if (!string.equals(that.string)) return false; |
| 1316 | |
| 1317 | return true; |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
| 1321 | public int hashCode() { |
| 1322 | int result = string.hashCode(); |
| 1323 | result = 31 * result + uid; |
| 1324 | return result; |
| 1325 | } |
| 1326 | } |
| 1327 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1328 | /** |
| 1329 | * Optional detailed information that can go into a history step. This is typically |
| 1330 | * generated each time the battery level changes. |
| 1331 | */ |
| 1332 | public final static class HistoryStepDetails { |
| 1333 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1334 | public int userTime; |
| 1335 | public int systemTime; |
| 1336 | |
| 1337 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1338 | public int appCpuUid1; |
| 1339 | public int appCpuUTime1; |
| 1340 | public int appCpuSTime1; |
| 1341 | public int appCpuUid2; |
| 1342 | public int appCpuUTime2; |
| 1343 | public int appCpuSTime2; |
| 1344 | public int appCpuUid3; |
| 1345 | public int appCpuUTime3; |
| 1346 | public int appCpuSTime3; |
| 1347 | |
| 1348 | // Information from /proc/stat |
| 1349 | public int statUserTime; |
| 1350 | public int statSystemTime; |
| 1351 | public int statIOWaitTime; |
| 1352 | public int statIrqTime; |
| 1353 | public int statSoftIrqTime; |
| 1354 | public int statIdlTime; |
| 1355 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1356 | // Platform-level low power state stats |
| 1357 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1358 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1359 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1360 | public HistoryStepDetails() { |
| 1361 | clear(); |
| 1362 | } |
| 1363 | |
| 1364 | public void clear() { |
| 1365 | userTime = systemTime = 0; |
| 1366 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1367 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1368 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1369 | } |
| 1370 | |
| 1371 | public void writeToParcel(Parcel out) { |
| 1372 | out.writeInt(userTime); |
| 1373 | out.writeInt(systemTime); |
| 1374 | out.writeInt(appCpuUid1); |
| 1375 | out.writeInt(appCpuUTime1); |
| 1376 | out.writeInt(appCpuSTime1); |
| 1377 | out.writeInt(appCpuUid2); |
| 1378 | out.writeInt(appCpuUTime2); |
| 1379 | out.writeInt(appCpuSTime2); |
| 1380 | out.writeInt(appCpuUid3); |
| 1381 | out.writeInt(appCpuUTime3); |
| 1382 | out.writeInt(appCpuSTime3); |
| 1383 | out.writeInt(statUserTime); |
| 1384 | out.writeInt(statSystemTime); |
| 1385 | out.writeInt(statIOWaitTime); |
| 1386 | out.writeInt(statIrqTime); |
| 1387 | out.writeInt(statSoftIrqTime); |
| 1388 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1389 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1390 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | public void readFromParcel(Parcel in) { |
| 1394 | userTime = in.readInt(); |
| 1395 | systemTime = in.readInt(); |
| 1396 | appCpuUid1 = in.readInt(); |
| 1397 | appCpuUTime1 = in.readInt(); |
| 1398 | appCpuSTime1 = in.readInt(); |
| 1399 | appCpuUid2 = in.readInt(); |
| 1400 | appCpuUTime2 = in.readInt(); |
| 1401 | appCpuSTime2 = in.readInt(); |
| 1402 | appCpuUid3 = in.readInt(); |
| 1403 | appCpuUTime3 = in.readInt(); |
| 1404 | appCpuSTime3 = in.readInt(); |
| 1405 | statUserTime = in.readInt(); |
| 1406 | statSystemTime = in.readInt(); |
| 1407 | statIOWaitTime = in.readInt(); |
| 1408 | statIrqTime = in.readInt(); |
| 1409 | statSoftIrqTime = in.readInt(); |
| 1410 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1411 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1412 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1416 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1417 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1418 | |
| 1419 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1420 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1421 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1422 | 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] | 1423 | public static final byte CMD_NULL = -1; |
| 1424 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1425 | public static final byte CMD_CURRENT_TIME = 5; |
| 1426 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1427 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1428 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1429 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1430 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1431 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1432 | /** |
| 1433 | * Return whether the command code is a delta data update. |
| 1434 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1435 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1436 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1437 | } |
| 1438 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1439 | public byte batteryLevel; |
| 1440 | public byte batteryStatus; |
| 1441 | public byte batteryHealth; |
| 1442 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1443 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1444 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1445 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1446 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1447 | // The charge of the battery in micro-Ampere-hours. |
| 1448 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1449 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1450 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1451 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1452 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1453 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1454 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1455 | 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] | 1456 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1457 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1458 | 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] | 1459 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1460 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1461 | 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] | 1462 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1463 | // These states always appear directly in the first int token |
| 1464 | // of a delta change; they should be ones that change relatively |
| 1465 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1466 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1467 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1468 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1469 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1470 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1471 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1472 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1473 | // Do not use, this is used for coulomb delta count. |
| 1474 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1475 | // These are on the lower bits used for the command; if they change |
| 1476 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1477 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1478 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1479 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1480 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1481 | 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] | 1482 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1483 | // empty slot |
| 1484 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1485 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1486 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1487 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1488 | |
| 1489 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1490 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1491 | public int states; |
| 1492 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1493 | // Constants from WIFI_SUPPL_STATE_* |
| 1494 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1495 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1496 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1497 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1498 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1499 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1500 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1501 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1502 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1503 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1504 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1505 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1506 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1507 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1508 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1509 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1510 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1511 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1512 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1513 | |
| 1514 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1515 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1516 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1517 | |
| 1518 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1519 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1520 | public int states2; |
| 1521 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1522 | // The wake lock that was acquired at this point. |
| 1523 | public HistoryTag wakelockTag; |
| 1524 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1525 | // Kernel wakeup reason at this point. |
| 1526 | public HistoryTag wakeReasonTag; |
| 1527 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1528 | // Non-null when there is more detailed information at this step. |
| 1529 | public HistoryStepDetails stepDetails; |
| 1530 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1531 | public static final int EVENT_FLAG_START = 0x8000; |
| 1532 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1533 | |
| 1534 | // No event in this item. |
| 1535 | public static final int EVENT_NONE = 0x0000; |
| 1536 | // Event is about a process that is running. |
| 1537 | public static final int EVENT_PROC = 0x0001; |
| 1538 | // Event is about an application package that is in the foreground. |
| 1539 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1540 | // Event is about an application package that is at the top of the screen. |
| 1541 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1542 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1543 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1544 | // Events for all additional wake locks aquired/release within a wake block. |
| 1545 | // These are not generated by default. |
| 1546 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1547 | // Event is about an application executing a scheduled job. |
| 1548 | public static final int EVENT_JOB = 0x0006; |
| 1549 | // Events for users running. |
| 1550 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1551 | // Events for foreground user. |
| 1552 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1553 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1554 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1555 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1556 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1557 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1558 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1559 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1560 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1561 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1562 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1563 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1564 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1565 | // 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] | 1566 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1567 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1568 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1569 | // Event for a package being on the temporary whitelist. |
| 1570 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1571 | // Event for the screen waking up. |
| 1572 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1573 | // Event for the UID that woke up the application processor. |
| 1574 | // Used for wakeups coming from WiFi, modem, etc. |
| 1575 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1576 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1577 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1578 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1579 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1580 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1581 | // Mask to extract out only the type part of the event. |
| 1582 | 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] | 1583 | |
| 1584 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1585 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1586 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1587 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1588 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1589 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1590 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1591 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1592 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1593 | 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] | 1594 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1595 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1596 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1597 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1598 | public static final int EVENT_USER_FOREGROUND_START = |
| 1599 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1600 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1601 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1602 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1603 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1604 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1605 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1606 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1607 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1608 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1609 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1610 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1611 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1612 | |
| 1613 | // For CMD_EVENT. |
| 1614 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1615 | public HistoryTag eventTag; |
| 1616 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1617 | // 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] | 1618 | public long currentTime; |
| 1619 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1620 | // Meta-data when reading. |
| 1621 | public int numReadInts; |
| 1622 | |
| 1623 | // Pre-allocated objects. |
| 1624 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1625 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1626 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1627 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1628 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1629 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1630 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1631 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1632 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1633 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1634 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1635 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1636 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1637 | public int describeContents() { |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | public void writeToParcel(Parcel dest, int flags) { |
| 1642 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1643 | int bat = (((int)cmd)&0xff) |
| 1644 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1645 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1646 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1647 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1648 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1649 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1650 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1651 | dest.writeInt(bat); |
| 1652 | bat = (((int)batteryTemperature)&0xffff) |
| 1653 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1654 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1655 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1656 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1657 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1658 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1659 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1660 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1661 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1662 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1663 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1664 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1665 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1666 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1667 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1668 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1669 | dest.writeLong(currentTime); |
| 1670 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1671 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1672 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1673 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1674 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1675 | int bat = src.readInt(); |
| 1676 | cmd = (byte)(bat&0xff); |
| 1677 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1678 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1679 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1680 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1681 | int bat2 = src.readInt(); |
| 1682 | batteryTemperature = (short)(bat2&0xffff); |
| 1683 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1684 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1685 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1686 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1687 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1688 | wakelockTag = localWakelockTag; |
| 1689 | wakelockTag.readFromParcel(src); |
| 1690 | } else { |
| 1691 | wakelockTag = null; |
| 1692 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1693 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1694 | wakeReasonTag = localWakeReasonTag; |
| 1695 | wakeReasonTag.readFromParcel(src); |
| 1696 | } else { |
| 1697 | wakeReasonTag = null; |
| 1698 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1699 | if ((bat&0x40000000) != 0) { |
| 1700 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1701 | eventTag = localEventTag; |
| 1702 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1703 | } else { |
| 1704 | eventCode = EVENT_NONE; |
| 1705 | eventTag = null; |
| 1706 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1707 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1708 | currentTime = src.readLong(); |
| 1709 | } else { |
| 1710 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1711 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1712 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1715 | public void clear() { |
| 1716 | time = 0; |
| 1717 | cmd = CMD_NULL; |
| 1718 | batteryLevel = 0; |
| 1719 | batteryStatus = 0; |
| 1720 | batteryHealth = 0; |
| 1721 | batteryPlugType = 0; |
| 1722 | batteryTemperature = 0; |
| 1723 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1724 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1725 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1726 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1727 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1728 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1729 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1730 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1731 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1732 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1733 | public void setTo(HistoryItem o) { |
| 1734 | time = o.time; |
| 1735 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1736 | setToCommon(o); |
| 1737 | } |
| 1738 | |
| 1739 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1740 | this.time = time; |
| 1741 | this.cmd = cmd; |
| 1742 | setToCommon(o); |
| 1743 | } |
| 1744 | |
| 1745 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1746 | batteryLevel = o.batteryLevel; |
| 1747 | batteryStatus = o.batteryStatus; |
| 1748 | batteryHealth = o.batteryHealth; |
| 1749 | batteryPlugType = o.batteryPlugType; |
| 1750 | batteryTemperature = o.batteryTemperature; |
| 1751 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1752 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1753 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1754 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1755 | if (o.wakelockTag != null) { |
| 1756 | wakelockTag = localWakelockTag; |
| 1757 | wakelockTag.setTo(o.wakelockTag); |
| 1758 | } else { |
| 1759 | wakelockTag = null; |
| 1760 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1761 | if (o.wakeReasonTag != null) { |
| 1762 | wakeReasonTag = localWakeReasonTag; |
| 1763 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1764 | } else { |
| 1765 | wakeReasonTag = null; |
| 1766 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1767 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1768 | if (o.eventTag != null) { |
| 1769 | eventTag = localEventTag; |
| 1770 | eventTag.setTo(o.eventTag); |
| 1771 | } else { |
| 1772 | eventTag = null; |
| 1773 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1774 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1777 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1778 | return batteryLevel == o.batteryLevel |
| 1779 | && batteryStatus == o.batteryStatus |
| 1780 | && batteryHealth == o.batteryHealth |
| 1781 | && batteryPlugType == o.batteryPlugType |
| 1782 | && batteryTemperature == o.batteryTemperature |
| 1783 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1784 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1785 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1786 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1787 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1788 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1789 | |
| 1790 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1791 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1794 | if (wakelockTag != o.wakelockTag) { |
| 1795 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1796 | return false; |
| 1797 | } |
| 1798 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1799 | return false; |
| 1800 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1801 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1802 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1803 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1804 | return false; |
| 1805 | } |
| 1806 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1807 | return false; |
| 1808 | } |
| 1809 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1810 | if (eventTag != o.eventTag) { |
| 1811 | if (eventTag == null || o.eventTag == null) { |
| 1812 | return false; |
| 1813 | } |
| 1814 | if (!eventTag.equals(o.eventTag)) { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } |
| 1818 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1819 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1820 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1821 | |
| 1822 | public final static class HistoryEventTracker { |
| 1823 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1824 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1825 | |
| 1826 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1827 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1828 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1829 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1830 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1831 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1832 | mActiveEvents[idx] = active; |
| 1833 | } |
| 1834 | SparseIntArray uids = active.get(name); |
| 1835 | if (uids == null) { |
| 1836 | uids = new SparseIntArray(); |
| 1837 | active.put(name, uids); |
| 1838 | } |
| 1839 | if (uids.indexOfKey(uid) >= 0) { |
| 1840 | // Already set, nothing to do! |
| 1841 | return false; |
| 1842 | } |
| 1843 | uids.put(uid, poolIdx); |
| 1844 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1845 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1846 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1847 | if (active == null) { |
| 1848 | // not currently active, nothing to do. |
| 1849 | return false; |
| 1850 | } |
| 1851 | SparseIntArray uids = active.get(name); |
| 1852 | if (uids == null) { |
| 1853 | // not currently active, nothing to do. |
| 1854 | return false; |
| 1855 | } |
| 1856 | idx = uids.indexOfKey(uid); |
| 1857 | if (idx < 0) { |
| 1858 | // not currently active, nothing to do. |
| 1859 | return false; |
| 1860 | } |
| 1861 | uids.removeAt(idx); |
| 1862 | if (uids.size() <= 0) { |
| 1863 | active.remove(name); |
| 1864 | } |
| 1865 | } |
| 1866 | return true; |
| 1867 | } |
| 1868 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1869 | public void removeEvents(int code) { |
| 1870 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1871 | mActiveEvents[idx] = null; |
| 1872 | } |
| 1873 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1874 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1875 | return mActiveEvents[code]; |
| 1876 | } |
| 1877 | } |
| 1878 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1879 | public static final class BitDescription { |
| 1880 | public final int mask; |
| 1881 | public final int shift; |
| 1882 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1883 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1884 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1885 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1886 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1887 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1888 | this.mask = mask; |
| 1889 | this.shift = -1; |
| 1890 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1891 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1892 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1893 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1894 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1895 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1896 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1897 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1898 | this.mask = mask; |
| 1899 | this.shift = shift; |
| 1900 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1901 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1902 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1903 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1904 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1905 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1906 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1907 | /** |
| 1908 | * Don't allow any more batching in to the current history event. This |
| 1909 | * is called when printing partial histories, so to ensure that the next |
| 1910 | * history event will go in to a new batch after what was printed in the |
| 1911 | * last partial history. |
| 1912 | */ |
| 1913 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1914 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1915 | public abstract int getHistoryTotalSize(); |
| 1916 | |
| 1917 | public abstract int getHistoryUsedSize(); |
| 1918 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1919 | public abstract boolean startIteratingHistoryLocked(); |
| 1920 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1921 | public abstract int getHistoryStringPoolSize(); |
| 1922 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1923 | public abstract int getHistoryStringPoolBytes(); |
| 1924 | |
| 1925 | public abstract String getHistoryTagPoolString(int index); |
| 1926 | |
| 1927 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1928 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1929 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1930 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1931 | public abstract void finishIteratingHistoryLocked(); |
| 1932 | |
| 1933 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1934 | |
| 1935 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1936 | |
| 1937 | public abstract void finishIteratingOldHistoryLocked(); |
| 1938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1940 | * Return the base time offset for the battery history. |
| 1941 | */ |
| 1942 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1943 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1944 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | * Returns the number of times the device has been started. |
| 1946 | */ |
| 1947 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1950 | * 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] | 1951 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1952 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | * {@hide} |
| 1954 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1955 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1956 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1957 | /** |
| 1958 | * Returns the number of times the screen was turned on. |
| 1959 | * |
| 1960 | * {@hide} |
| 1961 | */ |
| 1962 | public abstract int getScreenOnCount(int which); |
| 1963 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1964 | /** |
| 1965 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1966 | * running on battery. |
| 1967 | * |
| 1968 | * {@hide} |
| 1969 | */ |
| 1970 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1971 | |
| 1972 | /** |
| 1973 | * Returns the number of times the screen was turned dozing. |
| 1974 | * |
| 1975 | * {@hide} |
| 1976 | */ |
| 1977 | public abstract int getScreenDozeCount(int which); |
| 1978 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1979 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1980 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1981 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1982 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1983 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1984 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1985 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1986 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1987 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1988 | "dark", "dim", "medium", "light", "bright" |
| 1989 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1990 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1991 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1992 | "0", "1", "2", "3", "4" |
| 1993 | }; |
| 1994 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1995 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1996 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1997 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1998 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1999 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2000 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2001 | * {@hide} |
| 2002 | */ |
| 2003 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2004 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2006 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2007 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2008 | * |
| 2009 | * {@hide} |
| 2010 | */ |
| 2011 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2012 | |
| 2013 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2014 | * 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] | 2015 | * running on battery. |
| 2016 | * |
| 2017 | * {@hide} |
| 2018 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2019 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2020 | |
| 2021 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2022 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2023 | * |
| 2024 | * {@hide} |
| 2025 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2026 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2027 | |
| 2028 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2029 | * Constant for device idle mode: not active. |
| 2030 | */ |
| 2031 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 2032 | |
| 2033 | /** |
| 2034 | * Constant for device idle mode: active in lightweight mode. |
| 2035 | */ |
| 2036 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 2037 | |
| 2038 | /** |
| 2039 | * Constant for device idle mode: active in full mode. |
| 2040 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2041 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2042 | |
| 2043 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2044 | * Returns the time in microseconds that device has been in idle mode while |
| 2045 | * running on battery. |
| 2046 | * |
| 2047 | * {@hide} |
| 2048 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2049 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2050 | |
| 2051 | /** |
| 2052 | * Returns the number of times that the devie has gone in to idle mode. |
| 2053 | * |
| 2054 | * {@hide} |
| 2055 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2056 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2057 | |
| 2058 | /** |
| 2059 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2060 | * mode, not in idle maintenance etc). |
| 2061 | */ |
| 2062 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2063 | |
| 2064 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2065 | * 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] | 2066 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2067 | * counts all of the time that we consider the device to be idle, whether or not |
| 2068 | * it is currently in the actual device idle mode. |
| 2069 | * |
| 2070 | * {@hide} |
| 2071 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2072 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2073 | |
| 2074 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2075 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2076 | * |
| 2077 | * {@hide} |
| 2078 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2079 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2080 | |
| 2081 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2082 | * Returns the number of times that connectivity state changed. |
| 2083 | * |
| 2084 | * {@hide} |
| 2085 | */ |
| 2086 | public abstract int getNumConnectivityChange(int which); |
| 2087 | |
| 2088 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2089 | * 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] | 2090 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2091 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | * {@hide} |
| 2093 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2094 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2095 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2096 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2097 | * Returns the number of times a phone call was activated. |
| 2098 | * |
| 2099 | * {@hide} |
| 2100 | */ |
| 2101 | public abstract int getPhoneOnCount(int which); |
| 2102 | |
| 2103 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2104 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2105 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2106 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2107 | * {@hide} |
| 2108 | */ |
| 2109 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2110 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2111 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2112 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2113 | * Returns the time in microseconds that the phone has been trying to |
| 2114 | * acquire a signal. |
| 2115 | * |
| 2116 | * {@hide} |
| 2117 | */ |
| 2118 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2119 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2120 | |
| 2121 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2122 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2123 | * acquire a signal. |
| 2124 | * |
| 2125 | * {@hide} |
| 2126 | */ |
| 2127 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2128 | |
| 2129 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2130 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2131 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2132 | * {@hide} |
| 2133 | */ |
| 2134 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2135 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2136 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2137 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2138 | * counts. |
| 2139 | */ |
| 2140 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2141 | |
| 2142 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2143 | * Returns the time in microseconds that the mobile network has been active |
| 2144 | * (in a high power state). |
| 2145 | * |
| 2146 | * {@hide} |
| 2147 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2148 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2149 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2150 | /** |
| 2151 | * Returns the number of times that the mobile network has transitioned to the |
| 2152 | * active state. |
| 2153 | * |
| 2154 | * {@hide} |
| 2155 | */ |
| 2156 | public abstract int getMobileRadioActiveCount(int which); |
| 2157 | |
| 2158 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2159 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2160 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2161 | * from the radio. |
| 2162 | * |
| 2163 | * {@hide} |
| 2164 | */ |
| 2165 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2166 | |
| 2167 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2168 | * Returns the time in microseconds that the mobile network has been active |
| 2169 | * (in a high power state) but not being able to blame on an app. |
| 2170 | * |
| 2171 | * {@hide} |
| 2172 | */ |
| 2173 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2174 | |
| 2175 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2176 | * 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] | 2177 | * |
| 2178 | * {@hide} |
| 2179 | */ |
| 2180 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2181 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2182 | public static final int DATA_CONNECTION_NONE = 0; |
| 2183 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2184 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2185 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2186 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2187 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2188 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2189 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2190 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2191 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2192 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2193 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2194 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2195 | public static final int DATA_CONNECTION_LTE = 13; |
| 2196 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2197 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2198 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2199 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2200 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2201 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2202 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2203 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2204 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2205 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2206 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2207 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2208 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2209 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2210 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2211 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2212 | * {@hide} |
| 2213 | */ |
| 2214 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2215 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2217 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2218 | * Returns the number of times the phone has entered the given data |
| 2219 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2220 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2221 | * {@hide} |
| 2222 | */ |
| 2223 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2224 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2225 | /** |
| 2226 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2227 | */ |
| 2228 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2229 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2230 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2231 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2232 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2233 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2234 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2235 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2236 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2237 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2238 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2239 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2240 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2241 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2242 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2243 | |
| 2244 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2245 | |
| 2246 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2247 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2248 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2249 | "group-handshake", "completed", "dormant", "uninit" |
| 2250 | }; |
| 2251 | |
| 2252 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2253 | "inv", "dsc", "dis", "inact", "scan", |
| 2254 | "auth", "ascing", "asced", "4-way", |
| 2255 | "group", "compl", "dorm", "uninit" |
| 2256 | }; |
| 2257 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2258 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2259 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2260 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2261 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2262 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2263 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2264 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2265 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2266 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2267 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2268 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2269 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2270 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2271 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2272 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2273 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2274 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2275 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2276 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2277 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2278 | new String[] {"in", "out", "emergency", "off"}, |
| 2279 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2280 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2281 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2282 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2283 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2284 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2285 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2286 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2287 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2288 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2289 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2290 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2291 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2292 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2293 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2294 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2295 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2296 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2297 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2298 | new String[] { "off", "light", "full", "???" }, |
| 2299 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2300 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2301 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2302 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2303 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2304 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2305 | new String[] { "0", "1", "2", "3", "4" }, |
| 2306 | new String[] { "0", "1", "2", "3", "4" }), |
| 2307 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2308 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2309 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2310 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2311 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2312 | }; |
| 2313 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2314 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2315 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2316 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2317 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2318 | }; |
| 2319 | |
| 2320 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2321 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2322 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2323 | "Esw", "Ewa", "Elw", "Eec" |
| 2324 | }; |
| 2325 | |
| 2326 | @FunctionalInterface |
| 2327 | public interface IntToString { |
| 2328 | String applyAsString(int val); |
| 2329 | } |
| 2330 | |
| 2331 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2332 | private static final IntToString sIntToString = Integer::toString; |
| 2333 | |
| 2334 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2335 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2336 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2337 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2338 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2339 | }; |
| 2340 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2341 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2342 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2343 | * Note that this may be different from the sum of per uid timer values. |
| 2344 | * |
| 2345 | * {@hide} |
| 2346 | */ |
| 2347 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2348 | |
| 2349 | /** |
| 2350 | * Returns total time for WiFi Multicast Wakelock timer |
| 2351 | * Note that this may be different from the sum of per uid timer values. |
| 2352 | * |
| 2353 | * {@hide} |
| 2354 | */ |
| 2355 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2356 | |
| 2357 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2358 | * 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] | 2359 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2360 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2361 | * {@hide} |
| 2362 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2363 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2364 | |
| 2365 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2366 | * 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] | 2367 | * been in the running state while the device was running on battery. |
| 2368 | * |
| 2369 | * {@hide} |
| 2370 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2371 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2372 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2373 | public static final int WIFI_STATE_OFF = 0; |
| 2374 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2375 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2376 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2377 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2378 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2379 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2380 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2381 | |
| 2382 | static final String[] WIFI_STATE_NAMES = { |
| 2383 | "off", "scanning", "no_net", "disconn", |
| 2384 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2385 | }; |
| 2386 | |
| 2387 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2388 | |
| 2389 | /** |
| 2390 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2391 | * |
| 2392 | * {@hide} |
| 2393 | */ |
| 2394 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2395 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2396 | |
| 2397 | /** |
| 2398 | * Returns the number of times that WiFi has entered the given state. |
| 2399 | * |
| 2400 | * {@hide} |
| 2401 | */ |
| 2402 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2403 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2404 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2405 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2406 | * |
| 2407 | * {@hide} |
| 2408 | */ |
| 2409 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2410 | |
| 2411 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2412 | * Returns the time in microseconds that the wifi supplicant has been |
| 2413 | * in a given state. |
| 2414 | * |
| 2415 | * {@hide} |
| 2416 | */ |
| 2417 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2418 | |
| 2419 | /** |
| 2420 | * Returns the number of times that the wifi supplicant has transitioned |
| 2421 | * to a given state. |
| 2422 | * |
| 2423 | * {@hide} |
| 2424 | */ |
| 2425 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2426 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2427 | /** |
| 2428 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2429 | * |
| 2430 | * {@hide} |
| 2431 | */ |
| 2432 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2433 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2434 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2435 | |
| 2436 | /** |
| 2437 | * Returns the time in microseconds that WIFI has been running with |
| 2438 | * the given signal strength. |
| 2439 | * |
| 2440 | * {@hide} |
| 2441 | */ |
| 2442 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2443 | long elapsedRealtimeUs, int which); |
| 2444 | |
| 2445 | /** |
| 2446 | * Returns the number of times WIFI has entered the given signal strength. |
| 2447 | * |
| 2448 | * {@hide} |
| 2449 | */ |
| 2450 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2451 | |
| 2452 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2453 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2454 | * |
| 2455 | * {@hide} |
| 2456 | */ |
| 2457 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2458 | |
| 2459 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2460 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2461 | * running on battery. |
| 2462 | * |
| 2463 | * {@hide} |
| 2464 | */ |
| 2465 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2466 | |
| 2467 | /** |
| 2468 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2469 | * running on battery. |
| 2470 | * |
| 2471 | * {@hide} |
| 2472 | */ |
| 2473 | public abstract long getFlashlightOnCount(int which); |
| 2474 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2475 | /** |
| 2476 | * Returns the time in microseconds that the camera has been on while the device was |
| 2477 | * running on battery. |
| 2478 | * |
| 2479 | * {@hide} |
| 2480 | */ |
| 2481 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2482 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2483 | /** |
| 2484 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2485 | * on battery. |
| 2486 | * |
| 2487 | * {@hide} |
| 2488 | */ |
| 2489 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2490 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2491 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2492 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2493 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2494 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2495 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2496 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2497 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2498 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2499 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2500 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2501 | 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] | 2502 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2503 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2504 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2505 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2506 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2507 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2508 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2509 | * actual power data. |
| 2510 | */ |
| 2511 | public abstract boolean hasWifiActivityReporting(); |
| 2512 | |
| 2513 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2514 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2515 | * in various radio controller states, such as transmit, receive, and idle. |
| 2516 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2517 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2518 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2519 | |
| 2520 | /** |
| 2521 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2522 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2523 | * actual power data. |
| 2524 | */ |
| 2525 | public abstract boolean hasBluetoothActivityReporting(); |
| 2526 | |
| 2527 | /** |
| 2528 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2529 | * in various radio controller states, such as transmit, receive, and idle. |
| 2530 | * @return non-null {@link ControllerActivityCounter} |
| 2531 | */ |
| 2532 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2533 | |
| 2534 | /** |
| 2535 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2536 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2537 | * actual power data. |
| 2538 | */ |
| 2539 | public abstract boolean hasModemActivityReporting(); |
| 2540 | |
| 2541 | /** |
| 2542 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2543 | * in various radio controller states, such as transmit, receive, and idle. |
| 2544 | * @return non-null {@link ControllerActivityCounter} |
| 2545 | */ |
| 2546 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2547 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2548 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2549 | * Return the wall clock time when battery stats data collection started. |
| 2550 | */ |
| 2551 | public abstract long getStartClockTime(); |
| 2552 | |
| 2553 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2554 | * Return platform version tag that we were running in when the battery stats started. |
| 2555 | */ |
| 2556 | public abstract String getStartPlatformVersion(); |
| 2557 | |
| 2558 | /** |
| 2559 | * Return platform version tag that we were running in when the battery stats ended. |
| 2560 | */ |
| 2561 | public abstract String getEndPlatformVersion(); |
| 2562 | |
| 2563 | /** |
| 2564 | * Return the internal version code of the parcelled format. |
| 2565 | */ |
| 2566 | public abstract int getParcelVersion(); |
| 2567 | |
| 2568 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | * Return whether we are currently running on battery. |
| 2570 | */ |
| 2571 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | /** |
| 2574 | * Returns a SparseArray containing the statistics for each uid. |
| 2575 | */ |
| 2576 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2577 | |
| 2578 | /** |
| 2579 | * Returns the current battery uptime in microseconds. |
| 2580 | * |
| 2581 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2582 | */ |
| 2583 | public abstract long getBatteryUptime(long curTime); |
| 2584 | |
| 2585 | /** |
| 2586 | * Returns the current battery realtime in microseconds. |
| 2587 | * |
| 2588 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2589 | */ |
| 2590 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2591 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2592 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2593 | * 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] | 2594 | * the last time it booted on battery power. |
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 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2597 | |
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 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2600 | * returns the level at the last plug event. |
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 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | |
| 2604 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2605 | * Get the amount the battery has discharged since the stats were |
| 2606 | * last reset after charging, as a lower-end approximation. |
| 2607 | */ |
| 2608 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2609 | |
| 2610 | /** |
| 2611 | * Get the amount the battery has discharged since the stats were |
| 2612 | * last reset after charging, as an upper-end approximation. |
| 2613 | */ |
| 2614 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2615 | |
| 2616 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2617 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2618 | */ |
| 2619 | public abstract int getDischargeAmount(int which); |
| 2620 | |
| 2621 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2622 | * Get the amount the battery has discharged while the screen was on, |
| 2623 | * since the last time power was unplugged. |
| 2624 | */ |
| 2625 | public abstract int getDischargeAmountScreenOn(); |
| 2626 | |
| 2627 | /** |
| 2628 | * Get the amount the battery has discharged while the screen was on, |
| 2629 | * since the last time the device was charged. |
| 2630 | */ |
| 2631 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2632 | |
| 2633 | /** |
| 2634 | * Get the amount the battery has discharged while the screen was off, |
| 2635 | * since the last time power was unplugged. |
| 2636 | */ |
| 2637 | public abstract int getDischargeAmountScreenOff(); |
| 2638 | |
| 2639 | /** |
| 2640 | * Get the amount the battery has discharged while the screen was off, |
| 2641 | * since the last time the device was charged. |
| 2642 | */ |
| 2643 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2644 | |
| 2645 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2646 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2647 | * since the last time power was unplugged. |
| 2648 | */ |
| 2649 | public abstract int getDischargeAmountScreenDoze(); |
| 2650 | |
| 2651 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2652 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2653 | * since the last time the device was charged. |
| 2654 | */ |
| 2655 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2656 | |
| 2657 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | * Returns the total, last, or current battery uptime in microseconds. |
| 2659 | * |
| 2660 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2661 | * @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] | 2662 | */ |
| 2663 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2664 | |
| 2665 | /** |
| 2666 | * Returns the total, last, or current battery realtime in microseconds. |
| 2667 | * |
| 2668 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2669 | * @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] | 2670 | */ |
| 2671 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2672 | |
| 2673 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2674 | * 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] | 2675 | * |
| 2676 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2677 | * @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] | 2678 | */ |
| 2679 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2680 | |
| 2681 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2682 | * 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] | 2683 | * |
| 2684 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2685 | * @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] | 2686 | */ |
| 2687 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2688 | |
| 2689 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | * Returns the total, last, or current uptime in microseconds. |
| 2691 | * |
| 2692 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2693 | * @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] | 2694 | */ |
| 2695 | public abstract long computeUptime(long curTime, int which); |
| 2696 | |
| 2697 | /** |
| 2698 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2699 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2701 | * @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] | 2702 | */ |
| 2703 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2704 | |
| 2705 | /** |
| 2706 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2707 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2708 | * enough current data to make a decision, or the battery is currently |
| 2709 | * charging. |
| 2710 | * |
| 2711 | * @param curTime The current elepsed realtime in microseconds. |
| 2712 | */ |
| 2713 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2714 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2715 | // The part of a step duration that is the actual time. |
| 2716 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2717 | |
| 2718 | // Bits in a step duration that are the new battery level we are at. |
| 2719 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2720 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2721 | |
| 2722 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2723 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2724 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2725 | |
| 2726 | // Bits in a step duration that indicate which modes changed during that step. |
| 2727 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2728 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2729 | |
| 2730 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2731 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2732 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2733 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2734 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2735 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2736 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2737 | // Step duration mode: power save is on. |
| 2738 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2739 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2740 | // Step duration mode: device is currently in idle mode. |
| 2741 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2742 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2743 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2744 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2745 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2746 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2747 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2748 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2749 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2750 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2751 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2752 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2753 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2754 | }; |
| 2755 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2756 | (Display.STATE_OFF-1), |
| 2757 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2758 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2759 | (Display.STATE_ON-1), |
| 2760 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2761 | (Display.STATE_DOZE-1), |
| 2762 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2763 | (Display.STATE_DOZE_SUSPEND-1), |
| 2764 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2765 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2766 | }; |
| 2767 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2768 | "screen off", |
| 2769 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2770 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2771 | "screen on", |
| 2772 | "screen on power save", |
| 2773 | "screen doze", |
| 2774 | "screen doze power save", |
| 2775 | "screen doze-suspend", |
| 2776 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2777 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2778 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2779 | |
| 2780 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2781 | * 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] | 2782 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2783 | * a coulomb counter. |
| 2784 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2785 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2786 | |
| 2787 | /** |
| 2788 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2789 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2790 | * a coulomb counter. |
| 2791 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2792 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2793 | |
| 2794 | /** |
| 2795 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2796 | * non-zero only if the device's battery has a coulomb counter. |
| 2797 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2798 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2799 | |
| 2800 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2801 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2802 | * micro-Ampere-hours. |
| 2803 | */ |
| 2804 | public abstract long getUahDischargeLightDoze(int which); |
| 2805 | |
| 2806 | /** |
| 2807 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2808 | * micro-Ampere-hours. |
| 2809 | */ |
| 2810 | public abstract long getUahDischargeDeepDoze(int which); |
| 2811 | |
| 2812 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2813 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2814 | * declared by the PowerProfile. |
| 2815 | * @return The estimated battery capacity in mAh. |
| 2816 | */ |
| 2817 | public abstract int getEstimatedBatteryCapacity(); |
| 2818 | |
| 2819 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2820 | * @return The minimum learned battery capacity in uAh. |
| 2821 | */ |
| 2822 | public abstract int getMinLearnedBatteryCapacity(); |
| 2823 | |
| 2824 | /** |
| 2825 | * @return The maximum learned battery capacity in uAh. |
| 2826 | */ |
| 2827 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2828 | |
| 2829 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2830 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2831 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2832 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2833 | |
| 2834 | /** |
| 2835 | * Return the array of daily discharge step durations. |
| 2836 | */ |
| 2837 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2838 | |
| 2839 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2840 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2841 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2842 | * enough current data to make a decision, or the battery is currently |
| 2843 | * discharging. |
| 2844 | * |
| 2845 | * @param curTime The current elepsed realtime in microseconds. |
| 2846 | */ |
| 2847 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2848 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2849 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2850 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2851 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2852 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2853 | |
| 2854 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2855 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2856 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2857 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2858 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2859 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2860 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2861 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2862 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2863 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2865 | /** |
| 2866 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2867 | */ |
| 2868 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2869 | /** |
| 2870 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2871 | */ |
| 2872 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2873 | |
| 2874 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2875 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2876 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2877 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2878 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2879 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | long days = seconds / (60 * 60 * 24); |
| 2881 | if (days != 0) { |
| 2882 | out.append(days); |
| 2883 | out.append("d "); |
| 2884 | } |
| 2885 | long used = days * 60 * 60 * 24; |
| 2886 | |
| 2887 | long hours = (seconds - used) / (60 * 60); |
| 2888 | if (hours != 0 || used != 0) { |
| 2889 | out.append(hours); |
| 2890 | out.append("h "); |
| 2891 | } |
| 2892 | used += hours * 60 * 60; |
| 2893 | |
| 2894 | long mins = (seconds-used) / 60; |
| 2895 | if (mins != 0 || used != 0) { |
| 2896 | out.append(mins); |
| 2897 | out.append("m "); |
| 2898 | } |
| 2899 | used += mins * 60; |
| 2900 | |
| 2901 | if (seconds != 0 || used != 0) { |
| 2902 | out.append(seconds-used); |
| 2903 | out.append("s "); |
| 2904 | } |
| 2905 | } |
| 2906 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2907 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2909 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | sb.append(time - (sec * 1000)); |
| 2911 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | } |
| 2913 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2914 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2915 | long sec = time / 1000; |
| 2916 | formatTimeRaw(sb, sec); |
| 2917 | sb.append(time - (sec * 1000)); |
| 2918 | sb.append("ms"); |
| 2919 | } |
| 2920 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2921 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2923 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | } |
| 2925 | float perc = ((float)num) / ((float)den) * 100; |
| 2926 | mFormatBuilder.setLength(0); |
| 2927 | mFormatter.format("%.1f%%", perc); |
| 2928 | return mFormatBuilder.toString(); |
| 2929 | } |
| 2930 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2931 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2932 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2933 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2934 | if (bytes < BYTES_PER_KB) { |
| 2935 | return bytes + "B"; |
| 2936 | } else if (bytes < BYTES_PER_MB) { |
| 2937 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2938 | return mFormatBuilder.toString(); |
| 2939 | } else if (bytes < BYTES_PER_GB){ |
| 2940 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2941 | return mFormatBuilder.toString(); |
| 2942 | } else { |
| 2943 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2944 | return mFormatBuilder.toString(); |
| 2945 | } |
| 2946 | } |
| 2947 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 2948 | private static long roundUsToMs(long timeUs) { |
| 2949 | return (timeUs + 500) / 1000; |
| 2950 | } |
| 2951 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2952 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2953 | if (timer != null) { |
| 2954 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2955 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2956 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2957 | return totalTimeMillis; |
| 2958 | } |
| 2959 | return 0; |
| 2960 | } |
| 2961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | /** |
| 2963 | * |
| 2964 | * @param sb a StringBuilder object. |
| 2965 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2966 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2968 | * @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] | 2969 | * @param linePrefix a String to be prepended to each line of output. |
| 2970 | * @return the line prefix |
| 2971 | */ |
| 2972 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2973 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2976 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2977 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2978 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | if (totalTimeMillis != 0) { |
| 2980 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2981 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2982 | if (name != null) { |
| 2983 | sb.append(name); |
| 2984 | sb.append(' '); |
| 2985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | sb.append('('); |
| 2987 | sb.append(count); |
| 2988 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2989 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2990 | if (maxDurationMs >= 0) { |
| 2991 | sb.append(" max="); |
| 2992 | sb.append(maxDurationMs); |
| 2993 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2994 | // Put actual time if it is available and different from totalTimeMillis. |
| 2995 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2996 | if (totalDurMs > totalTimeMillis) { |
| 2997 | sb.append(" actual="); |
| 2998 | sb.append(totalDurMs); |
| 2999 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3000 | if (timer.isRunningLocked()) { |
| 3001 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3002 | if (currentMs >= 0) { |
| 3003 | sb.append(" (running for "); |
| 3004 | sb.append(currentMs); |
| 3005 | sb.append("ms)"); |
| 3006 | } else { |
| 3007 | sb.append(" (running)"); |
| 3008 | } |
| 3009 | } |
| 3010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | return ", "; |
| 3012 | } |
| 3013 | } |
| 3014 | return linePrefix; |
| 3015 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3016 | |
| 3017 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3018 | * 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] | 3019 | * |
| 3020 | * @param pw a PrintWriter object to print to. |
| 3021 | * @param sb a StringBuilder object. |
| 3022 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3023 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3024 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3025 | * @param prefix a String to be prepended to each line of output. |
| 3026 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3027 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3028 | */ |
| 3029 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3030 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3031 | if (timer != null) { |
| 3032 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3033 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3034 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3035 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3036 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3037 | sb.setLength(0); |
| 3038 | sb.append(prefix); |
| 3039 | sb.append(" "); |
| 3040 | sb.append(type); |
| 3041 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3042 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3043 | sb.append("realtime ("); |
| 3044 | sb.append(count); |
| 3045 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3046 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3047 | if (maxDurationMs >= 0) { |
| 3048 | sb.append(" max="); |
| 3049 | sb.append(maxDurationMs); |
| 3050 | } |
| 3051 | if (timer.isRunningLocked()) { |
| 3052 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3053 | if (currentMs >= 0) { |
| 3054 | sb.append(" (running for "); |
| 3055 | sb.append(currentMs); |
| 3056 | sb.append("ms)"); |
| 3057 | } else { |
| 3058 | sb.append(" (running)"); |
| 3059 | } |
| 3060 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3061 | pw.println(sb.toString()); |
| 3062 | return true; |
| 3063 | } |
| 3064 | } |
| 3065 | return false; |
| 3066 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | /** |
| 3069 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
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 | * @param sb a StringBuilder object. |
| 3072 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3073 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3075 | * @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] | 3076 | * @param linePrefix a String to be prepended to each line of output. |
| 3077 | * @return the line prefix |
| 3078 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3079 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3080 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | long totalTimeMicros = 0; |
| 3082 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3083 | long max = 0; |
| 3084 | long current = 0; |
| 3085 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3087 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3088 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3089 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3090 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3091 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | } |
| 3093 | sb.append(linePrefix); |
| 3094 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3095 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3096 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3098 | sb.append(','); |
| 3099 | sb.append(current); |
| 3100 | sb.append(','); |
| 3101 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3102 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3103 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3104 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3105 | if (name != null) { |
| 3106 | sb.append(','); |
| 3107 | sb.append(totalDuration); |
| 3108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | return ","; |
| 3110 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3111 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3112 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3113 | String type) { |
| 3114 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3115 | pw.print(','); |
| 3116 | pw.print(uid); |
| 3117 | pw.print(','); |
| 3118 | pw.print(category); |
| 3119 | pw.print(','); |
| 3120 | pw.print(type); |
| 3121 | } |
| 3122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | /** |
| 3124 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3125 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | * @param pw the PageWriter to dump log to |
| 3127 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3128 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3129 | * @param args type-dependent data arguments |
| 3130 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3131 | 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] | 3132 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3133 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3134 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3135 | pw.print(','); |
| 3136 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3138 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3140 | |
| 3141 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3142 | * Dump a given timer stat for terse checkin mode. |
| 3143 | * |
| 3144 | * @param pw the PageWriter to dump log to |
| 3145 | * @param uid the UID to log |
| 3146 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3147 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3148 | * @param timer a {@link Timer} to dump stats for |
| 3149 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3150 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3151 | */ |
| 3152 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3153 | Timer timer, long rawRealtime, int which) { |
| 3154 | if (timer != null) { |
| 3155 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3156 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3157 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3158 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3159 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3165 | * Dump a given timer stat to the proto stream. |
| 3166 | * |
| 3167 | * @param proto the ProtoOutputStream to log to |
| 3168 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3169 | * @param timer a {@link Timer} to dump stats for |
| 3170 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3171 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3172 | */ |
| 3173 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3174 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3175 | if (timer == null) { |
| 3176 | return; |
| 3177 | } |
| 3178 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3179 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3180 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3181 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3182 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3183 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3184 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3185 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3186 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3187 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3188 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3189 | // These values will be -1 for timers that don't implement the functionality. |
| 3190 | if (maxDurationMs != -1) { |
| 3191 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3192 | } |
| 3193 | if (curDurationMs != -1) { |
| 3194 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3195 | } |
| 3196 | if (totalDurationMs != -1) { |
| 3197 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3198 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3199 | proto.end(token); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3204 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3205 | */ |
| 3206 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3207 | if (counter == null) { |
| 3208 | return false; |
| 3209 | } |
| 3210 | |
| 3211 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3212 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3213 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3214 | return true; |
| 3215 | } |
| 3216 | |
| 3217 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3218 | if (c.getCountLocked(which) != 0) { |
| 3219 | return true; |
| 3220 | } |
| 3221 | } |
| 3222 | return false; |
| 3223 | } |
| 3224 | |
| 3225 | /** |
| 3226 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3227 | * The order of the arguments in the final check in line is: |
| 3228 | * |
| 3229 | * idle, rx, power, tx... |
| 3230 | * |
| 3231 | * where tx... is one or more transmit level times. |
| 3232 | */ |
| 3233 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3234 | String type, |
| 3235 | ControllerActivityCounter counter, |
| 3236 | int which) { |
| 3237 | if (!controllerActivityHasData(counter, which)) { |
| 3238 | return; |
| 3239 | } |
| 3240 | |
| 3241 | dumpLineHeader(pw, uid, category, type); |
| 3242 | pw.print(","); |
| 3243 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3244 | pw.print(","); |
| 3245 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3246 | pw.print(","); |
| 3247 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3248 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3249 | pw.print(","); |
| 3250 | pw.print(c.getCountLocked(which)); |
| 3251 | } |
| 3252 | pw.println(); |
| 3253 | } |
| 3254 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3255 | /** |
| 3256 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3257 | */ |
| 3258 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3259 | ControllerActivityCounter counter, |
| 3260 | int which) { |
| 3261 | if (!controllerActivityHasData(counter, which)) { |
| 3262 | return; |
| 3263 | } |
| 3264 | |
| 3265 | final long cToken = proto.start(fieldId); |
| 3266 | |
| 3267 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3268 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3269 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3270 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3271 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3272 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3273 | |
| 3274 | long tToken; |
| 3275 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3276 | for (int i = 0; i < txCounters.length; ++i) { |
| 3277 | LongCounter c = txCounters[i]; |
| 3278 | tToken = proto.start(ControllerActivityProto.TX); |
| 3279 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3280 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3281 | proto.end(tToken); |
| 3282 | } |
| 3283 | |
| 3284 | proto.end(cToken); |
| 3285 | } |
| 3286 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3287 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3288 | String prefix, String controllerName, |
| 3289 | ControllerActivityCounter counter, |
| 3290 | int which) { |
| 3291 | if (controllerActivityHasData(counter, which)) { |
| 3292 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3297 | String controllerName, |
| 3298 | ControllerActivityCounter counter, int which) { |
| 3299 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3300 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3301 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3302 | // Battery real time |
| 3303 | final long totalControllerActivityTimeMs |
| 3304 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3305 | long totalTxTimeMs = 0; |
| 3306 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3307 | totalTxTimeMs += txState.getCountLocked(which); |
| 3308 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3309 | final long sleepTimeMs |
| 3310 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3311 | |
| 3312 | sb.setLength(0); |
| 3313 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3314 | sb.append(" "); |
| 3315 | sb.append(controllerName); |
| 3316 | sb.append(" Sleep time: "); |
| 3317 | formatTimeMs(sb, sleepTimeMs); |
| 3318 | sb.append("("); |
| 3319 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3320 | sb.append(")"); |
| 3321 | pw.println(sb.toString()); |
| 3322 | |
| 3323 | sb.setLength(0); |
| 3324 | sb.append(prefix); |
| 3325 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3326 | sb.append(controllerName); |
| 3327 | sb.append(" Idle time: "); |
| 3328 | formatTimeMs(sb, idleTimeMs); |
| 3329 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3330 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3331 | sb.append(")"); |
| 3332 | pw.println(sb.toString()); |
| 3333 | |
| 3334 | sb.setLength(0); |
| 3335 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3336 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3337 | sb.append(controllerName); |
| 3338 | sb.append(" Rx time: "); |
| 3339 | formatTimeMs(sb, rxTimeMs); |
| 3340 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3341 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3342 | sb.append(")"); |
| 3343 | pw.println(sb.toString()); |
| 3344 | |
| 3345 | sb.setLength(0); |
| 3346 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3347 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3348 | sb.append(controllerName); |
| 3349 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3350 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3351 | String [] powerLevel; |
| 3352 | switch(controllerName) { |
| 3353 | case "Cellular": |
| 3354 | powerLevel = new String[] { |
| 3355 | " less than 0dBm: ", |
| 3356 | " 0dBm to 8dBm: ", |
| 3357 | " 8dBm to 15dBm: ", |
| 3358 | " 15dBm to 20dBm: ", |
| 3359 | " above 20dBm: "}; |
| 3360 | break; |
| 3361 | default: |
| 3362 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3363 | break; |
| 3364 | } |
| 3365 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3366 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3367 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3368 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3369 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3370 | sb.setLength(0); |
| 3371 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3372 | sb.append(" "); |
| 3373 | sb.append(powerLevel[lvl]); |
| 3374 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3375 | formatTimeMs(sb, txLvlTimeMs); |
| 3376 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3377 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3378 | sb.append(")"); |
| 3379 | pw.println(sb.toString()); |
| 3380 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3381 | } else { |
| 3382 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3383 | formatTimeMs(sb, txLvlTimeMs); |
| 3384 | sb.append("("); |
| 3385 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3386 | sb.append(")"); |
| 3387 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3388 | } |
| 3389 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3390 | if (powerDrainMaMs > 0) { |
| 3391 | sb.setLength(0); |
| 3392 | sb.append(prefix); |
| 3393 | sb.append(" "); |
| 3394 | sb.append(controllerName); |
| 3395 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3396 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3397 | sb.append("mAh"); |
| 3398 | pw.println(sb.toString()); |
| 3399 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3403 | * Temporary for settings. |
| 3404 | */ |
| 3405 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3406 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3407 | } |
| 3408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | /** |
| 3410 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3411 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3412 | * 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] | 3413 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3414 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3415 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3417 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3418 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3421 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3422 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3423 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3424 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3426 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3427 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3428 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3429 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3430 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3431 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3432 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3433 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3434 | rawRealtime, which); |
| 3435 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3436 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3437 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3438 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3439 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3440 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3441 | final long dischargeCount = getUahDischarge(which); |
| 3442 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3443 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3444 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3445 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3446 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3447 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3448 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3449 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3450 | final int NU = uidStats.size(); |
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 String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3455 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3456 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3457 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3458 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3459 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3460 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3461 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3462 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3463 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3464 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3465 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3466 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3467 | long fullWakeLockTimeTotal = 0; |
| 3468 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3469 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3470 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3471 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3472 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3473 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3474 | = u.getWakelockStats(); |
| 3475 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3476 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3477 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3478 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3479 | if (fullWakeTimer != null) { |
| 3480 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3481 | which); |
| 3482 | } |
| 3483 | |
| 3484 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3485 | if (partialWakeTimer != null) { |
| 3486 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3487 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3491 | |
| 3492 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3493 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3494 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3495 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3496 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3497 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3498 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3499 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3500 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3501 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3502 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3503 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3504 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3505 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3506 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3507 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3508 | // Dump Modem controller stats |
| 3509 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3510 | getModemControllerActivity(), which); |
| 3511 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3512 | // Dump Wifi controller stats |
| 3513 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3514 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3515 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3516 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3517 | |
| 3518 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3519 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3520 | |
| 3521 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3522 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3523 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | // Dump misc stats |
| 3526 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3527 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3528 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3529 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3530 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3531 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3532 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3533 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3534 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3535 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3536 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3537 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3538 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3539 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3540 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3541 | // Dump screen brightness stats |
| 3542 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3543 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3544 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3545 | } |
| 3546 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3547 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3548 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3549 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3550 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3551 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3552 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3553 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3554 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3555 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3556 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3557 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3558 | } |
| 3559 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3560 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3561 | // Dump network type stats |
| 3562 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3563 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3564 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3565 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3566 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3567 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3568 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3569 | } |
| 3570 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3571 | |
| 3572 | // Dump wifi state stats |
| 3573 | args = new Object[NUM_WIFI_STATES]; |
| 3574 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3575 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3576 | } |
| 3577 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3578 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3579 | args[i] = getWifiStateCount(i, which); |
| 3580 | } |
| 3581 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3582 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3583 | // Dump wifi suppl state stats |
| 3584 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3585 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3586 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3587 | } |
| 3588 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3589 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3590 | args[i] = getWifiSupplStateCount(i, which); |
| 3591 | } |
| 3592 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3593 | |
| 3594 | // Dump wifi signal strength stats |
| 3595 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3596 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3597 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3598 | } |
| 3599 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3600 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3601 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3602 | } |
| 3603 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3604 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3605 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3606 | final long multicastWakeLockTimeTotalMicros = |
| 3607 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3608 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3609 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3610 | multicastWakeLockTimeTotalMicros / 1000, |
| 3611 | multicastWakeLockCountTotal); |
| 3612 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3613 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3614 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3615 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3616 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3617 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3618 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3619 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3620 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3621 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3622 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3623 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3624 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3625 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3626 | } else { |
| 3627 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3628 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3629 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3630 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3631 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3632 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3633 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3634 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3635 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3636 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3637 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3638 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3639 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3640 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3641 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3642 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3643 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3644 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3645 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3646 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3647 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3648 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3649 | // Not doing the regular wake lock formatting to remain compatible |
| 3650 | // with the old checkin format. |
| 3651 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3652 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3653 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3654 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3655 | } |
| 3656 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3657 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3658 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3659 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3660 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3661 | if (rpmStats.size() > 0) { |
| 3662 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3663 | sb.setLength(0); |
| 3664 | Timer totalTimer = ent.getValue(); |
| 3665 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3666 | int count = totalTimer.getCountLocked(which); |
| 3667 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3668 | long screenOffTimeMs = screenOffTimer != null |
| 3669 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3670 | int screenOffCount = screenOffTimer != null |
| 3671 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3672 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3673 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3674 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3675 | screenOffCount); |
| 3676 | } else { |
| 3677 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3678 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3679 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3683 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3684 | helper.create(this); |
| 3685 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3686 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3687 | if (sippers != null && sippers.size() > 0) { |
| 3688 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3689 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3690 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3691 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3692 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3693 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3694 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3695 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3696 | String label; |
| 3697 | switch (bs.drainType) { |
| 3698 | case IDLE: |
| 3699 | label="idle"; |
| 3700 | break; |
| 3701 | case CELL: |
| 3702 | label="cell"; |
| 3703 | break; |
| 3704 | case PHONE: |
| 3705 | label="phone"; |
| 3706 | break; |
| 3707 | case WIFI: |
| 3708 | label="wifi"; |
| 3709 | break; |
| 3710 | case BLUETOOTH: |
| 3711 | label="blue"; |
| 3712 | break; |
| 3713 | case SCREEN: |
| 3714 | label="scrn"; |
| 3715 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3716 | case FLASHLIGHT: |
| 3717 | label="flashlight"; |
| 3718 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3719 | case APP: |
| 3720 | uid = bs.uidObj.getUid(); |
| 3721 | label = "uid"; |
| 3722 | break; |
| 3723 | case USER: |
| 3724 | uid = UserHandle.getUid(bs.userId, 0); |
| 3725 | label = "user"; |
| 3726 | break; |
| 3727 | case UNACCOUNTED: |
| 3728 | label = "unacc"; |
| 3729 | break; |
| 3730 | case OVERCOUNTED: |
| 3731 | label = "over"; |
| 3732 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3733 | case CAMERA: |
| 3734 | label = "camera"; |
| 3735 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3736 | case MEMORY: |
| 3737 | label = "memory"; |
| 3738 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3739 | default: |
| 3740 | label = "???"; |
| 3741 | } |
| 3742 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3743 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3744 | bs.shouldHide ? 1 : 0, |
| 3745 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3746 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3747 | } |
| 3748 | } |
| 3749 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3750 | final long[] cpuFreqs = getCpuFreqs(); |
| 3751 | if (cpuFreqs != null) { |
| 3752 | sb.setLength(0); |
| 3753 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3754 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3755 | } |
| 3756 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3757 | } |
| 3758 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3759 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3760 | for (int iu = 0; iu < NU; iu++) { |
| 3761 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3762 | if (reqUid >= 0 && uid != reqUid) { |
| 3763 | continue; |
| 3764 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3765 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3768 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3769 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3770 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3771 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3772 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3773 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3774 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3775 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3776 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3777 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3778 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3779 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3780 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3781 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3782 | // Background data transfers |
| 3783 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3784 | which); |
| 3785 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3786 | which); |
| 3787 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3788 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3789 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3790 | which); |
| 3791 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3792 | which); |
| 3793 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3794 | which); |
| 3795 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3796 | which); |
| 3797 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3798 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3799 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3800 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3801 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3802 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3803 | || wifiBytesBgTx > 0 |
| 3804 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3805 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3806 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3807 | wifiBytesRx, wifiBytesTx, |
| 3808 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3809 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3810 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3811 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3812 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3813 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3814 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3817 | // Dump modem controller data, per UID. |
| 3818 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3819 | u.getModemControllerActivity(), which); |
| 3820 | |
| 3821 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3822 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3823 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3824 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3825 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3826 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3827 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3828 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3829 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3830 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3831 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3832 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3833 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3834 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3835 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3836 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3837 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3839 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3840 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3841 | u.getWifiControllerActivity(), which); |
| 3842 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3843 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3844 | if (bleTimer != null) { |
| 3845 | // Convert from microseconds to milliseconds with rounding |
| 3846 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3847 | / 1000; |
| 3848 | if (totalTime != 0) { |
| 3849 | final int count = bleTimer.getCountLocked(which); |
| 3850 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3851 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3852 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3853 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3854 | final long actualTimeBg = bleTimerBg != null ? |
| 3855 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3856 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3857 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3858 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3859 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3860 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3861 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3862 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3863 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3864 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3865 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3866 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3867 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3868 | final Timer unoptimizedScanTimerBg = |
| 3869 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3870 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3871 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3872 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3873 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3874 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3875 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3876 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3877 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3878 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3879 | } |
| 3880 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3881 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3882 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3883 | u.getBluetoothControllerActivity(), which); |
| 3884 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3885 | if (u.hasUserActivity()) { |
| 3886 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3887 | boolean hasData = false; |
| 3888 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3889 | int val = u.getUserActivityCount(i, which); |
| 3890 | args[i] = val; |
| 3891 | if (val != 0) hasData = true; |
| 3892 | } |
| 3893 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3894 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3895 | } |
| 3896 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3897 | |
| 3898 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3899 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3900 | // Times are since reset (regardless of 'which') |
| 3901 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3902 | final Timer bgTimer = timer.getSubTimer(); |
| 3903 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3904 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3905 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3906 | } |
| 3907 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3908 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3909 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3910 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3911 | String linePrefix = ""; |
| 3912 | sb.setLength(0); |
| 3913 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3914 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3915 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3916 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3917 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3918 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3919 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3920 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3921 | rawRealtime, "w", which, linePrefix); |
| 3922 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3923 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3924 | if (sb.length() > 0) { |
| 3925 | String name = wakelocks.keyAt(iw); |
| 3926 | if (name.indexOf(',') >= 0) { |
| 3927 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3929 | if (name.indexOf('\n') >= 0) { |
| 3930 | name = name.replace('\n', '_'); |
| 3931 | } |
| 3932 | if (name.indexOf('\r') >= 0) { |
| 3933 | name = name.replace('\r', '_'); |
| 3934 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3935 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | } |
| 3937 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3938 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3939 | // WiFi Multicast Wakelock Statistics |
| 3940 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3941 | if (mcTimer != null) { |
| 3942 | final long totalMcWakelockTimeMs = |
| 3943 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 3944 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 3945 | if(totalMcWakelockTimeMs > 0) { |
| 3946 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 3947 | totalMcWakelockTimeMs, countMcWakelock); |
| 3948 | } |
| 3949 | } |
| 3950 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3951 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3952 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3953 | final Timer timer = syncs.valueAt(isy); |
| 3954 | // Convert from microseconds to milliseconds with rounding |
| 3955 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3956 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3957 | final Timer bgTimer = timer.getSubTimer(); |
| 3958 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3959 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3960 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3961 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3962 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3963 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3964 | } |
| 3965 | } |
| 3966 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3967 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3968 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3969 | final Timer timer = jobs.valueAt(ij); |
| 3970 | // Convert from microseconds to milliseconds with rounding |
| 3971 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3972 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3973 | final Timer bgTimer = timer.getSubTimer(); |
| 3974 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3975 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3976 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3977 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3978 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3979 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3983 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3984 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3985 | SparseIntArray types = completions.valueAt(ic); |
| 3986 | if (types != null) { |
| 3987 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3988 | "\"" + completions.keyAt(ic) + "\"", |
| 3989 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3990 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3991 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3992 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3993 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3994 | } |
| 3995 | } |
| 3996 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3997 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3998 | rawRealtime, which); |
| 3999 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4000 | rawRealtime, which); |
| 4001 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4002 | rawRealtime, which); |
| 4003 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4004 | rawRealtime, which); |
| 4005 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4006 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4007 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4008 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4009 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4010 | final int sensorNumber = sensors.keyAt(ise); |
| 4011 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4012 | if (timer != null) { |
| 4013 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4014 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4015 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4016 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4017 | final int count = timer.getCountLocked(which); |
| 4018 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4019 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4020 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4021 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4022 | final long bgActualTime = bgTimer != null ? |
| 4023 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4024 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4025 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | } |
| 4028 | } |
| 4029 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4030 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4031 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4032 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4033 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4034 | rawRealtime, which); |
| 4035 | |
| 4036 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4037 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4038 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4039 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4040 | long totalStateTime = 0; |
| 4041 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4042 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4043 | totalStateTime += time; |
| 4044 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4045 | } |
| 4046 | if (totalStateTime > 0) { |
| 4047 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4048 | } |
| 4049 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4050 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4051 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4052 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4053 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4054 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4055 | } |
| 4056 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4057 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4058 | if (cpuFreqs != null) { |
| 4059 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4060 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4061 | // screenOffCpuFreqTimes. |
| 4062 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4063 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4064 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4065 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4066 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4067 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4068 | if (screenOffCpuFreqTimeMs != null) { |
| 4069 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4070 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4071 | } |
| 4072 | } else { |
| 4073 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4074 | sb.append(",0"); |
| 4075 | } |
| 4076 | } |
| 4077 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4078 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4079 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4080 | |
| 4081 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4082 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4083 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4084 | sb.setLength(0); |
| 4085 | for (int i = 0; i < timesMs.length; ++i) { |
| 4086 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4087 | } |
| 4088 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4089 | which, procState); |
| 4090 | if (screenOffTimesMs != null) { |
| 4091 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4092 | sb.append("," + screenOffTimesMs[i]); |
| 4093 | } |
| 4094 | } else { |
| 4095 | for (int i = 0; i < timesMs.length; ++i) { |
| 4096 | sb.append(",0"); |
| 4097 | } |
| 4098 | } |
| 4099 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4100 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4101 | } |
| 4102 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4105 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4106 | = u.getProcessStats(); |
| 4107 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4108 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4109 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4110 | final long userMillis = ps.getUserTime(which); |
| 4111 | final long systemMillis = ps.getSystemTime(which); |
| 4112 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4113 | final int starts = ps.getStarts(which); |
| 4114 | final int numCrashes = ps.getNumCrashes(which); |
| 4115 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4116 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4117 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4118 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4119 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4120 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4124 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4125 | = u.getPackageStats(); |
| 4126 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4127 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4128 | int wakeups = 0; |
| 4129 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4130 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4131 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4132 | wakeups += count; |
| 4133 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4134 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4135 | } |
| 4136 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4137 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4138 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4139 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4140 | final int starts = ss.getStarts(which); |
| 4141 | final int launches = ss.getLaunches(which); |
| 4142 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4143 | dumpLine(pw, uid, category, APK_DATA, |
| 4144 | wakeups, // wakeup alarms |
| 4145 | packageStats.keyAt(ipkg), // Apk |
| 4146 | serviceStats.keyAt(isvc), // service |
| 4147 | startTime / 1000, // time spent started, in ms |
| 4148 | starts, |
| 4149 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | } |
| 4151 | } |
| 4152 | } |
| 4153 | } |
| 4154 | } |
| 4155 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4156 | static final class TimerEntry { |
| 4157 | final String mName; |
| 4158 | final int mId; |
| 4159 | final BatteryStats.Timer mTimer; |
| 4160 | final long mTime; |
| 4161 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4162 | mName = name; |
| 4163 | mId = id; |
| 4164 | mTimer = timer; |
| 4165 | mTime = time; |
| 4166 | } |
| 4167 | } |
| 4168 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4169 | private void printmAh(PrintWriter printer, double power) { |
| 4170 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4171 | } |
| 4172 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4173 | private void printmAh(StringBuilder sb, double power) { |
| 4174 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4175 | } |
| 4176 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4177 | /** |
| 4178 | * Temporary for settings. |
| 4179 | */ |
| 4180 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4181 | int reqUid) { |
| 4182 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4183 | } |
| 4184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4186 | 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] | 4187 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4189 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4190 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | |
| 4193 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4194 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4195 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4196 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4197 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4198 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4199 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4200 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4201 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4202 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4203 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4204 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4205 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4206 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4207 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4209 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4210 | if (estimatedBatteryCapacity > 0) { |
| 4211 | sb.setLength(0); |
| 4212 | sb.append(prefix); |
| 4213 | sb.append(" Estimated battery capacity: "); |
| 4214 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4215 | sb.append(" mAh"); |
| 4216 | pw.println(sb.toString()); |
| 4217 | } |
| 4218 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4219 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4220 | if (minLearnedBatteryCapacity > 0) { |
| 4221 | sb.setLength(0); |
| 4222 | sb.append(prefix); |
| 4223 | sb.append(" Min learned battery capacity: "); |
| 4224 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4225 | sb.append(" mAh"); |
| 4226 | pw.println(sb.toString()); |
| 4227 | } |
| 4228 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4229 | if (maxLearnedBatteryCapacity > 0) { |
| 4230 | sb.setLength(0); |
| 4231 | sb.append(prefix); |
| 4232 | sb.append(" Max learned battery capacity: "); |
| 4233 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4234 | sb.append(" mAh"); |
| 4235 | pw.println(sb.toString()); |
| 4236 | } |
| 4237 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4238 | sb.setLength(0); |
| 4239 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4240 | sb.append(" Time on battery: "); |
| 4241 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4242 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4243 | sb.append(") realtime, "); |
| 4244 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4245 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4246 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4247 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4248 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4249 | sb.setLength(0); |
| 4250 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4251 | sb.append(" Time on battery screen off: "); |
| 4252 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4253 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4254 | sb.append(") realtime, "); |
| 4255 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4256 | sb.append("("); |
| 4257 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4258 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4259 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4260 | |
| 4261 | sb.setLength(0); |
| 4262 | sb.append(prefix); |
| 4263 | sb.append(" Time on battery screen doze: "); |
| 4264 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4265 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4266 | sb.append(")"); |
| 4267 | pw.println(sb.toString()); |
| 4268 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4269 | sb.setLength(0); |
| 4270 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4271 | sb.append(" Total run time: "); |
| 4272 | formatTimeMs(sb, totalRealtime / 1000); |
| 4273 | sb.append("realtime, "); |
| 4274 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4275 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4276 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4277 | if (batteryTimeRemaining >= 0) { |
| 4278 | sb.setLength(0); |
| 4279 | sb.append(prefix); |
| 4280 | sb.append(" Battery time remaining: "); |
| 4281 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4282 | pw.println(sb.toString()); |
| 4283 | } |
| 4284 | if (chargeTimeRemaining >= 0) { |
| 4285 | sb.setLength(0); |
| 4286 | sb.append(prefix); |
| 4287 | sb.append(" Charge time remaining: "); |
| 4288 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4289 | pw.println(sb.toString()); |
| 4290 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4291 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4292 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4293 | if (dischargeCount >= 0) { |
| 4294 | sb.setLength(0); |
| 4295 | sb.append(prefix); |
| 4296 | sb.append(" Discharge: "); |
| 4297 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4298 | sb.append(" mAh"); |
| 4299 | pw.println(sb.toString()); |
| 4300 | } |
| 4301 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4302 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4303 | if (dischargeScreenOffCount >= 0) { |
| 4304 | sb.setLength(0); |
| 4305 | sb.append(prefix); |
| 4306 | sb.append(" Screen off discharge: "); |
| 4307 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4308 | sb.append(" mAh"); |
| 4309 | pw.println(sb.toString()); |
| 4310 | } |
| 4311 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4312 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4313 | if (dischargeScreenDozeCount >= 0) { |
| 4314 | sb.setLength(0); |
| 4315 | sb.append(prefix); |
| 4316 | sb.append(" Screen doze discharge: "); |
| 4317 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4318 | sb.append(" mAh"); |
| 4319 | pw.println(sb.toString()); |
| 4320 | } |
| 4321 | |
| 4322 | final long dischargeScreenOnCount = |
| 4323 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4324 | if (dischargeScreenOnCount >= 0) { |
| 4325 | sb.setLength(0); |
| 4326 | sb.append(prefix); |
| 4327 | sb.append(" Screen on discharge: "); |
| 4328 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4329 | sb.append(" mAh"); |
| 4330 | pw.println(sb.toString()); |
| 4331 | } |
| 4332 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4333 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4334 | if (dischargeLightDozeCount >= 0) { |
| 4335 | sb.setLength(0); |
| 4336 | sb.append(prefix); |
| 4337 | sb.append(" Device light doze discharge: "); |
| 4338 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4339 | sb.append(" mAh"); |
| 4340 | pw.println(sb.toString()); |
| 4341 | } |
| 4342 | |
| 4343 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4344 | if (dischargeDeepDozeCount >= 0) { |
| 4345 | sb.setLength(0); |
| 4346 | sb.append(prefix); |
| 4347 | sb.append(" Device deep doze discharge: "); |
| 4348 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4349 | sb.append(" mAh"); |
| 4350 | pw.println(sb.toString()); |
| 4351 | } |
| 4352 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4353 | pw.print(" Start clock time: "); |
| 4354 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4355 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4356 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4357 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4358 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4359 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4360 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4361 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4362 | rawRealtime, which); |
| 4363 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4364 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4365 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4366 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4367 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4368 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4369 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4370 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4371 | sb.append(prefix); |
| 4372 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4373 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4374 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4375 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4376 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4377 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4378 | pw.println(sb.toString()); |
| 4379 | sb.setLength(0); |
| 4380 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4381 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4382 | boolean didOne = false; |
| 4383 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4384 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4385 | if (time == 0) { |
| 4386 | continue; |
| 4387 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4388 | sb.append("\n "); |
| 4389 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4390 | didOne = true; |
| 4391 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4392 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4393 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4394 | sb.append("("); |
| 4395 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4396 | sb.append(")"); |
| 4397 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4398 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4399 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4400 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4401 | sb.setLength(0); |
| 4402 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4403 | sb.append(" Power save mode enabled: "); |
| 4404 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4405 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4406 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4407 | sb.append(")"); |
| 4408 | pw.println(sb.toString()); |
| 4409 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4410 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4411 | sb.setLength(0); |
| 4412 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4413 | sb.append(" Device light idling: "); |
| 4414 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4415 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4416 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4417 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4418 | sb.append("x"); |
| 4419 | pw.println(sb.toString()); |
| 4420 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4421 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4422 | sb.setLength(0); |
| 4423 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4424 | sb.append(" Idle mode light time: "); |
| 4425 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4426 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4427 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4428 | sb.append(") "); |
| 4429 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4430 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4431 | sb.append(" -- longest "); |
| 4432 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4433 | pw.println(sb.toString()); |
| 4434 | } |
| 4435 | if (deviceIdlingTime != 0) { |
| 4436 | sb.setLength(0); |
| 4437 | sb.append(prefix); |
| 4438 | sb.append(" Device full idling: "); |
| 4439 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4440 | sb.append("("); |
| 4441 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4442 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4443 | sb.append("x"); |
| 4444 | pw.println(sb.toString()); |
| 4445 | } |
| 4446 | if (deviceIdleModeFullTime != 0) { |
| 4447 | sb.setLength(0); |
| 4448 | sb.append(prefix); |
| 4449 | sb.append(" Idle mode full time: "); |
| 4450 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4451 | sb.append("("); |
| 4452 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4453 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4454 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4455 | sb.append("x"); |
| 4456 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4457 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4458 | pw.println(sb.toString()); |
| 4459 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4460 | if (phoneOnTime != 0) { |
| 4461 | sb.setLength(0); |
| 4462 | sb.append(prefix); |
| 4463 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4464 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4465 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4466 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4467 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4468 | if (connChanges != 0) { |
| 4469 | pw.print(prefix); |
| 4470 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4471 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4472 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4473 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4474 | long fullWakeLockTimeTotalMicros = 0; |
| 4475 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4476 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4477 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4478 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4479 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4480 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4481 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4482 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4483 | = u.getWakelockStats(); |
| 4484 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4485 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4486 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4487 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4488 | if (fullWakeTimer != null) { |
| 4489 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4490 | rawRealtime, which); |
| 4491 | } |
| 4492 | |
| 4493 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4494 | if (partialWakeTimer != null) { |
| 4495 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4496 | rawRealtime, which); |
| 4497 | if (totalTimeMicros > 0) { |
| 4498 | if (reqUid < 0) { |
| 4499 | // Only show the ordered list of all wake |
| 4500 | // locks if the caller is not asking for data |
| 4501 | // about a specific uid. |
| 4502 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4503 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4504 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4505 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | } |
| 4509 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4510 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4511 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4512 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4513 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4514 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4515 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4516 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4517 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4518 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4519 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4520 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4521 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4522 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4523 | sb.setLength(0); |
| 4524 | sb.append(prefix); |
| 4525 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4526 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4527 | pw.println(sb.toString()); |
| 4528 | } |
| 4529 | |
| 4530 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4531 | sb.setLength(0); |
| 4532 | sb.append(prefix); |
| 4533 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4534 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4535 | pw.println(sb.toString()); |
| 4536 | } |
| 4537 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4538 | final long multicastWakeLockTimeTotalMicros = |
| 4539 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4540 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4541 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4542 | sb.setLength(0); |
| 4543 | sb.append(prefix); |
| 4544 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4545 | sb.append(multicastWakeLockCountTotal); |
| 4546 | pw.println(sb.toString()); |
| 4547 | |
| 4548 | sb.setLength(0); |
| 4549 | sb.append(prefix); |
| 4550 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4551 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4552 | pw.println(sb.toString()); |
| 4553 | } |
| 4554 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4555 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4556 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4557 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4558 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4559 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4560 | pw.println(sb.toString()); |
| 4561 | |
| 4562 | pw.print(prefix); |
| 4563 | sb.setLength(0); |
| 4564 | sb.append(prefix); |
| 4565 | sb.append(" Logging duration for connectivity statistics: "); |
| 4566 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4567 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4568 | |
| 4569 | sb.setLength(0); |
| 4570 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4571 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4572 | pw.println(sb.toString()); |
| 4573 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4574 | pw.print(prefix); |
| 4575 | sb.setLength(0); |
| 4576 | sb.append(prefix); |
| 4577 | sb.append(" Cellular kernel active time: "); |
| 4578 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4579 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4580 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4581 | sb.append(")"); |
| 4582 | pw.println(sb.toString()); |
| 4583 | |
| 4584 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4585 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4586 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4587 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4588 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4589 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4590 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4591 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4592 | didOne = false; |
| 4593 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4594 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4595 | if (time == 0) { |
| 4596 | continue; |
| 4597 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4598 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4599 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4600 | didOne = true; |
| 4601 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4602 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4603 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4604 | sb.append("("); |
| 4605 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4606 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4607 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4608 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4609 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4610 | |
| 4611 | sb.setLength(0); |
| 4612 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4613 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4614 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4615 | "very poor (less than -128dBm): ", |
| 4616 | "poor (-128dBm to -118dBm): ", |
| 4617 | "moderate (-118dBm to -108dBm): ", |
| 4618 | "good (-108dBm to -98dBm): ", |
| 4619 | "great (greater than -98dBm): "}; |
| 4620 | didOne = false; |
| 4621 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4622 | cellularRxSignalStrengthDescription.length); |
| 4623 | for (int i=0; i<numCellularRxBins; i++) { |
| 4624 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4625 | if (time == 0) { |
| 4626 | continue; |
| 4627 | } |
| 4628 | sb.append("\n "); |
| 4629 | sb.append(prefix); |
| 4630 | didOne = true; |
| 4631 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4632 | sb.append(" "); |
| 4633 | formatTimeMs(sb, time/1000); |
| 4634 | sb.append("("); |
| 4635 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4636 | sb.append(") "); |
| 4637 | } |
| 4638 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4639 | pw.println(sb.toString()); |
| 4640 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4641 | printControllerActivity(pw, sb, prefix, "Cellular", |
| 4642 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4643 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4644 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4645 | sb.setLength(0); |
| 4646 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4647 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4648 | pw.println(sb.toString()); |
| 4649 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4650 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4651 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4652 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4653 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4654 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4655 | sb.setLength(0); |
| 4656 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4657 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4658 | didOne = false; |
| 4659 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4660 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4661 | if (time == 0) { |
| 4662 | continue; |
| 4663 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4664 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4665 | didOne = true; |
| 4666 | sb.append(WIFI_STATE_NAMES[i]); |
| 4667 | sb.append(" "); |
| 4668 | formatTimeMs(sb, time/1000); |
| 4669 | sb.append("("); |
| 4670 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4671 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4672 | } |
| 4673 | if (!didOne) sb.append(" (no activity)"); |
| 4674 | pw.println(sb.toString()); |
| 4675 | |
| 4676 | sb.setLength(0); |
| 4677 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4678 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4679 | didOne = false; |
| 4680 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4681 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4682 | if (time == 0) { |
| 4683 | continue; |
| 4684 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4685 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4686 | didOne = true; |
| 4687 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4688 | sb.append(" "); |
| 4689 | formatTimeMs(sb, time/1000); |
| 4690 | sb.append("("); |
| 4691 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4692 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4693 | } |
| 4694 | if (!didOne) sb.append(" (no activity)"); |
| 4695 | pw.println(sb.toString()); |
| 4696 | |
| 4697 | sb.setLength(0); |
| 4698 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4699 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4700 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4701 | "very poor (less than -88.75dBm): ", |
| 4702 | "poor (-88.75 to -77.5dBm): ", |
| 4703 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4704 | "good (-66.25dBm to -55dBm): ", |
| 4705 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4706 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4707 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4708 | wifiRxSignalStrengthDescription.length); |
| 4709 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4710 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4711 | if (time == 0) { |
| 4712 | continue; |
| 4713 | } |
| 4714 | sb.append("\n "); |
| 4715 | sb.append(prefix); |
| 4716 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4717 | sb.append(" "); |
| 4718 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4719 | formatTimeMs(sb, time/1000); |
| 4720 | sb.append("("); |
| 4721 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4722 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4723 | } |
| 4724 | if (!didOne) sb.append(" (no activity)"); |
| 4725 | pw.println(sb.toString()); |
| 4726 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4727 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4728 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4729 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4730 | sb.setLength(0); |
| 4731 | sb.append(prefix); |
| 4732 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4733 | pw.println(sb.toString()); |
| 4734 | pw.println(""); |
| 4735 | |
| 4736 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4737 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4738 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4739 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4740 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4741 | sb.setLength(0); |
| 4742 | sb.append(prefix); |
| 4743 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4744 | pw.println(sb.toString()); |
| 4745 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4746 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4747 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4748 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4749 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4750 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4751 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4752 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4753 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4754 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4755 | pw.println(getDischargeStartLevel()); |
| 4756 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4757 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4758 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4759 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4760 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4761 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4762 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4763 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4764 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4765 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4766 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4767 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4768 | pw.println(getDischargeAmountScreenOff()); |
| 4769 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4770 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4771 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4772 | } else { |
| 4773 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4774 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4775 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4776 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4777 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4778 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4779 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4780 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4781 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4782 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4783 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4784 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4785 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4786 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4787 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4788 | helper.create(this); |
| 4789 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4790 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4791 | if (sippers != null && sippers.size() > 0) { |
| 4792 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4793 | pw.print(prefix); pw.print(" Capacity: "); |
| 4794 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4795 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4796 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4797 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4798 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4799 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4800 | pw.println(); |
| 4801 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4802 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4803 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4804 | switch (bs.drainType) { |
| 4805 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4806 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4807 | break; |
| 4808 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4809 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4810 | break; |
| 4811 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4812 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4813 | break; |
| 4814 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4815 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4816 | break; |
| 4817 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4818 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4819 | break; |
| 4820 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4821 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4822 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4823 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4824 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4825 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4826 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4827 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4828 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4829 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4830 | break; |
| 4831 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4832 | pw.print(" User "); pw.print(bs.userId); |
| 4833 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4834 | break; |
| 4835 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4836 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4837 | break; |
| 4838 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4839 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4840 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4841 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4842 | pw.print(" Camera: "); |
| 4843 | break; |
| 4844 | default: |
| 4845 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4846 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4847 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4848 | printmAh(pw, bs.totalPowerMah); |
| 4849 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4850 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4851 | // If the usage (generic power) isn't the whole amount, we list out |
| 4852 | // what components are involved in the calculation. |
| 4853 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4854 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4855 | if (bs.usagePowerMah != 0) { |
| 4856 | pw.print(" usage="); |
| 4857 | printmAh(pw, bs.usagePowerMah); |
| 4858 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4859 | if (bs.cpuPowerMah != 0) { |
| 4860 | pw.print(" cpu="); |
| 4861 | printmAh(pw, bs.cpuPowerMah); |
| 4862 | } |
| 4863 | if (bs.wakeLockPowerMah != 0) { |
| 4864 | pw.print(" wake="); |
| 4865 | printmAh(pw, bs.wakeLockPowerMah); |
| 4866 | } |
| 4867 | if (bs.mobileRadioPowerMah != 0) { |
| 4868 | pw.print(" radio="); |
| 4869 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4870 | } |
| 4871 | if (bs.wifiPowerMah != 0) { |
| 4872 | pw.print(" wifi="); |
| 4873 | printmAh(pw, bs.wifiPowerMah); |
| 4874 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4875 | if (bs.bluetoothPowerMah != 0) { |
| 4876 | pw.print(" bt="); |
| 4877 | printmAh(pw, bs.bluetoothPowerMah); |
| 4878 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4879 | if (bs.gpsPowerMah != 0) { |
| 4880 | pw.print(" gps="); |
| 4881 | printmAh(pw, bs.gpsPowerMah); |
| 4882 | } |
| 4883 | if (bs.sensorPowerMah != 0) { |
| 4884 | pw.print(" sensor="); |
| 4885 | printmAh(pw, bs.sensorPowerMah); |
| 4886 | } |
| 4887 | if (bs.cameraPowerMah != 0) { |
| 4888 | pw.print(" camera="); |
| 4889 | printmAh(pw, bs.cameraPowerMah); |
| 4890 | } |
| 4891 | if (bs.flashlightPowerMah != 0) { |
| 4892 | pw.print(" flash="); |
| 4893 | printmAh(pw, bs.flashlightPowerMah); |
| 4894 | } |
| 4895 | pw.print(" )"); |
| 4896 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4897 | |
| 4898 | // If there is additional smearing information, include it. |
| 4899 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4900 | pw.print(" Including smearing: "); |
| 4901 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4902 | pw.print(" ("); |
| 4903 | if (bs.screenPowerMah != 0) { |
| 4904 | pw.print(" screen="); |
| 4905 | printmAh(pw, bs.screenPowerMah); |
| 4906 | } |
| 4907 | if (bs.proportionalSmearMah != 0) { |
| 4908 | pw.print(" proportional="); |
| 4909 | printmAh(pw, bs.proportionalSmearMah); |
| 4910 | } |
| 4911 | pw.print(" )"); |
| 4912 | } |
| 4913 | if (bs.shouldHide) { |
| 4914 | pw.print(" Excluded from smearing"); |
| 4915 | } |
| 4916 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4917 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4918 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4919 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4920 | } |
| 4921 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4922 | sippers = helper.getMobilemsppList(); |
| 4923 | if (sippers != null && sippers.size() > 0) { |
| 4924 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4925 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4926 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4927 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4928 | sb.setLength(0); |
| 4929 | sb.append(prefix); sb.append(" Uid "); |
| 4930 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4931 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4932 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4933 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4934 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4935 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4936 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4937 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4938 | sb.setLength(0); |
| 4939 | sb.append(prefix); |
| 4940 | sb.append(" TOTAL TIME: "); |
| 4941 | formatTimeMs(sb, totalTime); |
| 4942 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4943 | sb.append(")"); |
| 4944 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4945 | pw.println(); |
| 4946 | } |
| 4947 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4948 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4949 | @Override |
| 4950 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4951 | long lhsTime = lhs.mTime; |
| 4952 | long rhsTime = rhs.mTime; |
| 4953 | if (lhsTime < rhsTime) { |
| 4954 | return 1; |
| 4955 | } |
| 4956 | if (lhsTime > rhsTime) { |
| 4957 | return -1; |
| 4958 | } |
| 4959 | return 0; |
| 4960 | } |
| 4961 | }; |
| 4962 | |
| 4963 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4964 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4965 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4966 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4967 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4968 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4969 | : kernelWakelocks.entrySet()) { |
| 4970 | final BatteryStats.Timer timer = ent.getValue(); |
| 4971 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4972 | if (totalTimeMillis > 0) { |
| 4973 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4974 | } |
| 4975 | } |
| 4976 | if (ktimers.size() > 0) { |
| 4977 | Collections.sort(ktimers, timerComparator); |
| 4978 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4979 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4980 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4981 | String linePrefix = ": "; |
| 4982 | sb.setLength(0); |
| 4983 | sb.append(prefix); |
| 4984 | sb.append(" Kernel Wake lock "); |
| 4985 | sb.append(timer.mName); |
| 4986 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4987 | which, linePrefix); |
| 4988 | if (!linePrefix.equals(": ")) { |
| 4989 | sb.append(" realtime"); |
| 4990 | // Only print out wake locks that were held |
| 4991 | pw.println(sb.toString()); |
| 4992 | } |
| 4993 | } |
| 4994 | pw.println(); |
| 4995 | } |
| 4996 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4997 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4998 | if (timers.size() > 0) { |
| 4999 | Collections.sort(timers, timerComparator); |
| 5000 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5001 | for (int i=0; i<timers.size(); i++) { |
| 5002 | TimerEntry timer = timers.get(i); |
| 5003 | sb.setLength(0); |
| 5004 | sb.append(" Wake lock "); |
| 5005 | UserHandle.formatUid(sb, timer.mId); |
| 5006 | sb.append(" "); |
| 5007 | sb.append(timer.mName); |
| 5008 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5009 | sb.append(" realtime"); |
| 5010 | pw.println(sb.toString()); |
| 5011 | } |
| 5012 | timers.clear(); |
| 5013 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5014 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5015 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5016 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5017 | if (wakeupReasons.size() > 0) { |
| 5018 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5019 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5020 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5021 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5022 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5023 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5024 | } |
| 5025 | Collections.sort(reasons, timerComparator); |
| 5026 | for (int i=0; i<reasons.size(); i++) { |
| 5027 | TimerEntry timer = reasons.get(i); |
| 5028 | String linePrefix = ": "; |
| 5029 | sb.setLength(0); |
| 5030 | sb.append(prefix); |
| 5031 | sb.append(" Wakeup reason "); |
| 5032 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5033 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5034 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5035 | pw.println(sb.toString()); |
| 5036 | } |
| 5037 | pw.println(); |
| 5038 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5039 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5040 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5041 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5042 | if (mMemoryStats.size() > 0) { |
| 5043 | pw.println(" Memory Stats"); |
| 5044 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5045 | sb.setLength(0); |
| 5046 | sb.append(" Bandwidth "); |
| 5047 | sb.append(mMemoryStats.keyAt(i)); |
| 5048 | sb.append(" Time "); |
| 5049 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5050 | pw.println(sb.toString()); |
| 5051 | } |
| 5052 | pw.println(); |
| 5053 | } |
| 5054 | |
| 5055 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5056 | if (rpmStats.size() > 0) { |
| 5057 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5058 | if (rpmStats.size() > 0) { |
| 5059 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5060 | final String timerName = ent.getKey(); |
| 5061 | final Timer timer = ent.getValue(); |
| 5062 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5063 | } |
| 5064 | } |
| 5065 | pw.println(); |
| 5066 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5067 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5068 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5069 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5070 | pw.print(prefix); |
| 5071 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5072 | if (screenOffRpmStats.size() > 0) { |
| 5073 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5074 | final String timerName = ent.getKey(); |
| 5075 | final Timer timer = ent.getValue(); |
| 5076 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5077 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5078 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5079 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5080 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5083 | final long[] cpuFreqs = getCpuFreqs(); |
| 5084 | if (cpuFreqs != null) { |
| 5085 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5086 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5087 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5088 | sb.append(" " + cpuFreqs[i]); |
| 5089 | } |
| 5090 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5091 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | for (int iu=0; iu<NU; iu++) { |
| 5095 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5096 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5097 | continue; |
| 5098 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5099 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5100 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5101 | |
| 5102 | pw.print(prefix); |
| 5103 | pw.print(" "); |
| 5104 | UserHandle.formatUid(pw, uid); |
| 5105 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5106 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5107 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5108 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5109 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5110 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5111 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5112 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5113 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5114 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5115 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5116 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5117 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5118 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5119 | |
| 5120 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5121 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5122 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5123 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5124 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5125 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5126 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5127 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5128 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5129 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5130 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5131 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5132 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5133 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5134 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5135 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5136 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5137 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5138 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5139 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5140 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5141 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5142 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5143 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5144 | sb.setLength(0); |
| 5145 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5146 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5147 | sb.append("("); |
| 5148 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5149 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5150 | long packets = mobileRxPackets + mobileTxPackets; |
| 5151 | if (packets == 0) { |
| 5152 | packets = 1; |
| 5153 | } |
| 5154 | sb.append(" @ "); |
| 5155 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5156 | sb.append(" mspp"); |
| 5157 | pw.println(sb.toString()); |
| 5158 | } |
| 5159 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5160 | if (mobileWakeup > 0) { |
| 5161 | sb.setLength(0); |
| 5162 | sb.append(prefix); |
| 5163 | sb.append(" Mobile radio AP wakeups: "); |
| 5164 | sb.append(mobileWakeup); |
| 5165 | pw.println(sb.toString()); |
| 5166 | } |
| 5167 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5168 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 5169 | u.getModemControllerActivity(), which); |
| 5170 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5171 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5172 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5173 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5174 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5175 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5176 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5179 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5180 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5181 | || uidWifiRunningTime != 0) { |
| 5182 | sb.setLength(0); |
| 5183 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5184 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5185 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5186 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5187 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5188 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5189 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5190 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5191 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5192 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5193 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5194 | whichBatteryRealtime)); sb.append(") "); |
| 5195 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5196 | sb.append("x\n"); |
| 5197 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5198 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5199 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5200 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5201 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5202 | sb.append(") "); |
| 5203 | sb.append(wifiScanCount); |
| 5204 | sb.append("x\n"); |
| 5205 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5206 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5207 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5208 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5209 | sb.append(") "); |
| 5210 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5211 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5212 | pw.println(sb.toString()); |
| 5213 | } |
| 5214 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5215 | if (wifiWakeup > 0) { |
| 5216 | sb.setLength(0); |
| 5217 | sb.append(prefix); |
| 5218 | sb.append(" WiFi AP wakeups: "); |
| 5219 | sb.append(wifiWakeup); |
| 5220 | pw.println(sb.toString()); |
| 5221 | } |
| 5222 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5223 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 5224 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5225 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5226 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5227 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5228 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5229 | pw.print(formatBytesLocked(btTxBytes)); |
| 5230 | pw.println(" sent"); |
| 5231 | } |
| 5232 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5233 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5234 | if (bleTimer != null) { |
| 5235 | // Convert from microseconds to milliseconds with rounding |
| 5236 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5237 | / 1000; |
| 5238 | if (totalTimeMs != 0) { |
| 5239 | final int count = bleTimer.getCountLocked(which); |
| 5240 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5241 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5242 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5243 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5244 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5245 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5246 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5247 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5248 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5249 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5250 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5251 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5252 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5253 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5254 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5255 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5256 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5257 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5258 | final Timer unoptimizedScanTimerBg = |
| 5259 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5260 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5261 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5262 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5263 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5264 | |
| 5265 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5266 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5267 | sb.append(prefix); |
| 5268 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5269 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5270 | sb.append(" ("); |
| 5271 | sb.append(count); |
| 5272 | sb.append(" times)"); |
| 5273 | if (bleTimer.isRunningLocked()) { |
| 5274 | sb.append(" (currently running)"); |
| 5275 | } |
| 5276 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5277 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5278 | |
| 5279 | sb.append(prefix); |
| 5280 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5281 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5282 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5283 | sb.append(count); |
| 5284 | sb.append(" times)"); |
| 5285 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5286 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5287 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5288 | sb.append("\n"); |
| 5289 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5290 | sb.append(prefix); |
| 5291 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5292 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5293 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5294 | sb.append(countBg); |
| 5295 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5296 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5297 | sb.append(" (currently running in background)"); |
| 5298 | } |
| 5299 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5300 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5301 | |
| 5302 | sb.append(prefix); |
| 5303 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5304 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5305 | sb.append(" ("); |
| 5306 | sb.append(resultCountBg); |
| 5307 | sb.append(" in background)"); |
| 5308 | |
| 5309 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5310 | sb.append("\n"); |
| 5311 | sb.append(prefix); |
| 5312 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5313 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5314 | sb.append(" (max "); |
| 5315 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5316 | sb.append(")"); |
| 5317 | if (unoptimizedScanTimer != null |
| 5318 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5319 | sb.append(" (currently running unoptimized)"); |
| 5320 | } |
| 5321 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5322 | sb.append("\n"); |
| 5323 | sb.append(prefix); |
| 5324 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5325 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5326 | sb.append(" (max "); |
| 5327 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5328 | sb.append(")"); |
| 5329 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5330 | sb.append(" (currently running unoptimized in background)"); |
| 5331 | } |
| 5332 | } |
| 5333 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5334 | pw.println(sb.toString()); |
| 5335 | uidActivity = true; |
| 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5340 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5341 | if (u.hasUserActivity()) { |
| 5342 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5343 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5344 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5345 | if (val != 0) { |
| 5346 | if (!hasData) { |
| 5347 | sb.setLength(0); |
| 5348 | sb.append(" User activity: "); |
| 5349 | hasData = true; |
| 5350 | } else { |
| 5351 | sb.append(", "); |
| 5352 | } |
| 5353 | sb.append(val); |
| 5354 | sb.append(" "); |
| 5355 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5356 | } |
| 5357 | } |
| 5358 | if (hasData) { |
| 5359 | pw.println(sb.toString()); |
| 5360 | } |
| 5361 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5363 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5364 | = u.getWakelockStats(); |
| 5365 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5366 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5367 | int countWakelock = 0; |
| 5368 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5369 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5370 | String linePrefix = ": "; |
| 5371 | sb.setLength(0); |
| 5372 | sb.append(prefix); |
| 5373 | sb.append(" Wake lock "); |
| 5374 | sb.append(wakelocks.keyAt(iw)); |
| 5375 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5376 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5377 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5378 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5379 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5380 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5381 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5382 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5383 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5384 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5385 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5386 | sb.append(" realtime"); |
| 5387 | pw.println(sb.toString()); |
| 5388 | uidActivity = true; |
| 5389 | countWakelock++; |
| 5390 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5391 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5392 | rawRealtime, which); |
| 5393 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5394 | rawRealtime, which); |
| 5395 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5396 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5397 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5398 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5399 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5400 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5401 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5402 | // pooled and therefore just a lower bound) |
| 5403 | long actualTotalPartialWakelock = 0; |
| 5404 | long actualBgPartialWakelock = 0; |
| 5405 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5406 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5407 | // Convert from microseconds to milliseconds with rounding |
| 5408 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5409 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5410 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5411 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5412 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5416 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5417 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5418 | sb.setLength(0); |
| 5419 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5420 | sb.append(" TOTAL wake: "); |
| 5421 | boolean needComma = false; |
| 5422 | if (totalFullWakelock != 0) { |
| 5423 | needComma = true; |
| 5424 | formatTimeMs(sb, totalFullWakelock); |
| 5425 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5426 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5427 | if (totalPartialWakelock != 0) { |
| 5428 | if (needComma) { |
| 5429 | sb.append(", "); |
| 5430 | } |
| 5431 | needComma = true; |
| 5432 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5433 | sb.append("blamed partial"); |
| 5434 | } |
| 5435 | if (actualTotalPartialWakelock != 0) { |
| 5436 | if (needComma) { |
| 5437 | sb.append(", "); |
| 5438 | } |
| 5439 | needComma = true; |
| 5440 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5441 | sb.append("actual partial"); |
| 5442 | } |
| 5443 | if (actualBgPartialWakelock != 0) { |
| 5444 | if (needComma) { |
| 5445 | sb.append(", "); |
| 5446 | } |
| 5447 | needComma = true; |
| 5448 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5449 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5450 | } |
| 5451 | if (totalWindowWakelock != 0) { |
| 5452 | if (needComma) { |
| 5453 | sb.append(", "); |
| 5454 | } |
| 5455 | needComma = true; |
| 5456 | formatTimeMs(sb, totalWindowWakelock); |
| 5457 | sb.append("window"); |
| 5458 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5459 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5460 | if (needComma) { |
| 5461 | sb.append(","); |
| 5462 | } |
| 5463 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5464 | formatTimeMs(sb, totalDrawWakelock); |
| 5465 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5466 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5467 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5468 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5472 | // Calculate multicast wakelock stats |
| 5473 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5474 | if (mcTimer != null) { |
| 5475 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5476 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5477 | |
| 5478 | if (multicastWakeLockTimeMicros > 0) { |
| 5479 | sb.setLength(0); |
| 5480 | sb.append(prefix); |
| 5481 | sb.append(" WiFi Multicast Wakelock"); |
| 5482 | sb.append(" count = "); |
| 5483 | sb.append(multicastWakeLockCount); |
| 5484 | sb.append(" time = "); |
| 5485 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5486 | pw.println(sb.toString()); |
| 5487 | } |
| 5488 | } |
| 5489 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5490 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5491 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5492 | final Timer timer = syncs.valueAt(isy); |
| 5493 | // Convert from microseconds to milliseconds with rounding |
| 5494 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5495 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5496 | final Timer bgTimer = timer.getSubTimer(); |
| 5497 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5498 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5499 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5500 | sb.setLength(0); |
| 5501 | sb.append(prefix); |
| 5502 | sb.append(" Sync "); |
| 5503 | sb.append(syncs.keyAt(isy)); |
| 5504 | sb.append(": "); |
| 5505 | if (totalTime != 0) { |
| 5506 | formatTimeMs(sb, totalTime); |
| 5507 | sb.append("realtime ("); |
| 5508 | sb.append(count); |
| 5509 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5510 | if (bgTime > 0) { |
| 5511 | sb.append(", "); |
| 5512 | formatTimeMs(sb, bgTime); |
| 5513 | sb.append("background ("); |
| 5514 | sb.append(bgCount); |
| 5515 | sb.append(" times)"); |
| 5516 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5517 | } else { |
| 5518 | sb.append("(not used)"); |
| 5519 | } |
| 5520 | pw.println(sb.toString()); |
| 5521 | uidActivity = true; |
| 5522 | } |
| 5523 | |
| 5524 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5525 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5526 | final Timer timer = jobs.valueAt(ij); |
| 5527 | // Convert from microseconds to milliseconds with rounding |
| 5528 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5529 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5530 | final Timer bgTimer = timer.getSubTimer(); |
| 5531 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5532 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5533 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5534 | sb.setLength(0); |
| 5535 | sb.append(prefix); |
| 5536 | sb.append(" Job "); |
| 5537 | sb.append(jobs.keyAt(ij)); |
| 5538 | sb.append(": "); |
| 5539 | if (totalTime != 0) { |
| 5540 | formatTimeMs(sb, totalTime); |
| 5541 | sb.append("realtime ("); |
| 5542 | sb.append(count); |
| 5543 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5544 | if (bgTime > 0) { |
| 5545 | sb.append(", "); |
| 5546 | formatTimeMs(sb, bgTime); |
| 5547 | sb.append("background ("); |
| 5548 | sb.append(bgCount); |
| 5549 | sb.append(" times)"); |
| 5550 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5551 | } else { |
| 5552 | sb.append("(not used)"); |
| 5553 | } |
| 5554 | pw.println(sb.toString()); |
| 5555 | uidActivity = true; |
| 5556 | } |
| 5557 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5558 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5559 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5560 | SparseIntArray types = completions.valueAt(ic); |
| 5561 | if (types != null) { |
| 5562 | pw.print(prefix); |
| 5563 | pw.print(" Job Completions "); |
| 5564 | pw.print(completions.keyAt(ic)); |
| 5565 | pw.print(":"); |
| 5566 | for (int it=0; it<types.size(); it++) { |
| 5567 | pw.print(" "); |
| 5568 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5569 | pw.print("("); |
| 5570 | pw.print(types.valueAt(it)); |
| 5571 | pw.print("x)"); |
| 5572 | } |
| 5573 | pw.println(); |
| 5574 | } |
| 5575 | } |
| 5576 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5577 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5578 | prefix, "Flashlight"); |
| 5579 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5580 | prefix, "Camera"); |
| 5581 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5582 | prefix, "Video"); |
| 5583 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5584 | prefix, "Audio"); |
| 5585 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5586 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5587 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5588 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5589 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5590 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5591 | sb.setLength(0); |
| 5592 | sb.append(prefix); |
| 5593 | sb.append(" Sensor "); |
| 5594 | int handle = se.getHandle(); |
| 5595 | if (handle == Uid.Sensor.GPS) { |
| 5596 | sb.append("GPS"); |
| 5597 | } else { |
| 5598 | sb.append(handle); |
| 5599 | } |
| 5600 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5602 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5603 | if (timer != null) { |
| 5604 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5605 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5606 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5607 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5608 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5609 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5610 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5611 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5612 | final long bgActualTime = bgTimer != null ? |
| 5613 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5614 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5615 | //timer.logState(); |
| 5616 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5617 | if (actualTime != totalTime) { |
| 5618 | formatTimeMs(sb, totalTime); |
| 5619 | sb.append("blamed realtime, "); |
| 5620 | } |
| 5621 | |
| 5622 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5623 | sb.append("realtime ("); |
| 5624 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5625 | sb.append(" times)"); |
| 5626 | |
| 5627 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5628 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5629 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5630 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5631 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5632 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | } else { |
| 5635 | sb.append("(not used)"); |
| 5636 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5637 | } else { |
| 5638 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5640 | |
| 5641 | pw.println(sb.toString()); |
| 5642 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5643 | } |
| 5644 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5645 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5646 | "Vibrator"); |
| 5647 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5648 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5649 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5650 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5651 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5652 | long totalStateTime = 0; |
| 5653 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5654 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5655 | if (time > 0) { |
| 5656 | totalStateTime += time; |
| 5657 | sb.setLength(0); |
| 5658 | sb.append(prefix); |
| 5659 | sb.append(" "); |
| 5660 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5661 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5662 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5663 | pw.println(sb.toString()); |
| 5664 | uidActivity = true; |
| 5665 | } |
| 5666 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5667 | if (totalStateTime > 0) { |
| 5668 | sb.setLength(0); |
| 5669 | sb.append(prefix); |
| 5670 | sb.append(" Total running: "); |
| 5671 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5672 | pw.println(sb.toString()); |
| 5673 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5674 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5675 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5676 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5677 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5678 | sb.setLength(0); |
| 5679 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5680 | sb.append(" Total cpu time: u="); |
| 5681 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5682 | sb.append("s="); |
| 5683 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5684 | pw.println(sb.toString()); |
| 5685 | } |
| 5686 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5687 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5688 | if (cpuFreqTimes != null) { |
| 5689 | sb.setLength(0); |
| 5690 | sb.append(" Total cpu time per freq:"); |
| 5691 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5692 | sb.append(" " + cpuFreqTimes[i]); |
| 5693 | } |
| 5694 | pw.println(sb.toString()); |
| 5695 | } |
| 5696 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5697 | if (screenOffCpuFreqTimes != null) { |
| 5698 | sb.setLength(0); |
| 5699 | sb.append(" Total screen-off cpu time per freq:"); |
| 5700 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5701 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5702 | } |
| 5703 | pw.println(sb.toString()); |
| 5704 | } |
| 5705 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5706 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5707 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5708 | if (cpuTimes != null) { |
| 5709 | sb.setLength(0); |
| 5710 | sb.append(" Cpu times per freq at state " |
| 5711 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5712 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5713 | sb.append(" " + cpuTimes[i]); |
| 5714 | } |
| 5715 | pw.println(sb.toString()); |
| 5716 | } |
| 5717 | |
| 5718 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5719 | if (screenOffCpuTimes != null) { |
| 5720 | sb.setLength(0); |
| 5721 | sb.append(" Screen-off cpu times per freq at state " |
| 5722 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5723 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5724 | sb.append(" " + screenOffCpuTimes[i]); |
| 5725 | } |
| 5726 | pw.println(sb.toString()); |
| 5727 | } |
| 5728 | } |
| 5729 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5730 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5731 | = u.getProcessStats(); |
| 5732 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5733 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5734 | long userTime; |
| 5735 | long systemTime; |
| 5736 | long foregroundTime; |
| 5737 | int starts; |
| 5738 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5740 | userTime = ps.getUserTime(which); |
| 5741 | systemTime = ps.getSystemTime(which); |
| 5742 | foregroundTime = ps.getForegroundTime(which); |
| 5743 | starts = ps.getStarts(which); |
| 5744 | final int numCrashes = ps.getNumCrashes(which); |
| 5745 | final int numAnrs = ps.getNumAnrs(which); |
| 5746 | numExcessive = which == STATS_SINCE_CHARGED |
| 5747 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5749 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5750 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5751 | sb.setLength(0); |
| 5752 | sb.append(prefix); sb.append(" Proc "); |
| 5753 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5754 | sb.append(prefix); sb.append(" CPU: "); |
| 5755 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5756 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5757 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5758 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5759 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5760 | boolean hasOne = false; |
| 5761 | if (starts != 0) { |
| 5762 | hasOne = true; |
| 5763 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5764 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5765 | if (numCrashes != 0) { |
| 5766 | if (hasOne) { |
| 5767 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5768 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5769 | hasOne = true; |
| 5770 | sb.append(numCrashes); sb.append(" crashes"); |
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 | if (numAnrs != 0) { |
| 5773 | if (hasOne) { |
| 5774 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5775 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5776 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | } |
| 5778 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5779 | pw.println(sb.toString()); |
| 5780 | for (int e=0; e<numExcessive; e++) { |
| 5781 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5782 | if (ew != null) { |
| 5783 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5784 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5785 | pw.print("cpu"); |
| 5786 | } else { |
| 5787 | pw.print("unknown"); |
| 5788 | } |
| 5789 | pw.print(" use: "); |
| 5790 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5791 | pw.print(" over "); |
| 5792 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5793 | if (ew.overTime != 0) { |
| 5794 | pw.print(" ("); |
| 5795 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5796 | pw.println("%)"); |
| 5797 | } |
| 5798 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | } |
| 5800 | uidActivity = true; |
| 5801 | } |
| 5802 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5803 | |
| 5804 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5805 | = u.getPackageStats(); |
| 5806 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5807 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5808 | pw.println(":"); |
| 5809 | boolean apkActivity = false; |
| 5810 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5811 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5812 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5813 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5814 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5815 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5816 | pw.println(" times"); |
| 5817 | apkActivity = true; |
| 5818 | } |
| 5819 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5820 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5821 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5822 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5823 | final int starts = ss.getStarts(which); |
| 5824 | final int launches = ss.getLaunches(which); |
| 5825 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5826 | sb.setLength(0); |
| 5827 | sb.append(prefix); sb.append(" Service "); |
| 5828 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5829 | sb.append(prefix); sb.append(" Created for: "); |
| 5830 | formatTimeMs(sb, startTime / 1000); |
| 5831 | sb.append("uptime\n"); |
| 5832 | sb.append(prefix); sb.append(" Starts: "); |
| 5833 | sb.append(starts); |
| 5834 | sb.append(", launches: "); sb.append(launches); |
| 5835 | pw.println(sb.toString()); |
| 5836 | apkActivity = true; |
| 5837 | } |
| 5838 | } |
| 5839 | if (!apkActivity) { |
| 5840 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5841 | } |
| 5842 | uidActivity = true; |
| 5843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5845 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5846 | } |
| 5847 | } |
| 5848 | } |
| 5849 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5850 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5851 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5852 | int diff = oldval ^ newval; |
| 5853 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5854 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5855 | for (int i=0; i<descriptions.length; i++) { |
| 5856 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5857 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5858 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5859 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5860 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5861 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5862 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5863 | didWake = true; |
| 5864 | pw.print("="); |
| 5865 | if (longNames) { |
| 5866 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5867 | pw.print(":\""); |
| 5868 | pw.print(wakelockTag.string); |
| 5869 | pw.print("\""); |
| 5870 | } else { |
| 5871 | pw.print(wakelockTag.poolIdx); |
| 5872 | } |
| 5873 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5874 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5875 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5876 | pw.print("="); |
| 5877 | int val = (newval&bd.mask)>>bd.shift; |
| 5878 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5879 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5880 | } else { |
| 5881 | pw.print(val); |
| 5882 | } |
| 5883 | } |
| 5884 | } |
| 5885 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5886 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5887 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5888 | if (longNames) { |
| 5889 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5890 | pw.print(":\""); |
| 5891 | pw.print(wakelockTag.string); |
| 5892 | pw.print("\""); |
| 5893 | } else { |
| 5894 | pw.print(wakelockTag.poolIdx); |
| 5895 | } |
| 5896 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5897 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5898 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5899 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 5900 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | public static class HistoryPrinter { |
| 5904 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5905 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5906 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5907 | int oldStatus = -1; |
| 5908 | int oldHealth = -1; |
| 5909 | int oldPlug = -1; |
| 5910 | int oldTemp = -1; |
| 5911 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5912 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5913 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5914 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5915 | void reset() { |
| 5916 | oldState = oldState2 = 0; |
| 5917 | oldLevel = -1; |
| 5918 | oldStatus = -1; |
| 5919 | oldHealth = -1; |
| 5920 | oldPlug = -1; |
| 5921 | oldTemp = -1; |
| 5922 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5923 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5926 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5927 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5928 | if (!checkin) { |
| 5929 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5930 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5931 | pw.print(" ("); |
| 5932 | pw.print(rec.numReadInts); |
| 5933 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5934 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5935 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5936 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5937 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5938 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5939 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5940 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5941 | } |
| 5942 | lastTime = rec.time; |
| 5943 | } |
| 5944 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5945 | if (checkin) { |
| 5946 | pw.print(":"); |
| 5947 | } |
| 5948 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5949 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5950 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5951 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5952 | if (checkin) { |
| 5953 | pw.print(":"); |
| 5954 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5955 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5956 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5957 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5958 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5959 | pw.print("TIME:"); |
| 5960 | if (checkin) { |
| 5961 | pw.println(rec.currentTime); |
| 5962 | } else { |
| 5963 | pw.print(" "); |
| 5964 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5965 | rec.currentTime).toString()); |
| 5966 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5967 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5968 | if (checkin) { |
| 5969 | pw.print(":"); |
| 5970 | } |
| 5971 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5972 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5973 | if (checkin) { |
| 5974 | pw.print(":"); |
| 5975 | } |
| 5976 | pw.println("*OVERFLOW*"); |
| 5977 | } else { |
| 5978 | if (!checkin) { |
| 5979 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5980 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5981 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5982 | if (verbose) { |
| 5983 | pw.print(" "); |
| 5984 | if (rec.states < 0) ; |
| 5985 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5986 | else if (rec.states < 0x100) pw.print("000000"); |
| 5987 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5988 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5989 | else if (rec.states < 0x100000) pw.print("000"); |
| 5990 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5991 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5992 | pw.print(Integer.toHexString(rec.states)); |
| 5993 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5994 | } else { |
| 5995 | if (oldLevel != rec.batteryLevel) { |
| 5996 | oldLevel = rec.batteryLevel; |
| 5997 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5998 | } |
| 5999 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6000 | if (oldStatus != rec.batteryStatus) { |
| 6001 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6002 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6003 | switch (oldStatus) { |
| 6004 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6005 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6006 | break; |
| 6007 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6008 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6009 | break; |
| 6010 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6011 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6012 | break; |
| 6013 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6014 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6015 | break; |
| 6016 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6017 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6018 | break; |
| 6019 | default: |
| 6020 | pw.print(oldStatus); |
| 6021 | break; |
| 6022 | } |
| 6023 | } |
| 6024 | if (oldHealth != rec.batteryHealth) { |
| 6025 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6026 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6027 | switch (oldHealth) { |
| 6028 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6029 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6030 | break; |
| 6031 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6032 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6033 | break; |
| 6034 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6035 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6036 | break; |
| 6037 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6038 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6039 | break; |
| 6040 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6041 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6042 | break; |
| 6043 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6044 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6045 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6046 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 6047 | pw.print(checkin ? "c" : "cold"); |
| 6048 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6049 | default: |
| 6050 | pw.print(oldHealth); |
| 6051 | break; |
| 6052 | } |
| 6053 | } |
| 6054 | if (oldPlug != rec.batteryPlugType) { |
| 6055 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6056 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6057 | switch (oldPlug) { |
| 6058 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6059 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6060 | break; |
| 6061 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6062 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6063 | break; |
| 6064 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6065 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6066 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6067 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6068 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6069 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6070 | default: |
| 6071 | pw.print(oldPlug); |
| 6072 | break; |
| 6073 | } |
| 6074 | } |
| 6075 | if (oldTemp != rec.batteryTemperature) { |
| 6076 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6077 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6078 | pw.print(oldTemp); |
| 6079 | } |
| 6080 | if (oldVolt != rec.batteryVoltage) { |
| 6081 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6082 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6083 | pw.print(oldVolt); |
| 6084 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6085 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6086 | if (oldChargeMAh != chargeMAh) { |
| 6087 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6088 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6089 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6090 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6091 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6092 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6093 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 6094 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6095 | if (rec.wakeReasonTag != null) { |
| 6096 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6097 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6098 | pw.print(rec.wakeReasonTag.poolIdx); |
| 6099 | } else { |
| 6100 | pw.print(" wake_reason="); |
| 6101 | pw.print(rec.wakeReasonTag.uid); |
| 6102 | pw.print(":\""); |
| 6103 | pw.print(rec.wakeReasonTag.string); |
| 6104 | pw.print("\""); |
| 6105 | } |
| 6106 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6107 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6108 | pw.print(checkin ? "," : " "); |
| 6109 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 6110 | pw.print("+"); |
| 6111 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6112 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6113 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6114 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6115 | : HISTORY_EVENT_NAMES; |
| 6116 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6117 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6118 | if (idx >= 0 && idx < eventNames.length) { |
| 6119 | pw.print(eventNames[idx]); |
| 6120 | } else { |
| 6121 | pw.print(checkin ? "Ev" : "event"); |
| 6122 | pw.print(idx); |
| 6123 | } |
| 6124 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6125 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6126 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6127 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6128 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6129 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6130 | pw.print(":\""); |
| 6131 | pw.print(rec.eventTag.string); |
| 6132 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6133 | } |
| 6134 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6135 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6136 | if (rec.stepDetails != null) { |
| 6137 | if (!checkin) { |
| 6138 | pw.print(" Details: cpu="); |
| 6139 | pw.print(rec.stepDetails.userTime); |
| 6140 | pw.print("u+"); |
| 6141 | pw.print(rec.stepDetails.systemTime); |
| 6142 | pw.print("s"); |
| 6143 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6144 | pw.print(" ("); |
| 6145 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6146 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6147 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6148 | pw.print(", "); |
| 6149 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6150 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6151 | } |
| 6152 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6153 | pw.print(", "); |
| 6154 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6155 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6156 | } |
| 6157 | pw.print(')'); |
| 6158 | } |
| 6159 | pw.println(); |
| 6160 | pw.print(" /proc/stat="); |
| 6161 | pw.print(rec.stepDetails.statUserTime); |
| 6162 | pw.print(" usr, "); |
| 6163 | pw.print(rec.stepDetails.statSystemTime); |
| 6164 | pw.print(" sys, "); |
| 6165 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6166 | pw.print(" io, "); |
| 6167 | pw.print(rec.stepDetails.statIrqTime); |
| 6168 | pw.print(" irq, "); |
| 6169 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6170 | pw.print(" sirq, "); |
| 6171 | pw.print(rec.stepDetails.statIdlTime); |
| 6172 | pw.print(" idle"); |
| 6173 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6174 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6175 | + rec.stepDetails.statSoftIrqTime; |
| 6176 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6177 | if (total > 0) { |
| 6178 | pw.print(" ("); |
| 6179 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6180 | pw.print(String.format("%.1f%%", perc)); |
| 6181 | pw.print(" of "); |
| 6182 | StringBuilder sb = new StringBuilder(64); |
| 6183 | formatTimeMsNoSpace(sb, total*10); |
| 6184 | pw.print(sb); |
| 6185 | pw.print(")"); |
| 6186 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6187 | pw.print(", PlatformIdleStat "); |
| 6188 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6189 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6190 | |
| 6191 | pw.print(", SubsystemPowerState "); |
| 6192 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6193 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6194 | } else { |
| 6195 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6196 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6197 | pw.print(rec.stepDetails.userTime); |
| 6198 | pw.print(":"); |
| 6199 | pw.print(rec.stepDetails.systemTime); |
| 6200 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6201 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6202 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6203 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6204 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6205 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6206 | } |
| 6207 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6208 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6209 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6210 | } |
| 6211 | } |
| 6212 | pw.println(); |
| 6213 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6214 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6215 | pw.print(rec.stepDetails.statUserTime); |
| 6216 | pw.print(','); |
| 6217 | pw.print(rec.stepDetails.statSystemTime); |
| 6218 | pw.print(','); |
| 6219 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6220 | pw.print(','); |
| 6221 | pw.print(rec.stepDetails.statIrqTime); |
| 6222 | pw.print(','); |
| 6223 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6224 | pw.print(','); |
| 6225 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6226 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6227 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6228 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6229 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6230 | pw.print(','); |
| 6231 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6232 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6233 | |
| 6234 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6235 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6236 | } |
| 6237 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6238 | } |
| 6239 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6240 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6241 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6242 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6243 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6244 | |
| 6245 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6246 | UserHandle.formatUid(pw, uid); |
| 6247 | pw.print("="); |
| 6248 | pw.print(utime); |
| 6249 | pw.print("u+"); |
| 6250 | pw.print(stime); |
| 6251 | pw.print("s"); |
| 6252 | } |
| 6253 | |
| 6254 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6255 | pw.print('/'); |
| 6256 | pw.print(uid); |
| 6257 | pw.print(":"); |
| 6258 | pw.print(utime); |
| 6259 | pw.print(":"); |
| 6260 | pw.print(stime); |
| 6261 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6262 | } |
| 6263 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6264 | private void printSizeValue(PrintWriter pw, long size) { |
| 6265 | float result = size; |
| 6266 | String suffix = ""; |
| 6267 | if (result >= 10*1024) { |
| 6268 | suffix = "KB"; |
| 6269 | result = result / 1024; |
| 6270 | } |
| 6271 | if (result >= 10*1024) { |
| 6272 | suffix = "MB"; |
| 6273 | result = result / 1024; |
| 6274 | } |
| 6275 | if (result >= 10*1024) { |
| 6276 | suffix = "GB"; |
| 6277 | result = result / 1024; |
| 6278 | } |
| 6279 | if (result >= 10*1024) { |
| 6280 | suffix = "TB"; |
| 6281 | result = result / 1024; |
| 6282 | } |
| 6283 | if (result >= 10*1024) { |
| 6284 | suffix = "PB"; |
| 6285 | result = result / 1024; |
| 6286 | } |
| 6287 | pw.print((int)result); |
| 6288 | pw.print(suffix); |
| 6289 | } |
| 6290 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6291 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6292 | String label3, long estimatedTime) { |
| 6293 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6294 | return false; |
| 6295 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6296 | pw.print(label1); |
| 6297 | pw.print(label2); |
| 6298 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6299 | StringBuilder sb = new StringBuilder(64); |
| 6300 | formatTimeMs(sb, estimatedTime); |
| 6301 | pw.print(sb); |
| 6302 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6303 | return true; |
| 6304 | } |
| 6305 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6306 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6307 | LevelStepTracker steps, boolean checkin) { |
| 6308 | if (steps == null) { |
| 6309 | return false; |
| 6310 | } |
| 6311 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6312 | if (count <= 0) { |
| 6313 | return false; |
| 6314 | } |
| 6315 | if (!checkin) { |
| 6316 | pw.println(header); |
| 6317 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6318 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6319 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6320 | long duration = steps.getDurationAt(i); |
| 6321 | int level = steps.getLevelAt(i); |
| 6322 | long initMode = steps.getInitModeAt(i); |
| 6323 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6324 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6325 | lineArgs[0] = Long.toString(duration); |
| 6326 | lineArgs[1] = Integer.toString(level); |
| 6327 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6328 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6329 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6330 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6331 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6332 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6333 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6334 | } |
| 6335 | } else { |
| 6336 | lineArgs[2] = ""; |
| 6337 | } |
| 6338 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6339 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6340 | } else { |
| 6341 | lineArgs[3] = ""; |
| 6342 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6343 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6344 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6345 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6346 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6347 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6348 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6349 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6350 | pw.print(prefix); |
| 6351 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6352 | TimeUtils.formatDuration(duration, pw); |
| 6353 | pw.print(" to "); pw.print(level); |
| 6354 | boolean haveModes = false; |
| 6355 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6356 | pw.print(" ("); |
| 6357 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6358 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6359 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6360 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6361 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6362 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6363 | } |
| 6364 | haveModes = true; |
| 6365 | } |
| 6366 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6367 | pw.print(haveModes ? ", " : " ("); |
| 6368 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6369 | ? "power-save-on" : "power-save-off"); |
| 6370 | haveModes = true; |
| 6371 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6372 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6373 | pw.print(haveModes ? ", " : " ("); |
| 6374 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6375 | ? "device-idle-on" : "device-idle-off"); |
| 6376 | haveModes = true; |
| 6377 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6378 | if (haveModes) { |
| 6379 | pw.print(")"); |
| 6380 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6381 | pw.println(); |
| 6382 | } |
| 6383 | } |
| 6384 | return true; |
| 6385 | } |
| 6386 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6387 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6388 | LevelStepTracker steps) { |
| 6389 | if (steps == null) { |
| 6390 | return; |
| 6391 | } |
| 6392 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6393 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6394 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6395 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6396 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6397 | |
| 6398 | final long initMode = steps.getInitModeAt(i); |
| 6399 | final long modMode = steps.getModModeAt(i); |
| 6400 | |
| 6401 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6402 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6403 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6404 | case Display.STATE_OFF: |
| 6405 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6406 | break; |
| 6407 | case Display.STATE_ON: |
| 6408 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6409 | break; |
| 6410 | case Display.STATE_DOZE: |
| 6411 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6412 | break; |
| 6413 | case Display.STATE_DOZE_SUSPEND: |
| 6414 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6415 | break; |
| 6416 | default: |
| 6417 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6418 | break; |
| 6419 | } |
| 6420 | } |
| 6421 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6422 | |
| 6423 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6424 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6425 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6426 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6427 | } |
| 6428 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6429 | |
| 6430 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6431 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6432 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6433 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6434 | } |
| 6435 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6436 | |
| 6437 | proto.end(token); |
| 6438 | } |
| 6439 | } |
| 6440 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6441 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6442 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6443 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6444 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6445 | public static final int DUMP_VERBOSE = 1<<5; |
| 6446 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6447 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6448 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6449 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6450 | final HistoryItem rec = new HistoryItem(); |
| 6451 | long lastTime = -1; |
| 6452 | long baseTime = -1; |
| 6453 | boolean printed = false; |
| 6454 | HistoryEventTracker tracker = null; |
| 6455 | while (getNextHistoryLocked(rec)) { |
| 6456 | lastTime = rec.time; |
| 6457 | if (baseTime < 0) { |
| 6458 | baseTime = lastTime; |
| 6459 | } |
| 6460 | if (rec.time >= histStart) { |
| 6461 | if (histStart >= 0 && !printed) { |
| 6462 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6463 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6464 | || rec.cmd == HistoryItem.CMD_START |
| 6465 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6466 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6467 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6468 | (flags&DUMP_VERBOSE) != 0); |
| 6469 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6470 | } else if (rec.currentTime != 0) { |
| 6471 | printed = true; |
| 6472 | byte cmd = rec.cmd; |
| 6473 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6474 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6475 | (flags&DUMP_VERBOSE) != 0); |
| 6476 | rec.cmd = cmd; |
| 6477 | } |
| 6478 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6479 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6480 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6481 | (flags&DUMP_VERBOSE) != 0); |
| 6482 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6483 | } |
| 6484 | int oldEventCode = rec.eventCode; |
| 6485 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6486 | rec.eventTag = new HistoryTag(); |
| 6487 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6488 | HashMap<String, SparseIntArray> active |
| 6489 | = tracker.getStateForEvent(i); |
| 6490 | if (active == null) { |
| 6491 | continue; |
| 6492 | } |
| 6493 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6494 | : active.entrySet()) { |
| 6495 | SparseIntArray uids = ent.getValue(); |
| 6496 | for (int j=0; j<uids.size(); j++) { |
| 6497 | rec.eventCode = i; |
| 6498 | rec.eventTag.string = ent.getKey(); |
| 6499 | rec.eventTag.uid = uids.keyAt(j); |
| 6500 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6501 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6502 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6503 | rec.wakeReasonTag = null; |
| 6504 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6505 | } |
| 6506 | } |
| 6507 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6508 | rec.eventCode = oldEventCode; |
| 6509 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6510 | tracker = null; |
| 6511 | } |
| 6512 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6513 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6514 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6515 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6516 | // This is an attempt to aggregate the previous state and generate |
| 6517 | //Â fake events to reflect that state at the point where we start |
| 6518 | // 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] | 6519 | if (tracker == null) { |
| 6520 | tracker = new HistoryEventTracker(); |
| 6521 | } |
| 6522 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6523 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6524 | } |
| 6525 | } |
| 6526 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6527 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6528 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6529 | } |
| 6530 | } |
| 6531 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6532 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6533 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6534 | if (steps == null) { |
| 6535 | return; |
| 6536 | } |
| 6537 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6538 | if (timeRemaining >= 0) { |
| 6539 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6540 | tmpSb.setLength(0); |
| 6541 | formatTimeMs(tmpSb, timeRemaining); |
| 6542 | pw.print(tmpSb); |
| 6543 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6544 | pw.println(" steps)"); |
| 6545 | } |
| 6546 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6547 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6548 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6549 | if (estimatedTime > 0) { |
| 6550 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6551 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6552 | pw.print(" time: "); |
| 6553 | tmpSb.setLength(0); |
| 6554 | formatTimeMs(tmpSb, estimatedTime); |
| 6555 | pw.print(tmpSb); |
| 6556 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6557 | pw.println(" steps)"); |
| 6558 | } |
| 6559 | } |
| 6560 | } |
| 6561 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6562 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6563 | ArrayList<PackageChange> changes) { |
| 6564 | if (changes == null) { |
| 6565 | return; |
| 6566 | } |
| 6567 | pw.print(prefix); pw.println("Package changes:"); |
| 6568 | for (int i=0; i<changes.size(); i++) { |
| 6569 | PackageChange pc = changes.get(i); |
| 6570 | if (pc.mUpdate) { |
| 6571 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6572 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6573 | } else { |
| 6574 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6575 | } |
| 6576 | } |
| 6577 | } |
| 6578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | /** |
| 6580 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6581 | * |
| 6582 | * @param pw a Printer to receive the dump output. |
| 6583 | */ |
| 6584 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6585 | 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] | 6586 | prepareForDumpLocked(); |
| 6587 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6588 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6589 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6590 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6591 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6592 | final long historyTotalSize = getHistoryTotalSize(); |
| 6593 | final long historyUsedSize = getHistoryUsedSize(); |
| 6594 | if (startIteratingHistoryLocked()) { |
| 6595 | try { |
| 6596 | pw.print("Battery History ("); |
| 6597 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6598 | pw.print("% used, "); |
| 6599 | printSizeValue(pw, historyUsedSize); |
| 6600 | pw.print(" used of "); |
| 6601 | printSizeValue(pw, historyTotalSize); |
| 6602 | pw.print(", "); |
| 6603 | pw.print(getHistoryStringPoolSize()); |
| 6604 | pw.print(" strings using "); |
| 6605 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6606 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6607 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6608 | pw.println(); |
| 6609 | } finally { |
| 6610 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6611 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | if (startIteratingOldHistoryLocked()) { |
| 6615 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6616 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6617 | pw.println("Old battery History:"); |
| 6618 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6619 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6620 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6621 | if (baseTime < 0) { |
| 6622 | baseTime = rec.time; |
| 6623 | } |
| 6624 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6625 | } |
| 6626 | pw.println(); |
| 6627 | } finally { |
| 6628 | finishIteratingOldHistoryLocked(); |
| 6629 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6630 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6633 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6634 | return; |
| 6635 | } |
| 6636 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6637 | if (!filtering) { |
| 6638 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6639 | final int NU = uidStats.size(); |
| 6640 | boolean didPid = false; |
| 6641 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6642 | for (int i=0; i<NU; i++) { |
| 6643 | Uid uid = uidStats.valueAt(i); |
| 6644 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6645 | if (pids != null) { |
| 6646 | for (int j=0; j<pids.size(); j++) { |
| 6647 | Uid.Pid pid = pids.valueAt(j); |
| 6648 | if (!didPid) { |
| 6649 | pw.println("Per-PID Stats:"); |
| 6650 | didPid = true; |
| 6651 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6652 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6653 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6654 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6655 | pw.print(" wake time: "); |
| 6656 | TimeUtils.formatDuration(time, pw); |
| 6657 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6658 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6659 | } |
| 6660 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6661 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6662 | pw.println(); |
| 6663 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6667 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6668 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6669 | long timeRemaining = computeBatteryTimeRemaining( |
| 6670 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6671 | if (timeRemaining >= 0) { |
| 6672 | pw.print(" Estimated discharge time remaining: "); |
| 6673 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6674 | pw.println(); |
| 6675 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6676 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6677 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6678 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6679 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6680 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6681 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6682 | pw.println(); |
| 6683 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6684 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6685 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6686 | long timeRemaining = computeChargeTimeRemaining( |
| 6687 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6688 | if (timeRemaining >= 0) { |
| 6689 | pw.print(" Estimated charge time remaining: "); |
| 6690 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6691 | pw.println(); |
| 6692 | } |
| 6693 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6694 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6695 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6696 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6697 | pw.println("Daily stats:"); |
| 6698 | pw.print(" Current start time: "); |
| 6699 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6700 | getCurrentDailyStartTime()).toString()); |
| 6701 | pw.print(" Next min deadline: "); |
| 6702 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6703 | getNextMinDailyDeadline()).toString()); |
| 6704 | pw.print(" Next max deadline: "); |
| 6705 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6706 | getNextMaxDailyDeadline()).toString()); |
| 6707 | StringBuilder sb = new StringBuilder(64); |
| 6708 | int[] outInt = new int[1]; |
| 6709 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6710 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6711 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6712 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6713 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6714 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6715 | dsteps, false)) { |
| 6716 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6717 | sb, outInt); |
| 6718 | } |
| 6719 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6720 | csteps, false)) { |
| 6721 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6722 | sb, outInt); |
| 6723 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6724 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6725 | } else { |
| 6726 | pw.println(" Current daily steps:"); |
| 6727 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6728 | sb, outInt); |
| 6729 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6730 | sb, outInt); |
| 6731 | } |
| 6732 | } |
| 6733 | DailyItem dit; |
| 6734 | int curIndex = 0; |
| 6735 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6736 | curIndex++; |
| 6737 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6738 | pw.println(); |
| 6739 | } |
| 6740 | pw.print(" Daily from "); |
| 6741 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6742 | pw.print(" to "); |
| 6743 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6744 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6745 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6746 | if (dumpDurationSteps(pw, " ", |
| 6747 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6748 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6749 | sb, outInt); |
| 6750 | } |
| 6751 | if (dumpDurationSteps(pw, " ", |
| 6752 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6753 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6754 | sb, outInt); |
| 6755 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6756 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6757 | } else { |
| 6758 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6759 | sb, outInt); |
| 6760 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6761 | sb, outInt); |
| 6762 | } |
| 6763 | } |
| 6764 | pw.println(); |
| 6765 | } |
| 6766 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6767 | pw.println("Statistics since last charge:"); |
| 6768 | pw.println(" System starts: " + getStartCount() |
| 6769 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6770 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6771 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6772 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6774 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6775 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6776 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6778 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6779 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6780 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6781 | |
| 6782 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6783 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6784 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6785 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6786 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6787 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6788 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6789 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6790 | try { |
| 6791 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6792 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6793 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6794 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6795 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6796 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6797 | pw.print(",\""); |
| 6798 | String str = getHistoryTagPoolString(i); |
| 6799 | str = str.replace("\\", "\\\\"); |
| 6800 | str = str.replace("\"", "\\\""); |
| 6801 | pw.print(str); |
| 6802 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6803 | pw.println(); |
| 6804 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6805 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6806 | } finally { |
| 6807 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6808 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6809 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6810 | } |
| 6811 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6812 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6813 | return; |
| 6814 | } |
| 6815 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6816 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6817 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6818 | for (int i=0; i<apps.size(); i++) { |
| 6819 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6820 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6821 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6822 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6823 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6824 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6825 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6826 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6827 | } |
| 6828 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6829 | final int NU = uidStats.size(); |
| 6830 | String[] lineArgs = new String[2]; |
| 6831 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6832 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6833 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6834 | if (pkgs != null && !pkgs.second.value) { |
| 6835 | pkgs.second.value = true; |
| 6836 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6837 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6838 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6839 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6840 | (Object[])lineArgs); |
| 6841 | } |
| 6842 | } |
| 6843 | } |
| 6844 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6845 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6846 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6847 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6848 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6849 | if (timeRemaining >= 0) { |
| 6850 | lineArgs[0] = Long.toString(timeRemaining); |
| 6851 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6852 | (Object[])lineArgs); |
| 6853 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6854 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6855 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6856 | if (timeRemaining >= 0) { |
| 6857 | lineArgs[0] = Long.toString(timeRemaining); |
| 6858 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6859 | (Object[])lineArgs); |
| 6860 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6861 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6862 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6864 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6865 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6866 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6867 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6868 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6869 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6870 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6871 | prepareForDumpLocked(); |
| 6872 | |
| 6873 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6874 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6875 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6876 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6877 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6878 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6879 | |
| 6880 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6881 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 6882 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 6883 | helper.create(this); |
| 6884 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 6885 | |
| 6886 | dumpProtoAppsLocked(proto, helper, apps); |
| 6887 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | proto.end(bToken); |
| 6891 | proto.flush(); |
| 6892 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6893 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6894 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 6895 | List<ApplicationInfo> apps) { |
| 6896 | final int which = STATS_SINCE_CHARGED; |
| 6897 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 6898 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 6899 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 6900 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 6901 | |
| 6902 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 6903 | if (apps != null) { |
| 6904 | for (int i = 0; i < apps.size(); ++i) { |
| 6905 | ApplicationInfo ai = apps.get(i); |
| 6906 | int aid = UserHandle.getAppId(ai.uid); |
| 6907 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 6908 | if (pkgs == null) { |
| 6909 | pkgs = new ArrayList<String>(); |
| 6910 | aidToPackages.put(aid, pkgs); |
| 6911 | } |
| 6912 | pkgs.add(ai.packageName); |
| 6913 | } |
| 6914 | } |
| 6915 | |
| 6916 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 6917 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 6918 | if (sippers != null) { |
| 6919 | for (int i = 0; i < sippers.size(); ++i) { |
| 6920 | final BatterySipper bs = sippers.get(i); |
| 6921 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 6922 | // Others are handled by dumpProtoSystemLocked() |
| 6923 | continue; |
| 6924 | } |
| 6925 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6930 | final int n = uidStats.size(); |
| 6931 | for (int iu = 0; iu < n; ++iu) { |
| 6932 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 6933 | final Uid u = uidStats.valueAt(iu); |
| 6934 | |
| 6935 | final int uid = uidStats.keyAt(iu); |
| 6936 | proto.write(UidProto.UID, uid); |
| 6937 | |
| 6938 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 6939 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 6940 | if (pkgs == null) { |
| 6941 | pkgs = new ArrayList<String>(); |
| 6942 | } |
| 6943 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 6944 | u.getPackageStats(); |
| 6945 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 6946 | String pkg = packageStats.keyAt(ipkg); |
| 6947 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 6948 | packageStats.valueAt(ipkg).getServiceStats(); |
| 6949 | if (serviceStats.size() == 0) { |
| 6950 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 6951 | // example, "android") may be included in the packageStats that aren't part of |
| 6952 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 6953 | // These packages won't be a part in the pkgs List. |
| 6954 | continue; |
| 6955 | } |
| 6956 | |
| 6957 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6958 | proto.write(UidProto.Package.NAME, pkg); |
| 6959 | // Remove from the packages list since we're logging it here. |
| 6960 | pkgs.remove(pkg); |
| 6961 | |
| 6962 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 6963 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 6964 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 6965 | |
| 6966 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 6967 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 6968 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 6969 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 6970 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 6971 | |
| 6972 | proto.end(sToken); |
| 6973 | } |
| 6974 | proto.end(pToken); |
| 6975 | } |
| 6976 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 6977 | // from PackageManager data. Packages are only included in packageStats if there was |
| 6978 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 6979 | for (String p : pkgs) { |
| 6980 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6981 | proto.write(UidProto.Package.NAME, p); |
| 6982 | proto.end(pToken); |
| 6983 | } |
| 6984 | |
| 6985 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 6986 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 6987 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 6988 | // Times are since reset (regardless of 'which') |
| 6989 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 6990 | final Timer bgTimer = timer.getSubTimer(); |
| 6991 | final long bgTimeMs = bgTimer != null |
| 6992 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 6993 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 6994 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 6995 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 6996 | proto.end(awToken); |
| 6997 | } |
| 6998 | |
| 6999 | // Audio (AUDIO_DATA) |
| 7000 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7001 | |
| 7002 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7003 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7004 | u.getBluetoothControllerActivity(), which); |
| 7005 | |
| 7006 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7007 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7008 | if (bleTimer != null) { |
| 7009 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7010 | |
| 7011 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7012 | rawRealtimeUs, which); |
| 7013 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7014 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7015 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7016 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7017 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7018 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7019 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7020 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7021 | // Result counters |
| 7022 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7023 | u.getBluetoothScanResultCounter() != null |
| 7024 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7025 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7026 | u.getBluetoothScanResultBgCounter() != null |
| 7027 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7028 | |
| 7029 | proto.end(bmToken); |
| 7030 | } |
| 7031 | |
| 7032 | // Camera (CAMERA_DATA) |
| 7033 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7034 | |
| 7035 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7036 | final long cpuToken = proto.start(UidProto.CPU); |
| 7037 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7038 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7039 | |
| 7040 | final long[] cpuFreqs = getCpuFreqs(); |
| 7041 | if (cpuFreqs != null) { |
| 7042 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7043 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7044 | // screenOffCpuFreqTimes. |
| 7045 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7046 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7047 | if (screenOffCpuFreqTimeMs == null) { |
| 7048 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7049 | } |
| 7050 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7051 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7052 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7053 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7054 | cpuFreqTimeMs[ic]); |
| 7055 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7056 | screenOffCpuFreqTimeMs[ic]); |
| 7057 | proto.end(cToken); |
| 7058 | } |
| 7059 | } |
| 7060 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7061 | |
| 7062 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7063 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7064 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7065 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7066 | if (screenOffTimesMs == null) { |
| 7067 | screenOffTimesMs = new long[timesMs.length]; |
| 7068 | } |
| 7069 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7070 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7071 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7072 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7073 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7074 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7075 | timesMs[ic]); |
| 7076 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7077 | screenOffTimesMs[ic]); |
| 7078 | proto.end(cToken); |
| 7079 | } |
| 7080 | proto.end(procToken); |
| 7081 | } |
| 7082 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7083 | proto.end(cpuToken); |
| 7084 | |
| 7085 | // Flashlight (FLASHLIGHT_DATA) |
| 7086 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7087 | rawRealtimeUs, which); |
| 7088 | |
| 7089 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7090 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7091 | rawRealtimeUs, which); |
| 7092 | |
| 7093 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7094 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7095 | rawRealtimeUs, which); |
| 7096 | |
| 7097 | // Job completion (JOB_COMPLETION_DATA) |
| 7098 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7099 | final int[] reasons = new int[]{ |
| 7100 | JobParameters.REASON_CANCELED, |
| 7101 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7102 | JobParameters.REASON_PREEMPT, |
| 7103 | JobParameters.REASON_TIMEOUT, |
| 7104 | JobParameters.REASON_DEVICE_IDLE, |
| 7105 | }; |
| 7106 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7107 | SparseIntArray types = completions.valueAt(ic); |
| 7108 | if (types != null) { |
| 7109 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7110 | |
| 7111 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7112 | |
| 7113 | for (int r : reasons) { |
| 7114 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7115 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7116 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7117 | proto.end(rToken); |
| 7118 | } |
| 7119 | |
| 7120 | proto.end(jcToken); |
| 7121 | } |
| 7122 | } |
| 7123 | |
| 7124 | // Scheduled jobs (JOB_DATA) |
| 7125 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7126 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7127 | final Timer timer = jobs.valueAt(ij); |
| 7128 | final Timer bgTimer = timer.getSubTimer(); |
| 7129 | final long jToken = proto.start(UidProto.JOBS); |
| 7130 | |
| 7131 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7132 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7133 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7134 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7135 | |
| 7136 | proto.end(jToken); |
| 7137 | } |
| 7138 | |
| 7139 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7140 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7141 | u.getModemControllerActivity(), which); |
| 7142 | |
| 7143 | // Network stats (NETWORK_DATA) |
| 7144 | final long nToken = proto.start(UidProto.NETWORK); |
| 7145 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7146 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7147 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7148 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7149 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7150 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7151 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7152 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7153 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7154 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7155 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7156 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7157 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7158 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7159 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7160 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7161 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7162 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7163 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7164 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7165 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7166 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7167 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7168 | u.getMobileRadioActiveCount(which)); |
| 7169 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7170 | u.getMobileRadioApWakeupCount(which)); |
| 7171 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7172 | u.getWifiRadioApWakeupCount(which)); |
| 7173 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7174 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7175 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7176 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7177 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7178 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7179 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7180 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7181 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7182 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7183 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7184 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7185 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7186 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7187 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7188 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7189 | proto.end(nToken); |
| 7190 | |
| 7191 | // Power use item (POWER_USE_ITEM_DATA) |
| 7192 | BatterySipper bs = uidToSipper.get(uid); |
| 7193 | if (bs != null) { |
| 7194 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7195 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7196 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7197 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7198 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7199 | bs.proportionalSmearMah); |
| 7200 | proto.end(bsToken); |
| 7201 | } |
| 7202 | |
| 7203 | // Processes (PROCESS_DATA) |
| 7204 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7205 | u.getProcessStats(); |
| 7206 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7207 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7208 | final long prToken = proto.start(UidProto.PROCESS); |
| 7209 | |
| 7210 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7211 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7212 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7213 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7214 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7215 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7216 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7217 | |
| 7218 | proto.end(prToken); |
| 7219 | } |
| 7220 | |
| 7221 | // Sensors (SENSOR_DATA) |
| 7222 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7223 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7224 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7225 | final Timer timer = se.getSensorTime(); |
| 7226 | if (timer == null) { |
| 7227 | continue; |
| 7228 | } |
| 7229 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7230 | final int sensorNumber = sensors.keyAt(ise); |
| 7231 | final long seToken = proto.start(UidProto.SENSORS); |
| 7232 | |
| 7233 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7234 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7235 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7236 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7237 | |
| 7238 | proto.end(seToken); |
| 7239 | } |
| 7240 | |
| 7241 | // State times (STATE_TIME_DATA) |
| 7242 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7243 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7244 | if (durMs == 0) { |
| 7245 | continue; |
| 7246 | } |
| 7247 | final long stToken = proto.start(UidProto.STATES); |
| 7248 | proto.write(UidProto.StateTime.STATE, ips); |
| 7249 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7250 | proto.end(stToken); |
| 7251 | } |
| 7252 | |
| 7253 | // Syncs (SYNC_DATA) |
| 7254 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7255 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7256 | final Timer timer = syncs.valueAt(isy); |
| 7257 | final Timer bgTimer = timer.getSubTimer(); |
| 7258 | final long syToken = proto.start(UidProto.SYNCS); |
| 7259 | |
| 7260 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7261 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7262 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7263 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7264 | |
| 7265 | proto.end(syToken); |
| 7266 | } |
| 7267 | |
| 7268 | // User activity (USER_ACTIVITY_DATA) |
| 7269 | if (u.hasUserActivity()) { |
| 7270 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7271 | int val = u.getUserActivityCount(i, which); |
| 7272 | if (val != 0) { |
| 7273 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7274 | proto.write(UidProto.UserActivity.NAME, i); |
| 7275 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7276 | proto.end(uaToken); |
| 7277 | } |
| 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | // Vibrator (VIBRATOR_DATA) |
| 7282 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7283 | |
| 7284 | // Video (VIDEO_DATA) |
| 7285 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7286 | |
| 7287 | // Wakelocks (WAKELOCK_DATA) |
| 7288 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7289 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7290 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7291 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7292 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7293 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7294 | rawRealtimeUs, which); |
| 7295 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7296 | if (pTimer != null) { |
| 7297 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7298 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7299 | rawRealtimeUs, which); |
| 7300 | } |
| 7301 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7302 | rawRealtimeUs, which); |
| 7303 | proto.end(wToken); |
| 7304 | } |
| 7305 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7306 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7307 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7308 | rawRealtimeUs, which); |
| 7309 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7310 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7311 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7312 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7313 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7314 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7315 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7316 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7317 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7318 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7319 | proto.end(waToken); |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7324 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7325 | u.getWifiControllerActivity(), which); |
| 7326 | |
| 7327 | // Wifi data (WIFI_DATA) |
| 7328 | final long wToken = proto.start(UidProto.WIFI); |
| 7329 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7330 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7331 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7332 | rawRealtimeUs, which); |
| 7333 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7334 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7335 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7336 | rawRealtimeUs, which); |
| 7337 | proto.end(wToken); |
| 7338 | |
| 7339 | proto.end(uTkn); |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7344 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7345 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7346 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7347 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7348 | final int which = STATS_SINCE_CHARGED; |
| 7349 | |
| 7350 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7351 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7352 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7353 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7354 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7355 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7356 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7357 | computeUptime(rawUptimeUs, which) / 1000); |
| 7358 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7359 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7360 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7361 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7362 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7363 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7364 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7365 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7366 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7367 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7368 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7369 | getEstimatedBatteryCapacity()); |
| 7370 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7371 | getMinLearnedBatteryCapacity()); |
| 7372 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7373 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7374 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7375 | |
| 7376 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7377 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7378 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7379 | getLowDischargeAmountSinceCharge()); |
| 7380 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7381 | getHighDischargeAmountSinceCharge()); |
| 7382 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7383 | getDischargeAmountScreenOnSinceCharge()); |
| 7384 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7385 | getDischargeAmountScreenOffSinceCharge()); |
| 7386 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7387 | getDischargeAmountScreenDozeSinceCharge()); |
| 7388 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7389 | getUahDischarge(which) / 1000); |
| 7390 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7391 | getUahDischargeScreenOff(which) / 1000); |
| 7392 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7393 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7394 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7395 | getUahDischargeLightDoze(which) / 1000); |
| 7396 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7397 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7398 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7399 | |
| 7400 | // Time remaining |
| 7401 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7402 | // 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] | 7403 | if (timeRemainingUs >= 0) { |
| 7404 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7405 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7406 | } else { |
| 7407 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7408 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7409 | if (timeRemainingUs >= 0) { |
| 7410 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7411 | } else { |
| 7412 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | // Charge step (CHARGE_STEP_DATA) |
| 7417 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7418 | |
| 7419 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7420 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7421 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7422 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7423 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7424 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7425 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7429 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7430 | |
| 7431 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7432 | final long[] cpuFreqs = getCpuFreqs(); |
| 7433 | if (cpuFreqs != null) { |
| 7434 | for (long i : cpuFreqs) { |
| 7435 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7436 | } |
| 7437 | } |
| 7438 | |
| 7439 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7440 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7441 | getBluetoothControllerActivity(), which); |
| 7442 | |
| 7443 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7444 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7445 | getModemControllerActivity(), which); |
| 7446 | |
| 7447 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7448 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7449 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7450 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7451 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7452 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7453 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7454 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7455 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7456 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7457 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7458 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7459 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7460 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7461 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7462 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7463 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7464 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7465 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7466 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7467 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7468 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7469 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7470 | |
| 7471 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7472 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7473 | getWifiControllerActivity(), which); |
| 7474 | |
| 7475 | |
| 7476 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7477 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7478 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7479 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7480 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7481 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7482 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7483 | |
| 7484 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7485 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7486 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7487 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7488 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7489 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7490 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7491 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7492 | } |
| 7493 | |
| 7494 | // Misc (MISC_DATA) |
| 7495 | // Calculate wakelock times across all uids. |
| 7496 | long fullWakeLockTimeTotalUs = 0; |
| 7497 | long partialWakeLockTimeTotalUs = 0; |
| 7498 | |
| 7499 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7500 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7501 | final Uid u = uidStats.valueAt(iu); |
| 7502 | |
| 7503 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7504 | u.getWakelockStats(); |
| 7505 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7506 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7507 | |
| 7508 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7509 | if (fullWakeTimer != null) { |
| 7510 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7511 | which); |
| 7512 | } |
| 7513 | |
| 7514 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7515 | if (partialWakeTimer != null) { |
| 7516 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7517 | rawRealtimeUs, which); |
| 7518 | } |
| 7519 | } |
| 7520 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7521 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7522 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7523 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7524 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7525 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7526 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7527 | fullWakeLockTimeTotalUs / 1000); |
| 7528 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7529 | partialWakeLockTimeTotalUs / 1000); |
| 7530 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7531 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7532 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7533 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7534 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7535 | getMobileRadioActiveCount(which)); |
| 7536 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7537 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7538 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7539 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7540 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7541 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7542 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7543 | getNumConnectivityChange(which)); |
| 7544 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7545 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7546 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7547 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7548 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7549 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7550 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7551 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7552 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7553 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7554 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7555 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7556 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7557 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7558 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7559 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7560 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7561 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7562 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7563 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7564 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7565 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7566 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7567 | final long multicastWakeLockTimeTotalUs = |
| 7568 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7569 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7570 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7571 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7572 | multicastWakeLockTimeTotalUs / 1000); |
| 7573 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7574 | multicastWakeLockCountTotal); |
| 7575 | proto.end(wmctToken); |
| 7576 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7577 | // Power use item (POWER_USE_ITEM_DATA) |
| 7578 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7579 | if (sippers != null) { |
| 7580 | for (int i = 0; i < sippers.size(); ++i) { |
| 7581 | final BatterySipper bs = sippers.get(i); |
| 7582 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7583 | int uid = 0; |
| 7584 | switch (bs.drainType) { |
| 7585 | case IDLE: |
| 7586 | n = SystemProto.PowerUseItem.IDLE; |
| 7587 | break; |
| 7588 | case CELL: |
| 7589 | n = SystemProto.PowerUseItem.CELL; |
| 7590 | break; |
| 7591 | case PHONE: |
| 7592 | n = SystemProto.PowerUseItem.PHONE; |
| 7593 | break; |
| 7594 | case WIFI: |
| 7595 | n = SystemProto.PowerUseItem.WIFI; |
| 7596 | break; |
| 7597 | case BLUETOOTH: |
| 7598 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7599 | break; |
| 7600 | case SCREEN: |
| 7601 | n = SystemProto.PowerUseItem.SCREEN; |
| 7602 | break; |
| 7603 | case FLASHLIGHT: |
| 7604 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7605 | break; |
| 7606 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7607 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7608 | continue; |
| 7609 | case USER: |
| 7610 | n = SystemProto.PowerUseItem.USER; |
| 7611 | uid = UserHandle.getUid(bs.userId, 0); |
| 7612 | break; |
| 7613 | case UNACCOUNTED: |
| 7614 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7615 | break; |
| 7616 | case OVERCOUNTED: |
| 7617 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7618 | break; |
| 7619 | case CAMERA: |
| 7620 | n = SystemProto.PowerUseItem.CAMERA; |
| 7621 | break; |
| 7622 | case MEMORY: |
| 7623 | n = SystemProto.PowerUseItem.MEMORY; |
| 7624 | break; |
| 7625 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7626 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7627 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7628 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7629 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7630 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7631 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7632 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7633 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7634 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7639 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7640 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7641 | helper.getPowerProfile().getBatteryCapacity()); |
| 7642 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7643 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7644 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7645 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7646 | |
| 7647 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7648 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7649 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7650 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7651 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7652 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7653 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7654 | ent.getValue(), rawRealtimeUs, which); |
| 7655 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7656 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7657 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7661 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7662 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7663 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7664 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7665 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7666 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7670 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7671 | which); |
| 7672 | |
| 7673 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7674 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7675 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7676 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7677 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7678 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7679 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7683 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7684 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7685 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7686 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7687 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7688 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7689 | } |
| 7690 | |
| 7691 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7692 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7693 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7694 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7695 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7696 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7697 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7698 | } |
| 7699 | |
| 7700 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7701 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7702 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7703 | proto.write(SystemProto.WifiState.NAME, i); |
| 7704 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7705 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7706 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7710 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7711 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7712 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7713 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7714 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7715 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | proto.end(sToken); |
| 7719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | } |