Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 19 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 22 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 23 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 24 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 25 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 26 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 27 | import android.util.MutableBoolean; |
| 28 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.util.Printer; |
| 30 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 31 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 32 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 33 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 35 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 36 | import com.android.internal.os.BatterySipper; |
| 37 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 39 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 40 | import java.io.PrintWriter; |
| 41 | import java.util.ArrayList; |
| 42 | import java.util.Collections; |
| 43 | import java.util.Comparator; |
| 44 | import java.util.Formatter; |
| 45 | import java.util.HashMap; |
| 46 | import java.util.List; |
| 47 | import java.util.Map; |
| 48 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | /** |
| 50 | * A class providing access to battery usage statistics, including information on |
| 51 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 52 | * except where indicated otherwise. |
| 53 | * @hide |
| 54 | */ |
| 55 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 56 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 59 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 60 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 61 | |
| 62 | /** @hide */ |
| 63 | public static final String SERVICE_NAME = "batterystats"; |
| 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | /** |
| 66 | * A constant indicating a partial wake lock timer. |
| 67 | */ |
| 68 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 69 | |
| 70 | /** |
| 71 | * A constant indicating a full wake lock timer. |
| 72 | */ |
| 73 | public static final int WAKE_TYPE_FULL = 1; |
| 74 | |
| 75 | /** |
| 76 | * A constant indicating a window wake lock timer. |
| 77 | */ |
| 78 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | /** |
| 81 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | */ |
| 83 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 85 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 86 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 87 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 88 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 89 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 90 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 91 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 92 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 93 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 94 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 95 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 96 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 97 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 98 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 100 | /** |
| 101 | * A constant indicating a wifi multicast timer |
| 102 | */ |
| 103 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 106 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 107 | */ |
| 108 | public static final int VIDEO_TURNED_ON = 8; |
| 109 | |
| 110 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 111 | * A constant indicating a vibrator on timer |
| 112 | */ |
| 113 | public static final int VIBRATOR_ON = 9; |
| 114 | |
| 115 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 116 | * A constant indicating a foreground activity timer |
| 117 | */ |
| 118 | public static final int FOREGROUND_ACTIVITY = 10; |
| 119 | |
| 120 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 121 | * A constant indicating a wifi batched scan is active |
| 122 | */ |
| 123 | public static final int WIFI_BATCHED_SCAN = 11; |
| 124 | |
| 125 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 126 | * A constant indicating a process state timer |
| 127 | */ |
| 128 | public static final int PROCESS_STATE = 12; |
| 129 | |
| 130 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 131 | * A constant indicating a sync timer |
| 132 | */ |
| 133 | public static final int SYNC = 13; |
| 134 | |
| 135 | /** |
| 136 | * A constant indicating a job timer |
| 137 | */ |
| 138 | public static final int JOB = 14; |
| 139 | |
| 140 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 141 | * A constant indicating an audio turn on timer |
| 142 | */ |
| 143 | public static final int AUDIO_TURNED_ON = 15; |
| 144 | |
| 145 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 146 | * A constant indicating a flashlight turn on timer |
| 147 | */ |
| 148 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 149 | |
| 150 | /** |
| 151 | * A constant indicating a camera turn on timer |
| 152 | */ |
| 153 | public static final int CAMERA_TURNED_ON = 17; |
| 154 | |
| 155 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 156 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 157 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 158 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 161 | * A constant indicating a bluetooth scan timer. |
| 162 | */ |
| 163 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 164 | |
| 165 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 166 | * A constant indicating an aggregated partial wake lock timer. |
| 167 | */ |
| 168 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 169 | |
| 170 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 171 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 172 | */ |
| 173 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 174 | |
| 175 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 176 | * A constant indicating a foreground service timer |
| 177 | */ |
| 178 | public static final int FOREGROUND_SERVICE = 22; |
| 179 | |
| 180 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * Include all of the data in the stats, including previously saved data. |
| 182 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 183 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | * Include only the current run in the stats. |
| 187 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 188 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Include only the run since the last time the device was unplugged in the stats. |
| 192 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 193 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 194 | |
| 195 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 196 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 197 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 198 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 201 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 202 | * |
| 203 | * New in version 19: |
| 204 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 205 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 206 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 207 | * New in version 21: |
| 208 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 209 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 210 | * - BLE scan result count |
| 211 | * - CPU frequency time per uid |
| 212 | * New in version 22: |
| 213 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 214 | * - Background partial wakelock time & count |
| 215 | * New in version 23: |
| 216 | * - Logging smeared power model values |
| 217 | * New in version 24: |
| 218 | * - Fixed bugs in background timers and BLE scan time |
| 219 | * New in version 25: |
| 220 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 221 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 222 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 223 | * New in version 27: |
| 224 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 225 | * New in version 28: |
| 226 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 227 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame^] | 228 | * New in version 29: |
| 229 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 230 | * - CPU times per UID process state |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 231 | */ |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame^] | 232 | static final int CHECKIN_VERSION = 29; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * 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] | 236 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 237 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 238 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 239 | private static final long BYTES_PER_KB = 1024; |
| 240 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 241 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 242 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 243 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 244 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 245 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 247 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 248 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 249 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 250 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 251 | // rpm line is: |
| 252 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 253 | // screen-off time, screen-off count |
| 254 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 255 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 256 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 257 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 258 | // fgs line is: |
| 259 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 260 | // foreground service time, count |
| 261 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 262 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 263 | // wl line is: |
| 264 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 265 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 266 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 267 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 268 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 269 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 270 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 271 | // awl line is: |
| 272 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 273 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 274 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 275 | private static final String SYNC_DATA = "sy"; |
| 276 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 277 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 278 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 279 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 280 | private static final String NETWORK_DATA = "nt"; |
| 281 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 282 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 283 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 284 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 285 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 286 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 287 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 288 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 289 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 290 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 291 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 292 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 293 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 294 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 295 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 296 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 297 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 298 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 299 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 300 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 301 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 302 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 303 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 304 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 305 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 306 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 307 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 308 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 309 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 310 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 311 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 312 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 313 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 314 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 315 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 316 | private static final String FLASHLIGHT_DATA = "fla"; |
| 317 | private static final String CAMERA_DATA = "cam"; |
| 318 | private static final String VIDEO_DATA = "vid"; |
| 319 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 320 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 321 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 323 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 324 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 325 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 327 | |
| 328 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 329 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 330 | * |
| 331 | * Other types might include times spent in foreground, background etc. |
| 332 | */ |
| 333 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 334 | |
| 335 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 336 | * State for keeping track of counting information. |
| 337 | */ |
| 338 | public static abstract class Counter { |
| 339 | |
| 340 | /** |
| 341 | * Returns the count associated with this Counter for the |
| 342 | * selected type of statistics. |
| 343 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 344 | * @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] | 345 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 346 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * Temporary for debugging. |
| 350 | */ |
| 351 | public abstract void logState(Printer pw, String prefix); |
| 352 | } |
| 353 | |
| 354 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 355 | * State for keeping track of long counting information. |
| 356 | */ |
| 357 | public static abstract class LongCounter { |
| 358 | |
| 359 | /** |
| 360 | * Returns the count associated with this Counter for the |
| 361 | * selected type of statistics. |
| 362 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 363 | * @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] | 364 | */ |
| 365 | public abstract long getCountLocked(int which); |
| 366 | |
| 367 | /** |
| 368 | * Temporary for debugging. |
| 369 | */ |
| 370 | public abstract void logState(Printer pw, String prefix); |
| 371 | } |
| 372 | |
| 373 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 374 | * State for keeping track of array of long counting information. |
| 375 | */ |
| 376 | public static abstract class LongCounterArray { |
| 377 | /** |
| 378 | * Returns the counts associated with this Counter for the |
| 379 | * selected type of statistics. |
| 380 | * |
| 381 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 382 | */ |
| 383 | public abstract long[] getCountsLocked(int which); |
| 384 | |
| 385 | /** |
| 386 | * Temporary for debugging. |
| 387 | */ |
| 388 | public abstract void logState(Printer pw, String prefix); |
| 389 | } |
| 390 | |
| 391 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 392 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 393 | * radio controller. |
| 394 | */ |
| 395 | public static abstract class ControllerActivityCounter { |
| 396 | /** |
| 397 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 398 | * idle state. |
| 399 | */ |
| 400 | public abstract LongCounter getIdleTimeCounter(); |
| 401 | |
| 402 | /** |
| 403 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 404 | * receive state. |
| 405 | */ |
| 406 | public abstract LongCounter getRxTimeCounter(); |
| 407 | |
| 408 | /** |
| 409 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 410 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 411 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 412 | * various transmit level states. |
| 413 | */ |
| 414 | public abstract LongCounter[] getTxTimeCounters(); |
| 415 | |
| 416 | /** |
| 417 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 418 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 419 | * yield a value of 0 if the device doesn't support power calculations. |
| 420 | */ |
| 421 | public abstract LongCounter getPowerCounter(); |
| 422 | } |
| 423 | |
| 424 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | * State for keeping track of timing information. |
| 426 | */ |
| 427 | public static abstract class Timer { |
| 428 | |
| 429 | /** |
| 430 | * Returns the count associated with this Timer for the |
| 431 | * selected type of statistics. |
| 432 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 433 | * @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] | 434 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 435 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | |
| 437 | /** |
| 438 | * Returns the total time in microseconds associated with this Timer for the |
| 439 | * selected type of statistics. |
| 440 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 441 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 442 | * @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] | 443 | * @return a time in microseconds |
| 444 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 445 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 448 | * Returns the total time in microseconds associated with this Timer since the |
| 449 | * 'mark' was last set. |
| 450 | * |
| 451 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 452 | * @return a time in microseconds |
| 453 | */ |
| 454 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 455 | |
| 456 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 457 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 458 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 459 | */ |
| 460 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 461 | return -1; |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * 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] | 466 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 467 | */ |
| 468 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 469 | return -1; |
| 470 | } |
| 471 | |
| 472 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 473 | * 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] | 474 | * |
| 475 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 476 | * been on since reset. |
| 477 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 478 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 479 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 480 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 481 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 482 | */ |
| 483 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 484 | return -1; |
| 485 | } |
| 486 | |
| 487 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 488 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 489 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 490 | * |
| 491 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 492 | */ |
| 493 | public Timer getSubTimer() { |
| 494 | return null; |
| 495 | } |
| 496 | |
| 497 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 498 | * Returns whether the timer is currently running. Some types of timers |
| 499 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 500 | * and report false. |
| 501 | */ |
| 502 | public boolean isRunningLocked() { |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | * Temporary for debugging. |
| 508 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 509 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
| 513 | * The statistics associated with a particular uid. |
| 514 | */ |
| 515 | public static abstract class Uid { |
| 516 | |
| 517 | /** |
| 518 | * Returns a mapping containing wakelock statistics. |
| 519 | * |
| 520 | * @return a Map from Strings to Uid.Wakelock objects. |
| 521 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 522 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | |
| 524 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 525 | * Returns the WiFi Multicast Wakelock statistics. |
| 526 | * |
| 527 | * @return a Timer Object for the per uid Multicast statistics. |
| 528 | */ |
| 529 | public abstract Timer getMulticastWakelockStats(); |
| 530 | |
| 531 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 532 | * Returns a mapping containing sync statistics. |
| 533 | * |
| 534 | * @return a Map from Strings to Timer objects. |
| 535 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 536 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 537 | |
| 538 | /** |
| 539 | * Returns a mapping containing scheduled job statistics. |
| 540 | * |
| 541 | * @return a Map from Strings to Timer objects. |
| 542 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 543 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 544 | |
| 545 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 546 | * Returns statistics about how jobs have completed. |
| 547 | * |
| 548 | * @return A Map of String job names to completion type -> count mapping. |
| 549 | */ |
| 550 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 551 | |
| 552 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | * The statistics associated with a particular wake lock. |
| 554 | */ |
| 555 | public static abstract class Wakelock { |
| 556 | public abstract Timer getWakeTime(int type); |
| 557 | } |
| 558 | |
| 559 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 560 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 561 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 562 | * wakelocks that overlap in time (and therefore over-counts). |
| 563 | */ |
| 564 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 565 | |
| 566 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | * Returns a mapping containing sensor statistics. |
| 568 | * |
| 569 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 570 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 571 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | |
| 573 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 574 | * Returns a mapping containing active process data. |
| 575 | */ |
| 576 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 577 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 578 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | * Returns a mapping containing process statistics. |
| 580 | * |
| 581 | * @return a Map from Strings to Uid.Proc objects. |
| 582 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 583 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | |
| 585 | /** |
| 586 | * Returns a mapping containing package statistics. |
| 587 | * |
| 588 | * @return a Map from Strings to Uid.Pkg objects. |
| 589 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 590 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 591 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 592 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 593 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 594 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 595 | |
| 596 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | * {@hide} |
| 598 | */ |
| 599 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 600 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 601 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 602 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 603 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 604 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 605 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 606 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 607 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 608 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 609 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 610 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 611 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 612 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 613 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 614 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 615 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 616 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 617 | /** |
| 618 | * Returns the timer keeping track of wifi scans. |
| 619 | */ |
| 620 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 621 | public abstract int getWifiScanBackgroundCount(int which); |
| 622 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 623 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 624 | /** |
| 625 | * Returns the timer keeping track of background wifi scans. |
| 626 | */ |
| 627 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 628 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 629 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 630 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 631 | public abstract Timer getAudioTurnedOnTimer(); |
| 632 | public abstract Timer getVideoTurnedOnTimer(); |
| 633 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 634 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 635 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 636 | |
| 637 | /** |
| 638 | * Returns the timer keeping track of Foreground Service time |
| 639 | */ |
| 640 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 641 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 642 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 643 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 644 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 645 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 646 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 647 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 648 | public abstract long[] getCpuFreqTimes(int which); |
| 649 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 650 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 651 | // Note: the following times are disjoint. They can be added together to find the |
| 652 | // total time a uid has had any processes running at all. |
| 653 | |
| 654 | /** |
| 655 | * Time this uid has any processes in the top state (or above such as persistent). |
| 656 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 657 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 658 | /** |
| 659 | * Time this uid has any process with a started out bound foreground service, but |
| 660 | * none in the "top" state. |
| 661 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 662 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 663 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 664 | * Time this uid has any process in an active foreground state, but none in the |
| 665 | * "top sleeping" or better state. |
| 666 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 667 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 668 | /** |
| 669 | * Time this uid has any process in an active background state, but none in the |
| 670 | * "foreground" or better state. |
| 671 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 672 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 673 | /** |
| 674 | * Time this uid has any process that is top while the device is sleeping, but not |
| 675 | * active for any other reason. We kind-of consider it a kind of cached process |
| 676 | * for execution restrictions. |
| 677 | */ |
| 678 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 679 | /** |
| 680 | * Time this uid has any process that is in the background but it has an activity |
| 681 | * marked as "can't save state". This is essentially a cached process, though the |
| 682 | * system will try much harder than normal to avoid killing it. |
| 683 | */ |
| 684 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 685 | /** |
| 686 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 687 | * other active states. |
| 688 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 689 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 690 | /** |
| 691 | * Total number of process states we track. |
| 692 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 693 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 694 | |
| 695 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 696 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 697 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 698 | }; |
| 699 | |
| 700 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 701 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 702 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 703 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 705 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 706 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 707 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 708 | * Note that these must match the constants in android.os.PowerManager. |
| 709 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 710 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 711 | */ |
| 712 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 713 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 714 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 715 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 716 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 717 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 718 | public abstract void noteUserActivityLocked(int type); |
| 719 | public abstract boolean hasUserActivity(); |
| 720 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 721 | |
| 722 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 723 | public abstract long getNetworkActivityBytes(int type, int which); |
| 724 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 725 | public abstract long getMobileRadioActiveTime(int which); |
| 726 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 727 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 728 | /** |
| 729 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 730 | */ |
| 731 | public abstract long getUserCpuTimeUs(int which); |
| 732 | |
| 733 | /** |
| 734 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 735 | */ |
| 736 | public abstract long getSystemCpuTimeUs(int which); |
| 737 | |
| 738 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 739 | * 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] | 740 | * given CPU cluster. |
| 741 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 742 | * @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] | 743 | * @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] | 744 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 745 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 746 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 747 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 748 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 749 | /** |
| 750 | * Returns the number of times this UID woke up the Application Processor to |
| 751 | * process a mobile radio packet. |
| 752 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 753 | */ |
| 754 | public abstract long getMobileRadioApWakeupCount(int which); |
| 755 | |
| 756 | /** |
| 757 | * Returns the number of times this UID woke up the Application Processor to |
| 758 | * process a WiFi packet. |
| 759 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 760 | */ |
| 761 | public abstract long getWifiRadioApWakeupCount(int which); |
| 762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 764 | /* |
| 765 | * FIXME: it's not correct to use this magic value because it |
| 766 | * could clash with a sensor handle (which are defined by |
| 767 | * the sensor HAL, and therefore out of our control |
| 768 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | // Magic sensor number for the GPS. |
| 770 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 775 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 776 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 777 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 780 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 781 | public int mWakeNesting; |
| 782 | public long mWakeSumMs; |
| 783 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 784 | } |
| 785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | /** |
| 787 | * The statistics associated with a particular process. |
| 788 | */ |
| 789 | public static abstract class Proc { |
| 790 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 791 | public static class ExcessivePower { |
| 792 | public static final int TYPE_WAKE = 1; |
| 793 | public static final int TYPE_CPU = 2; |
| 794 | |
| 795 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 796 | public long overTime; |
| 797 | public long usedTime; |
| 798 | } |
| 799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 801 | * Returns true if this process is still active in the battery stats. |
| 802 | */ |
| 803 | public abstract boolean isActive(); |
| 804 | |
| 805 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 806 | * 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] | 807 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 808 | * @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] | 809 | */ |
| 810 | public abstract long getUserTime(int which); |
| 811 | |
| 812 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 813 | * 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] | 814 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 815 | * @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] | 816 | */ |
| 817 | public abstract long getSystemTime(int which); |
| 818 | |
| 819 | /** |
| 820 | * Returns the number of times the process has been started. |
| 821 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 822 | * @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] | 823 | */ |
| 824 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 825 | |
| 826 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 827 | * Returns the number of times the process has crashed. |
| 828 | * |
| 829 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 830 | */ |
| 831 | public abstract int getNumCrashes(int which); |
| 832 | |
| 833 | /** |
| 834 | * Returns the number of times the process has ANRed. |
| 835 | * |
| 836 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 837 | */ |
| 838 | public abstract int getNumAnrs(int which); |
| 839 | |
| 840 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 841 | * 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] | 842 | * @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] | 843 | * @return foreground cpu time in microseconds |
| 844 | */ |
| 845 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 846 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 847 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 848 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 849 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
| 853 | * The statistics associated with a particular package. |
| 854 | */ |
| 855 | public static abstract class Pkg { |
| 856 | |
| 857 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 858 | * Returns information about all wakeup alarms that have been triggered for this |
| 859 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 860 | * 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] | 861 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 862 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | |
| 864 | /** |
| 865 | * Returns a mapping containing service statistics. |
| 866 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 867 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | |
| 869 | /** |
| 870 | * The statistics associated with a particular service. |
| 871 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 872 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | |
| 874 | /** |
| 875 | * Returns the amount of time spent started. |
| 876 | * |
| 877 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 878 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | * @return |
| 880 | */ |
| 881 | public abstract long getStartTime(long batteryUptime, int which); |
| 882 | |
| 883 | /** |
| 884 | * Returns the total number of times startService() has been called. |
| 885 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 886 | * @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] | 887 | */ |
| 888 | public abstract int getStarts(int which); |
| 889 | |
| 890 | /** |
| 891 | * Returns the total number times the service has been launched. |
| 892 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 893 | * @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] | 894 | */ |
| 895 | public abstract int getLaunches(int which); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 900 | public static final class LevelStepTracker { |
| 901 | public long mLastStepTime = -1; |
| 902 | public int mNumStepDurations; |
| 903 | public final long[] mStepDurations; |
| 904 | |
| 905 | public LevelStepTracker(int maxLevelSteps) { |
| 906 | mStepDurations = new long[maxLevelSteps]; |
| 907 | } |
| 908 | |
| 909 | public LevelStepTracker(int numSteps, long[] steps) { |
| 910 | mNumStepDurations = numSteps; |
| 911 | mStepDurations = new long[numSteps]; |
| 912 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 913 | } |
| 914 | |
| 915 | public long getDurationAt(int index) { |
| 916 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 917 | } |
| 918 | |
| 919 | public int getLevelAt(int index) { |
| 920 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 921 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 922 | } |
| 923 | |
| 924 | public int getInitModeAt(int index) { |
| 925 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 926 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 927 | } |
| 928 | |
| 929 | public int getModModeAt(int index) { |
| 930 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 931 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 932 | } |
| 933 | |
| 934 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 935 | boolean hasData = false; |
| 936 | while (topOffset >= 0) { |
| 937 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 938 | topOffset -= 4; |
| 939 | if (!hasData && digit == 0) { |
| 940 | continue; |
| 941 | } |
| 942 | hasData = true; |
| 943 | if (digit >= 0 && digit <= 9) { |
| 944 | out.append((char)('0' + digit)); |
| 945 | } else { |
| 946 | out.append((char)('a' + digit - 10)); |
| 947 | } |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | public void encodeEntryAt(int index, StringBuilder out) { |
| 952 | long item = mStepDurations[index]; |
| 953 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 954 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 955 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 956 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 957 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 958 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 959 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 960 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 961 | case Display.STATE_OFF: out.append('f'); break; |
| 962 | case Display.STATE_ON: out.append('o'); break; |
| 963 | case Display.STATE_DOZE: out.append('d'); break; |
| 964 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 965 | } |
| 966 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 967 | out.append('p'); |
| 968 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 969 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 970 | out.append('i'); |
| 971 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 972 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 973 | case Display.STATE_OFF: out.append('F'); break; |
| 974 | case Display.STATE_ON: out.append('O'); break; |
| 975 | case Display.STATE_DOZE: out.append('D'); break; |
| 976 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 977 | } |
| 978 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 979 | out.append('P'); |
| 980 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 981 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 982 | out.append('I'); |
| 983 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 984 | out.append('-'); |
| 985 | appendHex(level, 4, out); |
| 986 | out.append('-'); |
| 987 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 988 | } |
| 989 | |
| 990 | public void decodeEntryAt(int index, String value) { |
| 991 | final int N = value.length(); |
| 992 | int i = 0; |
| 993 | char c; |
| 994 | long out = 0; |
| 995 | while (i < N && (c=value.charAt(i)) != '-') { |
| 996 | i++; |
| 997 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 998 | 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] | 999 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1000 | 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] | 1001 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1002 | 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] | 1003 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1004 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1005 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1006 | break; |
| 1007 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1008 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1009 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1010 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1011 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1012 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1013 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1014 | break; |
| 1015 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1016 | break; |
| 1017 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1018 | break; |
| 1019 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1020 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1021 | break; |
| 1022 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1023 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1024 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1025 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1026 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1027 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1031 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1032 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1033 | i++; |
| 1034 | level <<= 4; |
| 1035 | if (c >= '0' && c <= '9') { |
| 1036 | level += c - '0'; |
| 1037 | } else if (c >= 'a' && c <= 'f') { |
| 1038 | level += c - 'a' + 10; |
| 1039 | } else if (c >= 'A' && c <= 'F') { |
| 1040 | level += c - 'A' + 10; |
| 1041 | } |
| 1042 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1043 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1044 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1045 | long duration = 0; |
| 1046 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1047 | i++; |
| 1048 | duration <<= 4; |
| 1049 | if (c >= '0' && c <= '9') { |
| 1050 | duration += c - '0'; |
| 1051 | } else if (c >= 'a' && c <= 'f') { |
| 1052 | duration += c - 'a' + 10; |
| 1053 | } else if (c >= 'A' && c <= 'F') { |
| 1054 | duration += c - 'A' + 10; |
| 1055 | } |
| 1056 | } |
| 1057 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1058 | } |
| 1059 | |
| 1060 | public void init() { |
| 1061 | mLastStepTime = -1; |
| 1062 | mNumStepDurations = 0; |
| 1063 | } |
| 1064 | |
| 1065 | public void clearTime() { |
| 1066 | mLastStepTime = -1; |
| 1067 | } |
| 1068 | |
| 1069 | public long computeTimePerLevel() { |
| 1070 | final long[] steps = mStepDurations; |
| 1071 | final int numSteps = mNumStepDurations; |
| 1072 | |
| 1073 | // For now we'll do a simple average across all steps. |
| 1074 | if (numSteps <= 0) { |
| 1075 | return -1; |
| 1076 | } |
| 1077 | long total = 0; |
| 1078 | for (int i=0; i<numSteps; i++) { |
| 1079 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1080 | } |
| 1081 | return total / numSteps; |
| 1082 | /* |
| 1083 | long[] buckets = new long[numSteps]; |
| 1084 | int numBuckets = 0; |
| 1085 | int numToAverage = 4; |
| 1086 | int i = 0; |
| 1087 | while (i < numSteps) { |
| 1088 | long totalTime = 0; |
| 1089 | int num = 0; |
| 1090 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1091 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1092 | num++; |
| 1093 | } |
| 1094 | buckets[numBuckets] = totalTime / num; |
| 1095 | numBuckets++; |
| 1096 | numToAverage *= 2; |
| 1097 | i += num; |
| 1098 | } |
| 1099 | if (numBuckets < 1) { |
| 1100 | return -1; |
| 1101 | } |
| 1102 | long averageTime = buckets[numBuckets-1]; |
| 1103 | for (i=numBuckets-2; i>=0; i--) { |
| 1104 | averageTime = (averageTime + buckets[i]) / 2; |
| 1105 | } |
| 1106 | return averageTime; |
| 1107 | */ |
| 1108 | } |
| 1109 | |
| 1110 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1111 | int[] outNumOfInterest) { |
| 1112 | final long[] steps = mStepDurations; |
| 1113 | final int count = mNumStepDurations; |
| 1114 | if (count <= 0) { |
| 1115 | return -1; |
| 1116 | } |
| 1117 | long total = 0; |
| 1118 | int numOfInterest = 0; |
| 1119 | for (int i=0; i<count; i++) { |
| 1120 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1121 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1122 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1123 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1124 | // If the modes of interest didn't change during this step period... |
| 1125 | if ((modMode&modesOfInterest) == 0) { |
| 1126 | // And the mode values during this period match those we are measuring... |
| 1127 | if ((initMode&modesOfInterest) == modeValues) { |
| 1128 | // Then this can be used to estimate the total time! |
| 1129 | numOfInterest++; |
| 1130 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | if (numOfInterest <= 0) { |
| 1135 | return -1; |
| 1136 | } |
| 1137 | |
| 1138 | if (outNumOfInterest != null) { |
| 1139 | outNumOfInterest[0] = numOfInterest; |
| 1140 | } |
| 1141 | |
| 1142 | // The estimated time is the average time we spend in each level, multipled |
| 1143 | // by 100 -- the total number of battery levels |
| 1144 | return (total / numOfInterest) * 100; |
| 1145 | } |
| 1146 | |
| 1147 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1148 | int stepCount = mNumStepDurations; |
| 1149 | final long lastStepTime = mLastStepTime; |
| 1150 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1151 | final long[] steps = mStepDurations; |
| 1152 | long duration = elapsedRealtime - lastStepTime; |
| 1153 | for (int i=0; i<numStepLevels; i++) { |
| 1154 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1155 | long thisDuration = duration / (numStepLevels-i); |
| 1156 | duration -= thisDuration; |
| 1157 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1158 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1159 | } |
| 1160 | steps[0] = thisDuration | modeBits; |
| 1161 | } |
| 1162 | stepCount += numStepLevels; |
| 1163 | if (stepCount > steps.length) { |
| 1164 | stepCount = steps.length; |
| 1165 | } |
| 1166 | } |
| 1167 | mNumStepDurations = stepCount; |
| 1168 | mLastStepTime = elapsedRealtime; |
| 1169 | } |
| 1170 | |
| 1171 | public void readFromParcel(Parcel in) { |
| 1172 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1173 | if (N > mStepDurations.length) { |
| 1174 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1175 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1176 | mNumStepDurations = N; |
| 1177 | for (int i=0; i<N; i++) { |
| 1178 | mStepDurations[i] = in.readLong(); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | public void writeToParcel(Parcel out) { |
| 1183 | final int N = mNumStepDurations; |
| 1184 | out.writeInt(N); |
| 1185 | for (int i=0; i<N; i++) { |
| 1186 | out.writeLong(mStepDurations[i]); |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1191 | public static final class PackageChange { |
| 1192 | public String mPackageName; |
| 1193 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1194 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1197 | public static final class DailyItem { |
| 1198 | public long mStartTime; |
| 1199 | public long mEndTime; |
| 1200 | public LevelStepTracker mDischargeSteps; |
| 1201 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1202 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1206 | |
| 1207 | public abstract long getCurrentDailyStartTime(); |
| 1208 | |
| 1209 | public abstract long getNextMinDailyDeadline(); |
| 1210 | |
| 1211 | public abstract long getNextMaxDailyDeadline(); |
| 1212 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1213 | public abstract long[] getCpuFreqs(); |
| 1214 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1215 | public final static class HistoryTag { |
| 1216 | public String string; |
| 1217 | public int uid; |
| 1218 | |
| 1219 | public int poolIdx; |
| 1220 | |
| 1221 | public void setTo(HistoryTag o) { |
| 1222 | string = o.string; |
| 1223 | uid = o.uid; |
| 1224 | poolIdx = o.poolIdx; |
| 1225 | } |
| 1226 | |
| 1227 | public void setTo(String _string, int _uid) { |
| 1228 | string = _string; |
| 1229 | uid = _uid; |
| 1230 | poolIdx = -1; |
| 1231 | } |
| 1232 | |
| 1233 | public void writeToParcel(Parcel dest, int flags) { |
| 1234 | dest.writeString(string); |
| 1235 | dest.writeInt(uid); |
| 1236 | } |
| 1237 | |
| 1238 | public void readFromParcel(Parcel src) { |
| 1239 | string = src.readString(); |
| 1240 | uid = src.readInt(); |
| 1241 | poolIdx = -1; |
| 1242 | } |
| 1243 | |
| 1244 | @Override |
| 1245 | public boolean equals(Object o) { |
| 1246 | if (this == o) return true; |
| 1247 | if (o == null || getClass() != o.getClass()) return false; |
| 1248 | |
| 1249 | HistoryTag that = (HistoryTag) o; |
| 1250 | |
| 1251 | if (uid != that.uid) return false; |
| 1252 | if (!string.equals(that.string)) return false; |
| 1253 | |
| 1254 | return true; |
| 1255 | } |
| 1256 | |
| 1257 | @Override |
| 1258 | public int hashCode() { |
| 1259 | int result = string.hashCode(); |
| 1260 | result = 31 * result + uid; |
| 1261 | return result; |
| 1262 | } |
| 1263 | } |
| 1264 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1265 | /** |
| 1266 | * Optional detailed information that can go into a history step. This is typically |
| 1267 | * generated each time the battery level changes. |
| 1268 | */ |
| 1269 | public final static class HistoryStepDetails { |
| 1270 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1271 | public int userTime; |
| 1272 | public int systemTime; |
| 1273 | |
| 1274 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1275 | public int appCpuUid1; |
| 1276 | public int appCpuUTime1; |
| 1277 | public int appCpuSTime1; |
| 1278 | public int appCpuUid2; |
| 1279 | public int appCpuUTime2; |
| 1280 | public int appCpuSTime2; |
| 1281 | public int appCpuUid3; |
| 1282 | public int appCpuUTime3; |
| 1283 | public int appCpuSTime3; |
| 1284 | |
| 1285 | // Information from /proc/stat |
| 1286 | public int statUserTime; |
| 1287 | public int statSystemTime; |
| 1288 | public int statIOWaitTime; |
| 1289 | public int statIrqTime; |
| 1290 | public int statSoftIrqTime; |
| 1291 | public int statIdlTime; |
| 1292 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1293 | // Platform-level low power state stats |
| 1294 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1295 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1296 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1297 | public HistoryStepDetails() { |
| 1298 | clear(); |
| 1299 | } |
| 1300 | |
| 1301 | public void clear() { |
| 1302 | userTime = systemTime = 0; |
| 1303 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1304 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1305 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1306 | } |
| 1307 | |
| 1308 | public void writeToParcel(Parcel out) { |
| 1309 | out.writeInt(userTime); |
| 1310 | out.writeInt(systemTime); |
| 1311 | out.writeInt(appCpuUid1); |
| 1312 | out.writeInt(appCpuUTime1); |
| 1313 | out.writeInt(appCpuSTime1); |
| 1314 | out.writeInt(appCpuUid2); |
| 1315 | out.writeInt(appCpuUTime2); |
| 1316 | out.writeInt(appCpuSTime2); |
| 1317 | out.writeInt(appCpuUid3); |
| 1318 | out.writeInt(appCpuUTime3); |
| 1319 | out.writeInt(appCpuSTime3); |
| 1320 | out.writeInt(statUserTime); |
| 1321 | out.writeInt(statSystemTime); |
| 1322 | out.writeInt(statIOWaitTime); |
| 1323 | out.writeInt(statIrqTime); |
| 1324 | out.writeInt(statSoftIrqTime); |
| 1325 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1326 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1327 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | public void readFromParcel(Parcel in) { |
| 1331 | userTime = in.readInt(); |
| 1332 | systemTime = in.readInt(); |
| 1333 | appCpuUid1 = in.readInt(); |
| 1334 | appCpuUTime1 = in.readInt(); |
| 1335 | appCpuSTime1 = in.readInt(); |
| 1336 | appCpuUid2 = in.readInt(); |
| 1337 | appCpuUTime2 = in.readInt(); |
| 1338 | appCpuSTime2 = in.readInt(); |
| 1339 | appCpuUid3 = in.readInt(); |
| 1340 | appCpuUTime3 = in.readInt(); |
| 1341 | appCpuSTime3 = in.readInt(); |
| 1342 | statUserTime = in.readInt(); |
| 1343 | statSystemTime = in.readInt(); |
| 1344 | statIOWaitTime = in.readInt(); |
| 1345 | statIrqTime = in.readInt(); |
| 1346 | statSoftIrqTime = in.readInt(); |
| 1347 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1348 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1349 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1353 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1354 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1355 | |
| 1356 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1357 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1358 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1359 | 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] | 1360 | public static final byte CMD_NULL = -1; |
| 1361 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1362 | public static final byte CMD_CURRENT_TIME = 5; |
| 1363 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1364 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1365 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1366 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1367 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1368 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1369 | /** |
| 1370 | * Return whether the command code is a delta data update. |
| 1371 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1372 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1373 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1376 | public byte batteryLevel; |
| 1377 | public byte batteryStatus; |
| 1378 | public byte batteryHealth; |
| 1379 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1380 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1381 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1382 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1383 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1384 | // The charge of the battery in micro-Ampere-hours. |
| 1385 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1386 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1387 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1388 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1389 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1390 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1391 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1392 | 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] | 1393 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1394 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1395 | 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] | 1396 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1397 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1398 | 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] | 1399 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1400 | // These states always appear directly in the first int token |
| 1401 | // of a delta change; they should be ones that change relatively |
| 1402 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1403 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1404 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1405 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1406 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1407 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1408 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1409 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1410 | // Do not use, this is used for coulomb delta count. |
| 1411 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1412 | // These are on the lower bits used for the command; if they change |
| 1413 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1414 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1415 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1416 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1417 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1418 | 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] | 1419 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1420 | // empty slot |
| 1421 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1422 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1423 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1424 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1425 | |
| 1426 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1427 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1428 | public int states; |
| 1429 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1430 | // Constants from WIFI_SUPPL_STATE_* |
| 1431 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1432 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1433 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1434 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1435 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1436 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1437 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1438 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1439 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1440 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1441 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1442 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1443 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1444 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1445 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1446 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1447 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1448 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1449 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1450 | |
| 1451 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1452 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1453 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1454 | |
| 1455 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1456 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1457 | public int states2; |
| 1458 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1459 | // The wake lock that was acquired at this point. |
| 1460 | public HistoryTag wakelockTag; |
| 1461 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1462 | // Kernel wakeup reason at this point. |
| 1463 | public HistoryTag wakeReasonTag; |
| 1464 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1465 | // Non-null when there is more detailed information at this step. |
| 1466 | public HistoryStepDetails stepDetails; |
| 1467 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1468 | public static final int EVENT_FLAG_START = 0x8000; |
| 1469 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1470 | |
| 1471 | // No event in this item. |
| 1472 | public static final int EVENT_NONE = 0x0000; |
| 1473 | // Event is about a process that is running. |
| 1474 | public static final int EVENT_PROC = 0x0001; |
| 1475 | // Event is about an application package that is in the foreground. |
| 1476 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1477 | // Event is about an application package that is at the top of the screen. |
| 1478 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1479 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1480 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1481 | // Events for all additional wake locks aquired/release within a wake block. |
| 1482 | // These are not generated by default. |
| 1483 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1484 | // Event is about an application executing a scheduled job. |
| 1485 | public static final int EVENT_JOB = 0x0006; |
| 1486 | // Events for users running. |
| 1487 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1488 | // Events for foreground user. |
| 1489 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1490 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1491 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1492 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1493 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1494 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1495 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1496 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1497 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1498 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1499 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1500 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1501 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1502 | // 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] | 1503 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1504 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1505 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1506 | // Event for a package being on the temporary whitelist. |
| 1507 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1508 | // Event for the screen waking up. |
| 1509 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1510 | // Event for the UID that woke up the application processor. |
| 1511 | // Used for wakeups coming from WiFi, modem, etc. |
| 1512 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1513 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1514 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1515 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1516 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1517 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1518 | // Mask to extract out only the type part of the event. |
| 1519 | 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] | 1520 | |
| 1521 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1522 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1523 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1524 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1525 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1526 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1527 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1528 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1529 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1530 | 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] | 1531 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1532 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1533 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1534 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1535 | public static final int EVENT_USER_FOREGROUND_START = |
| 1536 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1537 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1538 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1539 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1540 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1541 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1542 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1543 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1544 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1545 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1546 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1547 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1548 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1549 | |
| 1550 | // For CMD_EVENT. |
| 1551 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1552 | public HistoryTag eventTag; |
| 1553 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1554 | // 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] | 1555 | public long currentTime; |
| 1556 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1557 | // Meta-data when reading. |
| 1558 | public int numReadInts; |
| 1559 | |
| 1560 | // Pre-allocated objects. |
| 1561 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1562 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1563 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1564 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1565 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1566 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1567 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1568 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1569 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1570 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1571 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1572 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1573 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1574 | public int describeContents() { |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | public void writeToParcel(Parcel dest, int flags) { |
| 1579 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1580 | int bat = (((int)cmd)&0xff) |
| 1581 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1582 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1583 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1584 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1585 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1586 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1587 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1588 | dest.writeInt(bat); |
| 1589 | bat = (((int)batteryTemperature)&0xffff) |
| 1590 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1591 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1592 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1593 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1594 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1595 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1596 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1597 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1598 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1599 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1600 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1601 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1602 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1603 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1604 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1605 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1606 | dest.writeLong(currentTime); |
| 1607 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1608 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1609 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1610 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1611 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1612 | int bat = src.readInt(); |
| 1613 | cmd = (byte)(bat&0xff); |
| 1614 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1615 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1616 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1617 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1618 | int bat2 = src.readInt(); |
| 1619 | batteryTemperature = (short)(bat2&0xffff); |
| 1620 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1621 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1622 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1623 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1624 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1625 | wakelockTag = localWakelockTag; |
| 1626 | wakelockTag.readFromParcel(src); |
| 1627 | } else { |
| 1628 | wakelockTag = null; |
| 1629 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1630 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1631 | wakeReasonTag = localWakeReasonTag; |
| 1632 | wakeReasonTag.readFromParcel(src); |
| 1633 | } else { |
| 1634 | wakeReasonTag = null; |
| 1635 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1636 | if ((bat&0x40000000) != 0) { |
| 1637 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1638 | eventTag = localEventTag; |
| 1639 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1640 | } else { |
| 1641 | eventCode = EVENT_NONE; |
| 1642 | eventTag = null; |
| 1643 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1644 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1645 | currentTime = src.readLong(); |
| 1646 | } else { |
| 1647 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1648 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1649 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1652 | public void clear() { |
| 1653 | time = 0; |
| 1654 | cmd = CMD_NULL; |
| 1655 | batteryLevel = 0; |
| 1656 | batteryStatus = 0; |
| 1657 | batteryHealth = 0; |
| 1658 | batteryPlugType = 0; |
| 1659 | batteryTemperature = 0; |
| 1660 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1661 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1662 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1663 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1664 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1665 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1666 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1667 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1668 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1669 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1670 | public void setTo(HistoryItem o) { |
| 1671 | time = o.time; |
| 1672 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1673 | setToCommon(o); |
| 1674 | } |
| 1675 | |
| 1676 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1677 | this.time = time; |
| 1678 | this.cmd = cmd; |
| 1679 | setToCommon(o); |
| 1680 | } |
| 1681 | |
| 1682 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1683 | batteryLevel = o.batteryLevel; |
| 1684 | batteryStatus = o.batteryStatus; |
| 1685 | batteryHealth = o.batteryHealth; |
| 1686 | batteryPlugType = o.batteryPlugType; |
| 1687 | batteryTemperature = o.batteryTemperature; |
| 1688 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1689 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1690 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1691 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1692 | if (o.wakelockTag != null) { |
| 1693 | wakelockTag = localWakelockTag; |
| 1694 | wakelockTag.setTo(o.wakelockTag); |
| 1695 | } else { |
| 1696 | wakelockTag = null; |
| 1697 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1698 | if (o.wakeReasonTag != null) { |
| 1699 | wakeReasonTag = localWakeReasonTag; |
| 1700 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1701 | } else { |
| 1702 | wakeReasonTag = null; |
| 1703 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1704 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1705 | if (o.eventTag != null) { |
| 1706 | eventTag = localEventTag; |
| 1707 | eventTag.setTo(o.eventTag); |
| 1708 | } else { |
| 1709 | eventTag = null; |
| 1710 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1711 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1714 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1715 | return batteryLevel == o.batteryLevel |
| 1716 | && batteryStatus == o.batteryStatus |
| 1717 | && batteryHealth == o.batteryHealth |
| 1718 | && batteryPlugType == o.batteryPlugType |
| 1719 | && batteryTemperature == o.batteryTemperature |
| 1720 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1721 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1722 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1723 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1724 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1725 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1726 | |
| 1727 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1728 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1729 | return false; |
| 1730 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1731 | if (wakelockTag != o.wakelockTag) { |
| 1732 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1733 | return false; |
| 1734 | } |
| 1735 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1736 | return false; |
| 1737 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1738 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1739 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1740 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1741 | return false; |
| 1742 | } |
| 1743 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1744 | return false; |
| 1745 | } |
| 1746 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1747 | if (eventTag != o.eventTag) { |
| 1748 | if (eventTag == null || o.eventTag == null) { |
| 1749 | return false; |
| 1750 | } |
| 1751 | if (!eventTag.equals(o.eventTag)) { |
| 1752 | return false; |
| 1753 | } |
| 1754 | } |
| 1755 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1756 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1757 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1758 | |
| 1759 | public final static class HistoryEventTracker { |
| 1760 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1761 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1762 | |
| 1763 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1764 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1765 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1766 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1767 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1768 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1769 | mActiveEvents[idx] = active; |
| 1770 | } |
| 1771 | SparseIntArray uids = active.get(name); |
| 1772 | if (uids == null) { |
| 1773 | uids = new SparseIntArray(); |
| 1774 | active.put(name, uids); |
| 1775 | } |
| 1776 | if (uids.indexOfKey(uid) >= 0) { |
| 1777 | // Already set, nothing to do! |
| 1778 | return false; |
| 1779 | } |
| 1780 | uids.put(uid, poolIdx); |
| 1781 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1782 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1783 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1784 | if (active == null) { |
| 1785 | // not currently active, nothing to do. |
| 1786 | return false; |
| 1787 | } |
| 1788 | SparseIntArray uids = active.get(name); |
| 1789 | if (uids == null) { |
| 1790 | // not currently active, nothing to do. |
| 1791 | return false; |
| 1792 | } |
| 1793 | idx = uids.indexOfKey(uid); |
| 1794 | if (idx < 0) { |
| 1795 | // not currently active, nothing to do. |
| 1796 | return false; |
| 1797 | } |
| 1798 | uids.removeAt(idx); |
| 1799 | if (uids.size() <= 0) { |
| 1800 | active.remove(name); |
| 1801 | } |
| 1802 | } |
| 1803 | return true; |
| 1804 | } |
| 1805 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1806 | public void removeEvents(int code) { |
| 1807 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1808 | mActiveEvents[idx] = null; |
| 1809 | } |
| 1810 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1811 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1812 | return mActiveEvents[code]; |
| 1813 | } |
| 1814 | } |
| 1815 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1816 | public static final class BitDescription { |
| 1817 | public final int mask; |
| 1818 | public final int shift; |
| 1819 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1820 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1821 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1822 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1823 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1824 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1825 | this.mask = mask; |
| 1826 | this.shift = -1; |
| 1827 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1828 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1829 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1830 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1831 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1832 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1833 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1834 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1835 | this.mask = mask; |
| 1836 | this.shift = shift; |
| 1837 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1838 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1839 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1840 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1841 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1842 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1843 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1844 | /** |
| 1845 | * Don't allow any more batching in to the current history event. This |
| 1846 | * is called when printing partial histories, so to ensure that the next |
| 1847 | * history event will go in to a new batch after what was printed in the |
| 1848 | * last partial history. |
| 1849 | */ |
| 1850 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1851 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1852 | public abstract int getHistoryTotalSize(); |
| 1853 | |
| 1854 | public abstract int getHistoryUsedSize(); |
| 1855 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1856 | public abstract boolean startIteratingHistoryLocked(); |
| 1857 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1858 | public abstract int getHistoryStringPoolSize(); |
| 1859 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1860 | public abstract int getHistoryStringPoolBytes(); |
| 1861 | |
| 1862 | public abstract String getHistoryTagPoolString(int index); |
| 1863 | |
| 1864 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1865 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1866 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1867 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1868 | public abstract void finishIteratingHistoryLocked(); |
| 1869 | |
| 1870 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1871 | |
| 1872 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1873 | |
| 1874 | public abstract void finishIteratingOldHistoryLocked(); |
| 1875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1877 | * Return the base time offset for the battery history. |
| 1878 | */ |
| 1879 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1880 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1881 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | * Returns the number of times the device has been started. |
| 1883 | */ |
| 1884 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1886 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1887 | * 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] | 1888 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1889 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | * {@hide} |
| 1891 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1892 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1893 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1894 | /** |
| 1895 | * Returns the number of times the screen was turned on. |
| 1896 | * |
| 1897 | * {@hide} |
| 1898 | */ |
| 1899 | public abstract int getScreenOnCount(int which); |
| 1900 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1901 | /** |
| 1902 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1903 | * running on battery. |
| 1904 | * |
| 1905 | * {@hide} |
| 1906 | */ |
| 1907 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1908 | |
| 1909 | /** |
| 1910 | * Returns the number of times the screen was turned dozing. |
| 1911 | * |
| 1912 | * {@hide} |
| 1913 | */ |
| 1914 | public abstract int getScreenDozeCount(int which); |
| 1915 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1916 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1917 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1918 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1919 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1920 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1921 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1922 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1923 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1924 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1925 | "dark", "dim", "medium", "light", "bright" |
| 1926 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1927 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1928 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1929 | "0", "1", "2", "3", "4" |
| 1930 | }; |
| 1931 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1932 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1933 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1934 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1935 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1936 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1937 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1938 | * {@hide} |
| 1939 | */ |
| 1940 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1941 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 1944 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 1945 | * |
| 1946 | * {@hide} |
| 1947 | */ |
| 1948 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 1949 | |
| 1950 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1951 | * 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] | 1952 | * running on battery. |
| 1953 | * |
| 1954 | * {@hide} |
| 1955 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1956 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1957 | |
| 1958 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1959 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1960 | * |
| 1961 | * {@hide} |
| 1962 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1963 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1964 | |
| 1965 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1966 | * Constant for device idle mode: not active. |
| 1967 | */ |
| 1968 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1969 | |
| 1970 | /** |
| 1971 | * Constant for device idle mode: active in lightweight mode. |
| 1972 | */ |
| 1973 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1974 | |
| 1975 | /** |
| 1976 | * Constant for device idle mode: active in full mode. |
| 1977 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1978 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1979 | |
| 1980 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1981 | * Returns the time in microseconds that device has been in idle mode while |
| 1982 | * running on battery. |
| 1983 | * |
| 1984 | * {@hide} |
| 1985 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1986 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1987 | |
| 1988 | /** |
| 1989 | * Returns the number of times that the devie has gone in to idle mode. |
| 1990 | * |
| 1991 | * {@hide} |
| 1992 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1993 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1994 | |
| 1995 | /** |
| 1996 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1997 | * mode, not in idle maintenance etc). |
| 1998 | */ |
| 1999 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2000 | |
| 2001 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2002 | * 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] | 2003 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2004 | * counts all of the time that we consider the device to be idle, whether or not |
| 2005 | * it is currently in the actual device idle mode. |
| 2006 | * |
| 2007 | * {@hide} |
| 2008 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2009 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2010 | |
| 2011 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2012 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2013 | * |
| 2014 | * {@hide} |
| 2015 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2016 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2017 | |
| 2018 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2019 | * Returns the number of times that connectivity state changed. |
| 2020 | * |
| 2021 | * {@hide} |
| 2022 | */ |
| 2023 | public abstract int getNumConnectivityChange(int which); |
| 2024 | |
| 2025 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2026 | * 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] | 2027 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2028 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | * {@hide} |
| 2030 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2031 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2032 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2033 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2034 | * Returns the number of times a phone call was activated. |
| 2035 | * |
| 2036 | * {@hide} |
| 2037 | */ |
| 2038 | public abstract int getPhoneOnCount(int which); |
| 2039 | |
| 2040 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2041 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2042 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2043 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2044 | * {@hide} |
| 2045 | */ |
| 2046 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2047 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2048 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2049 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2050 | * Returns the time in microseconds that the phone has been trying to |
| 2051 | * acquire a signal. |
| 2052 | * |
| 2053 | * {@hide} |
| 2054 | */ |
| 2055 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2056 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2057 | |
| 2058 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2059 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2060 | * acquire a signal. |
| 2061 | * |
| 2062 | * {@hide} |
| 2063 | */ |
| 2064 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2065 | |
| 2066 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2067 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2068 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2069 | * {@hide} |
| 2070 | */ |
| 2071 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2072 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2073 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2074 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2075 | * counts. |
| 2076 | */ |
| 2077 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2078 | |
| 2079 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2080 | * Returns the time in microseconds that the mobile network has been active |
| 2081 | * (in a high power state). |
| 2082 | * |
| 2083 | * {@hide} |
| 2084 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2085 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2086 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2087 | /** |
| 2088 | * Returns the number of times that the mobile network has transitioned to the |
| 2089 | * active state. |
| 2090 | * |
| 2091 | * {@hide} |
| 2092 | */ |
| 2093 | public abstract int getMobileRadioActiveCount(int which); |
| 2094 | |
| 2095 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2096 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2097 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2098 | * from the radio. |
| 2099 | * |
| 2100 | * {@hide} |
| 2101 | */ |
| 2102 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2103 | |
| 2104 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2105 | * Returns the time in microseconds that the mobile network has been active |
| 2106 | * (in a high power state) but not being able to blame on an app. |
| 2107 | * |
| 2108 | * {@hide} |
| 2109 | */ |
| 2110 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2111 | |
| 2112 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2113 | * 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] | 2114 | * |
| 2115 | * {@hide} |
| 2116 | */ |
| 2117 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2118 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2119 | public static final int DATA_CONNECTION_NONE = 0; |
| 2120 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2121 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2122 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2123 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2124 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2125 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2126 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2127 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2128 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2129 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2130 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2131 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2132 | public static final int DATA_CONNECTION_LTE = 13; |
| 2133 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2134 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2135 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2136 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2137 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2138 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2139 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2140 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2141 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2142 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2143 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2144 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2145 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2146 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2147 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2148 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2149 | * {@hide} |
| 2150 | */ |
| 2151 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2152 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2155 | * Returns the number of times the phone has entered the given data |
| 2156 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2157 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2158 | * {@hide} |
| 2159 | */ |
| 2160 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2161 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2162 | /** |
| 2163 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2164 | */ |
| 2165 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2166 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2167 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2168 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2169 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2170 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2171 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2172 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2173 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2174 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2175 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2176 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2177 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2178 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2179 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2180 | |
| 2181 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2182 | |
| 2183 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2184 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2185 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2186 | "group-handshake", "completed", "dormant", "uninit" |
| 2187 | }; |
| 2188 | |
| 2189 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2190 | "inv", "dsc", "dis", "inact", "scan", |
| 2191 | "auth", "ascing", "asced", "4-way", |
| 2192 | "group", "compl", "dorm", "uninit" |
| 2193 | }; |
| 2194 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2195 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2196 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2197 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2198 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2199 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2200 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2201 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2202 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2203 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2204 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2205 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2206 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2207 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2208 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2209 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2210 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2211 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2212 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2213 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2214 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2215 | new String[] {"in", "out", "emergency", "off"}, |
| 2216 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2217 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2218 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2219 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2220 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2221 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2222 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2223 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2224 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2225 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2226 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2227 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2228 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2229 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2230 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2231 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2232 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2233 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2234 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2235 | new String[] { "off", "light", "full", "???" }, |
| 2236 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2237 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2238 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2239 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2240 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2241 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2242 | new String[] { "0", "1", "2", "3", "4" }, |
| 2243 | new String[] { "0", "1", "2", "3", "4" }), |
| 2244 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2245 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2246 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2247 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2248 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2249 | }; |
| 2250 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2251 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2252 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2253 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2254 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2255 | }; |
| 2256 | |
| 2257 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2258 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2259 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2260 | "Esw", "Ewa", "Elw", "Eec" |
| 2261 | }; |
| 2262 | |
| 2263 | @FunctionalInterface |
| 2264 | public interface IntToString { |
| 2265 | String applyAsString(int val); |
| 2266 | } |
| 2267 | |
| 2268 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2269 | private static final IntToString sIntToString = Integer::toString; |
| 2270 | |
| 2271 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2272 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2273 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2274 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2275 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2276 | }; |
| 2277 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2278 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2279 | * 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] | 2280 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2281 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2282 | * {@hide} |
| 2283 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2284 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2285 | |
| 2286 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2287 | * 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] | 2288 | * been in the running state while the device was running on battery. |
| 2289 | * |
| 2290 | * {@hide} |
| 2291 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2292 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2293 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2294 | public static final int WIFI_STATE_OFF = 0; |
| 2295 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2296 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2297 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2298 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2299 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2300 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2301 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2302 | |
| 2303 | static final String[] WIFI_STATE_NAMES = { |
| 2304 | "off", "scanning", "no_net", "disconn", |
| 2305 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2306 | }; |
| 2307 | |
| 2308 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2309 | |
| 2310 | /** |
| 2311 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2312 | * |
| 2313 | * {@hide} |
| 2314 | */ |
| 2315 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2316 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2317 | |
| 2318 | /** |
| 2319 | * Returns the number of times that WiFi has entered the given state. |
| 2320 | * |
| 2321 | * {@hide} |
| 2322 | */ |
| 2323 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2324 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2325 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2326 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2327 | * |
| 2328 | * {@hide} |
| 2329 | */ |
| 2330 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2331 | |
| 2332 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2333 | * Returns the time in microseconds that the wifi supplicant has been |
| 2334 | * in a given state. |
| 2335 | * |
| 2336 | * {@hide} |
| 2337 | */ |
| 2338 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2339 | |
| 2340 | /** |
| 2341 | * Returns the number of times that the wifi supplicant has transitioned |
| 2342 | * to a given state. |
| 2343 | * |
| 2344 | * {@hide} |
| 2345 | */ |
| 2346 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2347 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2348 | /** |
| 2349 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2350 | * |
| 2351 | * {@hide} |
| 2352 | */ |
| 2353 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2354 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2355 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2356 | |
| 2357 | /** |
| 2358 | * Returns the time in microseconds that WIFI has been running with |
| 2359 | * the given signal strength. |
| 2360 | * |
| 2361 | * {@hide} |
| 2362 | */ |
| 2363 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2364 | long elapsedRealtimeUs, int which); |
| 2365 | |
| 2366 | /** |
| 2367 | * Returns the number of times WIFI has entered the given signal strength. |
| 2368 | * |
| 2369 | * {@hide} |
| 2370 | */ |
| 2371 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2372 | |
| 2373 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2374 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2375 | * |
| 2376 | * {@hide} |
| 2377 | */ |
| 2378 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2379 | |
| 2380 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2381 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2382 | * running on battery. |
| 2383 | * |
| 2384 | * {@hide} |
| 2385 | */ |
| 2386 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2387 | |
| 2388 | /** |
| 2389 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2390 | * running on battery. |
| 2391 | * |
| 2392 | * {@hide} |
| 2393 | */ |
| 2394 | public abstract long getFlashlightOnCount(int which); |
| 2395 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2396 | /** |
| 2397 | * Returns the time in microseconds that the camera has been on while the device was |
| 2398 | * running on battery. |
| 2399 | * |
| 2400 | * {@hide} |
| 2401 | */ |
| 2402 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2403 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2404 | /** |
| 2405 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2406 | * on battery. |
| 2407 | * |
| 2408 | * {@hide} |
| 2409 | */ |
| 2410 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2411 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2412 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2413 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2414 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2415 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2416 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2417 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2418 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2419 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2420 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2421 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2422 | 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] | 2423 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2424 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2425 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2426 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2427 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2428 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2429 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2430 | * actual power data. |
| 2431 | */ |
| 2432 | public abstract boolean hasWifiActivityReporting(); |
| 2433 | |
| 2434 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2435 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2436 | * in various radio controller states, such as transmit, receive, and idle. |
| 2437 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2438 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2439 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2440 | |
| 2441 | /** |
| 2442 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2443 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2444 | * actual power data. |
| 2445 | */ |
| 2446 | public abstract boolean hasBluetoothActivityReporting(); |
| 2447 | |
| 2448 | /** |
| 2449 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2450 | * in various radio controller states, such as transmit, receive, and idle. |
| 2451 | * @return non-null {@link ControllerActivityCounter} |
| 2452 | */ |
| 2453 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2454 | |
| 2455 | /** |
| 2456 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2457 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2458 | * actual power data. |
| 2459 | */ |
| 2460 | public abstract boolean hasModemActivityReporting(); |
| 2461 | |
| 2462 | /** |
| 2463 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2464 | * in various radio controller states, such as transmit, receive, and idle. |
| 2465 | * @return non-null {@link ControllerActivityCounter} |
| 2466 | */ |
| 2467 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2468 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2469 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2470 | * Return the wall clock time when battery stats data collection started. |
| 2471 | */ |
| 2472 | public abstract long getStartClockTime(); |
| 2473 | |
| 2474 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2475 | * Return platform version tag that we were running in when the battery stats started. |
| 2476 | */ |
| 2477 | public abstract String getStartPlatformVersion(); |
| 2478 | |
| 2479 | /** |
| 2480 | * Return platform version tag that we were running in when the battery stats ended. |
| 2481 | */ |
| 2482 | public abstract String getEndPlatformVersion(); |
| 2483 | |
| 2484 | /** |
| 2485 | * Return the internal version code of the parcelled format. |
| 2486 | */ |
| 2487 | public abstract int getParcelVersion(); |
| 2488 | |
| 2489 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | * Return whether we are currently running on battery. |
| 2491 | */ |
| 2492 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | /** |
| 2495 | * Returns a SparseArray containing the statistics for each uid. |
| 2496 | */ |
| 2497 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2498 | |
| 2499 | /** |
| 2500 | * Returns the current battery uptime in microseconds. |
| 2501 | * |
| 2502 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2503 | */ |
| 2504 | public abstract long getBatteryUptime(long curTime); |
| 2505 | |
| 2506 | /** |
| 2507 | * Returns the current battery realtime in microseconds. |
| 2508 | * |
| 2509 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2510 | */ |
| 2511 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2512 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2513 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2514 | * 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] | 2515 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2516 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2517 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2518 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2519 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2520 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2521 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2522 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2523 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | |
| 2525 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2526 | * Get the amount the battery has discharged since the stats were |
| 2527 | * last reset after charging, as a lower-end approximation. |
| 2528 | */ |
| 2529 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2530 | |
| 2531 | /** |
| 2532 | * Get the amount the battery has discharged since the stats were |
| 2533 | * last reset after charging, as an upper-end approximation. |
| 2534 | */ |
| 2535 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2536 | |
| 2537 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2538 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2539 | */ |
| 2540 | public abstract int getDischargeAmount(int which); |
| 2541 | |
| 2542 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2543 | * Get the amount the battery has discharged while the screen was on, |
| 2544 | * since the last time power was unplugged. |
| 2545 | */ |
| 2546 | public abstract int getDischargeAmountScreenOn(); |
| 2547 | |
| 2548 | /** |
| 2549 | * Get the amount the battery has discharged while the screen was on, |
| 2550 | * since the last time the device was charged. |
| 2551 | */ |
| 2552 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2553 | |
| 2554 | /** |
| 2555 | * Get the amount the battery has discharged while the screen was off, |
| 2556 | * since the last time power was unplugged. |
| 2557 | */ |
| 2558 | public abstract int getDischargeAmountScreenOff(); |
| 2559 | |
| 2560 | /** |
| 2561 | * Get the amount the battery has discharged while the screen was off, |
| 2562 | * since the last time the device was charged. |
| 2563 | */ |
| 2564 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2565 | |
| 2566 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2567 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2568 | * since the last time power was unplugged. |
| 2569 | */ |
| 2570 | public abstract int getDischargeAmountScreenDoze(); |
| 2571 | |
| 2572 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2573 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2574 | * since the last time the device was charged. |
| 2575 | */ |
| 2576 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2577 | |
| 2578 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | * Returns the total, last, or current battery uptime in microseconds. |
| 2580 | * |
| 2581 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2582 | * @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] | 2583 | */ |
| 2584 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2585 | |
| 2586 | /** |
| 2587 | * Returns the total, last, or current battery realtime in microseconds. |
| 2588 | * |
| 2589 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2590 | * @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] | 2591 | */ |
| 2592 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2593 | |
| 2594 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2595 | * 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] | 2596 | * |
| 2597 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2598 | * @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] | 2599 | */ |
| 2600 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2601 | |
| 2602 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2603 | * 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] | 2604 | * |
| 2605 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2606 | * @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] | 2607 | */ |
| 2608 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2609 | |
| 2610 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | * Returns the total, last, or current uptime in microseconds. |
| 2612 | * |
| 2613 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2614 | * @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] | 2615 | */ |
| 2616 | public abstract long computeUptime(long curTime, int which); |
| 2617 | |
| 2618 | /** |
| 2619 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2620 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2622 | * @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] | 2623 | */ |
| 2624 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2625 | |
| 2626 | /** |
| 2627 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2628 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2629 | * enough current data to make a decision, or the battery is currently |
| 2630 | * charging. |
| 2631 | * |
| 2632 | * @param curTime The current elepsed realtime in microseconds. |
| 2633 | */ |
| 2634 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2635 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2636 | // The part of a step duration that is the actual time. |
| 2637 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2638 | |
| 2639 | // Bits in a step duration that are the new battery level we are at. |
| 2640 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2641 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2642 | |
| 2643 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2644 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2645 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2646 | |
| 2647 | // Bits in a step duration that indicate which modes changed during that step. |
| 2648 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2649 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2650 | |
| 2651 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2652 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2653 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2654 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2655 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2656 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2657 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2658 | // Step duration mode: power save is on. |
| 2659 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2660 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2661 | // Step duration mode: device is currently in idle mode. |
| 2662 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2663 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2664 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2665 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2666 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2667 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2668 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2669 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2670 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2671 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2672 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2673 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2674 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2675 | }; |
| 2676 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2677 | (Display.STATE_OFF-1), |
| 2678 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2679 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2680 | (Display.STATE_ON-1), |
| 2681 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2682 | (Display.STATE_DOZE-1), |
| 2683 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2684 | (Display.STATE_DOZE_SUSPEND-1), |
| 2685 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2686 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2687 | }; |
| 2688 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2689 | "screen off", |
| 2690 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2691 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2692 | "screen on", |
| 2693 | "screen on power save", |
| 2694 | "screen doze", |
| 2695 | "screen doze power save", |
| 2696 | "screen doze-suspend", |
| 2697 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2698 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2699 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2700 | |
| 2701 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2702 | * 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] | 2703 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2704 | * a coulomb counter. |
| 2705 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2706 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2707 | |
| 2708 | /** |
| 2709 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2710 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2711 | * a coulomb counter. |
| 2712 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2713 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2714 | |
| 2715 | /** |
| 2716 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2717 | * non-zero only if the device's battery has a coulomb counter. |
| 2718 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2719 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2720 | |
| 2721 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2722 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2723 | * micro-Ampere-hours. |
| 2724 | */ |
| 2725 | public abstract long getUahDischargeLightDoze(int which); |
| 2726 | |
| 2727 | /** |
| 2728 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2729 | * micro-Ampere-hours. |
| 2730 | */ |
| 2731 | public abstract long getUahDischargeDeepDoze(int which); |
| 2732 | |
| 2733 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2734 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2735 | * declared by the PowerProfile. |
| 2736 | * @return The estimated battery capacity in mAh. |
| 2737 | */ |
| 2738 | public abstract int getEstimatedBatteryCapacity(); |
| 2739 | |
| 2740 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2741 | * @return The minimum learned battery capacity in uAh. |
| 2742 | */ |
| 2743 | public abstract int getMinLearnedBatteryCapacity(); |
| 2744 | |
| 2745 | /** |
| 2746 | * @return The maximum learned battery capacity in uAh. |
| 2747 | */ |
| 2748 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2749 | |
| 2750 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2751 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2752 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2753 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2754 | |
| 2755 | /** |
| 2756 | * Return the array of daily discharge step durations. |
| 2757 | */ |
| 2758 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2759 | |
| 2760 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2761 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2762 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2763 | * enough current data to make a decision, or the battery is currently |
| 2764 | * discharging. |
| 2765 | * |
| 2766 | * @param curTime The current elepsed realtime in microseconds. |
| 2767 | */ |
| 2768 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2769 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2770 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2771 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2772 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2773 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2774 | |
| 2775 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2776 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2777 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2778 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2779 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2780 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2781 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2782 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2783 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2784 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2785 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2786 | /** |
| 2787 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2788 | */ |
| 2789 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2790 | /** |
| 2791 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2792 | */ |
| 2793 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2794 | |
| 2795 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2796 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2797 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2798 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2799 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2800 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | long days = seconds / (60 * 60 * 24); |
| 2802 | if (days != 0) { |
| 2803 | out.append(days); |
| 2804 | out.append("d "); |
| 2805 | } |
| 2806 | long used = days * 60 * 60 * 24; |
| 2807 | |
| 2808 | long hours = (seconds - used) / (60 * 60); |
| 2809 | if (hours != 0 || used != 0) { |
| 2810 | out.append(hours); |
| 2811 | out.append("h "); |
| 2812 | } |
| 2813 | used += hours * 60 * 60; |
| 2814 | |
| 2815 | long mins = (seconds-used) / 60; |
| 2816 | if (mins != 0 || used != 0) { |
| 2817 | out.append(mins); |
| 2818 | out.append("m "); |
| 2819 | } |
| 2820 | used += mins * 60; |
| 2821 | |
| 2822 | if (seconds != 0 || used != 0) { |
| 2823 | out.append(seconds-used); |
| 2824 | out.append("s "); |
| 2825 | } |
| 2826 | } |
| 2827 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2828 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2830 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | sb.append(time - (sec * 1000)); |
| 2832 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | } |
| 2834 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2835 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2836 | long sec = time / 1000; |
| 2837 | formatTimeRaw(sb, sec); |
| 2838 | sb.append(time - (sec * 1000)); |
| 2839 | sb.append("ms"); |
| 2840 | } |
| 2841 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2842 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2844 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | } |
| 2846 | float perc = ((float)num) / ((float)den) * 100; |
| 2847 | mFormatBuilder.setLength(0); |
| 2848 | mFormatter.format("%.1f%%", perc); |
| 2849 | return mFormatBuilder.toString(); |
| 2850 | } |
| 2851 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2852 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2853 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2854 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2855 | if (bytes < BYTES_PER_KB) { |
| 2856 | return bytes + "B"; |
| 2857 | } else if (bytes < BYTES_PER_MB) { |
| 2858 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2859 | return mFormatBuilder.toString(); |
| 2860 | } else if (bytes < BYTES_PER_GB){ |
| 2861 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2862 | return mFormatBuilder.toString(); |
| 2863 | } else { |
| 2864 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2865 | return mFormatBuilder.toString(); |
| 2866 | } |
| 2867 | } |
| 2868 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 2869 | private static long roundUsToMs(long timeUs) { |
| 2870 | return (timeUs + 500) / 1000; |
| 2871 | } |
| 2872 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2873 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2874 | if (timer != null) { |
| 2875 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2876 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2877 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2878 | return totalTimeMillis; |
| 2879 | } |
| 2880 | return 0; |
| 2881 | } |
| 2882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | /** |
| 2884 | * |
| 2885 | * @param sb a StringBuilder object. |
| 2886 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2887 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2889 | * @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] | 2890 | * @param linePrefix a String to be prepended to each line of output. |
| 2891 | * @return the line prefix |
| 2892 | */ |
| 2893 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2894 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2897 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2898 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2899 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | if (totalTimeMillis != 0) { |
| 2901 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2902 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2903 | if (name != null) { |
| 2904 | sb.append(name); |
| 2905 | sb.append(' '); |
| 2906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | sb.append('('); |
| 2908 | sb.append(count); |
| 2909 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2910 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2911 | if (maxDurationMs >= 0) { |
| 2912 | sb.append(" max="); |
| 2913 | sb.append(maxDurationMs); |
| 2914 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2915 | // Put actual time if it is available and different from totalTimeMillis. |
| 2916 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2917 | if (totalDurMs > totalTimeMillis) { |
| 2918 | sb.append(" actual="); |
| 2919 | sb.append(totalDurMs); |
| 2920 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2921 | if (timer.isRunningLocked()) { |
| 2922 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2923 | if (currentMs >= 0) { |
| 2924 | sb.append(" (running for "); |
| 2925 | sb.append(currentMs); |
| 2926 | sb.append("ms)"); |
| 2927 | } else { |
| 2928 | sb.append(" (running)"); |
| 2929 | } |
| 2930 | } |
| 2931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | return ", "; |
| 2933 | } |
| 2934 | } |
| 2935 | return linePrefix; |
| 2936 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2937 | |
| 2938 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2939 | * 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] | 2940 | * |
| 2941 | * @param pw a PrintWriter object to print to. |
| 2942 | * @param sb a StringBuilder object. |
| 2943 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2944 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2945 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2946 | * @param prefix a String to be prepended to each line of output. |
| 2947 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2948 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2949 | */ |
| 2950 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2951 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2952 | if (timer != null) { |
| 2953 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2954 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2955 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2956 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2957 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2958 | sb.setLength(0); |
| 2959 | sb.append(prefix); |
| 2960 | sb.append(" "); |
| 2961 | sb.append(type); |
| 2962 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2963 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2964 | sb.append("realtime ("); |
| 2965 | sb.append(count); |
| 2966 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2967 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2968 | if (maxDurationMs >= 0) { |
| 2969 | sb.append(" max="); |
| 2970 | sb.append(maxDurationMs); |
| 2971 | } |
| 2972 | if (timer.isRunningLocked()) { |
| 2973 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2974 | if (currentMs >= 0) { |
| 2975 | sb.append(" (running for "); |
| 2976 | sb.append(currentMs); |
| 2977 | sb.append("ms)"); |
| 2978 | } else { |
| 2979 | sb.append(" (running)"); |
| 2980 | } |
| 2981 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2982 | pw.println(sb.toString()); |
| 2983 | return true; |
| 2984 | } |
| 2985 | } |
| 2986 | return false; |
| 2987 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | /** |
| 2990 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2991 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | * @param sb a StringBuilder object. |
| 2993 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2994 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2996 | * @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] | 2997 | * @param linePrefix a String to be prepended to each line of output. |
| 2998 | * @return the line prefix |
| 2999 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3000 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3001 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | long totalTimeMicros = 0; |
| 3003 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3004 | long max = 0; |
| 3005 | long current = 0; |
| 3006 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3008 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3009 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3010 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3011 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3012 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | } |
| 3014 | sb.append(linePrefix); |
| 3015 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3016 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3017 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3019 | sb.append(','); |
| 3020 | sb.append(current); |
| 3021 | sb.append(','); |
| 3022 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3023 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3024 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3025 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3026 | if (name != null) { |
| 3027 | sb.append(','); |
| 3028 | sb.append(totalDuration); |
| 3029 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | return ","; |
| 3031 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3032 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3033 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3034 | String type) { |
| 3035 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3036 | pw.print(','); |
| 3037 | pw.print(uid); |
| 3038 | pw.print(','); |
| 3039 | pw.print(category); |
| 3040 | pw.print(','); |
| 3041 | pw.print(type); |
| 3042 | } |
| 3043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3044 | /** |
| 3045 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3046 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | * @param pw the PageWriter to dump log to |
| 3048 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3049 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3050 | * @param args type-dependent data arguments |
| 3051 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3052 | 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] | 3053 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3054 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3055 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3056 | pw.print(','); |
| 3057 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3059 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3061 | |
| 3062 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3063 | * Dump a given timer stat for terse checkin mode. |
| 3064 | * |
| 3065 | * @param pw the PageWriter to dump log to |
| 3066 | * @param uid the UID to log |
| 3067 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3068 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3069 | * @param timer a {@link Timer} to dump stats for |
| 3070 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3071 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3072 | */ |
| 3073 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3074 | Timer timer, long rawRealtime, int which) { |
| 3075 | if (timer != null) { |
| 3076 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3077 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3078 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3079 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3080 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3081 | } |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3086 | * Dump a given timer stat to the proto stream. |
| 3087 | * |
| 3088 | * @param proto the ProtoOutputStream to log to |
| 3089 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3090 | * @param timer a {@link Timer} to dump stats for |
| 3091 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3092 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3093 | */ |
| 3094 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3095 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3096 | if (timer == null) { |
| 3097 | return; |
| 3098 | } |
| 3099 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3100 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3101 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3102 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3103 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3104 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3105 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3106 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3107 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3108 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3109 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3110 | // These values will be -1 for timers that don't implement the functionality. |
| 3111 | if (maxDurationMs != -1) { |
| 3112 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3113 | } |
| 3114 | if (curDurationMs != -1) { |
| 3115 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3116 | } |
| 3117 | if (totalDurationMs != -1) { |
| 3118 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3119 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3120 | proto.end(token); |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3125 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3126 | */ |
| 3127 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3128 | if (counter == null) { |
| 3129 | return false; |
| 3130 | } |
| 3131 | |
| 3132 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3133 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3134 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3135 | return true; |
| 3136 | } |
| 3137 | |
| 3138 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3139 | if (c.getCountLocked(which) != 0) { |
| 3140 | return true; |
| 3141 | } |
| 3142 | } |
| 3143 | return false; |
| 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3148 | * The order of the arguments in the final check in line is: |
| 3149 | * |
| 3150 | * idle, rx, power, tx... |
| 3151 | * |
| 3152 | * where tx... is one or more transmit level times. |
| 3153 | */ |
| 3154 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3155 | String type, |
| 3156 | ControllerActivityCounter counter, |
| 3157 | int which) { |
| 3158 | if (!controllerActivityHasData(counter, which)) { |
| 3159 | return; |
| 3160 | } |
| 3161 | |
| 3162 | dumpLineHeader(pw, uid, category, type); |
| 3163 | pw.print(","); |
| 3164 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3165 | pw.print(","); |
| 3166 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3167 | pw.print(","); |
| 3168 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3169 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3170 | pw.print(","); |
| 3171 | pw.print(c.getCountLocked(which)); |
| 3172 | } |
| 3173 | pw.println(); |
| 3174 | } |
| 3175 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3176 | /** |
| 3177 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3178 | */ |
| 3179 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3180 | ControllerActivityCounter counter, |
| 3181 | int which) { |
| 3182 | if (!controllerActivityHasData(counter, which)) { |
| 3183 | return; |
| 3184 | } |
| 3185 | |
| 3186 | final long cToken = proto.start(fieldId); |
| 3187 | |
| 3188 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3189 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3190 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3191 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3192 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3193 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3194 | |
| 3195 | long tToken; |
| 3196 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3197 | for (int i = 0; i < txCounters.length; ++i) { |
| 3198 | LongCounter c = txCounters[i]; |
| 3199 | tToken = proto.start(ControllerActivityProto.TX); |
| 3200 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3201 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3202 | proto.end(tToken); |
| 3203 | } |
| 3204 | |
| 3205 | proto.end(cToken); |
| 3206 | } |
| 3207 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3208 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3209 | String prefix, String controllerName, |
| 3210 | ControllerActivityCounter counter, |
| 3211 | int which) { |
| 3212 | if (controllerActivityHasData(counter, which)) { |
| 3213 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3218 | String controllerName, |
| 3219 | ControllerActivityCounter counter, int which) { |
| 3220 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3221 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3222 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3223 | // Battery real time |
| 3224 | final long totalControllerActivityTimeMs |
| 3225 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3226 | long totalTxTimeMs = 0; |
| 3227 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3228 | totalTxTimeMs += txState.getCountLocked(which); |
| 3229 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3230 | final long sleepTimeMs |
| 3231 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3232 | |
| 3233 | sb.setLength(0); |
| 3234 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3235 | sb.append(" "); |
| 3236 | sb.append(controllerName); |
| 3237 | sb.append(" Sleep time: "); |
| 3238 | formatTimeMs(sb, sleepTimeMs); |
| 3239 | sb.append("("); |
| 3240 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3241 | sb.append(")"); |
| 3242 | pw.println(sb.toString()); |
| 3243 | |
| 3244 | sb.setLength(0); |
| 3245 | sb.append(prefix); |
| 3246 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3247 | sb.append(controllerName); |
| 3248 | sb.append(" Idle time: "); |
| 3249 | formatTimeMs(sb, idleTimeMs); |
| 3250 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3251 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3252 | sb.append(")"); |
| 3253 | pw.println(sb.toString()); |
| 3254 | |
| 3255 | sb.setLength(0); |
| 3256 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3257 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3258 | sb.append(controllerName); |
| 3259 | sb.append(" Rx time: "); |
| 3260 | formatTimeMs(sb, rxTimeMs); |
| 3261 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3262 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3263 | sb.append(")"); |
| 3264 | pw.println(sb.toString()); |
| 3265 | |
| 3266 | sb.setLength(0); |
| 3267 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3268 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3269 | sb.append(controllerName); |
| 3270 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3271 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3272 | String [] powerLevel; |
| 3273 | switch(controllerName) { |
| 3274 | case "Cellular": |
| 3275 | powerLevel = new String[] { |
| 3276 | " less than 0dBm: ", |
| 3277 | " 0dBm to 8dBm: ", |
| 3278 | " 8dBm to 15dBm: ", |
| 3279 | " 15dBm to 20dBm: ", |
| 3280 | " above 20dBm: "}; |
| 3281 | break; |
| 3282 | default: |
| 3283 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3284 | break; |
| 3285 | } |
| 3286 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3287 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3288 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3289 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3290 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3291 | sb.setLength(0); |
| 3292 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3293 | sb.append(" "); |
| 3294 | sb.append(powerLevel[lvl]); |
| 3295 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3296 | formatTimeMs(sb, txLvlTimeMs); |
| 3297 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3298 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3299 | sb.append(")"); |
| 3300 | pw.println(sb.toString()); |
| 3301 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3302 | } else { |
| 3303 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3304 | formatTimeMs(sb, txLvlTimeMs); |
| 3305 | sb.append("("); |
| 3306 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3307 | sb.append(")"); |
| 3308 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3309 | } |
| 3310 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3311 | if (powerDrainMaMs > 0) { |
| 3312 | sb.setLength(0); |
| 3313 | sb.append(prefix); |
| 3314 | sb.append(" "); |
| 3315 | sb.append(controllerName); |
| 3316 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3317 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3318 | sb.append("mAh"); |
| 3319 | pw.println(sb.toString()); |
| 3320 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3324 | * Temporary for settings. |
| 3325 | */ |
| 3326 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3327 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3328 | } |
| 3329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | /** |
| 3331 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3332 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3333 | * 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] | 3334 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3335 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3336 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3338 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3339 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3342 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3343 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3344 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3345 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3347 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3348 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3349 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3350 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3351 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3352 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3353 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3354 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3355 | rawRealtime, which); |
| 3356 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3357 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3358 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3359 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3360 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3361 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3362 | final long dischargeCount = getUahDischarge(which); |
| 3363 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3364 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3365 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3366 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3367 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3368 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3369 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3370 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3371 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3372 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3373 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3376 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3377 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3378 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3379 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3380 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3381 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3382 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3383 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3384 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3385 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3386 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3387 | // Calculate both wakelock and wifi multicast wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3388 | long fullWakeLockTimeTotal = 0; |
| 3389 | long partialWakeLockTimeTotal = 0; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3390 | long multicastWakeLockTimeTotalMicros = 0; |
| 3391 | int multicastWakeLockCountTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3392 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3393 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3394 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3395 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3396 | // First calculating the wakelock stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3397 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3398 | = u.getWakelockStats(); |
| 3399 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3400 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3401 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3402 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3403 | if (fullWakeTimer != null) { |
| 3404 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3405 | which); |
| 3406 | } |
| 3407 | |
| 3408 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3409 | if (partialWakeTimer != null) { |
| 3410 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3411 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3412 | } |
| 3413 | } |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3414 | |
| 3415 | // Now calculating the wifi multicast wakelock stats |
| 3416 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3417 | if (mcTimer != null) { |
| 3418 | multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 3419 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 3420 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3421 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3422 | |
| 3423 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3424 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3425 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3426 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3427 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3428 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3429 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3430 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3431 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3432 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3433 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3434 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3435 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3436 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3437 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3438 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3439 | // Dump Modem controller stats |
| 3440 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3441 | getModemControllerActivity(), which); |
| 3442 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3443 | // Dump Wifi controller stats |
| 3444 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3445 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3446 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3447 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3448 | |
| 3449 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3450 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3451 | |
| 3452 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3453 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3454 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | // Dump misc stats |
| 3457 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3458 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3459 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3460 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3461 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3462 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3463 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3464 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3465 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3466 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3467 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3468 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3469 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3470 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3471 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3472 | // Dump screen brightness stats |
| 3473 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3474 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3475 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3476 | } |
| 3477 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3478 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3479 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3480 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3481 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3482 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3483 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3484 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3485 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3486 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3487 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3488 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3489 | } |
| 3490 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3491 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3492 | // Dump network type stats |
| 3493 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3494 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3495 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3496 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3497 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3498 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3499 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3500 | } |
| 3501 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3502 | |
| 3503 | // Dump wifi state stats |
| 3504 | args = new Object[NUM_WIFI_STATES]; |
| 3505 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3506 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3507 | } |
| 3508 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3509 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3510 | args[i] = getWifiStateCount(i, which); |
| 3511 | } |
| 3512 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3513 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3514 | // Dump wifi suppl state stats |
| 3515 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3516 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3517 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3518 | } |
| 3519 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3520 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3521 | args[i] = getWifiSupplStateCount(i, which); |
| 3522 | } |
| 3523 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3524 | |
| 3525 | // Dump wifi signal strength stats |
| 3526 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3527 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3528 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3529 | } |
| 3530 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3531 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3532 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3533 | } |
| 3534 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3535 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3536 | // Dump Multicast total stats |
| 3537 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3538 | multicastWakeLockTimeTotalMicros / 1000, |
| 3539 | multicastWakeLockCountTotal); |
| 3540 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3541 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3542 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3543 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3544 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3545 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3546 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3547 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3548 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3549 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3550 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3551 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3552 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3553 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3554 | } else { |
| 3555 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3556 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3557 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3558 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3559 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3560 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3561 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3562 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3563 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3564 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3565 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3566 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3567 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3568 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3569 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3570 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3571 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3572 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3573 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3574 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3575 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3576 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3577 | // Not doing the regular wake lock formatting to remain compatible |
| 3578 | // with the old checkin format. |
| 3579 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3580 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3581 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3582 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3585 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3586 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3587 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3588 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3589 | if (rpmStats.size() > 0) { |
| 3590 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3591 | sb.setLength(0); |
| 3592 | Timer totalTimer = ent.getValue(); |
| 3593 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3594 | int count = totalTimer.getCountLocked(which); |
| 3595 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3596 | long screenOffTimeMs = screenOffTimer != null |
| 3597 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3598 | int screenOffCount = screenOffTimer != null |
| 3599 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3600 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3601 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3602 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3603 | screenOffCount); |
| 3604 | } else { |
| 3605 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3606 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3607 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3608 | } |
| 3609 | } |
| 3610 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3611 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3612 | helper.create(this); |
| 3613 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3614 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3615 | if (sippers != null && sippers.size() > 0) { |
| 3616 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3617 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3618 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3619 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3620 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3621 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3622 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3623 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3624 | String label; |
| 3625 | switch (bs.drainType) { |
| 3626 | case IDLE: |
| 3627 | label="idle"; |
| 3628 | break; |
| 3629 | case CELL: |
| 3630 | label="cell"; |
| 3631 | break; |
| 3632 | case PHONE: |
| 3633 | label="phone"; |
| 3634 | break; |
| 3635 | case WIFI: |
| 3636 | label="wifi"; |
| 3637 | break; |
| 3638 | case BLUETOOTH: |
| 3639 | label="blue"; |
| 3640 | break; |
| 3641 | case SCREEN: |
| 3642 | label="scrn"; |
| 3643 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3644 | case FLASHLIGHT: |
| 3645 | label="flashlight"; |
| 3646 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3647 | case APP: |
| 3648 | uid = bs.uidObj.getUid(); |
| 3649 | label = "uid"; |
| 3650 | break; |
| 3651 | case USER: |
| 3652 | uid = UserHandle.getUid(bs.userId, 0); |
| 3653 | label = "user"; |
| 3654 | break; |
| 3655 | case UNACCOUNTED: |
| 3656 | label = "unacc"; |
| 3657 | break; |
| 3658 | case OVERCOUNTED: |
| 3659 | label = "over"; |
| 3660 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3661 | case CAMERA: |
| 3662 | label = "camera"; |
| 3663 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3664 | case MEMORY: |
| 3665 | label = "memory"; |
| 3666 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3667 | default: |
| 3668 | label = "???"; |
| 3669 | } |
| 3670 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3671 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3672 | bs.shouldHide ? 1 : 0, |
| 3673 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3674 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3675 | } |
| 3676 | } |
| 3677 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3678 | final long[] cpuFreqs = getCpuFreqs(); |
| 3679 | if (cpuFreqs != null) { |
| 3680 | sb.setLength(0); |
| 3681 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3682 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3683 | } |
| 3684 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3685 | } |
| 3686 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3687 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | for (int iu = 0; iu < NU; iu++) { |
| 3689 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3690 | if (reqUid >= 0 && uid != reqUid) { |
| 3691 | continue; |
| 3692 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3693 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3696 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3697 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3698 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3699 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3700 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3701 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3702 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3703 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3704 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3705 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3706 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3707 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3708 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3709 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3710 | // Background data transfers |
| 3711 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3712 | which); |
| 3713 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3714 | which); |
| 3715 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3716 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3717 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3718 | which); |
| 3719 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3720 | which); |
| 3721 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3722 | which); |
| 3723 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3724 | which); |
| 3725 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3726 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3727 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3728 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3729 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3730 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3731 | || wifiBytesBgTx > 0 |
| 3732 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3733 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3734 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3735 | wifiBytesRx, wifiBytesTx, |
| 3736 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3737 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3738 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3739 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3740 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3741 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3742 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3745 | // Dump modem controller data, per UID. |
| 3746 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3747 | u.getModemControllerActivity(), which); |
| 3748 | |
| 3749 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3750 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3751 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3752 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3753 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3754 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3755 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3756 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3757 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3758 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3759 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3760 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3761 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3762 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3763 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3764 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3765 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3766 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3768 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3769 | u.getWifiControllerActivity(), which); |
| 3770 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3771 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3772 | if (bleTimer != null) { |
| 3773 | // Convert from microseconds to milliseconds with rounding |
| 3774 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3775 | / 1000; |
| 3776 | if (totalTime != 0) { |
| 3777 | final int count = bleTimer.getCountLocked(which); |
| 3778 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3779 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3780 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3781 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3782 | final long actualTimeBg = bleTimerBg != null ? |
| 3783 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3784 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3785 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3786 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3787 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3788 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3789 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3790 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3791 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3792 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3793 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3794 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3795 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3796 | final Timer unoptimizedScanTimerBg = |
| 3797 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3798 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3799 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3800 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3801 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3802 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3803 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3804 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3805 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3806 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3807 | } |
| 3808 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3809 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3810 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3811 | u.getBluetoothControllerActivity(), which); |
| 3812 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3813 | if (u.hasUserActivity()) { |
| 3814 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3815 | boolean hasData = false; |
| 3816 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3817 | int val = u.getUserActivityCount(i, which); |
| 3818 | args[i] = val; |
| 3819 | if (val != 0) hasData = true; |
| 3820 | } |
| 3821 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3822 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3823 | } |
| 3824 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3825 | |
| 3826 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3827 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3828 | // Times are since reset (regardless of 'which') |
| 3829 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3830 | final Timer bgTimer = timer.getSubTimer(); |
| 3831 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3832 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3833 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3834 | } |
| 3835 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3836 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3837 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3838 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3839 | String linePrefix = ""; |
| 3840 | sb.setLength(0); |
| 3841 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3842 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3843 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3844 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3845 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3846 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3847 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3848 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3849 | rawRealtime, "w", which, linePrefix); |
| 3850 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3851 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3852 | if (sb.length() > 0) { |
| 3853 | String name = wakelocks.keyAt(iw); |
| 3854 | if (name.indexOf(',') >= 0) { |
| 3855 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3857 | if (name.indexOf('\n') >= 0) { |
| 3858 | name = name.replace('\n', '_'); |
| 3859 | } |
| 3860 | if (name.indexOf('\r') >= 0) { |
| 3861 | name = name.replace('\r', '_'); |
| 3862 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3863 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | } |
| 3865 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3866 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3867 | // WiFi Multicast Wakelock Statistics |
| 3868 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3869 | if (mcTimer != null) { |
| 3870 | final long totalMcWakelockTimeMs = |
| 3871 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 3872 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 3873 | if(totalMcWakelockTimeMs > 0) { |
| 3874 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 3875 | totalMcWakelockTimeMs, countMcWakelock); |
| 3876 | } |
| 3877 | } |
| 3878 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3879 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3880 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3881 | final Timer timer = syncs.valueAt(isy); |
| 3882 | // Convert from microseconds to milliseconds with rounding |
| 3883 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3884 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3885 | final Timer bgTimer = timer.getSubTimer(); |
| 3886 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3887 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3888 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3889 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3890 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3891 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3895 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3896 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3897 | final Timer timer = jobs.valueAt(ij); |
| 3898 | // Convert from microseconds to milliseconds with rounding |
| 3899 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3900 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3901 | final Timer bgTimer = timer.getSubTimer(); |
| 3902 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3903 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3904 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3905 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3906 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3907 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3911 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3912 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3913 | SparseIntArray types = completions.valueAt(ic); |
| 3914 | if (types != null) { |
| 3915 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3916 | "\"" + completions.keyAt(ic) + "\"", |
| 3917 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3918 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3919 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3920 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3921 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3922 | } |
| 3923 | } |
| 3924 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3925 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3926 | rawRealtime, which); |
| 3927 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3928 | rawRealtime, which); |
| 3929 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3930 | rawRealtime, which); |
| 3931 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3932 | rawRealtime, which); |
| 3933 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3934 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3935 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3936 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3937 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3938 | final int sensorNumber = sensors.keyAt(ise); |
| 3939 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3940 | if (timer != null) { |
| 3941 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3942 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3943 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3944 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3945 | final int count = timer.getCountLocked(which); |
| 3946 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3947 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3948 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3949 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3950 | final long bgActualTime = bgTimer != null ? |
| 3951 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3952 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3953 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3954 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3955 | } |
| 3956 | } |
| 3957 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3958 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3959 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3960 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 3961 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 3962 | rawRealtime, which); |
| 3963 | |
| 3964 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3965 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3966 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3967 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3968 | long totalStateTime = 0; |
| 3969 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3970 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3971 | totalStateTime += time; |
| 3972 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3973 | } |
| 3974 | if (totalStateTime > 0) { |
| 3975 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3976 | } |
| 3977 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3978 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3979 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3980 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3981 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3982 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3985 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 3986 | if (cpuFreqs != null) { |
| 3987 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3988 | // If total cpuFreqTimes is null, then we don't need to check for |
| 3989 | // screenOffCpuFreqTimes. |
| 3990 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 3991 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3992 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3993 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3994 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3995 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3996 | if (screenOffCpuFreqTimeMs != null) { |
| 3997 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3998 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3999 | } |
| 4000 | } else { |
| 4001 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4002 | sb.append(",0"); |
| 4003 | } |
| 4004 | } |
| 4005 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4006 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4007 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4010 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4011 | = u.getProcessStats(); |
| 4012 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4013 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4014 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4015 | final long userMillis = ps.getUserTime(which); |
| 4016 | final long systemMillis = ps.getSystemTime(which); |
| 4017 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4018 | final int starts = ps.getStarts(which); |
| 4019 | final int numCrashes = ps.getNumCrashes(which); |
| 4020 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4021 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4022 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4023 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4024 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4025 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | } |
| 4027 | } |
| 4028 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4029 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4030 | = u.getPackageStats(); |
| 4031 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4032 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4033 | int wakeups = 0; |
| 4034 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4035 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4036 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4037 | wakeups += count; |
| 4038 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4039 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4040 | } |
| 4041 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4042 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4043 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4044 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4045 | final int starts = ss.getStarts(which); |
| 4046 | final int launches = ss.getLaunches(which); |
| 4047 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4048 | dumpLine(pw, uid, category, APK_DATA, |
| 4049 | wakeups, // wakeup alarms |
| 4050 | packageStats.keyAt(ipkg), // Apk |
| 4051 | serviceStats.keyAt(isvc), // service |
| 4052 | startTime / 1000, // time spent started, in ms |
| 4053 | starts, |
| 4054 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4061 | static final class TimerEntry { |
| 4062 | final String mName; |
| 4063 | final int mId; |
| 4064 | final BatteryStats.Timer mTimer; |
| 4065 | final long mTime; |
| 4066 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4067 | mName = name; |
| 4068 | mId = id; |
| 4069 | mTimer = timer; |
| 4070 | mTime = time; |
| 4071 | } |
| 4072 | } |
| 4073 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4074 | private void printmAh(PrintWriter printer, double power) { |
| 4075 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4076 | } |
| 4077 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4078 | private void printmAh(StringBuilder sb, double power) { |
| 4079 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4080 | } |
| 4081 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4082 | /** |
| 4083 | * Temporary for settings. |
| 4084 | */ |
| 4085 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4086 | int reqUid) { |
| 4087 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4088 | } |
| 4089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4090 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4091 | 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] | 4092 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4094 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4095 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | |
| 4098 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4099 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4100 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4101 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4102 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4103 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4104 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4105 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4106 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4107 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4108 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4109 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4110 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4111 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4112 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4114 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4115 | if (estimatedBatteryCapacity > 0) { |
| 4116 | sb.setLength(0); |
| 4117 | sb.append(prefix); |
| 4118 | sb.append(" Estimated battery capacity: "); |
| 4119 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4120 | sb.append(" mAh"); |
| 4121 | pw.println(sb.toString()); |
| 4122 | } |
| 4123 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4124 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4125 | if (minLearnedBatteryCapacity > 0) { |
| 4126 | sb.setLength(0); |
| 4127 | sb.append(prefix); |
| 4128 | sb.append(" Min learned battery capacity: "); |
| 4129 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4130 | sb.append(" mAh"); |
| 4131 | pw.println(sb.toString()); |
| 4132 | } |
| 4133 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4134 | if (maxLearnedBatteryCapacity > 0) { |
| 4135 | sb.setLength(0); |
| 4136 | sb.append(prefix); |
| 4137 | sb.append(" Max learned battery capacity: "); |
| 4138 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4139 | sb.append(" mAh"); |
| 4140 | pw.println(sb.toString()); |
| 4141 | } |
| 4142 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4143 | sb.setLength(0); |
| 4144 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4145 | sb.append(" Time on battery: "); |
| 4146 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4147 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4148 | sb.append(") realtime, "); |
| 4149 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4150 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4151 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4152 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4153 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4154 | sb.setLength(0); |
| 4155 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4156 | sb.append(" Time on battery screen off: "); |
| 4157 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4158 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4159 | sb.append(") realtime, "); |
| 4160 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4161 | sb.append("("); |
| 4162 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4163 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4164 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4165 | |
| 4166 | sb.setLength(0); |
| 4167 | sb.append(prefix); |
| 4168 | sb.append(" Time on battery screen doze: "); |
| 4169 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4170 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4171 | sb.append(")"); |
| 4172 | pw.println(sb.toString()); |
| 4173 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4174 | sb.setLength(0); |
| 4175 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4176 | sb.append(" Total run time: "); |
| 4177 | formatTimeMs(sb, totalRealtime / 1000); |
| 4178 | sb.append("realtime, "); |
| 4179 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4180 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4181 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4182 | if (batteryTimeRemaining >= 0) { |
| 4183 | sb.setLength(0); |
| 4184 | sb.append(prefix); |
| 4185 | sb.append(" Battery time remaining: "); |
| 4186 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4187 | pw.println(sb.toString()); |
| 4188 | } |
| 4189 | if (chargeTimeRemaining >= 0) { |
| 4190 | sb.setLength(0); |
| 4191 | sb.append(prefix); |
| 4192 | sb.append(" Charge time remaining: "); |
| 4193 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4194 | pw.println(sb.toString()); |
| 4195 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4196 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4197 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4198 | if (dischargeCount >= 0) { |
| 4199 | sb.setLength(0); |
| 4200 | sb.append(prefix); |
| 4201 | sb.append(" Discharge: "); |
| 4202 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4203 | sb.append(" mAh"); |
| 4204 | pw.println(sb.toString()); |
| 4205 | } |
| 4206 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4207 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4208 | if (dischargeScreenOffCount >= 0) { |
| 4209 | sb.setLength(0); |
| 4210 | sb.append(prefix); |
| 4211 | sb.append(" Screen off discharge: "); |
| 4212 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4213 | sb.append(" mAh"); |
| 4214 | pw.println(sb.toString()); |
| 4215 | } |
| 4216 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4217 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4218 | if (dischargeScreenDozeCount >= 0) { |
| 4219 | sb.setLength(0); |
| 4220 | sb.append(prefix); |
| 4221 | sb.append(" Screen doze discharge: "); |
| 4222 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4223 | sb.append(" mAh"); |
| 4224 | pw.println(sb.toString()); |
| 4225 | } |
| 4226 | |
| 4227 | final long dischargeScreenOnCount = |
| 4228 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4229 | if (dischargeScreenOnCount >= 0) { |
| 4230 | sb.setLength(0); |
| 4231 | sb.append(prefix); |
| 4232 | sb.append(" Screen on discharge: "); |
| 4233 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4234 | sb.append(" mAh"); |
| 4235 | pw.println(sb.toString()); |
| 4236 | } |
| 4237 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4238 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4239 | if (dischargeLightDozeCount >= 0) { |
| 4240 | sb.setLength(0); |
| 4241 | sb.append(prefix); |
| 4242 | sb.append(" Device light doze discharge: "); |
| 4243 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4244 | sb.append(" mAh"); |
| 4245 | pw.println(sb.toString()); |
| 4246 | } |
| 4247 | |
| 4248 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4249 | if (dischargeDeepDozeCount >= 0) { |
| 4250 | sb.setLength(0); |
| 4251 | sb.append(prefix); |
| 4252 | sb.append(" Device deep doze discharge: "); |
| 4253 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4254 | sb.append(" mAh"); |
| 4255 | pw.println(sb.toString()); |
| 4256 | } |
| 4257 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4258 | pw.print(" Start clock time: "); |
| 4259 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4260 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4261 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4262 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4263 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4264 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4265 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4266 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4267 | rawRealtime, which); |
| 4268 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4269 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4270 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4271 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4272 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4273 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4274 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4275 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4276 | sb.append(prefix); |
| 4277 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4278 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4279 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4280 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4281 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4282 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4283 | pw.println(sb.toString()); |
| 4284 | sb.setLength(0); |
| 4285 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4286 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4287 | boolean didOne = false; |
| 4288 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4289 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4290 | if (time == 0) { |
| 4291 | continue; |
| 4292 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4293 | sb.append("\n "); |
| 4294 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4295 | didOne = true; |
| 4296 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4297 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4298 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4299 | sb.append("("); |
| 4300 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4301 | sb.append(")"); |
| 4302 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4303 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4304 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4305 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4306 | sb.setLength(0); |
| 4307 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4308 | sb.append(" Power save mode enabled: "); |
| 4309 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4310 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4311 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4312 | sb.append(")"); |
| 4313 | pw.println(sb.toString()); |
| 4314 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4315 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4316 | sb.setLength(0); |
| 4317 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4318 | sb.append(" Device light idling: "); |
| 4319 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4320 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4321 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4322 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4323 | sb.append("x"); |
| 4324 | pw.println(sb.toString()); |
| 4325 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4326 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4327 | sb.setLength(0); |
| 4328 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4329 | sb.append(" Idle mode light time: "); |
| 4330 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4331 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4332 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4333 | sb.append(") "); |
| 4334 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4335 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4336 | sb.append(" -- longest "); |
| 4337 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4338 | pw.println(sb.toString()); |
| 4339 | } |
| 4340 | if (deviceIdlingTime != 0) { |
| 4341 | sb.setLength(0); |
| 4342 | sb.append(prefix); |
| 4343 | sb.append(" Device full idling: "); |
| 4344 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4345 | sb.append("("); |
| 4346 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4347 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4348 | sb.append("x"); |
| 4349 | pw.println(sb.toString()); |
| 4350 | } |
| 4351 | if (deviceIdleModeFullTime != 0) { |
| 4352 | sb.setLength(0); |
| 4353 | sb.append(prefix); |
| 4354 | sb.append(" Idle mode full time: "); |
| 4355 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4356 | sb.append("("); |
| 4357 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4358 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4359 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4360 | sb.append("x"); |
| 4361 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4362 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4363 | pw.println(sb.toString()); |
| 4364 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4365 | if (phoneOnTime != 0) { |
| 4366 | sb.setLength(0); |
| 4367 | sb.append(prefix); |
| 4368 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4369 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4370 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4371 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4372 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4373 | if (connChanges != 0) { |
| 4374 | pw.print(prefix); |
| 4375 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4376 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4377 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4378 | // Calculate both wakelock and wifi multicast wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4379 | long fullWakeLockTimeTotalMicros = 0; |
| 4380 | long partialWakeLockTimeTotalMicros = 0; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4381 | long multicastWakeLockTimeTotalMicros = 0; |
| 4382 | int multicastWakeLockCountTotal = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4383 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4384 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4385 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4386 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4387 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4388 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4389 | // First calculate wakelock statistics |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4390 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4391 | = u.getWakelockStats(); |
| 4392 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4393 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4394 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4395 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4396 | if (fullWakeTimer != null) { |
| 4397 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4398 | rawRealtime, which); |
| 4399 | } |
| 4400 | |
| 4401 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4402 | if (partialWakeTimer != null) { |
| 4403 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4404 | rawRealtime, which); |
| 4405 | if (totalTimeMicros > 0) { |
| 4406 | if (reqUid < 0) { |
| 4407 | // Only show the ordered list of all wake |
| 4408 | // locks if the caller is not asking for data |
| 4409 | // about a specific uid. |
| 4410 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4411 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4412 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4413 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4414 | } |
| 4415 | } |
| 4416 | } |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4417 | |
| 4418 | // Next calculate wifi multicast wakelock statistics |
| 4419 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 4420 | if (mcTimer != null) { |
| 4421 | multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 4422 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 4423 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4424 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4425 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4426 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4427 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4428 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4429 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4430 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4431 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4432 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4433 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4434 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4435 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4436 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4437 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4438 | sb.setLength(0); |
| 4439 | sb.append(prefix); |
| 4440 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4441 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4442 | pw.println(sb.toString()); |
| 4443 | } |
| 4444 | |
| 4445 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4446 | sb.setLength(0); |
| 4447 | sb.append(prefix); |
| 4448 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4449 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4450 | pw.println(sb.toString()); |
| 4451 | } |
| 4452 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4453 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4454 | sb.setLength(0); |
| 4455 | sb.append(prefix); |
| 4456 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4457 | sb.append(multicastWakeLockCountTotal); |
| 4458 | pw.println(sb.toString()); |
| 4459 | |
| 4460 | sb.setLength(0); |
| 4461 | sb.append(prefix); |
| 4462 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4463 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4464 | pw.println(sb.toString()); |
| 4465 | } |
| 4466 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4467 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4468 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4469 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4470 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4471 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4472 | pw.println(sb.toString()); |
| 4473 | |
| 4474 | pw.print(prefix); |
| 4475 | sb.setLength(0); |
| 4476 | sb.append(prefix); |
| 4477 | sb.append(" Logging duration for connectivity statistics: "); |
| 4478 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4479 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4480 | |
| 4481 | sb.setLength(0); |
| 4482 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4483 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4484 | pw.println(sb.toString()); |
| 4485 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4486 | pw.print(prefix); |
| 4487 | sb.setLength(0); |
| 4488 | sb.append(prefix); |
| 4489 | sb.append(" Cellular kernel active time: "); |
| 4490 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4491 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4492 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4493 | sb.append(")"); |
| 4494 | pw.println(sb.toString()); |
| 4495 | |
| 4496 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4497 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4498 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4499 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4500 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4501 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4502 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4503 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4504 | didOne = false; |
| 4505 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4506 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4507 | if (time == 0) { |
| 4508 | continue; |
| 4509 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4510 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4511 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4512 | didOne = true; |
| 4513 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4514 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4515 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4516 | sb.append("("); |
| 4517 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4518 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4519 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4520 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4521 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4522 | |
| 4523 | sb.setLength(0); |
| 4524 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4525 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4526 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4527 | "very poor (less than -128dBm): ", |
| 4528 | "poor (-128dBm to -118dBm): ", |
| 4529 | "moderate (-118dBm to -108dBm): ", |
| 4530 | "good (-108dBm to -98dBm): ", |
| 4531 | "great (greater than -98dBm): "}; |
| 4532 | didOne = false; |
| 4533 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4534 | cellularRxSignalStrengthDescription.length); |
| 4535 | for (int i=0; i<numCellularRxBins; i++) { |
| 4536 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4537 | if (time == 0) { |
| 4538 | continue; |
| 4539 | } |
| 4540 | sb.append("\n "); |
| 4541 | sb.append(prefix); |
| 4542 | didOne = true; |
| 4543 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4544 | sb.append(" "); |
| 4545 | formatTimeMs(sb, time/1000); |
| 4546 | sb.append("("); |
| 4547 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4548 | sb.append(") "); |
| 4549 | } |
| 4550 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4551 | pw.println(sb.toString()); |
| 4552 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4553 | printControllerActivity(pw, sb, prefix, "Cellular", |
| 4554 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4555 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4556 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4557 | sb.setLength(0); |
| 4558 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4559 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4560 | pw.println(sb.toString()); |
| 4561 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4562 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4563 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4564 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4565 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4566 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4567 | sb.setLength(0); |
| 4568 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4569 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4570 | didOne = false; |
| 4571 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4572 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4573 | if (time == 0) { |
| 4574 | continue; |
| 4575 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4576 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4577 | didOne = true; |
| 4578 | sb.append(WIFI_STATE_NAMES[i]); |
| 4579 | sb.append(" "); |
| 4580 | formatTimeMs(sb, time/1000); |
| 4581 | sb.append("("); |
| 4582 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4583 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4584 | } |
| 4585 | if (!didOne) sb.append(" (no activity)"); |
| 4586 | pw.println(sb.toString()); |
| 4587 | |
| 4588 | sb.setLength(0); |
| 4589 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4590 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4591 | didOne = false; |
| 4592 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4593 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4594 | if (time == 0) { |
| 4595 | continue; |
| 4596 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4597 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4598 | didOne = true; |
| 4599 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4600 | sb.append(" "); |
| 4601 | formatTimeMs(sb, time/1000); |
| 4602 | sb.append("("); |
| 4603 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4604 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4605 | } |
| 4606 | if (!didOne) sb.append(" (no activity)"); |
| 4607 | pw.println(sb.toString()); |
| 4608 | |
| 4609 | sb.setLength(0); |
| 4610 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4611 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4612 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4613 | "very poor (less than -88.75dBm): ", |
| 4614 | "poor (-88.75 to -77.5dBm): ", |
| 4615 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4616 | "good (-66.25dBm to -55dBm): ", |
| 4617 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4618 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4619 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4620 | wifiRxSignalStrengthDescription.length); |
| 4621 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4622 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4623 | if (time == 0) { |
| 4624 | continue; |
| 4625 | } |
| 4626 | sb.append("\n "); |
| 4627 | sb.append(prefix); |
| 4628 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4629 | sb.append(" "); |
| 4630 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4631 | formatTimeMs(sb, time/1000); |
| 4632 | sb.append("("); |
| 4633 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4634 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4635 | } |
| 4636 | if (!didOne) sb.append(" (no activity)"); |
| 4637 | pw.println(sb.toString()); |
| 4638 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4639 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4640 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4641 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4642 | sb.setLength(0); |
| 4643 | sb.append(prefix); |
| 4644 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4645 | pw.println(sb.toString()); |
| 4646 | pw.println(""); |
| 4647 | |
| 4648 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4649 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4650 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4651 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4652 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4653 | sb.setLength(0); |
| 4654 | sb.append(prefix); |
| 4655 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4656 | pw.println(sb.toString()); |
| 4657 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4658 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4659 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4660 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4661 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4662 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4663 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4664 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4665 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4666 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4667 | pw.println(getDischargeStartLevel()); |
| 4668 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4669 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4670 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4671 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4672 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4673 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4674 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4675 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4676 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4677 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4678 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4679 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4680 | pw.println(getDischargeAmountScreenOff()); |
| 4681 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4682 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4683 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4684 | } else { |
| 4685 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4686 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4687 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4688 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4689 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4690 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4691 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4692 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4693 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4694 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4695 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4696 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4697 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4698 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4699 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4700 | helper.create(this); |
| 4701 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4702 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4703 | if (sippers != null && sippers.size() > 0) { |
| 4704 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4705 | pw.print(prefix); pw.print(" Capacity: "); |
| 4706 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4707 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4708 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4709 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4710 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4711 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4712 | pw.println(); |
| 4713 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4714 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4715 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4716 | switch (bs.drainType) { |
| 4717 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4718 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4719 | break; |
| 4720 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4721 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4722 | break; |
| 4723 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4724 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4725 | break; |
| 4726 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4727 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4728 | break; |
| 4729 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4730 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4731 | break; |
| 4732 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4733 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4734 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4735 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4736 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4737 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4738 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4739 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4740 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4741 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4742 | break; |
| 4743 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4744 | pw.print(" User "); pw.print(bs.userId); |
| 4745 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4746 | break; |
| 4747 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4748 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4749 | break; |
| 4750 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4751 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4752 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4753 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4754 | pw.print(" Camera: "); |
| 4755 | break; |
| 4756 | default: |
| 4757 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4758 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4759 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4760 | printmAh(pw, bs.totalPowerMah); |
| 4761 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4762 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4763 | // If the usage (generic power) isn't the whole amount, we list out |
| 4764 | // what components are involved in the calculation. |
| 4765 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4766 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4767 | if (bs.usagePowerMah != 0) { |
| 4768 | pw.print(" usage="); |
| 4769 | printmAh(pw, bs.usagePowerMah); |
| 4770 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4771 | if (bs.cpuPowerMah != 0) { |
| 4772 | pw.print(" cpu="); |
| 4773 | printmAh(pw, bs.cpuPowerMah); |
| 4774 | } |
| 4775 | if (bs.wakeLockPowerMah != 0) { |
| 4776 | pw.print(" wake="); |
| 4777 | printmAh(pw, bs.wakeLockPowerMah); |
| 4778 | } |
| 4779 | if (bs.mobileRadioPowerMah != 0) { |
| 4780 | pw.print(" radio="); |
| 4781 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4782 | } |
| 4783 | if (bs.wifiPowerMah != 0) { |
| 4784 | pw.print(" wifi="); |
| 4785 | printmAh(pw, bs.wifiPowerMah); |
| 4786 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4787 | if (bs.bluetoothPowerMah != 0) { |
| 4788 | pw.print(" bt="); |
| 4789 | printmAh(pw, bs.bluetoothPowerMah); |
| 4790 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4791 | if (bs.gpsPowerMah != 0) { |
| 4792 | pw.print(" gps="); |
| 4793 | printmAh(pw, bs.gpsPowerMah); |
| 4794 | } |
| 4795 | if (bs.sensorPowerMah != 0) { |
| 4796 | pw.print(" sensor="); |
| 4797 | printmAh(pw, bs.sensorPowerMah); |
| 4798 | } |
| 4799 | if (bs.cameraPowerMah != 0) { |
| 4800 | pw.print(" camera="); |
| 4801 | printmAh(pw, bs.cameraPowerMah); |
| 4802 | } |
| 4803 | if (bs.flashlightPowerMah != 0) { |
| 4804 | pw.print(" flash="); |
| 4805 | printmAh(pw, bs.flashlightPowerMah); |
| 4806 | } |
| 4807 | pw.print(" )"); |
| 4808 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4809 | |
| 4810 | // If there is additional smearing information, include it. |
| 4811 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4812 | pw.print(" Including smearing: "); |
| 4813 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4814 | pw.print(" ("); |
| 4815 | if (bs.screenPowerMah != 0) { |
| 4816 | pw.print(" screen="); |
| 4817 | printmAh(pw, bs.screenPowerMah); |
| 4818 | } |
| 4819 | if (bs.proportionalSmearMah != 0) { |
| 4820 | pw.print(" proportional="); |
| 4821 | printmAh(pw, bs.proportionalSmearMah); |
| 4822 | } |
| 4823 | pw.print(" )"); |
| 4824 | } |
| 4825 | if (bs.shouldHide) { |
| 4826 | pw.print(" Excluded from smearing"); |
| 4827 | } |
| 4828 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4829 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4830 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4831 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4832 | } |
| 4833 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4834 | sippers = helper.getMobilemsppList(); |
| 4835 | if (sippers != null && sippers.size() > 0) { |
| 4836 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4837 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4838 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4839 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4840 | sb.setLength(0); |
| 4841 | sb.append(prefix); sb.append(" Uid "); |
| 4842 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4843 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4844 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4845 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4846 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4847 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4848 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4849 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4850 | sb.setLength(0); |
| 4851 | sb.append(prefix); |
| 4852 | sb.append(" TOTAL TIME: "); |
| 4853 | formatTimeMs(sb, totalTime); |
| 4854 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4855 | sb.append(")"); |
| 4856 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4857 | pw.println(); |
| 4858 | } |
| 4859 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4860 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4861 | @Override |
| 4862 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4863 | long lhsTime = lhs.mTime; |
| 4864 | long rhsTime = rhs.mTime; |
| 4865 | if (lhsTime < rhsTime) { |
| 4866 | return 1; |
| 4867 | } |
| 4868 | if (lhsTime > rhsTime) { |
| 4869 | return -1; |
| 4870 | } |
| 4871 | return 0; |
| 4872 | } |
| 4873 | }; |
| 4874 | |
| 4875 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4876 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4877 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4878 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4879 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4880 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4881 | : kernelWakelocks.entrySet()) { |
| 4882 | final BatteryStats.Timer timer = ent.getValue(); |
| 4883 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4884 | if (totalTimeMillis > 0) { |
| 4885 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4886 | } |
| 4887 | } |
| 4888 | if (ktimers.size() > 0) { |
| 4889 | Collections.sort(ktimers, timerComparator); |
| 4890 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4891 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4892 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4893 | String linePrefix = ": "; |
| 4894 | sb.setLength(0); |
| 4895 | sb.append(prefix); |
| 4896 | sb.append(" Kernel Wake lock "); |
| 4897 | sb.append(timer.mName); |
| 4898 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4899 | which, linePrefix); |
| 4900 | if (!linePrefix.equals(": ")) { |
| 4901 | sb.append(" realtime"); |
| 4902 | // Only print out wake locks that were held |
| 4903 | pw.println(sb.toString()); |
| 4904 | } |
| 4905 | } |
| 4906 | pw.println(); |
| 4907 | } |
| 4908 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4909 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4910 | if (timers.size() > 0) { |
| 4911 | Collections.sort(timers, timerComparator); |
| 4912 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4913 | for (int i=0; i<timers.size(); i++) { |
| 4914 | TimerEntry timer = timers.get(i); |
| 4915 | sb.setLength(0); |
| 4916 | sb.append(" Wake lock "); |
| 4917 | UserHandle.formatUid(sb, timer.mId); |
| 4918 | sb.append(" "); |
| 4919 | sb.append(timer.mName); |
| 4920 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4921 | sb.append(" realtime"); |
| 4922 | pw.println(sb.toString()); |
| 4923 | } |
| 4924 | timers.clear(); |
| 4925 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4926 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4927 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4928 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4929 | if (wakeupReasons.size() > 0) { |
| 4930 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4931 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4932 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4933 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4934 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4935 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4936 | } |
| 4937 | Collections.sort(reasons, timerComparator); |
| 4938 | for (int i=0; i<reasons.size(); i++) { |
| 4939 | TimerEntry timer = reasons.get(i); |
| 4940 | String linePrefix = ": "; |
| 4941 | sb.setLength(0); |
| 4942 | sb.append(prefix); |
| 4943 | sb.append(" Wakeup reason "); |
| 4944 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4945 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4946 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4947 | pw.println(sb.toString()); |
| 4948 | } |
| 4949 | pw.println(); |
| 4950 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4951 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4952 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4953 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4954 | if (mMemoryStats.size() > 0) { |
| 4955 | pw.println(" Memory Stats"); |
| 4956 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4957 | sb.setLength(0); |
| 4958 | sb.append(" Bandwidth "); |
| 4959 | sb.append(mMemoryStats.keyAt(i)); |
| 4960 | sb.append(" Time "); |
| 4961 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4962 | pw.println(sb.toString()); |
| 4963 | } |
| 4964 | pw.println(); |
| 4965 | } |
| 4966 | |
| 4967 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 4968 | if (rpmStats.size() > 0) { |
| 4969 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 4970 | if (rpmStats.size() > 0) { |
| 4971 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 4972 | final String timerName = ent.getKey(); |
| 4973 | final Timer timer = ent.getValue(); |
| 4974 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4975 | } |
| 4976 | } |
| 4977 | pw.println(); |
| 4978 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4979 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 4980 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4981 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4982 | pw.print(prefix); |
| 4983 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 4984 | if (screenOffRpmStats.size() > 0) { |
| 4985 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 4986 | final String timerName = ent.getKey(); |
| 4987 | final Timer timer = ent.getValue(); |
| 4988 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4989 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4990 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4991 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4992 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4995 | final long[] cpuFreqs = getCpuFreqs(); |
| 4996 | if (cpuFreqs != null) { |
| 4997 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4998 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4999 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5000 | sb.append(" " + cpuFreqs[i]); |
| 5001 | } |
| 5002 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5003 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5004 | } |
| 5005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | for (int iu=0; iu<NU; iu++) { |
| 5007 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5008 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5009 | continue; |
| 5010 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5011 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5012 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5013 | |
| 5014 | pw.print(prefix); |
| 5015 | pw.print(" "); |
| 5016 | UserHandle.formatUid(pw, uid); |
| 5017 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5019 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5020 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5021 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5022 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5023 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5024 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5025 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5026 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5027 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5028 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5029 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5030 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5031 | |
| 5032 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5033 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5034 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5035 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5036 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5037 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5038 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5039 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5040 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5041 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5042 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5043 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5044 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5045 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5046 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5047 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5048 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5049 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5050 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5051 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5052 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5053 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5055 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5056 | sb.setLength(0); |
| 5057 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5058 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5059 | sb.append("("); |
| 5060 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5061 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5062 | long packets = mobileRxPackets + mobileTxPackets; |
| 5063 | if (packets == 0) { |
| 5064 | packets = 1; |
| 5065 | } |
| 5066 | sb.append(" @ "); |
| 5067 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5068 | sb.append(" mspp"); |
| 5069 | pw.println(sb.toString()); |
| 5070 | } |
| 5071 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5072 | if (mobileWakeup > 0) { |
| 5073 | sb.setLength(0); |
| 5074 | sb.append(prefix); |
| 5075 | sb.append(" Mobile radio AP wakeups: "); |
| 5076 | sb.append(mobileWakeup); |
| 5077 | pw.println(sb.toString()); |
| 5078 | } |
| 5079 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5080 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 5081 | u.getModemControllerActivity(), which); |
| 5082 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5083 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5084 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5085 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5086 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5087 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5088 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5091 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5092 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5093 | || uidWifiRunningTime != 0) { |
| 5094 | sb.setLength(0); |
| 5095 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5096 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5097 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5098 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5099 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5100 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5101 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5102 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5103 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5104 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5105 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5106 | whichBatteryRealtime)); sb.append(") "); |
| 5107 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5108 | sb.append("x\n"); |
| 5109 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5110 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5111 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5112 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5113 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5114 | sb.append(") "); |
| 5115 | sb.append(wifiScanCount); |
| 5116 | sb.append("x\n"); |
| 5117 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5118 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5119 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5120 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5121 | sb.append(") "); |
| 5122 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5123 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5124 | pw.println(sb.toString()); |
| 5125 | } |
| 5126 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5127 | if (wifiWakeup > 0) { |
| 5128 | sb.setLength(0); |
| 5129 | sb.append(prefix); |
| 5130 | sb.append(" WiFi AP wakeups: "); |
| 5131 | sb.append(wifiWakeup); |
| 5132 | pw.println(sb.toString()); |
| 5133 | } |
| 5134 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5135 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 5136 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5137 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5138 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5139 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5140 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5141 | pw.print(formatBytesLocked(btTxBytes)); |
| 5142 | pw.println(" sent"); |
| 5143 | } |
| 5144 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5145 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5146 | if (bleTimer != null) { |
| 5147 | // Convert from microseconds to milliseconds with rounding |
| 5148 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5149 | / 1000; |
| 5150 | if (totalTimeMs != 0) { |
| 5151 | final int count = bleTimer.getCountLocked(which); |
| 5152 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5153 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5154 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5155 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5156 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5157 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5158 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5159 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5160 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5161 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5162 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5163 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5164 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5165 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5166 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5167 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5168 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5169 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5170 | final Timer unoptimizedScanTimerBg = |
| 5171 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5172 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5173 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5174 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5175 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5176 | |
| 5177 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5178 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5179 | sb.append(prefix); |
| 5180 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5181 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5182 | sb.append(" ("); |
| 5183 | sb.append(count); |
| 5184 | sb.append(" times)"); |
| 5185 | if (bleTimer.isRunningLocked()) { |
| 5186 | sb.append(" (currently running)"); |
| 5187 | } |
| 5188 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5189 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5190 | |
| 5191 | sb.append(prefix); |
| 5192 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5193 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5194 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5195 | sb.append(count); |
| 5196 | sb.append(" times)"); |
| 5197 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5198 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5199 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5200 | sb.append("\n"); |
| 5201 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5202 | sb.append(prefix); |
| 5203 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5204 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5205 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5206 | sb.append(countBg); |
| 5207 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5208 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5209 | sb.append(" (currently running in background)"); |
| 5210 | } |
| 5211 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5212 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5213 | |
| 5214 | sb.append(prefix); |
| 5215 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5216 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5217 | sb.append(" ("); |
| 5218 | sb.append(resultCountBg); |
| 5219 | sb.append(" in background)"); |
| 5220 | |
| 5221 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5222 | sb.append("\n"); |
| 5223 | sb.append(prefix); |
| 5224 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5225 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5226 | sb.append(" (max "); |
| 5227 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5228 | sb.append(")"); |
| 5229 | if (unoptimizedScanTimer != null |
| 5230 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5231 | sb.append(" (currently running unoptimized)"); |
| 5232 | } |
| 5233 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5234 | sb.append("\n"); |
| 5235 | sb.append(prefix); |
| 5236 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5237 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5238 | sb.append(" (max "); |
| 5239 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5240 | sb.append(")"); |
| 5241 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5242 | sb.append(" (currently running unoptimized in background)"); |
| 5243 | } |
| 5244 | } |
| 5245 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5246 | pw.println(sb.toString()); |
| 5247 | uidActivity = true; |
| 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5252 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5253 | if (u.hasUserActivity()) { |
| 5254 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5255 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5256 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5257 | if (val != 0) { |
| 5258 | if (!hasData) { |
| 5259 | sb.setLength(0); |
| 5260 | sb.append(" User activity: "); |
| 5261 | hasData = true; |
| 5262 | } else { |
| 5263 | sb.append(", "); |
| 5264 | } |
| 5265 | sb.append(val); |
| 5266 | sb.append(" "); |
| 5267 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5268 | } |
| 5269 | } |
| 5270 | if (hasData) { |
| 5271 | pw.println(sb.toString()); |
| 5272 | } |
| 5273 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5275 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5276 | = u.getWakelockStats(); |
| 5277 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5278 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5279 | int countWakelock = 0; |
| 5280 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5281 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5282 | String linePrefix = ": "; |
| 5283 | sb.setLength(0); |
| 5284 | sb.append(prefix); |
| 5285 | sb.append(" Wake lock "); |
| 5286 | sb.append(wakelocks.keyAt(iw)); |
| 5287 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5288 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5289 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5290 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5291 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5292 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5293 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5294 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5295 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5296 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5297 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5298 | sb.append(" realtime"); |
| 5299 | pw.println(sb.toString()); |
| 5300 | uidActivity = true; |
| 5301 | countWakelock++; |
| 5302 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5303 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5304 | rawRealtime, which); |
| 5305 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5306 | rawRealtime, which); |
| 5307 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5308 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5309 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5310 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5311 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5312 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5313 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5314 | // pooled and therefore just a lower bound) |
| 5315 | long actualTotalPartialWakelock = 0; |
| 5316 | long actualBgPartialWakelock = 0; |
| 5317 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5318 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5319 | // Convert from microseconds to milliseconds with rounding |
| 5320 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5321 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5322 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5323 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5324 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5328 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5329 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5330 | sb.setLength(0); |
| 5331 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5332 | sb.append(" TOTAL wake: "); |
| 5333 | boolean needComma = false; |
| 5334 | if (totalFullWakelock != 0) { |
| 5335 | needComma = true; |
| 5336 | formatTimeMs(sb, totalFullWakelock); |
| 5337 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5338 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5339 | if (totalPartialWakelock != 0) { |
| 5340 | if (needComma) { |
| 5341 | sb.append(", "); |
| 5342 | } |
| 5343 | needComma = true; |
| 5344 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5345 | sb.append("blamed partial"); |
| 5346 | } |
| 5347 | if (actualTotalPartialWakelock != 0) { |
| 5348 | if (needComma) { |
| 5349 | sb.append(", "); |
| 5350 | } |
| 5351 | needComma = true; |
| 5352 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5353 | sb.append("actual partial"); |
| 5354 | } |
| 5355 | if (actualBgPartialWakelock != 0) { |
| 5356 | if (needComma) { |
| 5357 | sb.append(", "); |
| 5358 | } |
| 5359 | needComma = true; |
| 5360 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5361 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5362 | } |
| 5363 | if (totalWindowWakelock != 0) { |
| 5364 | if (needComma) { |
| 5365 | sb.append(", "); |
| 5366 | } |
| 5367 | needComma = true; |
| 5368 | formatTimeMs(sb, totalWindowWakelock); |
| 5369 | sb.append("window"); |
| 5370 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5371 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5372 | if (needComma) { |
| 5373 | sb.append(","); |
| 5374 | } |
| 5375 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5376 | formatTimeMs(sb, totalDrawWakelock); |
| 5377 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5378 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5379 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5380 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5381 | } |
| 5382 | } |
| 5383 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5384 | // Calculate multicast wakelock stats |
| 5385 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5386 | if (mcTimer != null) { |
| 5387 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5388 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5389 | |
| 5390 | if (multicastWakeLockTimeMicros > 0) { |
| 5391 | sb.setLength(0); |
| 5392 | sb.append(prefix); |
| 5393 | sb.append(" WiFi Multicast Wakelock"); |
| 5394 | sb.append(" count = "); |
| 5395 | sb.append(multicastWakeLockCount); |
| 5396 | sb.append(" time = "); |
| 5397 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5398 | pw.println(sb.toString()); |
| 5399 | } |
| 5400 | } |
| 5401 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5402 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5403 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5404 | final Timer timer = syncs.valueAt(isy); |
| 5405 | // Convert from microseconds to milliseconds with rounding |
| 5406 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5407 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5408 | final Timer bgTimer = timer.getSubTimer(); |
| 5409 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5410 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5411 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5412 | sb.setLength(0); |
| 5413 | sb.append(prefix); |
| 5414 | sb.append(" Sync "); |
| 5415 | sb.append(syncs.keyAt(isy)); |
| 5416 | sb.append(": "); |
| 5417 | if (totalTime != 0) { |
| 5418 | formatTimeMs(sb, totalTime); |
| 5419 | sb.append("realtime ("); |
| 5420 | sb.append(count); |
| 5421 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5422 | if (bgTime > 0) { |
| 5423 | sb.append(", "); |
| 5424 | formatTimeMs(sb, bgTime); |
| 5425 | sb.append("background ("); |
| 5426 | sb.append(bgCount); |
| 5427 | sb.append(" times)"); |
| 5428 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5429 | } else { |
| 5430 | sb.append("(not used)"); |
| 5431 | } |
| 5432 | pw.println(sb.toString()); |
| 5433 | uidActivity = true; |
| 5434 | } |
| 5435 | |
| 5436 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5437 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5438 | final Timer timer = jobs.valueAt(ij); |
| 5439 | // Convert from microseconds to milliseconds with rounding |
| 5440 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5441 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5442 | final Timer bgTimer = timer.getSubTimer(); |
| 5443 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5444 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5445 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5446 | sb.setLength(0); |
| 5447 | sb.append(prefix); |
| 5448 | sb.append(" Job "); |
| 5449 | sb.append(jobs.keyAt(ij)); |
| 5450 | sb.append(": "); |
| 5451 | if (totalTime != 0) { |
| 5452 | formatTimeMs(sb, totalTime); |
| 5453 | sb.append("realtime ("); |
| 5454 | sb.append(count); |
| 5455 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5456 | if (bgTime > 0) { |
| 5457 | sb.append(", "); |
| 5458 | formatTimeMs(sb, bgTime); |
| 5459 | sb.append("background ("); |
| 5460 | sb.append(bgCount); |
| 5461 | sb.append(" times)"); |
| 5462 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5463 | } else { |
| 5464 | sb.append("(not used)"); |
| 5465 | } |
| 5466 | pw.println(sb.toString()); |
| 5467 | uidActivity = true; |
| 5468 | } |
| 5469 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5470 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5471 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5472 | SparseIntArray types = completions.valueAt(ic); |
| 5473 | if (types != null) { |
| 5474 | pw.print(prefix); |
| 5475 | pw.print(" Job Completions "); |
| 5476 | pw.print(completions.keyAt(ic)); |
| 5477 | pw.print(":"); |
| 5478 | for (int it=0; it<types.size(); it++) { |
| 5479 | pw.print(" "); |
| 5480 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5481 | pw.print("("); |
| 5482 | pw.print(types.valueAt(it)); |
| 5483 | pw.print("x)"); |
| 5484 | } |
| 5485 | pw.println(); |
| 5486 | } |
| 5487 | } |
| 5488 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5489 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5490 | prefix, "Flashlight"); |
| 5491 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5492 | prefix, "Camera"); |
| 5493 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5494 | prefix, "Video"); |
| 5495 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5496 | prefix, "Audio"); |
| 5497 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5498 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5499 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5500 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5501 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5502 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5503 | sb.setLength(0); |
| 5504 | sb.append(prefix); |
| 5505 | sb.append(" Sensor "); |
| 5506 | int handle = se.getHandle(); |
| 5507 | if (handle == Uid.Sensor.GPS) { |
| 5508 | sb.append("GPS"); |
| 5509 | } else { |
| 5510 | sb.append(handle); |
| 5511 | } |
| 5512 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5514 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5515 | if (timer != null) { |
| 5516 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5517 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5518 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5519 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5520 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5521 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5522 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5523 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5524 | final long bgActualTime = bgTimer != null ? |
| 5525 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5526 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5527 | //timer.logState(); |
| 5528 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5529 | if (actualTime != totalTime) { |
| 5530 | formatTimeMs(sb, totalTime); |
| 5531 | sb.append("blamed realtime, "); |
| 5532 | } |
| 5533 | |
| 5534 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5535 | sb.append("realtime ("); |
| 5536 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5537 | sb.append(" times)"); |
| 5538 | |
| 5539 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5540 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5541 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5542 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5543 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5544 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | } else { |
| 5547 | sb.append("(not used)"); |
| 5548 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5549 | } else { |
| 5550 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5552 | |
| 5553 | pw.println(sb.toString()); |
| 5554 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | } |
| 5556 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5557 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5558 | "Vibrator"); |
| 5559 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5560 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5561 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5562 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5563 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5564 | long totalStateTime = 0; |
| 5565 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5566 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5567 | if (time > 0) { |
| 5568 | totalStateTime += time; |
| 5569 | sb.setLength(0); |
| 5570 | sb.append(prefix); |
| 5571 | sb.append(" "); |
| 5572 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5573 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5574 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5575 | pw.println(sb.toString()); |
| 5576 | uidActivity = true; |
| 5577 | } |
| 5578 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5579 | if (totalStateTime > 0) { |
| 5580 | sb.setLength(0); |
| 5581 | sb.append(prefix); |
| 5582 | sb.append(" Total running: "); |
| 5583 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5584 | pw.println(sb.toString()); |
| 5585 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5586 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5587 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5588 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5589 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5590 | sb.setLength(0); |
| 5591 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5592 | sb.append(" Total cpu time: u="); |
| 5593 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5594 | sb.append("s="); |
| 5595 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5596 | pw.println(sb.toString()); |
| 5597 | } |
| 5598 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5599 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5600 | if (cpuFreqTimes != null) { |
| 5601 | sb.setLength(0); |
| 5602 | sb.append(" Total cpu time per freq:"); |
| 5603 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5604 | sb.append(" " + cpuFreqTimes[i]); |
| 5605 | } |
| 5606 | pw.println(sb.toString()); |
| 5607 | } |
| 5608 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5609 | if (screenOffCpuFreqTimes != null) { |
| 5610 | sb.setLength(0); |
| 5611 | sb.append(" Total screen-off cpu time per freq:"); |
| 5612 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5613 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5614 | } |
| 5615 | pw.println(sb.toString()); |
| 5616 | } |
| 5617 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5618 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5619 | = u.getProcessStats(); |
| 5620 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5621 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5622 | long userTime; |
| 5623 | long systemTime; |
| 5624 | long foregroundTime; |
| 5625 | int starts; |
| 5626 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5628 | userTime = ps.getUserTime(which); |
| 5629 | systemTime = ps.getSystemTime(which); |
| 5630 | foregroundTime = ps.getForegroundTime(which); |
| 5631 | starts = ps.getStarts(which); |
| 5632 | final int numCrashes = ps.getNumCrashes(which); |
| 5633 | final int numAnrs = ps.getNumAnrs(which); |
| 5634 | numExcessive = which == STATS_SINCE_CHARGED |
| 5635 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5637 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5638 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5639 | sb.setLength(0); |
| 5640 | sb.append(prefix); sb.append(" Proc "); |
| 5641 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5642 | sb.append(prefix); sb.append(" CPU: "); |
| 5643 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5644 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5645 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5646 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5647 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5648 | boolean hasOne = false; |
| 5649 | if (starts != 0) { |
| 5650 | hasOne = true; |
| 5651 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5652 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5653 | if (numCrashes != 0) { |
| 5654 | if (hasOne) { |
| 5655 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5656 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5657 | hasOne = true; |
| 5658 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5659 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5660 | if (numAnrs != 0) { |
| 5661 | if (hasOne) { |
| 5662 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5663 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5664 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | } |
| 5666 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5667 | pw.println(sb.toString()); |
| 5668 | for (int e=0; e<numExcessive; e++) { |
| 5669 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5670 | if (ew != null) { |
| 5671 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5672 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5673 | pw.print("cpu"); |
| 5674 | } else { |
| 5675 | pw.print("unknown"); |
| 5676 | } |
| 5677 | pw.print(" use: "); |
| 5678 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5679 | pw.print(" over "); |
| 5680 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5681 | if (ew.overTime != 0) { |
| 5682 | pw.print(" ("); |
| 5683 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5684 | pw.println("%)"); |
| 5685 | } |
| 5686 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | } |
| 5688 | uidActivity = true; |
| 5689 | } |
| 5690 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5691 | |
| 5692 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5693 | = u.getPackageStats(); |
| 5694 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5695 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5696 | pw.println(":"); |
| 5697 | boolean apkActivity = false; |
| 5698 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5699 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5700 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5701 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5702 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5703 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5704 | pw.println(" times"); |
| 5705 | apkActivity = true; |
| 5706 | } |
| 5707 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5708 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5709 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5710 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5711 | final int starts = ss.getStarts(which); |
| 5712 | final int launches = ss.getLaunches(which); |
| 5713 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5714 | sb.setLength(0); |
| 5715 | sb.append(prefix); sb.append(" Service "); |
| 5716 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5717 | sb.append(prefix); sb.append(" Created for: "); |
| 5718 | formatTimeMs(sb, startTime / 1000); |
| 5719 | sb.append("uptime\n"); |
| 5720 | sb.append(prefix); sb.append(" Starts: "); |
| 5721 | sb.append(starts); |
| 5722 | sb.append(", launches: "); sb.append(launches); |
| 5723 | pw.println(sb.toString()); |
| 5724 | apkActivity = true; |
| 5725 | } |
| 5726 | } |
| 5727 | if (!apkActivity) { |
| 5728 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5729 | } |
| 5730 | uidActivity = true; |
| 5731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5733 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | } |
| 5735 | } |
| 5736 | } |
| 5737 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5738 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5739 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5740 | int diff = oldval ^ newval; |
| 5741 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5742 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5743 | for (int i=0; i<descriptions.length; i++) { |
| 5744 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5745 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5746 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5747 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5748 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5749 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5750 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5751 | didWake = true; |
| 5752 | pw.print("="); |
| 5753 | if (longNames) { |
| 5754 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5755 | pw.print(":\""); |
| 5756 | pw.print(wakelockTag.string); |
| 5757 | pw.print("\""); |
| 5758 | } else { |
| 5759 | pw.print(wakelockTag.poolIdx); |
| 5760 | } |
| 5761 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5762 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5763 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5764 | pw.print("="); |
| 5765 | int val = (newval&bd.mask)>>bd.shift; |
| 5766 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5767 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5768 | } else { |
| 5769 | pw.print(val); |
| 5770 | } |
| 5771 | } |
| 5772 | } |
| 5773 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5774 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5775 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5776 | if (longNames) { |
| 5777 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5778 | pw.print(":\""); |
| 5779 | pw.print(wakelockTag.string); |
| 5780 | pw.print("\""); |
| 5781 | } else { |
| 5782 | pw.print(wakelockTag.poolIdx); |
| 5783 | } |
| 5784 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5785 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5786 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5787 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 5788 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | public static class HistoryPrinter { |
| 5792 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5793 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5794 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5795 | int oldStatus = -1; |
| 5796 | int oldHealth = -1; |
| 5797 | int oldPlug = -1; |
| 5798 | int oldTemp = -1; |
| 5799 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5800 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5801 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5802 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5803 | void reset() { |
| 5804 | oldState = oldState2 = 0; |
| 5805 | oldLevel = -1; |
| 5806 | oldStatus = -1; |
| 5807 | oldHealth = -1; |
| 5808 | oldPlug = -1; |
| 5809 | oldTemp = -1; |
| 5810 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5811 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5814 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5815 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5816 | if (!checkin) { |
| 5817 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5818 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5819 | pw.print(" ("); |
| 5820 | pw.print(rec.numReadInts); |
| 5821 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5822 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5823 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5824 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5825 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5826 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5827 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5828 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5829 | } |
| 5830 | lastTime = rec.time; |
| 5831 | } |
| 5832 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5833 | if (checkin) { |
| 5834 | pw.print(":"); |
| 5835 | } |
| 5836 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5837 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5838 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5839 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5840 | if (checkin) { |
| 5841 | pw.print(":"); |
| 5842 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5843 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5844 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5845 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5846 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5847 | pw.print("TIME:"); |
| 5848 | if (checkin) { |
| 5849 | pw.println(rec.currentTime); |
| 5850 | } else { |
| 5851 | pw.print(" "); |
| 5852 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5853 | rec.currentTime).toString()); |
| 5854 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5855 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5856 | if (checkin) { |
| 5857 | pw.print(":"); |
| 5858 | } |
| 5859 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5860 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5861 | if (checkin) { |
| 5862 | pw.print(":"); |
| 5863 | } |
| 5864 | pw.println("*OVERFLOW*"); |
| 5865 | } else { |
| 5866 | if (!checkin) { |
| 5867 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5868 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5869 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5870 | if (verbose) { |
| 5871 | pw.print(" "); |
| 5872 | if (rec.states < 0) ; |
| 5873 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5874 | else if (rec.states < 0x100) pw.print("000000"); |
| 5875 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5876 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5877 | else if (rec.states < 0x100000) pw.print("000"); |
| 5878 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5879 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5880 | pw.print(Integer.toHexString(rec.states)); |
| 5881 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5882 | } else { |
| 5883 | if (oldLevel != rec.batteryLevel) { |
| 5884 | oldLevel = rec.batteryLevel; |
| 5885 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5886 | } |
| 5887 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5888 | if (oldStatus != rec.batteryStatus) { |
| 5889 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5890 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5891 | switch (oldStatus) { |
| 5892 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5893 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5894 | break; |
| 5895 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5896 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5897 | break; |
| 5898 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5899 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5900 | break; |
| 5901 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5902 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5903 | break; |
| 5904 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5905 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5906 | break; |
| 5907 | default: |
| 5908 | pw.print(oldStatus); |
| 5909 | break; |
| 5910 | } |
| 5911 | } |
| 5912 | if (oldHealth != rec.batteryHealth) { |
| 5913 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5914 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5915 | switch (oldHealth) { |
| 5916 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5917 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5918 | break; |
| 5919 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5920 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5921 | break; |
| 5922 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5923 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5924 | break; |
| 5925 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5926 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5927 | break; |
| 5928 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5929 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5930 | break; |
| 5931 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5932 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5933 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5934 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5935 | pw.print(checkin ? "c" : "cold"); |
| 5936 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5937 | default: |
| 5938 | pw.print(oldHealth); |
| 5939 | break; |
| 5940 | } |
| 5941 | } |
| 5942 | if (oldPlug != rec.batteryPlugType) { |
| 5943 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5944 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5945 | switch (oldPlug) { |
| 5946 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5947 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5948 | break; |
| 5949 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5950 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5951 | break; |
| 5952 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5953 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5954 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5955 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5956 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5957 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5958 | default: |
| 5959 | pw.print(oldPlug); |
| 5960 | break; |
| 5961 | } |
| 5962 | } |
| 5963 | if (oldTemp != rec.batteryTemperature) { |
| 5964 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5965 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5966 | pw.print(oldTemp); |
| 5967 | } |
| 5968 | if (oldVolt != rec.batteryVoltage) { |
| 5969 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5970 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5971 | pw.print(oldVolt); |
| 5972 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5973 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5974 | if (oldChargeMAh != chargeMAh) { |
| 5975 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5976 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5977 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5978 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5979 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5980 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5981 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5982 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5983 | if (rec.wakeReasonTag != null) { |
| 5984 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5985 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5986 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5987 | } else { |
| 5988 | pw.print(" wake_reason="); |
| 5989 | pw.print(rec.wakeReasonTag.uid); |
| 5990 | pw.print(":\""); |
| 5991 | pw.print(rec.wakeReasonTag.string); |
| 5992 | pw.print("\""); |
| 5993 | } |
| 5994 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5995 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5996 | pw.print(checkin ? "," : " "); |
| 5997 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5998 | pw.print("+"); |
| 5999 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6000 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6001 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6002 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6003 | : HISTORY_EVENT_NAMES; |
| 6004 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6005 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6006 | if (idx >= 0 && idx < eventNames.length) { |
| 6007 | pw.print(eventNames[idx]); |
| 6008 | } else { |
| 6009 | pw.print(checkin ? "Ev" : "event"); |
| 6010 | pw.print(idx); |
| 6011 | } |
| 6012 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6013 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6014 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6015 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6016 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6017 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6018 | pw.print(":\""); |
| 6019 | pw.print(rec.eventTag.string); |
| 6020 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6021 | } |
| 6022 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6023 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6024 | if (rec.stepDetails != null) { |
| 6025 | if (!checkin) { |
| 6026 | pw.print(" Details: cpu="); |
| 6027 | pw.print(rec.stepDetails.userTime); |
| 6028 | pw.print("u+"); |
| 6029 | pw.print(rec.stepDetails.systemTime); |
| 6030 | pw.print("s"); |
| 6031 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6032 | pw.print(" ("); |
| 6033 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6034 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6035 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6036 | pw.print(", "); |
| 6037 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6038 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6039 | } |
| 6040 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6041 | pw.print(", "); |
| 6042 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6043 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6044 | } |
| 6045 | pw.print(')'); |
| 6046 | } |
| 6047 | pw.println(); |
| 6048 | pw.print(" /proc/stat="); |
| 6049 | pw.print(rec.stepDetails.statUserTime); |
| 6050 | pw.print(" usr, "); |
| 6051 | pw.print(rec.stepDetails.statSystemTime); |
| 6052 | pw.print(" sys, "); |
| 6053 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6054 | pw.print(" io, "); |
| 6055 | pw.print(rec.stepDetails.statIrqTime); |
| 6056 | pw.print(" irq, "); |
| 6057 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6058 | pw.print(" sirq, "); |
| 6059 | pw.print(rec.stepDetails.statIdlTime); |
| 6060 | pw.print(" idle"); |
| 6061 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6062 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6063 | + rec.stepDetails.statSoftIrqTime; |
| 6064 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6065 | if (total > 0) { |
| 6066 | pw.print(" ("); |
| 6067 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6068 | pw.print(String.format("%.1f%%", perc)); |
| 6069 | pw.print(" of "); |
| 6070 | StringBuilder sb = new StringBuilder(64); |
| 6071 | formatTimeMsNoSpace(sb, total*10); |
| 6072 | pw.print(sb); |
| 6073 | pw.print(")"); |
| 6074 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6075 | pw.print(", PlatformIdleStat "); |
| 6076 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6077 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6078 | |
| 6079 | pw.print(", SubsystemPowerState "); |
| 6080 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6081 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6082 | } else { |
| 6083 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6084 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6085 | pw.print(rec.stepDetails.userTime); |
| 6086 | pw.print(":"); |
| 6087 | pw.print(rec.stepDetails.systemTime); |
| 6088 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6089 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6090 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6091 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6092 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6093 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6094 | } |
| 6095 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6096 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6097 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6098 | } |
| 6099 | } |
| 6100 | pw.println(); |
| 6101 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6102 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6103 | pw.print(rec.stepDetails.statUserTime); |
| 6104 | pw.print(','); |
| 6105 | pw.print(rec.stepDetails.statSystemTime); |
| 6106 | pw.print(','); |
| 6107 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6108 | pw.print(','); |
| 6109 | pw.print(rec.stepDetails.statIrqTime); |
| 6110 | pw.print(','); |
| 6111 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6112 | pw.print(','); |
| 6113 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6114 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6115 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6116 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6117 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6118 | pw.print(','); |
| 6119 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6120 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6121 | |
| 6122 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6123 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6124 | } |
| 6125 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6126 | } |
| 6127 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6128 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6129 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6130 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6131 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6132 | |
| 6133 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6134 | UserHandle.formatUid(pw, uid); |
| 6135 | pw.print("="); |
| 6136 | pw.print(utime); |
| 6137 | pw.print("u+"); |
| 6138 | pw.print(stime); |
| 6139 | pw.print("s"); |
| 6140 | } |
| 6141 | |
| 6142 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6143 | pw.print('/'); |
| 6144 | pw.print(uid); |
| 6145 | pw.print(":"); |
| 6146 | pw.print(utime); |
| 6147 | pw.print(":"); |
| 6148 | pw.print(stime); |
| 6149 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6150 | } |
| 6151 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6152 | private void printSizeValue(PrintWriter pw, long size) { |
| 6153 | float result = size; |
| 6154 | String suffix = ""; |
| 6155 | if (result >= 10*1024) { |
| 6156 | suffix = "KB"; |
| 6157 | result = result / 1024; |
| 6158 | } |
| 6159 | if (result >= 10*1024) { |
| 6160 | suffix = "MB"; |
| 6161 | result = result / 1024; |
| 6162 | } |
| 6163 | if (result >= 10*1024) { |
| 6164 | suffix = "GB"; |
| 6165 | result = result / 1024; |
| 6166 | } |
| 6167 | if (result >= 10*1024) { |
| 6168 | suffix = "TB"; |
| 6169 | result = result / 1024; |
| 6170 | } |
| 6171 | if (result >= 10*1024) { |
| 6172 | suffix = "PB"; |
| 6173 | result = result / 1024; |
| 6174 | } |
| 6175 | pw.print((int)result); |
| 6176 | pw.print(suffix); |
| 6177 | } |
| 6178 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6179 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6180 | String label3, long estimatedTime) { |
| 6181 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6182 | return false; |
| 6183 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6184 | pw.print(label1); |
| 6185 | pw.print(label2); |
| 6186 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6187 | StringBuilder sb = new StringBuilder(64); |
| 6188 | formatTimeMs(sb, estimatedTime); |
| 6189 | pw.print(sb); |
| 6190 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6191 | return true; |
| 6192 | } |
| 6193 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6194 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6195 | LevelStepTracker steps, boolean checkin) { |
| 6196 | if (steps == null) { |
| 6197 | return false; |
| 6198 | } |
| 6199 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6200 | if (count <= 0) { |
| 6201 | return false; |
| 6202 | } |
| 6203 | if (!checkin) { |
| 6204 | pw.println(header); |
| 6205 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6206 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6207 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6208 | long duration = steps.getDurationAt(i); |
| 6209 | int level = steps.getLevelAt(i); |
| 6210 | long initMode = steps.getInitModeAt(i); |
| 6211 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6212 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6213 | lineArgs[0] = Long.toString(duration); |
| 6214 | lineArgs[1] = Integer.toString(level); |
| 6215 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6216 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6217 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6218 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6219 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6220 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6221 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6222 | } |
| 6223 | } else { |
| 6224 | lineArgs[2] = ""; |
| 6225 | } |
| 6226 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6227 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6228 | } else { |
| 6229 | lineArgs[3] = ""; |
| 6230 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6231 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6232 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6233 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6234 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6235 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6236 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6237 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6238 | pw.print(prefix); |
| 6239 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6240 | TimeUtils.formatDuration(duration, pw); |
| 6241 | pw.print(" to "); pw.print(level); |
| 6242 | boolean haveModes = false; |
| 6243 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6244 | pw.print(" ("); |
| 6245 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6246 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6247 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6248 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6249 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6250 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6251 | } |
| 6252 | haveModes = true; |
| 6253 | } |
| 6254 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6255 | pw.print(haveModes ? ", " : " ("); |
| 6256 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6257 | ? "power-save-on" : "power-save-off"); |
| 6258 | haveModes = true; |
| 6259 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6260 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6261 | pw.print(haveModes ? ", " : " ("); |
| 6262 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6263 | ? "device-idle-on" : "device-idle-off"); |
| 6264 | haveModes = true; |
| 6265 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6266 | if (haveModes) { |
| 6267 | pw.print(")"); |
| 6268 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6269 | pw.println(); |
| 6270 | } |
| 6271 | } |
| 6272 | return true; |
| 6273 | } |
| 6274 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6275 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6276 | LevelStepTracker steps) { |
| 6277 | if (steps == null) { |
| 6278 | return; |
| 6279 | } |
| 6280 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6281 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6282 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6283 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6284 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6285 | |
| 6286 | final long initMode = steps.getInitModeAt(i); |
| 6287 | final long modMode = steps.getModModeAt(i); |
| 6288 | |
| 6289 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6290 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6291 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6292 | case Display.STATE_OFF: |
| 6293 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6294 | break; |
| 6295 | case Display.STATE_ON: |
| 6296 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6297 | break; |
| 6298 | case Display.STATE_DOZE: |
| 6299 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6300 | break; |
| 6301 | case Display.STATE_DOZE_SUSPEND: |
| 6302 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6303 | break; |
| 6304 | default: |
| 6305 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6306 | break; |
| 6307 | } |
| 6308 | } |
| 6309 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6310 | |
| 6311 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6312 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6313 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6314 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6315 | } |
| 6316 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6317 | |
| 6318 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6319 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6320 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6321 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6322 | } |
| 6323 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6324 | |
| 6325 | proto.end(token); |
| 6326 | } |
| 6327 | } |
| 6328 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6329 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6330 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6331 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6332 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6333 | public static final int DUMP_VERBOSE = 1<<5; |
| 6334 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6335 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6336 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6337 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6338 | final HistoryItem rec = new HistoryItem(); |
| 6339 | long lastTime = -1; |
| 6340 | long baseTime = -1; |
| 6341 | boolean printed = false; |
| 6342 | HistoryEventTracker tracker = null; |
| 6343 | while (getNextHistoryLocked(rec)) { |
| 6344 | lastTime = rec.time; |
| 6345 | if (baseTime < 0) { |
| 6346 | baseTime = lastTime; |
| 6347 | } |
| 6348 | if (rec.time >= histStart) { |
| 6349 | if (histStart >= 0 && !printed) { |
| 6350 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6351 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6352 | || rec.cmd == HistoryItem.CMD_START |
| 6353 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6354 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6355 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6356 | (flags&DUMP_VERBOSE) != 0); |
| 6357 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6358 | } else if (rec.currentTime != 0) { |
| 6359 | printed = true; |
| 6360 | byte cmd = rec.cmd; |
| 6361 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6362 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6363 | (flags&DUMP_VERBOSE) != 0); |
| 6364 | rec.cmd = cmd; |
| 6365 | } |
| 6366 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6367 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6368 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6369 | (flags&DUMP_VERBOSE) != 0); |
| 6370 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6371 | } |
| 6372 | int oldEventCode = rec.eventCode; |
| 6373 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6374 | rec.eventTag = new HistoryTag(); |
| 6375 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6376 | HashMap<String, SparseIntArray> active |
| 6377 | = tracker.getStateForEvent(i); |
| 6378 | if (active == null) { |
| 6379 | continue; |
| 6380 | } |
| 6381 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6382 | : active.entrySet()) { |
| 6383 | SparseIntArray uids = ent.getValue(); |
| 6384 | for (int j=0; j<uids.size(); j++) { |
| 6385 | rec.eventCode = i; |
| 6386 | rec.eventTag.string = ent.getKey(); |
| 6387 | rec.eventTag.uid = uids.keyAt(j); |
| 6388 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6389 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6390 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6391 | rec.wakeReasonTag = null; |
| 6392 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6393 | } |
| 6394 | } |
| 6395 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6396 | rec.eventCode = oldEventCode; |
| 6397 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6398 | tracker = null; |
| 6399 | } |
| 6400 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6401 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6402 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6403 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6404 | // This is an attempt to aggregate the previous state and generate |
| 6405 | //Â fake events to reflect that state at the point where we start |
| 6406 | // 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] | 6407 | if (tracker == null) { |
| 6408 | tracker = new HistoryEventTracker(); |
| 6409 | } |
| 6410 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6411 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6412 | } |
| 6413 | } |
| 6414 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6415 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6416 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6417 | } |
| 6418 | } |
| 6419 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6420 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6421 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6422 | if (steps == null) { |
| 6423 | return; |
| 6424 | } |
| 6425 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6426 | if (timeRemaining >= 0) { |
| 6427 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6428 | tmpSb.setLength(0); |
| 6429 | formatTimeMs(tmpSb, timeRemaining); |
| 6430 | pw.print(tmpSb); |
| 6431 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6432 | pw.println(" steps)"); |
| 6433 | } |
| 6434 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6435 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6436 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6437 | if (estimatedTime > 0) { |
| 6438 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6439 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6440 | pw.print(" time: "); |
| 6441 | tmpSb.setLength(0); |
| 6442 | formatTimeMs(tmpSb, estimatedTime); |
| 6443 | pw.print(tmpSb); |
| 6444 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6445 | pw.println(" steps)"); |
| 6446 | } |
| 6447 | } |
| 6448 | } |
| 6449 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6450 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6451 | ArrayList<PackageChange> changes) { |
| 6452 | if (changes == null) { |
| 6453 | return; |
| 6454 | } |
| 6455 | pw.print(prefix); pw.println("Package changes:"); |
| 6456 | for (int i=0; i<changes.size(); i++) { |
| 6457 | PackageChange pc = changes.get(i); |
| 6458 | if (pc.mUpdate) { |
| 6459 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6460 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6461 | } else { |
| 6462 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6463 | } |
| 6464 | } |
| 6465 | } |
| 6466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6467 | /** |
| 6468 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6469 | * |
| 6470 | * @param pw a Printer to receive the dump output. |
| 6471 | */ |
| 6472 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6473 | 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] | 6474 | prepareForDumpLocked(); |
| 6475 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6476 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6477 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6478 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6479 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6480 | final long historyTotalSize = getHistoryTotalSize(); |
| 6481 | final long historyUsedSize = getHistoryUsedSize(); |
| 6482 | if (startIteratingHistoryLocked()) { |
| 6483 | try { |
| 6484 | pw.print("Battery History ("); |
| 6485 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6486 | pw.print("% used, "); |
| 6487 | printSizeValue(pw, historyUsedSize); |
| 6488 | pw.print(" used of "); |
| 6489 | printSizeValue(pw, historyTotalSize); |
| 6490 | pw.print(", "); |
| 6491 | pw.print(getHistoryStringPoolSize()); |
| 6492 | pw.print(" strings using "); |
| 6493 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6494 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6495 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6496 | pw.println(); |
| 6497 | } finally { |
| 6498 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6499 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | if (startIteratingOldHistoryLocked()) { |
| 6503 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6504 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6505 | pw.println("Old battery History:"); |
| 6506 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6507 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6508 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6509 | if (baseTime < 0) { |
| 6510 | baseTime = rec.time; |
| 6511 | } |
| 6512 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6513 | } |
| 6514 | pw.println(); |
| 6515 | } finally { |
| 6516 | finishIteratingOldHistoryLocked(); |
| 6517 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6518 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6519 | } |
| 6520 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6521 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6522 | return; |
| 6523 | } |
| 6524 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6525 | if (!filtering) { |
| 6526 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6527 | final int NU = uidStats.size(); |
| 6528 | boolean didPid = false; |
| 6529 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6530 | for (int i=0; i<NU; i++) { |
| 6531 | Uid uid = uidStats.valueAt(i); |
| 6532 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6533 | if (pids != null) { |
| 6534 | for (int j=0; j<pids.size(); j++) { |
| 6535 | Uid.Pid pid = pids.valueAt(j); |
| 6536 | if (!didPid) { |
| 6537 | pw.println("Per-PID Stats:"); |
| 6538 | didPid = true; |
| 6539 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6540 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6541 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6542 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6543 | pw.print(" wake time: "); |
| 6544 | TimeUtils.formatDuration(time, pw); |
| 6545 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6546 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6547 | } |
| 6548 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6549 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6550 | pw.println(); |
| 6551 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6555 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6556 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6557 | long timeRemaining = computeBatteryTimeRemaining( |
| 6558 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6559 | if (timeRemaining >= 0) { |
| 6560 | pw.print(" Estimated discharge time remaining: "); |
| 6561 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6562 | pw.println(); |
| 6563 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6564 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6565 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6566 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6567 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6568 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6569 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6570 | pw.println(); |
| 6571 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6572 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6573 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6574 | long timeRemaining = computeChargeTimeRemaining( |
| 6575 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6576 | if (timeRemaining >= 0) { |
| 6577 | pw.print(" Estimated charge time remaining: "); |
| 6578 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6579 | pw.println(); |
| 6580 | } |
| 6581 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6582 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6583 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6584 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6585 | pw.println("Daily stats:"); |
| 6586 | pw.print(" Current start time: "); |
| 6587 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6588 | getCurrentDailyStartTime()).toString()); |
| 6589 | pw.print(" Next min deadline: "); |
| 6590 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6591 | getNextMinDailyDeadline()).toString()); |
| 6592 | pw.print(" Next max deadline: "); |
| 6593 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6594 | getNextMaxDailyDeadline()).toString()); |
| 6595 | StringBuilder sb = new StringBuilder(64); |
| 6596 | int[] outInt = new int[1]; |
| 6597 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6598 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6599 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6600 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6601 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6602 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6603 | dsteps, false)) { |
| 6604 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6605 | sb, outInt); |
| 6606 | } |
| 6607 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6608 | csteps, false)) { |
| 6609 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6610 | sb, outInt); |
| 6611 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6612 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6613 | } else { |
| 6614 | pw.println(" Current daily steps:"); |
| 6615 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6616 | sb, outInt); |
| 6617 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6618 | sb, outInt); |
| 6619 | } |
| 6620 | } |
| 6621 | DailyItem dit; |
| 6622 | int curIndex = 0; |
| 6623 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6624 | curIndex++; |
| 6625 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6626 | pw.println(); |
| 6627 | } |
| 6628 | pw.print(" Daily from "); |
| 6629 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6630 | pw.print(" to "); |
| 6631 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6632 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6633 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6634 | if (dumpDurationSteps(pw, " ", |
| 6635 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6636 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6637 | sb, outInt); |
| 6638 | } |
| 6639 | if (dumpDurationSteps(pw, " ", |
| 6640 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6641 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6642 | sb, outInt); |
| 6643 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6644 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6645 | } else { |
| 6646 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6647 | sb, outInt); |
| 6648 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6649 | sb, outInt); |
| 6650 | } |
| 6651 | } |
| 6652 | pw.println(); |
| 6653 | } |
| 6654 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6655 | pw.println("Statistics since last charge:"); |
| 6656 | pw.println(" System starts: " + getStartCount() |
| 6657 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6658 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6659 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6660 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6663 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6664 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6666 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6667 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6668 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6669 | |
| 6670 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6671 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6672 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6673 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6674 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6675 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6676 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6677 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6678 | try { |
| 6679 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6680 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6681 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6682 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6683 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6684 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6685 | pw.print(",\""); |
| 6686 | String str = getHistoryTagPoolString(i); |
| 6687 | str = str.replace("\\", "\\\\"); |
| 6688 | str = str.replace("\"", "\\\""); |
| 6689 | pw.print(str); |
| 6690 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6691 | pw.println(); |
| 6692 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6693 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6694 | } finally { |
| 6695 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6696 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6697 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6698 | } |
| 6699 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6700 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6701 | return; |
| 6702 | } |
| 6703 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6704 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6705 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6706 | for (int i=0; i<apps.size(); i++) { |
| 6707 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6708 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6709 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6710 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6711 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6712 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6713 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6714 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6715 | } |
| 6716 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6717 | final int NU = uidStats.size(); |
| 6718 | String[] lineArgs = new String[2]; |
| 6719 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6720 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6721 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6722 | if (pkgs != null && !pkgs.second.value) { |
| 6723 | pkgs.second.value = true; |
| 6724 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6725 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6726 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6727 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6728 | (Object[])lineArgs); |
| 6729 | } |
| 6730 | } |
| 6731 | } |
| 6732 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6733 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6734 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6735 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6736 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6737 | if (timeRemaining >= 0) { |
| 6738 | lineArgs[0] = Long.toString(timeRemaining); |
| 6739 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6740 | (Object[])lineArgs); |
| 6741 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6742 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6743 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6744 | if (timeRemaining >= 0) { |
| 6745 | lineArgs[0] = Long.toString(timeRemaining); |
| 6746 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6747 | (Object[])lineArgs); |
| 6748 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6749 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6750 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6751 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6753 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6754 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6755 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6756 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6757 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6758 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6759 | prepareForDumpLocked(); |
| 6760 | |
| 6761 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6762 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6763 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6764 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6765 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6766 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6767 | |
| 6768 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6769 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 6770 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 6771 | helper.create(this); |
| 6772 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 6773 | |
| 6774 | dumpProtoAppsLocked(proto, helper, apps); |
| 6775 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | proto.end(bToken); |
| 6779 | proto.flush(); |
| 6780 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6781 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6782 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 6783 | List<ApplicationInfo> apps) { |
| 6784 | final int which = STATS_SINCE_CHARGED; |
| 6785 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 6786 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 6787 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 6788 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 6789 | |
| 6790 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 6791 | if (apps != null) { |
| 6792 | for (int i = 0; i < apps.size(); ++i) { |
| 6793 | ApplicationInfo ai = apps.get(i); |
| 6794 | int aid = UserHandle.getAppId(ai.uid); |
| 6795 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 6796 | if (pkgs == null) { |
| 6797 | pkgs = new ArrayList<String>(); |
| 6798 | aidToPackages.put(aid, pkgs); |
| 6799 | } |
| 6800 | pkgs.add(ai.packageName); |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 6805 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 6806 | if (sippers != null) { |
| 6807 | for (int i = 0; i < sippers.size(); ++i) { |
| 6808 | final BatterySipper bs = sippers.get(i); |
| 6809 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 6810 | // Others are handled by dumpProtoSystemLocked() |
| 6811 | continue; |
| 6812 | } |
| 6813 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 6814 | } |
| 6815 | } |
| 6816 | |
| 6817 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6818 | final int n = uidStats.size(); |
| 6819 | for (int iu = 0; iu < n; ++iu) { |
| 6820 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 6821 | final Uid u = uidStats.valueAt(iu); |
| 6822 | |
| 6823 | final int uid = uidStats.keyAt(iu); |
| 6824 | proto.write(UidProto.UID, uid); |
| 6825 | |
| 6826 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 6827 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 6828 | if (pkgs == null) { |
| 6829 | pkgs = new ArrayList<String>(); |
| 6830 | } |
| 6831 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 6832 | u.getPackageStats(); |
| 6833 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 6834 | String pkg = packageStats.keyAt(ipkg); |
| 6835 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 6836 | packageStats.valueAt(ipkg).getServiceStats(); |
| 6837 | if (serviceStats.size() == 0) { |
| 6838 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 6839 | // example, "android") may be included in the packageStats that aren't part of |
| 6840 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 6841 | // These packages won't be a part in the pkgs List. |
| 6842 | continue; |
| 6843 | } |
| 6844 | |
| 6845 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6846 | proto.write(UidProto.Package.NAME, pkg); |
| 6847 | // Remove from the packages list since we're logging it here. |
| 6848 | pkgs.remove(pkg); |
| 6849 | |
| 6850 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 6851 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 6852 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 6853 | |
| 6854 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 6855 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 6856 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 6857 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 6858 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 6859 | |
| 6860 | proto.end(sToken); |
| 6861 | } |
| 6862 | proto.end(pToken); |
| 6863 | } |
| 6864 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 6865 | // from PackageManager data. Packages are only included in packageStats if there was |
| 6866 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 6867 | for (String p : pkgs) { |
| 6868 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6869 | proto.write(UidProto.Package.NAME, p); |
| 6870 | proto.end(pToken); |
| 6871 | } |
| 6872 | |
| 6873 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 6874 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 6875 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 6876 | // Times are since reset (regardless of 'which') |
| 6877 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 6878 | final Timer bgTimer = timer.getSubTimer(); |
| 6879 | final long bgTimeMs = bgTimer != null |
| 6880 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 6881 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 6882 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 6883 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 6884 | proto.end(awToken); |
| 6885 | } |
| 6886 | |
| 6887 | // Audio (AUDIO_DATA) |
| 6888 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 6889 | |
| 6890 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 6891 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 6892 | u.getBluetoothControllerActivity(), which); |
| 6893 | |
| 6894 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 6895 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 6896 | if (bleTimer != null) { |
| 6897 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 6898 | |
| 6899 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 6900 | rawRealtimeUs, which); |
| 6901 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 6902 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 6903 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 6904 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 6905 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 6906 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 6907 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 6908 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 6909 | // Result counters |
| 6910 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 6911 | u.getBluetoothScanResultCounter() != null |
| 6912 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 6913 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 6914 | u.getBluetoothScanResultBgCounter() != null |
| 6915 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 6916 | |
| 6917 | proto.end(bmToken); |
| 6918 | } |
| 6919 | |
| 6920 | // Camera (CAMERA_DATA) |
| 6921 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 6922 | |
| 6923 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 6924 | final long cpuToken = proto.start(UidProto.CPU); |
| 6925 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 6926 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 6927 | |
| 6928 | final long[] cpuFreqs = getCpuFreqs(); |
| 6929 | if (cpuFreqs != null) { |
| 6930 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 6931 | // If total cpuFreqTimes is null, then we don't need to check for |
| 6932 | // screenOffCpuFreqTimes. |
| 6933 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 6934 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 6935 | if (screenOffCpuFreqTimeMs == null) { |
| 6936 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 6937 | } |
| 6938 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 6939 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 6940 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 6941 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 6942 | cpuFreqTimeMs[ic]); |
| 6943 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 6944 | screenOffCpuFreqTimeMs[ic]); |
| 6945 | proto.end(cToken); |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | proto.end(cpuToken); |
| 6950 | |
| 6951 | // Flashlight (FLASHLIGHT_DATA) |
| 6952 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 6953 | rawRealtimeUs, which); |
| 6954 | |
| 6955 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 6956 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 6957 | rawRealtimeUs, which); |
| 6958 | |
| 6959 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 6960 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 6961 | rawRealtimeUs, which); |
| 6962 | |
| 6963 | // Job completion (JOB_COMPLETION_DATA) |
| 6964 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 6965 | final int[] reasons = new int[]{ |
| 6966 | JobParameters.REASON_CANCELED, |
| 6967 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 6968 | JobParameters.REASON_PREEMPT, |
| 6969 | JobParameters.REASON_TIMEOUT, |
| 6970 | JobParameters.REASON_DEVICE_IDLE, |
| 6971 | }; |
| 6972 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 6973 | SparseIntArray types = completions.valueAt(ic); |
| 6974 | if (types != null) { |
| 6975 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 6976 | |
| 6977 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 6978 | |
| 6979 | for (int r : reasons) { |
| 6980 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 6981 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 6982 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 6983 | proto.end(rToken); |
| 6984 | } |
| 6985 | |
| 6986 | proto.end(jcToken); |
| 6987 | } |
| 6988 | } |
| 6989 | |
| 6990 | // Scheduled jobs (JOB_DATA) |
| 6991 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 6992 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 6993 | final Timer timer = jobs.valueAt(ij); |
| 6994 | final Timer bgTimer = timer.getSubTimer(); |
| 6995 | final long jToken = proto.start(UidProto.JOBS); |
| 6996 | |
| 6997 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 6998 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 6999 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7000 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7001 | |
| 7002 | proto.end(jToken); |
| 7003 | } |
| 7004 | |
| 7005 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7006 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7007 | u.getModemControllerActivity(), which); |
| 7008 | |
| 7009 | // Network stats (NETWORK_DATA) |
| 7010 | final long nToken = proto.start(UidProto.NETWORK); |
| 7011 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7012 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7013 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7014 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7015 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7016 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7017 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7018 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7019 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7020 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7021 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7022 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7023 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7024 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7025 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7026 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7027 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7028 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7029 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7030 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7031 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7032 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7033 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7034 | u.getMobileRadioActiveCount(which)); |
| 7035 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7036 | u.getMobileRadioApWakeupCount(which)); |
| 7037 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7038 | u.getWifiRadioApWakeupCount(which)); |
| 7039 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7040 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7041 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7042 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7043 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7044 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7045 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7046 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7047 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7048 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7049 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7050 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7051 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7052 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7053 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7054 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7055 | proto.end(nToken); |
| 7056 | |
| 7057 | // Power use item (POWER_USE_ITEM_DATA) |
| 7058 | BatterySipper bs = uidToSipper.get(uid); |
| 7059 | if (bs != null) { |
| 7060 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7061 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7062 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7063 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7064 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7065 | bs.proportionalSmearMah); |
| 7066 | proto.end(bsToken); |
| 7067 | } |
| 7068 | |
| 7069 | // Processes (PROCESS_DATA) |
| 7070 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7071 | u.getProcessStats(); |
| 7072 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7073 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7074 | final long prToken = proto.start(UidProto.PROCESS); |
| 7075 | |
| 7076 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7077 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7078 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7079 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7080 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7081 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7082 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7083 | |
| 7084 | proto.end(prToken); |
| 7085 | } |
| 7086 | |
| 7087 | // Sensors (SENSOR_DATA) |
| 7088 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7089 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7090 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7091 | final Timer timer = se.getSensorTime(); |
| 7092 | if (timer == null) { |
| 7093 | continue; |
| 7094 | } |
| 7095 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7096 | final int sensorNumber = sensors.keyAt(ise); |
| 7097 | final long seToken = proto.start(UidProto.SENSORS); |
| 7098 | |
| 7099 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7100 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7101 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7102 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7103 | |
| 7104 | proto.end(seToken); |
| 7105 | } |
| 7106 | |
| 7107 | // State times (STATE_TIME_DATA) |
| 7108 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7109 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7110 | if (durMs == 0) { |
| 7111 | continue; |
| 7112 | } |
| 7113 | final long stToken = proto.start(UidProto.STATES); |
| 7114 | proto.write(UidProto.StateTime.STATE, ips); |
| 7115 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7116 | proto.end(stToken); |
| 7117 | } |
| 7118 | |
| 7119 | // Syncs (SYNC_DATA) |
| 7120 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7121 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7122 | final Timer timer = syncs.valueAt(isy); |
| 7123 | final Timer bgTimer = timer.getSubTimer(); |
| 7124 | final long syToken = proto.start(UidProto.SYNCS); |
| 7125 | |
| 7126 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7127 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7128 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7129 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7130 | |
| 7131 | proto.end(syToken); |
| 7132 | } |
| 7133 | |
| 7134 | // User activity (USER_ACTIVITY_DATA) |
| 7135 | if (u.hasUserActivity()) { |
| 7136 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7137 | int val = u.getUserActivityCount(i, which); |
| 7138 | if (val != 0) { |
| 7139 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7140 | proto.write(UidProto.UserActivity.NAME, i); |
| 7141 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7142 | proto.end(uaToken); |
| 7143 | } |
| 7144 | } |
| 7145 | } |
| 7146 | |
| 7147 | // Vibrator (VIBRATOR_DATA) |
| 7148 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7149 | |
| 7150 | // Video (VIDEO_DATA) |
| 7151 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7152 | |
| 7153 | // Wakelocks (WAKELOCK_DATA) |
| 7154 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7155 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7156 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7157 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7158 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7159 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7160 | rawRealtimeUs, which); |
| 7161 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7162 | if (pTimer != null) { |
| 7163 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7164 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7165 | rawRealtimeUs, which); |
| 7166 | } |
| 7167 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7168 | rawRealtimeUs, which); |
| 7169 | proto.end(wToken); |
| 7170 | } |
| 7171 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7172 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7173 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7174 | rawRealtimeUs, which); |
| 7175 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7176 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7177 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7178 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7179 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7180 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7181 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7182 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7183 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7184 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7185 | proto.end(waToken); |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7190 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7191 | u.getWifiControllerActivity(), which); |
| 7192 | |
| 7193 | // Wifi data (WIFI_DATA) |
| 7194 | final long wToken = proto.start(UidProto.WIFI); |
| 7195 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7196 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7197 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7198 | rawRealtimeUs, which); |
| 7199 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7200 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7201 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7202 | rawRealtimeUs, which); |
| 7203 | proto.end(wToken); |
| 7204 | |
| 7205 | proto.end(uTkn); |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7210 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7211 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7212 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7213 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7214 | final int which = STATS_SINCE_CHARGED; |
| 7215 | |
| 7216 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7217 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7218 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7219 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7220 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7221 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7222 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7223 | computeUptime(rawUptimeUs, which) / 1000); |
| 7224 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7225 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7226 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7227 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7228 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7229 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7230 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7231 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7232 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7233 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7234 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7235 | getEstimatedBatteryCapacity()); |
| 7236 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7237 | getMinLearnedBatteryCapacity()); |
| 7238 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7239 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7240 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7241 | |
| 7242 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7243 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7244 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7245 | getLowDischargeAmountSinceCharge()); |
| 7246 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7247 | getHighDischargeAmountSinceCharge()); |
| 7248 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7249 | getDischargeAmountScreenOnSinceCharge()); |
| 7250 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7251 | getDischargeAmountScreenOffSinceCharge()); |
| 7252 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7253 | getDischargeAmountScreenDozeSinceCharge()); |
| 7254 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7255 | getUahDischarge(which) / 1000); |
| 7256 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7257 | getUahDischargeScreenOff(which) / 1000); |
| 7258 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7259 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7260 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7261 | getUahDischargeLightDoze(which) / 1000); |
| 7262 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7263 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7264 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7265 | |
| 7266 | // Time remaining |
| 7267 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7268 | // 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] | 7269 | if (timeRemainingUs >= 0) { |
| 7270 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7271 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7272 | } else { |
| 7273 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7274 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7275 | if (timeRemainingUs >= 0) { |
| 7276 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7277 | } else { |
| 7278 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | // Charge step (CHARGE_STEP_DATA) |
| 7283 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7284 | |
| 7285 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7286 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7287 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7288 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7289 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7290 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7291 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7292 | } |
| 7293 | |
| 7294 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7295 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7296 | |
| 7297 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7298 | final long[] cpuFreqs = getCpuFreqs(); |
| 7299 | if (cpuFreqs != null) { |
| 7300 | for (long i : cpuFreqs) { |
| 7301 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7302 | } |
| 7303 | } |
| 7304 | |
| 7305 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7306 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7307 | getBluetoothControllerActivity(), which); |
| 7308 | |
| 7309 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7310 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7311 | getModemControllerActivity(), which); |
| 7312 | |
| 7313 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7314 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7315 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7316 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7317 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7318 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7319 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7320 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7321 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7322 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7323 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7324 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7325 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7326 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7327 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7328 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7329 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7330 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7331 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7332 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7333 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7334 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7335 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7336 | |
| 7337 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7338 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7339 | getWifiControllerActivity(), which); |
| 7340 | |
| 7341 | |
| 7342 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7343 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7344 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7345 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7346 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7347 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7348 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7349 | |
| 7350 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7351 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7352 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7353 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7354 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7355 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7356 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7357 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7358 | } |
| 7359 | |
| 7360 | // Misc (MISC_DATA) |
| 7361 | // Calculate wakelock times across all uids. |
| 7362 | long fullWakeLockTimeTotalUs = 0; |
| 7363 | long partialWakeLockTimeTotalUs = 0; |
| 7364 | |
| 7365 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7366 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7367 | final Uid u = uidStats.valueAt(iu); |
| 7368 | |
| 7369 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7370 | u.getWakelockStats(); |
| 7371 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7372 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7373 | |
| 7374 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7375 | if (fullWakeTimer != null) { |
| 7376 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7377 | which); |
| 7378 | } |
| 7379 | |
| 7380 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7381 | if (partialWakeTimer != null) { |
| 7382 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7383 | rawRealtimeUs, which); |
| 7384 | } |
| 7385 | } |
| 7386 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7387 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7388 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7389 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7390 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7391 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7392 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7393 | fullWakeLockTimeTotalUs / 1000); |
| 7394 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7395 | partialWakeLockTimeTotalUs / 1000); |
| 7396 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7397 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7398 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7399 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7400 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7401 | getMobileRadioActiveCount(which)); |
| 7402 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7403 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7404 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7405 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7406 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7407 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7408 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7409 | getNumConnectivityChange(which)); |
| 7410 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7411 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7412 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7413 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7414 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7415 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7416 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7417 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7418 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7419 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7420 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7421 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7422 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7423 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7424 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7425 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7426 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7427 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7428 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7429 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7430 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7431 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7432 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
| 7433 | // Calculate multicast wakelock stats across all uids. |
| 7434 | long multicastWakeLockTimeTotalUs = 0; |
| 7435 | int multicastWakeLockCountTotal = 0; |
| 7436 | |
| 7437 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7438 | final Uid u = uidStats.valueAt(iu); |
| 7439 | |
| 7440 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 7441 | |
| 7442 | if (mcTimer != null) { |
| 7443 | multicastWakeLockTimeTotalUs += |
| 7444 | mcTimer.getTotalTimeLocked(rawRealtimeUs, which); |
| 7445 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 7446 | } |
| 7447 | } |
| 7448 | |
| 7449 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7450 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7451 | multicastWakeLockTimeTotalUs / 1000); |
| 7452 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7453 | multicastWakeLockCountTotal); |
| 7454 | proto.end(wmctToken); |
| 7455 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7456 | // Power use item (POWER_USE_ITEM_DATA) |
| 7457 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7458 | if (sippers != null) { |
| 7459 | for (int i = 0; i < sippers.size(); ++i) { |
| 7460 | final BatterySipper bs = sippers.get(i); |
| 7461 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7462 | int uid = 0; |
| 7463 | switch (bs.drainType) { |
| 7464 | case IDLE: |
| 7465 | n = SystemProto.PowerUseItem.IDLE; |
| 7466 | break; |
| 7467 | case CELL: |
| 7468 | n = SystemProto.PowerUseItem.CELL; |
| 7469 | break; |
| 7470 | case PHONE: |
| 7471 | n = SystemProto.PowerUseItem.PHONE; |
| 7472 | break; |
| 7473 | case WIFI: |
| 7474 | n = SystemProto.PowerUseItem.WIFI; |
| 7475 | break; |
| 7476 | case BLUETOOTH: |
| 7477 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7478 | break; |
| 7479 | case SCREEN: |
| 7480 | n = SystemProto.PowerUseItem.SCREEN; |
| 7481 | break; |
| 7482 | case FLASHLIGHT: |
| 7483 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7484 | break; |
| 7485 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7486 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7487 | continue; |
| 7488 | case USER: |
| 7489 | n = SystemProto.PowerUseItem.USER; |
| 7490 | uid = UserHandle.getUid(bs.userId, 0); |
| 7491 | break; |
| 7492 | case UNACCOUNTED: |
| 7493 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7494 | break; |
| 7495 | case OVERCOUNTED: |
| 7496 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7497 | break; |
| 7498 | case CAMERA: |
| 7499 | n = SystemProto.PowerUseItem.CAMERA; |
| 7500 | break; |
| 7501 | case MEMORY: |
| 7502 | n = SystemProto.PowerUseItem.MEMORY; |
| 7503 | break; |
| 7504 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7505 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7506 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7507 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7508 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7509 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7510 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7511 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7512 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7513 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7518 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7519 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7520 | helper.getPowerProfile().getBatteryCapacity()); |
| 7521 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7522 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7523 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7524 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7525 | |
| 7526 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7527 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7528 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7529 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7530 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7531 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7532 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7533 | ent.getValue(), rawRealtimeUs, which); |
| 7534 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7535 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7536 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7540 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7541 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7542 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7543 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7544 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7545 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
| 7548 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7549 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7550 | which); |
| 7551 | |
| 7552 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7553 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7554 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7555 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7556 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7557 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7558 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7559 | } |
| 7560 | |
| 7561 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7562 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7563 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7564 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7565 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7566 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7567 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7568 | } |
| 7569 | |
| 7570 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7571 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7572 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7573 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7574 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7575 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7576 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7580 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7581 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7582 | proto.write(SystemProto.WifiState.NAME, i); |
| 7583 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7584 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7585 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7589 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7590 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7591 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7592 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7593 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7594 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | proto.end(sToken); |
| 7598 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7599 | } |