Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 20 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 22 | import android.content.pm.ApplicationInfo; |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 23 | import android.server.ServerProtoEnums; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 24 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 25 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 26 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 27 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 28 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 29 | import android.util.MutableBoolean; |
| 30 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.Printer; |
| 32 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 33 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 34 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 35 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 36 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 37 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 38 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 39 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 40 | import com.android.internal.os.BatterySipper; |
| 41 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 43 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
| 45 | import java.util.ArrayList; |
| 46 | import java.util.Collections; |
| 47 | import java.util.Comparator; |
| 48 | import java.util.Formatter; |
| 49 | import java.util.HashMap; |
| 50 | import java.util.List; |
| 51 | import java.util.Map; |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /** |
| 54 | * A class providing access to battery usage statistics, including information on |
| 55 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 56 | * except where indicated otherwise. |
| 57 | * @hide |
| 58 | */ |
| 59 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 60 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 63 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 64 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 65 | |
| 66 | /** @hide */ |
| 67 | public static final String SERVICE_NAME = "batterystats"; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /** |
| 70 | * A constant indicating a partial wake lock timer. |
| 71 | */ |
| 72 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 73 | |
| 74 | /** |
| 75 | * A constant indicating a full wake lock timer. |
| 76 | */ |
| 77 | public static final int WAKE_TYPE_FULL = 1; |
| 78 | |
| 79 | /** |
| 80 | * A constant indicating a window wake lock timer. |
| 81 | */ |
| 82 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | /** |
| 85 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | */ |
| 87 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 89 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 90 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 91 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 92 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 93 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 94 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 95 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 96 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 97 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 99 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 100 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 101 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 102 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 104 | /** |
| 105 | * A constant indicating a wifi multicast timer |
| 106 | */ |
| 107 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 110 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 111 | */ |
| 112 | public static final int VIDEO_TURNED_ON = 8; |
| 113 | |
| 114 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 115 | * A constant indicating a vibrator on timer |
| 116 | */ |
| 117 | public static final int VIBRATOR_ON = 9; |
| 118 | |
| 119 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 120 | * A constant indicating a foreground activity timer |
| 121 | */ |
| 122 | public static final int FOREGROUND_ACTIVITY = 10; |
| 123 | |
| 124 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 125 | * A constant indicating a wifi batched scan is active |
| 126 | */ |
| 127 | public static final int WIFI_BATCHED_SCAN = 11; |
| 128 | |
| 129 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 130 | * A constant indicating a process state timer |
| 131 | */ |
| 132 | public static final int PROCESS_STATE = 12; |
| 133 | |
| 134 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 135 | * A constant indicating a sync timer |
| 136 | */ |
| 137 | public static final int SYNC = 13; |
| 138 | |
| 139 | /** |
| 140 | * A constant indicating a job timer |
| 141 | */ |
| 142 | public static final int JOB = 14; |
| 143 | |
| 144 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 145 | * A constant indicating an audio turn on timer |
| 146 | */ |
| 147 | public static final int AUDIO_TURNED_ON = 15; |
| 148 | |
| 149 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 150 | * A constant indicating a flashlight turn on timer |
| 151 | */ |
| 152 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 153 | |
| 154 | /** |
| 155 | * A constant indicating a camera turn on timer |
| 156 | */ |
| 157 | public static final int CAMERA_TURNED_ON = 17; |
| 158 | |
| 159 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 160 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 161 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 162 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 165 | * A constant indicating a bluetooth scan timer. |
| 166 | */ |
| 167 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 168 | |
| 169 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 170 | * A constant indicating an aggregated partial wake lock timer. |
| 171 | */ |
| 172 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 173 | |
| 174 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 175 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 176 | */ |
| 177 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 178 | |
| 179 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 180 | * A constant indicating a foreground service timer |
| 181 | */ |
| 182 | public static final int FOREGROUND_SERVICE = 22; |
| 183 | |
| 184 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 185 | * A constant indicating an aggregate wifi multicast timer |
| 186 | */ |
| 187 | public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; |
| 188 | |
| 189 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | * Include all of the data in the stats, including previously saved data. |
| 191 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 192 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | |
| 194 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | * Include only the current run in the stats. |
| 196 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 197 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Include only the run since the last time the device was unplugged in the stats. |
| 201 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 202 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 203 | |
| 204 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 205 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 206 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 207 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 210 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 211 | * |
| 212 | * New in version 19: |
| 213 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 214 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 215 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 216 | * New in version 21: |
| 217 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 218 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 219 | * - BLE scan result count |
| 220 | * - CPU frequency time per uid |
| 221 | * New in version 22: |
| 222 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 223 | * - Background partial wakelock time & count |
| 224 | * New in version 23: |
| 225 | * - Logging smeared power model values |
| 226 | * New in version 24: |
| 227 | * - Fixed bugs in background timers and BLE scan time |
| 228 | * New in version 25: |
| 229 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 230 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 231 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 232 | * New in version 27: |
| 233 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 234 | * New in version 28: |
| 235 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 236 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 237 | * New in version 29: |
| 238 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 239 | * - CPU times per UID process state |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 240 | * New in version 30: |
| 241 | * - Uid.PROCESS_STATE_FOREGROUND_SERVICE only tracks |
| 242 | * ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 243 | */ |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 244 | static final int CHECKIN_VERSION = 30; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Old version, we hit 9 and ran out of room, need to remove. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 249 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 250 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 251 | private static final long BYTES_PER_KB = 1024; |
| 252 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 253 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 254 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 255 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 256 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 257 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 259 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 260 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 261 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 262 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 263 | // rpm line is: |
| 264 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 265 | // screen-off time, screen-off count |
| 266 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 267 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 268 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 269 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 270 | // fgs line is: |
| 271 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 272 | // foreground service time, count |
| 273 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 274 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 275 | // wl line is: |
| 276 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 277 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 278 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 279 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 280 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 281 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 282 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 283 | // awl line is: |
| 284 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 285 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 286 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 287 | private static final String SYNC_DATA = "sy"; |
| 288 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 289 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 290 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 291 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 292 | private static final String NETWORK_DATA = "nt"; |
| 293 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 294 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 295 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 296 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 297 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 298 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 299 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 300 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 301 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 302 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 303 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 304 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 305 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 306 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 307 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 308 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 309 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 310 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 311 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 312 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 313 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 314 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 315 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 316 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 317 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 318 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 319 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 320 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 321 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 322 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 323 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 324 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 325 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 326 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 327 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 328 | private static final String FLASHLIGHT_DATA = "fla"; |
| 329 | private static final String CAMERA_DATA = "cam"; |
| 330 | private static final String VIDEO_DATA = "vid"; |
| 331 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 332 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 333 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 335 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 336 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 337 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 339 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 340 | private static final String CELLULAR_CONTROLLER_NAME = "Cellular"; |
| 341 | private static final String WIFI_CONTROLLER_NAME = "WiFi"; |
| 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 344 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 345 | * |
| 346 | * Other types might include times spent in foreground, background etc. |
| 347 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 348 | @VisibleForTesting |
| 349 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 350 | |
| 351 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 352 | * State for keeping track of counting information. |
| 353 | */ |
| 354 | public static abstract class Counter { |
| 355 | |
| 356 | /** |
| 357 | * Returns the count associated with this Counter for the |
| 358 | * selected type of statistics. |
| 359 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 360 | * @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] | 361 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 362 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 363 | |
| 364 | /** |
| 365 | * Temporary for debugging. |
| 366 | */ |
| 367 | public abstract void logState(Printer pw, String prefix); |
| 368 | } |
| 369 | |
| 370 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 371 | * State for keeping track of long counting information. |
| 372 | */ |
| 373 | public static abstract class LongCounter { |
| 374 | |
| 375 | /** |
| 376 | * Returns the count associated with this Counter for the |
| 377 | * selected type of statistics. |
| 378 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 379 | * @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] | 380 | */ |
| 381 | public abstract long getCountLocked(int which); |
| 382 | |
| 383 | /** |
| 384 | * Temporary for debugging. |
| 385 | */ |
| 386 | public abstract void logState(Printer pw, String prefix); |
| 387 | } |
| 388 | |
| 389 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 390 | * State for keeping track of array of long counting information. |
| 391 | */ |
| 392 | public static abstract class LongCounterArray { |
| 393 | /** |
| 394 | * Returns the counts associated with this Counter for the |
| 395 | * selected type of statistics. |
| 396 | * |
| 397 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 398 | */ |
| 399 | public abstract long[] getCountsLocked(int which); |
| 400 | |
| 401 | /** |
| 402 | * Temporary for debugging. |
| 403 | */ |
| 404 | public abstract void logState(Printer pw, String prefix); |
| 405 | } |
| 406 | |
| 407 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 408 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 409 | * radio controller. |
| 410 | */ |
| 411 | public static abstract class ControllerActivityCounter { |
| 412 | /** |
| 413 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 414 | * idle state. |
| 415 | */ |
| 416 | public abstract LongCounter getIdleTimeCounter(); |
| 417 | |
| 418 | /** |
| 419 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 420 | * scan state. |
| 421 | */ |
| 422 | public abstract LongCounter getScanTimeCounter(); |
| 423 | |
| 424 | |
| 425 | /** |
| 426 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 427 | * receive state. |
| 428 | */ |
| 429 | public abstract LongCounter getRxTimeCounter(); |
| 430 | |
| 431 | /** |
| 432 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 433 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 434 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 435 | * various transmit level states. |
| 436 | */ |
| 437 | public abstract LongCounter[] getTxTimeCounters(); |
| 438 | |
| 439 | /** |
| 440 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 441 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 442 | * yield a value of 0 if the device doesn't support power calculations. |
| 443 | */ |
| 444 | public abstract LongCounter getPowerCounter(); |
| 445 | } |
| 446 | |
| 447 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | * State for keeping track of timing information. |
| 449 | */ |
| 450 | public static abstract class Timer { |
| 451 | |
| 452 | /** |
| 453 | * Returns the count associated with this Timer for the |
| 454 | * selected type of statistics. |
| 455 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 456 | * @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] | 457 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 458 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | |
| 460 | /** |
| 461 | * Returns the total time in microseconds associated with this Timer for the |
| 462 | * selected type of statistics. |
| 463 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 464 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 465 | * @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] | 466 | * @return a time in microseconds |
| 467 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 468 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 471 | * Returns the total time in microseconds associated with this Timer since the |
| 472 | * 'mark' was last set. |
| 473 | * |
| 474 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 475 | * @return a time in microseconds |
| 476 | */ |
| 477 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 478 | |
| 479 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 480 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 481 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 482 | */ |
| 483 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 484 | return -1; |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * 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] | 489 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 490 | */ |
| 491 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 496 | * 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] | 497 | * |
| 498 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 499 | * been on since reset. |
| 500 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 501 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 502 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 503 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 504 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 505 | */ |
| 506 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 507 | return -1; |
| 508 | } |
| 509 | |
| 510 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 511 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 512 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 513 | * |
| 514 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 515 | */ |
| 516 | public Timer getSubTimer() { |
| 517 | return null; |
| 518 | } |
| 519 | |
| 520 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 521 | * Returns whether the timer is currently running. Some types of timers |
| 522 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 523 | * and report false. |
| 524 | */ |
| 525 | public boolean isRunningLocked() { |
| 526 | return false; |
| 527 | } |
| 528 | |
| 529 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | * Temporary for debugging. |
| 531 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 532 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 536 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 537 | */ |
| 538 | public static int mapToInternalProcessState(int procState) { |
| 539 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 540 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 541 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 542 | return Uid.PROCESS_STATE_TOP; |
Dianne Hackborn | 10fc4fd | 2017-12-19 17:23:13 -0800 | [diff] [blame] | 543 | } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 544 | // State when app has put itself in the foreground. |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 545 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 546 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 547 | // Persistent and other foreground states go here. |
| 548 | return Uid.PROCESS_STATE_FOREGROUND; |
| 549 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 550 | return Uid.PROCESS_STATE_BACKGROUND; |
| 551 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 552 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 553 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 554 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 555 | } else { |
| 556 | return Uid.PROCESS_STATE_CACHED; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | * The statistics associated with a particular uid. |
| 562 | */ |
| 563 | public static abstract class Uid { |
| 564 | |
| 565 | /** |
| 566 | * Returns a mapping containing wakelock statistics. |
| 567 | * |
| 568 | * @return a Map from Strings to Uid.Wakelock objects. |
| 569 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 570 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | |
| 572 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 573 | * Returns the WiFi Multicast Wakelock statistics. |
| 574 | * |
| 575 | * @return a Timer Object for the per uid Multicast statistics. |
| 576 | */ |
| 577 | public abstract Timer getMulticastWakelockStats(); |
| 578 | |
| 579 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 580 | * Returns a mapping containing sync statistics. |
| 581 | * |
| 582 | * @return a Map from Strings to Timer objects. |
| 583 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 584 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * Returns a mapping containing scheduled job statistics. |
| 588 | * |
| 589 | * @return a Map from Strings to Timer objects. |
| 590 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 591 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 592 | |
| 593 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 594 | * Returns statistics about how jobs have completed. |
| 595 | * |
| 596 | * @return A Map of String job names to completion type -> count mapping. |
| 597 | */ |
| 598 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 599 | |
| 600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | * The statistics associated with a particular wake lock. |
| 602 | */ |
| 603 | public static abstract class Wakelock { |
| 604 | public abstract Timer getWakeTime(int type); |
| 605 | } |
| 606 | |
| 607 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 608 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 609 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 610 | * wakelocks that overlap in time (and therefore over-counts). |
| 611 | */ |
| 612 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 613 | |
| 614 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | * Returns a mapping containing sensor statistics. |
| 616 | * |
| 617 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 618 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 619 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | |
| 621 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 622 | * Returns a mapping containing active process data. |
| 623 | */ |
| 624 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 625 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 626 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | * Returns a mapping containing process statistics. |
| 628 | * |
| 629 | * @return a Map from Strings to Uid.Proc objects. |
| 630 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 631 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
| 633 | /** |
| 634 | * Returns a mapping containing package statistics. |
| 635 | * |
| 636 | * @return a Map from Strings to Uid.Pkg objects. |
| 637 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 638 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 639 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 640 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 641 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 642 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 643 | |
| 644 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | * {@hide} |
| 646 | */ |
| 647 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 648 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 649 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 650 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 651 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 652 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 653 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 654 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 655 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 656 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 657 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 658 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 659 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 660 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 661 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 662 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 663 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 664 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 665 | /** |
| 666 | * Returns the timer keeping track of wifi scans. |
| 667 | */ |
| 668 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 669 | public abstract int getWifiScanBackgroundCount(int which); |
| 670 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 671 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 672 | /** |
| 673 | * Returns the timer keeping track of background wifi scans. |
| 674 | */ |
| 675 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 676 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 677 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 678 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 679 | public abstract Timer getAudioTurnedOnTimer(); |
| 680 | public abstract Timer getVideoTurnedOnTimer(); |
| 681 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 682 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 683 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 684 | |
| 685 | /** |
| 686 | * Returns the timer keeping track of Foreground Service time |
| 687 | */ |
| 688 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 689 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 690 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 691 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 692 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 693 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 694 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 695 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 696 | public abstract long[] getCpuFreqTimes(int which); |
| 697 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 698 | /** |
| 699 | * Returns cpu active time of an uid. |
| 700 | */ |
| 701 | public abstract long getCpuActiveTime(); |
| 702 | /** |
| 703 | * Returns cpu times of an uid on each cluster |
| 704 | */ |
| 705 | public abstract long[] getCpuClusterTimes(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 706 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 707 | /** |
| 708 | * Returns cpu times of an uid at a particular process state. |
| 709 | */ |
| 710 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 711 | /** |
| 712 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 713 | */ |
| 714 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 715 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 716 | // Note: the following times are disjoint. They can be added together to find the |
| 717 | // total time a uid has had any processes running at all. |
| 718 | |
| 719 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 720 | * Time this uid has any processes in the top state. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 721 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 722 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 723 | /** |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 724 | * Time this uid has any process with a started foreground service, but |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 725 | * none in the "top" state. |
| 726 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 727 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 728 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 729 | * Time this uid has any process in an active foreground state, but none in the |
zhouwenjie | 46712bc | 2018-01-11 15:21:27 -0800 | [diff] [blame] | 730 | * "foreground service" or better state. Persistent and other foreground states go here. |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 731 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 732 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 733 | /** |
| 734 | * Time this uid has any process in an active background state, but none in the |
| 735 | * "foreground" or better state. |
| 736 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 737 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 738 | /** |
| 739 | * Time this uid has any process that is top while the device is sleeping, but not |
| 740 | * active for any other reason. We kind-of consider it a kind of cached process |
| 741 | * for execution restrictions. |
| 742 | */ |
| 743 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 744 | /** |
| 745 | * Time this uid has any process that is in the background but it has an activity |
| 746 | * marked as "can't save state". This is essentially a cached process, though the |
| 747 | * system will try much harder than normal to avoid killing it. |
| 748 | */ |
| 749 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 752 | * other active states. |
| 753 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 754 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 755 | /** |
| 756 | * Total number of process states we track. |
| 757 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 758 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 759 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 760 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 761 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 762 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 763 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 764 | }; |
| 765 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 766 | // Used in checkin dump |
| 767 | @VisibleForTesting |
| 768 | public static final String[] UID_PROCESS_TYPES = { |
| 769 | "T", // TOP |
| 770 | "FS", // FOREGROUND_SERVICE |
| 771 | "F", // FOREGROUND |
| 772 | "B", // BACKGROUND |
| 773 | "TS", // TOP_SLEEPING |
| 774 | "HW", // HEAVY_WEIGHT |
| 775 | "C" // CACHED |
| 776 | }; |
| 777 | |
| 778 | /** |
| 779 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 780 | * is not attributed to any non-critical process states. |
| 781 | */ |
| 782 | public static final int[] CRITICAL_PROC_STATES = { |
| 783 | PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND |
| 784 | }; |
| 785 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 786 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 787 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 788 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 789 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 791 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 792 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 793 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 794 | * Note that these must match the constants in android.os.PowerManager. |
| 795 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 796 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 797 | */ |
| 798 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 799 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 800 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 801 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 802 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 803 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 804 | public abstract void noteUserActivityLocked(int type); |
| 805 | public abstract boolean hasUserActivity(); |
| 806 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 807 | |
| 808 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 809 | public abstract long getNetworkActivityBytes(int type, int which); |
| 810 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 811 | public abstract long getMobileRadioActiveTime(int which); |
| 812 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 813 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 814 | /** |
| 815 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 816 | */ |
| 817 | public abstract long getUserCpuTimeUs(int which); |
| 818 | |
| 819 | /** |
| 820 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 821 | */ |
| 822 | public abstract long getSystemCpuTimeUs(int which); |
| 823 | |
| 824 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 825 | * 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] | 826 | * given CPU cluster. |
| 827 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 828 | * @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] | 829 | * @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] | 830 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 831 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 832 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 833 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 834 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 835 | /** |
| 836 | * Returns the number of times this UID woke up the Application Processor to |
| 837 | * process a mobile radio packet. |
| 838 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 839 | */ |
| 840 | public abstract long getMobileRadioApWakeupCount(int which); |
| 841 | |
| 842 | /** |
| 843 | * Returns the number of times this UID woke up the Application Processor to |
| 844 | * process a WiFi packet. |
| 845 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 846 | */ |
| 847 | public abstract long getWifiRadioApWakeupCount(int which); |
| 848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 850 | /* |
| 851 | * FIXME: it's not correct to use this magic value because it |
| 852 | * could clash with a sensor handle (which are defined by |
| 853 | * the sensor HAL, and therefore out of our control |
| 854 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | // Magic sensor number for the GPS. |
| 856 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 861 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 862 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 863 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 866 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 867 | public int mWakeNesting; |
| 868 | public long mWakeSumMs; |
| 869 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 870 | } |
| 871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | /** |
| 873 | * The statistics associated with a particular process. |
| 874 | */ |
| 875 | public static abstract class Proc { |
| 876 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 877 | public static class ExcessivePower { |
| 878 | public static final int TYPE_WAKE = 1; |
| 879 | public static final int TYPE_CPU = 2; |
| 880 | |
| 881 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 882 | public long overTime; |
| 883 | public long usedTime; |
| 884 | } |
| 885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 887 | * Returns true if this process is still active in the battery stats. |
| 888 | */ |
| 889 | public abstract boolean isActive(); |
| 890 | |
| 891 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 892 | * 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] | 893 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 894 | * @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] | 895 | */ |
| 896 | public abstract long getUserTime(int which); |
| 897 | |
| 898 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 899 | * 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] | 900 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 901 | * @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] | 902 | */ |
| 903 | public abstract long getSystemTime(int which); |
| 904 | |
| 905 | /** |
| 906 | * Returns the number of times the process has been started. |
| 907 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 908 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | */ |
| 910 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 911 | |
| 912 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 913 | * Returns the number of times the process has crashed. |
| 914 | * |
| 915 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 916 | */ |
| 917 | public abstract int getNumCrashes(int which); |
| 918 | |
| 919 | /** |
| 920 | * Returns the number of times the process has ANRed. |
| 921 | * |
| 922 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 923 | */ |
| 924 | public abstract int getNumAnrs(int which); |
| 925 | |
| 926 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 927 | * 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] | 928 | * @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] | 929 | * @return foreground cpu time in microseconds |
| 930 | */ |
| 931 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 932 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 933 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 934 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 935 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /** |
| 939 | * The statistics associated with a particular package. |
| 940 | */ |
| 941 | public static abstract class Pkg { |
| 942 | |
| 943 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 944 | * Returns information about all wakeup alarms that have been triggered for this |
| 945 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 946 | * 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] | 947 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 948 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | |
| 950 | /** |
| 951 | * Returns a mapping containing service statistics. |
| 952 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 953 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | |
| 955 | /** |
| 956 | * The statistics associated with a particular service. |
| 957 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 958 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | |
| 960 | /** |
| 961 | * Returns the amount of time spent started. |
| 962 | * |
| 963 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 964 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | * @return |
| 966 | */ |
| 967 | public abstract long getStartTime(long batteryUptime, int which); |
| 968 | |
| 969 | /** |
| 970 | * Returns the total number of times startService() has been called. |
| 971 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 972 | * @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] | 973 | */ |
| 974 | public abstract int getStarts(int which); |
| 975 | |
| 976 | /** |
| 977 | * Returns the total number times the service has been launched. |
| 978 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 979 | * @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] | 980 | */ |
| 981 | public abstract int getLaunches(int which); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 986 | public static final class LevelStepTracker { |
| 987 | public long mLastStepTime = -1; |
| 988 | public int mNumStepDurations; |
| 989 | public final long[] mStepDurations; |
| 990 | |
| 991 | public LevelStepTracker(int maxLevelSteps) { |
| 992 | mStepDurations = new long[maxLevelSteps]; |
| 993 | } |
| 994 | |
| 995 | public LevelStepTracker(int numSteps, long[] steps) { |
| 996 | mNumStepDurations = numSteps; |
| 997 | mStepDurations = new long[numSteps]; |
| 998 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 999 | } |
| 1000 | |
| 1001 | public long getDurationAt(int index) { |
| 1002 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 1003 | } |
| 1004 | |
| 1005 | public int getLevelAt(int index) { |
| 1006 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 1007 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1008 | } |
| 1009 | |
| 1010 | public int getInitModeAt(int index) { |
| 1011 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1012 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1013 | } |
| 1014 | |
| 1015 | public int getModModeAt(int index) { |
| 1016 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1017 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1018 | } |
| 1019 | |
| 1020 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 1021 | boolean hasData = false; |
| 1022 | while (topOffset >= 0) { |
| 1023 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1024 | topOffset -= 4; |
| 1025 | if (!hasData && digit == 0) { |
| 1026 | continue; |
| 1027 | } |
| 1028 | hasData = true; |
| 1029 | if (digit >= 0 && digit <= 9) { |
| 1030 | out.append((char)('0' + digit)); |
| 1031 | } else { |
| 1032 | out.append((char)('a' + digit - 10)); |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1038 | long item = mStepDurations[index]; |
| 1039 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1040 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1041 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1042 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1043 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1044 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1045 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1046 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1047 | case Display.STATE_OFF: out.append('f'); break; |
| 1048 | case Display.STATE_ON: out.append('o'); break; |
| 1049 | case Display.STATE_DOZE: out.append('d'); break; |
| 1050 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1051 | } |
| 1052 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1053 | out.append('p'); |
| 1054 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1055 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1056 | out.append('i'); |
| 1057 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1058 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1059 | case Display.STATE_OFF: out.append('F'); break; |
| 1060 | case Display.STATE_ON: out.append('O'); break; |
| 1061 | case Display.STATE_DOZE: out.append('D'); break; |
| 1062 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1063 | } |
| 1064 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1065 | out.append('P'); |
| 1066 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1067 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1068 | out.append('I'); |
| 1069 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1070 | out.append('-'); |
| 1071 | appendHex(level, 4, out); |
| 1072 | out.append('-'); |
| 1073 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1074 | } |
| 1075 | |
| 1076 | public void decodeEntryAt(int index, String value) { |
| 1077 | final int N = value.length(); |
| 1078 | int i = 0; |
| 1079 | char c; |
| 1080 | long out = 0; |
| 1081 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1082 | i++; |
| 1083 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1084 | 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] | 1085 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1086 | 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] | 1087 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1088 | 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] | 1089 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1090 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1091 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1092 | break; |
| 1093 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1094 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1095 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1096 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1097 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1098 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1099 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1100 | break; |
| 1101 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1102 | break; |
| 1103 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1104 | break; |
| 1105 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1106 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1107 | break; |
| 1108 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1109 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1110 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1111 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1112 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1113 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1117 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1118 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1119 | i++; |
| 1120 | level <<= 4; |
| 1121 | if (c >= '0' && c <= '9') { |
| 1122 | level += c - '0'; |
| 1123 | } else if (c >= 'a' && c <= 'f') { |
| 1124 | level += c - 'a' + 10; |
| 1125 | } else if (c >= 'A' && c <= 'F') { |
| 1126 | level += c - 'A' + 10; |
| 1127 | } |
| 1128 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1129 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1130 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1131 | long duration = 0; |
| 1132 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1133 | i++; |
| 1134 | duration <<= 4; |
| 1135 | if (c >= '0' && c <= '9') { |
| 1136 | duration += c - '0'; |
| 1137 | } else if (c >= 'a' && c <= 'f') { |
| 1138 | duration += c - 'a' + 10; |
| 1139 | } else if (c >= 'A' && c <= 'F') { |
| 1140 | duration += c - 'A' + 10; |
| 1141 | } |
| 1142 | } |
| 1143 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1144 | } |
| 1145 | |
| 1146 | public void init() { |
| 1147 | mLastStepTime = -1; |
| 1148 | mNumStepDurations = 0; |
| 1149 | } |
| 1150 | |
| 1151 | public void clearTime() { |
| 1152 | mLastStepTime = -1; |
| 1153 | } |
| 1154 | |
| 1155 | public long computeTimePerLevel() { |
| 1156 | final long[] steps = mStepDurations; |
| 1157 | final int numSteps = mNumStepDurations; |
| 1158 | |
| 1159 | // For now we'll do a simple average across all steps. |
| 1160 | if (numSteps <= 0) { |
| 1161 | return -1; |
| 1162 | } |
| 1163 | long total = 0; |
| 1164 | for (int i=0; i<numSteps; i++) { |
| 1165 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1166 | } |
| 1167 | return total / numSteps; |
| 1168 | /* |
| 1169 | long[] buckets = new long[numSteps]; |
| 1170 | int numBuckets = 0; |
| 1171 | int numToAverage = 4; |
| 1172 | int i = 0; |
| 1173 | while (i < numSteps) { |
| 1174 | long totalTime = 0; |
| 1175 | int num = 0; |
| 1176 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1177 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1178 | num++; |
| 1179 | } |
| 1180 | buckets[numBuckets] = totalTime / num; |
| 1181 | numBuckets++; |
| 1182 | numToAverage *= 2; |
| 1183 | i += num; |
| 1184 | } |
| 1185 | if (numBuckets < 1) { |
| 1186 | return -1; |
| 1187 | } |
| 1188 | long averageTime = buckets[numBuckets-1]; |
| 1189 | for (i=numBuckets-2; i>=0; i--) { |
| 1190 | averageTime = (averageTime + buckets[i]) / 2; |
| 1191 | } |
| 1192 | return averageTime; |
| 1193 | */ |
| 1194 | } |
| 1195 | |
| 1196 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1197 | int[] outNumOfInterest) { |
| 1198 | final long[] steps = mStepDurations; |
| 1199 | final int count = mNumStepDurations; |
| 1200 | if (count <= 0) { |
| 1201 | return -1; |
| 1202 | } |
| 1203 | long total = 0; |
| 1204 | int numOfInterest = 0; |
| 1205 | for (int i=0; i<count; i++) { |
| 1206 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1207 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1208 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1209 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1210 | // If the modes of interest didn't change during this step period... |
| 1211 | if ((modMode&modesOfInterest) == 0) { |
| 1212 | // And the mode values during this period match those we are measuring... |
| 1213 | if ((initMode&modesOfInterest) == modeValues) { |
| 1214 | // Then this can be used to estimate the total time! |
| 1215 | numOfInterest++; |
| 1216 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | if (numOfInterest <= 0) { |
| 1221 | return -1; |
| 1222 | } |
| 1223 | |
| 1224 | if (outNumOfInterest != null) { |
| 1225 | outNumOfInterest[0] = numOfInterest; |
| 1226 | } |
| 1227 | |
| 1228 | // The estimated time is the average time we spend in each level, multipled |
| 1229 | // by 100 -- the total number of battery levels |
| 1230 | return (total / numOfInterest) * 100; |
| 1231 | } |
| 1232 | |
| 1233 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1234 | int stepCount = mNumStepDurations; |
| 1235 | final long lastStepTime = mLastStepTime; |
| 1236 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1237 | final long[] steps = mStepDurations; |
| 1238 | long duration = elapsedRealtime - lastStepTime; |
| 1239 | for (int i=0; i<numStepLevels; i++) { |
| 1240 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1241 | long thisDuration = duration / (numStepLevels-i); |
| 1242 | duration -= thisDuration; |
| 1243 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1244 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1245 | } |
| 1246 | steps[0] = thisDuration | modeBits; |
| 1247 | } |
| 1248 | stepCount += numStepLevels; |
| 1249 | if (stepCount > steps.length) { |
| 1250 | stepCount = steps.length; |
| 1251 | } |
| 1252 | } |
| 1253 | mNumStepDurations = stepCount; |
| 1254 | mLastStepTime = elapsedRealtime; |
| 1255 | } |
| 1256 | |
| 1257 | public void readFromParcel(Parcel in) { |
| 1258 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1259 | if (N > mStepDurations.length) { |
| 1260 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1261 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1262 | mNumStepDurations = N; |
| 1263 | for (int i=0; i<N; i++) { |
| 1264 | mStepDurations[i] = in.readLong(); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | public void writeToParcel(Parcel out) { |
| 1269 | final int N = mNumStepDurations; |
| 1270 | out.writeInt(N); |
| 1271 | for (int i=0; i<N; i++) { |
| 1272 | out.writeLong(mStepDurations[i]); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1277 | public static final class PackageChange { |
| 1278 | public String mPackageName; |
| 1279 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1280 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1283 | public static final class DailyItem { |
| 1284 | public long mStartTime; |
| 1285 | public long mEndTime; |
| 1286 | public LevelStepTracker mDischargeSteps; |
| 1287 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1288 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1292 | |
| 1293 | public abstract long getCurrentDailyStartTime(); |
| 1294 | |
| 1295 | public abstract long getNextMinDailyDeadline(); |
| 1296 | |
| 1297 | public abstract long getNextMaxDailyDeadline(); |
| 1298 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1299 | public abstract long[] getCpuFreqs(); |
| 1300 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1301 | public final static class HistoryTag { |
| 1302 | public String string; |
| 1303 | public int uid; |
| 1304 | |
| 1305 | public int poolIdx; |
| 1306 | |
| 1307 | public void setTo(HistoryTag o) { |
| 1308 | string = o.string; |
| 1309 | uid = o.uid; |
| 1310 | poolIdx = o.poolIdx; |
| 1311 | } |
| 1312 | |
| 1313 | public void setTo(String _string, int _uid) { |
| 1314 | string = _string; |
| 1315 | uid = _uid; |
| 1316 | poolIdx = -1; |
| 1317 | } |
| 1318 | |
| 1319 | public void writeToParcel(Parcel dest, int flags) { |
| 1320 | dest.writeString(string); |
| 1321 | dest.writeInt(uid); |
| 1322 | } |
| 1323 | |
| 1324 | public void readFromParcel(Parcel src) { |
| 1325 | string = src.readString(); |
| 1326 | uid = src.readInt(); |
| 1327 | poolIdx = -1; |
| 1328 | } |
| 1329 | |
| 1330 | @Override |
| 1331 | public boolean equals(Object o) { |
| 1332 | if (this == o) return true; |
| 1333 | if (o == null || getClass() != o.getClass()) return false; |
| 1334 | |
| 1335 | HistoryTag that = (HistoryTag) o; |
| 1336 | |
| 1337 | if (uid != that.uid) return false; |
| 1338 | if (!string.equals(that.string)) return false; |
| 1339 | |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | @Override |
| 1344 | public int hashCode() { |
| 1345 | int result = string.hashCode(); |
| 1346 | result = 31 * result + uid; |
| 1347 | return result; |
| 1348 | } |
| 1349 | } |
| 1350 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1351 | /** |
| 1352 | * Optional detailed information that can go into a history step. This is typically |
| 1353 | * generated each time the battery level changes. |
| 1354 | */ |
| 1355 | public final static class HistoryStepDetails { |
| 1356 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1357 | public int userTime; |
| 1358 | public int systemTime; |
| 1359 | |
| 1360 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1361 | public int appCpuUid1; |
| 1362 | public int appCpuUTime1; |
| 1363 | public int appCpuSTime1; |
| 1364 | public int appCpuUid2; |
| 1365 | public int appCpuUTime2; |
| 1366 | public int appCpuSTime2; |
| 1367 | public int appCpuUid3; |
| 1368 | public int appCpuUTime3; |
| 1369 | public int appCpuSTime3; |
| 1370 | |
| 1371 | // Information from /proc/stat |
| 1372 | public int statUserTime; |
| 1373 | public int statSystemTime; |
| 1374 | public int statIOWaitTime; |
| 1375 | public int statIrqTime; |
| 1376 | public int statSoftIrqTime; |
| 1377 | public int statIdlTime; |
| 1378 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1379 | // Platform-level low power state stats |
| 1380 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1381 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1382 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1383 | public HistoryStepDetails() { |
| 1384 | clear(); |
| 1385 | } |
| 1386 | |
| 1387 | public void clear() { |
| 1388 | userTime = systemTime = 0; |
| 1389 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1390 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1391 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1392 | } |
| 1393 | |
| 1394 | public void writeToParcel(Parcel out) { |
| 1395 | out.writeInt(userTime); |
| 1396 | out.writeInt(systemTime); |
| 1397 | out.writeInt(appCpuUid1); |
| 1398 | out.writeInt(appCpuUTime1); |
| 1399 | out.writeInt(appCpuSTime1); |
| 1400 | out.writeInt(appCpuUid2); |
| 1401 | out.writeInt(appCpuUTime2); |
| 1402 | out.writeInt(appCpuSTime2); |
| 1403 | out.writeInt(appCpuUid3); |
| 1404 | out.writeInt(appCpuUTime3); |
| 1405 | out.writeInt(appCpuSTime3); |
| 1406 | out.writeInt(statUserTime); |
| 1407 | out.writeInt(statSystemTime); |
| 1408 | out.writeInt(statIOWaitTime); |
| 1409 | out.writeInt(statIrqTime); |
| 1410 | out.writeInt(statSoftIrqTime); |
| 1411 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1412 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1413 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | public void readFromParcel(Parcel in) { |
| 1417 | userTime = in.readInt(); |
| 1418 | systemTime = in.readInt(); |
| 1419 | appCpuUid1 = in.readInt(); |
| 1420 | appCpuUTime1 = in.readInt(); |
| 1421 | appCpuSTime1 = in.readInt(); |
| 1422 | appCpuUid2 = in.readInt(); |
| 1423 | appCpuUTime2 = in.readInt(); |
| 1424 | appCpuSTime2 = in.readInt(); |
| 1425 | appCpuUid3 = in.readInt(); |
| 1426 | appCpuUTime3 = in.readInt(); |
| 1427 | appCpuSTime3 = in.readInt(); |
| 1428 | statUserTime = in.readInt(); |
| 1429 | statSystemTime = in.readInt(); |
| 1430 | statIOWaitTime = in.readInt(); |
| 1431 | statIrqTime = in.readInt(); |
| 1432 | statSoftIrqTime = in.readInt(); |
| 1433 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1434 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1435 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1439 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1440 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1441 | |
| 1442 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1443 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1444 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1445 | 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] | 1446 | public static final byte CMD_NULL = -1; |
| 1447 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1448 | public static final byte CMD_CURRENT_TIME = 5; |
| 1449 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1450 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1451 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1452 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1453 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1454 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1455 | /** |
| 1456 | * Return whether the command code is a delta data update. |
| 1457 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1458 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1459 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1462 | public byte batteryLevel; |
| 1463 | public byte batteryStatus; |
| 1464 | public byte batteryHealth; |
| 1465 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1466 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1467 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1468 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1469 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1470 | // The charge of the battery in micro-Ampere-hours. |
| 1471 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1472 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1473 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1474 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1475 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1476 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1477 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1478 | 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] | 1479 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1480 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1481 | 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] | 1482 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1483 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1484 | 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] | 1485 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1486 | // These states always appear directly in the first int token |
| 1487 | // of a delta change; they should be ones that change relatively |
| 1488 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1489 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1490 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1491 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1492 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1493 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1494 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1495 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1496 | // Do not use, this is used for coulomb delta count. |
| 1497 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1498 | // These are on the lower bits used for the command; if they change |
| 1499 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1500 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1501 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1502 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1503 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1504 | 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] | 1505 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1506 | // empty slot |
| 1507 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1508 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1509 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1510 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1511 | |
| 1512 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1513 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1514 | public int states; |
| 1515 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1516 | // Constants from WIFI_SUPPL_STATE_* |
| 1517 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1518 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1519 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1520 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1521 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1522 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 1523 | // Values for NUM_GPS_SIGNAL_QUALITY_LEVELS |
| 1524 | public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7; |
| 1525 | public static final int STATE2_GPS_SIGNAL_QUALITY_MASK = |
| 1526 | 0x1 << STATE2_GPS_SIGNAL_QUALITY_SHIFT; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1527 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1528 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1529 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1530 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1531 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1532 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1533 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1534 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1535 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1536 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1537 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1538 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1539 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 1540 | public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1541 | |
| 1542 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1543 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1544 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1545 | |
| 1546 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1547 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1548 | public int states2; |
| 1549 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1550 | // The wake lock that was acquired at this point. |
| 1551 | public HistoryTag wakelockTag; |
| 1552 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1553 | // Kernel wakeup reason at this point. |
| 1554 | public HistoryTag wakeReasonTag; |
| 1555 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1556 | // Non-null when there is more detailed information at this step. |
| 1557 | public HistoryStepDetails stepDetails; |
| 1558 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1559 | public static final int EVENT_FLAG_START = 0x8000; |
| 1560 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1561 | |
| 1562 | // No event in this item. |
| 1563 | public static final int EVENT_NONE = 0x0000; |
| 1564 | // Event is about a process that is running. |
| 1565 | public static final int EVENT_PROC = 0x0001; |
| 1566 | // Event is about an application package that is in the foreground. |
| 1567 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1568 | // Event is about an application package that is at the top of the screen. |
| 1569 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1570 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1571 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1572 | // Events for all additional wake locks aquired/release within a wake block. |
| 1573 | // These are not generated by default. |
| 1574 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1575 | // Event is about an application executing a scheduled job. |
| 1576 | public static final int EVENT_JOB = 0x0006; |
| 1577 | // Events for users running. |
| 1578 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1579 | // Events for foreground user. |
| 1580 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1581 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1582 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1583 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1584 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1585 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1586 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1587 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1588 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1589 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1590 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1591 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1592 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1593 | // 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] | 1594 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1595 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1596 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1597 | // Event for a package being on the temporary whitelist. |
| 1598 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1599 | // Event for the screen waking up. |
| 1600 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1601 | // Event for the UID that woke up the application processor. |
| 1602 | // Used for wakeups coming from WiFi, modem, etc. |
| 1603 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1604 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1605 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1606 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1607 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1608 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1609 | // Mask to extract out only the type part of the event. |
| 1610 | 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] | 1611 | |
| 1612 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1613 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1614 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1615 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1616 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1617 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1618 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1619 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1620 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1621 | 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] | 1622 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1623 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1624 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1625 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1626 | public static final int EVENT_USER_FOREGROUND_START = |
| 1627 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1628 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1629 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1630 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1631 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1632 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1633 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1634 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1635 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1636 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1637 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1638 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1639 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1640 | |
| 1641 | // For CMD_EVENT. |
| 1642 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1643 | public HistoryTag eventTag; |
| 1644 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1645 | // 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] | 1646 | public long currentTime; |
| 1647 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1648 | // Meta-data when reading. |
| 1649 | public int numReadInts; |
| 1650 | |
| 1651 | // Pre-allocated objects. |
| 1652 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1653 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1654 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1655 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1656 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1657 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1658 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1659 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1660 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1661 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1662 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1663 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1664 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1665 | public int describeContents() { |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | public void writeToParcel(Parcel dest, int flags) { |
| 1670 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1671 | int bat = (((int)cmd)&0xff) |
| 1672 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1673 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1674 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1675 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1676 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1677 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1678 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1679 | dest.writeInt(bat); |
| 1680 | bat = (((int)batteryTemperature)&0xffff) |
| 1681 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1682 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1683 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1684 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1685 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1686 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1687 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1688 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1689 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1690 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1691 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1692 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1693 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1694 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1695 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1696 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1697 | dest.writeLong(currentTime); |
| 1698 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1699 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1700 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1701 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1702 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1703 | int bat = src.readInt(); |
| 1704 | cmd = (byte)(bat&0xff); |
| 1705 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1706 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1707 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1708 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1709 | int bat2 = src.readInt(); |
| 1710 | batteryTemperature = (short)(bat2&0xffff); |
| 1711 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1712 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1713 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1714 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1715 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1716 | wakelockTag = localWakelockTag; |
| 1717 | wakelockTag.readFromParcel(src); |
| 1718 | } else { |
| 1719 | wakelockTag = null; |
| 1720 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1721 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1722 | wakeReasonTag = localWakeReasonTag; |
| 1723 | wakeReasonTag.readFromParcel(src); |
| 1724 | } else { |
| 1725 | wakeReasonTag = null; |
| 1726 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1727 | if ((bat&0x40000000) != 0) { |
| 1728 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1729 | eventTag = localEventTag; |
| 1730 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1731 | } else { |
| 1732 | eventCode = EVENT_NONE; |
| 1733 | eventTag = null; |
| 1734 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1735 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1736 | currentTime = src.readLong(); |
| 1737 | } else { |
| 1738 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1739 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1740 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1743 | public void clear() { |
| 1744 | time = 0; |
| 1745 | cmd = CMD_NULL; |
| 1746 | batteryLevel = 0; |
| 1747 | batteryStatus = 0; |
| 1748 | batteryHealth = 0; |
| 1749 | batteryPlugType = 0; |
| 1750 | batteryTemperature = 0; |
| 1751 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1752 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1753 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1754 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1755 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1756 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1757 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1758 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1759 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1760 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1761 | public void setTo(HistoryItem o) { |
| 1762 | time = o.time; |
| 1763 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1764 | setToCommon(o); |
| 1765 | } |
| 1766 | |
| 1767 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1768 | this.time = time; |
| 1769 | this.cmd = cmd; |
| 1770 | setToCommon(o); |
| 1771 | } |
| 1772 | |
| 1773 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1774 | batteryLevel = o.batteryLevel; |
| 1775 | batteryStatus = o.batteryStatus; |
| 1776 | batteryHealth = o.batteryHealth; |
| 1777 | batteryPlugType = o.batteryPlugType; |
| 1778 | batteryTemperature = o.batteryTemperature; |
| 1779 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1780 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1781 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1782 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1783 | if (o.wakelockTag != null) { |
| 1784 | wakelockTag = localWakelockTag; |
| 1785 | wakelockTag.setTo(o.wakelockTag); |
| 1786 | } else { |
| 1787 | wakelockTag = null; |
| 1788 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1789 | if (o.wakeReasonTag != null) { |
| 1790 | wakeReasonTag = localWakeReasonTag; |
| 1791 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1792 | } else { |
| 1793 | wakeReasonTag = null; |
| 1794 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1795 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1796 | if (o.eventTag != null) { |
| 1797 | eventTag = localEventTag; |
| 1798 | eventTag.setTo(o.eventTag); |
| 1799 | } else { |
| 1800 | eventTag = null; |
| 1801 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1802 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1805 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1806 | return batteryLevel == o.batteryLevel |
| 1807 | && batteryStatus == o.batteryStatus |
| 1808 | && batteryHealth == o.batteryHealth |
| 1809 | && batteryPlugType == o.batteryPlugType |
| 1810 | && batteryTemperature == o.batteryTemperature |
| 1811 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1812 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1813 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1814 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1815 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1816 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1817 | |
| 1818 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1819 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1822 | if (wakelockTag != o.wakelockTag) { |
| 1823 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1824 | return false; |
| 1825 | } |
| 1826 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1827 | return false; |
| 1828 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1829 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1830 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1831 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1832 | return false; |
| 1833 | } |
| 1834 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1835 | return false; |
| 1836 | } |
| 1837 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1838 | if (eventTag != o.eventTag) { |
| 1839 | if (eventTag == null || o.eventTag == null) { |
| 1840 | return false; |
| 1841 | } |
| 1842 | if (!eventTag.equals(o.eventTag)) { |
| 1843 | return false; |
| 1844 | } |
| 1845 | } |
| 1846 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1847 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1848 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1849 | |
| 1850 | public final static class HistoryEventTracker { |
| 1851 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1852 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1853 | |
| 1854 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1855 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1856 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1857 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1858 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1859 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1860 | mActiveEvents[idx] = active; |
| 1861 | } |
| 1862 | SparseIntArray uids = active.get(name); |
| 1863 | if (uids == null) { |
| 1864 | uids = new SparseIntArray(); |
| 1865 | active.put(name, uids); |
| 1866 | } |
| 1867 | if (uids.indexOfKey(uid) >= 0) { |
| 1868 | // Already set, nothing to do! |
| 1869 | return false; |
| 1870 | } |
| 1871 | uids.put(uid, poolIdx); |
| 1872 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1873 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1874 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1875 | if (active == null) { |
| 1876 | // not currently active, nothing to do. |
| 1877 | return false; |
| 1878 | } |
| 1879 | SparseIntArray uids = active.get(name); |
| 1880 | if (uids == null) { |
| 1881 | // not currently active, nothing to do. |
| 1882 | return false; |
| 1883 | } |
| 1884 | idx = uids.indexOfKey(uid); |
| 1885 | if (idx < 0) { |
| 1886 | // not currently active, nothing to do. |
| 1887 | return false; |
| 1888 | } |
| 1889 | uids.removeAt(idx); |
| 1890 | if (uids.size() <= 0) { |
| 1891 | active.remove(name); |
| 1892 | } |
| 1893 | } |
| 1894 | return true; |
| 1895 | } |
| 1896 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1897 | public void removeEvents(int code) { |
| 1898 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1899 | mActiveEvents[idx] = null; |
| 1900 | } |
| 1901 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1902 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1903 | return mActiveEvents[code]; |
| 1904 | } |
| 1905 | } |
| 1906 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1907 | public static final class BitDescription { |
| 1908 | public final int mask; |
| 1909 | public final int shift; |
| 1910 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1911 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1912 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1913 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1914 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1915 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1916 | this.mask = mask; |
| 1917 | this.shift = -1; |
| 1918 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1919 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1920 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1921 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1922 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1923 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1924 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1925 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1926 | this.mask = mask; |
| 1927 | this.shift = shift; |
| 1928 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1929 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1930 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1931 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1932 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1933 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1934 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1935 | /** |
| 1936 | * Don't allow any more batching in to the current history event. This |
| 1937 | * is called when printing partial histories, so to ensure that the next |
| 1938 | * history event will go in to a new batch after what was printed in the |
| 1939 | * last partial history. |
| 1940 | */ |
| 1941 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1942 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1943 | public abstract int getHistoryTotalSize(); |
| 1944 | |
| 1945 | public abstract int getHistoryUsedSize(); |
| 1946 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1947 | public abstract boolean startIteratingHistoryLocked(); |
| 1948 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1949 | public abstract int getHistoryStringPoolSize(); |
| 1950 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1951 | public abstract int getHistoryStringPoolBytes(); |
| 1952 | |
| 1953 | public abstract String getHistoryTagPoolString(int index); |
| 1954 | |
| 1955 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1956 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1957 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1958 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1959 | public abstract void finishIteratingHistoryLocked(); |
| 1960 | |
| 1961 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1962 | |
| 1963 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1964 | |
| 1965 | public abstract void finishIteratingOldHistoryLocked(); |
| 1966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1968 | * Return the base time offset for the battery history. |
| 1969 | */ |
| 1970 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1972 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | * Returns the number of times the device has been started. |
| 1974 | */ |
| 1975 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1978 | * 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] | 1979 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1980 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | * {@hide} |
| 1982 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1983 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1984 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1985 | /** |
| 1986 | * Returns the number of times the screen was turned on. |
| 1987 | * |
| 1988 | * {@hide} |
| 1989 | */ |
| 1990 | public abstract int getScreenOnCount(int which); |
| 1991 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1992 | /** |
| 1993 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1994 | * running on battery. |
| 1995 | * |
| 1996 | * {@hide} |
| 1997 | */ |
| 1998 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1999 | |
| 2000 | /** |
| 2001 | * Returns the number of times the screen was turned dozing. |
| 2002 | * |
| 2003 | * {@hide} |
| 2004 | */ |
| 2005 | public abstract int getScreenDozeCount(int which); |
| 2006 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2007 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 2008 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2009 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 2010 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 2011 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 2012 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 2013 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2014 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2015 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 2016 | "dark", "dim", "medium", "light", "bright" |
| 2017 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2018 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2019 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 2020 | "0", "1", "2", "3", "4" |
| 2021 | }; |
| 2022 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2023 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2024 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2025 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2026 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2027 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2028 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2029 | * {@hide} |
| 2030 | */ |
| 2031 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2032 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2035 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2036 | * |
| 2037 | * {@hide} |
| 2038 | */ |
| 2039 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2040 | |
| 2041 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2042 | * 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] | 2043 | * running on battery. |
| 2044 | * |
| 2045 | * {@hide} |
| 2046 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2047 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2048 | |
| 2049 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2050 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2051 | * |
| 2052 | * {@hide} |
| 2053 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2054 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2055 | |
| 2056 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2057 | * Constant for device idle mode: not active. |
| 2058 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2059 | public static final int DEVICE_IDLE_MODE_OFF = ServerProtoEnums.DEVICE_IDLE_MODE_OFF; // 0 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2060 | |
| 2061 | /** |
| 2062 | * Constant for device idle mode: active in lightweight mode. |
| 2063 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2064 | public static final int DEVICE_IDLE_MODE_LIGHT = ServerProtoEnums.DEVICE_IDLE_MODE_LIGHT; // 1 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2065 | |
| 2066 | /** |
| 2067 | * Constant for device idle mode: active in full mode. |
| 2068 | */ |
Bookatz | 8bdae8d | 2018-01-16 11:24:30 -0800 | [diff] [blame] | 2069 | public static final int DEVICE_IDLE_MODE_DEEP = ServerProtoEnums.DEVICE_IDLE_MODE_DEEP; // 2 |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2070 | |
| 2071 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2072 | * Returns the time in microseconds that device has been in idle mode while |
| 2073 | * running on battery. |
| 2074 | * |
| 2075 | * {@hide} |
| 2076 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2077 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2078 | |
| 2079 | /** |
| 2080 | * Returns the number of times that the devie has gone in to idle mode. |
| 2081 | * |
| 2082 | * {@hide} |
| 2083 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2084 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2085 | |
| 2086 | /** |
| 2087 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2088 | * mode, not in idle maintenance etc). |
| 2089 | */ |
| 2090 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2091 | |
| 2092 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2093 | * 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] | 2094 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2095 | * counts all of the time that we consider the device to be idle, whether or not |
| 2096 | * it is currently in the actual device idle mode. |
| 2097 | * |
| 2098 | * {@hide} |
| 2099 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2100 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2101 | |
| 2102 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2103 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2104 | * |
| 2105 | * {@hide} |
| 2106 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2107 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2108 | |
| 2109 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2110 | * Returns the number of times that connectivity state changed. |
| 2111 | * |
| 2112 | * {@hide} |
| 2113 | */ |
| 2114 | public abstract int getNumConnectivityChange(int which); |
| 2115 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2116 | |
| 2117 | /** |
| 2118 | * Returns the time in microseconds that the phone has been running with |
| 2119 | * the given GPS signal quality level |
| 2120 | * |
| 2121 | * {@hide} |
| 2122 | */ |
| 2123 | public abstract long getGpsSignalQualityTime(int strengthBin, |
| 2124 | long elapsedRealtimeUs, int which); |
| 2125 | |
| 2126 | /** |
| 2127 | * Returns the GPS battery drain in mA-ms |
| 2128 | * |
| 2129 | * {@hide} |
| 2130 | */ |
| 2131 | public abstract long getGpsBatteryDrainMaMs(); |
| 2132 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2133 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2134 | * 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] | 2135 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2136 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | * {@hide} |
| 2138 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2139 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2140 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2141 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2142 | * Returns the number of times a phone call was activated. |
| 2143 | * |
| 2144 | * {@hide} |
| 2145 | */ |
| 2146 | public abstract int getPhoneOnCount(int which); |
| 2147 | |
| 2148 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2149 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2150 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2151 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2152 | * {@hide} |
| 2153 | */ |
| 2154 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2155 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2156 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2157 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2158 | * Returns the time in microseconds that the phone has been trying to |
| 2159 | * acquire a signal. |
| 2160 | * |
| 2161 | * {@hide} |
| 2162 | */ |
| 2163 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2164 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2165 | |
| 2166 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2167 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2168 | * acquire a signal. |
| 2169 | * |
| 2170 | * {@hide} |
| 2171 | */ |
| 2172 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2173 | |
| 2174 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2175 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2176 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2177 | * {@hide} |
| 2178 | */ |
| 2179 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2180 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2181 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2182 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2183 | * counts. |
| 2184 | */ |
| 2185 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2186 | |
| 2187 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2188 | * Returns the time in microseconds that the mobile network has been active |
| 2189 | * (in a high power state). |
| 2190 | * |
| 2191 | * {@hide} |
| 2192 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2193 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2194 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2195 | /** |
| 2196 | * Returns the number of times that the mobile network has transitioned to the |
| 2197 | * active state. |
| 2198 | * |
| 2199 | * {@hide} |
| 2200 | */ |
| 2201 | public abstract int getMobileRadioActiveCount(int which); |
| 2202 | |
| 2203 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2204 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2205 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2206 | * from the radio. |
| 2207 | * |
| 2208 | * {@hide} |
| 2209 | */ |
| 2210 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2211 | |
| 2212 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2213 | * Returns the time in microseconds that the mobile network has been active |
| 2214 | * (in a high power state) but not being able to blame on an app. |
| 2215 | * |
| 2216 | * {@hide} |
| 2217 | */ |
| 2218 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2219 | |
| 2220 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2221 | * 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] | 2222 | * |
| 2223 | * {@hide} |
| 2224 | */ |
| 2225 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2226 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2227 | public static final int DATA_CONNECTION_NONE = 0; |
| 2228 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2229 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2230 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2231 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2232 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2233 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2234 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2235 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2236 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2237 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2238 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2239 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2240 | public static final int DATA_CONNECTION_LTE = 13; |
| 2241 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2242 | public static final int DATA_CONNECTION_HSPAP = 15; |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame^] | 2243 | public static final int DATA_CONNECTION_GSM = 16; |
| 2244 | public static final int DATA_CONNECTION_TD_SCDMA = 17; |
| 2245 | public static final int DATA_CONNECTION_IWLAN = 18; |
| 2246 | public static final int DATA_CONNECTION_LTE_CA = 19; |
| 2247 | public static final int DATA_CONNECTION_OTHER = 20; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2248 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2249 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2250 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2251 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame^] | 2252 | "ehrpd", "hspap", "gsm", "td_scdma", "iwlan", "lte_ca", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2253 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2254 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2255 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2256 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2257 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2258 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2259 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2260 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2261 | * {@hide} |
| 2262 | */ |
| 2263 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2264 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2267 | * Returns the number of times the phone has entered the given data |
| 2268 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2269 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2270 | * {@hide} |
| 2271 | */ |
| 2272 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2273 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2274 | /** |
| 2275 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2276 | */ |
| 2277 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2278 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2279 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2280 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2281 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2282 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2283 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2284 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2285 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2286 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2287 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2288 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2289 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2290 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2291 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2292 | |
| 2293 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2294 | |
| 2295 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2296 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2297 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2298 | "group-handshake", "completed", "dormant", "uninit" |
| 2299 | }; |
| 2300 | |
| 2301 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2302 | "inv", "dsc", "dis", "inact", "scan", |
| 2303 | "auth", "ascing", "asced", "4-way", |
| 2304 | "group", "compl", "dorm", "uninit" |
| 2305 | }; |
| 2306 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2307 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2308 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2309 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2310 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2311 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2312 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2313 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2314 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2315 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2316 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2317 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2318 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2319 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2320 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2321 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2322 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2323 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2324 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2325 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2326 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2327 | new String[] {"in", "out", "emergency", "off"}, |
| 2328 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2329 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2330 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2331 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2332 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2333 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2334 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2335 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2336 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2337 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2338 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2339 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2340 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2341 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2342 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2343 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2344 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2345 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2346 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2347 | new String[] { "off", "light", "full", "???" }, |
| 2348 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2349 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2350 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2351 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2352 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2353 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2354 | new String[] { "0", "1", "2", "3", "4" }, |
| 2355 | new String[] { "0", "1", "2", "3", "4" }), |
| 2356 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2357 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2358 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2359 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2360 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2361 | new BitDescription(HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG, |
| 2362 | "cellular_high_tx_power", "Chtp"), |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 2363 | new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK, |
| 2364 | HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss", |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 2365 | new String[] { "poor", "good"}, new String[] { "poor", "good"}) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2366 | }; |
| 2367 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2368 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2369 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2370 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2371 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2372 | }; |
| 2373 | |
| 2374 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2375 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2376 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2377 | "Esw", "Ewa", "Elw", "Eec" |
| 2378 | }; |
| 2379 | |
| 2380 | @FunctionalInterface |
| 2381 | public interface IntToString { |
| 2382 | String applyAsString(int val); |
| 2383 | } |
| 2384 | |
| 2385 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2386 | private static final IntToString sIntToString = Integer::toString; |
| 2387 | |
| 2388 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2389 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2390 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2391 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2392 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2393 | }; |
| 2394 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2395 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2396 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2397 | * Note that this may be different from the sum of per uid timer values. |
| 2398 | * |
| 2399 | * {@hide} |
| 2400 | */ |
| 2401 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2402 | |
| 2403 | /** |
| 2404 | * Returns total time for WiFi Multicast Wakelock timer |
| 2405 | * Note that this may be different from the sum of per uid timer values. |
| 2406 | * |
| 2407 | * {@hide} |
| 2408 | */ |
| 2409 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2410 | |
| 2411 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2412 | * 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] | 2413 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2414 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2415 | * {@hide} |
| 2416 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2417 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2418 | |
| 2419 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2420 | * Returns the time in microseconds that wifi has been active while the device was |
| 2421 | * running on battery. |
| 2422 | * |
| 2423 | * {@hide} |
| 2424 | */ |
| 2425 | public abstract long getWifiActiveTime(long elapsedRealtimeUs, int which); |
| 2426 | |
| 2427 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2428 | * 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] | 2429 | * been in the running state while the device was running on battery. |
| 2430 | * |
| 2431 | * {@hide} |
| 2432 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2433 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2434 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2435 | public static final int WIFI_STATE_OFF = 0; |
| 2436 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2437 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2438 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2439 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2440 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2441 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2442 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2443 | |
| 2444 | static final String[] WIFI_STATE_NAMES = { |
| 2445 | "off", "scanning", "no_net", "disconn", |
| 2446 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2447 | }; |
| 2448 | |
| 2449 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2450 | |
| 2451 | /** |
| 2452 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2453 | * |
| 2454 | * {@hide} |
| 2455 | */ |
| 2456 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2457 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2458 | |
| 2459 | /** |
| 2460 | * Returns the number of times that WiFi has entered the given state. |
| 2461 | * |
| 2462 | * {@hide} |
| 2463 | */ |
| 2464 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2465 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2466 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2467 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2468 | * |
| 2469 | * {@hide} |
| 2470 | */ |
| 2471 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2472 | |
| 2473 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2474 | * Returns the time in microseconds that the wifi supplicant has been |
| 2475 | * in a given state. |
| 2476 | * |
| 2477 | * {@hide} |
| 2478 | */ |
| 2479 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2480 | |
| 2481 | /** |
| 2482 | * Returns the number of times that the wifi supplicant has transitioned |
| 2483 | * to a given state. |
| 2484 | * |
| 2485 | * {@hide} |
| 2486 | */ |
| 2487 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2488 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2489 | /** |
| 2490 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2491 | * |
| 2492 | * {@hide} |
| 2493 | */ |
| 2494 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2495 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2496 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2497 | |
| 2498 | /** |
| 2499 | * Returns the time in microseconds that WIFI has been running with |
| 2500 | * the given signal strength. |
| 2501 | * |
| 2502 | * {@hide} |
| 2503 | */ |
| 2504 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2505 | long elapsedRealtimeUs, int which); |
| 2506 | |
| 2507 | /** |
| 2508 | * Returns the number of times WIFI has entered the given signal strength. |
| 2509 | * |
| 2510 | * {@hide} |
| 2511 | */ |
| 2512 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2513 | |
| 2514 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2515 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2516 | * |
| 2517 | * {@hide} |
| 2518 | */ |
| 2519 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2520 | |
| 2521 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2522 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2523 | * running on battery. |
| 2524 | * |
| 2525 | * {@hide} |
| 2526 | */ |
| 2527 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2528 | |
| 2529 | /** |
| 2530 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2531 | * running on battery. |
| 2532 | * |
| 2533 | * {@hide} |
| 2534 | */ |
| 2535 | public abstract long getFlashlightOnCount(int which); |
| 2536 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2537 | /** |
| 2538 | * Returns the time in microseconds that the camera has been on while the device was |
| 2539 | * running on battery. |
| 2540 | * |
| 2541 | * {@hide} |
| 2542 | */ |
| 2543 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2544 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2545 | /** |
| 2546 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2547 | * on battery. |
| 2548 | * |
| 2549 | * {@hide} |
| 2550 | */ |
| 2551 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2552 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2553 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2554 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2555 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2556 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2557 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2558 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2559 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2560 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2561 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2562 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2563 | 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] | 2564 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2565 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2566 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2567 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2568 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2569 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2570 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2571 | * actual power data. |
| 2572 | */ |
| 2573 | public abstract boolean hasWifiActivityReporting(); |
| 2574 | |
| 2575 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2576 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2577 | * in various radio controller states, such as transmit, receive, and idle. |
| 2578 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2579 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2580 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2581 | |
| 2582 | /** |
| 2583 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2584 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2585 | * actual power data. |
| 2586 | */ |
| 2587 | public abstract boolean hasBluetoothActivityReporting(); |
| 2588 | |
| 2589 | /** |
| 2590 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2591 | * in various radio controller states, such as transmit, receive, and idle. |
| 2592 | * @return non-null {@link ControllerActivityCounter} |
| 2593 | */ |
| 2594 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2595 | |
| 2596 | /** |
| 2597 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2598 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2599 | * actual power data. |
| 2600 | */ |
| 2601 | public abstract boolean hasModemActivityReporting(); |
| 2602 | |
| 2603 | /** |
| 2604 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2605 | * in various radio controller states, such as transmit, receive, and idle. |
| 2606 | * @return non-null {@link ControllerActivityCounter} |
| 2607 | */ |
| 2608 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2609 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2610 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2611 | * Return the wall clock time when battery stats data collection started. |
| 2612 | */ |
| 2613 | public abstract long getStartClockTime(); |
| 2614 | |
| 2615 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2616 | * Return platform version tag that we were running in when the battery stats started. |
| 2617 | */ |
| 2618 | public abstract String getStartPlatformVersion(); |
| 2619 | |
| 2620 | /** |
| 2621 | * Return platform version tag that we were running in when the battery stats ended. |
| 2622 | */ |
| 2623 | public abstract String getEndPlatformVersion(); |
| 2624 | |
| 2625 | /** |
| 2626 | * Return the internal version code of the parcelled format. |
| 2627 | */ |
| 2628 | public abstract int getParcelVersion(); |
| 2629 | |
| 2630 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2631 | * Return whether we are currently running on battery. |
| 2632 | */ |
| 2633 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | /** |
| 2636 | * Returns a SparseArray containing the statistics for each uid. |
| 2637 | */ |
| 2638 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2639 | |
| 2640 | /** |
| 2641 | * Returns the current battery uptime in microseconds. |
| 2642 | * |
| 2643 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2644 | */ |
| 2645 | public abstract long getBatteryUptime(long curTime); |
| 2646 | |
| 2647 | /** |
| 2648 | * Returns the current battery realtime in microseconds. |
| 2649 | * |
| 2650 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2651 | */ |
| 2652 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2653 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2654 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2655 | * 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] | 2656 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2657 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2658 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2659 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2660 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2661 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2662 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2663 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2664 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | |
| 2666 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2667 | * Get the amount the battery has discharged since the stats were |
| 2668 | * last reset after charging, as a lower-end approximation. |
| 2669 | */ |
| 2670 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2671 | |
| 2672 | /** |
| 2673 | * Get the amount the battery has discharged since the stats were |
| 2674 | * last reset after charging, as an upper-end approximation. |
| 2675 | */ |
| 2676 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2677 | |
| 2678 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2679 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2680 | */ |
| 2681 | public abstract int getDischargeAmount(int which); |
| 2682 | |
| 2683 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2684 | * Get the amount the battery has discharged while the screen was on, |
| 2685 | * since the last time power was unplugged. |
| 2686 | */ |
| 2687 | public abstract int getDischargeAmountScreenOn(); |
| 2688 | |
| 2689 | /** |
| 2690 | * Get the amount the battery has discharged while the screen was on, |
| 2691 | * since the last time the device was charged. |
| 2692 | */ |
| 2693 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2694 | |
| 2695 | /** |
| 2696 | * Get the amount the battery has discharged while the screen was off, |
| 2697 | * since the last time power was unplugged. |
| 2698 | */ |
| 2699 | public abstract int getDischargeAmountScreenOff(); |
| 2700 | |
| 2701 | /** |
| 2702 | * Get the amount the battery has discharged while the screen was off, |
| 2703 | * since the last time the device was charged. |
| 2704 | */ |
| 2705 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2706 | |
| 2707 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2708 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2709 | * since the last time power was unplugged. |
| 2710 | */ |
| 2711 | public abstract int getDischargeAmountScreenDoze(); |
| 2712 | |
| 2713 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2714 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2715 | * since the last time the device was charged. |
| 2716 | */ |
| 2717 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2718 | |
| 2719 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | * Returns the total, last, or current battery uptime in microseconds. |
| 2721 | * |
| 2722 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2723 | * @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] | 2724 | */ |
| 2725 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2726 | |
| 2727 | /** |
| 2728 | * Returns the total, last, or current battery realtime in microseconds. |
| 2729 | * |
| 2730 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2731 | * @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] | 2732 | */ |
| 2733 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2734 | |
| 2735 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2736 | * 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] | 2737 | * |
| 2738 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2739 | * @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] | 2740 | */ |
| 2741 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2742 | |
| 2743 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2744 | * 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] | 2745 | * |
| 2746 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2747 | * @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] | 2748 | */ |
| 2749 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2750 | |
| 2751 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | * Returns the total, last, or current uptime in microseconds. |
| 2753 | * |
| 2754 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2755 | * @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] | 2756 | */ |
| 2757 | public abstract long computeUptime(long curTime, int which); |
| 2758 | |
| 2759 | /** |
| 2760 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2761 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2763 | * @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] | 2764 | */ |
| 2765 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2766 | |
| 2767 | /** |
| 2768 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2769 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2770 | * enough current data to make a decision, or the battery is currently |
| 2771 | * charging. |
| 2772 | * |
| 2773 | * @param curTime The current elepsed realtime in microseconds. |
| 2774 | */ |
| 2775 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2776 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2777 | // The part of a step duration that is the actual time. |
| 2778 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2779 | |
| 2780 | // Bits in a step duration that are the new battery level we are at. |
| 2781 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2782 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2783 | |
| 2784 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2785 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2786 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2787 | |
| 2788 | // Bits in a step duration that indicate which modes changed during that step. |
| 2789 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2790 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2791 | |
| 2792 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2793 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2794 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2795 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2796 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2797 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2798 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2799 | // Step duration mode: power save is on. |
| 2800 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2801 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2802 | // Step duration mode: device is currently in idle mode. |
| 2803 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2804 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2805 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2806 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2807 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2808 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2809 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2810 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2811 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2812 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2813 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2814 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2815 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2816 | }; |
| 2817 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2818 | (Display.STATE_OFF-1), |
| 2819 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2820 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2821 | (Display.STATE_ON-1), |
| 2822 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2823 | (Display.STATE_DOZE-1), |
| 2824 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2825 | (Display.STATE_DOZE_SUSPEND-1), |
| 2826 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2827 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2828 | }; |
| 2829 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2830 | "screen off", |
| 2831 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2832 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2833 | "screen on", |
| 2834 | "screen on power save", |
| 2835 | "screen doze", |
| 2836 | "screen doze power save", |
| 2837 | "screen doze-suspend", |
| 2838 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2839 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2840 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2841 | |
| 2842 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2843 | * 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] | 2844 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2845 | * a coulomb counter. |
| 2846 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2847 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2848 | |
| 2849 | /** |
| 2850 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2851 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2852 | * a coulomb counter. |
| 2853 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2854 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2855 | |
| 2856 | /** |
| 2857 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2858 | * non-zero only if the device's battery has a coulomb counter. |
| 2859 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2860 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2861 | |
| 2862 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2863 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2864 | * micro-Ampere-hours. |
| 2865 | */ |
| 2866 | public abstract long getUahDischargeLightDoze(int which); |
| 2867 | |
| 2868 | /** |
| 2869 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2870 | * micro-Ampere-hours. |
| 2871 | */ |
| 2872 | public abstract long getUahDischargeDeepDoze(int which); |
| 2873 | |
| 2874 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2875 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2876 | * declared by the PowerProfile. |
| 2877 | * @return The estimated battery capacity in mAh. |
| 2878 | */ |
| 2879 | public abstract int getEstimatedBatteryCapacity(); |
| 2880 | |
| 2881 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2882 | * @return The minimum learned battery capacity in uAh. |
| 2883 | */ |
| 2884 | public abstract int getMinLearnedBatteryCapacity(); |
| 2885 | |
| 2886 | /** |
| 2887 | * @return The maximum learned battery capacity in uAh. |
| 2888 | */ |
| 2889 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2890 | |
| 2891 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2892 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2893 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2894 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2895 | |
| 2896 | /** |
| 2897 | * Return the array of daily discharge step durations. |
| 2898 | */ |
| 2899 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2900 | |
| 2901 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2902 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2903 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2904 | * enough current data to make a decision, or the battery is currently |
| 2905 | * discharging. |
| 2906 | * |
| 2907 | * @param curTime The current elepsed realtime in microseconds. |
| 2908 | */ |
| 2909 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2910 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2911 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2912 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2913 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2914 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2915 | |
| 2916 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2917 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2918 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2919 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2920 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2921 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2922 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2923 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2924 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2925 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2927 | /** |
| 2928 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2929 | */ |
| 2930 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2931 | /** |
| 2932 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2933 | */ |
| 2934 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2935 | |
| 2936 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2937 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2938 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2939 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2940 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2941 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | long days = seconds / (60 * 60 * 24); |
| 2943 | if (days != 0) { |
| 2944 | out.append(days); |
| 2945 | out.append("d "); |
| 2946 | } |
| 2947 | long used = days * 60 * 60 * 24; |
| 2948 | |
| 2949 | long hours = (seconds - used) / (60 * 60); |
| 2950 | if (hours != 0 || used != 0) { |
| 2951 | out.append(hours); |
| 2952 | out.append("h "); |
| 2953 | } |
| 2954 | used += hours * 60 * 60; |
| 2955 | |
| 2956 | long mins = (seconds-used) / 60; |
| 2957 | if (mins != 0 || used != 0) { |
| 2958 | out.append(mins); |
| 2959 | out.append("m "); |
| 2960 | } |
| 2961 | used += mins * 60; |
| 2962 | |
| 2963 | if (seconds != 0 || used != 0) { |
| 2964 | out.append(seconds-used); |
| 2965 | out.append("s "); |
| 2966 | } |
| 2967 | } |
| 2968 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2969 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2971 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | sb.append(time - (sec * 1000)); |
| 2973 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | } |
| 2975 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2976 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2977 | long sec = time / 1000; |
| 2978 | formatTimeRaw(sb, sec); |
| 2979 | sb.append(time - (sec * 1000)); |
| 2980 | sb.append("ms"); |
| 2981 | } |
| 2982 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2983 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2984 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2985 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | } |
| 2987 | float perc = ((float)num) / ((float)den) * 100; |
| 2988 | mFormatBuilder.setLength(0); |
| 2989 | mFormatter.format("%.1f%%", perc); |
| 2990 | return mFormatBuilder.toString(); |
| 2991 | } |
| 2992 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2993 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2994 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2995 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2996 | if (bytes < BYTES_PER_KB) { |
| 2997 | return bytes + "B"; |
| 2998 | } else if (bytes < BYTES_PER_MB) { |
| 2999 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 3000 | return mFormatBuilder.toString(); |
| 3001 | } else if (bytes < BYTES_PER_GB){ |
| 3002 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 3003 | return mFormatBuilder.toString(); |
| 3004 | } else { |
| 3005 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 3006 | return mFormatBuilder.toString(); |
| 3007 | } |
| 3008 | } |
| 3009 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3010 | private static long roundUsToMs(long timeUs) { |
| 3011 | return (timeUs + 500) / 1000; |
| 3012 | } |
| 3013 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3014 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3015 | if (timer != null) { |
| 3016 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3017 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3018 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 3019 | return totalTimeMillis; |
| 3020 | } |
| 3021 | return 0; |
| 3022 | } |
| 3023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | /** |
| 3025 | * |
| 3026 | * @param sb a StringBuilder object. |
| 3027 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3028 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3030 | * @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] | 3031 | * @param linePrefix a String to be prepended to each line of output. |
| 3032 | * @return the line prefix |
| 3033 | */ |
| 3034 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3035 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3038 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3039 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3040 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | if (totalTimeMillis != 0) { |
| 3042 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3043 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3044 | if (name != null) { |
| 3045 | sb.append(name); |
| 3046 | sb.append(' '); |
| 3047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | sb.append('('); |
| 3049 | sb.append(count); |
| 3050 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3051 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 3052 | if (maxDurationMs >= 0) { |
| 3053 | sb.append(" max="); |
| 3054 | sb.append(maxDurationMs); |
| 3055 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3056 | // Put actual time if it is available and different from totalTimeMillis. |
| 3057 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 3058 | if (totalDurMs > totalTimeMillis) { |
| 3059 | sb.append(" actual="); |
| 3060 | sb.append(totalDurMs); |
| 3061 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3062 | if (timer.isRunningLocked()) { |
| 3063 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3064 | if (currentMs >= 0) { |
| 3065 | sb.append(" (running for "); |
| 3066 | sb.append(currentMs); |
| 3067 | sb.append("ms)"); |
| 3068 | } else { |
| 3069 | sb.append(" (running)"); |
| 3070 | } |
| 3071 | } |
| 3072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3073 | return ", "; |
| 3074 | } |
| 3075 | } |
| 3076 | return linePrefix; |
| 3077 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3078 | |
| 3079 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3080 | * 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] | 3081 | * |
| 3082 | * @param pw a PrintWriter object to print to. |
| 3083 | * @param sb a StringBuilder object. |
| 3084 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3085 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3086 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3087 | * @param prefix a String to be prepended to each line of output. |
| 3088 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3089 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3090 | */ |
| 3091 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3092 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3093 | if (timer != null) { |
| 3094 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3095 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3096 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3097 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3098 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3099 | sb.setLength(0); |
| 3100 | sb.append(prefix); |
| 3101 | sb.append(" "); |
| 3102 | sb.append(type); |
| 3103 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3104 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3105 | sb.append("realtime ("); |
| 3106 | sb.append(count); |
| 3107 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3108 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3109 | if (maxDurationMs >= 0) { |
| 3110 | sb.append(" max="); |
| 3111 | sb.append(maxDurationMs); |
| 3112 | } |
| 3113 | if (timer.isRunningLocked()) { |
| 3114 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3115 | if (currentMs >= 0) { |
| 3116 | sb.append(" (running for "); |
| 3117 | sb.append(currentMs); |
| 3118 | sb.append("ms)"); |
| 3119 | } else { |
| 3120 | sb.append(" (running)"); |
| 3121 | } |
| 3122 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3123 | pw.println(sb.toString()); |
| 3124 | return true; |
| 3125 | } |
| 3126 | } |
| 3127 | return false; |
| 3128 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | /** |
| 3131 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3132 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3133 | * @param sb a StringBuilder object. |
| 3134 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3135 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3137 | * @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] | 3138 | * @param linePrefix a String to be prepended to each line of output. |
| 3139 | * @return the line prefix |
| 3140 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3141 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3142 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | long totalTimeMicros = 0; |
| 3144 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3145 | long max = 0; |
| 3146 | long current = 0; |
| 3147 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3149 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3150 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3151 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3152 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3153 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3154 | } |
| 3155 | sb.append(linePrefix); |
| 3156 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3157 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3158 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3160 | sb.append(','); |
| 3161 | sb.append(current); |
| 3162 | sb.append(','); |
| 3163 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3164 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3165 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3166 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3167 | if (name != null) { |
| 3168 | sb.append(','); |
| 3169 | sb.append(totalDuration); |
| 3170 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | return ","; |
| 3172 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3173 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3174 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3175 | String type) { |
| 3176 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3177 | pw.print(','); |
| 3178 | pw.print(uid); |
| 3179 | pw.print(','); |
| 3180 | pw.print(category); |
| 3181 | pw.print(','); |
| 3182 | pw.print(type); |
| 3183 | } |
| 3184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | /** |
| 3186 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3187 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | * @param pw the PageWriter to dump log to |
| 3189 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3190 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3191 | * @param args type-dependent data arguments |
| 3192 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3193 | 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] | 3194 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3195 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3196 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3197 | pw.print(','); |
| 3198 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3200 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3202 | |
| 3203 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3204 | * Dump a given timer stat for terse checkin mode. |
| 3205 | * |
| 3206 | * @param pw the PageWriter to dump log to |
| 3207 | * @param uid the UID to log |
| 3208 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3209 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3210 | * @param timer a {@link Timer} to dump stats for |
| 3211 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3212 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3213 | */ |
| 3214 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3215 | Timer timer, long rawRealtime, int which) { |
| 3216 | if (timer != null) { |
| 3217 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3218 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3219 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3220 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3221 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3222 | } |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3227 | * Dump a given timer stat to the proto stream. |
| 3228 | * |
| 3229 | * @param proto the ProtoOutputStream to log to |
| 3230 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3231 | * @param timer a {@link Timer} to dump stats for |
| 3232 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3233 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3234 | */ |
| 3235 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3236 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3237 | if (timer == null) { |
| 3238 | return; |
| 3239 | } |
| 3240 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3241 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3242 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3243 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3244 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3245 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3246 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3247 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3248 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3249 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3250 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3251 | // These values will be -1 for timers that don't implement the functionality. |
| 3252 | if (maxDurationMs != -1) { |
| 3253 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3254 | } |
| 3255 | if (curDurationMs != -1) { |
| 3256 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3257 | } |
| 3258 | if (totalDurationMs != -1) { |
| 3259 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3260 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3261 | proto.end(token); |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3266 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3267 | */ |
| 3268 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3269 | if (counter == null) { |
| 3270 | return false; |
| 3271 | } |
| 3272 | |
| 3273 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3274 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3275 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3276 | return true; |
| 3277 | } |
| 3278 | |
| 3279 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3280 | if (c.getCountLocked(which) != 0) { |
| 3281 | return true; |
| 3282 | } |
| 3283 | } |
| 3284 | return false; |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3289 | * The order of the arguments in the final check in line is: |
| 3290 | * |
| 3291 | * idle, rx, power, tx... |
| 3292 | * |
| 3293 | * where tx... is one or more transmit level times. |
| 3294 | */ |
| 3295 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3296 | String type, |
| 3297 | ControllerActivityCounter counter, |
| 3298 | int which) { |
| 3299 | if (!controllerActivityHasData(counter, which)) { |
| 3300 | return; |
| 3301 | } |
| 3302 | |
| 3303 | dumpLineHeader(pw, uid, category, type); |
| 3304 | pw.print(","); |
| 3305 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3306 | pw.print(","); |
| 3307 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3308 | pw.print(","); |
| 3309 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3310 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3311 | pw.print(","); |
| 3312 | pw.print(c.getCountLocked(which)); |
| 3313 | } |
| 3314 | pw.println(); |
| 3315 | } |
| 3316 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3317 | /** |
| 3318 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3319 | */ |
| 3320 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3321 | ControllerActivityCounter counter, |
| 3322 | int which) { |
| 3323 | if (!controllerActivityHasData(counter, which)) { |
| 3324 | return; |
| 3325 | } |
| 3326 | |
| 3327 | final long cToken = proto.start(fieldId); |
| 3328 | |
| 3329 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3330 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3331 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3332 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3333 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3334 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3335 | |
| 3336 | long tToken; |
| 3337 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3338 | for (int i = 0; i < txCounters.length; ++i) { |
| 3339 | LongCounter c = txCounters[i]; |
| 3340 | tToken = proto.start(ControllerActivityProto.TX); |
| 3341 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3342 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3343 | proto.end(tToken); |
| 3344 | } |
| 3345 | |
| 3346 | proto.end(cToken); |
| 3347 | } |
| 3348 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3349 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3350 | String prefix, String controllerName, |
| 3351 | ControllerActivityCounter counter, |
| 3352 | int which) { |
| 3353 | if (controllerActivityHasData(counter, which)) { |
| 3354 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3359 | String controllerName, |
| 3360 | ControllerActivityCounter counter, int which) { |
| 3361 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3362 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3363 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3364 | // Battery real time |
| 3365 | final long totalControllerActivityTimeMs |
| 3366 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3367 | long totalTxTimeMs = 0; |
| 3368 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3369 | totalTxTimeMs += txState.getCountLocked(which); |
| 3370 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3371 | final long sleepTimeMs |
| 3372 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3373 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3374 | if (controllerName.equals(WIFI_CONTROLLER_NAME)) { |
| 3375 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 3376 | sb.setLength(0); |
| 3377 | sb.append(prefix); |
| 3378 | sb.append(" "); |
| 3379 | sb.append(controllerName); |
| 3380 | sb.append(" Scan time: "); |
| 3381 | formatTimeMs(sb, scanTimeMs); |
| 3382 | sb.append("("); |
| 3383 | sb.append(formatRatioLocked(scanTimeMs, totalControllerActivityTimeMs)); |
| 3384 | sb.append(")"); |
| 3385 | pw.println(sb.toString()); |
| 3386 | } |
| 3387 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3388 | sb.setLength(0); |
| 3389 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3390 | sb.append(" "); |
| 3391 | sb.append(controllerName); |
| 3392 | sb.append(" Sleep time: "); |
| 3393 | formatTimeMs(sb, sleepTimeMs); |
| 3394 | sb.append("("); |
| 3395 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3396 | sb.append(")"); |
| 3397 | pw.println(sb.toString()); |
| 3398 | |
| 3399 | sb.setLength(0); |
| 3400 | sb.append(prefix); |
| 3401 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3402 | sb.append(controllerName); |
| 3403 | sb.append(" Idle time: "); |
| 3404 | formatTimeMs(sb, idleTimeMs); |
| 3405 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3406 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3407 | sb.append(")"); |
| 3408 | pw.println(sb.toString()); |
| 3409 | |
| 3410 | sb.setLength(0); |
| 3411 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3412 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3413 | sb.append(controllerName); |
| 3414 | sb.append(" Rx time: "); |
| 3415 | formatTimeMs(sb, rxTimeMs); |
| 3416 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3417 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3418 | sb.append(")"); |
| 3419 | pw.println(sb.toString()); |
| 3420 | |
| 3421 | sb.setLength(0); |
| 3422 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3423 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3424 | sb.append(controllerName); |
| 3425 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3426 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3427 | String [] powerLevel; |
| 3428 | switch(controllerName) { |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3429 | case CELLULAR_CONTROLLER_NAME: |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3430 | powerLevel = new String[] { |
| 3431 | " less than 0dBm: ", |
| 3432 | " 0dBm to 8dBm: ", |
| 3433 | " 8dBm to 15dBm: ", |
| 3434 | " 15dBm to 20dBm: ", |
| 3435 | " above 20dBm: "}; |
| 3436 | break; |
| 3437 | default: |
| 3438 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3439 | break; |
| 3440 | } |
| 3441 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3442 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3443 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3444 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3445 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3446 | sb.setLength(0); |
| 3447 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3448 | sb.append(" "); |
| 3449 | sb.append(powerLevel[lvl]); |
| 3450 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3451 | formatTimeMs(sb, txLvlTimeMs); |
| 3452 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3453 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3454 | sb.append(")"); |
| 3455 | pw.println(sb.toString()); |
| 3456 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3457 | } else { |
| 3458 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3459 | formatTimeMs(sb, txLvlTimeMs); |
| 3460 | sb.append("("); |
| 3461 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3462 | sb.append(")"); |
| 3463 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3466 | if (powerDrainMaMs > 0) { |
| 3467 | sb.setLength(0); |
| 3468 | sb.append(prefix); |
| 3469 | sb.append(" "); |
| 3470 | sb.append(controllerName); |
| 3471 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3472 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3473 | sb.append("mAh"); |
| 3474 | pw.println(sb.toString()); |
| 3475 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3479 | * Temporary for settings. |
| 3480 | */ |
| 3481 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3482 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3483 | } |
| 3484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | /** |
| 3486 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3487 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3488 | * 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] | 3489 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3490 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3491 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3493 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3494 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3497 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3498 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3499 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3500 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3502 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3503 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3504 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3505 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3506 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3507 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3508 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3509 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3510 | rawRealtime, which); |
| 3511 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3512 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3513 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3514 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3515 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3516 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3517 | final long dischargeCount = getUahDischarge(which); |
| 3518 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3519 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3520 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3521 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3522 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3523 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3524 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3525 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3526 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3527 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3528 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3531 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3532 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3533 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3534 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3535 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3536 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3537 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3538 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3539 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3540 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3541 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3542 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3543 | long fullWakeLockTimeTotal = 0; |
| 3544 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3545 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3546 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3547 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3548 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3549 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3550 | = u.getWakelockStats(); |
| 3551 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3552 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3553 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3554 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3555 | if (fullWakeTimer != null) { |
| 3556 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3557 | which); |
| 3558 | } |
| 3559 | |
| 3560 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3561 | if (partialWakeTimer != null) { |
| 3562 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3563 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3567 | |
| 3568 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3569 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3570 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3571 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3572 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3573 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3574 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3575 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3576 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3577 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3578 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3579 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3580 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3581 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3582 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3583 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3584 | // Dump Modem controller stats |
| 3585 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3586 | getModemControllerActivity(), which); |
| 3587 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3588 | // Dump Wifi controller stats |
| 3589 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3590 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3591 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3592 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3593 | |
| 3594 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3595 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3596 | |
| 3597 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3598 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3599 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | // Dump misc stats |
| 3602 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3603 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3604 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3605 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3606 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3607 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3608 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3609 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3610 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3611 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3612 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3613 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3614 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3615 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3616 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3617 | // Dump screen brightness stats |
| 3618 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3619 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3620 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3621 | } |
| 3622 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3623 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3624 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3625 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3626 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3627 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3628 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3629 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3630 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3631 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3632 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3633 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3634 | } |
| 3635 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3636 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3637 | // Dump network type stats |
| 3638 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3639 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3640 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3641 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3642 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3643 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3644 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3645 | } |
| 3646 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3647 | |
| 3648 | // Dump wifi state stats |
| 3649 | args = new Object[NUM_WIFI_STATES]; |
| 3650 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3651 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3652 | } |
| 3653 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3654 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3655 | args[i] = getWifiStateCount(i, which); |
| 3656 | } |
| 3657 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3658 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3659 | // Dump wifi suppl state stats |
| 3660 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3661 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3662 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3663 | } |
| 3664 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3665 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3666 | args[i] = getWifiSupplStateCount(i, which); |
| 3667 | } |
| 3668 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3669 | |
| 3670 | // Dump wifi signal strength stats |
| 3671 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3672 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3673 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3674 | } |
| 3675 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3676 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3677 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3678 | } |
| 3679 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3680 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3681 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3682 | final long multicastWakeLockTimeTotalMicros = |
| 3683 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3684 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3685 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3686 | multicastWakeLockTimeTotalMicros / 1000, |
| 3687 | multicastWakeLockCountTotal); |
| 3688 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3689 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3690 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3691 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3692 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3693 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3694 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3695 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3696 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3697 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3698 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3699 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3700 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3701 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3702 | } else { |
| 3703 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3704 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3705 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3706 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3707 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3708 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3709 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3710 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3711 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3712 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3713 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3714 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3715 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3716 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3717 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3718 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3719 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3720 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3721 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3722 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3723 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3724 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3725 | // Not doing the regular wake lock formatting to remain compatible |
| 3726 | // with the old checkin format. |
| 3727 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3728 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3729 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3730 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3731 | } |
| 3732 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3733 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3734 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3735 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3736 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3737 | if (rpmStats.size() > 0) { |
| 3738 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3739 | sb.setLength(0); |
| 3740 | Timer totalTimer = ent.getValue(); |
| 3741 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3742 | int count = totalTimer.getCountLocked(which); |
| 3743 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3744 | long screenOffTimeMs = screenOffTimer != null |
| 3745 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3746 | int screenOffCount = screenOffTimer != null |
| 3747 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3748 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3749 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3750 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3751 | screenOffCount); |
| 3752 | } else { |
| 3753 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3754 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3755 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3759 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3760 | helper.create(this); |
| 3761 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3762 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3763 | if (sippers != null && sippers.size() > 0) { |
| 3764 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3765 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3766 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3767 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3768 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3769 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3770 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3771 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3772 | String label; |
| 3773 | switch (bs.drainType) { |
| 3774 | case IDLE: |
| 3775 | label="idle"; |
| 3776 | break; |
| 3777 | case CELL: |
| 3778 | label="cell"; |
| 3779 | break; |
| 3780 | case PHONE: |
| 3781 | label="phone"; |
| 3782 | break; |
| 3783 | case WIFI: |
| 3784 | label="wifi"; |
| 3785 | break; |
| 3786 | case BLUETOOTH: |
| 3787 | label="blue"; |
| 3788 | break; |
| 3789 | case SCREEN: |
| 3790 | label="scrn"; |
| 3791 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3792 | case FLASHLIGHT: |
| 3793 | label="flashlight"; |
| 3794 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3795 | case APP: |
| 3796 | uid = bs.uidObj.getUid(); |
| 3797 | label = "uid"; |
| 3798 | break; |
| 3799 | case USER: |
| 3800 | uid = UserHandle.getUid(bs.userId, 0); |
| 3801 | label = "user"; |
| 3802 | break; |
| 3803 | case UNACCOUNTED: |
| 3804 | label = "unacc"; |
| 3805 | break; |
| 3806 | case OVERCOUNTED: |
| 3807 | label = "over"; |
| 3808 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3809 | case CAMERA: |
| 3810 | label = "camera"; |
| 3811 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3812 | case MEMORY: |
| 3813 | label = "memory"; |
| 3814 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3815 | default: |
| 3816 | label = "???"; |
| 3817 | } |
| 3818 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3819 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3820 | bs.shouldHide ? 1 : 0, |
| 3821 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3822 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3826 | final long[] cpuFreqs = getCpuFreqs(); |
| 3827 | if (cpuFreqs != null) { |
| 3828 | sb.setLength(0); |
| 3829 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3830 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3831 | } |
| 3832 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3833 | } |
| 3834 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3835 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | for (int iu = 0; iu < NU; iu++) { |
| 3837 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3838 | if (reqUid >= 0 && uid != reqUid) { |
| 3839 | continue; |
| 3840 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3841 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3844 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3845 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3846 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3847 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3848 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3849 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3850 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3851 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3852 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3853 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3854 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3855 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3856 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3857 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3858 | // Background data transfers |
| 3859 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3860 | which); |
| 3861 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3862 | which); |
| 3863 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3864 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3865 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3866 | which); |
| 3867 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3868 | which); |
| 3869 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3870 | which); |
| 3871 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3872 | which); |
| 3873 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3874 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3875 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3876 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3877 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3878 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3879 | || wifiBytesBgTx > 0 |
| 3880 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3881 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3882 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3883 | wifiBytesRx, wifiBytesTx, |
| 3884 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3885 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3886 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3887 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3888 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3889 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3890 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3893 | // Dump modem controller data, per UID. |
| 3894 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3895 | u.getModemControllerActivity(), which); |
| 3896 | |
| 3897 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3898 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3899 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3900 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3901 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3902 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3903 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3904 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3905 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3906 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3907 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3908 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3909 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3910 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3911 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3912 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3913 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3916 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3917 | u.getWifiControllerActivity(), which); |
| 3918 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3919 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3920 | if (bleTimer != null) { |
| 3921 | // Convert from microseconds to milliseconds with rounding |
| 3922 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3923 | / 1000; |
| 3924 | if (totalTime != 0) { |
| 3925 | final int count = bleTimer.getCountLocked(which); |
| 3926 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3927 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3928 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3929 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3930 | final long actualTimeBg = bleTimerBg != null ? |
| 3931 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3932 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3933 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3934 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3935 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3936 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3937 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3938 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3939 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3940 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3941 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3942 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3943 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3944 | final Timer unoptimizedScanTimerBg = |
| 3945 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3946 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3947 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3948 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3949 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3950 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3951 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3952 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3953 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3954 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3955 | } |
| 3956 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3957 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3958 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3959 | u.getBluetoothControllerActivity(), which); |
| 3960 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3961 | if (u.hasUserActivity()) { |
| 3962 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3963 | boolean hasData = false; |
| 3964 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3965 | int val = u.getUserActivityCount(i, which); |
| 3966 | args[i] = val; |
| 3967 | if (val != 0) hasData = true; |
| 3968 | } |
| 3969 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3970 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3971 | } |
| 3972 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3973 | |
| 3974 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3975 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3976 | // Times are since reset (regardless of 'which') |
| 3977 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3978 | final Timer bgTimer = timer.getSubTimer(); |
| 3979 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3980 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3981 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3982 | } |
| 3983 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3984 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3985 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3986 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3987 | String linePrefix = ""; |
| 3988 | sb.setLength(0); |
| 3989 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3990 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3991 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3992 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3993 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3994 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3995 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3996 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3997 | rawRealtime, "w", which, linePrefix); |
| 3998 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3999 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4000 | if (sb.length() > 0) { |
| 4001 | String name = wakelocks.keyAt(iw); |
| 4002 | if (name.indexOf(',') >= 0) { |
| 4003 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 4005 | if (name.indexOf('\n') >= 0) { |
| 4006 | name = name.replace('\n', '_'); |
| 4007 | } |
| 4008 | if (name.indexOf('\r') >= 0) { |
| 4009 | name = name.replace('\r', '_'); |
| 4010 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4011 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | } |
| 4013 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4014 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4015 | // WiFi Multicast Wakelock Statistics |
| 4016 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 4017 | if (mcTimer != null) { |
| 4018 | final long totalMcWakelockTimeMs = |
| 4019 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 4020 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 4021 | if(totalMcWakelockTimeMs > 0) { |
| 4022 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 4023 | totalMcWakelockTimeMs, countMcWakelock); |
| 4024 | } |
| 4025 | } |
| 4026 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4027 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4028 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4029 | final Timer timer = syncs.valueAt(isy); |
| 4030 | // Convert from microseconds to milliseconds with rounding |
| 4031 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4032 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4033 | final Timer bgTimer = timer.getSubTimer(); |
| 4034 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4035 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4036 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4037 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4038 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4039 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4040 | } |
| 4041 | } |
| 4042 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4043 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4044 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4045 | final Timer timer = jobs.valueAt(ij); |
| 4046 | // Convert from microseconds to milliseconds with rounding |
| 4047 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4048 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4049 | final Timer bgTimer = timer.getSubTimer(); |
| 4050 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4051 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4052 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4053 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4054 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4055 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4059 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 4060 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 4061 | SparseIntArray types = completions.valueAt(ic); |
| 4062 | if (types != null) { |
| 4063 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 4064 | "\"" + completions.keyAt(ic) + "\"", |
| 4065 | types.get(JobParameters.REASON_CANCELED, 0), |
| 4066 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 4067 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 4068 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 4069 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 4070 | } |
| 4071 | } |
| 4072 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4073 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 4074 | rawRealtime, which); |
| 4075 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4076 | rawRealtime, which); |
| 4077 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4078 | rawRealtime, which); |
| 4079 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4080 | rawRealtime, which); |
| 4081 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4082 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4083 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4084 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4085 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4086 | final int sensorNumber = sensors.keyAt(ise); |
| 4087 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4088 | if (timer != null) { |
| 4089 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4090 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4091 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4092 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4093 | final int count = timer.getCountLocked(which); |
| 4094 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4095 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4096 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4097 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4098 | final long bgActualTime = bgTimer != null ? |
| 4099 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4100 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4101 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4106 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4107 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4108 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4109 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4110 | rawRealtime, which); |
| 4111 | |
| 4112 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4113 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4114 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4115 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4116 | long totalStateTime = 0; |
| 4117 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4118 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4119 | totalStateTime += time; |
| 4120 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4121 | } |
| 4122 | if (totalStateTime > 0) { |
| 4123 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4124 | } |
| 4125 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4126 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4127 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4128 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4129 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4130 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4131 | } |
| 4132 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4133 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4134 | if (cpuFreqs != null) { |
| 4135 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4136 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4137 | // screenOffCpuFreqTimes. |
| 4138 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4139 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4140 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4141 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4142 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4143 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4144 | if (screenOffCpuFreqTimeMs != null) { |
| 4145 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4146 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4147 | } |
| 4148 | } else { |
| 4149 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4150 | sb.append(",0"); |
| 4151 | } |
| 4152 | } |
| 4153 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4154 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4155 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4156 | |
| 4157 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4158 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4159 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4160 | sb.setLength(0); |
| 4161 | for (int i = 0; i < timesMs.length; ++i) { |
| 4162 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4163 | } |
| 4164 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4165 | which, procState); |
| 4166 | if (screenOffTimesMs != null) { |
| 4167 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4168 | sb.append("," + screenOffTimesMs[i]); |
| 4169 | } |
| 4170 | } else { |
| 4171 | for (int i = 0; i < timesMs.length; ++i) { |
| 4172 | sb.append(",0"); |
| 4173 | } |
| 4174 | } |
| 4175 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4176 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4177 | } |
| 4178 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4181 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4182 | = u.getProcessStats(); |
| 4183 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4184 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4185 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4186 | final long userMillis = ps.getUserTime(which); |
| 4187 | final long systemMillis = ps.getSystemTime(which); |
| 4188 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4189 | final int starts = ps.getStarts(which); |
| 4190 | final int numCrashes = ps.getNumCrashes(which); |
| 4191 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4192 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4193 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4194 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4195 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4196 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | } |
| 4198 | } |
| 4199 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4200 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4201 | = u.getPackageStats(); |
| 4202 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4203 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4204 | int wakeups = 0; |
| 4205 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4206 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4207 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4208 | wakeups += count; |
| 4209 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4210 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4211 | } |
| 4212 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4213 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4214 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4215 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4216 | final int starts = ss.getStarts(which); |
| 4217 | final int launches = ss.getLaunches(which); |
| 4218 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4219 | dumpLine(pw, uid, category, APK_DATA, |
| 4220 | wakeups, // wakeup alarms |
| 4221 | packageStats.keyAt(ipkg), // Apk |
| 4222 | serviceStats.keyAt(isvc), // service |
| 4223 | startTime / 1000, // time spent started, in ms |
| 4224 | starts, |
| 4225 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | } |
| 4231 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4232 | static final class TimerEntry { |
| 4233 | final String mName; |
| 4234 | final int mId; |
| 4235 | final BatteryStats.Timer mTimer; |
| 4236 | final long mTime; |
| 4237 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4238 | mName = name; |
| 4239 | mId = id; |
| 4240 | mTimer = timer; |
| 4241 | mTime = time; |
| 4242 | } |
| 4243 | } |
| 4244 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4245 | private void printmAh(PrintWriter printer, double power) { |
| 4246 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4247 | } |
| 4248 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4249 | private void printmAh(StringBuilder sb, double power) { |
| 4250 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4251 | } |
| 4252 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4253 | /** |
| 4254 | * Temporary for settings. |
| 4255 | */ |
| 4256 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4257 | int reqUid) { |
| 4258 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4259 | } |
| 4260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4262 | 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] | 4263 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4264 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4265 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4266 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | |
| 4269 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4270 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4271 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4272 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4273 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4274 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4275 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4276 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4277 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4278 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4279 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4280 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4281 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4282 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4283 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4285 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4286 | if (estimatedBatteryCapacity > 0) { |
| 4287 | sb.setLength(0); |
| 4288 | sb.append(prefix); |
| 4289 | sb.append(" Estimated battery capacity: "); |
| 4290 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4291 | sb.append(" mAh"); |
| 4292 | pw.println(sb.toString()); |
| 4293 | } |
| 4294 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4295 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4296 | if (minLearnedBatteryCapacity > 0) { |
| 4297 | sb.setLength(0); |
| 4298 | sb.append(prefix); |
| 4299 | sb.append(" Min learned battery capacity: "); |
| 4300 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4301 | sb.append(" mAh"); |
| 4302 | pw.println(sb.toString()); |
| 4303 | } |
| 4304 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4305 | if (maxLearnedBatteryCapacity > 0) { |
| 4306 | sb.setLength(0); |
| 4307 | sb.append(prefix); |
| 4308 | sb.append(" Max learned battery capacity: "); |
| 4309 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4310 | sb.append(" mAh"); |
| 4311 | pw.println(sb.toString()); |
| 4312 | } |
| 4313 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4314 | sb.setLength(0); |
| 4315 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4316 | sb.append(" Time on battery: "); |
| 4317 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4318 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4319 | sb.append(") realtime, "); |
| 4320 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4321 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4322 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4323 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4324 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4325 | sb.setLength(0); |
| 4326 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4327 | sb.append(" Time on battery screen off: "); |
| 4328 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4329 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4330 | sb.append(") realtime, "); |
| 4331 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4332 | sb.append("("); |
| 4333 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4334 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4335 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4336 | |
| 4337 | sb.setLength(0); |
| 4338 | sb.append(prefix); |
| 4339 | sb.append(" Time on battery screen doze: "); |
| 4340 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4341 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4342 | sb.append(")"); |
| 4343 | pw.println(sb.toString()); |
| 4344 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4345 | sb.setLength(0); |
| 4346 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4347 | sb.append(" Total run time: "); |
| 4348 | formatTimeMs(sb, totalRealtime / 1000); |
| 4349 | sb.append("realtime, "); |
| 4350 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4351 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4352 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4353 | if (batteryTimeRemaining >= 0) { |
| 4354 | sb.setLength(0); |
| 4355 | sb.append(prefix); |
| 4356 | sb.append(" Battery time remaining: "); |
| 4357 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4358 | pw.println(sb.toString()); |
| 4359 | } |
| 4360 | if (chargeTimeRemaining >= 0) { |
| 4361 | sb.setLength(0); |
| 4362 | sb.append(prefix); |
| 4363 | sb.append(" Charge time remaining: "); |
| 4364 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4365 | pw.println(sb.toString()); |
| 4366 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4367 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4368 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4369 | if (dischargeCount >= 0) { |
| 4370 | sb.setLength(0); |
| 4371 | sb.append(prefix); |
| 4372 | sb.append(" Discharge: "); |
| 4373 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4374 | sb.append(" mAh"); |
| 4375 | pw.println(sb.toString()); |
| 4376 | } |
| 4377 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4378 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4379 | if (dischargeScreenOffCount >= 0) { |
| 4380 | sb.setLength(0); |
| 4381 | sb.append(prefix); |
| 4382 | sb.append(" Screen off discharge: "); |
| 4383 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4384 | sb.append(" mAh"); |
| 4385 | pw.println(sb.toString()); |
| 4386 | } |
| 4387 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4388 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4389 | if (dischargeScreenDozeCount >= 0) { |
| 4390 | sb.setLength(0); |
| 4391 | sb.append(prefix); |
| 4392 | sb.append(" Screen doze discharge: "); |
| 4393 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4394 | sb.append(" mAh"); |
| 4395 | pw.println(sb.toString()); |
| 4396 | } |
| 4397 | |
| 4398 | final long dischargeScreenOnCount = |
| 4399 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4400 | if (dischargeScreenOnCount >= 0) { |
| 4401 | sb.setLength(0); |
| 4402 | sb.append(prefix); |
| 4403 | sb.append(" Screen on discharge: "); |
| 4404 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4405 | sb.append(" mAh"); |
| 4406 | pw.println(sb.toString()); |
| 4407 | } |
| 4408 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4409 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4410 | if (dischargeLightDozeCount >= 0) { |
| 4411 | sb.setLength(0); |
| 4412 | sb.append(prefix); |
| 4413 | sb.append(" Device light doze discharge: "); |
| 4414 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4415 | sb.append(" mAh"); |
| 4416 | pw.println(sb.toString()); |
| 4417 | } |
| 4418 | |
| 4419 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4420 | if (dischargeDeepDozeCount >= 0) { |
| 4421 | sb.setLength(0); |
| 4422 | sb.append(prefix); |
| 4423 | sb.append(" Device deep doze discharge: "); |
| 4424 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4425 | sb.append(" mAh"); |
| 4426 | pw.println(sb.toString()); |
| 4427 | } |
| 4428 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4429 | pw.print(" Start clock time: "); |
| 4430 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4431 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4432 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4433 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4434 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4435 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4436 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4437 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4438 | rawRealtime, which); |
| 4439 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4440 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4441 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4442 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4443 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4444 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4445 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4446 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4447 | sb.append(prefix); |
| 4448 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4449 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4450 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4451 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4452 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4453 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4454 | pw.println(sb.toString()); |
| 4455 | sb.setLength(0); |
| 4456 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4457 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4458 | boolean didOne = false; |
| 4459 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4460 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4461 | if (time == 0) { |
| 4462 | continue; |
| 4463 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4464 | sb.append("\n "); |
| 4465 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4466 | didOne = true; |
| 4467 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4468 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4469 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4470 | sb.append("("); |
| 4471 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4472 | sb.append(")"); |
| 4473 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4474 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4475 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4476 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4477 | sb.setLength(0); |
| 4478 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4479 | sb.append(" Power save mode enabled: "); |
| 4480 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4481 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4482 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4483 | sb.append(")"); |
| 4484 | pw.println(sb.toString()); |
| 4485 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4486 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4487 | sb.setLength(0); |
| 4488 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4489 | sb.append(" Device light idling: "); |
| 4490 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4491 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4492 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4493 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4494 | sb.append("x"); |
| 4495 | pw.println(sb.toString()); |
| 4496 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4497 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4498 | sb.setLength(0); |
| 4499 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4500 | sb.append(" Idle mode light time: "); |
| 4501 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4502 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4503 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4504 | sb.append(") "); |
| 4505 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4506 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4507 | sb.append(" -- longest "); |
| 4508 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4509 | pw.println(sb.toString()); |
| 4510 | } |
| 4511 | if (deviceIdlingTime != 0) { |
| 4512 | sb.setLength(0); |
| 4513 | sb.append(prefix); |
| 4514 | sb.append(" Device full idling: "); |
| 4515 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4516 | sb.append("("); |
| 4517 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4518 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4519 | sb.append("x"); |
| 4520 | pw.println(sb.toString()); |
| 4521 | } |
| 4522 | if (deviceIdleModeFullTime != 0) { |
| 4523 | sb.setLength(0); |
| 4524 | sb.append(prefix); |
| 4525 | sb.append(" Idle mode full time: "); |
| 4526 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4527 | sb.append("("); |
| 4528 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4529 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4530 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4531 | sb.append("x"); |
| 4532 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4533 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4534 | pw.println(sb.toString()); |
| 4535 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4536 | if (phoneOnTime != 0) { |
| 4537 | sb.setLength(0); |
| 4538 | sb.append(prefix); |
| 4539 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4540 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4541 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4542 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4543 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4544 | if (connChanges != 0) { |
| 4545 | pw.print(prefix); |
| 4546 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4547 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4548 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4549 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4550 | long fullWakeLockTimeTotalMicros = 0; |
| 4551 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4552 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4553 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4554 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4555 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4556 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4557 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4558 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4559 | = u.getWakelockStats(); |
| 4560 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4561 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4562 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4563 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4564 | if (fullWakeTimer != null) { |
| 4565 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4566 | rawRealtime, which); |
| 4567 | } |
| 4568 | |
| 4569 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4570 | if (partialWakeTimer != null) { |
| 4571 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4572 | rawRealtime, which); |
| 4573 | if (totalTimeMicros > 0) { |
| 4574 | if (reqUid < 0) { |
| 4575 | // Only show the ordered list of all wake |
| 4576 | // locks if the caller is not asking for data |
| 4577 | // about a specific uid. |
| 4578 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4579 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4580 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4581 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | } |
| 4585 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4586 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4587 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4588 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4589 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4590 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4591 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4592 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4593 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4594 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4595 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4596 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4597 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4598 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4599 | sb.setLength(0); |
| 4600 | sb.append(prefix); |
| 4601 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4602 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4603 | pw.println(sb.toString()); |
| 4604 | } |
| 4605 | |
| 4606 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4607 | sb.setLength(0); |
| 4608 | sb.append(prefix); |
| 4609 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4610 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4611 | pw.println(sb.toString()); |
| 4612 | } |
| 4613 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4614 | final long multicastWakeLockTimeTotalMicros = |
| 4615 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4616 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4617 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4618 | sb.setLength(0); |
| 4619 | sb.append(prefix); |
| 4620 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4621 | sb.append(multicastWakeLockCountTotal); |
| 4622 | pw.println(sb.toString()); |
| 4623 | |
| 4624 | sb.setLength(0); |
| 4625 | sb.append(prefix); |
| 4626 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4627 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4628 | pw.println(sb.toString()); |
| 4629 | } |
| 4630 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4631 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4632 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4633 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4634 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4635 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4636 | pw.println(sb.toString()); |
| 4637 | |
| 4638 | pw.print(prefix); |
| 4639 | sb.setLength(0); |
| 4640 | sb.append(prefix); |
| 4641 | sb.append(" Logging duration for connectivity statistics: "); |
| 4642 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4643 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4644 | |
| 4645 | sb.setLength(0); |
| 4646 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4647 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4648 | pw.println(sb.toString()); |
| 4649 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4650 | pw.print(prefix); |
| 4651 | sb.setLength(0); |
| 4652 | sb.append(prefix); |
| 4653 | sb.append(" Cellular kernel active time: "); |
| 4654 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4655 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4656 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4657 | sb.append(")"); |
| 4658 | pw.println(sb.toString()); |
| 4659 | |
| 4660 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4661 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4662 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4663 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4664 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4665 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4666 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4667 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4668 | didOne = false; |
| 4669 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4670 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4671 | if (time == 0) { |
| 4672 | continue; |
| 4673 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4674 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4675 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4676 | didOne = true; |
| 4677 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4678 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4679 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4680 | sb.append("("); |
| 4681 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4682 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4683 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4684 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4685 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4686 | |
| 4687 | sb.setLength(0); |
| 4688 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4689 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4690 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4691 | "very poor (less than -128dBm): ", |
| 4692 | "poor (-128dBm to -118dBm): ", |
| 4693 | "moderate (-118dBm to -108dBm): ", |
| 4694 | "good (-108dBm to -98dBm): ", |
| 4695 | "great (greater than -98dBm): "}; |
| 4696 | didOne = false; |
| 4697 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4698 | cellularRxSignalStrengthDescription.length); |
| 4699 | for (int i=0; i<numCellularRxBins; i++) { |
| 4700 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4701 | if (time == 0) { |
| 4702 | continue; |
| 4703 | } |
| 4704 | sb.append("\n "); |
| 4705 | sb.append(prefix); |
| 4706 | didOne = true; |
| 4707 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4708 | sb.append(" "); |
| 4709 | formatTimeMs(sb, time/1000); |
| 4710 | sb.append("("); |
| 4711 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4712 | sb.append(") "); |
| 4713 | } |
| 4714 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4715 | pw.println(sb.toString()); |
| 4716 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4717 | printControllerActivity(pw, sb, prefix, CELLULAR_CONTROLLER_NAME, |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4718 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4719 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4720 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4721 | sb.setLength(0); |
| 4722 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4723 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4724 | pw.println(sb.toString()); |
| 4725 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4726 | pw.print(prefix); |
| 4727 | sb.setLength(0); |
| 4728 | sb.append(prefix); |
| 4729 | sb.append(" Wifi kernel active time: "); |
| 4730 | final long wifiActiveTime = getWifiActiveTime(rawRealtime, which); |
| 4731 | formatTimeMs(sb, wifiActiveTime / 1000); |
| 4732 | sb.append("("); sb.append(formatRatioLocked(wifiActiveTime, whichBatteryRealtime)); |
| 4733 | sb.append(")"); |
| 4734 | pw.println(sb.toString()); |
| 4735 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4736 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4737 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4738 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4739 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4740 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4741 | sb.setLength(0); |
| 4742 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4743 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4744 | didOne = false; |
| 4745 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4746 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4747 | if (time == 0) { |
| 4748 | continue; |
| 4749 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4750 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4751 | didOne = true; |
| 4752 | sb.append(WIFI_STATE_NAMES[i]); |
| 4753 | sb.append(" "); |
| 4754 | formatTimeMs(sb, time/1000); |
| 4755 | sb.append("("); |
| 4756 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4757 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4758 | } |
| 4759 | if (!didOne) sb.append(" (no activity)"); |
| 4760 | pw.println(sb.toString()); |
| 4761 | |
| 4762 | sb.setLength(0); |
| 4763 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4764 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4765 | didOne = false; |
| 4766 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4767 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4768 | if (time == 0) { |
| 4769 | continue; |
| 4770 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4771 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4772 | didOne = true; |
| 4773 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4774 | sb.append(" "); |
| 4775 | formatTimeMs(sb, time/1000); |
| 4776 | sb.append("("); |
| 4777 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4778 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4779 | } |
| 4780 | if (!didOne) sb.append(" (no activity)"); |
| 4781 | pw.println(sb.toString()); |
| 4782 | |
| 4783 | sb.setLength(0); |
| 4784 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4785 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4786 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4787 | "very poor (less than -88.75dBm): ", |
| 4788 | "poor (-88.75 to -77.5dBm): ", |
| 4789 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4790 | "good (-66.25dBm to -55dBm): ", |
| 4791 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4792 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4793 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4794 | wifiRxSignalStrengthDescription.length); |
| 4795 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4796 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4797 | if (time == 0) { |
| 4798 | continue; |
| 4799 | } |
| 4800 | sb.append("\n "); |
| 4801 | sb.append(prefix); |
| 4802 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4803 | sb.append(" "); |
| 4804 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4805 | formatTimeMs(sb, time/1000); |
| 4806 | sb.append("("); |
| 4807 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4808 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4809 | } |
| 4810 | if (!didOne) sb.append(" (no activity)"); |
| 4811 | pw.println(sb.toString()); |
| 4812 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 4813 | printControllerActivity(pw, sb, prefix, WIFI_CONTROLLER_NAME, |
| 4814 | getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4815 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4816 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4817 | sb.setLength(0); |
| 4818 | sb.append(prefix); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4819 | sb.append(" GPS Statistics:"); |
| 4820 | pw.println(sb.toString()); |
| 4821 | |
| 4822 | sb.setLength(0); |
| 4823 | sb.append(prefix); |
| 4824 | sb.append(" GPS signal quality (Top 4 Average CN0):"); |
| 4825 | final String[] gpsSignalQualityDescription = new String[]{ |
| 4826 | "poor (less than 20 dBHz): ", |
| 4827 | "good (greater than 20 dBHz): "}; |
| 4828 | final int numGpsSignalQualityBins = Math.min(GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS, |
| 4829 | gpsSignalQualityDescription.length); |
| 4830 | for (int i=0; i<numGpsSignalQualityBins; i++) { |
| 4831 | final long time = getGpsSignalQualityTime(i, rawRealtime, which); |
| 4832 | sb.append("\n "); |
| 4833 | sb.append(prefix); |
| 4834 | sb.append(" "); |
| 4835 | sb.append(gpsSignalQualityDescription[i]); |
| 4836 | formatTimeMs(sb, time/1000); |
| 4837 | sb.append("("); |
| 4838 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4839 | sb.append(") "); |
| 4840 | } |
| 4841 | pw.println(sb.toString()); |
| 4842 | |
| 4843 | final long gpsBatteryDrainMaMs = getGpsBatteryDrainMaMs(); |
| 4844 | if (gpsBatteryDrainMaMs > 0) { |
| 4845 | pw.print(prefix); |
| 4846 | sb.setLength(0); |
| 4847 | sb.append(prefix); |
| 4848 | sb.append(" Battery Drain (mAh): "); |
| 4849 | sb.append(Double.toString(((double) gpsBatteryDrainMaMs)/(3600 * 1000))); |
| 4850 | pw.println(sb.toString()); |
| 4851 | } |
| 4852 | |
| 4853 | pw.print(prefix); |
| 4854 | sb.setLength(0); |
| 4855 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4856 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4857 | pw.println(sb.toString()); |
| 4858 | pw.println(""); |
| 4859 | |
| 4860 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4861 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4862 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4863 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4864 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4865 | sb.setLength(0); |
| 4866 | sb.append(prefix); |
| 4867 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4868 | pw.println(sb.toString()); |
| 4869 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4870 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4871 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4872 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4873 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4874 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4875 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4876 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4877 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4878 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4879 | pw.println(getDischargeStartLevel()); |
| 4880 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4881 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4882 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4883 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4884 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4885 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4886 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4887 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4888 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4889 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4890 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4891 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4892 | pw.println(getDischargeAmountScreenOff()); |
| 4893 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4894 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4895 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4896 | } else { |
| 4897 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4898 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4899 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4900 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4901 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4902 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4903 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4904 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4905 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4906 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4907 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4908 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4909 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4910 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4911 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4912 | helper.create(this); |
| 4913 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4914 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4915 | if (sippers != null && sippers.size() > 0) { |
| 4916 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4917 | pw.print(prefix); pw.print(" Capacity: "); |
| 4918 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4919 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4920 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4921 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4922 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4923 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4924 | pw.println(); |
| 4925 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4926 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4927 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4928 | switch (bs.drainType) { |
| 4929 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4930 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4931 | break; |
| 4932 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4933 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4934 | break; |
| 4935 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4936 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4937 | break; |
| 4938 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4939 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4940 | break; |
| 4941 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4942 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4943 | break; |
| 4944 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4945 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4946 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4947 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4948 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4949 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4950 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4951 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4952 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4953 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4954 | break; |
| 4955 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4956 | pw.print(" User "); pw.print(bs.userId); |
| 4957 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4958 | break; |
| 4959 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4960 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4961 | break; |
| 4962 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4963 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4964 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4965 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4966 | pw.print(" Camera: "); |
| 4967 | break; |
| 4968 | default: |
| 4969 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4970 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4971 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4972 | printmAh(pw, bs.totalPowerMah); |
| 4973 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4974 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4975 | // If the usage (generic power) isn't the whole amount, we list out |
| 4976 | // what components are involved in the calculation. |
| 4977 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4978 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4979 | if (bs.usagePowerMah != 0) { |
| 4980 | pw.print(" usage="); |
| 4981 | printmAh(pw, bs.usagePowerMah); |
| 4982 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4983 | if (bs.cpuPowerMah != 0) { |
| 4984 | pw.print(" cpu="); |
| 4985 | printmAh(pw, bs.cpuPowerMah); |
| 4986 | } |
| 4987 | if (bs.wakeLockPowerMah != 0) { |
| 4988 | pw.print(" wake="); |
| 4989 | printmAh(pw, bs.wakeLockPowerMah); |
| 4990 | } |
| 4991 | if (bs.mobileRadioPowerMah != 0) { |
| 4992 | pw.print(" radio="); |
| 4993 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4994 | } |
| 4995 | if (bs.wifiPowerMah != 0) { |
| 4996 | pw.print(" wifi="); |
| 4997 | printmAh(pw, bs.wifiPowerMah); |
| 4998 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4999 | if (bs.bluetoothPowerMah != 0) { |
| 5000 | pw.print(" bt="); |
| 5001 | printmAh(pw, bs.bluetoothPowerMah); |
| 5002 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5003 | if (bs.gpsPowerMah != 0) { |
| 5004 | pw.print(" gps="); |
| 5005 | printmAh(pw, bs.gpsPowerMah); |
| 5006 | } |
| 5007 | if (bs.sensorPowerMah != 0) { |
| 5008 | pw.print(" sensor="); |
| 5009 | printmAh(pw, bs.sensorPowerMah); |
| 5010 | } |
| 5011 | if (bs.cameraPowerMah != 0) { |
| 5012 | pw.print(" camera="); |
| 5013 | printmAh(pw, bs.cameraPowerMah); |
| 5014 | } |
| 5015 | if (bs.flashlightPowerMah != 0) { |
| 5016 | pw.print(" flash="); |
| 5017 | printmAh(pw, bs.flashlightPowerMah); |
| 5018 | } |
| 5019 | pw.print(" )"); |
| 5020 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 5021 | |
| 5022 | // If there is additional smearing information, include it. |
| 5023 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 5024 | pw.print(" Including smearing: "); |
| 5025 | printmAh(pw, bs.totalSmearedPowerMah); |
| 5026 | pw.print(" ("); |
| 5027 | if (bs.screenPowerMah != 0) { |
| 5028 | pw.print(" screen="); |
| 5029 | printmAh(pw, bs.screenPowerMah); |
| 5030 | } |
| 5031 | if (bs.proportionalSmearMah != 0) { |
| 5032 | pw.print(" proportional="); |
| 5033 | printmAh(pw, bs.proportionalSmearMah); |
| 5034 | } |
| 5035 | pw.print(" )"); |
| 5036 | } |
| 5037 | if (bs.shouldHide) { |
| 5038 | pw.print(" Excluded from smearing"); |
| 5039 | } |
| 5040 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 5041 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5042 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5043 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5044 | } |
| 5045 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5046 | sippers = helper.getMobilemsppList(); |
| 5047 | if (sippers != null && sippers.size() > 0) { |
| 5048 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5049 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5050 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5051 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5052 | sb.setLength(0); |
| 5053 | sb.append(prefix); sb.append(" Uid "); |
| 5054 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 5055 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 5056 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 5057 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5058 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5059 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5060 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5061 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5062 | sb.setLength(0); |
| 5063 | sb.append(prefix); |
| 5064 | sb.append(" TOTAL TIME: "); |
| 5065 | formatTimeMs(sb, totalTime); |
| 5066 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 5067 | sb.append(")"); |
| 5068 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5069 | pw.println(); |
| 5070 | } |
| 5071 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5072 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 5073 | @Override |
| 5074 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 5075 | long lhsTime = lhs.mTime; |
| 5076 | long rhsTime = rhs.mTime; |
| 5077 | if (lhsTime < rhsTime) { |
| 5078 | return 1; |
| 5079 | } |
| 5080 | if (lhsTime > rhsTime) { |
| 5081 | return -1; |
| 5082 | } |
| 5083 | return 0; |
| 5084 | } |
| 5085 | }; |
| 5086 | |
| 5087 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5088 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 5089 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5090 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5091 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 5092 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 5093 | : kernelWakelocks.entrySet()) { |
| 5094 | final BatteryStats.Timer timer = ent.getValue(); |
| 5095 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5096 | if (totalTimeMillis > 0) { |
| 5097 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 5098 | } |
| 5099 | } |
| 5100 | if (ktimers.size() > 0) { |
| 5101 | Collections.sort(ktimers, timerComparator); |
| 5102 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 5103 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5104 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5105 | String linePrefix = ": "; |
| 5106 | sb.setLength(0); |
| 5107 | sb.append(prefix); |
| 5108 | sb.append(" Kernel Wake lock "); |
| 5109 | sb.append(timer.mName); |
| 5110 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 5111 | which, linePrefix); |
| 5112 | if (!linePrefix.equals(": ")) { |
| 5113 | sb.append(" realtime"); |
| 5114 | // Only print out wake locks that were held |
| 5115 | pw.println(sb.toString()); |
| 5116 | } |
| 5117 | } |
| 5118 | pw.println(); |
| 5119 | } |
| 5120 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5121 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5122 | if (timers.size() > 0) { |
| 5123 | Collections.sort(timers, timerComparator); |
| 5124 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5125 | for (int i=0; i<timers.size(); i++) { |
| 5126 | TimerEntry timer = timers.get(i); |
| 5127 | sb.setLength(0); |
| 5128 | sb.append(" Wake lock "); |
| 5129 | UserHandle.formatUid(sb, timer.mId); |
| 5130 | sb.append(" "); |
| 5131 | sb.append(timer.mName); |
| 5132 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5133 | sb.append(" realtime"); |
| 5134 | pw.println(sb.toString()); |
| 5135 | } |
| 5136 | timers.clear(); |
| 5137 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5138 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5139 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5140 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5141 | if (wakeupReasons.size() > 0) { |
| 5142 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5143 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5144 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5145 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5146 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5147 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5148 | } |
| 5149 | Collections.sort(reasons, timerComparator); |
| 5150 | for (int i=0; i<reasons.size(); i++) { |
| 5151 | TimerEntry timer = reasons.get(i); |
| 5152 | String linePrefix = ": "; |
| 5153 | sb.setLength(0); |
| 5154 | sb.append(prefix); |
| 5155 | sb.append(" Wakeup reason "); |
| 5156 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5157 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5158 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5159 | pw.println(sb.toString()); |
| 5160 | } |
| 5161 | pw.println(); |
| 5162 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5163 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5164 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5165 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5166 | if (mMemoryStats.size() > 0) { |
| 5167 | pw.println(" Memory Stats"); |
| 5168 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5169 | sb.setLength(0); |
| 5170 | sb.append(" Bandwidth "); |
| 5171 | sb.append(mMemoryStats.keyAt(i)); |
| 5172 | sb.append(" Time "); |
| 5173 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5174 | pw.println(sb.toString()); |
| 5175 | } |
| 5176 | pw.println(); |
| 5177 | } |
| 5178 | |
| 5179 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5180 | if (rpmStats.size() > 0) { |
| 5181 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5182 | if (rpmStats.size() > 0) { |
| 5183 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5184 | final String timerName = ent.getKey(); |
| 5185 | final Timer timer = ent.getValue(); |
| 5186 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5187 | } |
| 5188 | } |
| 5189 | pw.println(); |
| 5190 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5191 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5192 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5193 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5194 | pw.print(prefix); |
| 5195 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5196 | if (screenOffRpmStats.size() > 0) { |
| 5197 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5198 | final String timerName = ent.getKey(); |
| 5199 | final Timer timer = ent.getValue(); |
| 5200 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5201 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5202 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5203 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5204 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5207 | final long[] cpuFreqs = getCpuFreqs(); |
| 5208 | if (cpuFreqs != null) { |
| 5209 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5210 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5211 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5212 | sb.append(" " + cpuFreqs[i]); |
| 5213 | } |
| 5214 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5215 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | for (int iu=0; iu<NU; iu++) { |
| 5219 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5220 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5221 | continue; |
| 5222 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5223 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5224 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5225 | |
| 5226 | pw.print(prefix); |
| 5227 | pw.print(" "); |
| 5228 | UserHandle.formatUid(pw, uid); |
| 5229 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5231 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5232 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5233 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5234 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5235 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5236 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5237 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5238 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5239 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5240 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5241 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5242 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5243 | |
| 5244 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5245 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5246 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5247 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5248 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5249 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5250 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5251 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5252 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5253 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5254 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5255 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5256 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5257 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5258 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5259 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5260 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5261 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5262 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5263 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5264 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5265 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5266 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5267 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5268 | sb.setLength(0); |
| 5269 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5270 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5271 | sb.append("("); |
| 5272 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5273 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5274 | long packets = mobileRxPackets + mobileTxPackets; |
| 5275 | if (packets == 0) { |
| 5276 | packets = 1; |
| 5277 | } |
| 5278 | sb.append(" @ "); |
| 5279 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5280 | sb.append(" mspp"); |
| 5281 | pw.println(sb.toString()); |
| 5282 | } |
| 5283 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5284 | if (mobileWakeup > 0) { |
| 5285 | sb.setLength(0); |
| 5286 | sb.append(prefix); |
| 5287 | sb.append(" Mobile radio AP wakeups: "); |
| 5288 | sb.append(mobileWakeup); |
| 5289 | pw.println(sb.toString()); |
| 5290 | } |
| 5291 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5292 | printControllerActivityIfInteresting(pw, sb, prefix + " ", |
| 5293 | CELLULAR_CONTROLLER_NAME, u.getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5294 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5295 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5296 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5297 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5298 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5299 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5300 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5303 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5304 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5305 | || uidWifiRunningTime != 0) { |
| 5306 | sb.setLength(0); |
| 5307 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5308 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5309 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5310 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5311 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5312 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5313 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5314 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5315 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5316 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5317 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5318 | whichBatteryRealtime)); sb.append(") "); |
| 5319 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5320 | sb.append("x\n"); |
| 5321 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5322 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5323 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5324 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5325 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5326 | sb.append(") "); |
| 5327 | sb.append(wifiScanCount); |
| 5328 | sb.append("x\n"); |
| 5329 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5330 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5331 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5332 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5333 | sb.append(") "); |
| 5334 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5335 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5336 | pw.println(sb.toString()); |
| 5337 | } |
| 5338 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5339 | if (wifiWakeup > 0) { |
| 5340 | sb.setLength(0); |
| 5341 | sb.append(prefix); |
| 5342 | sb.append(" WiFi AP wakeups: "); |
| 5343 | sb.append(wifiWakeup); |
| 5344 | pw.println(sb.toString()); |
| 5345 | } |
| 5346 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5347 | printControllerActivityIfInteresting(pw, sb, prefix + " ", WIFI_CONTROLLER_NAME, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5348 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5349 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5350 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5351 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5352 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5353 | pw.print(formatBytesLocked(btTxBytes)); |
| 5354 | pw.println(" sent"); |
| 5355 | } |
| 5356 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5357 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5358 | if (bleTimer != null) { |
| 5359 | // Convert from microseconds to milliseconds with rounding |
| 5360 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5361 | / 1000; |
| 5362 | if (totalTimeMs != 0) { |
| 5363 | final int count = bleTimer.getCountLocked(which); |
| 5364 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5365 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5366 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5367 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5368 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5369 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5370 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5371 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5372 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5373 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5374 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5375 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5376 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5377 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5378 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5379 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5380 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5381 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5382 | final Timer unoptimizedScanTimerBg = |
| 5383 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5384 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5385 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5386 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5387 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5388 | |
| 5389 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5390 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5391 | sb.append(prefix); |
| 5392 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5393 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5394 | sb.append(" ("); |
| 5395 | sb.append(count); |
| 5396 | sb.append(" times)"); |
| 5397 | if (bleTimer.isRunningLocked()) { |
| 5398 | sb.append(" (currently running)"); |
| 5399 | } |
| 5400 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5401 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5402 | |
| 5403 | sb.append(prefix); |
| 5404 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5405 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5406 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5407 | sb.append(count); |
| 5408 | sb.append(" times)"); |
| 5409 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5410 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5411 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5412 | sb.append("\n"); |
| 5413 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5414 | sb.append(prefix); |
| 5415 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5416 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5417 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5418 | sb.append(countBg); |
| 5419 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5420 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5421 | sb.append(" (currently running in background)"); |
| 5422 | } |
| 5423 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5424 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5425 | |
| 5426 | sb.append(prefix); |
| 5427 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5428 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5429 | sb.append(" ("); |
| 5430 | sb.append(resultCountBg); |
| 5431 | sb.append(" in background)"); |
| 5432 | |
| 5433 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5434 | sb.append("\n"); |
| 5435 | sb.append(prefix); |
| 5436 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5437 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5438 | sb.append(" (max "); |
| 5439 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5440 | sb.append(")"); |
| 5441 | if (unoptimizedScanTimer != null |
| 5442 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5443 | sb.append(" (currently running unoptimized)"); |
| 5444 | } |
| 5445 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5446 | sb.append("\n"); |
| 5447 | sb.append(prefix); |
| 5448 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5449 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5450 | sb.append(" (max "); |
| 5451 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5452 | sb.append(")"); |
| 5453 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5454 | sb.append(" (currently running unoptimized in background)"); |
| 5455 | } |
| 5456 | } |
| 5457 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5458 | pw.println(sb.toString()); |
| 5459 | uidActivity = true; |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5464 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5465 | if (u.hasUserActivity()) { |
| 5466 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5467 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5468 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5469 | if (val != 0) { |
| 5470 | if (!hasData) { |
| 5471 | sb.setLength(0); |
| 5472 | sb.append(" User activity: "); |
| 5473 | hasData = true; |
| 5474 | } else { |
| 5475 | sb.append(", "); |
| 5476 | } |
| 5477 | sb.append(val); |
| 5478 | sb.append(" "); |
| 5479 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5480 | } |
| 5481 | } |
| 5482 | if (hasData) { |
| 5483 | pw.println(sb.toString()); |
| 5484 | } |
| 5485 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5486 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5487 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5488 | = u.getWakelockStats(); |
| 5489 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5490 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5491 | int countWakelock = 0; |
| 5492 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5493 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5494 | String linePrefix = ": "; |
| 5495 | sb.setLength(0); |
| 5496 | sb.append(prefix); |
| 5497 | sb.append(" Wake lock "); |
| 5498 | sb.append(wakelocks.keyAt(iw)); |
| 5499 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5500 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5501 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5502 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5503 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5504 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5505 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5506 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5507 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5508 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5509 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5510 | sb.append(" realtime"); |
| 5511 | pw.println(sb.toString()); |
| 5512 | uidActivity = true; |
| 5513 | countWakelock++; |
| 5514 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5515 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5516 | rawRealtime, which); |
| 5517 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5518 | rawRealtime, which); |
| 5519 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5520 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5521 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5522 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5523 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5524 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5525 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5526 | // pooled and therefore just a lower bound) |
| 5527 | long actualTotalPartialWakelock = 0; |
| 5528 | long actualBgPartialWakelock = 0; |
| 5529 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5530 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5531 | // Convert from microseconds to milliseconds with rounding |
| 5532 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5533 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5534 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5535 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5536 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5540 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5541 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5542 | sb.setLength(0); |
| 5543 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5544 | sb.append(" TOTAL wake: "); |
| 5545 | boolean needComma = false; |
| 5546 | if (totalFullWakelock != 0) { |
| 5547 | needComma = true; |
| 5548 | formatTimeMs(sb, totalFullWakelock); |
| 5549 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5550 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5551 | if (totalPartialWakelock != 0) { |
| 5552 | if (needComma) { |
| 5553 | sb.append(", "); |
| 5554 | } |
| 5555 | needComma = true; |
| 5556 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5557 | sb.append("blamed partial"); |
| 5558 | } |
| 5559 | if (actualTotalPartialWakelock != 0) { |
| 5560 | if (needComma) { |
| 5561 | sb.append(", "); |
| 5562 | } |
| 5563 | needComma = true; |
| 5564 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5565 | sb.append("actual partial"); |
| 5566 | } |
| 5567 | if (actualBgPartialWakelock != 0) { |
| 5568 | if (needComma) { |
| 5569 | sb.append(", "); |
| 5570 | } |
| 5571 | needComma = true; |
| 5572 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5573 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5574 | } |
| 5575 | if (totalWindowWakelock != 0) { |
| 5576 | if (needComma) { |
| 5577 | sb.append(", "); |
| 5578 | } |
| 5579 | needComma = true; |
| 5580 | formatTimeMs(sb, totalWindowWakelock); |
| 5581 | sb.append("window"); |
| 5582 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5583 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5584 | if (needComma) { |
| 5585 | sb.append(","); |
| 5586 | } |
| 5587 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5588 | formatTimeMs(sb, totalDrawWakelock); |
| 5589 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5590 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5591 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5592 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5596 | // Calculate multicast wakelock stats |
| 5597 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5598 | if (mcTimer != null) { |
| 5599 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5600 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5601 | |
| 5602 | if (multicastWakeLockTimeMicros > 0) { |
| 5603 | sb.setLength(0); |
| 5604 | sb.append(prefix); |
| 5605 | sb.append(" WiFi Multicast Wakelock"); |
| 5606 | sb.append(" count = "); |
| 5607 | sb.append(multicastWakeLockCount); |
| 5608 | sb.append(" time = "); |
| 5609 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5610 | pw.println(sb.toString()); |
| 5611 | } |
| 5612 | } |
| 5613 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5614 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5615 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5616 | final Timer timer = syncs.valueAt(isy); |
| 5617 | // Convert from microseconds to milliseconds with rounding |
| 5618 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5619 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5620 | final Timer bgTimer = timer.getSubTimer(); |
| 5621 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5622 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5623 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5624 | sb.setLength(0); |
| 5625 | sb.append(prefix); |
| 5626 | sb.append(" Sync "); |
| 5627 | sb.append(syncs.keyAt(isy)); |
| 5628 | sb.append(": "); |
| 5629 | if (totalTime != 0) { |
| 5630 | formatTimeMs(sb, totalTime); |
| 5631 | sb.append("realtime ("); |
| 5632 | sb.append(count); |
| 5633 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5634 | if (bgTime > 0) { |
| 5635 | sb.append(", "); |
| 5636 | formatTimeMs(sb, bgTime); |
| 5637 | sb.append("background ("); |
| 5638 | sb.append(bgCount); |
| 5639 | sb.append(" times)"); |
| 5640 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5641 | } else { |
| 5642 | sb.append("(not used)"); |
| 5643 | } |
| 5644 | pw.println(sb.toString()); |
| 5645 | uidActivity = true; |
| 5646 | } |
| 5647 | |
| 5648 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5649 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5650 | final Timer timer = jobs.valueAt(ij); |
| 5651 | // Convert from microseconds to milliseconds with rounding |
| 5652 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5653 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5654 | final Timer bgTimer = timer.getSubTimer(); |
| 5655 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5656 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5657 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5658 | sb.setLength(0); |
| 5659 | sb.append(prefix); |
| 5660 | sb.append(" Job "); |
| 5661 | sb.append(jobs.keyAt(ij)); |
| 5662 | sb.append(": "); |
| 5663 | if (totalTime != 0) { |
| 5664 | formatTimeMs(sb, totalTime); |
| 5665 | sb.append("realtime ("); |
| 5666 | sb.append(count); |
| 5667 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5668 | if (bgTime > 0) { |
| 5669 | sb.append(", "); |
| 5670 | formatTimeMs(sb, bgTime); |
| 5671 | sb.append("background ("); |
| 5672 | sb.append(bgCount); |
| 5673 | sb.append(" times)"); |
| 5674 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5675 | } else { |
| 5676 | sb.append("(not used)"); |
| 5677 | } |
| 5678 | pw.println(sb.toString()); |
| 5679 | uidActivity = true; |
| 5680 | } |
| 5681 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5682 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5683 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5684 | SparseIntArray types = completions.valueAt(ic); |
| 5685 | if (types != null) { |
| 5686 | pw.print(prefix); |
| 5687 | pw.print(" Job Completions "); |
| 5688 | pw.print(completions.keyAt(ic)); |
| 5689 | pw.print(":"); |
| 5690 | for (int it=0; it<types.size(); it++) { |
| 5691 | pw.print(" "); |
| 5692 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5693 | pw.print("("); |
| 5694 | pw.print(types.valueAt(it)); |
| 5695 | pw.print("x)"); |
| 5696 | } |
| 5697 | pw.println(); |
| 5698 | } |
| 5699 | } |
| 5700 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5701 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5702 | prefix, "Flashlight"); |
| 5703 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5704 | prefix, "Camera"); |
| 5705 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5706 | prefix, "Video"); |
| 5707 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5708 | prefix, "Audio"); |
| 5709 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5710 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5711 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5712 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5713 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5714 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5715 | sb.setLength(0); |
| 5716 | sb.append(prefix); |
| 5717 | sb.append(" Sensor "); |
| 5718 | int handle = se.getHandle(); |
| 5719 | if (handle == Uid.Sensor.GPS) { |
| 5720 | sb.append("GPS"); |
| 5721 | } else { |
| 5722 | sb.append(handle); |
| 5723 | } |
| 5724 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5725 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5726 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5727 | if (timer != null) { |
| 5728 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5729 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5730 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5731 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5732 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5733 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5734 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5735 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5736 | final long bgActualTime = bgTimer != null ? |
| 5737 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5738 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5739 | //timer.logState(); |
| 5740 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5741 | if (actualTime != totalTime) { |
| 5742 | formatTimeMs(sb, totalTime); |
| 5743 | sb.append("blamed realtime, "); |
| 5744 | } |
| 5745 | |
| 5746 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5747 | sb.append("realtime ("); |
| 5748 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5749 | sb.append(" times)"); |
| 5750 | |
| 5751 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5752 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5753 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5754 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5755 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5756 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5757 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | } else { |
| 5759 | sb.append("(not used)"); |
| 5760 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5761 | } else { |
| 5762 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5763 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5764 | |
| 5765 | pw.println(sb.toString()); |
| 5766 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | } |
| 5768 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5769 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5770 | "Vibrator"); |
| 5771 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5772 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5773 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5774 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5775 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5776 | long totalStateTime = 0; |
| 5777 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5778 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5779 | if (time > 0) { |
| 5780 | totalStateTime += time; |
| 5781 | sb.setLength(0); |
| 5782 | sb.append(prefix); |
| 5783 | sb.append(" "); |
| 5784 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5785 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5786 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5787 | pw.println(sb.toString()); |
| 5788 | uidActivity = true; |
| 5789 | } |
| 5790 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5791 | if (totalStateTime > 0) { |
| 5792 | sb.setLength(0); |
| 5793 | sb.append(prefix); |
| 5794 | sb.append(" Total running: "); |
| 5795 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5796 | pw.println(sb.toString()); |
| 5797 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5798 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5799 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5800 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5801 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5802 | sb.setLength(0); |
| 5803 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5804 | sb.append(" Total cpu time: u="); |
| 5805 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5806 | sb.append("s="); |
| 5807 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5808 | pw.println(sb.toString()); |
| 5809 | } |
| 5810 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5811 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5812 | if (cpuFreqTimes != null) { |
| 5813 | sb.setLength(0); |
| 5814 | sb.append(" Total cpu time per freq:"); |
| 5815 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5816 | sb.append(" " + cpuFreqTimes[i]); |
| 5817 | } |
| 5818 | pw.println(sb.toString()); |
| 5819 | } |
| 5820 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5821 | if (screenOffCpuFreqTimes != null) { |
| 5822 | sb.setLength(0); |
| 5823 | sb.append(" Total screen-off cpu time per freq:"); |
| 5824 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5825 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5826 | } |
| 5827 | pw.println(sb.toString()); |
| 5828 | } |
| 5829 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5830 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5831 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5832 | if (cpuTimes != null) { |
| 5833 | sb.setLength(0); |
| 5834 | sb.append(" Cpu times per freq at state " |
| 5835 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5836 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5837 | sb.append(" " + cpuTimes[i]); |
| 5838 | } |
| 5839 | pw.println(sb.toString()); |
| 5840 | } |
| 5841 | |
| 5842 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5843 | if (screenOffCpuTimes != null) { |
| 5844 | sb.setLength(0); |
| 5845 | sb.append(" Screen-off cpu times per freq at state " |
| 5846 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5847 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5848 | sb.append(" " + screenOffCpuTimes[i]); |
| 5849 | } |
| 5850 | pw.println(sb.toString()); |
| 5851 | } |
| 5852 | } |
| 5853 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5854 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5855 | = u.getProcessStats(); |
| 5856 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5857 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5858 | long userTime; |
| 5859 | long systemTime; |
| 5860 | long foregroundTime; |
| 5861 | int starts; |
| 5862 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5864 | userTime = ps.getUserTime(which); |
| 5865 | systemTime = ps.getSystemTime(which); |
| 5866 | foregroundTime = ps.getForegroundTime(which); |
| 5867 | starts = ps.getStarts(which); |
| 5868 | final int numCrashes = ps.getNumCrashes(which); |
| 5869 | final int numAnrs = ps.getNumAnrs(which); |
| 5870 | numExcessive = which == STATS_SINCE_CHARGED |
| 5871 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5873 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5874 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5875 | sb.setLength(0); |
| 5876 | sb.append(prefix); sb.append(" Proc "); |
| 5877 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5878 | sb.append(prefix); sb.append(" CPU: "); |
| 5879 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5880 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5881 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5882 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5883 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5884 | boolean hasOne = false; |
| 5885 | if (starts != 0) { |
| 5886 | hasOne = true; |
| 5887 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5888 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5889 | if (numCrashes != 0) { |
| 5890 | if (hasOne) { |
| 5891 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5892 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5893 | hasOne = true; |
| 5894 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5895 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5896 | if (numAnrs != 0) { |
| 5897 | if (hasOne) { |
| 5898 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5900 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | } |
| 5902 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5903 | pw.println(sb.toString()); |
| 5904 | for (int e=0; e<numExcessive; e++) { |
| 5905 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5906 | if (ew != null) { |
| 5907 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5908 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5909 | pw.print("cpu"); |
| 5910 | } else { |
| 5911 | pw.print("unknown"); |
| 5912 | } |
| 5913 | pw.print(" use: "); |
| 5914 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5915 | pw.print(" over "); |
| 5916 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5917 | if (ew.overTime != 0) { |
| 5918 | pw.print(" ("); |
| 5919 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5920 | pw.println("%)"); |
| 5921 | } |
| 5922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | } |
| 5924 | uidActivity = true; |
| 5925 | } |
| 5926 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5927 | |
| 5928 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5929 | = u.getPackageStats(); |
| 5930 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5931 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5932 | pw.println(":"); |
| 5933 | boolean apkActivity = false; |
| 5934 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5935 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5936 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5937 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5938 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5939 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5940 | pw.println(" times"); |
| 5941 | apkActivity = true; |
| 5942 | } |
| 5943 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5944 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5945 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5946 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5947 | final int starts = ss.getStarts(which); |
| 5948 | final int launches = ss.getLaunches(which); |
| 5949 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5950 | sb.setLength(0); |
| 5951 | sb.append(prefix); sb.append(" Service "); |
| 5952 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5953 | sb.append(prefix); sb.append(" Created for: "); |
| 5954 | formatTimeMs(sb, startTime / 1000); |
| 5955 | sb.append("uptime\n"); |
| 5956 | sb.append(prefix); sb.append(" Starts: "); |
| 5957 | sb.append(starts); |
| 5958 | sb.append(", launches: "); sb.append(launches); |
| 5959 | pw.println(sb.toString()); |
| 5960 | apkActivity = true; |
| 5961 | } |
| 5962 | } |
| 5963 | if (!apkActivity) { |
| 5964 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5965 | } |
| 5966 | uidActivity = true; |
| 5967 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5969 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | } |
| 5971 | } |
| 5972 | } |
| 5973 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5974 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5975 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5976 | int diff = oldval ^ newval; |
| 5977 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5978 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5979 | for (int i=0; i<descriptions.length; i++) { |
| 5980 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5981 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5982 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5983 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5984 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5985 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5986 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5987 | didWake = true; |
| 5988 | pw.print("="); |
| 5989 | if (longNames) { |
| 5990 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5991 | pw.print(":\""); |
| 5992 | pw.print(wakelockTag.string); |
| 5993 | pw.print("\""); |
| 5994 | } else { |
| 5995 | pw.print(wakelockTag.poolIdx); |
| 5996 | } |
| 5997 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5998 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5999 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6000 | pw.print("="); |
| 6001 | int val = (newval&bd.mask)>>bd.shift; |
| 6002 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6003 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6004 | } else { |
| 6005 | pw.print(val); |
| 6006 | } |
| 6007 | } |
| 6008 | } |
| 6009 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6010 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 6011 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6012 | if (longNames) { |
| 6013 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 6014 | pw.print(":\""); |
| 6015 | pw.print(wakelockTag.string); |
| 6016 | pw.print("\""); |
| 6017 | } else { |
| 6018 | pw.print(wakelockTag.poolIdx); |
| 6019 | } |
| 6020 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6021 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6022 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6023 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6024 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | public static class HistoryPrinter { |
| 6028 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6029 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6030 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6031 | int oldStatus = -1; |
| 6032 | int oldHealth = -1; |
| 6033 | int oldPlug = -1; |
| 6034 | int oldTemp = -1; |
| 6035 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6036 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6037 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6038 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6039 | void reset() { |
| 6040 | oldState = oldState2 = 0; |
| 6041 | oldLevel = -1; |
| 6042 | oldStatus = -1; |
| 6043 | oldHealth = -1; |
| 6044 | oldPlug = -1; |
| 6045 | oldTemp = -1; |
| 6046 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6047 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6048 | } |
| 6049 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6050 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6051 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6052 | if (!checkin) { |
| 6053 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6054 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6055 | pw.print(" ("); |
| 6056 | pw.print(rec.numReadInts); |
| 6057 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6058 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6059 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6060 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6061 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6062 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6063 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6064 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6065 | } |
| 6066 | lastTime = rec.time; |
| 6067 | } |
| 6068 | if (rec.cmd == HistoryItem.CMD_START) { |
| 6069 | if (checkin) { |
| 6070 | pw.print(":"); |
| 6071 | } |
| 6072 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6073 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6074 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 6075 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6076 | if (checkin) { |
| 6077 | pw.print(":"); |
| 6078 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6079 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 6080 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6081 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6082 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6083 | pw.print("TIME:"); |
| 6084 | if (checkin) { |
| 6085 | pw.println(rec.currentTime); |
| 6086 | } else { |
| 6087 | pw.print(" "); |
| 6088 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6089 | rec.currentTime).toString()); |
| 6090 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6091 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 6092 | if (checkin) { |
| 6093 | pw.print(":"); |
| 6094 | } |
| 6095 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6096 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 6097 | if (checkin) { |
| 6098 | pw.print(":"); |
| 6099 | } |
| 6100 | pw.println("*OVERFLOW*"); |
| 6101 | } else { |
| 6102 | if (!checkin) { |
| 6103 | if (rec.batteryLevel < 10) pw.print("00"); |
| 6104 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 6105 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6106 | if (verbose) { |
| 6107 | pw.print(" "); |
| 6108 | if (rec.states < 0) ; |
| 6109 | else if (rec.states < 0x10) pw.print("0000000"); |
| 6110 | else if (rec.states < 0x100) pw.print("000000"); |
| 6111 | else if (rec.states < 0x1000) pw.print("00000"); |
| 6112 | else if (rec.states < 0x10000) pw.print("0000"); |
| 6113 | else if (rec.states < 0x100000) pw.print("000"); |
| 6114 | else if (rec.states < 0x1000000) pw.print("00"); |
| 6115 | else if (rec.states < 0x10000000) pw.print("0"); |
| 6116 | pw.print(Integer.toHexString(rec.states)); |
| 6117 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6118 | } else { |
| 6119 | if (oldLevel != rec.batteryLevel) { |
| 6120 | oldLevel = rec.batteryLevel; |
| 6121 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 6122 | } |
| 6123 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6124 | if (oldStatus != rec.batteryStatus) { |
| 6125 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6126 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6127 | switch (oldStatus) { |
| 6128 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6129 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6130 | break; |
| 6131 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6132 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6133 | break; |
| 6134 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6135 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6136 | break; |
| 6137 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6138 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6139 | break; |
| 6140 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6141 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6142 | break; |
| 6143 | default: |
| 6144 | pw.print(oldStatus); |
| 6145 | break; |
| 6146 | } |
| 6147 | } |
| 6148 | if (oldHealth != rec.batteryHealth) { |
| 6149 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6150 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6151 | switch (oldHealth) { |
| 6152 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6153 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6154 | break; |
| 6155 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6156 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6157 | break; |
| 6158 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6159 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6160 | break; |
| 6161 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6162 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6163 | break; |
| 6164 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6165 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6166 | break; |
| 6167 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6168 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6169 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6170 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 6171 | pw.print(checkin ? "c" : "cold"); |
| 6172 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6173 | default: |
| 6174 | pw.print(oldHealth); |
| 6175 | break; |
| 6176 | } |
| 6177 | } |
| 6178 | if (oldPlug != rec.batteryPlugType) { |
| 6179 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6180 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6181 | switch (oldPlug) { |
| 6182 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6183 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6184 | break; |
| 6185 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6186 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6187 | break; |
| 6188 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6189 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6190 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6191 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6192 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6193 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6194 | default: |
| 6195 | pw.print(oldPlug); |
| 6196 | break; |
| 6197 | } |
| 6198 | } |
| 6199 | if (oldTemp != rec.batteryTemperature) { |
| 6200 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6201 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6202 | pw.print(oldTemp); |
| 6203 | } |
| 6204 | if (oldVolt != rec.batteryVoltage) { |
| 6205 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6206 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6207 | pw.print(oldVolt); |
| 6208 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6209 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6210 | if (oldChargeMAh != chargeMAh) { |
| 6211 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6212 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6213 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6214 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6215 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6216 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6217 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 6218 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6219 | if (rec.wakeReasonTag != null) { |
| 6220 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6221 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6222 | pw.print(rec.wakeReasonTag.poolIdx); |
| 6223 | } else { |
| 6224 | pw.print(" wake_reason="); |
| 6225 | pw.print(rec.wakeReasonTag.uid); |
| 6226 | pw.print(":\""); |
| 6227 | pw.print(rec.wakeReasonTag.string); |
| 6228 | pw.print("\""); |
| 6229 | } |
| 6230 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6231 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6232 | pw.print(checkin ? "," : " "); |
| 6233 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 6234 | pw.print("+"); |
| 6235 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6236 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6237 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6238 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6239 | : HISTORY_EVENT_NAMES; |
| 6240 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6241 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6242 | if (idx >= 0 && idx < eventNames.length) { |
| 6243 | pw.print(eventNames[idx]); |
| 6244 | } else { |
| 6245 | pw.print(checkin ? "Ev" : "event"); |
| 6246 | pw.print(idx); |
| 6247 | } |
| 6248 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6249 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6250 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6251 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6252 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6253 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6254 | pw.print(":\""); |
| 6255 | pw.print(rec.eventTag.string); |
| 6256 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6257 | } |
| 6258 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6259 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6260 | if (rec.stepDetails != null) { |
| 6261 | if (!checkin) { |
| 6262 | pw.print(" Details: cpu="); |
| 6263 | pw.print(rec.stepDetails.userTime); |
| 6264 | pw.print("u+"); |
| 6265 | pw.print(rec.stepDetails.systemTime); |
| 6266 | pw.print("s"); |
| 6267 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6268 | pw.print(" ("); |
| 6269 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6270 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6271 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6272 | pw.print(", "); |
| 6273 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6274 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6275 | } |
| 6276 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6277 | pw.print(", "); |
| 6278 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6279 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6280 | } |
| 6281 | pw.print(')'); |
| 6282 | } |
| 6283 | pw.println(); |
| 6284 | pw.print(" /proc/stat="); |
| 6285 | pw.print(rec.stepDetails.statUserTime); |
| 6286 | pw.print(" usr, "); |
| 6287 | pw.print(rec.stepDetails.statSystemTime); |
| 6288 | pw.print(" sys, "); |
| 6289 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6290 | pw.print(" io, "); |
| 6291 | pw.print(rec.stepDetails.statIrqTime); |
| 6292 | pw.print(" irq, "); |
| 6293 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6294 | pw.print(" sirq, "); |
| 6295 | pw.print(rec.stepDetails.statIdlTime); |
| 6296 | pw.print(" idle"); |
| 6297 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6298 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6299 | + rec.stepDetails.statSoftIrqTime; |
| 6300 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6301 | if (total > 0) { |
| 6302 | pw.print(" ("); |
| 6303 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6304 | pw.print(String.format("%.1f%%", perc)); |
| 6305 | pw.print(" of "); |
| 6306 | StringBuilder sb = new StringBuilder(64); |
| 6307 | formatTimeMsNoSpace(sb, total*10); |
| 6308 | pw.print(sb); |
| 6309 | pw.print(")"); |
| 6310 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6311 | pw.print(", PlatformIdleStat "); |
| 6312 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6313 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6314 | |
| 6315 | pw.print(", SubsystemPowerState "); |
| 6316 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6317 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6318 | } else { |
| 6319 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6320 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6321 | pw.print(rec.stepDetails.userTime); |
| 6322 | pw.print(":"); |
| 6323 | pw.print(rec.stepDetails.systemTime); |
| 6324 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6325 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6326 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6327 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6328 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6329 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6330 | } |
| 6331 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6332 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6333 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6334 | } |
| 6335 | } |
| 6336 | pw.println(); |
| 6337 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6338 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6339 | pw.print(rec.stepDetails.statUserTime); |
| 6340 | pw.print(','); |
| 6341 | pw.print(rec.stepDetails.statSystemTime); |
| 6342 | pw.print(','); |
| 6343 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6344 | pw.print(','); |
| 6345 | pw.print(rec.stepDetails.statIrqTime); |
| 6346 | pw.print(','); |
| 6347 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6348 | pw.print(','); |
| 6349 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6350 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6351 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6352 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6353 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6354 | pw.print(','); |
| 6355 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6356 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6357 | |
| 6358 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6359 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6360 | } |
| 6361 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6362 | } |
| 6363 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6364 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6365 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6366 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6367 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6368 | |
| 6369 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6370 | UserHandle.formatUid(pw, uid); |
| 6371 | pw.print("="); |
| 6372 | pw.print(utime); |
| 6373 | pw.print("u+"); |
| 6374 | pw.print(stime); |
| 6375 | pw.print("s"); |
| 6376 | } |
| 6377 | |
| 6378 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6379 | pw.print('/'); |
| 6380 | pw.print(uid); |
| 6381 | pw.print(":"); |
| 6382 | pw.print(utime); |
| 6383 | pw.print(":"); |
| 6384 | pw.print(stime); |
| 6385 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6386 | } |
| 6387 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6388 | private void printSizeValue(PrintWriter pw, long size) { |
| 6389 | float result = size; |
| 6390 | String suffix = ""; |
| 6391 | if (result >= 10*1024) { |
| 6392 | suffix = "KB"; |
| 6393 | result = result / 1024; |
| 6394 | } |
| 6395 | if (result >= 10*1024) { |
| 6396 | suffix = "MB"; |
| 6397 | result = result / 1024; |
| 6398 | } |
| 6399 | if (result >= 10*1024) { |
| 6400 | suffix = "GB"; |
| 6401 | result = result / 1024; |
| 6402 | } |
| 6403 | if (result >= 10*1024) { |
| 6404 | suffix = "TB"; |
| 6405 | result = result / 1024; |
| 6406 | } |
| 6407 | if (result >= 10*1024) { |
| 6408 | suffix = "PB"; |
| 6409 | result = result / 1024; |
| 6410 | } |
| 6411 | pw.print((int)result); |
| 6412 | pw.print(suffix); |
| 6413 | } |
| 6414 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6415 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6416 | String label3, long estimatedTime) { |
| 6417 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6418 | return false; |
| 6419 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6420 | pw.print(label1); |
| 6421 | pw.print(label2); |
| 6422 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6423 | StringBuilder sb = new StringBuilder(64); |
| 6424 | formatTimeMs(sb, estimatedTime); |
| 6425 | pw.print(sb); |
| 6426 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6427 | return true; |
| 6428 | } |
| 6429 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6430 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6431 | LevelStepTracker steps, boolean checkin) { |
| 6432 | if (steps == null) { |
| 6433 | return false; |
| 6434 | } |
| 6435 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6436 | if (count <= 0) { |
| 6437 | return false; |
| 6438 | } |
| 6439 | if (!checkin) { |
| 6440 | pw.println(header); |
| 6441 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6442 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6443 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6444 | long duration = steps.getDurationAt(i); |
| 6445 | int level = steps.getLevelAt(i); |
| 6446 | long initMode = steps.getInitModeAt(i); |
| 6447 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6448 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6449 | lineArgs[0] = Long.toString(duration); |
| 6450 | lineArgs[1] = Integer.toString(level); |
| 6451 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6452 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6453 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6454 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6455 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6456 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6457 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6458 | } |
| 6459 | } else { |
| 6460 | lineArgs[2] = ""; |
| 6461 | } |
| 6462 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6463 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6464 | } else { |
| 6465 | lineArgs[3] = ""; |
| 6466 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6467 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6468 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6469 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6470 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6471 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6472 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6473 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6474 | pw.print(prefix); |
| 6475 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6476 | TimeUtils.formatDuration(duration, pw); |
| 6477 | pw.print(" to "); pw.print(level); |
| 6478 | boolean haveModes = false; |
| 6479 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6480 | pw.print(" ("); |
| 6481 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6482 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6483 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6484 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6485 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6486 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6487 | } |
| 6488 | haveModes = true; |
| 6489 | } |
| 6490 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6491 | pw.print(haveModes ? ", " : " ("); |
| 6492 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6493 | ? "power-save-on" : "power-save-off"); |
| 6494 | haveModes = true; |
| 6495 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6496 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6497 | pw.print(haveModes ? ", " : " ("); |
| 6498 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6499 | ? "device-idle-on" : "device-idle-off"); |
| 6500 | haveModes = true; |
| 6501 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6502 | if (haveModes) { |
| 6503 | pw.print(")"); |
| 6504 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6505 | pw.println(); |
| 6506 | } |
| 6507 | } |
| 6508 | return true; |
| 6509 | } |
| 6510 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6511 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6512 | LevelStepTracker steps) { |
| 6513 | if (steps == null) { |
| 6514 | return; |
| 6515 | } |
| 6516 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6517 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6518 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6519 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6520 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6521 | |
| 6522 | final long initMode = steps.getInitModeAt(i); |
| 6523 | final long modMode = steps.getModModeAt(i); |
| 6524 | |
| 6525 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6526 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6527 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6528 | case Display.STATE_OFF: |
| 6529 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6530 | break; |
| 6531 | case Display.STATE_ON: |
| 6532 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6533 | break; |
| 6534 | case Display.STATE_DOZE: |
| 6535 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6536 | break; |
| 6537 | case Display.STATE_DOZE_SUSPEND: |
| 6538 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6539 | break; |
| 6540 | default: |
| 6541 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6542 | break; |
| 6543 | } |
| 6544 | } |
| 6545 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6546 | |
| 6547 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6548 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6549 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6550 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6551 | } |
| 6552 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6553 | |
| 6554 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6555 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6556 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6557 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6558 | } |
| 6559 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6560 | |
| 6561 | proto.end(token); |
| 6562 | } |
| 6563 | } |
| 6564 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6565 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6566 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6567 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6568 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6569 | public static final int DUMP_VERBOSE = 1<<5; |
| 6570 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6571 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6572 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6573 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6574 | final HistoryItem rec = new HistoryItem(); |
| 6575 | long lastTime = -1; |
| 6576 | long baseTime = -1; |
| 6577 | boolean printed = false; |
| 6578 | HistoryEventTracker tracker = null; |
| 6579 | while (getNextHistoryLocked(rec)) { |
| 6580 | lastTime = rec.time; |
| 6581 | if (baseTime < 0) { |
| 6582 | baseTime = lastTime; |
| 6583 | } |
| 6584 | if (rec.time >= histStart) { |
| 6585 | if (histStart >= 0 && !printed) { |
| 6586 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6587 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6588 | || rec.cmd == HistoryItem.CMD_START |
| 6589 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6590 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6591 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6592 | (flags&DUMP_VERBOSE) != 0); |
| 6593 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6594 | } else if (rec.currentTime != 0) { |
| 6595 | printed = true; |
| 6596 | byte cmd = rec.cmd; |
| 6597 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6598 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6599 | (flags&DUMP_VERBOSE) != 0); |
| 6600 | rec.cmd = cmd; |
| 6601 | } |
| 6602 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6603 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6604 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6605 | (flags&DUMP_VERBOSE) != 0); |
| 6606 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6607 | } |
| 6608 | int oldEventCode = rec.eventCode; |
| 6609 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6610 | rec.eventTag = new HistoryTag(); |
| 6611 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6612 | HashMap<String, SparseIntArray> active |
| 6613 | = tracker.getStateForEvent(i); |
| 6614 | if (active == null) { |
| 6615 | continue; |
| 6616 | } |
| 6617 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6618 | : active.entrySet()) { |
| 6619 | SparseIntArray uids = ent.getValue(); |
| 6620 | for (int j=0; j<uids.size(); j++) { |
| 6621 | rec.eventCode = i; |
| 6622 | rec.eventTag.string = ent.getKey(); |
| 6623 | rec.eventTag.uid = uids.keyAt(j); |
| 6624 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6625 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6626 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6627 | rec.wakeReasonTag = null; |
| 6628 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6629 | } |
| 6630 | } |
| 6631 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6632 | rec.eventCode = oldEventCode; |
| 6633 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6634 | tracker = null; |
| 6635 | } |
| 6636 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6637 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6638 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6639 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6640 | // This is an attempt to aggregate the previous state and generate |
| 6641 | //Â fake events to reflect that state at the point where we start |
| 6642 | // 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] | 6643 | if (tracker == null) { |
| 6644 | tracker = new HistoryEventTracker(); |
| 6645 | } |
| 6646 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6647 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6648 | } |
| 6649 | } |
| 6650 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6651 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6652 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6653 | } |
| 6654 | } |
| 6655 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6656 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6657 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6658 | if (steps == null) { |
| 6659 | return; |
| 6660 | } |
| 6661 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6662 | if (timeRemaining >= 0) { |
| 6663 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6664 | tmpSb.setLength(0); |
| 6665 | formatTimeMs(tmpSb, timeRemaining); |
| 6666 | pw.print(tmpSb); |
| 6667 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6668 | pw.println(" steps)"); |
| 6669 | } |
| 6670 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6671 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6672 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6673 | if (estimatedTime > 0) { |
| 6674 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6675 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6676 | pw.print(" time: "); |
| 6677 | tmpSb.setLength(0); |
| 6678 | formatTimeMs(tmpSb, estimatedTime); |
| 6679 | pw.print(tmpSb); |
| 6680 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6681 | pw.println(" steps)"); |
| 6682 | } |
| 6683 | } |
| 6684 | } |
| 6685 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6686 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6687 | ArrayList<PackageChange> changes) { |
| 6688 | if (changes == null) { |
| 6689 | return; |
| 6690 | } |
| 6691 | pw.print(prefix); pw.println("Package changes:"); |
| 6692 | for (int i=0; i<changes.size(); i++) { |
| 6693 | PackageChange pc = changes.get(i); |
| 6694 | if (pc.mUpdate) { |
| 6695 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6696 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6697 | } else { |
| 6698 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6699 | } |
| 6700 | } |
| 6701 | } |
| 6702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6703 | /** |
| 6704 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6705 | * |
| 6706 | * @param pw a Printer to receive the dump output. |
| 6707 | */ |
| 6708 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6709 | 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] | 6710 | prepareForDumpLocked(); |
| 6711 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6712 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6713 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6714 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6715 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6716 | final long historyTotalSize = getHistoryTotalSize(); |
| 6717 | final long historyUsedSize = getHistoryUsedSize(); |
| 6718 | if (startIteratingHistoryLocked()) { |
| 6719 | try { |
| 6720 | pw.print("Battery History ("); |
| 6721 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6722 | pw.print("% used, "); |
| 6723 | printSizeValue(pw, historyUsedSize); |
| 6724 | pw.print(" used of "); |
| 6725 | printSizeValue(pw, historyTotalSize); |
| 6726 | pw.print(", "); |
| 6727 | pw.print(getHistoryStringPoolSize()); |
| 6728 | pw.print(" strings using "); |
| 6729 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6730 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6731 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6732 | pw.println(); |
| 6733 | } finally { |
| 6734 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6735 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6736 | } |
| 6737 | |
| 6738 | if (startIteratingOldHistoryLocked()) { |
| 6739 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6740 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6741 | pw.println("Old battery History:"); |
| 6742 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6743 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6744 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6745 | if (baseTime < 0) { |
| 6746 | baseTime = rec.time; |
| 6747 | } |
| 6748 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6749 | } |
| 6750 | pw.println(); |
| 6751 | } finally { |
| 6752 | finishIteratingOldHistoryLocked(); |
| 6753 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6754 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6755 | } |
| 6756 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6757 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6758 | return; |
| 6759 | } |
| 6760 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6761 | if (!filtering) { |
| 6762 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6763 | final int NU = uidStats.size(); |
| 6764 | boolean didPid = false; |
| 6765 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6766 | for (int i=0; i<NU; i++) { |
| 6767 | Uid uid = uidStats.valueAt(i); |
| 6768 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6769 | if (pids != null) { |
| 6770 | for (int j=0; j<pids.size(); j++) { |
| 6771 | Uid.Pid pid = pids.valueAt(j); |
| 6772 | if (!didPid) { |
| 6773 | pw.println("Per-PID Stats:"); |
| 6774 | didPid = true; |
| 6775 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6776 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6777 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6778 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6779 | pw.print(" wake time: "); |
| 6780 | TimeUtils.formatDuration(time, pw); |
| 6781 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6782 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6783 | } |
| 6784 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6785 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6786 | pw.println(); |
| 6787 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6791 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6792 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6793 | long timeRemaining = computeBatteryTimeRemaining( |
| 6794 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6795 | if (timeRemaining >= 0) { |
| 6796 | pw.print(" Estimated discharge time remaining: "); |
| 6797 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6798 | pw.println(); |
| 6799 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6800 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6801 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6802 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6803 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6804 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6805 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6806 | pw.println(); |
| 6807 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6808 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6809 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6810 | long timeRemaining = computeChargeTimeRemaining( |
| 6811 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6812 | if (timeRemaining >= 0) { |
| 6813 | pw.print(" Estimated charge time remaining: "); |
| 6814 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6815 | pw.println(); |
| 6816 | } |
| 6817 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6818 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6819 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6820 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6821 | pw.println("Daily stats:"); |
| 6822 | pw.print(" Current start time: "); |
| 6823 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6824 | getCurrentDailyStartTime()).toString()); |
| 6825 | pw.print(" Next min deadline: "); |
| 6826 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6827 | getNextMinDailyDeadline()).toString()); |
| 6828 | pw.print(" Next max deadline: "); |
| 6829 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6830 | getNextMaxDailyDeadline()).toString()); |
| 6831 | StringBuilder sb = new StringBuilder(64); |
| 6832 | int[] outInt = new int[1]; |
| 6833 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6834 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6835 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6836 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6837 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6838 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6839 | dsteps, false)) { |
| 6840 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6841 | sb, outInt); |
| 6842 | } |
| 6843 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6844 | csteps, false)) { |
| 6845 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6846 | sb, outInt); |
| 6847 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6848 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6849 | } else { |
| 6850 | pw.println(" Current daily steps:"); |
| 6851 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6852 | sb, outInt); |
| 6853 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6854 | sb, outInt); |
| 6855 | } |
| 6856 | } |
| 6857 | DailyItem dit; |
| 6858 | int curIndex = 0; |
| 6859 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6860 | curIndex++; |
| 6861 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6862 | pw.println(); |
| 6863 | } |
| 6864 | pw.print(" Daily from "); |
| 6865 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6866 | pw.print(" to "); |
| 6867 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6868 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6869 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6870 | if (dumpDurationSteps(pw, " ", |
| 6871 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6872 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6873 | sb, outInt); |
| 6874 | } |
| 6875 | if (dumpDurationSteps(pw, " ", |
| 6876 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6877 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6878 | sb, outInt); |
| 6879 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6880 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6881 | } else { |
| 6882 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6883 | sb, outInt); |
| 6884 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6885 | sb, outInt); |
| 6886 | } |
| 6887 | } |
| 6888 | pw.println(); |
| 6889 | } |
| 6890 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6891 | pw.println("Statistics since last charge:"); |
| 6892 | pw.println(" System starts: " + getStartCount() |
| 6893 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6894 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6895 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6896 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6898 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6899 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6900 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6902 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6903 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6904 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6905 | |
| 6906 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6907 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6908 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6909 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6910 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6911 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6912 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6913 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6914 | try { |
| 6915 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6916 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6917 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6918 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6919 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6920 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6921 | pw.print(",\""); |
| 6922 | String str = getHistoryTagPoolString(i); |
| 6923 | str = str.replace("\\", "\\\\"); |
| 6924 | str = str.replace("\"", "\\\""); |
| 6925 | pw.print(str); |
| 6926 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6927 | pw.println(); |
| 6928 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6929 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6930 | } finally { |
| 6931 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6932 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6933 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6934 | } |
| 6935 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6936 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6937 | return; |
| 6938 | } |
| 6939 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6940 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6941 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6942 | for (int i=0; i<apps.size(); i++) { |
| 6943 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6944 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6945 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6946 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6947 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6948 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6949 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6950 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6951 | } |
| 6952 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6953 | final int NU = uidStats.size(); |
| 6954 | String[] lineArgs = new String[2]; |
| 6955 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6956 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6957 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6958 | if (pkgs != null && !pkgs.second.value) { |
| 6959 | pkgs.second.value = true; |
| 6960 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6961 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6962 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6963 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6964 | (Object[])lineArgs); |
| 6965 | } |
| 6966 | } |
| 6967 | } |
| 6968 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6969 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6970 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6971 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6972 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6973 | if (timeRemaining >= 0) { |
| 6974 | lineArgs[0] = Long.toString(timeRemaining); |
| 6975 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6976 | (Object[])lineArgs); |
| 6977 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6978 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6979 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6980 | if (timeRemaining >= 0) { |
| 6981 | lineArgs[0] = Long.toString(timeRemaining); |
| 6982 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6983 | (Object[])lineArgs); |
| 6984 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6985 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6986 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6989 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6990 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6991 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6992 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6993 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6994 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6995 | prepareForDumpLocked(); |
| 6996 | |
| 6997 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6998 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6999 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 7000 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 7001 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 7002 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7003 | |
| 7004 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7005 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 7006 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 7007 | helper.create(this); |
| 7008 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 7009 | |
| 7010 | dumpProtoAppsLocked(proto, helper, apps); |
| 7011 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | proto.end(bToken); |
| 7015 | proto.flush(); |
| 7016 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7017 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7018 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 7019 | List<ApplicationInfo> apps) { |
| 7020 | final int which = STATS_SINCE_CHARGED; |
| 7021 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7022 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7023 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7024 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 7025 | |
| 7026 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 7027 | if (apps != null) { |
| 7028 | for (int i = 0; i < apps.size(); ++i) { |
| 7029 | ApplicationInfo ai = apps.get(i); |
| 7030 | int aid = UserHandle.getAppId(ai.uid); |
| 7031 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 7032 | if (pkgs == null) { |
| 7033 | pkgs = new ArrayList<String>(); |
| 7034 | aidToPackages.put(aid, pkgs); |
| 7035 | } |
| 7036 | pkgs.add(ai.packageName); |
| 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 7041 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7042 | if (sippers != null) { |
| 7043 | for (int i = 0; i < sippers.size(); ++i) { |
| 7044 | final BatterySipper bs = sippers.get(i); |
| 7045 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 7046 | // Others are handled by dumpProtoSystemLocked() |
| 7047 | continue; |
| 7048 | } |
| 7049 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 7050 | } |
| 7051 | } |
| 7052 | |
| 7053 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7054 | final int n = uidStats.size(); |
| 7055 | for (int iu = 0; iu < n; ++iu) { |
| 7056 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 7057 | final Uid u = uidStats.valueAt(iu); |
| 7058 | |
| 7059 | final int uid = uidStats.keyAt(iu); |
| 7060 | proto.write(UidProto.UID, uid); |
| 7061 | |
| 7062 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 7063 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 7064 | if (pkgs == null) { |
| 7065 | pkgs = new ArrayList<String>(); |
| 7066 | } |
| 7067 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 7068 | u.getPackageStats(); |
| 7069 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7070 | String pkg = packageStats.keyAt(ipkg); |
| 7071 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 7072 | packageStats.valueAt(ipkg).getServiceStats(); |
| 7073 | if (serviceStats.size() == 0) { |
| 7074 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 7075 | // example, "android") may be included in the packageStats that aren't part of |
| 7076 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 7077 | // These packages won't be a part in the pkgs List. |
| 7078 | continue; |
| 7079 | } |
| 7080 | |
| 7081 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7082 | proto.write(UidProto.Package.NAME, pkg); |
| 7083 | // Remove from the packages list since we're logging it here. |
| 7084 | pkgs.remove(pkg); |
| 7085 | |
| 7086 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 7087 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 7088 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 7089 | |
| 7090 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 7091 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 7092 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 7093 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 7094 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 7095 | |
| 7096 | proto.end(sToken); |
| 7097 | } |
| 7098 | proto.end(pToken); |
| 7099 | } |
| 7100 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 7101 | // from PackageManager data. Packages are only included in packageStats if there was |
| 7102 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 7103 | for (String p : pkgs) { |
| 7104 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7105 | proto.write(UidProto.Package.NAME, p); |
| 7106 | proto.end(pToken); |
| 7107 | } |
| 7108 | |
| 7109 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 7110 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 7111 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 7112 | // Times are since reset (regardless of 'which') |
| 7113 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 7114 | final Timer bgTimer = timer.getSubTimer(); |
| 7115 | final long bgTimeMs = bgTimer != null |
| 7116 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 7117 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 7118 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 7119 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 7120 | proto.end(awToken); |
| 7121 | } |
| 7122 | |
| 7123 | // Audio (AUDIO_DATA) |
| 7124 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7125 | |
| 7126 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7127 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7128 | u.getBluetoothControllerActivity(), which); |
| 7129 | |
| 7130 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7131 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7132 | if (bleTimer != null) { |
| 7133 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7134 | |
| 7135 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7136 | rawRealtimeUs, which); |
| 7137 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7138 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7139 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7140 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7141 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7142 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7143 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7144 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7145 | // Result counters |
| 7146 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7147 | u.getBluetoothScanResultCounter() != null |
| 7148 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7149 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7150 | u.getBluetoothScanResultBgCounter() != null |
| 7151 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7152 | |
| 7153 | proto.end(bmToken); |
| 7154 | } |
| 7155 | |
| 7156 | // Camera (CAMERA_DATA) |
| 7157 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7158 | |
| 7159 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7160 | final long cpuToken = proto.start(UidProto.CPU); |
| 7161 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7162 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7163 | |
| 7164 | final long[] cpuFreqs = getCpuFreqs(); |
| 7165 | if (cpuFreqs != null) { |
| 7166 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7167 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7168 | // screenOffCpuFreqTimes. |
| 7169 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7170 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7171 | if (screenOffCpuFreqTimeMs == null) { |
| 7172 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7173 | } |
| 7174 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7175 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7176 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7177 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7178 | cpuFreqTimeMs[ic]); |
| 7179 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7180 | screenOffCpuFreqTimeMs[ic]); |
| 7181 | proto.end(cToken); |
| 7182 | } |
| 7183 | } |
| 7184 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7185 | |
| 7186 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7187 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7188 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7189 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7190 | if (screenOffTimesMs == null) { |
| 7191 | screenOffTimesMs = new long[timesMs.length]; |
| 7192 | } |
| 7193 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7194 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7195 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7196 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7197 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7198 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7199 | timesMs[ic]); |
| 7200 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7201 | screenOffTimesMs[ic]); |
| 7202 | proto.end(cToken); |
| 7203 | } |
| 7204 | proto.end(procToken); |
| 7205 | } |
| 7206 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7207 | proto.end(cpuToken); |
| 7208 | |
| 7209 | // Flashlight (FLASHLIGHT_DATA) |
| 7210 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7211 | rawRealtimeUs, which); |
| 7212 | |
| 7213 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7214 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7215 | rawRealtimeUs, which); |
| 7216 | |
| 7217 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7218 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7219 | rawRealtimeUs, which); |
| 7220 | |
| 7221 | // Job completion (JOB_COMPLETION_DATA) |
| 7222 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7223 | final int[] reasons = new int[]{ |
| 7224 | JobParameters.REASON_CANCELED, |
| 7225 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7226 | JobParameters.REASON_PREEMPT, |
| 7227 | JobParameters.REASON_TIMEOUT, |
| 7228 | JobParameters.REASON_DEVICE_IDLE, |
| 7229 | }; |
| 7230 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7231 | SparseIntArray types = completions.valueAt(ic); |
| 7232 | if (types != null) { |
| 7233 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7234 | |
| 7235 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7236 | |
| 7237 | for (int r : reasons) { |
| 7238 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7239 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7240 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7241 | proto.end(rToken); |
| 7242 | } |
| 7243 | |
| 7244 | proto.end(jcToken); |
| 7245 | } |
| 7246 | } |
| 7247 | |
| 7248 | // Scheduled jobs (JOB_DATA) |
| 7249 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7250 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7251 | final Timer timer = jobs.valueAt(ij); |
| 7252 | final Timer bgTimer = timer.getSubTimer(); |
| 7253 | final long jToken = proto.start(UidProto.JOBS); |
| 7254 | |
| 7255 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7256 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7257 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7258 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7259 | |
| 7260 | proto.end(jToken); |
| 7261 | } |
| 7262 | |
| 7263 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7264 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7265 | u.getModemControllerActivity(), which); |
| 7266 | |
| 7267 | // Network stats (NETWORK_DATA) |
| 7268 | final long nToken = proto.start(UidProto.NETWORK); |
| 7269 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7270 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7271 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7272 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7273 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7274 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7275 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7276 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7277 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7278 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7279 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7280 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7281 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7282 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7283 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7284 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7285 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7286 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7287 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7288 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7289 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7290 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7291 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7292 | u.getMobileRadioActiveCount(which)); |
| 7293 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7294 | u.getMobileRadioApWakeupCount(which)); |
| 7295 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7296 | u.getWifiRadioApWakeupCount(which)); |
| 7297 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7298 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7299 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7300 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7301 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7302 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7303 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7304 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7305 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7306 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7307 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7308 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7309 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7310 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7311 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7312 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7313 | proto.end(nToken); |
| 7314 | |
| 7315 | // Power use item (POWER_USE_ITEM_DATA) |
| 7316 | BatterySipper bs = uidToSipper.get(uid); |
| 7317 | if (bs != null) { |
| 7318 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7319 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7320 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7321 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7322 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7323 | bs.proportionalSmearMah); |
| 7324 | proto.end(bsToken); |
| 7325 | } |
| 7326 | |
| 7327 | // Processes (PROCESS_DATA) |
| 7328 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7329 | u.getProcessStats(); |
| 7330 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7331 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7332 | final long prToken = proto.start(UidProto.PROCESS); |
| 7333 | |
| 7334 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7335 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7336 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7337 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7338 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7339 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7340 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7341 | |
| 7342 | proto.end(prToken); |
| 7343 | } |
| 7344 | |
| 7345 | // Sensors (SENSOR_DATA) |
| 7346 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7347 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7348 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7349 | final Timer timer = se.getSensorTime(); |
| 7350 | if (timer == null) { |
| 7351 | continue; |
| 7352 | } |
| 7353 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7354 | final int sensorNumber = sensors.keyAt(ise); |
| 7355 | final long seToken = proto.start(UidProto.SENSORS); |
| 7356 | |
| 7357 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7358 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7359 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7360 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7361 | |
| 7362 | proto.end(seToken); |
| 7363 | } |
| 7364 | |
| 7365 | // State times (STATE_TIME_DATA) |
| 7366 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7367 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7368 | if (durMs == 0) { |
| 7369 | continue; |
| 7370 | } |
| 7371 | final long stToken = proto.start(UidProto.STATES); |
| 7372 | proto.write(UidProto.StateTime.STATE, ips); |
| 7373 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7374 | proto.end(stToken); |
| 7375 | } |
| 7376 | |
| 7377 | // Syncs (SYNC_DATA) |
| 7378 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7379 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7380 | final Timer timer = syncs.valueAt(isy); |
| 7381 | final Timer bgTimer = timer.getSubTimer(); |
| 7382 | final long syToken = proto.start(UidProto.SYNCS); |
| 7383 | |
| 7384 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7385 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7386 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7387 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7388 | |
| 7389 | proto.end(syToken); |
| 7390 | } |
| 7391 | |
| 7392 | // User activity (USER_ACTIVITY_DATA) |
| 7393 | if (u.hasUserActivity()) { |
| 7394 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7395 | int val = u.getUserActivityCount(i, which); |
| 7396 | if (val != 0) { |
| 7397 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7398 | proto.write(UidProto.UserActivity.NAME, i); |
| 7399 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7400 | proto.end(uaToken); |
| 7401 | } |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | // Vibrator (VIBRATOR_DATA) |
| 7406 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7407 | |
| 7408 | // Video (VIDEO_DATA) |
| 7409 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7410 | |
| 7411 | // Wakelocks (WAKELOCK_DATA) |
| 7412 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7413 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7414 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7415 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7416 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7417 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7418 | rawRealtimeUs, which); |
| 7419 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7420 | if (pTimer != null) { |
| 7421 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7422 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7423 | rawRealtimeUs, which); |
| 7424 | } |
| 7425 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7426 | rawRealtimeUs, which); |
| 7427 | proto.end(wToken); |
| 7428 | } |
| 7429 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7430 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7431 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7432 | rawRealtimeUs, which); |
| 7433 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7434 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7435 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7436 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7437 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7438 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7439 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7440 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7441 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7442 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7443 | proto.end(waToken); |
| 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7448 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7449 | u.getWifiControllerActivity(), which); |
| 7450 | |
| 7451 | // Wifi data (WIFI_DATA) |
| 7452 | final long wToken = proto.start(UidProto.WIFI); |
| 7453 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7454 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7455 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7456 | rawRealtimeUs, which); |
| 7457 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7458 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7459 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7460 | rawRealtimeUs, which); |
| 7461 | proto.end(wToken); |
| 7462 | |
| 7463 | proto.end(uTkn); |
| 7464 | } |
| 7465 | } |
| 7466 | |
| 7467 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7468 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7469 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7470 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7471 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7472 | final int which = STATS_SINCE_CHARGED; |
| 7473 | |
| 7474 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7475 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7476 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7477 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7478 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7479 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7480 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7481 | computeUptime(rawUptimeUs, which) / 1000); |
| 7482 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7483 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7484 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7485 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7486 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7487 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7488 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7489 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7490 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7491 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7492 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7493 | getEstimatedBatteryCapacity()); |
| 7494 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7495 | getMinLearnedBatteryCapacity()); |
| 7496 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7497 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7498 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7499 | |
| 7500 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7501 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7502 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7503 | getLowDischargeAmountSinceCharge()); |
| 7504 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7505 | getHighDischargeAmountSinceCharge()); |
| 7506 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7507 | getDischargeAmountScreenOnSinceCharge()); |
| 7508 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7509 | getDischargeAmountScreenOffSinceCharge()); |
| 7510 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7511 | getDischargeAmountScreenDozeSinceCharge()); |
| 7512 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7513 | getUahDischarge(which) / 1000); |
| 7514 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7515 | getUahDischargeScreenOff(which) / 1000); |
| 7516 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7517 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7518 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7519 | getUahDischargeLightDoze(which) / 1000); |
| 7520 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7521 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7522 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7523 | |
| 7524 | // Time remaining |
| 7525 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7526 | // 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] | 7527 | if (timeRemainingUs >= 0) { |
| 7528 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7529 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7530 | } else { |
| 7531 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7532 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7533 | if (timeRemainingUs >= 0) { |
| 7534 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7535 | } else { |
| 7536 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7537 | } |
| 7538 | } |
| 7539 | |
| 7540 | // Charge step (CHARGE_STEP_DATA) |
| 7541 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7542 | |
| 7543 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7544 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7545 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7546 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7547 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7548 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7549 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7550 | } |
| 7551 | |
| 7552 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7553 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7554 | |
| 7555 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7556 | final long[] cpuFreqs = getCpuFreqs(); |
| 7557 | if (cpuFreqs != null) { |
| 7558 | for (long i : cpuFreqs) { |
| 7559 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7560 | } |
| 7561 | } |
| 7562 | |
| 7563 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7564 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7565 | getBluetoothControllerActivity(), which); |
| 7566 | |
| 7567 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7568 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7569 | getModemControllerActivity(), which); |
| 7570 | |
| 7571 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7572 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7573 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7574 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7575 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7576 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7577 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7578 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7579 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7580 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7581 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7582 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7583 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7584 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7585 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7586 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7587 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7588 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7589 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7590 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7591 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7592 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7593 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7594 | |
| 7595 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7596 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7597 | getWifiControllerActivity(), which); |
| 7598 | |
| 7599 | |
| 7600 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7601 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7602 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7603 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7604 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7605 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7606 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7607 | |
| 7608 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7609 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7610 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7611 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7612 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7613 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7614 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7615 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7616 | } |
| 7617 | |
| 7618 | // Misc (MISC_DATA) |
| 7619 | // Calculate wakelock times across all uids. |
| 7620 | long fullWakeLockTimeTotalUs = 0; |
| 7621 | long partialWakeLockTimeTotalUs = 0; |
| 7622 | |
| 7623 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7624 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7625 | final Uid u = uidStats.valueAt(iu); |
| 7626 | |
| 7627 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7628 | u.getWakelockStats(); |
| 7629 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7630 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7631 | |
| 7632 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7633 | if (fullWakeTimer != null) { |
| 7634 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7635 | which); |
| 7636 | } |
| 7637 | |
| 7638 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7639 | if (partialWakeTimer != null) { |
| 7640 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7641 | rawRealtimeUs, which); |
| 7642 | } |
| 7643 | } |
| 7644 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7645 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7646 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7647 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7648 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7649 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7650 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7651 | fullWakeLockTimeTotalUs / 1000); |
| 7652 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7653 | partialWakeLockTimeTotalUs / 1000); |
| 7654 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7655 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7656 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7657 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7658 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7659 | getMobileRadioActiveCount(which)); |
| 7660 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7661 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7662 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7663 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7664 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7665 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7666 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7667 | getNumConnectivityChange(which)); |
| 7668 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7669 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7670 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7671 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7672 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7673 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7674 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7675 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7676 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7677 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7678 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7679 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7680 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7681 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7682 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7683 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7684 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7685 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7686 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7687 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7688 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7689 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7690 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7691 | final long multicastWakeLockTimeTotalUs = |
| 7692 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7693 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7694 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7695 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7696 | multicastWakeLockTimeTotalUs / 1000); |
| 7697 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7698 | multicastWakeLockCountTotal); |
| 7699 | proto.end(wmctToken); |
| 7700 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7701 | // Power use item (POWER_USE_ITEM_DATA) |
| 7702 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7703 | if (sippers != null) { |
| 7704 | for (int i = 0; i < sippers.size(); ++i) { |
| 7705 | final BatterySipper bs = sippers.get(i); |
| 7706 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7707 | int uid = 0; |
| 7708 | switch (bs.drainType) { |
| 7709 | case IDLE: |
| 7710 | n = SystemProto.PowerUseItem.IDLE; |
| 7711 | break; |
| 7712 | case CELL: |
| 7713 | n = SystemProto.PowerUseItem.CELL; |
| 7714 | break; |
| 7715 | case PHONE: |
| 7716 | n = SystemProto.PowerUseItem.PHONE; |
| 7717 | break; |
| 7718 | case WIFI: |
| 7719 | n = SystemProto.PowerUseItem.WIFI; |
| 7720 | break; |
| 7721 | case BLUETOOTH: |
| 7722 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7723 | break; |
| 7724 | case SCREEN: |
| 7725 | n = SystemProto.PowerUseItem.SCREEN; |
| 7726 | break; |
| 7727 | case FLASHLIGHT: |
| 7728 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7729 | break; |
| 7730 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7731 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7732 | continue; |
| 7733 | case USER: |
| 7734 | n = SystemProto.PowerUseItem.USER; |
| 7735 | uid = UserHandle.getUid(bs.userId, 0); |
| 7736 | break; |
| 7737 | case UNACCOUNTED: |
| 7738 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7739 | break; |
| 7740 | case OVERCOUNTED: |
| 7741 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7742 | break; |
| 7743 | case CAMERA: |
| 7744 | n = SystemProto.PowerUseItem.CAMERA; |
| 7745 | break; |
| 7746 | case MEMORY: |
| 7747 | n = SystemProto.PowerUseItem.MEMORY; |
| 7748 | break; |
| 7749 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7750 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7751 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7752 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7753 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7754 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7755 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7756 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7757 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7758 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7759 | } |
| 7760 | } |
| 7761 | |
| 7762 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7763 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7764 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7765 | helper.getPowerProfile().getBatteryCapacity()); |
| 7766 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7767 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7768 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7769 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7770 | |
| 7771 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7772 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7773 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7774 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7775 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7776 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7777 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7778 | ent.getValue(), rawRealtimeUs, which); |
| 7779 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7780 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7781 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7782 | } |
| 7783 | |
| 7784 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7785 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7786 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7787 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7788 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7789 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7790 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7791 | } |
| 7792 | |
| 7793 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7794 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7795 | which); |
| 7796 | |
| 7797 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7798 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7799 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7800 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7801 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7802 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7803 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7804 | } |
| 7805 | |
| 7806 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7807 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7808 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7809 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7810 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7811 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7812 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7813 | } |
| 7814 | |
| 7815 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7816 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7817 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7818 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7819 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7820 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7821 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7822 | } |
| 7823 | |
| 7824 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7825 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7826 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7827 | proto.write(SystemProto.WifiState.NAME, i); |
| 7828 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7829 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7830 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7831 | } |
| 7832 | |
| 7833 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7834 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7835 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7836 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7837 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7838 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7839 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7840 | } |
| 7841 | |
| 7842 | proto.end(sToken); |
| 7843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7844 | } |