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; |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 23 | import android.server.ServerProtoEnums; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 24 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 25 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 26 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 27 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 28 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 29 | import android.util.MutableBoolean; |
| 30 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.Printer; |
| 32 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 33 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 34 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 35 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 36 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 37 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 38 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 39 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 40 | import com.android.internal.os.BatterySipper; |
| 41 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 43 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
| 45 | import java.util.ArrayList; |
| 46 | import java.util.Collections; |
| 47 | import java.util.Comparator; |
| 48 | import java.util.Formatter; |
| 49 | import java.util.HashMap; |
| 50 | import java.util.List; |
| 51 | import java.util.Map; |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /** |
| 54 | * A class providing access to battery usage statistics, including information on |
| 55 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 56 | * except where indicated otherwise. |
| 57 | * @hide |
| 58 | */ |
| 59 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 60 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 63 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 64 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 65 | |
| 66 | /** @hide */ |
| 67 | public static final String SERVICE_NAME = "batterystats"; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /** |
| 70 | * A constant indicating a partial wake lock timer. |
| 71 | */ |
| 72 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 73 | |
| 74 | /** |
| 75 | * A constant indicating a full wake lock timer. |
| 76 | */ |
| 77 | public static final int WAKE_TYPE_FULL = 1; |
| 78 | |
| 79 | /** |
| 80 | * A constant indicating a window wake lock timer. |
| 81 | */ |
| 82 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | /** |
| 85 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | */ |
| 87 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 89 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 90 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 91 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 92 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 93 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 94 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 95 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 96 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 97 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 98 | |
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 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 101 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 102 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 104 | /** |
| 105 | * A constant indicating a wifi multicast timer |
| 106 | */ |
| 107 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 110 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 111 | */ |
| 112 | public static final int VIDEO_TURNED_ON = 8; |
| 113 | |
| 114 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 115 | * A constant indicating a vibrator on timer |
| 116 | */ |
| 117 | public static final int VIBRATOR_ON = 9; |
| 118 | |
| 119 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 120 | * A constant indicating a foreground activity timer |
| 121 | */ |
| 122 | public static final int FOREGROUND_ACTIVITY = 10; |
| 123 | |
| 124 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 125 | * A constant indicating a wifi batched scan is active |
| 126 | */ |
| 127 | public static final int WIFI_BATCHED_SCAN = 11; |
| 128 | |
| 129 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 130 | * A constant indicating a process state timer |
| 131 | */ |
| 132 | public static final int PROCESS_STATE = 12; |
| 133 | |
| 134 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 135 | * A constant indicating a sync timer |
| 136 | */ |
| 137 | public static final int SYNC = 13; |
| 138 | |
| 139 | /** |
| 140 | * A constant indicating a job timer |
| 141 | */ |
| 142 | public static final int JOB = 14; |
| 143 | |
| 144 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 145 | * A constant indicating an audio turn on timer |
| 146 | */ |
| 147 | public static final int AUDIO_TURNED_ON = 15; |
| 148 | |
| 149 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 150 | * A constant indicating a flashlight turn on timer |
| 151 | */ |
| 152 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 153 | |
| 154 | /** |
| 155 | * A constant indicating a camera turn on timer |
| 156 | */ |
| 157 | public static final int CAMERA_TURNED_ON = 17; |
| 158 | |
| 159 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 160 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 161 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 162 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 165 | * A constant indicating a bluetooth scan timer. |
| 166 | */ |
| 167 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 168 | |
| 169 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 170 | * A constant indicating an aggregated partial wake lock timer. |
| 171 | */ |
| 172 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 173 | |
| 174 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 175 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 176 | */ |
| 177 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 178 | |
| 179 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 180 | * A constant indicating a foreground service timer |
| 181 | */ |
| 182 | public static final int FOREGROUND_SERVICE = 22; |
| 183 | |
| 184 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 185 | * A constant indicating an aggregate wifi multicast timer |
| 186 | */ |
| 187 | public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; |
| 188 | |
| 189 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | * Include all of the data in the stats, including previously saved data. |
| 191 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 192 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | |
| 194 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | * Include only the current run in the stats. |
| 196 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 197 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Include only the run since the last time the device was unplugged in the stats. |
| 201 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 202 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 203 | |
| 204 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 205 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 206 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 207 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 210 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 211 | * |
| 212 | * New in version 19: |
| 213 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 214 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 215 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 216 | * New in version 21: |
| 217 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 218 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 219 | * - BLE scan result count |
| 220 | * - CPU frequency time per uid |
| 221 | * New in version 22: |
| 222 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 223 | * - Background partial wakelock time & count |
| 224 | * New in version 23: |
| 225 | * - Logging smeared power model values |
| 226 | * New in version 24: |
| 227 | * - Fixed bugs in background timers and BLE scan time |
| 228 | * New in version 25: |
| 229 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 230 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 231 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 232 | * New in version 27: |
| 233 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 234 | * New in version 28: |
| 235 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 236 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 237 | * New in version 29: |
| 238 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 239 | * - CPU times per UID process state |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 240 | * New in version 30: |
| 241 | * - Uid.PROCESS_STATE_FOREGROUND_SERVICE only tracks |
| 242 | * ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 243 | */ |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 244 | static final int CHECKIN_VERSION = 30; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * 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] | 248 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 249 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 250 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 251 | private static final long BYTES_PER_KB = 1024; |
| 252 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 253 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 254 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 255 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 256 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 257 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 259 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 260 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 261 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 262 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 263 | // rpm line is: |
| 264 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 265 | // screen-off time, screen-off count |
| 266 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 267 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 268 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 269 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 270 | // fgs line is: |
| 271 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 272 | // foreground service time, count |
| 273 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 274 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 275 | // wl line is: |
| 276 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 277 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 278 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 279 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 280 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 281 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 282 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 283 | // awl line is: |
| 284 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 285 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 286 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 287 | private static final String SYNC_DATA = "sy"; |
| 288 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 289 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame^] | 290 | |
| 291 | /** |
| 292 | * jbd line is: |
| 293 | * BATTERY_STATS_CHECKIN_VERSION, uid, which, "jbd", |
| 294 | * jobsDeferredEventCount, jobsDeferredCount, averageLatencyMillis, |
| 295 | * count at latency < 1 hr, count at latency < 2 hrs, count at latency < 6 hrs, beyond 6 hrs |
| 296 | * <p> |
| 297 | * @see #JOB_FRESHNESS_BUCKETS |
| 298 | */ |
| 299 | private static final String JOBS_DEFERRED_DATA = "jbd"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 300 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 301 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 302 | private static final String NETWORK_DATA = "nt"; |
| 303 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 304 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 305 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 306 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 307 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 308 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 309 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 310 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 311 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 312 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 313 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 314 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 315 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 316 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 317 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 318 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 319 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 320 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 321 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 322 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 323 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 324 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 325 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 326 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 327 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 328 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 329 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 330 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 331 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 332 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 333 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 334 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 335 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 336 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 337 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 338 | private static final String FLASHLIGHT_DATA = "fla"; |
| 339 | private static final String CAMERA_DATA = "cam"; |
| 340 | private static final String VIDEO_DATA = "vid"; |
| 341 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 342 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 343 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 345 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 346 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 347 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 349 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 350 | private static final String CELLULAR_CONTROLLER_NAME = "Cellular"; |
| 351 | private static final String WIFI_CONTROLLER_NAME = "WiFi"; |
| 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 354 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 355 | * |
| 356 | * Other types might include times spent in foreground, background etc. |
| 357 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 358 | @VisibleForTesting |
| 359 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 360 | |
| 361 | /** |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame^] | 362 | * These are the thresholds for bucketing last time since a job was run for an app |
| 363 | * that just moved to ACTIVE due to a launch. So if the last time a job ran was less |
| 364 | * than 30 minutes ago, then it's reasonably fresh, 2 hours ago, not so fresh and so |
| 365 | * on. |
| 366 | */ |
| 367 | public static final long[] JOB_FRESHNESS_BUCKETS = { |
| 368 | 1 * 60 * 60 * 1000L, |
| 369 | 2 * 60 * 60 * 1000L, |
| 370 | 6 * 60 * 60 * 1000L, |
| 371 | Long.MAX_VALUE |
| 372 | }; |
| 373 | |
| 374 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 375 | * State for keeping track of counting information. |
| 376 | */ |
| 377 | public static abstract class Counter { |
| 378 | |
| 379 | /** |
| 380 | * Returns the count associated with this Counter for the |
| 381 | * selected type of statistics. |
| 382 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 383 | * @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] | 384 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 385 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 386 | |
| 387 | /** |
| 388 | * Temporary for debugging. |
| 389 | */ |
| 390 | public abstract void logState(Printer pw, String prefix); |
| 391 | } |
| 392 | |
| 393 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 394 | * State for keeping track of long counting information. |
| 395 | */ |
| 396 | public static abstract class LongCounter { |
| 397 | |
| 398 | /** |
| 399 | * Returns the count associated with this Counter for the |
| 400 | * selected type of statistics. |
| 401 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 402 | * @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] | 403 | */ |
| 404 | public abstract long getCountLocked(int which); |
| 405 | |
| 406 | /** |
| 407 | * Temporary for debugging. |
| 408 | */ |
| 409 | public abstract void logState(Printer pw, String prefix); |
| 410 | } |
| 411 | |
| 412 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 413 | * State for keeping track of array of long counting information. |
| 414 | */ |
| 415 | public static abstract class LongCounterArray { |
| 416 | /** |
| 417 | * Returns the counts associated with this Counter for the |
| 418 | * selected type of statistics. |
| 419 | * |
| 420 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 421 | */ |
| 422 | public abstract long[] getCountsLocked(int which); |
| 423 | |
| 424 | /** |
| 425 | * Temporary for debugging. |
| 426 | */ |
| 427 | public abstract void logState(Printer pw, String prefix); |
| 428 | } |
| 429 | |
| 430 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 431 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 432 | * radio controller. |
| 433 | */ |
| 434 | public static abstract class ControllerActivityCounter { |
| 435 | /** |
| 436 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 437 | * idle state. |
| 438 | */ |
| 439 | public abstract LongCounter getIdleTimeCounter(); |
| 440 | |
| 441 | /** |
| 442 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 443 | * scan state. |
| 444 | */ |
| 445 | public abstract LongCounter getScanTimeCounter(); |
| 446 | |
| 447 | |
| 448 | /** |
| 449 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 450 | * receive state. |
| 451 | */ |
| 452 | public abstract LongCounter getRxTimeCounter(); |
| 453 | |
| 454 | /** |
| 455 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 456 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 457 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 458 | * various transmit level states. |
| 459 | */ |
| 460 | public abstract LongCounter[] getTxTimeCounters(); |
| 461 | |
| 462 | /** |
| 463 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 464 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 465 | * yield a value of 0 if the device doesn't support power calculations. |
| 466 | */ |
| 467 | public abstract LongCounter getPowerCounter(); |
| 468 | } |
| 469 | |
| 470 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | * State for keeping track of timing information. |
| 472 | */ |
| 473 | public static abstract class Timer { |
| 474 | |
| 475 | /** |
| 476 | * Returns the count associated with this Timer for the |
| 477 | * selected type of statistics. |
| 478 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 479 | * @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] | 480 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 481 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | |
| 483 | /** |
| 484 | * Returns the total time in microseconds associated with this Timer for the |
| 485 | * selected type of statistics. |
| 486 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 487 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 488 | * @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] | 489 | * @return a time in microseconds |
| 490 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 491 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 494 | * Returns the total time in microseconds associated with this Timer since the |
| 495 | * 'mark' was last set. |
| 496 | * |
| 497 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 498 | * @return a time in microseconds |
| 499 | */ |
| 500 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 501 | |
| 502 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 503 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 504 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 505 | */ |
| 506 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 507 | return -1; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * 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] | 512 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 513 | */ |
| 514 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 515 | return -1; |
| 516 | } |
| 517 | |
| 518 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 519 | * 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] | 520 | * |
| 521 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 522 | * been on since reset. |
| 523 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 524 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 525 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 526 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 527 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 528 | */ |
| 529 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 530 | return -1; |
| 531 | } |
| 532 | |
| 533 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 534 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 535 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 536 | * |
| 537 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 538 | */ |
| 539 | public Timer getSubTimer() { |
| 540 | return null; |
| 541 | } |
| 542 | |
| 543 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 544 | * Returns whether the timer is currently running. Some types of timers |
| 545 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 546 | * and report false. |
| 547 | */ |
| 548 | public boolean isRunningLocked() { |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | * Temporary for debugging. |
| 554 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 555 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 559 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 560 | */ |
| 561 | public static int mapToInternalProcessState(int procState) { |
| 562 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 563 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 564 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 565 | return Uid.PROCESS_STATE_TOP; |
Dianne Hackborn | 10fc4fd | 2017-12-19 17:23:13 -0800 | [diff] [blame] | 566 | } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 567 | // State when app has put itself in the foreground. |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 568 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 569 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 570 | // Persistent and other foreground states go here. |
| 571 | return Uid.PROCESS_STATE_FOREGROUND; |
| 572 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 573 | return Uid.PROCESS_STATE_BACKGROUND; |
| 574 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 575 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 576 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 577 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 578 | } else { |
| 579 | return Uid.PROCESS_STATE_CACHED; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | * The statistics associated with a particular uid. |
| 585 | */ |
| 586 | public static abstract class Uid { |
| 587 | |
| 588 | /** |
| 589 | * Returns a mapping containing wakelock statistics. |
| 590 | * |
| 591 | * @return a Map from Strings to Uid.Wakelock objects. |
| 592 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 593 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | |
| 595 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 596 | * Returns the WiFi Multicast Wakelock statistics. |
| 597 | * |
| 598 | * @return a Timer Object for the per uid Multicast statistics. |
| 599 | */ |
| 600 | public abstract Timer getMulticastWakelockStats(); |
| 601 | |
| 602 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 603 | * Returns a mapping containing sync statistics. |
| 604 | * |
| 605 | * @return a Map from Strings to Timer objects. |
| 606 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 607 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 608 | |
| 609 | /** |
| 610 | * Returns a mapping containing scheduled job statistics. |
| 611 | * |
| 612 | * @return a Map from Strings to Timer objects. |
| 613 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 614 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 615 | |
| 616 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 617 | * Returns statistics about how jobs have completed. |
| 618 | * |
| 619 | * @return A Map of String job names to completion type -> count mapping. |
| 620 | */ |
| 621 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 622 | |
| 623 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | * The statistics associated with a particular wake lock. |
| 625 | */ |
| 626 | public static abstract class Wakelock { |
| 627 | public abstract Timer getWakeTime(int type); |
| 628 | } |
| 629 | |
| 630 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 631 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 632 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 633 | * wakelocks that overlap in time (and therefore over-counts). |
| 634 | */ |
| 635 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 636 | |
| 637 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | * Returns a mapping containing sensor statistics. |
| 639 | * |
| 640 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 641 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 642 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | |
| 644 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 645 | * Returns a mapping containing active process data. |
| 646 | */ |
| 647 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 648 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 649 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | * Returns a mapping containing process statistics. |
| 651 | * |
| 652 | * @return a Map from Strings to Uid.Proc objects. |
| 653 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 654 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | |
| 656 | /** |
| 657 | * Returns a mapping containing package statistics. |
| 658 | * |
| 659 | * @return a Map from Strings to Uid.Pkg objects. |
| 660 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 661 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 662 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 663 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 664 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 665 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 666 | |
| 667 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * {@hide} |
| 669 | */ |
| 670 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 671 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 672 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 673 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 674 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 675 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 676 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 677 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 678 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 679 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 680 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 681 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 682 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 683 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 684 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 685 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 686 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 687 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 688 | /** |
| 689 | * Returns the timer keeping track of wifi scans. |
| 690 | */ |
| 691 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 692 | public abstract int getWifiScanBackgroundCount(int which); |
| 693 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 694 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 695 | /** |
| 696 | * Returns the timer keeping track of background wifi scans. |
| 697 | */ |
| 698 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 699 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 700 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 701 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 702 | public abstract Timer getAudioTurnedOnTimer(); |
| 703 | public abstract Timer getVideoTurnedOnTimer(); |
| 704 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 705 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 706 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 707 | |
| 708 | /** |
| 709 | * Returns the timer keeping track of Foreground Service time |
| 710 | */ |
| 711 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 712 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 713 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 714 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 715 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 716 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 717 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 718 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 719 | public abstract long[] getCpuFreqTimes(int which); |
| 720 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 721 | /** |
| 722 | * Returns cpu active time of an uid. |
| 723 | */ |
| 724 | public abstract long getCpuActiveTime(); |
| 725 | /** |
| 726 | * Returns cpu times of an uid on each cluster |
| 727 | */ |
| 728 | public abstract long[] getCpuClusterTimes(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 729 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 730 | /** |
| 731 | * Returns cpu times of an uid at a particular process state. |
| 732 | */ |
| 733 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 734 | /** |
| 735 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 736 | */ |
| 737 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 738 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 739 | // Note: the following times are disjoint. They can be added together to find the |
| 740 | // total time a uid has had any processes running at all. |
| 741 | |
| 742 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 743 | * Time this uid has any processes in the top state. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 744 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 745 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 746 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 747 | * Time this uid has any process with a started foreground service, but |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 748 | * none in the "top" state. |
| 749 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 750 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 751 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 752 | * Time this uid has any process in an active foreground state, but none in the |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 753 | * "foreground service" or better state. Persistent and other foreground states go here. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 754 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 755 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 756 | /** |
| 757 | * Time this uid has any process in an active background state, but none in the |
| 758 | * "foreground" or better state. |
| 759 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 760 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 761 | /** |
| 762 | * Time this uid has any process that is top while the device is sleeping, but not |
| 763 | * active for any other reason. We kind-of consider it a kind of cached process |
| 764 | * for execution restrictions. |
| 765 | */ |
| 766 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 767 | /** |
| 768 | * Time this uid has any process that is in the background but it has an activity |
| 769 | * marked as "can't save state". This is essentially a cached process, though the |
| 770 | * system will try much harder than normal to avoid killing it. |
| 771 | */ |
| 772 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 773 | /** |
| 774 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 775 | * other active states. |
| 776 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 777 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 778 | /** |
| 779 | * Total number of process states we track. |
| 780 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 781 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 782 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 783 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 784 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 785 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 786 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 787 | }; |
| 788 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 789 | // Used in checkin dump |
| 790 | @VisibleForTesting |
| 791 | public static final String[] UID_PROCESS_TYPES = { |
| 792 | "T", // TOP |
| 793 | "FS", // FOREGROUND_SERVICE |
| 794 | "F", // FOREGROUND |
| 795 | "B", // BACKGROUND |
| 796 | "TS", // TOP_SLEEPING |
| 797 | "HW", // HEAVY_WEIGHT |
| 798 | "C" // CACHED |
| 799 | }; |
| 800 | |
| 801 | /** |
| 802 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 803 | * is not attributed to any non-critical process states. |
| 804 | */ |
| 805 | public static final int[] CRITICAL_PROC_STATES = { |
| 806 | PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND |
| 807 | }; |
| 808 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 809 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 810 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 811 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 812 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 814 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 815 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 816 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 817 | * Note that these must match the constants in android.os.PowerManager. |
| 818 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 819 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 820 | */ |
| 821 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 822 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 823 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 824 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 825 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 826 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 827 | public abstract void noteUserActivityLocked(int type); |
| 828 | public abstract boolean hasUserActivity(); |
| 829 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 830 | |
| 831 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 832 | public abstract long getNetworkActivityBytes(int type, int which); |
| 833 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 834 | public abstract long getMobileRadioActiveTime(int which); |
| 835 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 836 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 837 | /** |
| 838 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 839 | */ |
| 840 | public abstract long getUserCpuTimeUs(int which); |
| 841 | |
| 842 | /** |
| 843 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 844 | */ |
| 845 | public abstract long getSystemCpuTimeUs(int which); |
| 846 | |
| 847 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 848 | * 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] | 849 | * given CPU cluster. |
| 850 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 851 | * @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] | 852 | * @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] | 853 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 854 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 855 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 856 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 857 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 858 | /** |
| 859 | * Returns the number of times this UID woke up the Application Processor to |
| 860 | * process a mobile radio packet. |
| 861 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 862 | */ |
| 863 | public abstract long getMobileRadioApWakeupCount(int which); |
| 864 | |
| 865 | /** |
| 866 | * Returns the number of times this UID woke up the Application Processor to |
| 867 | * process a WiFi packet. |
| 868 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 869 | */ |
| 870 | public abstract long getWifiRadioApWakeupCount(int which); |
| 871 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame^] | 872 | /** |
| 873 | * Appends the deferred jobs data to the StringBuilder passed in, in checkin format |
| 874 | * @param sb StringBuilder that can be overwritten with the deferred jobs data |
| 875 | * @param which one of STATS_* |
| 876 | */ |
| 877 | public abstract void getDeferredJobsCheckinLineLocked(StringBuilder sb, int which); |
| 878 | |
| 879 | /** |
| 880 | * Appends the deferred jobs data to the StringBuilder passed in |
| 881 | * @param sb StringBuilder that can be overwritten with the deferred jobs data |
| 882 | * @param which one of STATS_* |
| 883 | */ |
| 884 | public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which); |
| 885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 887 | /* |
| 888 | * FIXME: it's not correct to use this magic value because it |
| 889 | * could clash with a sensor handle (which are defined by |
| 890 | * the sensor HAL, and therefore out of our control |
| 891 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | // Magic sensor number for the GPS. |
| 893 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 898 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 899 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 900 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 903 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 904 | public int mWakeNesting; |
| 905 | public long mWakeSumMs; |
| 906 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 907 | } |
| 908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | /** |
| 910 | * The statistics associated with a particular process. |
| 911 | */ |
| 912 | public static abstract class Proc { |
| 913 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 914 | public static class ExcessivePower { |
| 915 | public static final int TYPE_WAKE = 1; |
| 916 | public static final int TYPE_CPU = 2; |
| 917 | |
| 918 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 919 | public long overTime; |
| 920 | public long usedTime; |
| 921 | } |
| 922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 924 | * Returns true if this process is still active in the battery stats. |
| 925 | */ |
| 926 | public abstract boolean isActive(); |
| 927 | |
| 928 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 929 | * 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] | 930 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 931 | * @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] | 932 | */ |
| 933 | public abstract long getUserTime(int which); |
| 934 | |
| 935 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 936 | * 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] | 937 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 938 | * @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] | 939 | */ |
| 940 | public abstract long getSystemTime(int which); |
| 941 | |
| 942 | /** |
| 943 | * Returns the number of times the process has been started. |
| 944 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 945 | * @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] | 946 | */ |
| 947 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 948 | |
| 949 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 950 | * Returns the number of times the process has crashed. |
| 951 | * |
| 952 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 953 | */ |
| 954 | public abstract int getNumCrashes(int which); |
| 955 | |
| 956 | /** |
| 957 | * Returns the number of times the process has ANRed. |
| 958 | * |
| 959 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 960 | */ |
| 961 | public abstract int getNumAnrs(int which); |
| 962 | |
| 963 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 964 | * 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] | 965 | * @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] | 966 | * @return foreground cpu time in microseconds |
| 967 | */ |
| 968 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 969 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 970 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 971 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 972 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /** |
| 976 | * The statistics associated with a particular package. |
| 977 | */ |
| 978 | public static abstract class Pkg { |
| 979 | |
| 980 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 981 | * Returns information about all wakeup alarms that have been triggered for this |
| 982 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 983 | * 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] | 984 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 985 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | |
| 987 | /** |
| 988 | * Returns a mapping containing service statistics. |
| 989 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 990 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | |
| 992 | /** |
| 993 | * The statistics associated with a particular service. |
| 994 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 995 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | |
| 997 | /** |
| 998 | * Returns the amount of time spent started. |
| 999 | * |
| 1000 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1001 | * @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] | 1002 | * @return |
| 1003 | */ |
| 1004 | public abstract long getStartTime(long batteryUptime, int which); |
| 1005 | |
| 1006 | /** |
| 1007 | * Returns the total number of times startService() has been called. |
| 1008 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1009 | * @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] | 1010 | */ |
| 1011 | public abstract int getStarts(int which); |
| 1012 | |
| 1013 | /** |
| 1014 | * Returns the total number times the service has been launched. |
| 1015 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1016 | * @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] | 1017 | */ |
| 1018 | public abstract int getLaunches(int which); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1023 | public static final class LevelStepTracker { |
| 1024 | public long mLastStepTime = -1; |
| 1025 | public int mNumStepDurations; |
| 1026 | public final long[] mStepDurations; |
| 1027 | |
| 1028 | public LevelStepTracker(int maxLevelSteps) { |
| 1029 | mStepDurations = new long[maxLevelSteps]; |
| 1030 | } |
| 1031 | |
| 1032 | public LevelStepTracker(int numSteps, long[] steps) { |
| 1033 | mNumStepDurations = numSteps; |
| 1034 | mStepDurations = new long[numSteps]; |
| 1035 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 1036 | } |
| 1037 | |
| 1038 | public long getDurationAt(int index) { |
| 1039 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 1040 | } |
| 1041 | |
| 1042 | public int getLevelAt(int index) { |
| 1043 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 1044 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1045 | } |
| 1046 | |
| 1047 | public int getInitModeAt(int index) { |
| 1048 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1049 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1050 | } |
| 1051 | |
| 1052 | public int getModModeAt(int index) { |
| 1053 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1054 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1055 | } |
| 1056 | |
| 1057 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 1058 | boolean hasData = false; |
| 1059 | while (topOffset >= 0) { |
| 1060 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1061 | topOffset -= 4; |
| 1062 | if (!hasData && digit == 0) { |
| 1063 | continue; |
| 1064 | } |
| 1065 | hasData = true; |
| 1066 | if (digit >= 0 && digit <= 9) { |
| 1067 | out.append((char)('0' + digit)); |
| 1068 | } else { |
| 1069 | out.append((char)('a' + digit - 10)); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1075 | long item = mStepDurations[index]; |
| 1076 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1077 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1078 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1079 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1080 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1081 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1082 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1083 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1084 | case Display.STATE_OFF: out.append('f'); break; |
| 1085 | case Display.STATE_ON: out.append('o'); break; |
| 1086 | case Display.STATE_DOZE: out.append('d'); break; |
| 1087 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1088 | } |
| 1089 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1090 | out.append('p'); |
| 1091 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1092 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1093 | out.append('i'); |
| 1094 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1095 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1096 | case Display.STATE_OFF: out.append('F'); break; |
| 1097 | case Display.STATE_ON: out.append('O'); break; |
| 1098 | case Display.STATE_DOZE: out.append('D'); break; |
| 1099 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1100 | } |
| 1101 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1102 | out.append('P'); |
| 1103 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1104 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1105 | out.append('I'); |
| 1106 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1107 | out.append('-'); |
| 1108 | appendHex(level, 4, out); |
| 1109 | out.append('-'); |
| 1110 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1111 | } |
| 1112 | |
| 1113 | public void decodeEntryAt(int index, String value) { |
| 1114 | final int N = value.length(); |
| 1115 | int i = 0; |
| 1116 | char c; |
| 1117 | long out = 0; |
| 1118 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1119 | i++; |
| 1120 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1121 | 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] | 1122 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1123 | 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] | 1124 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1125 | 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] | 1126 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1127 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1128 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1129 | break; |
| 1130 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1131 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1132 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1133 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1134 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1135 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1136 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1137 | break; |
| 1138 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1139 | break; |
| 1140 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1141 | break; |
| 1142 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1143 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1144 | break; |
| 1145 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1146 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1147 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1148 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1149 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1150 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1154 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1155 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1156 | i++; |
| 1157 | level <<= 4; |
| 1158 | if (c >= '0' && c <= '9') { |
| 1159 | level += c - '0'; |
| 1160 | } else if (c >= 'a' && c <= 'f') { |
| 1161 | level += c - 'a' + 10; |
| 1162 | } else if (c >= 'A' && c <= 'F') { |
| 1163 | level += c - 'A' + 10; |
| 1164 | } |
| 1165 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1166 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1167 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1168 | long duration = 0; |
| 1169 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1170 | i++; |
| 1171 | duration <<= 4; |
| 1172 | if (c >= '0' && c <= '9') { |
| 1173 | duration += c - '0'; |
| 1174 | } else if (c >= 'a' && c <= 'f') { |
| 1175 | duration += c - 'a' + 10; |
| 1176 | } else if (c >= 'A' && c <= 'F') { |
| 1177 | duration += c - 'A' + 10; |
| 1178 | } |
| 1179 | } |
| 1180 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1181 | } |
| 1182 | |
| 1183 | public void init() { |
| 1184 | mLastStepTime = -1; |
| 1185 | mNumStepDurations = 0; |
| 1186 | } |
| 1187 | |
| 1188 | public void clearTime() { |
| 1189 | mLastStepTime = -1; |
| 1190 | } |
| 1191 | |
| 1192 | public long computeTimePerLevel() { |
| 1193 | final long[] steps = mStepDurations; |
| 1194 | final int numSteps = mNumStepDurations; |
| 1195 | |
| 1196 | // For now we'll do a simple average across all steps. |
| 1197 | if (numSteps <= 0) { |
| 1198 | return -1; |
| 1199 | } |
| 1200 | long total = 0; |
| 1201 | for (int i=0; i<numSteps; i++) { |
| 1202 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1203 | } |
| 1204 | return total / numSteps; |
| 1205 | /* |
| 1206 | long[] buckets = new long[numSteps]; |
| 1207 | int numBuckets = 0; |
| 1208 | int numToAverage = 4; |
| 1209 | int i = 0; |
| 1210 | while (i < numSteps) { |
| 1211 | long totalTime = 0; |
| 1212 | int num = 0; |
| 1213 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1214 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1215 | num++; |
| 1216 | } |
| 1217 | buckets[numBuckets] = totalTime / num; |
| 1218 | numBuckets++; |
| 1219 | numToAverage *= 2; |
| 1220 | i += num; |
| 1221 | } |
| 1222 | if (numBuckets < 1) { |
| 1223 | return -1; |
| 1224 | } |
| 1225 | long averageTime = buckets[numBuckets-1]; |
| 1226 | for (i=numBuckets-2; i>=0; i--) { |
| 1227 | averageTime = (averageTime + buckets[i]) / 2; |
| 1228 | } |
| 1229 | return averageTime; |
| 1230 | */ |
| 1231 | } |
| 1232 | |
| 1233 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1234 | int[] outNumOfInterest) { |
| 1235 | final long[] steps = mStepDurations; |
| 1236 | final int count = mNumStepDurations; |
| 1237 | if (count <= 0) { |
| 1238 | return -1; |
| 1239 | } |
| 1240 | long total = 0; |
| 1241 | int numOfInterest = 0; |
| 1242 | for (int i=0; i<count; i++) { |
| 1243 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1244 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1245 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1246 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1247 | // If the modes of interest didn't change during this step period... |
| 1248 | if ((modMode&modesOfInterest) == 0) { |
| 1249 | // And the mode values during this period match those we are measuring... |
| 1250 | if ((initMode&modesOfInterest) == modeValues) { |
| 1251 | // Then this can be used to estimate the total time! |
| 1252 | numOfInterest++; |
| 1253 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | if (numOfInterest <= 0) { |
| 1258 | return -1; |
| 1259 | } |
| 1260 | |
| 1261 | if (outNumOfInterest != null) { |
| 1262 | outNumOfInterest[0] = numOfInterest; |
| 1263 | } |
| 1264 | |
| 1265 | // The estimated time is the average time we spend in each level, multipled |
| 1266 | // by 100 -- the total number of battery levels |
| 1267 | return (total / numOfInterest) * 100; |
| 1268 | } |
| 1269 | |
| 1270 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1271 | int stepCount = mNumStepDurations; |
| 1272 | final long lastStepTime = mLastStepTime; |
| 1273 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1274 | final long[] steps = mStepDurations; |
| 1275 | long duration = elapsedRealtime - lastStepTime; |
| 1276 | for (int i=0; i<numStepLevels; i++) { |
| 1277 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1278 | long thisDuration = duration / (numStepLevels-i); |
| 1279 | duration -= thisDuration; |
| 1280 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1281 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1282 | } |
| 1283 | steps[0] = thisDuration | modeBits; |
| 1284 | } |
| 1285 | stepCount += numStepLevels; |
| 1286 | if (stepCount > steps.length) { |
| 1287 | stepCount = steps.length; |
| 1288 | } |
| 1289 | } |
| 1290 | mNumStepDurations = stepCount; |
| 1291 | mLastStepTime = elapsedRealtime; |
| 1292 | } |
| 1293 | |
| 1294 | public void readFromParcel(Parcel in) { |
| 1295 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1296 | if (N > mStepDurations.length) { |
| 1297 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1298 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1299 | mNumStepDurations = N; |
| 1300 | for (int i=0; i<N; i++) { |
| 1301 | mStepDurations[i] = in.readLong(); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | public void writeToParcel(Parcel out) { |
| 1306 | final int N = mNumStepDurations; |
| 1307 | out.writeInt(N); |
| 1308 | for (int i=0; i<N; i++) { |
| 1309 | out.writeLong(mStepDurations[i]); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1314 | public static final class PackageChange { |
| 1315 | public String mPackageName; |
| 1316 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1317 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1320 | public static final class DailyItem { |
| 1321 | public long mStartTime; |
| 1322 | public long mEndTime; |
| 1323 | public LevelStepTracker mDischargeSteps; |
| 1324 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1325 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1329 | |
| 1330 | public abstract long getCurrentDailyStartTime(); |
| 1331 | |
| 1332 | public abstract long getNextMinDailyDeadline(); |
| 1333 | |
| 1334 | public abstract long getNextMaxDailyDeadline(); |
| 1335 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1336 | public abstract long[] getCpuFreqs(); |
| 1337 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1338 | public final static class HistoryTag { |
| 1339 | public String string; |
| 1340 | public int uid; |
| 1341 | |
| 1342 | public int poolIdx; |
| 1343 | |
| 1344 | public void setTo(HistoryTag o) { |
| 1345 | string = o.string; |
| 1346 | uid = o.uid; |
| 1347 | poolIdx = o.poolIdx; |
| 1348 | } |
| 1349 | |
| 1350 | public void setTo(String _string, int _uid) { |
| 1351 | string = _string; |
| 1352 | uid = _uid; |
| 1353 | poolIdx = -1; |
| 1354 | } |
| 1355 | |
| 1356 | public void writeToParcel(Parcel dest, int flags) { |
| 1357 | dest.writeString(string); |
| 1358 | dest.writeInt(uid); |
| 1359 | } |
| 1360 | |
| 1361 | public void readFromParcel(Parcel src) { |
| 1362 | string = src.readString(); |
| 1363 | uid = src.readInt(); |
| 1364 | poolIdx = -1; |
| 1365 | } |
| 1366 | |
| 1367 | @Override |
| 1368 | public boolean equals(Object o) { |
| 1369 | if (this == o) return true; |
| 1370 | if (o == null || getClass() != o.getClass()) return false; |
| 1371 | |
| 1372 | HistoryTag that = (HistoryTag) o; |
| 1373 | |
| 1374 | if (uid != that.uid) return false; |
| 1375 | if (!string.equals(that.string)) return false; |
| 1376 | |
| 1377 | return true; |
| 1378 | } |
| 1379 | |
| 1380 | @Override |
| 1381 | public int hashCode() { |
| 1382 | int result = string.hashCode(); |
| 1383 | result = 31 * result + uid; |
| 1384 | return result; |
| 1385 | } |
| 1386 | } |
| 1387 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1388 | /** |
| 1389 | * Optional detailed information that can go into a history step. This is typically |
| 1390 | * generated each time the battery level changes. |
| 1391 | */ |
| 1392 | public final static class HistoryStepDetails { |
| 1393 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1394 | public int userTime; |
| 1395 | public int systemTime; |
| 1396 | |
| 1397 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1398 | public int appCpuUid1; |
| 1399 | public int appCpuUTime1; |
| 1400 | public int appCpuSTime1; |
| 1401 | public int appCpuUid2; |
| 1402 | public int appCpuUTime2; |
| 1403 | public int appCpuSTime2; |
| 1404 | public int appCpuUid3; |
| 1405 | public int appCpuUTime3; |
| 1406 | public int appCpuSTime3; |
| 1407 | |
| 1408 | // Information from /proc/stat |
| 1409 | public int statUserTime; |
| 1410 | public int statSystemTime; |
| 1411 | public int statIOWaitTime; |
| 1412 | public int statIrqTime; |
| 1413 | public int statSoftIrqTime; |
| 1414 | public int statIdlTime; |
| 1415 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1416 | // Platform-level low power state stats |
| 1417 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1418 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1419 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1420 | public HistoryStepDetails() { |
| 1421 | clear(); |
| 1422 | } |
| 1423 | |
| 1424 | public void clear() { |
| 1425 | userTime = systemTime = 0; |
| 1426 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1427 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1428 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1429 | } |
| 1430 | |
| 1431 | public void writeToParcel(Parcel out) { |
| 1432 | out.writeInt(userTime); |
| 1433 | out.writeInt(systemTime); |
| 1434 | out.writeInt(appCpuUid1); |
| 1435 | out.writeInt(appCpuUTime1); |
| 1436 | out.writeInt(appCpuSTime1); |
| 1437 | out.writeInt(appCpuUid2); |
| 1438 | out.writeInt(appCpuUTime2); |
| 1439 | out.writeInt(appCpuSTime2); |
| 1440 | out.writeInt(appCpuUid3); |
| 1441 | out.writeInt(appCpuUTime3); |
| 1442 | out.writeInt(appCpuSTime3); |
| 1443 | out.writeInt(statUserTime); |
| 1444 | out.writeInt(statSystemTime); |
| 1445 | out.writeInt(statIOWaitTime); |
| 1446 | out.writeInt(statIrqTime); |
| 1447 | out.writeInt(statSoftIrqTime); |
| 1448 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1449 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1450 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | public void readFromParcel(Parcel in) { |
| 1454 | userTime = in.readInt(); |
| 1455 | systemTime = in.readInt(); |
| 1456 | appCpuUid1 = in.readInt(); |
| 1457 | appCpuUTime1 = in.readInt(); |
| 1458 | appCpuSTime1 = in.readInt(); |
| 1459 | appCpuUid2 = in.readInt(); |
| 1460 | appCpuUTime2 = in.readInt(); |
| 1461 | appCpuSTime2 = in.readInt(); |
| 1462 | appCpuUid3 = in.readInt(); |
| 1463 | appCpuUTime3 = in.readInt(); |
| 1464 | appCpuSTime3 = in.readInt(); |
| 1465 | statUserTime = in.readInt(); |
| 1466 | statSystemTime = in.readInt(); |
| 1467 | statIOWaitTime = in.readInt(); |
| 1468 | statIrqTime = in.readInt(); |
| 1469 | statSoftIrqTime = in.readInt(); |
| 1470 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1471 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1472 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1476 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1477 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1478 | |
| 1479 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1480 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1481 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1482 | 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] | 1483 | public static final byte CMD_NULL = -1; |
| 1484 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1485 | public static final byte CMD_CURRENT_TIME = 5; |
| 1486 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1487 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1488 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1489 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1490 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1491 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1492 | /** |
| 1493 | * Return whether the command code is a delta data update. |
| 1494 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1495 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1496 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1497 | } |
| 1498 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1499 | public byte batteryLevel; |
| 1500 | public byte batteryStatus; |
| 1501 | public byte batteryHealth; |
| 1502 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1503 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1504 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1505 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1506 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1507 | // The charge of the battery in micro-Ampere-hours. |
| 1508 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1509 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1510 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1511 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1512 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1513 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1514 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1515 | 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] | 1516 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1517 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1518 | 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] | 1519 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1520 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1521 | 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] | 1522 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1523 | // These states always appear directly in the first int token |
| 1524 | // of a delta change; they should be ones that change relatively |
| 1525 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1526 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1527 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1528 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1529 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1530 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1531 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1532 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1533 | // Do not use, this is used for coulomb delta count. |
| 1534 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1535 | // These are on the lower bits used for the command; if they change |
| 1536 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1537 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1538 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1539 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1540 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1541 | 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] | 1542 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1543 | // empty slot |
| 1544 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1545 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1546 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1547 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1548 | |
| 1549 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1550 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1551 | public int states; |
| 1552 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1553 | // Constants from WIFI_SUPPL_STATE_* |
| 1554 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1555 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1556 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1557 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1558 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1559 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 1560 | // Values for NUM_GPS_SIGNAL_QUALITY_LEVELS |
| 1561 | public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7; |
| 1562 | public static final int STATE2_GPS_SIGNAL_QUALITY_MASK = |
| 1563 | 0x1 << STATE2_GPS_SIGNAL_QUALITY_SHIFT; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1564 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1565 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1566 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1567 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1568 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1569 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1570 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1571 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1572 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1573 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1574 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1575 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1576 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 1577 | public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1578 | |
| 1579 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1580 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1581 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1582 | |
| 1583 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1584 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1585 | public int states2; |
| 1586 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1587 | // The wake lock that was acquired at this point. |
| 1588 | public HistoryTag wakelockTag; |
| 1589 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1590 | // Kernel wakeup reason at this point. |
| 1591 | public HistoryTag wakeReasonTag; |
| 1592 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1593 | // Non-null when there is more detailed information at this step. |
| 1594 | public HistoryStepDetails stepDetails; |
| 1595 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1596 | public static final int EVENT_FLAG_START = 0x8000; |
| 1597 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1598 | |
| 1599 | // No event in this item. |
| 1600 | public static final int EVENT_NONE = 0x0000; |
| 1601 | // Event is about a process that is running. |
| 1602 | public static final int EVENT_PROC = 0x0001; |
| 1603 | // Event is about an application package that is in the foreground. |
| 1604 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1605 | // Event is about an application package that is at the top of the screen. |
| 1606 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1607 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1608 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1609 | // Events for all additional wake locks aquired/release within a wake block. |
| 1610 | // These are not generated by default. |
| 1611 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1612 | // Event is about an application executing a scheduled job. |
| 1613 | public static final int EVENT_JOB = 0x0006; |
| 1614 | // Events for users running. |
| 1615 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1616 | // Events for foreground user. |
| 1617 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1618 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1619 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1620 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1621 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1622 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1623 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1624 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1625 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1626 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1627 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1628 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1629 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1630 | // 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] | 1631 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1632 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1633 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1634 | // Event for a package being on the temporary whitelist. |
| 1635 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1636 | // Event for the screen waking up. |
| 1637 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1638 | // Event for the UID that woke up the application processor. |
| 1639 | // Used for wakeups coming from WiFi, modem, etc. |
| 1640 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1641 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1642 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1643 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1644 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1645 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1646 | // Mask to extract out only the type part of the event. |
| 1647 | 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] | 1648 | |
| 1649 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1650 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1651 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1652 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1653 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1654 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1655 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1656 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1657 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1658 | 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] | 1659 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1660 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1661 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1662 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1663 | public static final int EVENT_USER_FOREGROUND_START = |
| 1664 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1665 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1666 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1667 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1668 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1669 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1670 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1671 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1672 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1673 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1674 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1675 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1676 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1677 | |
| 1678 | // For CMD_EVENT. |
| 1679 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1680 | public HistoryTag eventTag; |
| 1681 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1682 | // 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] | 1683 | public long currentTime; |
| 1684 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1685 | // Meta-data when reading. |
| 1686 | public int numReadInts; |
| 1687 | |
| 1688 | // Pre-allocated objects. |
| 1689 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1690 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1691 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1692 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1693 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1694 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1695 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1696 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1697 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1698 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1699 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1700 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1701 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1702 | public int describeContents() { |
| 1703 | return 0; |
| 1704 | } |
| 1705 | |
| 1706 | public void writeToParcel(Parcel dest, int flags) { |
| 1707 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1708 | int bat = (((int)cmd)&0xff) |
| 1709 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1710 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1711 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1712 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1713 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1714 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1715 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1716 | dest.writeInt(bat); |
| 1717 | bat = (((int)batteryTemperature)&0xffff) |
| 1718 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1719 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1720 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1721 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1722 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1723 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1724 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1725 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1726 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1727 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1728 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1729 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1730 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1731 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1732 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1733 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1734 | dest.writeLong(currentTime); |
| 1735 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1736 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1737 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1738 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1739 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1740 | int bat = src.readInt(); |
| 1741 | cmd = (byte)(bat&0xff); |
| 1742 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1743 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1744 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1745 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1746 | int bat2 = src.readInt(); |
| 1747 | batteryTemperature = (short)(bat2&0xffff); |
| 1748 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1749 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1750 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1751 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1752 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1753 | wakelockTag = localWakelockTag; |
| 1754 | wakelockTag.readFromParcel(src); |
| 1755 | } else { |
| 1756 | wakelockTag = null; |
| 1757 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1758 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1759 | wakeReasonTag = localWakeReasonTag; |
| 1760 | wakeReasonTag.readFromParcel(src); |
| 1761 | } else { |
| 1762 | wakeReasonTag = null; |
| 1763 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1764 | if ((bat&0x40000000) != 0) { |
| 1765 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1766 | eventTag = localEventTag; |
| 1767 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1768 | } else { |
| 1769 | eventCode = EVENT_NONE; |
| 1770 | eventTag = null; |
| 1771 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1772 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1773 | currentTime = src.readLong(); |
| 1774 | } else { |
| 1775 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1776 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1777 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1780 | public void clear() { |
| 1781 | time = 0; |
| 1782 | cmd = CMD_NULL; |
| 1783 | batteryLevel = 0; |
| 1784 | batteryStatus = 0; |
| 1785 | batteryHealth = 0; |
| 1786 | batteryPlugType = 0; |
| 1787 | batteryTemperature = 0; |
| 1788 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1789 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1790 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1791 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1792 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1793 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1794 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1795 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1796 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1797 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1798 | public void setTo(HistoryItem o) { |
| 1799 | time = o.time; |
| 1800 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1801 | setToCommon(o); |
| 1802 | } |
| 1803 | |
| 1804 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1805 | this.time = time; |
| 1806 | this.cmd = cmd; |
| 1807 | setToCommon(o); |
| 1808 | } |
| 1809 | |
| 1810 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1811 | batteryLevel = o.batteryLevel; |
| 1812 | batteryStatus = o.batteryStatus; |
| 1813 | batteryHealth = o.batteryHealth; |
| 1814 | batteryPlugType = o.batteryPlugType; |
| 1815 | batteryTemperature = o.batteryTemperature; |
| 1816 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1817 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1818 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1819 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1820 | if (o.wakelockTag != null) { |
| 1821 | wakelockTag = localWakelockTag; |
| 1822 | wakelockTag.setTo(o.wakelockTag); |
| 1823 | } else { |
| 1824 | wakelockTag = null; |
| 1825 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1826 | if (o.wakeReasonTag != null) { |
| 1827 | wakeReasonTag = localWakeReasonTag; |
| 1828 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1829 | } else { |
| 1830 | wakeReasonTag = null; |
| 1831 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1832 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1833 | if (o.eventTag != null) { |
| 1834 | eventTag = localEventTag; |
| 1835 | eventTag.setTo(o.eventTag); |
| 1836 | } else { |
| 1837 | eventTag = null; |
| 1838 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1839 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1842 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1843 | return batteryLevel == o.batteryLevel |
| 1844 | && batteryStatus == o.batteryStatus |
| 1845 | && batteryHealth == o.batteryHealth |
| 1846 | && batteryPlugType == o.batteryPlugType |
| 1847 | && batteryTemperature == o.batteryTemperature |
| 1848 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1849 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1850 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1851 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1852 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1853 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1854 | |
| 1855 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1856 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1857 | return false; |
| 1858 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1859 | if (wakelockTag != o.wakelockTag) { |
| 1860 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1861 | return false; |
| 1862 | } |
| 1863 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1864 | return false; |
| 1865 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1866 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1867 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1868 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1869 | return false; |
| 1870 | } |
| 1871 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1872 | return false; |
| 1873 | } |
| 1874 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1875 | if (eventTag != o.eventTag) { |
| 1876 | if (eventTag == null || o.eventTag == null) { |
| 1877 | return false; |
| 1878 | } |
| 1879 | if (!eventTag.equals(o.eventTag)) { |
| 1880 | return false; |
| 1881 | } |
| 1882 | } |
| 1883 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1884 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1885 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1886 | |
| 1887 | public final static class HistoryEventTracker { |
| 1888 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1889 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1890 | |
| 1891 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1892 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1893 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1894 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1895 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1896 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1897 | mActiveEvents[idx] = active; |
| 1898 | } |
| 1899 | SparseIntArray uids = active.get(name); |
| 1900 | if (uids == null) { |
| 1901 | uids = new SparseIntArray(); |
| 1902 | active.put(name, uids); |
| 1903 | } |
| 1904 | if (uids.indexOfKey(uid) >= 0) { |
| 1905 | // Already set, nothing to do! |
| 1906 | return false; |
| 1907 | } |
| 1908 | uids.put(uid, poolIdx); |
| 1909 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1910 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1911 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1912 | if (active == null) { |
| 1913 | // not currently active, nothing to do. |
| 1914 | return false; |
| 1915 | } |
| 1916 | SparseIntArray uids = active.get(name); |
| 1917 | if (uids == null) { |
| 1918 | // not currently active, nothing to do. |
| 1919 | return false; |
| 1920 | } |
| 1921 | idx = uids.indexOfKey(uid); |
| 1922 | if (idx < 0) { |
| 1923 | // not currently active, nothing to do. |
| 1924 | return false; |
| 1925 | } |
| 1926 | uids.removeAt(idx); |
| 1927 | if (uids.size() <= 0) { |
| 1928 | active.remove(name); |
| 1929 | } |
| 1930 | } |
| 1931 | return true; |
| 1932 | } |
| 1933 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1934 | public void removeEvents(int code) { |
| 1935 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1936 | mActiveEvents[idx] = null; |
| 1937 | } |
| 1938 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1939 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1940 | return mActiveEvents[code]; |
| 1941 | } |
| 1942 | } |
| 1943 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1944 | public static final class BitDescription { |
| 1945 | public final int mask; |
| 1946 | public final int shift; |
| 1947 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1948 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1949 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1950 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1951 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1952 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1953 | this.mask = mask; |
| 1954 | this.shift = -1; |
| 1955 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1956 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1957 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1958 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1959 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1960 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1961 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1962 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1963 | this.mask = mask; |
| 1964 | this.shift = shift; |
| 1965 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1966 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1967 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1968 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1969 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1970 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1972 | /** |
| 1973 | * Don't allow any more batching in to the current history event. This |
| 1974 | * is called when printing partial histories, so to ensure that the next |
| 1975 | * history event will go in to a new batch after what was printed in the |
| 1976 | * last partial history. |
| 1977 | */ |
| 1978 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1979 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1980 | public abstract int getHistoryTotalSize(); |
| 1981 | |
| 1982 | public abstract int getHistoryUsedSize(); |
| 1983 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1984 | public abstract boolean startIteratingHistoryLocked(); |
| 1985 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1986 | public abstract int getHistoryStringPoolSize(); |
| 1987 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1988 | public abstract int getHistoryStringPoolBytes(); |
| 1989 | |
| 1990 | public abstract String getHistoryTagPoolString(int index); |
| 1991 | |
| 1992 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1993 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1994 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1995 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1996 | public abstract void finishIteratingHistoryLocked(); |
| 1997 | |
| 1998 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1999 | |
| 2000 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 2001 | |
| 2002 | public abstract void finishIteratingOldHistoryLocked(); |
| 2003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2005 | * Return the base time offset for the battery history. |
| 2006 | */ |
| 2007 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2008 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2009 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | * Returns the number of times the device has been started. |
| 2011 | */ |
| 2012 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2015 | * 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] | 2016 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2017 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | * {@hide} |
| 2019 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2020 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2021 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2022 | /** |
| 2023 | * Returns the number of times the screen was turned on. |
| 2024 | * |
| 2025 | * {@hide} |
| 2026 | */ |
| 2027 | public abstract int getScreenOnCount(int which); |
| 2028 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2029 | /** |
| 2030 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 2031 | * running on battery. |
| 2032 | * |
| 2033 | * {@hide} |
| 2034 | */ |
| 2035 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 2036 | |
| 2037 | /** |
| 2038 | * Returns the number of times the screen was turned dozing. |
| 2039 | * |
| 2040 | * {@hide} |
| 2041 | */ |
| 2042 | public abstract int getScreenDozeCount(int which); |
| 2043 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2044 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 2045 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2046 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 2047 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 2048 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 2049 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 2050 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2051 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2052 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 2053 | "dark", "dim", "medium", "light", "bright" |
| 2054 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2055 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2056 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 2057 | "0", "1", "2", "3", "4" |
| 2058 | }; |
| 2059 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2060 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2061 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2062 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2063 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2064 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2065 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2066 | * {@hide} |
| 2067 | */ |
| 2068 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2069 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2072 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2073 | * |
| 2074 | * {@hide} |
| 2075 | */ |
| 2076 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2077 | |
| 2078 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2079 | * 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] | 2080 | * running on battery. |
| 2081 | * |
| 2082 | * {@hide} |
| 2083 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2084 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2085 | |
| 2086 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2087 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2088 | * |
| 2089 | * {@hide} |
| 2090 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2091 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2092 | |
| 2093 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2094 | * Constant for device idle mode: not active. |
| 2095 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2096 | public static final int DEVICE_IDLE_MODE_OFF = ServerProtoEnums.DEVICE_IDLE_MODE_OFF; // 0 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2097 | |
| 2098 | /** |
| 2099 | * Constant for device idle mode: active in lightweight mode. |
| 2100 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2101 | public static final int DEVICE_IDLE_MODE_LIGHT = ServerProtoEnums.DEVICE_IDLE_MODE_LIGHT; // 1 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2102 | |
| 2103 | /** |
| 2104 | * Constant for device idle mode: active in full mode. |
| 2105 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2106 | public static final int DEVICE_IDLE_MODE_DEEP = ServerProtoEnums.DEVICE_IDLE_MODE_DEEP; // 2 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2107 | |
| 2108 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2109 | * Returns the time in microseconds that device has been in idle mode while |
| 2110 | * running on battery. |
| 2111 | * |
| 2112 | * {@hide} |
| 2113 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2114 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2115 | |
| 2116 | /** |
| 2117 | * Returns the number of times that the devie has gone in to idle mode. |
| 2118 | * |
| 2119 | * {@hide} |
| 2120 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2121 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2122 | |
| 2123 | /** |
| 2124 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2125 | * mode, not in idle maintenance etc). |
| 2126 | */ |
| 2127 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2128 | |
| 2129 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2130 | * 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] | 2131 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2132 | * counts all of the time that we consider the device to be idle, whether or not |
| 2133 | * it is currently in the actual device idle mode. |
| 2134 | * |
| 2135 | * {@hide} |
| 2136 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2137 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2138 | |
| 2139 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2140 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2141 | * |
| 2142 | * {@hide} |
| 2143 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2144 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2145 | |
| 2146 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2147 | * Returns the number of times that connectivity state changed. |
| 2148 | * |
| 2149 | * {@hide} |
| 2150 | */ |
| 2151 | public abstract int getNumConnectivityChange(int which); |
| 2152 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2153 | |
| 2154 | /** |
| 2155 | * Returns the time in microseconds that the phone has been running with |
| 2156 | * the given GPS signal quality level |
| 2157 | * |
| 2158 | * {@hide} |
| 2159 | */ |
| 2160 | public abstract long getGpsSignalQualityTime(int strengthBin, |
| 2161 | long elapsedRealtimeUs, int which); |
| 2162 | |
| 2163 | /** |
| 2164 | * Returns the GPS battery drain in mA-ms |
| 2165 | * |
| 2166 | * {@hide} |
| 2167 | */ |
| 2168 | public abstract long getGpsBatteryDrainMaMs(); |
| 2169 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2170 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2171 | * 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] | 2172 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2173 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | * {@hide} |
| 2175 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2176 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2177 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2178 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2179 | * Returns the number of times a phone call was activated. |
| 2180 | * |
| 2181 | * {@hide} |
| 2182 | */ |
| 2183 | public abstract int getPhoneOnCount(int which); |
| 2184 | |
| 2185 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2186 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2187 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2188 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2189 | * {@hide} |
| 2190 | */ |
| 2191 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2192 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2193 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2194 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2195 | * Returns the time in microseconds that the phone has been trying to |
| 2196 | * acquire a signal. |
| 2197 | * |
| 2198 | * {@hide} |
| 2199 | */ |
| 2200 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2201 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2202 | |
| 2203 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2204 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2205 | * acquire a signal. |
| 2206 | * |
| 2207 | * {@hide} |
| 2208 | */ |
| 2209 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2210 | |
| 2211 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2212 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2213 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2214 | * {@hide} |
| 2215 | */ |
| 2216 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2217 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2218 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2219 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2220 | * counts. |
| 2221 | */ |
| 2222 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2223 | |
| 2224 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2225 | * Returns the time in microseconds that the mobile network has been active |
| 2226 | * (in a high power state). |
| 2227 | * |
| 2228 | * {@hide} |
| 2229 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2230 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2231 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2232 | /** |
| 2233 | * Returns the number of times that the mobile network has transitioned to the |
| 2234 | * active state. |
| 2235 | * |
| 2236 | * {@hide} |
| 2237 | */ |
| 2238 | public abstract int getMobileRadioActiveCount(int which); |
| 2239 | |
| 2240 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2241 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2242 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2243 | * from the radio. |
| 2244 | * |
| 2245 | * {@hide} |
| 2246 | */ |
| 2247 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2248 | |
| 2249 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2250 | * Returns the time in microseconds that the mobile network has been active |
| 2251 | * (in a high power state) but not being able to blame on an app. |
| 2252 | * |
| 2253 | * {@hide} |
| 2254 | */ |
| 2255 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2256 | |
| 2257 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2258 | * 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] | 2259 | * |
| 2260 | * {@hide} |
| 2261 | */ |
| 2262 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2263 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2264 | public static final int DATA_CONNECTION_NONE = 0; |
| 2265 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2266 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2267 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2268 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2269 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2270 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2271 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2272 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2273 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2274 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2275 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2276 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2277 | public static final int DATA_CONNECTION_LTE = 13; |
| 2278 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2279 | public static final int DATA_CONNECTION_HSPAP = 15; |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame] | 2280 | public static final int DATA_CONNECTION_GSM = 16; |
| 2281 | public static final int DATA_CONNECTION_TD_SCDMA = 17; |
| 2282 | public static final int DATA_CONNECTION_IWLAN = 18; |
| 2283 | public static final int DATA_CONNECTION_LTE_CA = 19; |
| 2284 | public static final int DATA_CONNECTION_OTHER = 20; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2285 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2286 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2287 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2288 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame] | 2289 | "ehrpd", "hspap", "gsm", "td_scdma", "iwlan", "lte_ca", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2290 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2291 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2292 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2293 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2294 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2295 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2296 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2297 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2298 | * {@hide} |
| 2299 | */ |
| 2300 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2301 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2304 | * Returns the number of times the phone has entered the given data |
| 2305 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2306 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2307 | * {@hide} |
| 2308 | */ |
| 2309 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2310 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2311 | /** |
| 2312 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2313 | */ |
| 2314 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2315 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2316 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2317 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2318 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2319 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2320 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2321 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2322 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2323 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2324 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2325 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2326 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2327 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2328 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2329 | |
| 2330 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2331 | |
| 2332 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2333 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2334 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2335 | "group-handshake", "completed", "dormant", "uninit" |
| 2336 | }; |
| 2337 | |
| 2338 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2339 | "inv", "dsc", "dis", "inact", "scan", |
| 2340 | "auth", "ascing", "asced", "4-way", |
| 2341 | "group", "compl", "dorm", "uninit" |
| 2342 | }; |
| 2343 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2344 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2345 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2346 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2347 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2348 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2349 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2350 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2351 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2352 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2353 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2354 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2355 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2356 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2357 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2358 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2359 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2360 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2361 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2362 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2363 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2364 | new String[] {"in", "out", "emergency", "off"}, |
| 2365 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2366 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2367 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2368 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2369 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2370 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2371 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2372 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2373 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2374 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2375 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2376 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2377 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2378 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2379 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2380 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2381 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2382 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2383 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2384 | new String[] { "off", "light", "full", "???" }, |
| 2385 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2386 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2387 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2388 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2389 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2390 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2391 | new String[] { "0", "1", "2", "3", "4" }, |
| 2392 | new String[] { "0", "1", "2", "3", "4" }), |
| 2393 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2394 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2395 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2396 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2397 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2398 | new BitDescription(HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG, |
| 2399 | "cellular_high_tx_power", "Chtp"), |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2400 | new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK, |
| 2401 | HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss", |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2402 | new String[] { "poor", "good"}, new String[] { "poor", "good"}) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2403 | }; |
| 2404 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2405 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2406 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2407 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2408 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2409 | }; |
| 2410 | |
| 2411 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2412 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2413 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2414 | "Esw", "Ewa", "Elw", "Eec" |
| 2415 | }; |
| 2416 | |
| 2417 | @FunctionalInterface |
| 2418 | public interface IntToString { |
| 2419 | String applyAsString(int val); |
| 2420 | } |
| 2421 | |
| 2422 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2423 | private static final IntToString sIntToString = Integer::toString; |
| 2424 | |
| 2425 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2426 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2427 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2428 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2429 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2430 | }; |
| 2431 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2432 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2433 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2434 | * Note that this may be different from the sum of per uid timer values. |
| 2435 | * |
| 2436 | * {@hide} |
| 2437 | */ |
| 2438 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2439 | |
| 2440 | /** |
| 2441 | * Returns total time for WiFi Multicast Wakelock timer |
| 2442 | * Note that this may be different from the sum of per uid timer values. |
| 2443 | * |
| 2444 | * {@hide} |
| 2445 | */ |
| 2446 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2447 | |
| 2448 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2449 | * 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] | 2450 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2451 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2452 | * {@hide} |
| 2453 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2454 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2455 | |
| 2456 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2457 | * Returns the time in microseconds that wifi has been active while the device was |
| 2458 | * running on battery. |
| 2459 | * |
| 2460 | * {@hide} |
| 2461 | */ |
| 2462 | public abstract long getWifiActiveTime(long elapsedRealtimeUs, int which); |
| 2463 | |
| 2464 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2465 | * 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] | 2466 | * been in the running state while the device was running on battery. |
| 2467 | * |
| 2468 | * {@hide} |
| 2469 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2470 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2471 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2472 | public static final int WIFI_STATE_OFF = 0; |
| 2473 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2474 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2475 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2476 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2477 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2478 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2479 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2480 | |
| 2481 | static final String[] WIFI_STATE_NAMES = { |
| 2482 | "off", "scanning", "no_net", "disconn", |
| 2483 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2484 | }; |
| 2485 | |
| 2486 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2487 | |
| 2488 | /** |
| 2489 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2490 | * |
| 2491 | * {@hide} |
| 2492 | */ |
| 2493 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2494 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2495 | |
| 2496 | /** |
| 2497 | * Returns the number of times that WiFi has entered the given state. |
| 2498 | * |
| 2499 | * {@hide} |
| 2500 | */ |
| 2501 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2502 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2503 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2504 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2505 | * |
| 2506 | * {@hide} |
| 2507 | */ |
| 2508 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2509 | |
| 2510 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2511 | * Returns the time in microseconds that the wifi supplicant has been |
| 2512 | * in a given state. |
| 2513 | * |
| 2514 | * {@hide} |
| 2515 | */ |
| 2516 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2517 | |
| 2518 | /** |
| 2519 | * Returns the number of times that the wifi supplicant has transitioned |
| 2520 | * to a given state. |
| 2521 | * |
| 2522 | * {@hide} |
| 2523 | */ |
| 2524 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2525 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2526 | /** |
| 2527 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2528 | * |
| 2529 | * {@hide} |
| 2530 | */ |
| 2531 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2532 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2533 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2534 | |
| 2535 | /** |
| 2536 | * Returns the time in microseconds that WIFI has been running with |
| 2537 | * the given signal strength. |
| 2538 | * |
| 2539 | * {@hide} |
| 2540 | */ |
| 2541 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2542 | long elapsedRealtimeUs, int which); |
| 2543 | |
| 2544 | /** |
| 2545 | * Returns the number of times WIFI has entered the given signal strength. |
| 2546 | * |
| 2547 | * {@hide} |
| 2548 | */ |
| 2549 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2550 | |
| 2551 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2552 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2553 | * |
| 2554 | * {@hide} |
| 2555 | */ |
| 2556 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2557 | |
| 2558 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2559 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2560 | * running on battery. |
| 2561 | * |
| 2562 | * {@hide} |
| 2563 | */ |
| 2564 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2565 | |
| 2566 | /** |
| 2567 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2568 | * running on battery. |
| 2569 | * |
| 2570 | * {@hide} |
| 2571 | */ |
| 2572 | public abstract long getFlashlightOnCount(int which); |
| 2573 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2574 | /** |
| 2575 | * Returns the time in microseconds that the camera has been on while the device was |
| 2576 | * running on battery. |
| 2577 | * |
| 2578 | * {@hide} |
| 2579 | */ |
| 2580 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2581 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2582 | /** |
| 2583 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2584 | * on battery. |
| 2585 | * |
| 2586 | * {@hide} |
| 2587 | */ |
| 2588 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2589 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2590 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2591 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2592 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2593 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2594 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2595 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2596 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2597 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2598 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2599 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2600 | 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] | 2601 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2602 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2603 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2604 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2605 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2606 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2607 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2608 | * actual power data. |
| 2609 | */ |
| 2610 | public abstract boolean hasWifiActivityReporting(); |
| 2611 | |
| 2612 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2613 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2614 | * in various radio controller states, such as transmit, receive, and idle. |
| 2615 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2616 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2617 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2618 | |
| 2619 | /** |
| 2620 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2621 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2622 | * actual power data. |
| 2623 | */ |
| 2624 | public abstract boolean hasBluetoothActivityReporting(); |
| 2625 | |
| 2626 | /** |
| 2627 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2628 | * in various radio controller states, such as transmit, receive, and idle. |
| 2629 | * @return non-null {@link ControllerActivityCounter} |
| 2630 | */ |
| 2631 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2632 | |
| 2633 | /** |
| 2634 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2635 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2636 | * actual power data. |
| 2637 | */ |
| 2638 | public abstract boolean hasModemActivityReporting(); |
| 2639 | |
| 2640 | /** |
| 2641 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2642 | * in various radio controller states, such as transmit, receive, and idle. |
| 2643 | * @return non-null {@link ControllerActivityCounter} |
| 2644 | */ |
| 2645 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2646 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2647 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2648 | * Return the wall clock time when battery stats data collection started. |
| 2649 | */ |
| 2650 | public abstract long getStartClockTime(); |
| 2651 | |
| 2652 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2653 | * Return platform version tag that we were running in when the battery stats started. |
| 2654 | */ |
| 2655 | public abstract String getStartPlatformVersion(); |
| 2656 | |
| 2657 | /** |
| 2658 | * Return platform version tag that we were running in when the battery stats ended. |
| 2659 | */ |
| 2660 | public abstract String getEndPlatformVersion(); |
| 2661 | |
| 2662 | /** |
| 2663 | * Return the internal version code of the parcelled format. |
| 2664 | */ |
| 2665 | public abstract int getParcelVersion(); |
| 2666 | |
| 2667 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | * Return whether we are currently running on battery. |
| 2669 | */ |
| 2670 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | /** |
| 2673 | * Returns a SparseArray containing the statistics for each uid. |
| 2674 | */ |
| 2675 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2676 | |
| 2677 | /** |
| 2678 | * Returns the current battery uptime in microseconds. |
| 2679 | * |
| 2680 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2681 | */ |
| 2682 | public abstract long getBatteryUptime(long curTime); |
| 2683 | |
| 2684 | /** |
| 2685 | * Returns the current battery realtime in microseconds. |
| 2686 | * |
| 2687 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2688 | */ |
| 2689 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2690 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2691 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2692 | * 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] | 2693 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2694 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2695 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2696 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2697 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2698 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2699 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2700 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2701 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | |
| 2703 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2704 | * Get the amount the battery has discharged since the stats were |
| 2705 | * last reset after charging, as a lower-end approximation. |
| 2706 | */ |
| 2707 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2708 | |
| 2709 | /** |
| 2710 | * Get the amount the battery has discharged since the stats were |
| 2711 | * last reset after charging, as an upper-end approximation. |
| 2712 | */ |
| 2713 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2714 | |
| 2715 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2716 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2717 | */ |
| 2718 | public abstract int getDischargeAmount(int which); |
| 2719 | |
| 2720 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2721 | * Get the amount the battery has discharged while the screen was on, |
| 2722 | * since the last time power was unplugged. |
| 2723 | */ |
| 2724 | public abstract int getDischargeAmountScreenOn(); |
| 2725 | |
| 2726 | /** |
| 2727 | * Get the amount the battery has discharged while the screen was on, |
| 2728 | * since the last time the device was charged. |
| 2729 | */ |
| 2730 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2731 | |
| 2732 | /** |
| 2733 | * Get the amount the battery has discharged while the screen was off, |
| 2734 | * since the last time power was unplugged. |
| 2735 | */ |
| 2736 | public abstract int getDischargeAmountScreenOff(); |
| 2737 | |
| 2738 | /** |
| 2739 | * Get the amount the battery has discharged while the screen was off, |
| 2740 | * since the last time the device was charged. |
| 2741 | */ |
| 2742 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2743 | |
| 2744 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2745 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2746 | * since the last time power was unplugged. |
| 2747 | */ |
| 2748 | public abstract int getDischargeAmountScreenDoze(); |
| 2749 | |
| 2750 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2751 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2752 | * since the last time the device was charged. |
| 2753 | */ |
| 2754 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2755 | |
| 2756 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | * Returns the total, last, or current battery uptime in microseconds. |
| 2758 | * |
| 2759 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2760 | * @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] | 2761 | */ |
| 2762 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2763 | |
| 2764 | /** |
| 2765 | * Returns the total, last, or current battery realtime in microseconds. |
| 2766 | * |
| 2767 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2768 | * @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] | 2769 | */ |
| 2770 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2771 | |
| 2772 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2773 | * 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] | 2774 | * |
| 2775 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2776 | * @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] | 2777 | */ |
| 2778 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2779 | |
| 2780 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2781 | * 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] | 2782 | * |
| 2783 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2784 | * @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] | 2785 | */ |
| 2786 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2787 | |
| 2788 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | * Returns the total, last, or current uptime in microseconds. |
| 2790 | * |
| 2791 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2792 | * @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] | 2793 | */ |
| 2794 | public abstract long computeUptime(long curTime, int which); |
| 2795 | |
| 2796 | /** |
| 2797 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2798 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2800 | * @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] | 2801 | */ |
| 2802 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2803 | |
| 2804 | /** |
| 2805 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2806 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2807 | * enough current data to make a decision, or the battery is currently |
| 2808 | * charging. |
| 2809 | * |
| 2810 | * @param curTime The current elepsed realtime in microseconds. |
| 2811 | */ |
| 2812 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2813 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2814 | // The part of a step duration that is the actual time. |
| 2815 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2816 | |
| 2817 | // Bits in a step duration that are the new battery level we are at. |
| 2818 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2819 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2820 | |
| 2821 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2822 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2823 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2824 | |
| 2825 | // Bits in a step duration that indicate which modes changed during that step. |
| 2826 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2827 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2828 | |
| 2829 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2830 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2831 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2832 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2833 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2834 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2835 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2836 | // Step duration mode: power save is on. |
| 2837 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2838 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2839 | // Step duration mode: device is currently in idle mode. |
| 2840 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2841 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2842 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2843 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2844 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2845 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2846 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2847 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2848 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2849 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2850 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2851 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2852 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2853 | }; |
| 2854 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2855 | (Display.STATE_OFF-1), |
| 2856 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2857 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2858 | (Display.STATE_ON-1), |
| 2859 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2860 | (Display.STATE_DOZE-1), |
| 2861 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2862 | (Display.STATE_DOZE_SUSPEND-1), |
| 2863 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2864 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2865 | }; |
| 2866 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2867 | "screen off", |
| 2868 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2869 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2870 | "screen on", |
| 2871 | "screen on power save", |
| 2872 | "screen doze", |
| 2873 | "screen doze power save", |
| 2874 | "screen doze-suspend", |
| 2875 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2876 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2877 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2878 | |
| 2879 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2880 | * 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] | 2881 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2882 | * a coulomb counter. |
| 2883 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2884 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2885 | |
| 2886 | /** |
| 2887 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2888 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2889 | * a coulomb counter. |
| 2890 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2891 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2892 | |
| 2893 | /** |
| 2894 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2895 | * non-zero only if the device's battery has a coulomb counter. |
| 2896 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2897 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2898 | |
| 2899 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2900 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2901 | * micro-Ampere-hours. |
| 2902 | */ |
| 2903 | public abstract long getUahDischargeLightDoze(int which); |
| 2904 | |
| 2905 | /** |
| 2906 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2907 | * micro-Ampere-hours. |
| 2908 | */ |
| 2909 | public abstract long getUahDischargeDeepDoze(int which); |
| 2910 | |
| 2911 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2912 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2913 | * declared by the PowerProfile. |
| 2914 | * @return The estimated battery capacity in mAh. |
| 2915 | */ |
| 2916 | public abstract int getEstimatedBatteryCapacity(); |
| 2917 | |
| 2918 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2919 | * @return The minimum learned battery capacity in uAh. |
| 2920 | */ |
| 2921 | public abstract int getMinLearnedBatteryCapacity(); |
| 2922 | |
| 2923 | /** |
| 2924 | * @return The maximum learned battery capacity in uAh. |
| 2925 | */ |
| 2926 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2927 | |
| 2928 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2929 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2930 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2931 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2932 | |
| 2933 | /** |
| 2934 | * Return the array of daily discharge step durations. |
| 2935 | */ |
| 2936 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2937 | |
| 2938 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2939 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2940 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2941 | * enough current data to make a decision, or the battery is currently |
| 2942 | * discharging. |
| 2943 | * |
| 2944 | * @param curTime The current elepsed realtime in microseconds. |
| 2945 | */ |
| 2946 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2947 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2948 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2949 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2950 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2951 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2952 | |
| 2953 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2954 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2955 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2956 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2957 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2958 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2959 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2960 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2961 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2962 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2964 | /** |
| 2965 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2966 | */ |
| 2967 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2968 | /** |
| 2969 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2970 | */ |
| 2971 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2972 | |
| 2973 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2974 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2975 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2976 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2977 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2978 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | long days = seconds / (60 * 60 * 24); |
| 2980 | if (days != 0) { |
| 2981 | out.append(days); |
| 2982 | out.append("d "); |
| 2983 | } |
| 2984 | long used = days * 60 * 60 * 24; |
| 2985 | |
| 2986 | long hours = (seconds - used) / (60 * 60); |
| 2987 | if (hours != 0 || used != 0) { |
| 2988 | out.append(hours); |
| 2989 | out.append("h "); |
| 2990 | } |
| 2991 | used += hours * 60 * 60; |
| 2992 | |
| 2993 | long mins = (seconds-used) / 60; |
| 2994 | if (mins != 0 || used != 0) { |
| 2995 | out.append(mins); |
| 2996 | out.append("m "); |
| 2997 | } |
| 2998 | used += mins * 60; |
| 2999 | |
| 3000 | if (seconds != 0 || used != 0) { |
| 3001 | out.append(seconds-used); |
| 3002 | out.append("s "); |
| 3003 | } |
| 3004 | } |
| 3005 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3006 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3008 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | sb.append(time - (sec * 1000)); |
| 3010 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | } |
| 3012 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3013 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3014 | long sec = time / 1000; |
| 3015 | formatTimeRaw(sb, sec); |
| 3016 | sb.append(time - (sec * 1000)); |
| 3017 | sb.append("ms"); |
| 3018 | } |
| 3019 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3020 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3022 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | } |
| 3024 | float perc = ((float)num) / ((float)den) * 100; |
| 3025 | mFormatBuilder.setLength(0); |
| 3026 | mFormatter.format("%.1f%%", perc); |
| 3027 | return mFormatBuilder.toString(); |
| 3028 | } |
| 3029 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3030 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3031 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3032 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3033 | if (bytes < BYTES_PER_KB) { |
| 3034 | return bytes + "B"; |
| 3035 | } else if (bytes < BYTES_PER_MB) { |
| 3036 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 3037 | return mFormatBuilder.toString(); |
| 3038 | } else if (bytes < BYTES_PER_GB){ |
| 3039 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 3040 | return mFormatBuilder.toString(); |
| 3041 | } else { |
| 3042 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 3043 | return mFormatBuilder.toString(); |
| 3044 | } |
| 3045 | } |
| 3046 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3047 | private static long roundUsToMs(long timeUs) { |
| 3048 | return (timeUs + 500) / 1000; |
| 3049 | } |
| 3050 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3051 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3052 | if (timer != null) { |
| 3053 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3054 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3055 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 3056 | return totalTimeMillis; |
| 3057 | } |
| 3058 | return 0; |
| 3059 | } |
| 3060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | /** |
| 3062 | * |
| 3063 | * @param sb a StringBuilder object. |
| 3064 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3065 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3067 | * @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] | 3068 | * @param linePrefix a String to be prepended to each line of output. |
| 3069 | * @return the line prefix |
| 3070 | */ |
| 3071 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3072 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3075 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3076 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3077 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | if (totalTimeMillis != 0) { |
| 3079 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3080 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3081 | if (name != null) { |
| 3082 | sb.append(name); |
| 3083 | sb.append(' '); |
| 3084 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | sb.append('('); |
| 3086 | sb.append(count); |
| 3087 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3088 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 3089 | if (maxDurationMs >= 0) { |
| 3090 | sb.append(" max="); |
| 3091 | sb.append(maxDurationMs); |
| 3092 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3093 | // Put actual time if it is available and different from totalTimeMillis. |
| 3094 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 3095 | if (totalDurMs > totalTimeMillis) { |
| 3096 | sb.append(" actual="); |
| 3097 | sb.append(totalDurMs); |
| 3098 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3099 | if (timer.isRunningLocked()) { |
| 3100 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3101 | if (currentMs >= 0) { |
| 3102 | sb.append(" (running for "); |
| 3103 | sb.append(currentMs); |
| 3104 | sb.append("ms)"); |
| 3105 | } else { |
| 3106 | sb.append(" (running)"); |
| 3107 | } |
| 3108 | } |
| 3109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | return ", "; |
| 3111 | } |
| 3112 | } |
| 3113 | return linePrefix; |
| 3114 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3115 | |
| 3116 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3117 | * 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] | 3118 | * |
| 3119 | * @param pw a PrintWriter object to print to. |
| 3120 | * @param sb a StringBuilder object. |
| 3121 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3122 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3123 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3124 | * @param prefix a String to be prepended to each line of output. |
| 3125 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3126 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3127 | */ |
| 3128 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3129 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3130 | if (timer != null) { |
| 3131 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3132 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3133 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3134 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3135 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3136 | sb.setLength(0); |
| 3137 | sb.append(prefix); |
| 3138 | sb.append(" "); |
| 3139 | sb.append(type); |
| 3140 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3141 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3142 | sb.append("realtime ("); |
| 3143 | sb.append(count); |
| 3144 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3145 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3146 | if (maxDurationMs >= 0) { |
| 3147 | sb.append(" max="); |
| 3148 | sb.append(maxDurationMs); |
| 3149 | } |
| 3150 | if (timer.isRunningLocked()) { |
| 3151 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3152 | if (currentMs >= 0) { |
| 3153 | sb.append(" (running for "); |
| 3154 | sb.append(currentMs); |
| 3155 | sb.append("ms)"); |
| 3156 | } else { |
| 3157 | sb.append(" (running)"); |
| 3158 | } |
| 3159 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3160 | pw.println(sb.toString()); |
| 3161 | return true; |
| 3162 | } |
| 3163 | } |
| 3164 | return false; |
| 3165 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | /** |
| 3168 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3169 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | * @param sb a StringBuilder object. |
| 3171 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3172 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3174 | * @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] | 3175 | * @param linePrefix a String to be prepended to each line of output. |
| 3176 | * @return the line prefix |
| 3177 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3178 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3179 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | long totalTimeMicros = 0; |
| 3181 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3182 | long max = 0; |
| 3183 | long current = 0; |
| 3184 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3186 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3187 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3188 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3189 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3190 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3191 | } |
| 3192 | sb.append(linePrefix); |
| 3193 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3194 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3195 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3197 | sb.append(','); |
| 3198 | sb.append(current); |
| 3199 | sb.append(','); |
| 3200 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3201 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3202 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3203 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3204 | if (name != null) { |
| 3205 | sb.append(','); |
| 3206 | sb.append(totalDuration); |
| 3207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | return ","; |
| 3209 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3210 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3211 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3212 | String type) { |
| 3213 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3214 | pw.print(','); |
| 3215 | pw.print(uid); |
| 3216 | pw.print(','); |
| 3217 | pw.print(category); |
| 3218 | pw.print(','); |
| 3219 | pw.print(type); |
| 3220 | } |
| 3221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | /** |
| 3223 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3224 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | * @param pw the PageWriter to dump log to |
| 3226 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3227 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3228 | * @param args type-dependent data arguments |
| 3229 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3230 | 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] | 3231 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3232 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3233 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3234 | pw.print(','); |
| 3235 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3237 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3239 | |
| 3240 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3241 | * Dump a given timer stat for terse checkin mode. |
| 3242 | * |
| 3243 | * @param pw the PageWriter to dump log to |
| 3244 | * @param uid the UID to log |
| 3245 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3246 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3247 | * @param timer a {@link Timer} to dump stats for |
| 3248 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3249 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3250 | */ |
| 3251 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3252 | Timer timer, long rawRealtime, int which) { |
| 3253 | if (timer != null) { |
| 3254 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3255 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3256 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3257 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3258 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3259 | } |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3264 | * Dump a given timer stat to the proto stream. |
| 3265 | * |
| 3266 | * @param proto the ProtoOutputStream to log to |
| 3267 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3268 | * @param timer a {@link Timer} to dump stats for |
| 3269 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3270 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3271 | */ |
| 3272 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3273 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3274 | if (timer == null) { |
| 3275 | return; |
| 3276 | } |
| 3277 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3278 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3279 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3280 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3281 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3282 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3283 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3284 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3285 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3286 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3287 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3288 | // These values will be -1 for timers that don't implement the functionality. |
| 3289 | if (maxDurationMs != -1) { |
| 3290 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3291 | } |
| 3292 | if (curDurationMs != -1) { |
| 3293 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3294 | } |
| 3295 | if (totalDurationMs != -1) { |
| 3296 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3297 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3298 | proto.end(token); |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3303 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3304 | */ |
| 3305 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3306 | if (counter == null) { |
| 3307 | return false; |
| 3308 | } |
| 3309 | |
| 3310 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3311 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3312 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3313 | return true; |
| 3314 | } |
| 3315 | |
| 3316 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3317 | if (c.getCountLocked(which) != 0) { |
| 3318 | return true; |
| 3319 | } |
| 3320 | } |
| 3321 | return false; |
| 3322 | } |
| 3323 | |
| 3324 | /** |
| 3325 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3326 | * The order of the arguments in the final check in line is: |
| 3327 | * |
| 3328 | * idle, rx, power, tx... |
| 3329 | * |
| 3330 | * where tx... is one or more transmit level times. |
| 3331 | */ |
| 3332 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3333 | String type, |
| 3334 | ControllerActivityCounter counter, |
| 3335 | int which) { |
| 3336 | if (!controllerActivityHasData(counter, which)) { |
| 3337 | return; |
| 3338 | } |
| 3339 | |
| 3340 | dumpLineHeader(pw, uid, category, type); |
| 3341 | pw.print(","); |
| 3342 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3343 | pw.print(","); |
| 3344 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3345 | pw.print(","); |
| 3346 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3347 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3348 | pw.print(","); |
| 3349 | pw.print(c.getCountLocked(which)); |
| 3350 | } |
| 3351 | pw.println(); |
| 3352 | } |
| 3353 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3354 | /** |
| 3355 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3356 | */ |
| 3357 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3358 | ControllerActivityCounter counter, |
| 3359 | int which) { |
| 3360 | if (!controllerActivityHasData(counter, which)) { |
| 3361 | return; |
| 3362 | } |
| 3363 | |
| 3364 | final long cToken = proto.start(fieldId); |
| 3365 | |
| 3366 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3367 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3368 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3369 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3370 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3371 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3372 | |
| 3373 | long tToken; |
| 3374 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3375 | for (int i = 0; i < txCounters.length; ++i) { |
| 3376 | LongCounter c = txCounters[i]; |
| 3377 | tToken = proto.start(ControllerActivityProto.TX); |
| 3378 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3379 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3380 | proto.end(tToken); |
| 3381 | } |
| 3382 | |
| 3383 | proto.end(cToken); |
| 3384 | } |
| 3385 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3386 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3387 | String prefix, String controllerName, |
| 3388 | ControllerActivityCounter counter, |
| 3389 | int which) { |
| 3390 | if (controllerActivityHasData(counter, which)) { |
| 3391 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3396 | String controllerName, |
| 3397 | ControllerActivityCounter counter, int which) { |
| 3398 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3399 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3400 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3401 | // Battery real time |
| 3402 | final long totalControllerActivityTimeMs |
| 3403 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3404 | long totalTxTimeMs = 0; |
| 3405 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3406 | totalTxTimeMs += txState.getCountLocked(which); |
| 3407 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3408 | final long sleepTimeMs |
| 3409 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3410 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3411 | if (controllerName.equals(WIFI_CONTROLLER_NAME)) { |
| 3412 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 3413 | sb.setLength(0); |
| 3414 | sb.append(prefix); |
| 3415 | sb.append(" "); |
| 3416 | sb.append(controllerName); |
| 3417 | sb.append(" Scan time: "); |
| 3418 | formatTimeMs(sb, scanTimeMs); |
| 3419 | sb.append("("); |
| 3420 | sb.append(formatRatioLocked(scanTimeMs, totalControllerActivityTimeMs)); |
| 3421 | sb.append(")"); |
| 3422 | pw.println(sb.toString()); |
| 3423 | } |
| 3424 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3425 | sb.setLength(0); |
| 3426 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3427 | sb.append(" "); |
| 3428 | sb.append(controllerName); |
| 3429 | sb.append(" Sleep time: "); |
| 3430 | formatTimeMs(sb, sleepTimeMs); |
| 3431 | sb.append("("); |
| 3432 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3433 | sb.append(")"); |
| 3434 | pw.println(sb.toString()); |
| 3435 | |
| 3436 | sb.setLength(0); |
| 3437 | sb.append(prefix); |
| 3438 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3439 | sb.append(controllerName); |
| 3440 | sb.append(" Idle time: "); |
| 3441 | formatTimeMs(sb, idleTimeMs); |
| 3442 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3443 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3444 | sb.append(")"); |
| 3445 | pw.println(sb.toString()); |
| 3446 | |
| 3447 | sb.setLength(0); |
| 3448 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3449 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3450 | sb.append(controllerName); |
| 3451 | sb.append(" Rx time: "); |
| 3452 | formatTimeMs(sb, rxTimeMs); |
| 3453 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3454 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3455 | sb.append(")"); |
| 3456 | pw.println(sb.toString()); |
| 3457 | |
| 3458 | sb.setLength(0); |
| 3459 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3460 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3461 | sb.append(controllerName); |
| 3462 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3463 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3464 | String [] powerLevel; |
| 3465 | switch(controllerName) { |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3466 | case CELLULAR_CONTROLLER_NAME: |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3467 | powerLevel = new String[] { |
| 3468 | " less than 0dBm: ", |
| 3469 | " 0dBm to 8dBm: ", |
| 3470 | " 8dBm to 15dBm: ", |
| 3471 | " 15dBm to 20dBm: ", |
| 3472 | " above 20dBm: "}; |
| 3473 | break; |
| 3474 | default: |
| 3475 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3476 | break; |
| 3477 | } |
| 3478 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3479 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3480 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3481 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3482 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3483 | sb.setLength(0); |
| 3484 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3485 | sb.append(" "); |
| 3486 | sb.append(powerLevel[lvl]); |
| 3487 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3488 | formatTimeMs(sb, txLvlTimeMs); |
| 3489 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3490 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3491 | sb.append(")"); |
| 3492 | pw.println(sb.toString()); |
| 3493 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3494 | } else { |
| 3495 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3496 | formatTimeMs(sb, txLvlTimeMs); |
| 3497 | sb.append("("); |
| 3498 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3499 | sb.append(")"); |
| 3500 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3501 | } |
| 3502 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3503 | if (powerDrainMaMs > 0) { |
| 3504 | sb.setLength(0); |
| 3505 | sb.append(prefix); |
| 3506 | sb.append(" "); |
| 3507 | sb.append(controllerName); |
| 3508 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3509 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3510 | sb.append("mAh"); |
| 3511 | pw.println(sb.toString()); |
| 3512 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3516 | * Temporary for settings. |
| 3517 | */ |
| 3518 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3519 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3520 | } |
| 3521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | /** |
| 3523 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3524 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3525 | * 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] | 3526 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3527 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3528 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3530 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3531 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3534 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3535 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3536 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3537 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3539 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3540 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3541 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3542 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3543 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3544 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3545 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3546 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3547 | rawRealtime, which); |
| 3548 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3549 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3550 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3551 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3552 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3553 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3554 | final long dischargeCount = getUahDischarge(which); |
| 3555 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3556 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3557 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3558 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3559 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3560 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3561 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3562 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3563 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3564 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3565 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3567 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3568 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3569 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3570 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3571 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3572 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3573 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3574 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3575 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3576 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3577 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3578 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3579 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3580 | long fullWakeLockTimeTotal = 0; |
| 3581 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3582 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3583 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3584 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3585 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3586 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3587 | = u.getWakelockStats(); |
| 3588 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3589 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3590 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3591 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3592 | if (fullWakeTimer != null) { |
| 3593 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3594 | which); |
| 3595 | } |
| 3596 | |
| 3597 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3598 | if (partialWakeTimer != null) { |
| 3599 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3600 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3604 | |
| 3605 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3606 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3607 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3608 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3609 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3610 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3611 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3612 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3613 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3614 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3615 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3616 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3617 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3618 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3619 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3620 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3621 | // Dump Modem controller stats |
| 3622 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3623 | getModemControllerActivity(), which); |
| 3624 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3625 | // Dump Wifi controller stats |
| 3626 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3627 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3628 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3629 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3630 | |
| 3631 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3632 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3633 | |
| 3634 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3635 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3636 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | // Dump misc stats |
| 3639 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3640 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3641 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3642 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3643 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3644 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3645 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3646 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3647 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3648 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3649 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3650 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3651 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3652 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3653 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3654 | // Dump screen brightness stats |
| 3655 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3656 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3657 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3658 | } |
| 3659 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3660 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3661 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3662 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3663 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3664 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3665 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3666 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3667 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3668 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3669 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3670 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3671 | } |
| 3672 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3673 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3674 | // Dump network type stats |
| 3675 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3676 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3677 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3678 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3679 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3680 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3681 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3682 | } |
| 3683 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3684 | |
| 3685 | // Dump wifi state stats |
| 3686 | args = new Object[NUM_WIFI_STATES]; |
| 3687 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3688 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3689 | } |
| 3690 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3691 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3692 | args[i] = getWifiStateCount(i, which); |
| 3693 | } |
| 3694 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3695 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3696 | // Dump wifi suppl state stats |
| 3697 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3698 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3699 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3700 | } |
| 3701 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3702 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3703 | args[i] = getWifiSupplStateCount(i, which); |
| 3704 | } |
| 3705 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3706 | |
| 3707 | // Dump wifi signal strength stats |
| 3708 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3709 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3710 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3711 | } |
| 3712 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3713 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3714 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3715 | } |
| 3716 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3717 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3718 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3719 | final long multicastWakeLockTimeTotalMicros = |
| 3720 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3721 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3722 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3723 | multicastWakeLockTimeTotalMicros / 1000, |
| 3724 | multicastWakeLockCountTotal); |
| 3725 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3726 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3727 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3728 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3729 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3730 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3731 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3732 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3733 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3734 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3735 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3736 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3737 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3738 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3739 | } else { |
| 3740 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3741 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3742 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3743 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3744 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3745 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3746 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3747 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3748 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3749 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3750 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3751 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3752 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3753 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3754 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3755 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3756 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3757 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3758 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3759 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3760 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3761 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3762 | // Not doing the regular wake lock formatting to remain compatible |
| 3763 | // with the old checkin format. |
| 3764 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3765 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3766 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3767 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3768 | } |
| 3769 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3770 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3771 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3772 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3773 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3774 | if (rpmStats.size() > 0) { |
| 3775 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3776 | sb.setLength(0); |
| 3777 | Timer totalTimer = ent.getValue(); |
| 3778 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3779 | int count = totalTimer.getCountLocked(which); |
| 3780 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3781 | long screenOffTimeMs = screenOffTimer != null |
| 3782 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3783 | int screenOffCount = screenOffTimer != null |
| 3784 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3785 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3786 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3787 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3788 | screenOffCount); |
| 3789 | } else { |
| 3790 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3791 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3792 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3793 | } |
| 3794 | } |
| 3795 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3796 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3797 | helper.create(this); |
| 3798 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3799 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3800 | if (sippers != null && sippers.size() > 0) { |
| 3801 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3802 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3803 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3804 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3805 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3806 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3807 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3808 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3809 | String label; |
| 3810 | switch (bs.drainType) { |
| 3811 | case IDLE: |
| 3812 | label="idle"; |
| 3813 | break; |
| 3814 | case CELL: |
| 3815 | label="cell"; |
| 3816 | break; |
| 3817 | case PHONE: |
| 3818 | label="phone"; |
| 3819 | break; |
| 3820 | case WIFI: |
| 3821 | label="wifi"; |
| 3822 | break; |
| 3823 | case BLUETOOTH: |
| 3824 | label="blue"; |
| 3825 | break; |
| 3826 | case SCREEN: |
| 3827 | label="scrn"; |
| 3828 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3829 | case FLASHLIGHT: |
| 3830 | label="flashlight"; |
| 3831 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3832 | case APP: |
| 3833 | uid = bs.uidObj.getUid(); |
| 3834 | label = "uid"; |
| 3835 | break; |
| 3836 | case USER: |
| 3837 | uid = UserHandle.getUid(bs.userId, 0); |
| 3838 | label = "user"; |
| 3839 | break; |
| 3840 | case UNACCOUNTED: |
| 3841 | label = "unacc"; |
| 3842 | break; |
| 3843 | case OVERCOUNTED: |
| 3844 | label = "over"; |
| 3845 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3846 | case CAMERA: |
| 3847 | label = "camera"; |
| 3848 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3849 | case MEMORY: |
| 3850 | label = "memory"; |
| 3851 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3852 | default: |
| 3853 | label = "???"; |
| 3854 | } |
| 3855 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3856 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3857 | bs.shouldHide ? 1 : 0, |
| 3858 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3859 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3863 | final long[] cpuFreqs = getCpuFreqs(); |
| 3864 | if (cpuFreqs != null) { |
| 3865 | sb.setLength(0); |
| 3866 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3867 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3868 | } |
| 3869 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3870 | } |
| 3871 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3872 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | for (int iu = 0; iu < NU; iu++) { |
| 3874 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3875 | if (reqUid >= 0 && uid != reqUid) { |
| 3876 | continue; |
| 3877 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3878 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3881 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3882 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3883 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3884 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3885 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3886 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3887 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3888 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3889 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3890 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3891 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3892 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3893 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3894 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3895 | // Background data transfers |
| 3896 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3897 | which); |
| 3898 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3899 | which); |
| 3900 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3901 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3902 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3903 | which); |
| 3904 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3905 | which); |
| 3906 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3907 | which); |
| 3908 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3909 | which); |
| 3910 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3911 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3912 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3913 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3914 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3915 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3916 | || wifiBytesBgTx > 0 |
| 3917 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3918 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3919 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3920 | wifiBytesRx, wifiBytesTx, |
| 3921 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3922 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3923 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3924 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3925 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3926 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3927 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3930 | // Dump modem controller data, per UID. |
| 3931 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3932 | u.getModemControllerActivity(), which); |
| 3933 | |
| 3934 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3935 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3936 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3937 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3938 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3939 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3940 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3941 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3942 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3943 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3944 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3945 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3946 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3947 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3948 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3949 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3950 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3951 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3953 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3954 | u.getWifiControllerActivity(), which); |
| 3955 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3956 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3957 | if (bleTimer != null) { |
| 3958 | // Convert from microseconds to milliseconds with rounding |
| 3959 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3960 | / 1000; |
| 3961 | if (totalTime != 0) { |
| 3962 | final int count = bleTimer.getCountLocked(which); |
| 3963 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3964 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3965 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3966 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3967 | final long actualTimeBg = bleTimerBg != null ? |
| 3968 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3969 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3970 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3971 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3972 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3973 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3974 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3975 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3976 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3977 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3978 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3979 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3980 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3981 | final Timer unoptimizedScanTimerBg = |
| 3982 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3983 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3984 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3985 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3986 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3987 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3988 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3989 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3990 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3991 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3992 | } |
| 3993 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3994 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3995 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3996 | u.getBluetoothControllerActivity(), which); |
| 3997 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3998 | if (u.hasUserActivity()) { |
| 3999 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 4000 | boolean hasData = false; |
| 4001 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 4002 | int val = u.getUserActivityCount(i, which); |
| 4003 | args[i] = val; |
| 4004 | if (val != 0) hasData = true; |
| 4005 | } |
| 4006 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 4007 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4008 | } |
| 4009 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4010 | |
| 4011 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 4012 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4013 | // Times are since reset (regardless of 'which') |
| 4014 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4015 | final Timer bgTimer = timer.getSubTimer(); |
| 4016 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4017 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4018 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 4019 | } |
| 4020 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4021 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 4022 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4023 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4024 | String linePrefix = ""; |
| 4025 | sb.setLength(0); |
| 4026 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 4027 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4028 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4029 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4030 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4031 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 4032 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4033 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4034 | rawRealtime, "w", which, linePrefix); |
| 4035 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 4036 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4037 | if (sb.length() > 0) { |
| 4038 | String name = wakelocks.keyAt(iw); |
| 4039 | if (name.indexOf(',') >= 0) { |
| 4040 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4041 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 4042 | if (name.indexOf('\n') >= 0) { |
| 4043 | name = name.replace('\n', '_'); |
| 4044 | } |
| 4045 | if (name.indexOf('\r') >= 0) { |
| 4046 | name = name.replace('\r', '_'); |
| 4047 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4048 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | } |
| 4050 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4051 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4052 | // WiFi Multicast Wakelock Statistics |
| 4053 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 4054 | if (mcTimer != null) { |
| 4055 | final long totalMcWakelockTimeMs = |
| 4056 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 4057 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 4058 | if(totalMcWakelockTimeMs > 0) { |
| 4059 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 4060 | totalMcWakelockTimeMs, countMcWakelock); |
| 4061 | } |
| 4062 | } |
| 4063 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4064 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4065 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4066 | final Timer timer = syncs.valueAt(isy); |
| 4067 | // Convert from microseconds to milliseconds with rounding |
| 4068 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4069 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4070 | final Timer bgTimer = timer.getSubTimer(); |
| 4071 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4072 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4073 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4074 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4075 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4076 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4077 | } |
| 4078 | } |
| 4079 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4080 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4081 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4082 | final Timer timer = jobs.valueAt(ij); |
| 4083 | // Convert from microseconds to milliseconds with rounding |
| 4084 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4085 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4086 | final Timer bgTimer = timer.getSubTimer(); |
| 4087 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4088 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4089 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4090 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4091 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4092 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4093 | } |
| 4094 | } |
| 4095 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4096 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 4097 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 4098 | SparseIntArray types = completions.valueAt(ic); |
| 4099 | if (types != null) { |
| 4100 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 4101 | "\"" + completions.keyAt(ic) + "\"", |
| 4102 | types.get(JobParameters.REASON_CANCELED, 0), |
| 4103 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 4104 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 4105 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 4106 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 4107 | } |
| 4108 | } |
| 4109 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame^] | 4110 | // Dump deferred jobs stats |
| 4111 | u.getDeferredJobsCheckinLineLocked(sb, which); |
| 4112 | if (sb.length() > 0) { |
| 4113 | dumpLine(pw, uid, category, JOBS_DEFERRED_DATA, sb.toString()); |
| 4114 | } |
| 4115 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4116 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 4117 | rawRealtime, which); |
| 4118 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4119 | rawRealtime, which); |
| 4120 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4121 | rawRealtime, which); |
| 4122 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4123 | rawRealtime, which); |
| 4124 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4125 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4126 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4127 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4128 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4129 | final int sensorNumber = sensors.keyAt(ise); |
| 4130 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4131 | if (timer != null) { |
| 4132 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4133 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4134 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4135 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4136 | final int count = timer.getCountLocked(which); |
| 4137 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4138 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4139 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4140 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4141 | final long bgActualTime = bgTimer != null ? |
| 4142 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4143 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4144 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4149 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4150 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4151 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4152 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4153 | rawRealtime, which); |
| 4154 | |
| 4155 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4156 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4157 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4158 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4159 | long totalStateTime = 0; |
| 4160 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4161 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4162 | totalStateTime += time; |
| 4163 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4164 | } |
| 4165 | if (totalStateTime > 0) { |
| 4166 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4167 | } |
| 4168 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4169 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4170 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4171 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4172 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4173 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4176 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4177 | if (cpuFreqs != null) { |
| 4178 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4179 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4180 | // screenOffCpuFreqTimes. |
| 4181 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4182 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4183 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4184 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4185 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4186 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4187 | if (screenOffCpuFreqTimeMs != null) { |
| 4188 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4189 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4190 | } |
| 4191 | } else { |
| 4192 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4193 | sb.append(",0"); |
| 4194 | } |
| 4195 | } |
| 4196 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4197 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4198 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4199 | |
| 4200 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4201 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4202 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4203 | sb.setLength(0); |
| 4204 | for (int i = 0; i < timesMs.length; ++i) { |
| 4205 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4206 | } |
| 4207 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4208 | which, procState); |
| 4209 | if (screenOffTimesMs != null) { |
| 4210 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4211 | sb.append("," + screenOffTimesMs[i]); |
| 4212 | } |
| 4213 | } else { |
| 4214 | for (int i = 0; i < timesMs.length; ++i) { |
| 4215 | sb.append(",0"); |
| 4216 | } |
| 4217 | } |
| 4218 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4219 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4220 | } |
| 4221 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4224 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4225 | = u.getProcessStats(); |
| 4226 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4227 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4228 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4229 | final long userMillis = ps.getUserTime(which); |
| 4230 | final long systemMillis = ps.getSystemTime(which); |
| 4231 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4232 | final int starts = ps.getStarts(which); |
| 4233 | final int numCrashes = ps.getNumCrashes(which); |
| 4234 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4235 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4236 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4237 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4238 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4239 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
| 4241 | } |
| 4242 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4243 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4244 | = u.getPackageStats(); |
| 4245 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4246 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4247 | int wakeups = 0; |
| 4248 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4249 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4250 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4251 | wakeups += count; |
| 4252 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4253 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4254 | } |
| 4255 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4256 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4257 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4258 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4259 | final int starts = ss.getStarts(which); |
| 4260 | final int launches = ss.getLaunches(which); |
| 4261 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4262 | dumpLine(pw, uid, category, APK_DATA, |
| 4263 | wakeups, // wakeup alarms |
| 4264 | packageStats.keyAt(ipkg), // Apk |
| 4265 | serviceStats.keyAt(isvc), // service |
| 4266 | startTime / 1000, // time spent started, in ms |
| 4267 | starts, |
| 4268 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | } |
| 4270 | } |
| 4271 | } |
| 4272 | } |
| 4273 | } |
| 4274 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4275 | static final class TimerEntry { |
| 4276 | final String mName; |
| 4277 | final int mId; |
| 4278 | final BatteryStats.Timer mTimer; |
| 4279 | final long mTime; |
| 4280 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4281 | mName = name; |
| 4282 | mId = id; |
| 4283 | mTimer = timer; |
| 4284 | mTime = time; |
| 4285 | } |
| 4286 | } |
| 4287 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4288 | private void printmAh(PrintWriter printer, double power) { |
| 4289 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4290 | } |
| 4291 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4292 | private void printmAh(StringBuilder sb, double power) { |
| 4293 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4294 | } |
| 4295 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4296 | /** |
| 4297 | * Temporary for settings. |
| 4298 | */ |
| 4299 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4300 | int reqUid) { |
| 4301 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4302 | } |
| 4303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4305 | 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] | 4306 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4308 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4309 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | |
| 4312 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4313 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4314 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4315 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4316 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4317 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4318 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4319 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4320 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4321 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4322 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4323 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4324 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4325 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4326 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4328 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4329 | if (estimatedBatteryCapacity > 0) { |
| 4330 | sb.setLength(0); |
| 4331 | sb.append(prefix); |
| 4332 | sb.append(" Estimated battery capacity: "); |
| 4333 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4334 | sb.append(" mAh"); |
| 4335 | pw.println(sb.toString()); |
| 4336 | } |
| 4337 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4338 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4339 | if (minLearnedBatteryCapacity > 0) { |
| 4340 | sb.setLength(0); |
| 4341 | sb.append(prefix); |
| 4342 | sb.append(" Min learned battery capacity: "); |
| 4343 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4344 | sb.append(" mAh"); |
| 4345 | pw.println(sb.toString()); |
| 4346 | } |
| 4347 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4348 | if (maxLearnedBatteryCapacity > 0) { |
| 4349 | sb.setLength(0); |
| 4350 | sb.append(prefix); |
| 4351 | sb.append(" Max learned battery capacity: "); |
| 4352 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4353 | sb.append(" mAh"); |
| 4354 | pw.println(sb.toString()); |
| 4355 | } |
| 4356 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4357 | sb.setLength(0); |
| 4358 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4359 | sb.append(" Time on battery: "); |
| 4360 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4361 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4362 | sb.append(") realtime, "); |
| 4363 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4364 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4365 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4366 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4367 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4368 | sb.setLength(0); |
| 4369 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4370 | sb.append(" Time on battery screen off: "); |
| 4371 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4372 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4373 | sb.append(") realtime, "); |
| 4374 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4375 | sb.append("("); |
| 4376 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4377 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4378 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4379 | |
| 4380 | sb.setLength(0); |
| 4381 | sb.append(prefix); |
| 4382 | sb.append(" Time on battery screen doze: "); |
| 4383 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4384 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4385 | sb.append(")"); |
| 4386 | pw.println(sb.toString()); |
| 4387 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4388 | sb.setLength(0); |
| 4389 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4390 | sb.append(" Total run time: "); |
| 4391 | formatTimeMs(sb, totalRealtime / 1000); |
| 4392 | sb.append("realtime, "); |
| 4393 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4394 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4395 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4396 | if (batteryTimeRemaining >= 0) { |
| 4397 | sb.setLength(0); |
| 4398 | sb.append(prefix); |
| 4399 | sb.append(" Battery time remaining: "); |
| 4400 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4401 | pw.println(sb.toString()); |
| 4402 | } |
| 4403 | if (chargeTimeRemaining >= 0) { |
| 4404 | sb.setLength(0); |
| 4405 | sb.append(prefix); |
| 4406 | sb.append(" Charge time remaining: "); |
| 4407 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4408 | pw.println(sb.toString()); |
| 4409 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4410 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4411 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4412 | if (dischargeCount >= 0) { |
| 4413 | sb.setLength(0); |
| 4414 | sb.append(prefix); |
| 4415 | sb.append(" Discharge: "); |
| 4416 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4417 | sb.append(" mAh"); |
| 4418 | pw.println(sb.toString()); |
| 4419 | } |
| 4420 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4421 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4422 | if (dischargeScreenOffCount >= 0) { |
| 4423 | sb.setLength(0); |
| 4424 | sb.append(prefix); |
| 4425 | sb.append(" Screen off discharge: "); |
| 4426 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4427 | sb.append(" mAh"); |
| 4428 | pw.println(sb.toString()); |
| 4429 | } |
| 4430 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4431 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4432 | if (dischargeScreenDozeCount >= 0) { |
| 4433 | sb.setLength(0); |
| 4434 | sb.append(prefix); |
| 4435 | sb.append(" Screen doze discharge: "); |
| 4436 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4437 | sb.append(" mAh"); |
| 4438 | pw.println(sb.toString()); |
| 4439 | } |
| 4440 | |
| 4441 | final long dischargeScreenOnCount = |
| 4442 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4443 | if (dischargeScreenOnCount >= 0) { |
| 4444 | sb.setLength(0); |
| 4445 | sb.append(prefix); |
| 4446 | sb.append(" Screen on discharge: "); |
| 4447 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4448 | sb.append(" mAh"); |
| 4449 | pw.println(sb.toString()); |
| 4450 | } |
| 4451 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4452 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4453 | if (dischargeLightDozeCount >= 0) { |
| 4454 | sb.setLength(0); |
| 4455 | sb.append(prefix); |
| 4456 | sb.append(" Device light doze discharge: "); |
| 4457 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4458 | sb.append(" mAh"); |
| 4459 | pw.println(sb.toString()); |
| 4460 | } |
| 4461 | |
| 4462 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4463 | if (dischargeDeepDozeCount >= 0) { |
| 4464 | sb.setLength(0); |
| 4465 | sb.append(prefix); |
| 4466 | sb.append(" Device deep doze discharge: "); |
| 4467 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4468 | sb.append(" mAh"); |
| 4469 | pw.println(sb.toString()); |
| 4470 | } |
| 4471 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4472 | pw.print(" Start clock time: "); |
| 4473 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4474 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4475 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4476 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4477 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4478 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4479 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4480 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4481 | rawRealtime, which); |
| 4482 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4483 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4484 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4485 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4486 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4487 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4488 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4489 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4490 | sb.append(prefix); |
| 4491 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4492 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4493 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4494 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4495 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4496 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4497 | pw.println(sb.toString()); |
| 4498 | sb.setLength(0); |
| 4499 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4500 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4501 | boolean didOne = false; |
| 4502 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4503 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4504 | if (time == 0) { |
| 4505 | continue; |
| 4506 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4507 | sb.append("\n "); |
| 4508 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4509 | didOne = true; |
| 4510 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4511 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4512 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4513 | sb.append("("); |
| 4514 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4515 | sb.append(")"); |
| 4516 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4517 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4518 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4519 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4520 | sb.setLength(0); |
| 4521 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4522 | sb.append(" Power save mode enabled: "); |
| 4523 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4524 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4525 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4526 | sb.append(")"); |
| 4527 | pw.println(sb.toString()); |
| 4528 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4529 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4530 | sb.setLength(0); |
| 4531 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4532 | sb.append(" Device light idling: "); |
| 4533 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4534 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4535 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4536 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4537 | sb.append("x"); |
| 4538 | pw.println(sb.toString()); |
| 4539 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4540 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4541 | sb.setLength(0); |
| 4542 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4543 | sb.append(" Idle mode light time: "); |
| 4544 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4545 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4546 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4547 | sb.append(") "); |
| 4548 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4549 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4550 | sb.append(" -- longest "); |
| 4551 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4552 | pw.println(sb.toString()); |
| 4553 | } |
| 4554 | if (deviceIdlingTime != 0) { |
| 4555 | sb.setLength(0); |
| 4556 | sb.append(prefix); |
| 4557 | sb.append(" Device full idling: "); |
| 4558 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4559 | sb.append("("); |
| 4560 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4561 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4562 | sb.append("x"); |
| 4563 | pw.println(sb.toString()); |
| 4564 | } |
| 4565 | if (deviceIdleModeFullTime != 0) { |
| 4566 | sb.setLength(0); |
| 4567 | sb.append(prefix); |
| 4568 | sb.append(" Idle mode full time: "); |
| 4569 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4570 | sb.append("("); |
| 4571 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4572 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4573 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4574 | sb.append("x"); |
| 4575 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4576 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4577 | pw.println(sb.toString()); |
| 4578 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4579 | if (phoneOnTime != 0) { |
| 4580 | sb.setLength(0); |
| 4581 | sb.append(prefix); |
| 4582 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4583 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4584 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4585 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4586 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4587 | if (connChanges != 0) { |
| 4588 | pw.print(prefix); |
| 4589 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4590 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4591 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4592 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4593 | long fullWakeLockTimeTotalMicros = 0; |
| 4594 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4595 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4596 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4597 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4598 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4599 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4600 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4601 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4602 | = u.getWakelockStats(); |
| 4603 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4604 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4605 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4606 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4607 | if (fullWakeTimer != null) { |
| 4608 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4609 | rawRealtime, which); |
| 4610 | } |
| 4611 | |
| 4612 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4613 | if (partialWakeTimer != null) { |
| 4614 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4615 | rawRealtime, which); |
| 4616 | if (totalTimeMicros > 0) { |
| 4617 | if (reqUid < 0) { |
| 4618 | // Only show the ordered list of all wake |
| 4619 | // locks if the caller is not asking for data |
| 4620 | // about a specific uid. |
| 4621 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4622 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4623 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4624 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | } |
| 4628 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4629 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4630 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4631 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4632 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4633 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4634 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4635 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4636 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4637 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4638 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4639 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4640 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4641 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4642 | sb.setLength(0); |
| 4643 | sb.append(prefix); |
| 4644 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4645 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4646 | pw.println(sb.toString()); |
| 4647 | } |
| 4648 | |
| 4649 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4650 | sb.setLength(0); |
| 4651 | sb.append(prefix); |
| 4652 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4653 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4654 | pw.println(sb.toString()); |
| 4655 | } |
| 4656 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4657 | final long multicastWakeLockTimeTotalMicros = |
| 4658 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4659 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4660 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4661 | sb.setLength(0); |
| 4662 | sb.append(prefix); |
| 4663 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4664 | sb.append(multicastWakeLockCountTotal); |
| 4665 | pw.println(sb.toString()); |
| 4666 | |
| 4667 | sb.setLength(0); |
| 4668 | sb.append(prefix); |
| 4669 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4670 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4671 | pw.println(sb.toString()); |
| 4672 | } |
| 4673 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4674 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4675 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4676 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4677 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4678 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4679 | pw.println(sb.toString()); |
| 4680 | |
| 4681 | pw.print(prefix); |
| 4682 | sb.setLength(0); |
| 4683 | sb.append(prefix); |
| 4684 | sb.append(" Logging duration for connectivity statistics: "); |
| 4685 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4686 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4687 | |
| 4688 | sb.setLength(0); |
| 4689 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4690 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4691 | pw.println(sb.toString()); |
| 4692 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4693 | pw.print(prefix); |
| 4694 | sb.setLength(0); |
| 4695 | sb.append(prefix); |
| 4696 | sb.append(" Cellular kernel active time: "); |
| 4697 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4698 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4699 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4700 | sb.append(")"); |
| 4701 | pw.println(sb.toString()); |
| 4702 | |
| 4703 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4704 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4705 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4706 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4707 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4708 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4709 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4710 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4711 | didOne = false; |
| 4712 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4713 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4714 | if (time == 0) { |
| 4715 | continue; |
| 4716 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4717 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4718 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4719 | didOne = true; |
| 4720 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4721 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4722 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4723 | sb.append("("); |
| 4724 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4725 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4726 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4727 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4728 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4729 | |
| 4730 | sb.setLength(0); |
| 4731 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4732 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4733 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4734 | "very poor (less than -128dBm): ", |
| 4735 | "poor (-128dBm to -118dBm): ", |
| 4736 | "moderate (-118dBm to -108dBm): ", |
| 4737 | "good (-108dBm to -98dBm): ", |
| 4738 | "great (greater than -98dBm): "}; |
| 4739 | didOne = false; |
| 4740 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4741 | cellularRxSignalStrengthDescription.length); |
| 4742 | for (int i=0; i<numCellularRxBins; i++) { |
| 4743 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4744 | if (time == 0) { |
| 4745 | continue; |
| 4746 | } |
| 4747 | sb.append("\n "); |
| 4748 | sb.append(prefix); |
| 4749 | didOne = true; |
| 4750 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4751 | sb.append(" "); |
| 4752 | formatTimeMs(sb, time/1000); |
| 4753 | sb.append("("); |
| 4754 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4755 | sb.append(") "); |
| 4756 | } |
| 4757 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4758 | pw.println(sb.toString()); |
| 4759 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4760 | printControllerActivity(pw, sb, prefix, CELLULAR_CONTROLLER_NAME, |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4761 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4762 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4763 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4764 | sb.setLength(0); |
| 4765 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4766 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4767 | pw.println(sb.toString()); |
| 4768 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4769 | pw.print(prefix); |
| 4770 | sb.setLength(0); |
| 4771 | sb.append(prefix); |
| 4772 | sb.append(" Wifi kernel active time: "); |
| 4773 | final long wifiActiveTime = getWifiActiveTime(rawRealtime, which); |
| 4774 | formatTimeMs(sb, wifiActiveTime / 1000); |
| 4775 | sb.append("("); sb.append(formatRatioLocked(wifiActiveTime, whichBatteryRealtime)); |
| 4776 | sb.append(")"); |
| 4777 | pw.println(sb.toString()); |
| 4778 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4779 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4780 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4781 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4782 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4783 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4784 | sb.setLength(0); |
| 4785 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4786 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4787 | didOne = false; |
| 4788 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4789 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4790 | if (time == 0) { |
| 4791 | continue; |
| 4792 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4793 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4794 | didOne = true; |
| 4795 | sb.append(WIFI_STATE_NAMES[i]); |
| 4796 | sb.append(" "); |
| 4797 | formatTimeMs(sb, time/1000); |
| 4798 | sb.append("("); |
| 4799 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4800 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4801 | } |
| 4802 | if (!didOne) sb.append(" (no activity)"); |
| 4803 | pw.println(sb.toString()); |
| 4804 | |
| 4805 | sb.setLength(0); |
| 4806 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4807 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4808 | didOne = false; |
| 4809 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4810 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4811 | if (time == 0) { |
| 4812 | continue; |
| 4813 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4814 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4815 | didOne = true; |
| 4816 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4817 | sb.append(" "); |
| 4818 | formatTimeMs(sb, time/1000); |
| 4819 | sb.append("("); |
| 4820 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4821 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4822 | } |
| 4823 | if (!didOne) sb.append(" (no activity)"); |
| 4824 | pw.println(sb.toString()); |
| 4825 | |
| 4826 | sb.setLength(0); |
| 4827 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4828 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4829 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4830 | "very poor (less than -88.75dBm): ", |
| 4831 | "poor (-88.75 to -77.5dBm): ", |
| 4832 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4833 | "good (-66.25dBm to -55dBm): ", |
| 4834 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4835 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4836 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4837 | wifiRxSignalStrengthDescription.length); |
| 4838 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4839 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4840 | if (time == 0) { |
| 4841 | continue; |
| 4842 | } |
| 4843 | sb.append("\n "); |
| 4844 | sb.append(prefix); |
| 4845 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4846 | sb.append(" "); |
| 4847 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4848 | formatTimeMs(sb, time/1000); |
| 4849 | sb.append("("); |
| 4850 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4851 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4852 | } |
| 4853 | if (!didOne) sb.append(" (no activity)"); |
| 4854 | pw.println(sb.toString()); |
| 4855 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4856 | printControllerActivity(pw, sb, prefix, WIFI_CONTROLLER_NAME, |
| 4857 | getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4858 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4859 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4860 | sb.setLength(0); |
| 4861 | sb.append(prefix); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4862 | sb.append(" GPS Statistics:"); |
| 4863 | pw.println(sb.toString()); |
| 4864 | |
| 4865 | sb.setLength(0); |
| 4866 | sb.append(prefix); |
| 4867 | sb.append(" GPS signal quality (Top 4 Average CN0):"); |
| 4868 | final String[] gpsSignalQualityDescription = new String[]{ |
| 4869 | "poor (less than 20 dBHz): ", |
| 4870 | "good (greater than 20 dBHz): "}; |
| 4871 | final int numGpsSignalQualityBins = Math.min(GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS, |
| 4872 | gpsSignalQualityDescription.length); |
| 4873 | for (int i=0; i<numGpsSignalQualityBins; i++) { |
| 4874 | final long time = getGpsSignalQualityTime(i, rawRealtime, which); |
| 4875 | sb.append("\n "); |
| 4876 | sb.append(prefix); |
| 4877 | sb.append(" "); |
| 4878 | sb.append(gpsSignalQualityDescription[i]); |
| 4879 | formatTimeMs(sb, time/1000); |
| 4880 | sb.append("("); |
| 4881 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4882 | sb.append(") "); |
| 4883 | } |
| 4884 | pw.println(sb.toString()); |
| 4885 | |
| 4886 | final long gpsBatteryDrainMaMs = getGpsBatteryDrainMaMs(); |
| 4887 | if (gpsBatteryDrainMaMs > 0) { |
| 4888 | pw.print(prefix); |
| 4889 | sb.setLength(0); |
| 4890 | sb.append(prefix); |
| 4891 | sb.append(" Battery Drain (mAh): "); |
| 4892 | sb.append(Double.toString(((double) gpsBatteryDrainMaMs)/(3600 * 1000))); |
| 4893 | pw.println(sb.toString()); |
| 4894 | } |
| 4895 | |
| 4896 | pw.print(prefix); |
| 4897 | sb.setLength(0); |
| 4898 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4899 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4900 | pw.println(sb.toString()); |
| 4901 | pw.println(""); |
| 4902 | |
| 4903 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4904 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4905 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4906 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4907 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4908 | sb.setLength(0); |
| 4909 | sb.append(prefix); |
| 4910 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4911 | pw.println(sb.toString()); |
| 4912 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4913 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4914 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4915 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4916 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4917 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4918 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4919 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4920 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4921 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4922 | pw.println(getDischargeStartLevel()); |
| 4923 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4924 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4925 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4926 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4927 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4928 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4929 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4930 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4931 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4932 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4933 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4934 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4935 | pw.println(getDischargeAmountScreenOff()); |
| 4936 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4937 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4938 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4939 | } else { |
| 4940 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4941 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4942 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4943 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4944 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4945 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4946 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4947 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4948 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4949 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4950 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4951 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4952 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4953 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4954 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4955 | helper.create(this); |
| 4956 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4957 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4958 | if (sippers != null && sippers.size() > 0) { |
| 4959 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4960 | pw.print(prefix); pw.print(" Capacity: "); |
| 4961 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4962 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4963 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4964 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4965 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4966 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4967 | pw.println(); |
| 4968 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4969 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4970 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4971 | switch (bs.drainType) { |
| 4972 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4973 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4974 | break; |
| 4975 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4976 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4977 | break; |
| 4978 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4979 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4980 | break; |
| 4981 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4982 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4983 | break; |
| 4984 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4985 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4986 | break; |
| 4987 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4988 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4989 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4990 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4991 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4992 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4993 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4994 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4995 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4996 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4997 | break; |
| 4998 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4999 | pw.print(" User "); pw.print(bs.userId); |
| 5000 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5001 | break; |
| 5002 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5003 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5004 | break; |
| 5005 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5006 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5007 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5008 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5009 | pw.print(" Camera: "); |
| 5010 | break; |
| 5011 | default: |
| 5012 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5013 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5014 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5015 | printmAh(pw, bs.totalPowerMah); |
| 5016 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 5017 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 5018 | // If the usage (generic power) isn't the whole amount, we list out |
| 5019 | // what components are involved in the calculation. |
| 5020 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5021 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 5022 | if (bs.usagePowerMah != 0) { |
| 5023 | pw.print(" usage="); |
| 5024 | printmAh(pw, bs.usagePowerMah); |
| 5025 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5026 | if (bs.cpuPowerMah != 0) { |
| 5027 | pw.print(" cpu="); |
| 5028 | printmAh(pw, bs.cpuPowerMah); |
| 5029 | } |
| 5030 | if (bs.wakeLockPowerMah != 0) { |
| 5031 | pw.print(" wake="); |
| 5032 | printmAh(pw, bs.wakeLockPowerMah); |
| 5033 | } |
| 5034 | if (bs.mobileRadioPowerMah != 0) { |
| 5035 | pw.print(" radio="); |
| 5036 | printmAh(pw, bs.mobileRadioPowerMah); |
| 5037 | } |
| 5038 | if (bs.wifiPowerMah != 0) { |
| 5039 | pw.print(" wifi="); |
| 5040 | printmAh(pw, bs.wifiPowerMah); |
| 5041 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5042 | if (bs.bluetoothPowerMah != 0) { |
| 5043 | pw.print(" bt="); |
| 5044 | printmAh(pw, bs.bluetoothPowerMah); |
| 5045 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5046 | if (bs.gpsPowerMah != 0) { |
| 5047 | pw.print(" gps="); |
| 5048 | printmAh(pw, bs.gpsPowerMah); |
| 5049 | } |
| 5050 | if (bs.sensorPowerMah != 0) { |
| 5051 | pw.print(" sensor="); |
| 5052 | printmAh(pw, bs.sensorPowerMah); |
| 5053 | } |
| 5054 | if (bs.cameraPowerMah != 0) { |
| 5055 | pw.print(" camera="); |
| 5056 | printmAh(pw, bs.cameraPowerMah); |
| 5057 | } |
| 5058 | if (bs.flashlightPowerMah != 0) { |
| 5059 | pw.print(" flash="); |
| 5060 | printmAh(pw, bs.flashlightPowerMah); |
| 5061 | } |
| 5062 | pw.print(" )"); |
| 5063 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 5064 | |
| 5065 | // If there is additional smearing information, include it. |
| 5066 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 5067 | pw.print(" Including smearing: "); |
| 5068 | printmAh(pw, bs.totalSmearedPowerMah); |
| 5069 | pw.print(" ("); |
| 5070 | if (bs.screenPowerMah != 0) { |
| 5071 | pw.print(" screen="); |
| 5072 | printmAh(pw, bs.screenPowerMah); |
| 5073 | } |
| 5074 | if (bs.proportionalSmearMah != 0) { |
| 5075 | pw.print(" proportional="); |
| 5076 | printmAh(pw, bs.proportionalSmearMah); |
| 5077 | } |
| 5078 | pw.print(" )"); |
| 5079 | } |
| 5080 | if (bs.shouldHide) { |
| 5081 | pw.print(" Excluded from smearing"); |
| 5082 | } |
| 5083 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5084 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5085 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5086 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5087 | } |
| 5088 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5089 | sippers = helper.getMobilemsppList(); |
| 5090 | if (sippers != null && sippers.size() > 0) { |
| 5091 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5092 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5093 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5094 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5095 | sb.setLength(0); |
| 5096 | sb.append(prefix); sb.append(" Uid "); |
| 5097 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 5098 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 5099 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 5100 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5101 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5102 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5103 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5104 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5105 | sb.setLength(0); |
| 5106 | sb.append(prefix); |
| 5107 | sb.append(" TOTAL TIME: "); |
| 5108 | formatTimeMs(sb, totalTime); |
| 5109 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 5110 | sb.append(")"); |
| 5111 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5112 | pw.println(); |
| 5113 | } |
| 5114 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5115 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 5116 | @Override |
| 5117 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 5118 | long lhsTime = lhs.mTime; |
| 5119 | long rhsTime = rhs.mTime; |
| 5120 | if (lhsTime < rhsTime) { |
| 5121 | return 1; |
| 5122 | } |
| 5123 | if (lhsTime > rhsTime) { |
| 5124 | return -1; |
| 5125 | } |
| 5126 | return 0; |
| 5127 | } |
| 5128 | }; |
| 5129 | |
| 5130 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5131 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 5132 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5133 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5134 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 5135 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 5136 | : kernelWakelocks.entrySet()) { |
| 5137 | final BatteryStats.Timer timer = ent.getValue(); |
| 5138 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5139 | if (totalTimeMillis > 0) { |
| 5140 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 5141 | } |
| 5142 | } |
| 5143 | if (ktimers.size() > 0) { |
| 5144 | Collections.sort(ktimers, timerComparator); |
| 5145 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 5146 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5147 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5148 | String linePrefix = ": "; |
| 5149 | sb.setLength(0); |
| 5150 | sb.append(prefix); |
| 5151 | sb.append(" Kernel Wake lock "); |
| 5152 | sb.append(timer.mName); |
| 5153 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 5154 | which, linePrefix); |
| 5155 | if (!linePrefix.equals(": ")) { |
| 5156 | sb.append(" realtime"); |
| 5157 | // Only print out wake locks that were held |
| 5158 | pw.println(sb.toString()); |
| 5159 | } |
| 5160 | } |
| 5161 | pw.println(); |
| 5162 | } |
| 5163 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5164 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5165 | if (timers.size() > 0) { |
| 5166 | Collections.sort(timers, timerComparator); |
| 5167 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5168 | for (int i=0; i<timers.size(); i++) { |
| 5169 | TimerEntry timer = timers.get(i); |
| 5170 | sb.setLength(0); |
| 5171 | sb.append(" Wake lock "); |
| 5172 | UserHandle.formatUid(sb, timer.mId); |
| 5173 | sb.append(" "); |
| 5174 | sb.append(timer.mName); |
| 5175 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5176 | sb.append(" realtime"); |
| 5177 | pw.println(sb.toString()); |
| 5178 | } |
| 5179 | timers.clear(); |
| 5180 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5181 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5182 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5183 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5184 | if (wakeupReasons.size() > 0) { |
| 5185 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5186 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5187 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5188 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5189 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5190 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5191 | } |
| 5192 | Collections.sort(reasons, timerComparator); |
| 5193 | for (int i=0; i<reasons.size(); i++) { |
| 5194 | TimerEntry timer = reasons.get(i); |
| 5195 | String linePrefix = ": "; |
| 5196 | sb.setLength(0); |
| 5197 | sb.append(prefix); |
| 5198 | sb.append(" Wakeup reason "); |
| 5199 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5200 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5201 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5202 | pw.println(sb.toString()); |
| 5203 | } |
| 5204 | pw.println(); |
| 5205 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5206 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5207 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5208 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5209 | if (mMemoryStats.size() > 0) { |
| 5210 | pw.println(" Memory Stats"); |
| 5211 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5212 | sb.setLength(0); |
| 5213 | sb.append(" Bandwidth "); |
| 5214 | sb.append(mMemoryStats.keyAt(i)); |
| 5215 | sb.append(" Time "); |
| 5216 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5217 | pw.println(sb.toString()); |
| 5218 | } |
| 5219 | pw.println(); |
| 5220 | } |
| 5221 | |
| 5222 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5223 | if (rpmStats.size() > 0) { |
| 5224 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5225 | if (rpmStats.size() > 0) { |
| 5226 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5227 | final String timerName = ent.getKey(); |
| 5228 | final Timer timer = ent.getValue(); |
| 5229 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5230 | } |
| 5231 | } |
| 5232 | pw.println(); |
| 5233 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5234 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5235 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5236 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5237 | pw.print(prefix); |
| 5238 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5239 | if (screenOffRpmStats.size() > 0) { |
| 5240 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5241 | final String timerName = ent.getKey(); |
| 5242 | final Timer timer = ent.getValue(); |
| 5243 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5244 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5245 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5246 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5247 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5250 | final long[] cpuFreqs = getCpuFreqs(); |
| 5251 | if (cpuFreqs != null) { |
| 5252 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5253 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5254 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5255 | sb.append(" " + cpuFreqs[i]); |
| 5256 | } |
| 5257 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5258 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | for (int iu=0; iu<NU; iu++) { |
| 5262 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5263 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5264 | continue; |
| 5265 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5266 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5267 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5268 | |
| 5269 | pw.print(prefix); |
| 5270 | pw.print(" "); |
| 5271 | UserHandle.formatUid(pw, uid); |
| 5272 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5273 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5274 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5275 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5276 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5277 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5278 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5279 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5280 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5281 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5282 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5283 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5284 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5285 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5286 | |
| 5287 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5288 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5289 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5290 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5291 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5292 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5293 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5294 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5295 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5296 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5297 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5298 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5299 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5300 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5301 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5302 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5303 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5304 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5305 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5306 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5307 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5308 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5310 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5311 | sb.setLength(0); |
| 5312 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5313 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5314 | sb.append("("); |
| 5315 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5316 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5317 | long packets = mobileRxPackets + mobileTxPackets; |
| 5318 | if (packets == 0) { |
| 5319 | packets = 1; |
| 5320 | } |
| 5321 | sb.append(" @ "); |
| 5322 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5323 | sb.append(" mspp"); |
| 5324 | pw.println(sb.toString()); |
| 5325 | } |
| 5326 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5327 | if (mobileWakeup > 0) { |
| 5328 | sb.setLength(0); |
| 5329 | sb.append(prefix); |
| 5330 | sb.append(" Mobile radio AP wakeups: "); |
| 5331 | sb.append(mobileWakeup); |
| 5332 | pw.println(sb.toString()); |
| 5333 | } |
| 5334 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5335 | printControllerActivityIfInteresting(pw, sb, prefix + " ", |
| 5336 | CELLULAR_CONTROLLER_NAME, u.getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5337 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5338 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5339 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5340 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5341 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5342 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5343 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5344 | } |
| 5345 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5346 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5347 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5348 | || uidWifiRunningTime != 0) { |
| 5349 | sb.setLength(0); |
| 5350 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5351 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5352 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5353 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5354 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5355 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5356 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5357 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5358 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5359 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5360 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5361 | whichBatteryRealtime)); sb.append(") "); |
| 5362 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5363 | sb.append("x\n"); |
| 5364 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5365 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5366 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5367 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5368 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5369 | sb.append(") "); |
| 5370 | sb.append(wifiScanCount); |
| 5371 | sb.append("x\n"); |
| 5372 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5373 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5374 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5375 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5376 | sb.append(") "); |
| 5377 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5378 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5379 | pw.println(sb.toString()); |
| 5380 | } |
| 5381 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5382 | if (wifiWakeup > 0) { |
| 5383 | sb.setLength(0); |
| 5384 | sb.append(prefix); |
| 5385 | sb.append(" WiFi AP wakeups: "); |
| 5386 | sb.append(wifiWakeup); |
| 5387 | pw.println(sb.toString()); |
| 5388 | } |
| 5389 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5390 | printControllerActivityIfInteresting(pw, sb, prefix + " ", WIFI_CONTROLLER_NAME, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5391 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5392 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5393 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5394 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5395 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5396 | pw.print(formatBytesLocked(btTxBytes)); |
| 5397 | pw.println(" sent"); |
| 5398 | } |
| 5399 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5400 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5401 | if (bleTimer != null) { |
| 5402 | // Convert from microseconds to milliseconds with rounding |
| 5403 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5404 | / 1000; |
| 5405 | if (totalTimeMs != 0) { |
| 5406 | final int count = bleTimer.getCountLocked(which); |
| 5407 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5408 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5409 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5410 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5411 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5412 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5413 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5414 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5415 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5416 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5417 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5418 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5419 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5420 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5421 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5422 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5423 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5424 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5425 | final Timer unoptimizedScanTimerBg = |
| 5426 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5427 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5428 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5429 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5430 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5431 | |
| 5432 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5433 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5434 | sb.append(prefix); |
| 5435 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5436 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5437 | sb.append(" ("); |
| 5438 | sb.append(count); |
| 5439 | sb.append(" times)"); |
| 5440 | if (bleTimer.isRunningLocked()) { |
| 5441 | sb.append(" (currently running)"); |
| 5442 | } |
| 5443 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5444 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5445 | |
| 5446 | sb.append(prefix); |
| 5447 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5448 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5449 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5450 | sb.append(count); |
| 5451 | sb.append(" times)"); |
| 5452 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5453 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5454 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5455 | sb.append("\n"); |
| 5456 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5457 | sb.append(prefix); |
| 5458 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5459 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5460 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5461 | sb.append(countBg); |
| 5462 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5463 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5464 | sb.append(" (currently running in background)"); |
| 5465 | } |
| 5466 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5467 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5468 | |
| 5469 | sb.append(prefix); |
| 5470 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5471 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5472 | sb.append(" ("); |
| 5473 | sb.append(resultCountBg); |
| 5474 | sb.append(" in background)"); |
| 5475 | |
| 5476 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5477 | sb.append("\n"); |
| 5478 | sb.append(prefix); |
| 5479 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5480 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5481 | sb.append(" (max "); |
| 5482 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5483 | sb.append(")"); |
| 5484 | if (unoptimizedScanTimer != null |
| 5485 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5486 | sb.append(" (currently running unoptimized)"); |
| 5487 | } |
| 5488 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5489 | sb.append("\n"); |
| 5490 | sb.append(prefix); |
| 5491 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5492 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5493 | sb.append(" (max "); |
| 5494 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5495 | sb.append(")"); |
| 5496 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5497 | sb.append(" (currently running unoptimized in background)"); |
| 5498 | } |
| 5499 | } |
| 5500 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5501 | pw.println(sb.toString()); |
| 5502 | uidActivity = true; |
| 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5507 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5508 | if (u.hasUserActivity()) { |
| 5509 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5510 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5511 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5512 | if (val != 0) { |
| 5513 | if (!hasData) { |
| 5514 | sb.setLength(0); |
| 5515 | sb.append(" User activity: "); |
| 5516 | hasData = true; |
| 5517 | } else { |
| 5518 | sb.append(", "); |
| 5519 | } |
| 5520 | sb.append(val); |
| 5521 | sb.append(" "); |
| 5522 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5523 | } |
| 5524 | } |
| 5525 | if (hasData) { |
| 5526 | pw.println(sb.toString()); |
| 5527 | } |
| 5528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5530 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5531 | = u.getWakelockStats(); |
| 5532 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5533 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5534 | int countWakelock = 0; |
| 5535 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5536 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5537 | String linePrefix = ": "; |
| 5538 | sb.setLength(0); |
| 5539 | sb.append(prefix); |
| 5540 | sb.append(" Wake lock "); |
| 5541 | sb.append(wakelocks.keyAt(iw)); |
| 5542 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5543 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5544 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5545 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5546 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5547 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5548 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5549 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5550 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5551 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5552 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5553 | sb.append(" realtime"); |
| 5554 | pw.println(sb.toString()); |
| 5555 | uidActivity = true; |
| 5556 | countWakelock++; |
| 5557 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5558 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5559 | rawRealtime, which); |
| 5560 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5561 | rawRealtime, which); |
| 5562 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5563 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5564 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5565 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5566 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5567 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5568 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5569 | // pooled and therefore just a lower bound) |
| 5570 | long actualTotalPartialWakelock = 0; |
| 5571 | long actualBgPartialWakelock = 0; |
| 5572 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5573 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5574 | // Convert from microseconds to milliseconds with rounding |
| 5575 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5576 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5577 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5578 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5579 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
| 5582 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5583 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5584 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5585 | sb.setLength(0); |
| 5586 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5587 | sb.append(" TOTAL wake: "); |
| 5588 | boolean needComma = false; |
| 5589 | if (totalFullWakelock != 0) { |
| 5590 | needComma = true; |
| 5591 | formatTimeMs(sb, totalFullWakelock); |
| 5592 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5593 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5594 | if (totalPartialWakelock != 0) { |
| 5595 | if (needComma) { |
| 5596 | sb.append(", "); |
| 5597 | } |
| 5598 | needComma = true; |
| 5599 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5600 | sb.append("blamed partial"); |
| 5601 | } |
| 5602 | if (actualTotalPartialWakelock != 0) { |
| 5603 | if (needComma) { |
| 5604 | sb.append(", "); |
| 5605 | } |
| 5606 | needComma = true; |
| 5607 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5608 | sb.append("actual partial"); |
| 5609 | } |
| 5610 | if (actualBgPartialWakelock != 0) { |
| 5611 | if (needComma) { |
| 5612 | sb.append(", "); |
| 5613 | } |
| 5614 | needComma = true; |
| 5615 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5616 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5617 | } |
| 5618 | if (totalWindowWakelock != 0) { |
| 5619 | if (needComma) { |
| 5620 | sb.append(", "); |
| 5621 | } |
| 5622 | needComma = true; |
| 5623 | formatTimeMs(sb, totalWindowWakelock); |
| 5624 | sb.append("window"); |
| 5625 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5626 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5627 | if (needComma) { |
| 5628 | sb.append(","); |
| 5629 | } |
| 5630 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5631 | formatTimeMs(sb, totalDrawWakelock); |
| 5632 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5633 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5634 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5635 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5639 | // Calculate multicast wakelock stats |
| 5640 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5641 | if (mcTimer != null) { |
| 5642 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5643 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5644 | |
| 5645 | if (multicastWakeLockTimeMicros > 0) { |
| 5646 | sb.setLength(0); |
| 5647 | sb.append(prefix); |
| 5648 | sb.append(" WiFi Multicast Wakelock"); |
| 5649 | sb.append(" count = "); |
| 5650 | sb.append(multicastWakeLockCount); |
| 5651 | sb.append(" time = "); |
| 5652 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5653 | pw.println(sb.toString()); |
| 5654 | } |
| 5655 | } |
| 5656 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5657 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5658 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5659 | final Timer timer = syncs.valueAt(isy); |
| 5660 | // Convert from microseconds to milliseconds with rounding |
| 5661 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5662 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5663 | final Timer bgTimer = timer.getSubTimer(); |
| 5664 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5665 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5666 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5667 | sb.setLength(0); |
| 5668 | sb.append(prefix); |
| 5669 | sb.append(" Sync "); |
| 5670 | sb.append(syncs.keyAt(isy)); |
| 5671 | sb.append(": "); |
| 5672 | if (totalTime != 0) { |
| 5673 | formatTimeMs(sb, totalTime); |
| 5674 | sb.append("realtime ("); |
| 5675 | sb.append(count); |
| 5676 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5677 | if (bgTime > 0) { |
| 5678 | sb.append(", "); |
| 5679 | formatTimeMs(sb, bgTime); |
| 5680 | sb.append("background ("); |
| 5681 | sb.append(bgCount); |
| 5682 | sb.append(" times)"); |
| 5683 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5684 | } else { |
| 5685 | sb.append("(not used)"); |
| 5686 | } |
| 5687 | pw.println(sb.toString()); |
| 5688 | uidActivity = true; |
| 5689 | } |
| 5690 | |
| 5691 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5692 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5693 | final Timer timer = jobs.valueAt(ij); |
| 5694 | // Convert from microseconds to milliseconds with rounding |
| 5695 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5696 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5697 | final Timer bgTimer = timer.getSubTimer(); |
| 5698 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5699 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5700 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5701 | sb.setLength(0); |
| 5702 | sb.append(prefix); |
| 5703 | sb.append(" Job "); |
| 5704 | sb.append(jobs.keyAt(ij)); |
| 5705 | sb.append(": "); |
| 5706 | if (totalTime != 0) { |
| 5707 | formatTimeMs(sb, totalTime); |
| 5708 | sb.append("realtime ("); |
| 5709 | sb.append(count); |
| 5710 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5711 | if (bgTime > 0) { |
| 5712 | sb.append(", "); |
| 5713 | formatTimeMs(sb, bgTime); |
| 5714 | sb.append("background ("); |
| 5715 | sb.append(bgCount); |
| 5716 | sb.append(" times)"); |
| 5717 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5718 | } else { |
| 5719 | sb.append("(not used)"); |
| 5720 | } |
| 5721 | pw.println(sb.toString()); |
| 5722 | uidActivity = true; |
| 5723 | } |
| 5724 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5725 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5726 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5727 | SparseIntArray types = completions.valueAt(ic); |
| 5728 | if (types != null) { |
| 5729 | pw.print(prefix); |
| 5730 | pw.print(" Job Completions "); |
| 5731 | pw.print(completions.keyAt(ic)); |
| 5732 | pw.print(":"); |
| 5733 | for (int it=0; it<types.size(); it++) { |
| 5734 | pw.print(" "); |
| 5735 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5736 | pw.print("("); |
| 5737 | pw.print(types.valueAt(it)); |
| 5738 | pw.print("x)"); |
| 5739 | } |
| 5740 | pw.println(); |
| 5741 | } |
| 5742 | } |
| 5743 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame^] | 5744 | u.getDeferredJobsLineLocked(sb, which); |
| 5745 | if (sb.length() > 0) { |
| 5746 | pw.print(" Jobs deferred on launch "); pw.println(sb.toString()); |
| 5747 | } |
| 5748 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5749 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5750 | prefix, "Flashlight"); |
| 5751 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5752 | prefix, "Camera"); |
| 5753 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5754 | prefix, "Video"); |
| 5755 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5756 | prefix, "Audio"); |
| 5757 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5758 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5759 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5760 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5761 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5762 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5763 | sb.setLength(0); |
| 5764 | sb.append(prefix); |
| 5765 | sb.append(" Sensor "); |
| 5766 | int handle = se.getHandle(); |
| 5767 | if (handle == Uid.Sensor.GPS) { |
| 5768 | sb.append("GPS"); |
| 5769 | } else { |
| 5770 | sb.append(handle); |
| 5771 | } |
| 5772 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5774 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5775 | if (timer != null) { |
| 5776 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5777 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5778 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5779 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5780 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5781 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5782 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5783 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5784 | final long bgActualTime = bgTimer != null ? |
| 5785 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5786 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5787 | //timer.logState(); |
| 5788 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5789 | if (actualTime != totalTime) { |
| 5790 | formatTimeMs(sb, totalTime); |
| 5791 | sb.append("blamed realtime, "); |
| 5792 | } |
| 5793 | |
| 5794 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5795 | sb.append("realtime ("); |
| 5796 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5797 | sb.append(" times)"); |
| 5798 | |
| 5799 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5800 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5801 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5802 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5803 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5804 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5805 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | } else { |
| 5807 | sb.append("(not used)"); |
| 5808 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5809 | } else { |
| 5810 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5812 | |
| 5813 | pw.println(sb.toString()); |
| 5814 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | } |
| 5816 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5817 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5818 | "Vibrator"); |
| 5819 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5820 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5821 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5822 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5823 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5824 | long totalStateTime = 0; |
| 5825 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5826 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5827 | if (time > 0) { |
| 5828 | totalStateTime += time; |
| 5829 | sb.setLength(0); |
| 5830 | sb.append(prefix); |
| 5831 | sb.append(" "); |
| 5832 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5833 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5834 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5835 | pw.println(sb.toString()); |
| 5836 | uidActivity = true; |
| 5837 | } |
| 5838 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5839 | if (totalStateTime > 0) { |
| 5840 | sb.setLength(0); |
| 5841 | sb.append(prefix); |
| 5842 | sb.append(" Total running: "); |
| 5843 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5844 | pw.println(sb.toString()); |
| 5845 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5846 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5847 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5848 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5849 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5850 | sb.setLength(0); |
| 5851 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5852 | sb.append(" Total cpu time: u="); |
| 5853 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5854 | sb.append("s="); |
| 5855 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5856 | pw.println(sb.toString()); |
| 5857 | } |
| 5858 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5859 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5860 | if (cpuFreqTimes != null) { |
| 5861 | sb.setLength(0); |
| 5862 | sb.append(" Total cpu time per freq:"); |
| 5863 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5864 | sb.append(" " + cpuFreqTimes[i]); |
| 5865 | } |
| 5866 | pw.println(sb.toString()); |
| 5867 | } |
| 5868 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5869 | if (screenOffCpuFreqTimes != null) { |
| 5870 | sb.setLength(0); |
| 5871 | sb.append(" Total screen-off cpu time per freq:"); |
| 5872 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5873 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5874 | } |
| 5875 | pw.println(sb.toString()); |
| 5876 | } |
| 5877 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5878 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5879 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5880 | if (cpuTimes != null) { |
| 5881 | sb.setLength(0); |
| 5882 | sb.append(" Cpu times per freq at state " |
| 5883 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5884 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5885 | sb.append(" " + cpuTimes[i]); |
| 5886 | } |
| 5887 | pw.println(sb.toString()); |
| 5888 | } |
| 5889 | |
| 5890 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5891 | if (screenOffCpuTimes != null) { |
| 5892 | sb.setLength(0); |
| 5893 | sb.append(" Screen-off cpu times per freq at state " |
| 5894 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5895 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5896 | sb.append(" " + screenOffCpuTimes[i]); |
| 5897 | } |
| 5898 | pw.println(sb.toString()); |
| 5899 | } |
| 5900 | } |
| 5901 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5902 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5903 | = u.getProcessStats(); |
| 5904 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5905 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5906 | long userTime; |
| 5907 | long systemTime; |
| 5908 | long foregroundTime; |
| 5909 | int starts; |
| 5910 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5912 | userTime = ps.getUserTime(which); |
| 5913 | systemTime = ps.getSystemTime(which); |
| 5914 | foregroundTime = ps.getForegroundTime(which); |
| 5915 | starts = ps.getStarts(which); |
| 5916 | final int numCrashes = ps.getNumCrashes(which); |
| 5917 | final int numAnrs = ps.getNumAnrs(which); |
| 5918 | numExcessive = which == STATS_SINCE_CHARGED |
| 5919 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5921 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5922 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5923 | sb.setLength(0); |
| 5924 | sb.append(prefix); sb.append(" Proc "); |
| 5925 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5926 | sb.append(prefix); sb.append(" CPU: "); |
| 5927 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5928 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5929 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5930 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5931 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5932 | boolean hasOne = false; |
| 5933 | if (starts != 0) { |
| 5934 | hasOne = true; |
| 5935 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5936 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5937 | if (numCrashes != 0) { |
| 5938 | if (hasOne) { |
| 5939 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5940 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5941 | hasOne = true; |
| 5942 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5943 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5944 | if (numAnrs != 0) { |
| 5945 | if (hasOne) { |
| 5946 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5948 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5949 | } |
| 5950 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5951 | pw.println(sb.toString()); |
| 5952 | for (int e=0; e<numExcessive; e++) { |
| 5953 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5954 | if (ew != null) { |
| 5955 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5956 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5957 | pw.print("cpu"); |
| 5958 | } else { |
| 5959 | pw.print("unknown"); |
| 5960 | } |
| 5961 | pw.print(" use: "); |
| 5962 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5963 | pw.print(" over "); |
| 5964 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5965 | if (ew.overTime != 0) { |
| 5966 | pw.print(" ("); |
| 5967 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5968 | pw.println("%)"); |
| 5969 | } |
| 5970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | } |
| 5972 | uidActivity = true; |
| 5973 | } |
| 5974 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5975 | |
| 5976 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5977 | = u.getPackageStats(); |
| 5978 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5979 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5980 | pw.println(":"); |
| 5981 | boolean apkActivity = false; |
| 5982 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5983 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5984 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5985 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5986 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5987 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5988 | pw.println(" times"); |
| 5989 | apkActivity = true; |
| 5990 | } |
| 5991 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5992 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5993 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5994 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5995 | final int starts = ss.getStarts(which); |
| 5996 | final int launches = ss.getLaunches(which); |
| 5997 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5998 | sb.setLength(0); |
| 5999 | sb.append(prefix); sb.append(" Service "); |
| 6000 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 6001 | sb.append(prefix); sb.append(" Created for: "); |
| 6002 | formatTimeMs(sb, startTime / 1000); |
| 6003 | sb.append("uptime\n"); |
| 6004 | sb.append(prefix); sb.append(" Starts: "); |
| 6005 | sb.append(starts); |
| 6006 | sb.append(", launches: "); sb.append(launches); |
| 6007 | pw.println(sb.toString()); |
| 6008 | apkActivity = true; |
| 6009 | } |
| 6010 | } |
| 6011 | if (!apkActivity) { |
| 6012 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 6013 | } |
| 6014 | uidActivity = true; |
| 6015 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6016 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6017 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | } |
| 6019 | } |
| 6020 | } |
| 6021 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6022 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6023 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6024 | int diff = oldval ^ newval; |
| 6025 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6026 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6027 | for (int i=0; i<descriptions.length; i++) { |
| 6028 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6029 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6030 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6031 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6032 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6033 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6034 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 6035 | didWake = true; |
| 6036 | pw.print("="); |
| 6037 | if (longNames) { |
| 6038 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 6039 | pw.print(":\""); |
| 6040 | pw.print(wakelockTag.string); |
| 6041 | pw.print("\""); |
| 6042 | } else { |
| 6043 | pw.print(wakelockTag.poolIdx); |
| 6044 | } |
| 6045 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6046 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6047 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6048 | pw.print("="); |
| 6049 | int val = (newval&bd.mask)>>bd.shift; |
| 6050 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6051 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6052 | } else { |
| 6053 | pw.print(val); |
| 6054 | } |
| 6055 | } |
| 6056 | } |
| 6057 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6058 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 6059 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6060 | if (longNames) { |
| 6061 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 6062 | pw.print(":\""); |
| 6063 | pw.print(wakelockTag.string); |
| 6064 | pw.print("\""); |
| 6065 | } else { |
| 6066 | pw.print(wakelockTag.poolIdx); |
| 6067 | } |
| 6068 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6069 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6070 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6071 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6072 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | public static class HistoryPrinter { |
| 6076 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6077 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6078 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6079 | int oldStatus = -1; |
| 6080 | int oldHealth = -1; |
| 6081 | int oldPlug = -1; |
| 6082 | int oldTemp = -1; |
| 6083 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6084 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6085 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6086 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6087 | void reset() { |
| 6088 | oldState = oldState2 = 0; |
| 6089 | oldLevel = -1; |
| 6090 | oldStatus = -1; |
| 6091 | oldHealth = -1; |
| 6092 | oldPlug = -1; |
| 6093 | oldTemp = -1; |
| 6094 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6095 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6098 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6099 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6100 | if (!checkin) { |
| 6101 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6102 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6103 | pw.print(" ("); |
| 6104 | pw.print(rec.numReadInts); |
| 6105 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6106 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6107 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6108 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6109 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6110 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6111 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6112 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6113 | } |
| 6114 | lastTime = rec.time; |
| 6115 | } |
| 6116 | if (rec.cmd == HistoryItem.CMD_START) { |
| 6117 | if (checkin) { |
| 6118 | pw.print(":"); |
| 6119 | } |
| 6120 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6121 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6122 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 6123 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6124 | if (checkin) { |
| 6125 | pw.print(":"); |
| 6126 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6127 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 6128 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6129 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6130 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6131 | pw.print("TIME:"); |
| 6132 | if (checkin) { |
| 6133 | pw.println(rec.currentTime); |
| 6134 | } else { |
| 6135 | pw.print(" "); |
| 6136 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6137 | rec.currentTime).toString()); |
| 6138 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6139 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 6140 | if (checkin) { |
| 6141 | pw.print(":"); |
| 6142 | } |
| 6143 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6144 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 6145 | if (checkin) { |
| 6146 | pw.print(":"); |
| 6147 | } |
| 6148 | pw.println("*OVERFLOW*"); |
| 6149 | } else { |
| 6150 | if (!checkin) { |
| 6151 | if (rec.batteryLevel < 10) pw.print("00"); |
| 6152 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 6153 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6154 | if (verbose) { |
| 6155 | pw.print(" "); |
| 6156 | if (rec.states < 0) ; |
| 6157 | else if (rec.states < 0x10) pw.print("0000000"); |
| 6158 | else if (rec.states < 0x100) pw.print("000000"); |
| 6159 | else if (rec.states < 0x1000) pw.print("00000"); |
| 6160 | else if (rec.states < 0x10000) pw.print("0000"); |
| 6161 | else if (rec.states < 0x100000) pw.print("000"); |
| 6162 | else if (rec.states < 0x1000000) pw.print("00"); |
| 6163 | else if (rec.states < 0x10000000) pw.print("0"); |
| 6164 | pw.print(Integer.toHexString(rec.states)); |
| 6165 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6166 | } else { |
| 6167 | if (oldLevel != rec.batteryLevel) { |
| 6168 | oldLevel = rec.batteryLevel; |
| 6169 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 6170 | } |
| 6171 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6172 | if (oldStatus != rec.batteryStatus) { |
| 6173 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6174 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6175 | switch (oldStatus) { |
| 6176 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6177 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6178 | break; |
| 6179 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6180 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6181 | break; |
| 6182 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6183 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6184 | break; |
| 6185 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6186 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6187 | break; |
| 6188 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6189 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6190 | break; |
| 6191 | default: |
| 6192 | pw.print(oldStatus); |
| 6193 | break; |
| 6194 | } |
| 6195 | } |
| 6196 | if (oldHealth != rec.batteryHealth) { |
| 6197 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6198 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6199 | switch (oldHealth) { |
| 6200 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6201 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6202 | break; |
| 6203 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6204 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6205 | break; |
| 6206 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6207 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6208 | break; |
| 6209 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6210 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6211 | break; |
| 6212 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6213 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6214 | break; |
| 6215 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6216 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6217 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6218 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 6219 | pw.print(checkin ? "c" : "cold"); |
| 6220 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6221 | default: |
| 6222 | pw.print(oldHealth); |
| 6223 | break; |
| 6224 | } |
| 6225 | } |
| 6226 | if (oldPlug != rec.batteryPlugType) { |
| 6227 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6228 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6229 | switch (oldPlug) { |
| 6230 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6231 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6232 | break; |
| 6233 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6234 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6235 | break; |
| 6236 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6237 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6238 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6239 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6240 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6241 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6242 | default: |
| 6243 | pw.print(oldPlug); |
| 6244 | break; |
| 6245 | } |
| 6246 | } |
| 6247 | if (oldTemp != rec.batteryTemperature) { |
| 6248 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6249 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6250 | pw.print(oldTemp); |
| 6251 | } |
| 6252 | if (oldVolt != rec.batteryVoltage) { |
| 6253 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6254 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6255 | pw.print(oldVolt); |
| 6256 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6257 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6258 | if (oldChargeMAh != chargeMAh) { |
| 6259 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6260 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6261 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6262 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6263 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6264 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6265 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 6266 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6267 | if (rec.wakeReasonTag != null) { |
| 6268 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6269 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6270 | pw.print(rec.wakeReasonTag.poolIdx); |
| 6271 | } else { |
| 6272 | pw.print(" wake_reason="); |
| 6273 | pw.print(rec.wakeReasonTag.uid); |
| 6274 | pw.print(":\""); |
| 6275 | pw.print(rec.wakeReasonTag.string); |
| 6276 | pw.print("\""); |
| 6277 | } |
| 6278 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6279 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6280 | pw.print(checkin ? "," : " "); |
| 6281 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 6282 | pw.print("+"); |
| 6283 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6284 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6285 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6286 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6287 | : HISTORY_EVENT_NAMES; |
| 6288 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6289 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6290 | if (idx >= 0 && idx < eventNames.length) { |
| 6291 | pw.print(eventNames[idx]); |
| 6292 | } else { |
| 6293 | pw.print(checkin ? "Ev" : "event"); |
| 6294 | pw.print(idx); |
| 6295 | } |
| 6296 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6297 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6298 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6299 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6300 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6301 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6302 | pw.print(":\""); |
| 6303 | pw.print(rec.eventTag.string); |
| 6304 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6305 | } |
| 6306 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6307 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6308 | if (rec.stepDetails != null) { |
| 6309 | if (!checkin) { |
| 6310 | pw.print(" Details: cpu="); |
| 6311 | pw.print(rec.stepDetails.userTime); |
| 6312 | pw.print("u+"); |
| 6313 | pw.print(rec.stepDetails.systemTime); |
| 6314 | pw.print("s"); |
| 6315 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6316 | pw.print(" ("); |
| 6317 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6318 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6319 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6320 | pw.print(", "); |
| 6321 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6322 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6323 | } |
| 6324 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6325 | pw.print(", "); |
| 6326 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6327 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6328 | } |
| 6329 | pw.print(')'); |
| 6330 | } |
| 6331 | pw.println(); |
| 6332 | pw.print(" /proc/stat="); |
| 6333 | pw.print(rec.stepDetails.statUserTime); |
| 6334 | pw.print(" usr, "); |
| 6335 | pw.print(rec.stepDetails.statSystemTime); |
| 6336 | pw.print(" sys, "); |
| 6337 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6338 | pw.print(" io, "); |
| 6339 | pw.print(rec.stepDetails.statIrqTime); |
| 6340 | pw.print(" irq, "); |
| 6341 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6342 | pw.print(" sirq, "); |
| 6343 | pw.print(rec.stepDetails.statIdlTime); |
| 6344 | pw.print(" idle"); |
| 6345 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6346 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6347 | + rec.stepDetails.statSoftIrqTime; |
| 6348 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6349 | if (total > 0) { |
| 6350 | pw.print(" ("); |
| 6351 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6352 | pw.print(String.format("%.1f%%", perc)); |
| 6353 | pw.print(" of "); |
| 6354 | StringBuilder sb = new StringBuilder(64); |
| 6355 | formatTimeMsNoSpace(sb, total*10); |
| 6356 | pw.print(sb); |
| 6357 | pw.print(")"); |
| 6358 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6359 | pw.print(", PlatformIdleStat "); |
| 6360 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6361 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6362 | |
| 6363 | pw.print(", SubsystemPowerState "); |
| 6364 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6365 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6366 | } else { |
| 6367 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6368 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6369 | pw.print(rec.stepDetails.userTime); |
| 6370 | pw.print(":"); |
| 6371 | pw.print(rec.stepDetails.systemTime); |
| 6372 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6373 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6374 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6375 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6376 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6377 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6378 | } |
| 6379 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6380 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6381 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6382 | } |
| 6383 | } |
| 6384 | pw.println(); |
| 6385 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6386 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6387 | pw.print(rec.stepDetails.statUserTime); |
| 6388 | pw.print(','); |
| 6389 | pw.print(rec.stepDetails.statSystemTime); |
| 6390 | pw.print(','); |
| 6391 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6392 | pw.print(','); |
| 6393 | pw.print(rec.stepDetails.statIrqTime); |
| 6394 | pw.print(','); |
| 6395 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6396 | pw.print(','); |
| 6397 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6398 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6399 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6400 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6401 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6402 | pw.print(','); |
| 6403 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6404 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6405 | |
| 6406 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6407 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6408 | } |
| 6409 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6410 | } |
| 6411 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6412 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6413 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6414 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6415 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6416 | |
| 6417 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6418 | UserHandle.formatUid(pw, uid); |
| 6419 | pw.print("="); |
| 6420 | pw.print(utime); |
| 6421 | pw.print("u+"); |
| 6422 | pw.print(stime); |
| 6423 | pw.print("s"); |
| 6424 | } |
| 6425 | |
| 6426 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6427 | pw.print('/'); |
| 6428 | pw.print(uid); |
| 6429 | pw.print(":"); |
| 6430 | pw.print(utime); |
| 6431 | pw.print(":"); |
| 6432 | pw.print(stime); |
| 6433 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6434 | } |
| 6435 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6436 | private void printSizeValue(PrintWriter pw, long size) { |
| 6437 | float result = size; |
| 6438 | String suffix = ""; |
| 6439 | if (result >= 10*1024) { |
| 6440 | suffix = "KB"; |
| 6441 | result = result / 1024; |
| 6442 | } |
| 6443 | if (result >= 10*1024) { |
| 6444 | suffix = "MB"; |
| 6445 | result = result / 1024; |
| 6446 | } |
| 6447 | if (result >= 10*1024) { |
| 6448 | suffix = "GB"; |
| 6449 | result = result / 1024; |
| 6450 | } |
| 6451 | if (result >= 10*1024) { |
| 6452 | suffix = "TB"; |
| 6453 | result = result / 1024; |
| 6454 | } |
| 6455 | if (result >= 10*1024) { |
| 6456 | suffix = "PB"; |
| 6457 | result = result / 1024; |
| 6458 | } |
| 6459 | pw.print((int)result); |
| 6460 | pw.print(suffix); |
| 6461 | } |
| 6462 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6463 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6464 | String label3, long estimatedTime) { |
| 6465 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6466 | return false; |
| 6467 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6468 | pw.print(label1); |
| 6469 | pw.print(label2); |
| 6470 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6471 | StringBuilder sb = new StringBuilder(64); |
| 6472 | formatTimeMs(sb, estimatedTime); |
| 6473 | pw.print(sb); |
| 6474 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6475 | return true; |
| 6476 | } |
| 6477 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6478 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6479 | LevelStepTracker steps, boolean checkin) { |
| 6480 | if (steps == null) { |
| 6481 | return false; |
| 6482 | } |
| 6483 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6484 | if (count <= 0) { |
| 6485 | return false; |
| 6486 | } |
| 6487 | if (!checkin) { |
| 6488 | pw.println(header); |
| 6489 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6490 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6491 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6492 | long duration = steps.getDurationAt(i); |
| 6493 | int level = steps.getLevelAt(i); |
| 6494 | long initMode = steps.getInitModeAt(i); |
| 6495 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6496 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6497 | lineArgs[0] = Long.toString(duration); |
| 6498 | lineArgs[1] = Integer.toString(level); |
| 6499 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6500 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6501 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6502 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6503 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6504 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6505 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6506 | } |
| 6507 | } else { |
| 6508 | lineArgs[2] = ""; |
| 6509 | } |
| 6510 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6511 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6512 | } else { |
| 6513 | lineArgs[3] = ""; |
| 6514 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6515 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6516 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6517 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6518 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6519 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6520 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6521 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6522 | pw.print(prefix); |
| 6523 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6524 | TimeUtils.formatDuration(duration, pw); |
| 6525 | pw.print(" to "); pw.print(level); |
| 6526 | boolean haveModes = false; |
| 6527 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6528 | pw.print(" ("); |
| 6529 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6530 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6531 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6532 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6533 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6534 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6535 | } |
| 6536 | haveModes = true; |
| 6537 | } |
| 6538 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6539 | pw.print(haveModes ? ", " : " ("); |
| 6540 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6541 | ? "power-save-on" : "power-save-off"); |
| 6542 | haveModes = true; |
| 6543 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6544 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6545 | pw.print(haveModes ? ", " : " ("); |
| 6546 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6547 | ? "device-idle-on" : "device-idle-off"); |
| 6548 | haveModes = true; |
| 6549 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6550 | if (haveModes) { |
| 6551 | pw.print(")"); |
| 6552 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6553 | pw.println(); |
| 6554 | } |
| 6555 | } |
| 6556 | return true; |
| 6557 | } |
| 6558 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6559 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6560 | LevelStepTracker steps) { |
| 6561 | if (steps == null) { |
| 6562 | return; |
| 6563 | } |
| 6564 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6565 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6566 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6567 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6568 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6569 | |
| 6570 | final long initMode = steps.getInitModeAt(i); |
| 6571 | final long modMode = steps.getModModeAt(i); |
| 6572 | |
| 6573 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6574 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6575 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6576 | case Display.STATE_OFF: |
| 6577 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6578 | break; |
| 6579 | case Display.STATE_ON: |
| 6580 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6581 | break; |
| 6582 | case Display.STATE_DOZE: |
| 6583 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6584 | break; |
| 6585 | case Display.STATE_DOZE_SUSPEND: |
| 6586 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6587 | break; |
| 6588 | default: |
| 6589 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6590 | break; |
| 6591 | } |
| 6592 | } |
| 6593 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6594 | |
| 6595 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6596 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6597 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6598 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6599 | } |
| 6600 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6601 | |
| 6602 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6603 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6604 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6605 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6606 | } |
| 6607 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6608 | |
| 6609 | proto.end(token); |
| 6610 | } |
| 6611 | } |
| 6612 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6613 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6614 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6615 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6616 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6617 | public static final int DUMP_VERBOSE = 1<<5; |
| 6618 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6619 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6620 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6621 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6622 | final HistoryItem rec = new HistoryItem(); |
| 6623 | long lastTime = -1; |
| 6624 | long baseTime = -1; |
| 6625 | boolean printed = false; |
| 6626 | HistoryEventTracker tracker = null; |
| 6627 | while (getNextHistoryLocked(rec)) { |
| 6628 | lastTime = rec.time; |
| 6629 | if (baseTime < 0) { |
| 6630 | baseTime = lastTime; |
| 6631 | } |
| 6632 | if (rec.time >= histStart) { |
| 6633 | if (histStart >= 0 && !printed) { |
| 6634 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6635 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6636 | || rec.cmd == HistoryItem.CMD_START |
| 6637 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6638 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6639 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6640 | (flags&DUMP_VERBOSE) != 0); |
| 6641 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6642 | } else if (rec.currentTime != 0) { |
| 6643 | printed = true; |
| 6644 | byte cmd = rec.cmd; |
| 6645 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6646 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6647 | (flags&DUMP_VERBOSE) != 0); |
| 6648 | rec.cmd = cmd; |
| 6649 | } |
| 6650 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6651 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6652 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6653 | (flags&DUMP_VERBOSE) != 0); |
| 6654 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6655 | } |
| 6656 | int oldEventCode = rec.eventCode; |
| 6657 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6658 | rec.eventTag = new HistoryTag(); |
| 6659 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6660 | HashMap<String, SparseIntArray> active |
| 6661 | = tracker.getStateForEvent(i); |
| 6662 | if (active == null) { |
| 6663 | continue; |
| 6664 | } |
| 6665 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6666 | : active.entrySet()) { |
| 6667 | SparseIntArray uids = ent.getValue(); |
| 6668 | for (int j=0; j<uids.size(); j++) { |
| 6669 | rec.eventCode = i; |
| 6670 | rec.eventTag.string = ent.getKey(); |
| 6671 | rec.eventTag.uid = uids.keyAt(j); |
| 6672 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6673 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6674 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6675 | rec.wakeReasonTag = null; |
| 6676 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6677 | } |
| 6678 | } |
| 6679 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6680 | rec.eventCode = oldEventCode; |
| 6681 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6682 | tracker = null; |
| 6683 | } |
| 6684 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6685 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6686 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6687 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6688 | // This is an attempt to aggregate the previous state and generate |
| 6689 | //Â fake events to reflect that state at the point where we start |
| 6690 | // 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] | 6691 | if (tracker == null) { |
| 6692 | tracker = new HistoryEventTracker(); |
| 6693 | } |
| 6694 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6695 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6696 | } |
| 6697 | } |
| 6698 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6699 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6700 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6701 | } |
| 6702 | } |
| 6703 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6704 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6705 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6706 | if (steps == null) { |
| 6707 | return; |
| 6708 | } |
| 6709 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6710 | if (timeRemaining >= 0) { |
| 6711 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6712 | tmpSb.setLength(0); |
| 6713 | formatTimeMs(tmpSb, timeRemaining); |
| 6714 | pw.print(tmpSb); |
| 6715 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6716 | pw.println(" steps)"); |
| 6717 | } |
| 6718 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6719 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6720 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6721 | if (estimatedTime > 0) { |
| 6722 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6723 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6724 | pw.print(" time: "); |
| 6725 | tmpSb.setLength(0); |
| 6726 | formatTimeMs(tmpSb, estimatedTime); |
| 6727 | pw.print(tmpSb); |
| 6728 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6729 | pw.println(" steps)"); |
| 6730 | } |
| 6731 | } |
| 6732 | } |
| 6733 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6734 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6735 | ArrayList<PackageChange> changes) { |
| 6736 | if (changes == null) { |
| 6737 | return; |
| 6738 | } |
| 6739 | pw.print(prefix); pw.println("Package changes:"); |
| 6740 | for (int i=0; i<changes.size(); i++) { |
| 6741 | PackageChange pc = changes.get(i); |
| 6742 | if (pc.mUpdate) { |
| 6743 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6744 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6745 | } else { |
| 6746 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6747 | } |
| 6748 | } |
| 6749 | } |
| 6750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | /** |
| 6752 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6753 | * |
| 6754 | * @param pw a Printer to receive the dump output. |
| 6755 | */ |
| 6756 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6757 | 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] | 6758 | prepareForDumpLocked(); |
| 6759 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6760 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6761 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6762 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6763 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6764 | final long historyTotalSize = getHistoryTotalSize(); |
| 6765 | final long historyUsedSize = getHistoryUsedSize(); |
| 6766 | if (startIteratingHistoryLocked()) { |
| 6767 | try { |
| 6768 | pw.print("Battery History ("); |
| 6769 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6770 | pw.print("% used, "); |
| 6771 | printSizeValue(pw, historyUsedSize); |
| 6772 | pw.print(" used of "); |
| 6773 | printSizeValue(pw, historyTotalSize); |
| 6774 | pw.print(", "); |
| 6775 | pw.print(getHistoryStringPoolSize()); |
| 6776 | pw.print(" strings using "); |
| 6777 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6778 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6779 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6780 | pw.println(); |
| 6781 | } finally { |
| 6782 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6783 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | if (startIteratingOldHistoryLocked()) { |
| 6787 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6788 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6789 | pw.println("Old battery History:"); |
| 6790 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6791 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6792 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6793 | if (baseTime < 0) { |
| 6794 | baseTime = rec.time; |
| 6795 | } |
| 6796 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6797 | } |
| 6798 | pw.println(); |
| 6799 | } finally { |
| 6800 | finishIteratingOldHistoryLocked(); |
| 6801 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6802 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6803 | } |
| 6804 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6805 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6806 | return; |
| 6807 | } |
| 6808 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6809 | if (!filtering) { |
| 6810 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6811 | final int NU = uidStats.size(); |
| 6812 | boolean didPid = false; |
| 6813 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6814 | for (int i=0; i<NU; i++) { |
| 6815 | Uid uid = uidStats.valueAt(i); |
| 6816 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6817 | if (pids != null) { |
| 6818 | for (int j=0; j<pids.size(); j++) { |
| 6819 | Uid.Pid pid = pids.valueAt(j); |
| 6820 | if (!didPid) { |
| 6821 | pw.println("Per-PID Stats:"); |
| 6822 | didPid = true; |
| 6823 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6824 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6825 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6826 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6827 | pw.print(" wake time: "); |
| 6828 | TimeUtils.formatDuration(time, pw); |
| 6829 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6830 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6831 | } |
| 6832 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6833 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6834 | pw.println(); |
| 6835 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6836 | } |
| 6837 | |
| 6838 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6839 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6840 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6841 | long timeRemaining = computeBatteryTimeRemaining( |
| 6842 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6843 | if (timeRemaining >= 0) { |
| 6844 | pw.print(" Estimated discharge time remaining: "); |
| 6845 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6846 | pw.println(); |
| 6847 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6848 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6849 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6850 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6851 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6852 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6853 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6854 | pw.println(); |
| 6855 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6856 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6857 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6858 | long timeRemaining = computeChargeTimeRemaining( |
| 6859 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6860 | if (timeRemaining >= 0) { |
| 6861 | pw.print(" Estimated charge time remaining: "); |
| 6862 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6863 | pw.println(); |
| 6864 | } |
| 6865 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6866 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6867 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6868 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6869 | pw.println("Daily stats:"); |
| 6870 | pw.print(" Current start time: "); |
| 6871 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6872 | getCurrentDailyStartTime()).toString()); |
| 6873 | pw.print(" Next min deadline: "); |
| 6874 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6875 | getNextMinDailyDeadline()).toString()); |
| 6876 | pw.print(" Next max deadline: "); |
| 6877 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6878 | getNextMaxDailyDeadline()).toString()); |
| 6879 | StringBuilder sb = new StringBuilder(64); |
| 6880 | int[] outInt = new int[1]; |
| 6881 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6882 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6883 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6884 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6885 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6886 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6887 | dsteps, false)) { |
| 6888 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6889 | sb, outInt); |
| 6890 | } |
| 6891 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6892 | csteps, false)) { |
| 6893 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6894 | sb, outInt); |
| 6895 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6896 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6897 | } else { |
| 6898 | pw.println(" Current daily steps:"); |
| 6899 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6900 | sb, outInt); |
| 6901 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6902 | sb, outInt); |
| 6903 | } |
| 6904 | } |
| 6905 | DailyItem dit; |
| 6906 | int curIndex = 0; |
| 6907 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6908 | curIndex++; |
| 6909 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6910 | pw.println(); |
| 6911 | } |
| 6912 | pw.print(" Daily from "); |
| 6913 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6914 | pw.print(" to "); |
| 6915 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6916 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6917 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6918 | if (dumpDurationSteps(pw, " ", |
| 6919 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6920 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6921 | sb, outInt); |
| 6922 | } |
| 6923 | if (dumpDurationSteps(pw, " ", |
| 6924 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6925 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6926 | sb, outInt); |
| 6927 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6928 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6929 | } else { |
| 6930 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6931 | sb, outInt); |
| 6932 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6933 | sb, outInt); |
| 6934 | } |
| 6935 | } |
| 6936 | pw.println(); |
| 6937 | } |
| 6938 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6939 | pw.println("Statistics since last charge:"); |
| 6940 | pw.println(" System starts: " + getStartCount() |
| 6941 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6942 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6943 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6944 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6947 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6948 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6950 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6951 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6952 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6953 | |
| 6954 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6955 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6956 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6957 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6958 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6959 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6960 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6961 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6962 | try { |
| 6963 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6964 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6965 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6966 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6967 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6968 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6969 | pw.print(",\""); |
| 6970 | String str = getHistoryTagPoolString(i); |
| 6971 | str = str.replace("\\", "\\\\"); |
| 6972 | str = str.replace("\"", "\\\""); |
| 6973 | pw.print(str); |
| 6974 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6975 | pw.println(); |
| 6976 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6977 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6978 | } finally { |
| 6979 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6980 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6981 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6984 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6985 | return; |
| 6986 | } |
| 6987 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6988 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6989 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6990 | for (int i=0; i<apps.size(); i++) { |
| 6991 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6992 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6993 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6994 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6995 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6996 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6997 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6998 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6999 | } |
| 7000 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7001 | final int NU = uidStats.size(); |
| 7002 | String[] lineArgs = new String[2]; |
| 7003 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7004 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 7005 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 7006 | if (pkgs != null && !pkgs.second.value) { |
| 7007 | pkgs.second.value = true; |
| 7008 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7009 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 7010 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7011 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 7012 | (Object[])lineArgs); |
| 7013 | } |
| 7014 | } |
| 7015 | } |
| 7016 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7017 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7018 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7019 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 7020 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7021 | if (timeRemaining >= 0) { |
| 7022 | lineArgs[0] = Long.toString(timeRemaining); |
| 7023 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 7024 | (Object[])lineArgs); |
| 7025 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7026 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 7027 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 7028 | if (timeRemaining >= 0) { |
| 7029 | lineArgs[0] = Long.toString(timeRemaining); |
| 7030 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 7031 | (Object[])lineArgs); |
| 7032 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7033 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 7034 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 7035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7037 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7038 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7039 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 7040 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7041 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 7042 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 7043 | prepareForDumpLocked(); |
| 7044 | |
| 7045 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 7046 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 7047 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 7048 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 7049 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 7050 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7051 | |
| 7052 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7053 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 7054 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 7055 | helper.create(this); |
| 7056 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 7057 | |
| 7058 | dumpProtoAppsLocked(proto, helper, apps); |
| 7059 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | proto.end(bToken); |
| 7063 | proto.flush(); |
| 7064 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7065 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7066 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 7067 | List<ApplicationInfo> apps) { |
| 7068 | final int which = STATS_SINCE_CHARGED; |
| 7069 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7070 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7071 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7072 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 7073 | |
| 7074 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 7075 | if (apps != null) { |
| 7076 | for (int i = 0; i < apps.size(); ++i) { |
| 7077 | ApplicationInfo ai = apps.get(i); |
| 7078 | int aid = UserHandle.getAppId(ai.uid); |
| 7079 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 7080 | if (pkgs == null) { |
| 7081 | pkgs = new ArrayList<String>(); |
| 7082 | aidToPackages.put(aid, pkgs); |
| 7083 | } |
| 7084 | pkgs.add(ai.packageName); |
| 7085 | } |
| 7086 | } |
| 7087 | |
| 7088 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 7089 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7090 | if (sippers != null) { |
| 7091 | for (int i = 0; i < sippers.size(); ++i) { |
| 7092 | final BatterySipper bs = sippers.get(i); |
| 7093 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 7094 | // Others are handled by dumpProtoSystemLocked() |
| 7095 | continue; |
| 7096 | } |
| 7097 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7102 | final int n = uidStats.size(); |
| 7103 | for (int iu = 0; iu < n; ++iu) { |
| 7104 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 7105 | final Uid u = uidStats.valueAt(iu); |
| 7106 | |
| 7107 | final int uid = uidStats.keyAt(iu); |
| 7108 | proto.write(UidProto.UID, uid); |
| 7109 | |
| 7110 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 7111 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 7112 | if (pkgs == null) { |
| 7113 | pkgs = new ArrayList<String>(); |
| 7114 | } |
| 7115 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 7116 | u.getPackageStats(); |
| 7117 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7118 | String pkg = packageStats.keyAt(ipkg); |
| 7119 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 7120 | packageStats.valueAt(ipkg).getServiceStats(); |
| 7121 | if (serviceStats.size() == 0) { |
| 7122 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 7123 | // example, "android") may be included in the packageStats that aren't part of |
| 7124 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 7125 | // These packages won't be a part in the pkgs List. |
| 7126 | continue; |
| 7127 | } |
| 7128 | |
| 7129 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7130 | proto.write(UidProto.Package.NAME, pkg); |
| 7131 | // Remove from the packages list since we're logging it here. |
| 7132 | pkgs.remove(pkg); |
| 7133 | |
| 7134 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 7135 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 7136 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 7137 | |
| 7138 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 7139 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 7140 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 7141 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 7142 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 7143 | |
| 7144 | proto.end(sToken); |
| 7145 | } |
| 7146 | proto.end(pToken); |
| 7147 | } |
| 7148 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 7149 | // from PackageManager data. Packages are only included in packageStats if there was |
| 7150 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 7151 | for (String p : pkgs) { |
| 7152 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7153 | proto.write(UidProto.Package.NAME, p); |
| 7154 | proto.end(pToken); |
| 7155 | } |
| 7156 | |
| 7157 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 7158 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 7159 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 7160 | // Times are since reset (regardless of 'which') |
| 7161 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 7162 | final Timer bgTimer = timer.getSubTimer(); |
| 7163 | final long bgTimeMs = bgTimer != null |
| 7164 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 7165 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 7166 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 7167 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 7168 | proto.end(awToken); |
| 7169 | } |
| 7170 | |
| 7171 | // Audio (AUDIO_DATA) |
| 7172 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7173 | |
| 7174 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7175 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7176 | u.getBluetoothControllerActivity(), which); |
| 7177 | |
| 7178 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7179 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7180 | if (bleTimer != null) { |
| 7181 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7182 | |
| 7183 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7184 | rawRealtimeUs, which); |
| 7185 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7186 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7187 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7188 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7189 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7190 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7191 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7192 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7193 | // Result counters |
| 7194 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7195 | u.getBluetoothScanResultCounter() != null |
| 7196 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7197 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7198 | u.getBluetoothScanResultBgCounter() != null |
| 7199 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7200 | |
| 7201 | proto.end(bmToken); |
| 7202 | } |
| 7203 | |
| 7204 | // Camera (CAMERA_DATA) |
| 7205 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7206 | |
| 7207 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7208 | final long cpuToken = proto.start(UidProto.CPU); |
| 7209 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7210 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7211 | |
| 7212 | final long[] cpuFreqs = getCpuFreqs(); |
| 7213 | if (cpuFreqs != null) { |
| 7214 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7215 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7216 | // screenOffCpuFreqTimes. |
| 7217 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7218 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7219 | if (screenOffCpuFreqTimeMs == null) { |
| 7220 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7221 | } |
| 7222 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7223 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7224 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7225 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7226 | cpuFreqTimeMs[ic]); |
| 7227 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7228 | screenOffCpuFreqTimeMs[ic]); |
| 7229 | proto.end(cToken); |
| 7230 | } |
| 7231 | } |
| 7232 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7233 | |
| 7234 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7235 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7236 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7237 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7238 | if (screenOffTimesMs == null) { |
| 7239 | screenOffTimesMs = new long[timesMs.length]; |
| 7240 | } |
| 7241 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7242 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7243 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7244 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7245 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7246 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7247 | timesMs[ic]); |
| 7248 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7249 | screenOffTimesMs[ic]); |
| 7250 | proto.end(cToken); |
| 7251 | } |
| 7252 | proto.end(procToken); |
| 7253 | } |
| 7254 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7255 | proto.end(cpuToken); |
| 7256 | |
| 7257 | // Flashlight (FLASHLIGHT_DATA) |
| 7258 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7259 | rawRealtimeUs, which); |
| 7260 | |
| 7261 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7262 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7263 | rawRealtimeUs, which); |
| 7264 | |
| 7265 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7266 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7267 | rawRealtimeUs, which); |
| 7268 | |
| 7269 | // Job completion (JOB_COMPLETION_DATA) |
| 7270 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7271 | final int[] reasons = new int[]{ |
| 7272 | JobParameters.REASON_CANCELED, |
| 7273 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7274 | JobParameters.REASON_PREEMPT, |
| 7275 | JobParameters.REASON_TIMEOUT, |
| 7276 | JobParameters.REASON_DEVICE_IDLE, |
| 7277 | }; |
| 7278 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7279 | SparseIntArray types = completions.valueAt(ic); |
| 7280 | if (types != null) { |
| 7281 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7282 | |
| 7283 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7284 | |
| 7285 | for (int r : reasons) { |
| 7286 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7287 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7288 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7289 | proto.end(rToken); |
| 7290 | } |
| 7291 | |
| 7292 | proto.end(jcToken); |
| 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | // Scheduled jobs (JOB_DATA) |
| 7297 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7298 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7299 | final Timer timer = jobs.valueAt(ij); |
| 7300 | final Timer bgTimer = timer.getSubTimer(); |
| 7301 | final long jToken = proto.start(UidProto.JOBS); |
| 7302 | |
| 7303 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7304 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7305 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7306 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7307 | |
| 7308 | proto.end(jToken); |
| 7309 | } |
| 7310 | |
| 7311 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7312 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7313 | u.getModemControllerActivity(), which); |
| 7314 | |
| 7315 | // Network stats (NETWORK_DATA) |
| 7316 | final long nToken = proto.start(UidProto.NETWORK); |
| 7317 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7318 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7319 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7320 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7321 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7322 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7323 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7324 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7325 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7326 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7327 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7328 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7329 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7330 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7331 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7332 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7333 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7334 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7335 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7336 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7337 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7338 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7339 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7340 | u.getMobileRadioActiveCount(which)); |
| 7341 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7342 | u.getMobileRadioApWakeupCount(which)); |
| 7343 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7344 | u.getWifiRadioApWakeupCount(which)); |
| 7345 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7346 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7347 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7348 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7349 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7350 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7351 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7352 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7353 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7354 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7355 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7356 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7357 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7358 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7359 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7360 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7361 | proto.end(nToken); |
| 7362 | |
| 7363 | // Power use item (POWER_USE_ITEM_DATA) |
| 7364 | BatterySipper bs = uidToSipper.get(uid); |
| 7365 | if (bs != null) { |
| 7366 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7367 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7368 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7369 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7370 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7371 | bs.proportionalSmearMah); |
| 7372 | proto.end(bsToken); |
| 7373 | } |
| 7374 | |
| 7375 | // Processes (PROCESS_DATA) |
| 7376 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7377 | u.getProcessStats(); |
| 7378 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7379 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7380 | final long prToken = proto.start(UidProto.PROCESS); |
| 7381 | |
| 7382 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7383 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7384 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7385 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7386 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7387 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7388 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7389 | |
| 7390 | proto.end(prToken); |
| 7391 | } |
| 7392 | |
| 7393 | // Sensors (SENSOR_DATA) |
| 7394 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7395 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7396 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7397 | final Timer timer = se.getSensorTime(); |
| 7398 | if (timer == null) { |
| 7399 | continue; |
| 7400 | } |
| 7401 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7402 | final int sensorNumber = sensors.keyAt(ise); |
| 7403 | final long seToken = proto.start(UidProto.SENSORS); |
| 7404 | |
| 7405 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7406 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7407 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7408 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7409 | |
| 7410 | proto.end(seToken); |
| 7411 | } |
| 7412 | |
| 7413 | // State times (STATE_TIME_DATA) |
| 7414 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7415 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7416 | if (durMs == 0) { |
| 7417 | continue; |
| 7418 | } |
| 7419 | final long stToken = proto.start(UidProto.STATES); |
| 7420 | proto.write(UidProto.StateTime.STATE, ips); |
| 7421 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7422 | proto.end(stToken); |
| 7423 | } |
| 7424 | |
| 7425 | // Syncs (SYNC_DATA) |
| 7426 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7427 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7428 | final Timer timer = syncs.valueAt(isy); |
| 7429 | final Timer bgTimer = timer.getSubTimer(); |
| 7430 | final long syToken = proto.start(UidProto.SYNCS); |
| 7431 | |
| 7432 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7433 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7434 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7435 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7436 | |
| 7437 | proto.end(syToken); |
| 7438 | } |
| 7439 | |
| 7440 | // User activity (USER_ACTIVITY_DATA) |
| 7441 | if (u.hasUserActivity()) { |
| 7442 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7443 | int val = u.getUserActivityCount(i, which); |
| 7444 | if (val != 0) { |
| 7445 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7446 | proto.write(UidProto.UserActivity.NAME, i); |
| 7447 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7448 | proto.end(uaToken); |
| 7449 | } |
| 7450 | } |
| 7451 | } |
| 7452 | |
| 7453 | // Vibrator (VIBRATOR_DATA) |
| 7454 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7455 | |
| 7456 | // Video (VIDEO_DATA) |
| 7457 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7458 | |
| 7459 | // Wakelocks (WAKELOCK_DATA) |
| 7460 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7461 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7462 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7463 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7464 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7465 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7466 | rawRealtimeUs, which); |
| 7467 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7468 | if (pTimer != null) { |
| 7469 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7470 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7471 | rawRealtimeUs, which); |
| 7472 | } |
| 7473 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7474 | rawRealtimeUs, which); |
| 7475 | proto.end(wToken); |
| 7476 | } |
| 7477 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7478 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7479 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7480 | rawRealtimeUs, which); |
| 7481 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7482 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7483 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7484 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7485 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7486 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7487 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7488 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7489 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7490 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7491 | proto.end(waToken); |
| 7492 | } |
| 7493 | } |
| 7494 | |
| 7495 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7496 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7497 | u.getWifiControllerActivity(), which); |
| 7498 | |
| 7499 | // Wifi data (WIFI_DATA) |
| 7500 | final long wToken = proto.start(UidProto.WIFI); |
| 7501 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7502 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7503 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7504 | rawRealtimeUs, which); |
| 7505 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7506 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7507 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7508 | rawRealtimeUs, which); |
| 7509 | proto.end(wToken); |
| 7510 | |
| 7511 | proto.end(uTkn); |
| 7512 | } |
| 7513 | } |
| 7514 | |
| 7515 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7516 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7517 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7518 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7519 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7520 | final int which = STATS_SINCE_CHARGED; |
| 7521 | |
| 7522 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7523 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7524 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7525 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7526 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7527 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7528 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7529 | computeUptime(rawUptimeUs, which) / 1000); |
| 7530 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7531 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7532 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7533 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7534 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7535 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7536 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7537 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7538 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7539 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7540 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7541 | getEstimatedBatteryCapacity()); |
| 7542 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7543 | getMinLearnedBatteryCapacity()); |
| 7544 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7545 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7546 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7547 | |
| 7548 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7549 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7550 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7551 | getLowDischargeAmountSinceCharge()); |
| 7552 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7553 | getHighDischargeAmountSinceCharge()); |
| 7554 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7555 | getDischargeAmountScreenOnSinceCharge()); |
| 7556 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7557 | getDischargeAmountScreenOffSinceCharge()); |
| 7558 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7559 | getDischargeAmountScreenDozeSinceCharge()); |
| 7560 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7561 | getUahDischarge(which) / 1000); |
| 7562 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7563 | getUahDischargeScreenOff(which) / 1000); |
| 7564 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7565 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7566 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7567 | getUahDischargeLightDoze(which) / 1000); |
| 7568 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7569 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7570 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7571 | |
| 7572 | // Time remaining |
| 7573 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7574 | // 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] | 7575 | if (timeRemainingUs >= 0) { |
| 7576 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7577 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7578 | } else { |
| 7579 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7580 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7581 | if (timeRemainingUs >= 0) { |
| 7582 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7583 | } else { |
| 7584 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7585 | } |
| 7586 | } |
| 7587 | |
| 7588 | // Charge step (CHARGE_STEP_DATA) |
| 7589 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7590 | |
| 7591 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7592 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7593 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7594 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7595 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7596 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7597 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7601 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7602 | |
| 7603 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7604 | final long[] cpuFreqs = getCpuFreqs(); |
| 7605 | if (cpuFreqs != null) { |
| 7606 | for (long i : cpuFreqs) { |
| 7607 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7608 | } |
| 7609 | } |
| 7610 | |
| 7611 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7612 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7613 | getBluetoothControllerActivity(), which); |
| 7614 | |
| 7615 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7616 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7617 | getModemControllerActivity(), which); |
| 7618 | |
| 7619 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7620 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7621 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7622 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7623 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7624 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7625 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7626 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7627 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7628 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7629 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7630 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7631 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7632 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7633 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7634 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7635 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7636 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7637 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7638 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7639 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7640 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7641 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7642 | |
| 7643 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7644 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7645 | getWifiControllerActivity(), which); |
| 7646 | |
| 7647 | |
| 7648 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7649 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7650 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7651 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7652 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7653 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7654 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7655 | |
| 7656 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7657 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7658 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7659 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7660 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7661 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7662 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7663 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | // Misc (MISC_DATA) |
| 7667 | // Calculate wakelock times across all uids. |
| 7668 | long fullWakeLockTimeTotalUs = 0; |
| 7669 | long partialWakeLockTimeTotalUs = 0; |
| 7670 | |
| 7671 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7672 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7673 | final Uid u = uidStats.valueAt(iu); |
| 7674 | |
| 7675 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7676 | u.getWakelockStats(); |
| 7677 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7678 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7679 | |
| 7680 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7681 | if (fullWakeTimer != null) { |
| 7682 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7683 | which); |
| 7684 | } |
| 7685 | |
| 7686 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7687 | if (partialWakeTimer != null) { |
| 7688 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7689 | rawRealtimeUs, which); |
| 7690 | } |
| 7691 | } |
| 7692 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7693 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7694 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7695 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7696 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7697 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7698 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7699 | fullWakeLockTimeTotalUs / 1000); |
| 7700 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7701 | partialWakeLockTimeTotalUs / 1000); |
| 7702 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7703 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7704 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7705 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7706 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7707 | getMobileRadioActiveCount(which)); |
| 7708 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7709 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7710 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7711 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7712 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7713 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7714 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7715 | getNumConnectivityChange(which)); |
| 7716 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7717 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7718 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7719 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7720 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7721 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7722 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7723 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7724 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7725 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7726 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7727 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7728 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7729 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7730 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7731 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7732 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7733 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7734 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7735 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7736 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7737 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7738 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7739 | final long multicastWakeLockTimeTotalUs = |
| 7740 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7741 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7742 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7743 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7744 | multicastWakeLockTimeTotalUs / 1000); |
| 7745 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7746 | multicastWakeLockCountTotal); |
| 7747 | proto.end(wmctToken); |
| 7748 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7749 | // Power use item (POWER_USE_ITEM_DATA) |
| 7750 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7751 | if (sippers != null) { |
| 7752 | for (int i = 0; i < sippers.size(); ++i) { |
| 7753 | final BatterySipper bs = sippers.get(i); |
| 7754 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7755 | int uid = 0; |
| 7756 | switch (bs.drainType) { |
| 7757 | case IDLE: |
| 7758 | n = SystemProto.PowerUseItem.IDLE; |
| 7759 | break; |
| 7760 | case CELL: |
| 7761 | n = SystemProto.PowerUseItem.CELL; |
| 7762 | break; |
| 7763 | case PHONE: |
| 7764 | n = SystemProto.PowerUseItem.PHONE; |
| 7765 | break; |
| 7766 | case WIFI: |
| 7767 | n = SystemProto.PowerUseItem.WIFI; |
| 7768 | break; |
| 7769 | case BLUETOOTH: |
| 7770 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7771 | break; |
| 7772 | case SCREEN: |
| 7773 | n = SystemProto.PowerUseItem.SCREEN; |
| 7774 | break; |
| 7775 | case FLASHLIGHT: |
| 7776 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7777 | break; |
| 7778 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7779 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7780 | continue; |
| 7781 | case USER: |
| 7782 | n = SystemProto.PowerUseItem.USER; |
| 7783 | uid = UserHandle.getUid(bs.userId, 0); |
| 7784 | break; |
| 7785 | case UNACCOUNTED: |
| 7786 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7787 | break; |
| 7788 | case OVERCOUNTED: |
| 7789 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7790 | break; |
| 7791 | case CAMERA: |
| 7792 | n = SystemProto.PowerUseItem.CAMERA; |
| 7793 | break; |
| 7794 | case MEMORY: |
| 7795 | n = SystemProto.PowerUseItem.MEMORY; |
| 7796 | break; |
| 7797 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7798 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7799 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7800 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7801 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7802 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7803 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7804 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7805 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7806 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7807 | } |
| 7808 | } |
| 7809 | |
| 7810 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7811 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7812 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7813 | helper.getPowerProfile().getBatteryCapacity()); |
| 7814 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7815 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7816 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7817 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7818 | |
| 7819 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7820 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7821 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7822 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7823 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7824 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7825 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7826 | ent.getValue(), rawRealtimeUs, which); |
| 7827 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7828 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7829 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7830 | } |
| 7831 | |
| 7832 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7833 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7834 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7835 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7836 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7837 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7838 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7839 | } |
| 7840 | |
| 7841 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7842 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7843 | which); |
| 7844 | |
| 7845 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7846 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7847 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7848 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7849 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7850 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7851 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7852 | } |
| 7853 | |
| 7854 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7855 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7856 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7857 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7858 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7859 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7860 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7861 | } |
| 7862 | |
| 7863 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7864 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7865 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7866 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7867 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7868 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7869 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7873 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7874 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7875 | proto.write(SystemProto.WifiState.NAME, i); |
| 7876 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7877 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7878 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7879 | } |
| 7880 | |
| 7881 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7882 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7883 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7884 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7885 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7886 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7887 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7888 | } |
| 7889 | |
| 7890 | proto.end(sToken); |
| 7891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | } |