Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 20 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 22 | import android.content.pm.ApplicationInfo; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 23 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 24 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 25 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 26 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 27 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 28 | import android.util.MutableBoolean; |
| 29 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.util.Printer; |
| 31 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 32 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 33 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 34 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 35 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 36 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 37 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame^] | 38 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 39 | import com.android.internal.os.BatterySipper; |
| 40 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 42 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 43 | import java.io.PrintWriter; |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.Collections; |
| 46 | import java.util.Comparator; |
| 47 | import java.util.Formatter; |
| 48 | import java.util.HashMap; |
| 49 | import java.util.List; |
| 50 | import java.util.Map; |
| 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | /** |
| 53 | * A class providing access to battery usage statistics, including information on |
| 54 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 55 | * except where indicated otherwise. |
| 56 | * @hide |
| 57 | */ |
| 58 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 59 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
| 61 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 62 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 63 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 64 | |
| 65 | /** @hide */ |
| 66 | public static final String SERVICE_NAME = "batterystats"; |
| 67 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | /** |
| 69 | * A constant indicating a partial wake lock timer. |
| 70 | */ |
| 71 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 72 | |
| 73 | /** |
| 74 | * A constant indicating a full wake lock timer. |
| 75 | */ |
| 76 | public static final int WAKE_TYPE_FULL = 1; |
| 77 | |
| 78 | /** |
| 79 | * A constant indicating a window wake lock timer. |
| 80 | */ |
| 81 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | /** |
| 84 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | */ |
| 86 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 87 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 88 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 89 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 90 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 91 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 92 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 93 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 94 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 95 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 96 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 97 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 98 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 99 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 100 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 101 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 103 | /** |
| 104 | * A constant indicating a wifi multicast timer |
| 105 | */ |
| 106 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 109 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 110 | */ |
| 111 | public static final int VIDEO_TURNED_ON = 8; |
| 112 | |
| 113 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 114 | * A constant indicating a vibrator on timer |
| 115 | */ |
| 116 | public static final int VIBRATOR_ON = 9; |
| 117 | |
| 118 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 119 | * A constant indicating a foreground activity timer |
| 120 | */ |
| 121 | public static final int FOREGROUND_ACTIVITY = 10; |
| 122 | |
| 123 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 124 | * A constant indicating a wifi batched scan is active |
| 125 | */ |
| 126 | public static final int WIFI_BATCHED_SCAN = 11; |
| 127 | |
| 128 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 129 | * A constant indicating a process state timer |
| 130 | */ |
| 131 | public static final int PROCESS_STATE = 12; |
| 132 | |
| 133 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 134 | * A constant indicating a sync timer |
| 135 | */ |
| 136 | public static final int SYNC = 13; |
| 137 | |
| 138 | /** |
| 139 | * A constant indicating a job timer |
| 140 | */ |
| 141 | public static final int JOB = 14; |
| 142 | |
| 143 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 144 | * A constant indicating an audio turn on timer |
| 145 | */ |
| 146 | public static final int AUDIO_TURNED_ON = 15; |
| 147 | |
| 148 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 149 | * A constant indicating a flashlight turn on timer |
| 150 | */ |
| 151 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 152 | |
| 153 | /** |
| 154 | * A constant indicating a camera turn on timer |
| 155 | */ |
| 156 | public static final int CAMERA_TURNED_ON = 17; |
| 157 | |
| 158 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 159 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 160 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 161 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 164 | * A constant indicating a bluetooth scan timer. |
| 165 | */ |
| 166 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 167 | |
| 168 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 169 | * A constant indicating an aggregated partial wake lock timer. |
| 170 | */ |
| 171 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 172 | |
| 173 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 174 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 175 | */ |
| 176 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 177 | |
| 178 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 179 | * A constant indicating a foreground service timer |
| 180 | */ |
| 181 | public static final int FOREGROUND_SERVICE = 22; |
| 182 | |
| 183 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 184 | * A constant indicating an aggregate wifi multicast timer |
| 185 | */ |
| 186 | public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; |
| 187 | |
| 188 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | * Include all of the data in the stats, including previously saved data. |
| 190 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 191 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | |
| 193 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | * Include only the current run in the stats. |
| 195 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 196 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Include only the run since the last time the device was unplugged in the stats. |
| 200 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 201 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 202 | |
| 203 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 204 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 205 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 206 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 209 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 210 | * |
| 211 | * New in version 19: |
| 212 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 213 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 214 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 215 | * New in version 21: |
| 216 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 217 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 218 | * - BLE scan result count |
| 219 | * - CPU frequency time per uid |
| 220 | * New in version 22: |
| 221 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 222 | * - Background partial wakelock time & count |
| 223 | * New in version 23: |
| 224 | * - Logging smeared power model values |
| 225 | * New in version 24: |
| 226 | * - Fixed bugs in background timers and BLE scan time |
| 227 | * New in version 25: |
| 228 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 229 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 230 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 231 | * New in version 27: |
| 232 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 233 | * New in version 28: |
| 234 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 235 | * - WiFi Multicast Wakelock statistics (count & duration) |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 236 | * New in version 29: |
| 237 | * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced. |
| 238 | * - CPU times per UID process state |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 239 | */ |
Kweku Adams | a8943cb | 2017-12-22 13:21:06 -0800 | [diff] [blame] | 240 | static final int CHECKIN_VERSION = 29; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * 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] | 244 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 245 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 246 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 247 | private static final long BYTES_PER_KB = 1024; |
| 248 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 249 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 250 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 251 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 252 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 253 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 255 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 256 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 257 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 258 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 259 | // rpm line is: |
| 260 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 261 | // screen-off time, screen-off count |
| 262 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 263 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 264 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 265 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 266 | // fgs line is: |
| 267 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 268 | // foreground service time, count |
| 269 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 270 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 271 | // wl line is: |
| 272 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 273 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 274 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 275 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 276 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 277 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 278 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 279 | // awl line is: |
| 280 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 281 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 282 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 283 | private static final String SYNC_DATA = "sy"; |
| 284 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 285 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 286 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 287 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 288 | private static final String NETWORK_DATA = "nt"; |
| 289 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 290 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 291 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 292 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 293 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 294 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 295 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 296 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 297 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 298 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 299 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 300 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 301 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 302 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 303 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 304 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 305 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 306 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 307 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 308 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 309 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 310 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 311 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 312 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 313 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 314 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 315 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 316 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 317 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 318 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 319 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 320 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 321 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 322 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 323 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 324 | private static final String FLASHLIGHT_DATA = "fla"; |
| 325 | private static final String CAMERA_DATA = "cam"; |
| 326 | private static final String VIDEO_DATA = "vid"; |
| 327 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 328 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 329 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 331 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 332 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 333 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 335 | |
| 336 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 337 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 338 | * |
| 339 | * Other types might include times spent in foreground, background etc. |
| 340 | */ |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 341 | @VisibleForTesting |
| 342 | public static final String UID_TIMES_TYPE_ALL = "A"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 343 | |
| 344 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 345 | * State for keeping track of counting information. |
| 346 | */ |
| 347 | public static abstract class Counter { |
| 348 | |
| 349 | /** |
| 350 | * Returns the count associated with this Counter for the |
| 351 | * selected type of statistics. |
| 352 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 353 | * @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] | 354 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 355 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * Temporary for debugging. |
| 359 | */ |
| 360 | public abstract void logState(Printer pw, String prefix); |
| 361 | } |
| 362 | |
| 363 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 364 | * State for keeping track of long counting information. |
| 365 | */ |
| 366 | public static abstract class LongCounter { |
| 367 | |
| 368 | /** |
| 369 | * Returns the count associated with this Counter for the |
| 370 | * selected type of statistics. |
| 371 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 372 | * @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] | 373 | */ |
| 374 | public abstract long getCountLocked(int which); |
| 375 | |
| 376 | /** |
| 377 | * Temporary for debugging. |
| 378 | */ |
| 379 | public abstract void logState(Printer pw, String prefix); |
| 380 | } |
| 381 | |
| 382 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 383 | * State for keeping track of array of long counting information. |
| 384 | */ |
| 385 | public static abstract class LongCounterArray { |
| 386 | /** |
| 387 | * Returns the counts associated with this Counter for the |
| 388 | * selected type of statistics. |
| 389 | * |
| 390 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 391 | */ |
| 392 | public abstract long[] getCountsLocked(int which); |
| 393 | |
| 394 | /** |
| 395 | * Temporary for debugging. |
| 396 | */ |
| 397 | public abstract void logState(Printer pw, String prefix); |
| 398 | } |
| 399 | |
| 400 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 401 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 402 | * radio controller. |
| 403 | */ |
| 404 | public static abstract class ControllerActivityCounter { |
| 405 | /** |
| 406 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 407 | * idle state. |
| 408 | */ |
| 409 | public abstract LongCounter getIdleTimeCounter(); |
| 410 | |
| 411 | /** |
| 412 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 413 | * receive state. |
| 414 | */ |
| 415 | public abstract LongCounter getRxTimeCounter(); |
| 416 | |
| 417 | /** |
| 418 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 419 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 420 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 421 | * various transmit level states. |
| 422 | */ |
| 423 | public abstract LongCounter[] getTxTimeCounters(); |
| 424 | |
| 425 | /** |
| 426 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 427 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 428 | * yield a value of 0 if the device doesn't support power calculations. |
| 429 | */ |
| 430 | public abstract LongCounter getPowerCounter(); |
| 431 | } |
| 432 | |
| 433 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | * State for keeping track of timing information. |
| 435 | */ |
| 436 | public static abstract class Timer { |
| 437 | |
| 438 | /** |
| 439 | * Returns the count associated with this Timer for the |
| 440 | * selected type of statistics. |
| 441 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 442 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 444 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | |
| 446 | /** |
| 447 | * Returns the total time in microseconds associated with this Timer for the |
| 448 | * selected type of statistics. |
| 449 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 450 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 451 | * @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] | 452 | * @return a time in microseconds |
| 453 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 454 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 457 | * Returns the total time in microseconds associated with this Timer since the |
| 458 | * 'mark' was last set. |
| 459 | * |
| 460 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 461 | * @return a time in microseconds |
| 462 | */ |
| 463 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 464 | |
| 465 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 466 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 467 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 468 | */ |
| 469 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * 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] | 475 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 476 | */ |
| 477 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 478 | return -1; |
| 479 | } |
| 480 | |
| 481 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 482 | * 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] | 483 | * |
| 484 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 485 | * been on since reset. |
| 486 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 487 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 488 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 489 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 490 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 491 | */ |
| 492 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 493 | return -1; |
| 494 | } |
| 495 | |
| 496 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 497 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 498 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 499 | * |
| 500 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 501 | */ |
| 502 | public Timer getSubTimer() { |
| 503 | return null; |
| 504 | } |
| 505 | |
| 506 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 507 | * Returns whether the timer is currently running. Some types of timers |
| 508 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 509 | * and report false. |
| 510 | */ |
| 511 | public boolean isRunningLocked() { |
| 512 | return false; |
| 513 | } |
| 514 | |
| 515 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | * Temporary for debugging. |
| 517 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 518 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 522 | * Maps the ActivityManager procstate into corresponding BatteryStats procstate. |
| 523 | */ |
| 524 | public static int mapToInternalProcessState(int procState) { |
| 525 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 526 | return ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 527 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 528 | return Uid.PROCESS_STATE_TOP; |
| 529 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 530 | // Persistent and other foreground states go here. |
| 531 | return Uid.PROCESS_STATE_FOREGROUND_SERVICE; |
| 532 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 533 | // Persistent and other foreground states go here. |
| 534 | return Uid.PROCESS_STATE_FOREGROUND; |
| 535 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 536 | return Uid.PROCESS_STATE_BACKGROUND; |
| 537 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 538 | return Uid.PROCESS_STATE_TOP_SLEEPING; |
| 539 | } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { |
| 540 | return Uid.PROCESS_STATE_HEAVY_WEIGHT; |
| 541 | } else { |
| 542 | return Uid.PROCESS_STATE_CACHED; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | * The statistics associated with a particular uid. |
| 548 | */ |
| 549 | public static abstract class Uid { |
| 550 | |
| 551 | /** |
| 552 | * Returns a mapping containing wakelock statistics. |
| 553 | * |
| 554 | * @return a Map from Strings to Uid.Wakelock objects. |
| 555 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 556 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | |
| 558 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 559 | * Returns the WiFi Multicast Wakelock statistics. |
| 560 | * |
| 561 | * @return a Timer Object for the per uid Multicast statistics. |
| 562 | */ |
| 563 | public abstract Timer getMulticastWakelockStats(); |
| 564 | |
| 565 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 566 | * Returns a mapping containing sync statistics. |
| 567 | * |
| 568 | * @return a Map from Strings to Timer objects. |
| 569 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 570 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * Returns a mapping containing scheduled job statistics. |
| 574 | * |
| 575 | * @return a Map from Strings to Timer objects. |
| 576 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 577 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 578 | |
| 579 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 580 | * Returns statistics about how jobs have completed. |
| 581 | * |
| 582 | * @return A Map of String job names to completion type -> count mapping. |
| 583 | */ |
| 584 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 585 | |
| 586 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | * The statistics associated with a particular wake lock. |
| 588 | */ |
| 589 | public static abstract class Wakelock { |
| 590 | public abstract Timer getWakeTime(int type); |
| 591 | } |
| 592 | |
| 593 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 594 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 595 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 596 | * wakelocks that overlap in time (and therefore over-counts). |
| 597 | */ |
| 598 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 599 | |
| 600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | * Returns a mapping containing sensor statistics. |
| 602 | * |
| 603 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 604 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 605 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | |
| 607 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 608 | * Returns a mapping containing active process data. |
| 609 | */ |
| 610 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 611 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 612 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | * Returns a mapping containing process statistics. |
| 614 | * |
| 615 | * @return a Map from Strings to Uid.Proc objects. |
| 616 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 617 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * Returns a mapping containing package statistics. |
| 621 | * |
| 622 | * @return a Map from Strings to Uid.Pkg objects. |
| 623 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 624 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 625 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 626 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 627 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 628 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 629 | |
| 630 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | * {@hide} |
| 632 | */ |
| 633 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 634 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 635 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 636 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 637 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 638 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 639 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 640 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 641 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 642 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 643 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 644 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 645 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 646 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 647 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 648 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 649 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 650 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 651 | /** |
| 652 | * Returns the timer keeping track of wifi scans. |
| 653 | */ |
| 654 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 655 | public abstract int getWifiScanBackgroundCount(int which); |
| 656 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 657 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 658 | /** |
| 659 | * Returns the timer keeping track of background wifi scans. |
| 660 | */ |
| 661 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 662 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 663 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 664 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 665 | public abstract Timer getAudioTurnedOnTimer(); |
| 666 | public abstract Timer getVideoTurnedOnTimer(); |
| 667 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 668 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 669 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 670 | |
| 671 | /** |
| 672 | * Returns the timer keeping track of Foreground Service time |
| 673 | */ |
| 674 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 675 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 676 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 677 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 678 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 679 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 680 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 681 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 682 | public abstract long[] getCpuFreqTimes(int which); |
| 683 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 684 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 685 | /** |
| 686 | * Returns cpu times of an uid at a particular process state. |
| 687 | */ |
| 688 | public abstract long[] getCpuFreqTimes(int which, int procState); |
| 689 | /** |
| 690 | * Returns cpu times of an uid while the screen if off at a particular process state. |
| 691 | */ |
| 692 | public abstract long[] getScreenOffCpuFreqTimes(int which, int procState); |
| 693 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 694 | // Note: the following times are disjoint. They can be added together to find the |
| 695 | // total time a uid has had any processes running at all. |
| 696 | |
| 697 | /** |
| 698 | * Time this uid has any processes in the top state (or above such as persistent). |
| 699 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 700 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 701 | /** |
| 702 | * Time this uid has any process with a started out bound foreground service, but |
| 703 | * none in the "top" state. |
| 704 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 705 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 706 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 707 | * Time this uid has any process in an active foreground state, but none in the |
| 708 | * "top sleeping" or better state. |
| 709 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 710 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 711 | /** |
| 712 | * Time this uid has any process in an active background state, but none in the |
| 713 | * "foreground" or better state. |
| 714 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 715 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 716 | /** |
| 717 | * Time this uid has any process that is top while the device is sleeping, but not |
| 718 | * active for any other reason. We kind-of consider it a kind of cached process |
| 719 | * for execution restrictions. |
| 720 | */ |
| 721 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 722 | /** |
| 723 | * Time this uid has any process that is in the background but it has an activity |
| 724 | * marked as "can't save state". This is essentially a cached process, though the |
| 725 | * system will try much harder than normal to avoid killing it. |
| 726 | */ |
| 727 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 728 | /** |
| 729 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 730 | * other active states. |
| 731 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 732 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 733 | /** |
| 734 | * Total number of process states we track. |
| 735 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 736 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 737 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 738 | // Used in dump |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 739 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 740 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 741 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 742 | }; |
| 743 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 744 | // Used in checkin dump |
| 745 | @VisibleForTesting |
| 746 | public static final String[] UID_PROCESS_TYPES = { |
| 747 | "T", // TOP |
| 748 | "FS", // FOREGROUND_SERVICE |
| 749 | "F", // FOREGROUND |
| 750 | "B", // BACKGROUND |
| 751 | "TS", // TOP_SLEEPING |
| 752 | "HW", // HEAVY_WEIGHT |
| 753 | "C" // CACHED |
| 754 | }; |
| 755 | |
| 756 | /** |
| 757 | * When the process exits one of these states, we need to make sure cpu time in this state |
| 758 | * is not attributed to any non-critical process states. |
| 759 | */ |
| 760 | public static final int[] CRITICAL_PROC_STATES = { |
| 761 | PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND |
| 762 | }; |
| 763 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 764 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 765 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 766 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 767 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 769 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 770 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 771 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 772 | * Note that these must match the constants in android.os.PowerManager. |
| 773 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 774 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 775 | */ |
| 776 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 777 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 778 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 779 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 780 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 781 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 782 | public abstract void noteUserActivityLocked(int type); |
| 783 | public abstract boolean hasUserActivity(); |
| 784 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 785 | |
| 786 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 787 | public abstract long getNetworkActivityBytes(int type, int which); |
| 788 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 789 | public abstract long getMobileRadioActiveTime(int which); |
| 790 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 791 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 792 | /** |
| 793 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 794 | */ |
| 795 | public abstract long getUserCpuTimeUs(int which); |
| 796 | |
| 797 | /** |
| 798 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 799 | */ |
| 800 | public abstract long getSystemCpuTimeUs(int which); |
| 801 | |
| 802 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 803 | * 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] | 804 | * given CPU cluster. |
| 805 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 806 | * @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] | 807 | * @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] | 808 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 809 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 810 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 811 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 812 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 813 | /** |
| 814 | * Returns the number of times this UID woke up the Application Processor to |
| 815 | * process a mobile radio packet. |
| 816 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 817 | */ |
| 818 | public abstract long getMobileRadioApWakeupCount(int which); |
| 819 | |
| 820 | /** |
| 821 | * Returns the number of times this UID woke up the Application Processor to |
| 822 | * process a WiFi packet. |
| 823 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 824 | */ |
| 825 | public abstract long getWifiRadioApWakeupCount(int which); |
| 826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 828 | /* |
| 829 | * FIXME: it's not correct to use this magic value because it |
| 830 | * could clash with a sensor handle (which are defined by |
| 831 | * the sensor HAL, and therefore out of our control |
| 832 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | // Magic sensor number for the GPS. |
| 834 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 839 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 840 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 841 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 844 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 845 | public int mWakeNesting; |
| 846 | public long mWakeSumMs; |
| 847 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 848 | } |
| 849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | /** |
| 851 | * The statistics associated with a particular process. |
| 852 | */ |
| 853 | public static abstract class Proc { |
| 854 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 855 | public static class ExcessivePower { |
| 856 | public static final int TYPE_WAKE = 1; |
| 857 | public static final int TYPE_CPU = 2; |
| 858 | |
| 859 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 860 | public long overTime; |
| 861 | public long usedTime; |
| 862 | } |
| 863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 865 | * Returns true if this process is still active in the battery stats. |
| 866 | */ |
| 867 | public abstract boolean isActive(); |
| 868 | |
| 869 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 870 | * 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] | 871 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 872 | * @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] | 873 | */ |
| 874 | public abstract long getUserTime(int which); |
| 875 | |
| 876 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 877 | * 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] | 878 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 879 | * @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] | 880 | */ |
| 881 | public abstract long getSystemTime(int which); |
| 882 | |
| 883 | /** |
| 884 | * Returns the number of times the process has been started. |
| 885 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 886 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | */ |
| 888 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 889 | |
| 890 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 891 | * Returns the number of times the process has crashed. |
| 892 | * |
| 893 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 894 | */ |
| 895 | public abstract int getNumCrashes(int which); |
| 896 | |
| 897 | /** |
| 898 | * Returns the number of times the process has ANRed. |
| 899 | * |
| 900 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 901 | */ |
| 902 | public abstract int getNumAnrs(int which); |
| 903 | |
| 904 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 905 | * 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] | 906 | * @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] | 907 | * @return foreground cpu time in microseconds |
| 908 | */ |
| 909 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 910 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 911 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 912 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 913 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | /** |
| 917 | * The statistics associated with a particular package. |
| 918 | */ |
| 919 | public static abstract class Pkg { |
| 920 | |
| 921 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 922 | * Returns information about all wakeup alarms that have been triggered for this |
| 923 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 924 | * 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] | 925 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 926 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | |
| 928 | /** |
| 929 | * Returns a mapping containing service statistics. |
| 930 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 931 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | |
| 933 | /** |
| 934 | * The statistics associated with a particular service. |
| 935 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 936 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | |
| 938 | /** |
| 939 | * Returns the amount of time spent started. |
| 940 | * |
| 941 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 942 | * @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] | 943 | * @return |
| 944 | */ |
| 945 | public abstract long getStartTime(long batteryUptime, int which); |
| 946 | |
| 947 | /** |
| 948 | * Returns the total number of times startService() has been called. |
| 949 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 950 | * @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] | 951 | */ |
| 952 | public abstract int getStarts(int which); |
| 953 | |
| 954 | /** |
| 955 | * Returns the total number times the service has been launched. |
| 956 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 957 | * @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] | 958 | */ |
| 959 | public abstract int getLaunches(int which); |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 964 | public static final class LevelStepTracker { |
| 965 | public long mLastStepTime = -1; |
| 966 | public int mNumStepDurations; |
| 967 | public final long[] mStepDurations; |
| 968 | |
| 969 | public LevelStepTracker(int maxLevelSteps) { |
| 970 | mStepDurations = new long[maxLevelSteps]; |
| 971 | } |
| 972 | |
| 973 | public LevelStepTracker(int numSteps, long[] steps) { |
| 974 | mNumStepDurations = numSteps; |
| 975 | mStepDurations = new long[numSteps]; |
| 976 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 977 | } |
| 978 | |
| 979 | public long getDurationAt(int index) { |
| 980 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 981 | } |
| 982 | |
| 983 | public int getLevelAt(int index) { |
| 984 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 985 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 986 | } |
| 987 | |
| 988 | public int getInitModeAt(int index) { |
| 989 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 990 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 991 | } |
| 992 | |
| 993 | public int getModModeAt(int index) { |
| 994 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 995 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 996 | } |
| 997 | |
| 998 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 999 | boolean hasData = false; |
| 1000 | while (topOffset >= 0) { |
| 1001 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 1002 | topOffset -= 4; |
| 1003 | if (!hasData && digit == 0) { |
| 1004 | continue; |
| 1005 | } |
| 1006 | hasData = true; |
| 1007 | if (digit >= 0 && digit <= 9) { |
| 1008 | out.append((char)('0' + digit)); |
| 1009 | } else { |
| 1010 | out.append((char)('a' + digit - 10)); |
| 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | public void encodeEntryAt(int index, StringBuilder out) { |
| 1016 | long item = mStepDurations[index]; |
| 1017 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 1018 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 1019 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 1020 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1021 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1022 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1023 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1024 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1025 | case Display.STATE_OFF: out.append('f'); break; |
| 1026 | case Display.STATE_ON: out.append('o'); break; |
| 1027 | case Display.STATE_DOZE: out.append('d'); break; |
| 1028 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 1029 | } |
| 1030 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1031 | out.append('p'); |
| 1032 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1033 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1034 | out.append('i'); |
| 1035 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1036 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 1037 | case Display.STATE_OFF: out.append('F'); break; |
| 1038 | case Display.STATE_ON: out.append('O'); break; |
| 1039 | case Display.STATE_DOZE: out.append('D'); break; |
| 1040 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 1041 | } |
| 1042 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 1043 | out.append('P'); |
| 1044 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1045 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 1046 | out.append('I'); |
| 1047 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1048 | out.append('-'); |
| 1049 | appendHex(level, 4, out); |
| 1050 | out.append('-'); |
| 1051 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 1052 | } |
| 1053 | |
| 1054 | public void decodeEntryAt(int index, String value) { |
| 1055 | final int N = value.length(); |
| 1056 | int i = 0; |
| 1057 | char c; |
| 1058 | long out = 0; |
| 1059 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1060 | i++; |
| 1061 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1062 | 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] | 1063 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1064 | 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] | 1065 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1066 | 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] | 1067 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1068 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1069 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1070 | break; |
| 1071 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1072 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1073 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1074 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1075 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1076 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1077 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1078 | break; |
| 1079 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1080 | break; |
| 1081 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1082 | break; |
| 1083 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1084 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1085 | break; |
| 1086 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1087 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1088 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1089 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1090 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1091 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1095 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1096 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1097 | i++; |
| 1098 | level <<= 4; |
| 1099 | if (c >= '0' && c <= '9') { |
| 1100 | level += c - '0'; |
| 1101 | } else if (c >= 'a' && c <= 'f') { |
| 1102 | level += c - 'a' + 10; |
| 1103 | } else if (c >= 'A' && c <= 'F') { |
| 1104 | level += c - 'A' + 10; |
| 1105 | } |
| 1106 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1107 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1108 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1109 | long duration = 0; |
| 1110 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1111 | i++; |
| 1112 | duration <<= 4; |
| 1113 | if (c >= '0' && c <= '9') { |
| 1114 | duration += c - '0'; |
| 1115 | } else if (c >= 'a' && c <= 'f') { |
| 1116 | duration += c - 'a' + 10; |
| 1117 | } else if (c >= 'A' && c <= 'F') { |
| 1118 | duration += c - 'A' + 10; |
| 1119 | } |
| 1120 | } |
| 1121 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1122 | } |
| 1123 | |
| 1124 | public void init() { |
| 1125 | mLastStepTime = -1; |
| 1126 | mNumStepDurations = 0; |
| 1127 | } |
| 1128 | |
| 1129 | public void clearTime() { |
| 1130 | mLastStepTime = -1; |
| 1131 | } |
| 1132 | |
| 1133 | public long computeTimePerLevel() { |
| 1134 | final long[] steps = mStepDurations; |
| 1135 | final int numSteps = mNumStepDurations; |
| 1136 | |
| 1137 | // For now we'll do a simple average across all steps. |
| 1138 | if (numSteps <= 0) { |
| 1139 | return -1; |
| 1140 | } |
| 1141 | long total = 0; |
| 1142 | for (int i=0; i<numSteps; i++) { |
| 1143 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1144 | } |
| 1145 | return total / numSteps; |
| 1146 | /* |
| 1147 | long[] buckets = new long[numSteps]; |
| 1148 | int numBuckets = 0; |
| 1149 | int numToAverage = 4; |
| 1150 | int i = 0; |
| 1151 | while (i < numSteps) { |
| 1152 | long totalTime = 0; |
| 1153 | int num = 0; |
| 1154 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1155 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1156 | num++; |
| 1157 | } |
| 1158 | buckets[numBuckets] = totalTime / num; |
| 1159 | numBuckets++; |
| 1160 | numToAverage *= 2; |
| 1161 | i += num; |
| 1162 | } |
| 1163 | if (numBuckets < 1) { |
| 1164 | return -1; |
| 1165 | } |
| 1166 | long averageTime = buckets[numBuckets-1]; |
| 1167 | for (i=numBuckets-2; i>=0; i--) { |
| 1168 | averageTime = (averageTime + buckets[i]) / 2; |
| 1169 | } |
| 1170 | return averageTime; |
| 1171 | */ |
| 1172 | } |
| 1173 | |
| 1174 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1175 | int[] outNumOfInterest) { |
| 1176 | final long[] steps = mStepDurations; |
| 1177 | final int count = mNumStepDurations; |
| 1178 | if (count <= 0) { |
| 1179 | return -1; |
| 1180 | } |
| 1181 | long total = 0; |
| 1182 | int numOfInterest = 0; |
| 1183 | for (int i=0; i<count; i++) { |
| 1184 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1185 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1186 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1187 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1188 | // If the modes of interest didn't change during this step period... |
| 1189 | if ((modMode&modesOfInterest) == 0) { |
| 1190 | // And the mode values during this period match those we are measuring... |
| 1191 | if ((initMode&modesOfInterest) == modeValues) { |
| 1192 | // Then this can be used to estimate the total time! |
| 1193 | numOfInterest++; |
| 1194 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | if (numOfInterest <= 0) { |
| 1199 | return -1; |
| 1200 | } |
| 1201 | |
| 1202 | if (outNumOfInterest != null) { |
| 1203 | outNumOfInterest[0] = numOfInterest; |
| 1204 | } |
| 1205 | |
| 1206 | // The estimated time is the average time we spend in each level, multipled |
| 1207 | // by 100 -- the total number of battery levels |
| 1208 | return (total / numOfInterest) * 100; |
| 1209 | } |
| 1210 | |
| 1211 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1212 | int stepCount = mNumStepDurations; |
| 1213 | final long lastStepTime = mLastStepTime; |
| 1214 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1215 | final long[] steps = mStepDurations; |
| 1216 | long duration = elapsedRealtime - lastStepTime; |
| 1217 | for (int i=0; i<numStepLevels; i++) { |
| 1218 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1219 | long thisDuration = duration / (numStepLevels-i); |
| 1220 | duration -= thisDuration; |
| 1221 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1222 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1223 | } |
| 1224 | steps[0] = thisDuration | modeBits; |
| 1225 | } |
| 1226 | stepCount += numStepLevels; |
| 1227 | if (stepCount > steps.length) { |
| 1228 | stepCount = steps.length; |
| 1229 | } |
| 1230 | } |
| 1231 | mNumStepDurations = stepCount; |
| 1232 | mLastStepTime = elapsedRealtime; |
| 1233 | } |
| 1234 | |
| 1235 | public void readFromParcel(Parcel in) { |
| 1236 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1237 | if (N > mStepDurations.length) { |
| 1238 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1239 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1240 | mNumStepDurations = N; |
| 1241 | for (int i=0; i<N; i++) { |
| 1242 | mStepDurations[i] = in.readLong(); |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | public void writeToParcel(Parcel out) { |
| 1247 | final int N = mNumStepDurations; |
| 1248 | out.writeInt(N); |
| 1249 | for (int i=0; i<N; i++) { |
| 1250 | out.writeLong(mStepDurations[i]); |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1255 | public static final class PackageChange { |
| 1256 | public String mPackageName; |
| 1257 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1258 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1261 | public static final class DailyItem { |
| 1262 | public long mStartTime; |
| 1263 | public long mEndTime; |
| 1264 | public LevelStepTracker mDischargeSteps; |
| 1265 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1266 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1270 | |
| 1271 | public abstract long getCurrentDailyStartTime(); |
| 1272 | |
| 1273 | public abstract long getNextMinDailyDeadline(); |
| 1274 | |
| 1275 | public abstract long getNextMaxDailyDeadline(); |
| 1276 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1277 | public abstract long[] getCpuFreqs(); |
| 1278 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1279 | public final static class HistoryTag { |
| 1280 | public String string; |
| 1281 | public int uid; |
| 1282 | |
| 1283 | public int poolIdx; |
| 1284 | |
| 1285 | public void setTo(HistoryTag o) { |
| 1286 | string = o.string; |
| 1287 | uid = o.uid; |
| 1288 | poolIdx = o.poolIdx; |
| 1289 | } |
| 1290 | |
| 1291 | public void setTo(String _string, int _uid) { |
| 1292 | string = _string; |
| 1293 | uid = _uid; |
| 1294 | poolIdx = -1; |
| 1295 | } |
| 1296 | |
| 1297 | public void writeToParcel(Parcel dest, int flags) { |
| 1298 | dest.writeString(string); |
| 1299 | dest.writeInt(uid); |
| 1300 | } |
| 1301 | |
| 1302 | public void readFromParcel(Parcel src) { |
| 1303 | string = src.readString(); |
| 1304 | uid = src.readInt(); |
| 1305 | poolIdx = -1; |
| 1306 | } |
| 1307 | |
| 1308 | @Override |
| 1309 | public boolean equals(Object o) { |
| 1310 | if (this == o) return true; |
| 1311 | if (o == null || getClass() != o.getClass()) return false; |
| 1312 | |
| 1313 | HistoryTag that = (HistoryTag) o; |
| 1314 | |
| 1315 | if (uid != that.uid) return false; |
| 1316 | if (!string.equals(that.string)) return false; |
| 1317 | |
| 1318 | return true; |
| 1319 | } |
| 1320 | |
| 1321 | @Override |
| 1322 | public int hashCode() { |
| 1323 | int result = string.hashCode(); |
| 1324 | result = 31 * result + uid; |
| 1325 | return result; |
| 1326 | } |
| 1327 | } |
| 1328 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1329 | /** |
| 1330 | * Optional detailed information that can go into a history step. This is typically |
| 1331 | * generated each time the battery level changes. |
| 1332 | */ |
| 1333 | public final static class HistoryStepDetails { |
| 1334 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1335 | public int userTime; |
| 1336 | public int systemTime; |
| 1337 | |
| 1338 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1339 | public int appCpuUid1; |
| 1340 | public int appCpuUTime1; |
| 1341 | public int appCpuSTime1; |
| 1342 | public int appCpuUid2; |
| 1343 | public int appCpuUTime2; |
| 1344 | public int appCpuSTime2; |
| 1345 | public int appCpuUid3; |
| 1346 | public int appCpuUTime3; |
| 1347 | public int appCpuSTime3; |
| 1348 | |
| 1349 | // Information from /proc/stat |
| 1350 | public int statUserTime; |
| 1351 | public int statSystemTime; |
| 1352 | public int statIOWaitTime; |
| 1353 | public int statIrqTime; |
| 1354 | public int statSoftIrqTime; |
| 1355 | public int statIdlTime; |
| 1356 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1357 | // Platform-level low power state stats |
| 1358 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1359 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1360 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1361 | public HistoryStepDetails() { |
| 1362 | clear(); |
| 1363 | } |
| 1364 | |
| 1365 | public void clear() { |
| 1366 | userTime = systemTime = 0; |
| 1367 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1368 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1369 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1370 | } |
| 1371 | |
| 1372 | public void writeToParcel(Parcel out) { |
| 1373 | out.writeInt(userTime); |
| 1374 | out.writeInt(systemTime); |
| 1375 | out.writeInt(appCpuUid1); |
| 1376 | out.writeInt(appCpuUTime1); |
| 1377 | out.writeInt(appCpuSTime1); |
| 1378 | out.writeInt(appCpuUid2); |
| 1379 | out.writeInt(appCpuUTime2); |
| 1380 | out.writeInt(appCpuSTime2); |
| 1381 | out.writeInt(appCpuUid3); |
| 1382 | out.writeInt(appCpuUTime3); |
| 1383 | out.writeInt(appCpuSTime3); |
| 1384 | out.writeInt(statUserTime); |
| 1385 | out.writeInt(statSystemTime); |
| 1386 | out.writeInt(statIOWaitTime); |
| 1387 | out.writeInt(statIrqTime); |
| 1388 | out.writeInt(statSoftIrqTime); |
| 1389 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1390 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1391 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | public void readFromParcel(Parcel in) { |
| 1395 | userTime = in.readInt(); |
| 1396 | systemTime = in.readInt(); |
| 1397 | appCpuUid1 = in.readInt(); |
| 1398 | appCpuUTime1 = in.readInt(); |
| 1399 | appCpuSTime1 = in.readInt(); |
| 1400 | appCpuUid2 = in.readInt(); |
| 1401 | appCpuUTime2 = in.readInt(); |
| 1402 | appCpuSTime2 = in.readInt(); |
| 1403 | appCpuUid3 = in.readInt(); |
| 1404 | appCpuUTime3 = in.readInt(); |
| 1405 | appCpuSTime3 = in.readInt(); |
| 1406 | statUserTime = in.readInt(); |
| 1407 | statSystemTime = in.readInt(); |
| 1408 | statIOWaitTime = in.readInt(); |
| 1409 | statIrqTime = in.readInt(); |
| 1410 | statSoftIrqTime = in.readInt(); |
| 1411 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1412 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1413 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1417 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1418 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1419 | |
| 1420 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1421 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1422 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1423 | 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] | 1424 | public static final byte CMD_NULL = -1; |
| 1425 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1426 | public static final byte CMD_CURRENT_TIME = 5; |
| 1427 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1428 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1429 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1430 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1431 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1432 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1433 | /** |
| 1434 | * Return whether the command code is a delta data update. |
| 1435 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1436 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1437 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1440 | public byte batteryLevel; |
| 1441 | public byte batteryStatus; |
| 1442 | public byte batteryHealth; |
| 1443 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1444 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1445 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1446 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1447 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1448 | // The charge of the battery in micro-Ampere-hours. |
| 1449 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1450 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1451 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1452 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1453 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1454 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1455 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1456 | 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] | 1457 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1458 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1459 | 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] | 1460 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1461 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1462 | 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] | 1463 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1464 | // These states always appear directly in the first int token |
| 1465 | // of a delta change; they should be ones that change relatively |
| 1466 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1467 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1468 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1469 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1470 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1471 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1472 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1473 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1474 | // Do not use, this is used for coulomb delta count. |
| 1475 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1476 | // These are on the lower bits used for the command; if they change |
| 1477 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1478 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1479 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1480 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1481 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1482 | 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] | 1483 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1484 | // empty slot |
| 1485 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1486 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1487 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1488 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1489 | |
| 1490 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1491 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1492 | public int states; |
| 1493 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1494 | // Constants from WIFI_SUPPL_STATE_* |
| 1495 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1496 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1497 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1498 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1499 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1500 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame^] | 1501 | // Values for NUM_GPS_SIGNAL_QUALITY_LEVELS |
| 1502 | public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7; |
| 1503 | public static final int STATE2_GPS_SIGNAL_QUALITY_MASK = |
| 1504 | 0x1 << STATE2_GPS_SIGNAL_QUALITY_SHIFT; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1505 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1506 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1507 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1508 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1509 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1510 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1511 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1512 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1513 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1514 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1515 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1516 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1517 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1518 | |
| 1519 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1520 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1521 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1522 | |
| 1523 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1524 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1525 | public int states2; |
| 1526 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1527 | // The wake lock that was acquired at this point. |
| 1528 | public HistoryTag wakelockTag; |
| 1529 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1530 | // Kernel wakeup reason at this point. |
| 1531 | public HistoryTag wakeReasonTag; |
| 1532 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1533 | // Non-null when there is more detailed information at this step. |
| 1534 | public HistoryStepDetails stepDetails; |
| 1535 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1536 | public static final int EVENT_FLAG_START = 0x8000; |
| 1537 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1538 | |
| 1539 | // No event in this item. |
| 1540 | public static final int EVENT_NONE = 0x0000; |
| 1541 | // Event is about a process that is running. |
| 1542 | public static final int EVENT_PROC = 0x0001; |
| 1543 | // Event is about an application package that is in the foreground. |
| 1544 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1545 | // Event is about an application package that is at the top of the screen. |
| 1546 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1547 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1548 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1549 | // Events for all additional wake locks aquired/release within a wake block. |
| 1550 | // These are not generated by default. |
| 1551 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1552 | // Event is about an application executing a scheduled job. |
| 1553 | public static final int EVENT_JOB = 0x0006; |
| 1554 | // Events for users running. |
| 1555 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1556 | // Events for foreground user. |
| 1557 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1558 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1559 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1560 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1561 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1562 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1563 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1564 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1565 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1566 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1567 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1568 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1569 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1570 | // 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] | 1571 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1572 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1573 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1574 | // Event for a package being on the temporary whitelist. |
| 1575 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1576 | // Event for the screen waking up. |
| 1577 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1578 | // Event for the UID that woke up the application processor. |
| 1579 | // Used for wakeups coming from WiFi, modem, etc. |
| 1580 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1581 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1582 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1583 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1584 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1585 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1586 | // Mask to extract out only the type part of the event. |
| 1587 | 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] | 1588 | |
| 1589 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1590 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1591 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1592 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1593 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1594 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1595 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1596 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1597 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1598 | 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] | 1599 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1600 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1601 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1602 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1603 | public static final int EVENT_USER_FOREGROUND_START = |
| 1604 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1605 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1606 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1607 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1608 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1609 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1610 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1611 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1612 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1613 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1614 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1615 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1616 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1617 | |
| 1618 | // For CMD_EVENT. |
| 1619 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1620 | public HistoryTag eventTag; |
| 1621 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1622 | // 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] | 1623 | public long currentTime; |
| 1624 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1625 | // Meta-data when reading. |
| 1626 | public int numReadInts; |
| 1627 | |
| 1628 | // Pre-allocated objects. |
| 1629 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1630 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1631 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1632 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1633 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1634 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1635 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1636 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1637 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1638 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1639 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1640 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1641 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1642 | public int describeContents() { |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | public void writeToParcel(Parcel dest, int flags) { |
| 1647 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1648 | int bat = (((int)cmd)&0xff) |
| 1649 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1650 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1651 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1652 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1653 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1654 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1655 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1656 | dest.writeInt(bat); |
| 1657 | bat = (((int)batteryTemperature)&0xffff) |
| 1658 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1659 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1660 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1661 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1662 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1663 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1664 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1665 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1666 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1667 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1668 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1669 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1670 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1671 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1672 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1673 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1674 | dest.writeLong(currentTime); |
| 1675 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1676 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1677 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1678 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1679 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1680 | int bat = src.readInt(); |
| 1681 | cmd = (byte)(bat&0xff); |
| 1682 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1683 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1684 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1685 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1686 | int bat2 = src.readInt(); |
| 1687 | batteryTemperature = (short)(bat2&0xffff); |
| 1688 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1689 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1690 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1691 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1692 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1693 | wakelockTag = localWakelockTag; |
| 1694 | wakelockTag.readFromParcel(src); |
| 1695 | } else { |
| 1696 | wakelockTag = null; |
| 1697 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1698 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1699 | wakeReasonTag = localWakeReasonTag; |
| 1700 | wakeReasonTag.readFromParcel(src); |
| 1701 | } else { |
| 1702 | wakeReasonTag = null; |
| 1703 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1704 | if ((bat&0x40000000) != 0) { |
| 1705 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1706 | eventTag = localEventTag; |
| 1707 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1708 | } else { |
| 1709 | eventCode = EVENT_NONE; |
| 1710 | eventTag = null; |
| 1711 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1712 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1713 | currentTime = src.readLong(); |
| 1714 | } else { |
| 1715 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1716 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1717 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1720 | public void clear() { |
| 1721 | time = 0; |
| 1722 | cmd = CMD_NULL; |
| 1723 | batteryLevel = 0; |
| 1724 | batteryStatus = 0; |
| 1725 | batteryHealth = 0; |
| 1726 | batteryPlugType = 0; |
| 1727 | batteryTemperature = 0; |
| 1728 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1729 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1730 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1731 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1732 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1733 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1734 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1735 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1736 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1737 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1738 | public void setTo(HistoryItem o) { |
| 1739 | time = o.time; |
| 1740 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1741 | setToCommon(o); |
| 1742 | } |
| 1743 | |
| 1744 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1745 | this.time = time; |
| 1746 | this.cmd = cmd; |
| 1747 | setToCommon(o); |
| 1748 | } |
| 1749 | |
| 1750 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1751 | batteryLevel = o.batteryLevel; |
| 1752 | batteryStatus = o.batteryStatus; |
| 1753 | batteryHealth = o.batteryHealth; |
| 1754 | batteryPlugType = o.batteryPlugType; |
| 1755 | batteryTemperature = o.batteryTemperature; |
| 1756 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1757 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1758 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1759 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1760 | if (o.wakelockTag != null) { |
| 1761 | wakelockTag = localWakelockTag; |
| 1762 | wakelockTag.setTo(o.wakelockTag); |
| 1763 | } else { |
| 1764 | wakelockTag = null; |
| 1765 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1766 | if (o.wakeReasonTag != null) { |
| 1767 | wakeReasonTag = localWakeReasonTag; |
| 1768 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1769 | } else { |
| 1770 | wakeReasonTag = null; |
| 1771 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1772 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1773 | if (o.eventTag != null) { |
| 1774 | eventTag = localEventTag; |
| 1775 | eventTag.setTo(o.eventTag); |
| 1776 | } else { |
| 1777 | eventTag = null; |
| 1778 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1779 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1782 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1783 | return batteryLevel == o.batteryLevel |
| 1784 | && batteryStatus == o.batteryStatus |
| 1785 | && batteryHealth == o.batteryHealth |
| 1786 | && batteryPlugType == o.batteryPlugType |
| 1787 | && batteryTemperature == o.batteryTemperature |
| 1788 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1789 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1790 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1791 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1792 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1793 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1794 | |
| 1795 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1796 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1799 | if (wakelockTag != o.wakelockTag) { |
| 1800 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1801 | return false; |
| 1802 | } |
| 1803 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1804 | return false; |
| 1805 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1806 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1807 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1808 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1809 | return false; |
| 1810 | } |
| 1811 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1812 | return false; |
| 1813 | } |
| 1814 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1815 | if (eventTag != o.eventTag) { |
| 1816 | if (eventTag == null || o.eventTag == null) { |
| 1817 | return false; |
| 1818 | } |
| 1819 | if (!eventTag.equals(o.eventTag)) { |
| 1820 | return false; |
| 1821 | } |
| 1822 | } |
| 1823 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1824 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1825 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1826 | |
| 1827 | public final static class HistoryEventTracker { |
| 1828 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1829 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1830 | |
| 1831 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1832 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1833 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1834 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1835 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1836 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1837 | mActiveEvents[idx] = active; |
| 1838 | } |
| 1839 | SparseIntArray uids = active.get(name); |
| 1840 | if (uids == null) { |
| 1841 | uids = new SparseIntArray(); |
| 1842 | active.put(name, uids); |
| 1843 | } |
| 1844 | if (uids.indexOfKey(uid) >= 0) { |
| 1845 | // Already set, nothing to do! |
| 1846 | return false; |
| 1847 | } |
| 1848 | uids.put(uid, poolIdx); |
| 1849 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1850 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1851 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1852 | if (active == null) { |
| 1853 | // not currently active, nothing to do. |
| 1854 | return false; |
| 1855 | } |
| 1856 | SparseIntArray uids = active.get(name); |
| 1857 | if (uids == null) { |
| 1858 | // not currently active, nothing to do. |
| 1859 | return false; |
| 1860 | } |
| 1861 | idx = uids.indexOfKey(uid); |
| 1862 | if (idx < 0) { |
| 1863 | // not currently active, nothing to do. |
| 1864 | return false; |
| 1865 | } |
| 1866 | uids.removeAt(idx); |
| 1867 | if (uids.size() <= 0) { |
| 1868 | active.remove(name); |
| 1869 | } |
| 1870 | } |
| 1871 | return true; |
| 1872 | } |
| 1873 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1874 | public void removeEvents(int code) { |
| 1875 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1876 | mActiveEvents[idx] = null; |
| 1877 | } |
| 1878 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1879 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1880 | return mActiveEvents[code]; |
| 1881 | } |
| 1882 | } |
| 1883 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1884 | public static final class BitDescription { |
| 1885 | public final int mask; |
| 1886 | public final int shift; |
| 1887 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1888 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1889 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1890 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1891 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1892 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1893 | this.mask = mask; |
| 1894 | this.shift = -1; |
| 1895 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1896 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1897 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1898 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1899 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1900 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1901 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1902 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1903 | this.mask = mask; |
| 1904 | this.shift = shift; |
| 1905 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1906 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1907 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1908 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1909 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1910 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1911 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1912 | /** |
| 1913 | * Don't allow any more batching in to the current history event. This |
| 1914 | * is called when printing partial histories, so to ensure that the next |
| 1915 | * history event will go in to a new batch after what was printed in the |
| 1916 | * last partial history. |
| 1917 | */ |
| 1918 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1919 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1920 | public abstract int getHistoryTotalSize(); |
| 1921 | |
| 1922 | public abstract int getHistoryUsedSize(); |
| 1923 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1924 | public abstract boolean startIteratingHistoryLocked(); |
| 1925 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1926 | public abstract int getHistoryStringPoolSize(); |
| 1927 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1928 | public abstract int getHistoryStringPoolBytes(); |
| 1929 | |
| 1930 | public abstract String getHistoryTagPoolString(int index); |
| 1931 | |
| 1932 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1933 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1934 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1935 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1936 | public abstract void finishIteratingHistoryLocked(); |
| 1937 | |
| 1938 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1939 | |
| 1940 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1941 | |
| 1942 | public abstract void finishIteratingOldHistoryLocked(); |
| 1943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1945 | * Return the base time offset for the battery history. |
| 1946 | */ |
| 1947 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1948 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1949 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | * Returns the number of times the device has been started. |
| 1951 | */ |
| 1952 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1955 | * 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] | 1956 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1957 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | * {@hide} |
| 1959 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1960 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1961 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1962 | /** |
| 1963 | * Returns the number of times the screen was turned on. |
| 1964 | * |
| 1965 | * {@hide} |
| 1966 | */ |
| 1967 | public abstract int getScreenOnCount(int which); |
| 1968 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1969 | /** |
| 1970 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1971 | * running on battery. |
| 1972 | * |
| 1973 | * {@hide} |
| 1974 | */ |
| 1975 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1976 | |
| 1977 | /** |
| 1978 | * Returns the number of times the screen was turned dozing. |
| 1979 | * |
| 1980 | * {@hide} |
| 1981 | */ |
| 1982 | public abstract int getScreenDozeCount(int which); |
| 1983 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1984 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1985 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1986 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1987 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1988 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1989 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1990 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1991 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1992 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1993 | "dark", "dim", "medium", "light", "bright" |
| 1994 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1995 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1996 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1997 | "0", "1", "2", "3", "4" |
| 1998 | }; |
| 1999 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2000 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2001 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2002 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2003 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2004 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2005 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2006 | * {@hide} |
| 2007 | */ |
| 2008 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2009 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2012 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 2013 | * |
| 2014 | * {@hide} |
| 2015 | */ |
| 2016 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 2017 | |
| 2018 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2019 | * 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] | 2020 | * running on battery. |
| 2021 | * |
| 2022 | * {@hide} |
| 2023 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2024 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2025 | |
| 2026 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2027 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2028 | * |
| 2029 | * {@hide} |
| 2030 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2031 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 2032 | |
| 2033 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2034 | * Constant for device idle mode: not active. |
| 2035 | */ |
| 2036 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 2037 | |
| 2038 | /** |
| 2039 | * Constant for device idle mode: active in lightweight mode. |
| 2040 | */ |
| 2041 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 2042 | |
| 2043 | /** |
| 2044 | * Constant for device idle mode: active in full mode. |
| 2045 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2046 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2047 | |
| 2048 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2049 | * Returns the time in microseconds that device has been in idle mode while |
| 2050 | * running on battery. |
| 2051 | * |
| 2052 | * {@hide} |
| 2053 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2054 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2055 | |
| 2056 | /** |
| 2057 | * Returns the number of times that the devie has gone in to idle mode. |
| 2058 | * |
| 2059 | * {@hide} |
| 2060 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2061 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 2062 | |
| 2063 | /** |
| 2064 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 2065 | * mode, not in idle maintenance etc). |
| 2066 | */ |
| 2067 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2068 | |
| 2069 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2070 | * 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] | 2071 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2072 | * counts all of the time that we consider the device to be idle, whether or not |
| 2073 | * it is currently in the actual device idle mode. |
| 2074 | * |
| 2075 | * {@hide} |
| 2076 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2077 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2078 | |
| 2079 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2080 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2081 | * |
| 2082 | * {@hide} |
| 2083 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2084 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2085 | |
| 2086 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2087 | * Returns the number of times that connectivity state changed. |
| 2088 | * |
| 2089 | * {@hide} |
| 2090 | */ |
| 2091 | public abstract int getNumConnectivityChange(int which); |
| 2092 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame^] | 2093 | |
| 2094 | /** |
| 2095 | * Returns the time in microseconds that the phone has been running with |
| 2096 | * the given GPS signal quality level |
| 2097 | * |
| 2098 | * {@hide} |
| 2099 | */ |
| 2100 | public abstract long getGpsSignalQualityTime(int strengthBin, |
| 2101 | long elapsedRealtimeUs, int which); |
| 2102 | |
| 2103 | /** |
| 2104 | * Returns the GPS battery drain in mA-ms |
| 2105 | * |
| 2106 | * {@hide} |
| 2107 | */ |
| 2108 | public abstract long getGpsBatteryDrainMaMs(); |
| 2109 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2110 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2111 | * 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] | 2112 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2113 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | * {@hide} |
| 2115 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2116 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2117 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2118 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2119 | * Returns the number of times a phone call was activated. |
| 2120 | * |
| 2121 | * {@hide} |
| 2122 | */ |
| 2123 | public abstract int getPhoneOnCount(int which); |
| 2124 | |
| 2125 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2126 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2127 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2128 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2129 | * {@hide} |
| 2130 | */ |
| 2131 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2132 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2133 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2134 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2135 | * Returns the time in microseconds that the phone has been trying to |
| 2136 | * acquire a signal. |
| 2137 | * |
| 2138 | * {@hide} |
| 2139 | */ |
| 2140 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2141 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2142 | |
| 2143 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2144 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2145 | * acquire a signal. |
| 2146 | * |
| 2147 | * {@hide} |
| 2148 | */ |
| 2149 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2150 | |
| 2151 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2152 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2153 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2154 | * {@hide} |
| 2155 | */ |
| 2156 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2157 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2158 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2159 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2160 | * counts. |
| 2161 | */ |
| 2162 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2163 | |
| 2164 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2165 | * Returns the time in microseconds that the mobile network has been active |
| 2166 | * (in a high power state). |
| 2167 | * |
| 2168 | * {@hide} |
| 2169 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2170 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2171 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2172 | /** |
| 2173 | * Returns the number of times that the mobile network has transitioned to the |
| 2174 | * active state. |
| 2175 | * |
| 2176 | * {@hide} |
| 2177 | */ |
| 2178 | public abstract int getMobileRadioActiveCount(int which); |
| 2179 | |
| 2180 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2181 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2182 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2183 | * from the radio. |
| 2184 | * |
| 2185 | * {@hide} |
| 2186 | */ |
| 2187 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2188 | |
| 2189 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2190 | * Returns the time in microseconds that the mobile network has been active |
| 2191 | * (in a high power state) but not being able to blame on an app. |
| 2192 | * |
| 2193 | * {@hide} |
| 2194 | */ |
| 2195 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2196 | |
| 2197 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2198 | * 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] | 2199 | * |
| 2200 | * {@hide} |
| 2201 | */ |
| 2202 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2203 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2204 | public static final int DATA_CONNECTION_NONE = 0; |
| 2205 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2206 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2207 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2208 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2209 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2210 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2211 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2212 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2213 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2214 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2215 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2216 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2217 | public static final int DATA_CONNECTION_LTE = 13; |
| 2218 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2219 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2220 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2221 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2222 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2223 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2224 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2225 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2226 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2227 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2228 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2229 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2230 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2231 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2232 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2233 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2234 | * {@hide} |
| 2235 | */ |
| 2236 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2237 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2240 | * Returns the number of times the phone has entered the given data |
| 2241 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2242 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2243 | * {@hide} |
| 2244 | */ |
| 2245 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2246 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2247 | /** |
| 2248 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2249 | */ |
| 2250 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2251 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2252 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2253 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2254 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2255 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2256 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2257 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2258 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2259 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2260 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2261 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2262 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2263 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2264 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2265 | |
| 2266 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2267 | |
| 2268 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2269 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2270 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2271 | "group-handshake", "completed", "dormant", "uninit" |
| 2272 | }; |
| 2273 | |
| 2274 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2275 | "inv", "dsc", "dis", "inact", "scan", |
| 2276 | "auth", "ascing", "asced", "4-way", |
| 2277 | "group", "compl", "dorm", "uninit" |
| 2278 | }; |
| 2279 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2280 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2281 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2282 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2283 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2284 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2285 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2286 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2287 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2288 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2289 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2290 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2291 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2292 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2293 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2294 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2295 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2296 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2297 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2298 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2299 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2300 | new String[] {"in", "out", "emergency", "off"}, |
| 2301 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2302 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2303 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2304 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2305 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2306 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2307 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2308 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2309 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2310 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2311 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2312 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2313 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2314 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2315 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2316 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2317 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2318 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2319 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2320 | new String[] { "off", "light", "full", "???" }, |
| 2321 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2322 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2323 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2324 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2325 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2326 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2327 | new String[] { "0", "1", "2", "3", "4" }, |
| 2328 | new String[] { "0", "1", "2", "3", "4" }), |
| 2329 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2330 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2331 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2332 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2333 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame^] | 2334 | new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK, |
| 2335 | HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss", |
| 2336 | new String[] { "poor", "good"}, new String[] { "poor", "good"}), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2337 | }; |
| 2338 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2339 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2340 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2341 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2342 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2343 | }; |
| 2344 | |
| 2345 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2346 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2347 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2348 | "Esw", "Ewa", "Elw", "Eec" |
| 2349 | }; |
| 2350 | |
| 2351 | @FunctionalInterface |
| 2352 | public interface IntToString { |
| 2353 | String applyAsString(int val); |
| 2354 | } |
| 2355 | |
| 2356 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2357 | private static final IntToString sIntToString = Integer::toString; |
| 2358 | |
| 2359 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2360 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2361 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2362 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2363 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2364 | }; |
| 2365 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2366 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 2367 | * Returns total time for WiFi Multicast Wakelock timer. |
| 2368 | * Note that this may be different from the sum of per uid timer values. |
| 2369 | * |
| 2370 | * {@hide} |
| 2371 | */ |
| 2372 | public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); |
| 2373 | |
| 2374 | /** |
| 2375 | * Returns total time for WiFi Multicast Wakelock timer |
| 2376 | * Note that this may be different from the sum of per uid timer values. |
| 2377 | * |
| 2378 | * {@hide} |
| 2379 | */ |
| 2380 | public abstract int getWifiMulticastWakelockCount(int which); |
| 2381 | |
| 2382 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2383 | * 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] | 2384 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2385 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2386 | * {@hide} |
| 2387 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2388 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2389 | |
| 2390 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2391 | * 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] | 2392 | * been in the running state while the device was running on battery. |
| 2393 | * |
| 2394 | * {@hide} |
| 2395 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2396 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2397 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2398 | public static final int WIFI_STATE_OFF = 0; |
| 2399 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2400 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2401 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2402 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2403 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2404 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2405 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2406 | |
| 2407 | static final String[] WIFI_STATE_NAMES = { |
| 2408 | "off", "scanning", "no_net", "disconn", |
| 2409 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2410 | }; |
| 2411 | |
| 2412 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2413 | |
| 2414 | /** |
| 2415 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2416 | * |
| 2417 | * {@hide} |
| 2418 | */ |
| 2419 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2420 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2421 | |
| 2422 | /** |
| 2423 | * Returns the number of times that WiFi has entered the given state. |
| 2424 | * |
| 2425 | * {@hide} |
| 2426 | */ |
| 2427 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2428 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2429 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2430 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2431 | * |
| 2432 | * {@hide} |
| 2433 | */ |
| 2434 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2435 | |
| 2436 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2437 | * Returns the time in microseconds that the wifi supplicant has been |
| 2438 | * in a given state. |
| 2439 | * |
| 2440 | * {@hide} |
| 2441 | */ |
| 2442 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2443 | |
| 2444 | /** |
| 2445 | * Returns the number of times that the wifi supplicant has transitioned |
| 2446 | * to a given state. |
| 2447 | * |
| 2448 | * {@hide} |
| 2449 | */ |
| 2450 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2451 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2452 | /** |
| 2453 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2454 | * |
| 2455 | * {@hide} |
| 2456 | */ |
| 2457 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2458 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2459 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2460 | |
| 2461 | /** |
| 2462 | * Returns the time in microseconds that WIFI has been running with |
| 2463 | * the given signal strength. |
| 2464 | * |
| 2465 | * {@hide} |
| 2466 | */ |
| 2467 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2468 | long elapsedRealtimeUs, int which); |
| 2469 | |
| 2470 | /** |
| 2471 | * Returns the number of times WIFI has entered the given signal strength. |
| 2472 | * |
| 2473 | * {@hide} |
| 2474 | */ |
| 2475 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2476 | |
| 2477 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2478 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2479 | * |
| 2480 | * {@hide} |
| 2481 | */ |
| 2482 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2483 | |
| 2484 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2485 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2486 | * running on battery. |
| 2487 | * |
| 2488 | * {@hide} |
| 2489 | */ |
| 2490 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2491 | |
| 2492 | /** |
| 2493 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2494 | * running on battery. |
| 2495 | * |
| 2496 | * {@hide} |
| 2497 | */ |
| 2498 | public abstract long getFlashlightOnCount(int which); |
| 2499 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2500 | /** |
| 2501 | * Returns the time in microseconds that the camera has been on while the device was |
| 2502 | * running on battery. |
| 2503 | * |
| 2504 | * {@hide} |
| 2505 | */ |
| 2506 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2507 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2508 | /** |
| 2509 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2510 | * on battery. |
| 2511 | * |
| 2512 | * {@hide} |
| 2513 | */ |
| 2514 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2515 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2516 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2517 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2518 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2519 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2520 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2521 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2522 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2523 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2524 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2525 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2526 | 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] | 2527 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2528 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2529 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2530 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2531 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2532 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2533 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2534 | * actual power data. |
| 2535 | */ |
| 2536 | public abstract boolean hasWifiActivityReporting(); |
| 2537 | |
| 2538 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2539 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2540 | * in various radio controller states, such as transmit, receive, and idle. |
| 2541 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2542 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2543 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2544 | |
| 2545 | /** |
| 2546 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2547 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2548 | * actual power data. |
| 2549 | */ |
| 2550 | public abstract boolean hasBluetoothActivityReporting(); |
| 2551 | |
| 2552 | /** |
| 2553 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2554 | * in various radio controller states, such as transmit, receive, and idle. |
| 2555 | * @return non-null {@link ControllerActivityCounter} |
| 2556 | */ |
| 2557 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2558 | |
| 2559 | /** |
| 2560 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2561 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2562 | * actual power data. |
| 2563 | */ |
| 2564 | public abstract boolean hasModemActivityReporting(); |
| 2565 | |
| 2566 | /** |
| 2567 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2568 | * in various radio controller states, such as transmit, receive, and idle. |
| 2569 | * @return non-null {@link ControllerActivityCounter} |
| 2570 | */ |
| 2571 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2572 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2573 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2574 | * Return the wall clock time when battery stats data collection started. |
| 2575 | */ |
| 2576 | public abstract long getStartClockTime(); |
| 2577 | |
| 2578 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2579 | * Return platform version tag that we were running in when the battery stats started. |
| 2580 | */ |
| 2581 | public abstract String getStartPlatformVersion(); |
| 2582 | |
| 2583 | /** |
| 2584 | * Return platform version tag that we were running in when the battery stats ended. |
| 2585 | */ |
| 2586 | public abstract String getEndPlatformVersion(); |
| 2587 | |
| 2588 | /** |
| 2589 | * Return the internal version code of the parcelled format. |
| 2590 | */ |
| 2591 | public abstract int getParcelVersion(); |
| 2592 | |
| 2593 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | * Return whether we are currently running on battery. |
| 2595 | */ |
| 2596 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | /** |
| 2599 | * Returns a SparseArray containing the statistics for each uid. |
| 2600 | */ |
| 2601 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2602 | |
| 2603 | /** |
| 2604 | * Returns the current battery uptime in microseconds. |
| 2605 | * |
| 2606 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2607 | */ |
| 2608 | public abstract long getBatteryUptime(long curTime); |
| 2609 | |
| 2610 | /** |
| 2611 | * Returns the current battery realtime in microseconds. |
| 2612 | * |
| 2613 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2614 | */ |
| 2615 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2616 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2617 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2618 | * 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] | 2619 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2620 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2621 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2622 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2623 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2624 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2625 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2626 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2627 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2628 | |
| 2629 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2630 | * Get the amount the battery has discharged since the stats were |
| 2631 | * last reset after charging, as a lower-end approximation. |
| 2632 | */ |
| 2633 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2634 | |
| 2635 | /** |
| 2636 | * Get the amount the battery has discharged since the stats were |
| 2637 | * last reset after charging, as an upper-end approximation. |
| 2638 | */ |
| 2639 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2640 | |
| 2641 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2642 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2643 | */ |
| 2644 | public abstract int getDischargeAmount(int which); |
| 2645 | |
| 2646 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2647 | * Get the amount the battery has discharged while the screen was on, |
| 2648 | * since the last time power was unplugged. |
| 2649 | */ |
| 2650 | public abstract int getDischargeAmountScreenOn(); |
| 2651 | |
| 2652 | /** |
| 2653 | * Get the amount the battery has discharged while the screen was on, |
| 2654 | * since the last time the device was charged. |
| 2655 | */ |
| 2656 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2657 | |
| 2658 | /** |
| 2659 | * Get the amount the battery has discharged while the screen was off, |
| 2660 | * since the last time power was unplugged. |
| 2661 | */ |
| 2662 | public abstract int getDischargeAmountScreenOff(); |
| 2663 | |
| 2664 | /** |
| 2665 | * Get the amount the battery has discharged while the screen was off, |
| 2666 | * since the last time the device was charged. |
| 2667 | */ |
| 2668 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2669 | |
| 2670 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2671 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2672 | * since the last time power was unplugged. |
| 2673 | */ |
| 2674 | public abstract int getDischargeAmountScreenDoze(); |
| 2675 | |
| 2676 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2677 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2678 | * since the last time the device was charged. |
| 2679 | */ |
| 2680 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2681 | |
| 2682 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | * Returns the total, last, or current battery uptime in microseconds. |
| 2684 | * |
| 2685 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2686 | * @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] | 2687 | */ |
| 2688 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2689 | |
| 2690 | /** |
| 2691 | * Returns the total, last, or current battery realtime in microseconds. |
| 2692 | * |
| 2693 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2694 | * @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] | 2695 | */ |
| 2696 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2697 | |
| 2698 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2699 | * 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] | 2700 | * |
| 2701 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2702 | * @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] | 2703 | */ |
| 2704 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2705 | |
| 2706 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2707 | * 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] | 2708 | * |
| 2709 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2710 | * @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] | 2711 | */ |
| 2712 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2713 | |
| 2714 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | * Returns the total, last, or current uptime in microseconds. |
| 2716 | * |
| 2717 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2718 | * @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] | 2719 | */ |
| 2720 | public abstract long computeUptime(long curTime, int which); |
| 2721 | |
| 2722 | /** |
| 2723 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2724 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2726 | * @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] | 2727 | */ |
| 2728 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2729 | |
| 2730 | /** |
| 2731 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2732 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2733 | * enough current data to make a decision, or the battery is currently |
| 2734 | * charging. |
| 2735 | * |
| 2736 | * @param curTime The current elepsed realtime in microseconds. |
| 2737 | */ |
| 2738 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2739 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2740 | // The part of a step duration that is the actual time. |
| 2741 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2742 | |
| 2743 | // Bits in a step duration that are the new battery level we are at. |
| 2744 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2745 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2746 | |
| 2747 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2748 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2749 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2750 | |
| 2751 | // Bits in a step duration that indicate which modes changed during that step. |
| 2752 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2753 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2754 | |
| 2755 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2756 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2757 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2758 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2759 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2760 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2761 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2762 | // Step duration mode: power save is on. |
| 2763 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2764 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2765 | // Step duration mode: device is currently in idle mode. |
| 2766 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2767 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2768 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2769 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2770 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2771 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2772 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2773 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2774 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2775 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2776 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2777 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2778 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2779 | }; |
| 2780 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2781 | (Display.STATE_OFF-1), |
| 2782 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2783 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2784 | (Display.STATE_ON-1), |
| 2785 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2786 | (Display.STATE_DOZE-1), |
| 2787 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2788 | (Display.STATE_DOZE_SUSPEND-1), |
| 2789 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2790 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2791 | }; |
| 2792 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2793 | "screen off", |
| 2794 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2795 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2796 | "screen on", |
| 2797 | "screen on power save", |
| 2798 | "screen doze", |
| 2799 | "screen doze power save", |
| 2800 | "screen doze-suspend", |
| 2801 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2802 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2803 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2804 | |
| 2805 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2806 | * 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] | 2807 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2808 | * a coulomb counter. |
| 2809 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2810 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2811 | |
| 2812 | /** |
| 2813 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2814 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2815 | * a coulomb counter. |
| 2816 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2817 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2818 | |
| 2819 | /** |
| 2820 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2821 | * non-zero only if the device's battery has a coulomb counter. |
| 2822 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2823 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2824 | |
| 2825 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2826 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2827 | * micro-Ampere-hours. |
| 2828 | */ |
| 2829 | public abstract long getUahDischargeLightDoze(int which); |
| 2830 | |
| 2831 | /** |
| 2832 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2833 | * micro-Ampere-hours. |
| 2834 | */ |
| 2835 | public abstract long getUahDischargeDeepDoze(int which); |
| 2836 | |
| 2837 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2838 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2839 | * declared by the PowerProfile. |
| 2840 | * @return The estimated battery capacity in mAh. |
| 2841 | */ |
| 2842 | public abstract int getEstimatedBatteryCapacity(); |
| 2843 | |
| 2844 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2845 | * @return The minimum learned battery capacity in uAh. |
| 2846 | */ |
| 2847 | public abstract int getMinLearnedBatteryCapacity(); |
| 2848 | |
| 2849 | /** |
| 2850 | * @return The maximum learned battery capacity in uAh. |
| 2851 | */ |
| 2852 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2853 | |
| 2854 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2855 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2856 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2857 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2858 | |
| 2859 | /** |
| 2860 | * Return the array of daily discharge step durations. |
| 2861 | */ |
| 2862 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2863 | |
| 2864 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2865 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2866 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2867 | * enough current data to make a decision, or the battery is currently |
| 2868 | * discharging. |
| 2869 | * |
| 2870 | * @param curTime The current elepsed realtime in microseconds. |
| 2871 | */ |
| 2872 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2873 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2874 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2875 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2876 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2877 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2878 | |
| 2879 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2880 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2881 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2882 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2883 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2884 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2885 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2886 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2887 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2888 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2890 | /** |
| 2891 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2892 | */ |
| 2893 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2894 | /** |
| 2895 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2896 | */ |
| 2897 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2898 | |
| 2899 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2900 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2901 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2902 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2903 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2904 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | long days = seconds / (60 * 60 * 24); |
| 2906 | if (days != 0) { |
| 2907 | out.append(days); |
| 2908 | out.append("d "); |
| 2909 | } |
| 2910 | long used = days * 60 * 60 * 24; |
| 2911 | |
| 2912 | long hours = (seconds - used) / (60 * 60); |
| 2913 | if (hours != 0 || used != 0) { |
| 2914 | out.append(hours); |
| 2915 | out.append("h "); |
| 2916 | } |
| 2917 | used += hours * 60 * 60; |
| 2918 | |
| 2919 | long mins = (seconds-used) / 60; |
| 2920 | if (mins != 0 || used != 0) { |
| 2921 | out.append(mins); |
| 2922 | out.append("m "); |
| 2923 | } |
| 2924 | used += mins * 60; |
| 2925 | |
| 2926 | if (seconds != 0 || used != 0) { |
| 2927 | out.append(seconds-used); |
| 2928 | out.append("s "); |
| 2929 | } |
| 2930 | } |
| 2931 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2932 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2934 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | sb.append(time - (sec * 1000)); |
| 2936 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2939 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2940 | long sec = time / 1000; |
| 2941 | formatTimeRaw(sb, sec); |
| 2942 | sb.append(time - (sec * 1000)); |
| 2943 | sb.append("ms"); |
| 2944 | } |
| 2945 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2946 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2948 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | } |
| 2950 | float perc = ((float)num) / ((float)den) * 100; |
| 2951 | mFormatBuilder.setLength(0); |
| 2952 | mFormatter.format("%.1f%%", perc); |
| 2953 | return mFormatBuilder.toString(); |
| 2954 | } |
| 2955 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2956 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2957 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2958 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2959 | if (bytes < BYTES_PER_KB) { |
| 2960 | return bytes + "B"; |
| 2961 | } else if (bytes < BYTES_PER_MB) { |
| 2962 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2963 | return mFormatBuilder.toString(); |
| 2964 | } else if (bytes < BYTES_PER_GB){ |
| 2965 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2966 | return mFormatBuilder.toString(); |
| 2967 | } else { |
| 2968 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2969 | return mFormatBuilder.toString(); |
| 2970 | } |
| 2971 | } |
| 2972 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 2973 | private static long roundUsToMs(long timeUs) { |
| 2974 | return (timeUs + 500) / 1000; |
| 2975 | } |
| 2976 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2977 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2978 | if (timer != null) { |
| 2979 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2980 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2981 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2982 | return totalTimeMillis; |
| 2983 | } |
| 2984 | return 0; |
| 2985 | } |
| 2986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | /** |
| 2988 | * |
| 2989 | * @param sb a StringBuilder object. |
| 2990 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2991 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2993 | * @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] | 2994 | * @param linePrefix a String to be prepended to each line of output. |
| 2995 | * @return the line prefix |
| 2996 | */ |
| 2997 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2998 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3000 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3001 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3002 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3003 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | if (totalTimeMillis != 0) { |
| 3005 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3006 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3007 | if (name != null) { |
| 3008 | sb.append(name); |
| 3009 | sb.append(' '); |
| 3010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | sb.append('('); |
| 3012 | sb.append(count); |
| 3013 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3014 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 3015 | if (maxDurationMs >= 0) { |
| 3016 | sb.append(" max="); |
| 3017 | sb.append(maxDurationMs); |
| 3018 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3019 | // Put actual time if it is available and different from totalTimeMillis. |
| 3020 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 3021 | if (totalDurMs > totalTimeMillis) { |
| 3022 | sb.append(" actual="); |
| 3023 | sb.append(totalDurMs); |
| 3024 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3025 | if (timer.isRunningLocked()) { |
| 3026 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3027 | if (currentMs >= 0) { |
| 3028 | sb.append(" (running for "); |
| 3029 | sb.append(currentMs); |
| 3030 | sb.append("ms)"); |
| 3031 | } else { |
| 3032 | sb.append(" (running)"); |
| 3033 | } |
| 3034 | } |
| 3035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | return ", "; |
| 3037 | } |
| 3038 | } |
| 3039 | return linePrefix; |
| 3040 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3041 | |
| 3042 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3043 | * 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] | 3044 | * |
| 3045 | * @param pw a PrintWriter object to print to. |
| 3046 | * @param sb a StringBuilder object. |
| 3047 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3048 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3049 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 3050 | * @param prefix a String to be prepended to each line of output. |
| 3051 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3052 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3053 | */ |
| 3054 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3055 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3056 | if (timer != null) { |
| 3057 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3058 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 3059 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3060 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3061 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3062 | sb.setLength(0); |
| 3063 | sb.append(prefix); |
| 3064 | sb.append(" "); |
| 3065 | sb.append(type); |
| 3066 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3067 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3068 | sb.append("realtime ("); |
| 3069 | sb.append(count); |
| 3070 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3071 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 3072 | if (maxDurationMs >= 0) { |
| 3073 | sb.append(" max="); |
| 3074 | sb.append(maxDurationMs); |
| 3075 | } |
| 3076 | if (timer.isRunningLocked()) { |
| 3077 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 3078 | if (currentMs >= 0) { |
| 3079 | sb.append(" (running for "); |
| 3080 | sb.append(currentMs); |
| 3081 | sb.append("ms)"); |
| 3082 | } else { |
| 3083 | sb.append(" (running)"); |
| 3084 | } |
| 3085 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3086 | pw.println(sb.toString()); |
| 3087 | return true; |
| 3088 | } |
| 3089 | } |
| 3090 | return false; |
| 3091 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | /** |
| 3094 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3095 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3096 | * @param sb a StringBuilder object. |
| 3097 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3098 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3100 | * @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] | 3101 | * @param linePrefix a String to be prepended to each line of output. |
| 3102 | * @return the line prefix |
| 3103 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3104 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 3105 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | long totalTimeMicros = 0; |
| 3107 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3108 | long max = 0; |
| 3109 | long current = 0; |
| 3110 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3112 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3113 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3114 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3115 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3116 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3117 | } |
| 3118 | sb.append(linePrefix); |
| 3119 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3120 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3121 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3123 | sb.append(','); |
| 3124 | sb.append(current); |
| 3125 | sb.append(','); |
| 3126 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3127 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3128 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3129 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3130 | if (name != null) { |
| 3131 | sb.append(','); |
| 3132 | sb.append(totalDuration); |
| 3133 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3134 | return ","; |
| 3135 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3136 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3137 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3138 | String type) { |
| 3139 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3140 | pw.print(','); |
| 3141 | pw.print(uid); |
| 3142 | pw.print(','); |
| 3143 | pw.print(category); |
| 3144 | pw.print(','); |
| 3145 | pw.print(type); |
| 3146 | } |
| 3147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | /** |
| 3149 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3150 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | * @param pw the PageWriter to dump log to |
| 3152 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3153 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3154 | * @param args type-dependent data arguments |
| 3155 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3156 | 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] | 3157 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3158 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3159 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3160 | pw.print(','); |
| 3161 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3163 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3165 | |
| 3166 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3167 | * Dump a given timer stat for terse checkin mode. |
| 3168 | * |
| 3169 | * @param pw the PageWriter to dump log to |
| 3170 | * @param uid the UID to log |
| 3171 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3172 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3173 | * @param timer a {@link Timer} to dump stats for |
| 3174 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3175 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3176 | */ |
| 3177 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3178 | Timer timer, long rawRealtime, int which) { |
| 3179 | if (timer != null) { |
| 3180 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3181 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3182 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3183 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3184 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3185 | } |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3190 | * Dump a given timer stat to the proto stream. |
| 3191 | * |
| 3192 | * @param proto the ProtoOutputStream to log to |
| 3193 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3194 | * @param timer a {@link Timer} to dump stats for |
| 3195 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3196 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3197 | */ |
| 3198 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3199 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3200 | if (timer == null) { |
| 3201 | return; |
| 3202 | } |
| 3203 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3204 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3205 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3206 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3207 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3208 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3209 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3210 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3211 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3212 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3213 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3214 | // These values will be -1 for timers that don't implement the functionality. |
| 3215 | if (maxDurationMs != -1) { |
| 3216 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3217 | } |
| 3218 | if (curDurationMs != -1) { |
| 3219 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3220 | } |
| 3221 | if (totalDurationMs != -1) { |
| 3222 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3223 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3224 | proto.end(token); |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3229 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3230 | */ |
| 3231 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3232 | if (counter == null) { |
| 3233 | return false; |
| 3234 | } |
| 3235 | |
| 3236 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3237 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3238 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3239 | return true; |
| 3240 | } |
| 3241 | |
| 3242 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3243 | if (c.getCountLocked(which) != 0) { |
| 3244 | return true; |
| 3245 | } |
| 3246 | } |
| 3247 | return false; |
| 3248 | } |
| 3249 | |
| 3250 | /** |
| 3251 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3252 | * The order of the arguments in the final check in line is: |
| 3253 | * |
| 3254 | * idle, rx, power, tx... |
| 3255 | * |
| 3256 | * where tx... is one or more transmit level times. |
| 3257 | */ |
| 3258 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3259 | String type, |
| 3260 | ControllerActivityCounter counter, |
| 3261 | int which) { |
| 3262 | if (!controllerActivityHasData(counter, which)) { |
| 3263 | return; |
| 3264 | } |
| 3265 | |
| 3266 | dumpLineHeader(pw, uid, category, type); |
| 3267 | pw.print(","); |
| 3268 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3269 | pw.print(","); |
| 3270 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3271 | pw.print(","); |
| 3272 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3273 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3274 | pw.print(","); |
| 3275 | pw.print(c.getCountLocked(which)); |
| 3276 | } |
| 3277 | pw.println(); |
| 3278 | } |
| 3279 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3280 | /** |
| 3281 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3282 | */ |
| 3283 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3284 | ControllerActivityCounter counter, |
| 3285 | int which) { |
| 3286 | if (!controllerActivityHasData(counter, which)) { |
| 3287 | return; |
| 3288 | } |
| 3289 | |
| 3290 | final long cToken = proto.start(fieldId); |
| 3291 | |
| 3292 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3293 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3294 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3295 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3296 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3297 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3298 | |
| 3299 | long tToken; |
| 3300 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3301 | for (int i = 0; i < txCounters.length; ++i) { |
| 3302 | LongCounter c = txCounters[i]; |
| 3303 | tToken = proto.start(ControllerActivityProto.TX); |
| 3304 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3305 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3306 | proto.end(tToken); |
| 3307 | } |
| 3308 | |
| 3309 | proto.end(cToken); |
| 3310 | } |
| 3311 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3312 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3313 | String prefix, String controllerName, |
| 3314 | ControllerActivityCounter counter, |
| 3315 | int which) { |
| 3316 | if (controllerActivityHasData(counter, which)) { |
| 3317 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3322 | String controllerName, |
| 3323 | ControllerActivityCounter counter, int which) { |
| 3324 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3325 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3326 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3327 | // Battery real time |
| 3328 | final long totalControllerActivityTimeMs |
| 3329 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3330 | long totalTxTimeMs = 0; |
| 3331 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3332 | totalTxTimeMs += txState.getCountLocked(which); |
| 3333 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3334 | final long sleepTimeMs |
| 3335 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3336 | |
| 3337 | sb.setLength(0); |
| 3338 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3339 | sb.append(" "); |
| 3340 | sb.append(controllerName); |
| 3341 | sb.append(" Sleep time: "); |
| 3342 | formatTimeMs(sb, sleepTimeMs); |
| 3343 | sb.append("("); |
| 3344 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3345 | sb.append(")"); |
| 3346 | pw.println(sb.toString()); |
| 3347 | |
| 3348 | sb.setLength(0); |
| 3349 | sb.append(prefix); |
| 3350 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3351 | sb.append(controllerName); |
| 3352 | sb.append(" Idle time: "); |
| 3353 | formatTimeMs(sb, idleTimeMs); |
| 3354 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3355 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3356 | sb.append(")"); |
| 3357 | pw.println(sb.toString()); |
| 3358 | |
| 3359 | sb.setLength(0); |
| 3360 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3361 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3362 | sb.append(controllerName); |
| 3363 | sb.append(" Rx time: "); |
| 3364 | formatTimeMs(sb, rxTimeMs); |
| 3365 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3366 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3367 | sb.append(")"); |
| 3368 | pw.println(sb.toString()); |
| 3369 | |
| 3370 | sb.setLength(0); |
| 3371 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3372 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3373 | sb.append(controllerName); |
| 3374 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3375 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3376 | String [] powerLevel; |
| 3377 | switch(controllerName) { |
| 3378 | case "Cellular": |
| 3379 | powerLevel = new String[] { |
| 3380 | " less than 0dBm: ", |
| 3381 | " 0dBm to 8dBm: ", |
| 3382 | " 8dBm to 15dBm: ", |
| 3383 | " 15dBm to 20dBm: ", |
| 3384 | " above 20dBm: "}; |
| 3385 | break; |
| 3386 | default: |
| 3387 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3388 | break; |
| 3389 | } |
| 3390 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3391 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3392 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3393 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3394 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3395 | sb.setLength(0); |
| 3396 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3397 | sb.append(" "); |
| 3398 | sb.append(powerLevel[lvl]); |
| 3399 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3400 | formatTimeMs(sb, txLvlTimeMs); |
| 3401 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3402 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3403 | sb.append(")"); |
| 3404 | pw.println(sb.toString()); |
| 3405 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3406 | } else { |
| 3407 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3408 | formatTimeMs(sb, txLvlTimeMs); |
| 3409 | sb.append("("); |
| 3410 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3411 | sb.append(")"); |
| 3412 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3413 | } |
| 3414 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3415 | if (powerDrainMaMs > 0) { |
| 3416 | sb.setLength(0); |
| 3417 | sb.append(prefix); |
| 3418 | sb.append(" "); |
| 3419 | sb.append(controllerName); |
| 3420 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3421 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3422 | sb.append("mAh"); |
| 3423 | pw.println(sb.toString()); |
| 3424 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3428 | * Temporary for settings. |
| 3429 | */ |
| 3430 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3431 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3432 | } |
| 3433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3434 | /** |
| 3435 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3436 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3437 | * 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] | 3438 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3439 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3440 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3442 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3443 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3446 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3447 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3448 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3449 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3451 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3452 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3453 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3454 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3455 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3456 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3457 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3458 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3459 | rawRealtime, which); |
| 3460 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3461 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3462 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3463 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3464 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3465 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3466 | final long dischargeCount = getUahDischarge(which); |
| 3467 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3468 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3469 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3470 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3471 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3472 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3473 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3474 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3475 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3476 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3477 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3479 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3480 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3481 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3482 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3483 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3484 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3485 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3486 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3487 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3488 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3489 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3490 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3491 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3492 | long fullWakeLockTimeTotal = 0; |
| 3493 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3494 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3495 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3496 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3497 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3498 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3499 | = u.getWakelockStats(); |
| 3500 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3501 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3502 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3503 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3504 | if (fullWakeTimer != null) { |
| 3505 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3506 | which); |
| 3507 | } |
| 3508 | |
| 3509 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3510 | if (partialWakeTimer != null) { |
| 3511 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3512 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3513 | } |
| 3514 | } |
| 3515 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3516 | |
| 3517 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3518 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3519 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3520 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3521 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3522 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3523 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3524 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3525 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3526 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3527 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3528 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3529 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3530 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3531 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3532 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3533 | // Dump Modem controller stats |
| 3534 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3535 | getModemControllerActivity(), which); |
| 3536 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3537 | // Dump Wifi controller stats |
| 3538 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3539 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3540 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3541 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3542 | |
| 3543 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3544 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3545 | |
| 3546 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3547 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3548 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | // Dump misc stats |
| 3551 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3552 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3553 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3554 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3555 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3556 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3557 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3558 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3559 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3560 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3561 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3562 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3563 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3564 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3565 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3566 | // Dump screen brightness stats |
| 3567 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3568 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3569 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3570 | } |
| 3571 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3572 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3573 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3574 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3575 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3576 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3577 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3578 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3579 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3580 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3581 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3582 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3583 | } |
| 3584 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3585 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3586 | // Dump network type stats |
| 3587 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3588 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3589 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3590 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3591 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3592 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3593 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3594 | } |
| 3595 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3596 | |
| 3597 | // Dump wifi state stats |
| 3598 | args = new Object[NUM_WIFI_STATES]; |
| 3599 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3600 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3601 | } |
| 3602 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3603 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3604 | args[i] = getWifiStateCount(i, which); |
| 3605 | } |
| 3606 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3607 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3608 | // Dump wifi suppl state stats |
| 3609 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3610 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3611 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3612 | } |
| 3613 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3614 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3615 | args[i] = getWifiSupplStateCount(i, which); |
| 3616 | } |
| 3617 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3618 | |
| 3619 | // Dump wifi signal strength stats |
| 3620 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3621 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3622 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3623 | } |
| 3624 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3625 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3626 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3627 | } |
| 3628 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3629 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3630 | // Dump Multicast total stats |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 3631 | final long multicastWakeLockTimeTotalMicros = |
| 3632 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 3633 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3634 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3635 | multicastWakeLockTimeTotalMicros / 1000, |
| 3636 | multicastWakeLockCountTotal); |
| 3637 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3638 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3639 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3640 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3641 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3642 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3643 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3644 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3645 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3646 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3647 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3648 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3649 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3650 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3651 | } else { |
| 3652 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3653 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3654 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3655 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3656 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3657 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3658 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3659 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3660 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3661 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3662 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3663 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3664 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3665 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3666 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3667 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3668 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3669 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3670 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3671 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3672 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3673 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3674 | // Not doing the regular wake lock formatting to remain compatible |
| 3675 | // with the old checkin format. |
| 3676 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3677 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3678 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3679 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3680 | } |
| 3681 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3682 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3683 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3684 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3685 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3686 | if (rpmStats.size() > 0) { |
| 3687 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3688 | sb.setLength(0); |
| 3689 | Timer totalTimer = ent.getValue(); |
| 3690 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3691 | int count = totalTimer.getCountLocked(which); |
| 3692 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3693 | long screenOffTimeMs = screenOffTimer != null |
| 3694 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3695 | int screenOffCount = screenOffTimer != null |
| 3696 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3697 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3698 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3699 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3700 | screenOffCount); |
| 3701 | } else { |
| 3702 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3703 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3704 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3705 | } |
| 3706 | } |
| 3707 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3708 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3709 | helper.create(this); |
| 3710 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3711 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3712 | if (sippers != null && sippers.size() > 0) { |
| 3713 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3714 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3715 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3716 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3717 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3718 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3719 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3720 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3721 | String label; |
| 3722 | switch (bs.drainType) { |
| 3723 | case IDLE: |
| 3724 | label="idle"; |
| 3725 | break; |
| 3726 | case CELL: |
| 3727 | label="cell"; |
| 3728 | break; |
| 3729 | case PHONE: |
| 3730 | label="phone"; |
| 3731 | break; |
| 3732 | case WIFI: |
| 3733 | label="wifi"; |
| 3734 | break; |
| 3735 | case BLUETOOTH: |
| 3736 | label="blue"; |
| 3737 | break; |
| 3738 | case SCREEN: |
| 3739 | label="scrn"; |
| 3740 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3741 | case FLASHLIGHT: |
| 3742 | label="flashlight"; |
| 3743 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3744 | case APP: |
| 3745 | uid = bs.uidObj.getUid(); |
| 3746 | label = "uid"; |
| 3747 | break; |
| 3748 | case USER: |
| 3749 | uid = UserHandle.getUid(bs.userId, 0); |
| 3750 | label = "user"; |
| 3751 | break; |
| 3752 | case UNACCOUNTED: |
| 3753 | label = "unacc"; |
| 3754 | break; |
| 3755 | case OVERCOUNTED: |
| 3756 | label = "over"; |
| 3757 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3758 | case CAMERA: |
| 3759 | label = "camera"; |
| 3760 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3761 | case MEMORY: |
| 3762 | label = "memory"; |
| 3763 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3764 | default: |
| 3765 | label = "???"; |
| 3766 | } |
| 3767 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3768 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3769 | bs.shouldHide ? 1 : 0, |
| 3770 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3771 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3775 | final long[] cpuFreqs = getCpuFreqs(); |
| 3776 | if (cpuFreqs != null) { |
| 3777 | sb.setLength(0); |
| 3778 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3779 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3780 | } |
| 3781 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3782 | } |
| 3783 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3784 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | for (int iu = 0; iu < NU; iu++) { |
| 3786 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3787 | if (reqUid >= 0 && uid != reqUid) { |
| 3788 | continue; |
| 3789 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3790 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3793 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3794 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3795 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3796 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3797 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3798 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3799 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3800 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3801 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3802 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3803 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3804 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3805 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3806 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3807 | // Background data transfers |
| 3808 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3809 | which); |
| 3810 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3811 | which); |
| 3812 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3813 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3814 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3815 | which); |
| 3816 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3817 | which); |
| 3818 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3819 | which); |
| 3820 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3821 | which); |
| 3822 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3823 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3824 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3825 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3826 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3827 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3828 | || wifiBytesBgTx > 0 |
| 3829 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3830 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3831 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3832 | wifiBytesRx, wifiBytesTx, |
| 3833 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3834 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3835 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3836 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3837 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3838 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3839 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3842 | // Dump modem controller data, per UID. |
| 3843 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3844 | u.getModemControllerActivity(), which); |
| 3845 | |
| 3846 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3847 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3848 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3849 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3850 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3851 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3852 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3853 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3854 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3855 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3856 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3857 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3858 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3859 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3860 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3861 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3862 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3865 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3866 | u.getWifiControllerActivity(), which); |
| 3867 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3868 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3869 | if (bleTimer != null) { |
| 3870 | // Convert from microseconds to milliseconds with rounding |
| 3871 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3872 | / 1000; |
| 3873 | if (totalTime != 0) { |
| 3874 | final int count = bleTimer.getCountLocked(which); |
| 3875 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3876 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3877 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3878 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3879 | final long actualTimeBg = bleTimerBg != null ? |
| 3880 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3881 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3882 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3883 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3884 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3885 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3886 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3887 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3888 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3889 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3890 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3891 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3892 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3893 | final Timer unoptimizedScanTimerBg = |
| 3894 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3895 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3896 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3897 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3898 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3899 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3900 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3901 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3902 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3903 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3904 | } |
| 3905 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3906 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3907 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3908 | u.getBluetoothControllerActivity(), which); |
| 3909 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3910 | if (u.hasUserActivity()) { |
| 3911 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3912 | boolean hasData = false; |
| 3913 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3914 | int val = u.getUserActivityCount(i, which); |
| 3915 | args[i] = val; |
| 3916 | if (val != 0) hasData = true; |
| 3917 | } |
| 3918 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3919 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3920 | } |
| 3921 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3922 | |
| 3923 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3924 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3925 | // Times are since reset (regardless of 'which') |
| 3926 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3927 | final Timer bgTimer = timer.getSubTimer(); |
| 3928 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3929 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3930 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3931 | } |
| 3932 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3933 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3934 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3935 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3936 | String linePrefix = ""; |
| 3937 | sb.setLength(0); |
| 3938 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3939 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3940 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3941 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3942 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3943 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3944 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3945 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3946 | rawRealtime, "w", which, linePrefix); |
| 3947 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3948 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3949 | if (sb.length() > 0) { |
| 3950 | String name = wakelocks.keyAt(iw); |
| 3951 | if (name.indexOf(',') >= 0) { |
| 3952 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3954 | if (name.indexOf('\n') >= 0) { |
| 3955 | name = name.replace('\n', '_'); |
| 3956 | } |
| 3957 | if (name.indexOf('\r') >= 0) { |
| 3958 | name = name.replace('\r', '_'); |
| 3959 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3960 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3961 | } |
| 3962 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3963 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3964 | // WiFi Multicast Wakelock Statistics |
| 3965 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3966 | if (mcTimer != null) { |
| 3967 | final long totalMcWakelockTimeMs = |
| 3968 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 3969 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 3970 | if(totalMcWakelockTimeMs > 0) { |
| 3971 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 3972 | totalMcWakelockTimeMs, countMcWakelock); |
| 3973 | } |
| 3974 | } |
| 3975 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3976 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3977 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3978 | final Timer timer = syncs.valueAt(isy); |
| 3979 | // Convert from microseconds to milliseconds with rounding |
| 3980 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3981 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3982 | final Timer bgTimer = timer.getSubTimer(); |
| 3983 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3984 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3985 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3986 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3987 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3988 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3992 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3993 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3994 | final Timer timer = jobs.valueAt(ij); |
| 3995 | // Convert from microseconds to milliseconds with rounding |
| 3996 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3997 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3998 | final Timer bgTimer = timer.getSubTimer(); |
| 3999 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4000 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4001 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4002 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4003 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4004 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4005 | } |
| 4006 | } |
| 4007 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4008 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 4009 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 4010 | SparseIntArray types = completions.valueAt(ic); |
| 4011 | if (types != null) { |
| 4012 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 4013 | "\"" + completions.keyAt(ic) + "\"", |
| 4014 | types.get(JobParameters.REASON_CANCELED, 0), |
| 4015 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 4016 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 4017 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 4018 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 4019 | } |
| 4020 | } |
| 4021 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4022 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 4023 | rawRealtime, which); |
| 4024 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 4025 | rawRealtime, which); |
| 4026 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 4027 | rawRealtime, which); |
| 4028 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 4029 | rawRealtime, which); |
| 4030 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4031 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4032 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4033 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4034 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4035 | final int sensorNumber = sensors.keyAt(ise); |
| 4036 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4037 | if (timer != null) { |
| 4038 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4039 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4040 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4041 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4042 | final int count = timer.getCountLocked(which); |
| 4043 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4044 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4045 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4046 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4047 | final long bgActualTime = bgTimer != null ? |
| 4048 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4049 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 4050 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4051 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4055 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 4056 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4057 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 4058 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 4059 | rawRealtime, which); |
| 4060 | |
| 4061 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4062 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4063 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4064 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4065 | long totalStateTime = 0; |
| 4066 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4067 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4068 | totalStateTime += time; |
| 4069 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4070 | } |
| 4071 | if (totalStateTime > 0) { |
| 4072 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 4073 | } |
| 4074 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4075 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4076 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4077 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4078 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4079 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4082 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 4083 | if (cpuFreqs != null) { |
| 4084 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 4085 | // If total cpuFreqTimes is null, then we don't need to check for |
| 4086 | // screenOffCpuFreqTimes. |
| 4087 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 4088 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4089 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4090 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4091 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 4092 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 4093 | if (screenOffCpuFreqTimeMs != null) { |
| 4094 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 4095 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 4096 | } |
| 4097 | } else { |
| 4098 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 4099 | sb.append(",0"); |
| 4100 | } |
| 4101 | } |
| 4102 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4103 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4104 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4105 | |
| 4106 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 4107 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 4108 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 4109 | sb.setLength(0); |
| 4110 | for (int i = 0; i < timesMs.length; ++i) { |
| 4111 | sb.append((i == 0 ? "" : ",") + timesMs[i]); |
| 4112 | } |
| 4113 | final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes( |
| 4114 | which, procState); |
| 4115 | if (screenOffTimesMs != null) { |
| 4116 | for (int i = 0; i < screenOffTimesMs.length; ++i) { |
| 4117 | sb.append("," + screenOffTimesMs[i]); |
| 4118 | } |
| 4119 | } else { |
| 4120 | for (int i = 0; i < timesMs.length; ++i) { |
| 4121 | sb.append(",0"); |
| 4122 | } |
| 4123 | } |
| 4124 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, |
| 4125 | Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString()); |
| 4126 | } |
| 4127 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4130 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4131 | = u.getProcessStats(); |
| 4132 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4133 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4134 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4135 | final long userMillis = ps.getUserTime(which); |
| 4136 | final long systemMillis = ps.getSystemTime(which); |
| 4137 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4138 | final int starts = ps.getStarts(which); |
| 4139 | final int numCrashes = ps.getNumCrashes(which); |
| 4140 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4141 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4142 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4143 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4144 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4145 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4149 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4150 | = u.getPackageStats(); |
| 4151 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4152 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4153 | int wakeups = 0; |
| 4154 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4155 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4156 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4157 | wakeups += count; |
| 4158 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4159 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4160 | } |
| 4161 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4162 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4163 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4164 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4165 | final int starts = ss.getStarts(which); |
| 4166 | final int launches = ss.getLaunches(which); |
| 4167 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4168 | dumpLine(pw, uid, category, APK_DATA, |
| 4169 | wakeups, // wakeup alarms |
| 4170 | packageStats.keyAt(ipkg), // Apk |
| 4171 | serviceStats.keyAt(isvc), // service |
| 4172 | startTime / 1000, // time spent started, in ms |
| 4173 | starts, |
| 4174 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | } |
| 4176 | } |
| 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4181 | static final class TimerEntry { |
| 4182 | final String mName; |
| 4183 | final int mId; |
| 4184 | final BatteryStats.Timer mTimer; |
| 4185 | final long mTime; |
| 4186 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4187 | mName = name; |
| 4188 | mId = id; |
| 4189 | mTimer = timer; |
| 4190 | mTime = time; |
| 4191 | } |
| 4192 | } |
| 4193 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4194 | private void printmAh(PrintWriter printer, double power) { |
| 4195 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4196 | } |
| 4197 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4198 | private void printmAh(StringBuilder sb, double power) { |
| 4199 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4200 | } |
| 4201 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4202 | /** |
| 4203 | * Temporary for settings. |
| 4204 | */ |
| 4205 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4206 | int reqUid) { |
| 4207 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4208 | } |
| 4209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4211 | 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] | 4212 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4214 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4215 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | |
| 4218 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4219 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4220 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4221 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4222 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4223 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4224 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4225 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4226 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4227 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4228 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4229 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4230 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4231 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4232 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4234 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4235 | if (estimatedBatteryCapacity > 0) { |
| 4236 | sb.setLength(0); |
| 4237 | sb.append(prefix); |
| 4238 | sb.append(" Estimated battery capacity: "); |
| 4239 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4240 | sb.append(" mAh"); |
| 4241 | pw.println(sb.toString()); |
| 4242 | } |
| 4243 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4244 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4245 | if (minLearnedBatteryCapacity > 0) { |
| 4246 | sb.setLength(0); |
| 4247 | sb.append(prefix); |
| 4248 | sb.append(" Min learned battery capacity: "); |
| 4249 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4250 | sb.append(" mAh"); |
| 4251 | pw.println(sb.toString()); |
| 4252 | } |
| 4253 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4254 | if (maxLearnedBatteryCapacity > 0) { |
| 4255 | sb.setLength(0); |
| 4256 | sb.append(prefix); |
| 4257 | sb.append(" Max learned battery capacity: "); |
| 4258 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4259 | sb.append(" mAh"); |
| 4260 | pw.println(sb.toString()); |
| 4261 | } |
| 4262 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4263 | sb.setLength(0); |
| 4264 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4265 | sb.append(" Time on battery: "); |
| 4266 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4267 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4268 | sb.append(") realtime, "); |
| 4269 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4270 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4271 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4272 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4273 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4274 | sb.setLength(0); |
| 4275 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4276 | sb.append(" Time on battery screen off: "); |
| 4277 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4278 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4279 | sb.append(") realtime, "); |
| 4280 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4281 | sb.append("("); |
| 4282 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4283 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4284 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4285 | |
| 4286 | sb.setLength(0); |
| 4287 | sb.append(prefix); |
| 4288 | sb.append(" Time on battery screen doze: "); |
| 4289 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4290 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4291 | sb.append(")"); |
| 4292 | pw.println(sb.toString()); |
| 4293 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4294 | sb.setLength(0); |
| 4295 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4296 | sb.append(" Total run time: "); |
| 4297 | formatTimeMs(sb, totalRealtime / 1000); |
| 4298 | sb.append("realtime, "); |
| 4299 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4300 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4301 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4302 | if (batteryTimeRemaining >= 0) { |
| 4303 | sb.setLength(0); |
| 4304 | sb.append(prefix); |
| 4305 | sb.append(" Battery time remaining: "); |
| 4306 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4307 | pw.println(sb.toString()); |
| 4308 | } |
| 4309 | if (chargeTimeRemaining >= 0) { |
| 4310 | sb.setLength(0); |
| 4311 | sb.append(prefix); |
| 4312 | sb.append(" Charge time remaining: "); |
| 4313 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4314 | pw.println(sb.toString()); |
| 4315 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4316 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4317 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4318 | if (dischargeCount >= 0) { |
| 4319 | sb.setLength(0); |
| 4320 | sb.append(prefix); |
| 4321 | sb.append(" Discharge: "); |
| 4322 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4323 | sb.append(" mAh"); |
| 4324 | pw.println(sb.toString()); |
| 4325 | } |
| 4326 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4327 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4328 | if (dischargeScreenOffCount >= 0) { |
| 4329 | sb.setLength(0); |
| 4330 | sb.append(prefix); |
| 4331 | sb.append(" Screen off discharge: "); |
| 4332 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4333 | sb.append(" mAh"); |
| 4334 | pw.println(sb.toString()); |
| 4335 | } |
| 4336 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4337 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4338 | if (dischargeScreenDozeCount >= 0) { |
| 4339 | sb.setLength(0); |
| 4340 | sb.append(prefix); |
| 4341 | sb.append(" Screen doze discharge: "); |
| 4342 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4343 | sb.append(" mAh"); |
| 4344 | pw.println(sb.toString()); |
| 4345 | } |
| 4346 | |
| 4347 | final long dischargeScreenOnCount = |
| 4348 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4349 | if (dischargeScreenOnCount >= 0) { |
| 4350 | sb.setLength(0); |
| 4351 | sb.append(prefix); |
| 4352 | sb.append(" Screen on discharge: "); |
| 4353 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4354 | sb.append(" mAh"); |
| 4355 | pw.println(sb.toString()); |
| 4356 | } |
| 4357 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4358 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4359 | if (dischargeLightDozeCount >= 0) { |
| 4360 | sb.setLength(0); |
| 4361 | sb.append(prefix); |
| 4362 | sb.append(" Device light doze discharge: "); |
| 4363 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4364 | sb.append(" mAh"); |
| 4365 | pw.println(sb.toString()); |
| 4366 | } |
| 4367 | |
| 4368 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4369 | if (dischargeDeepDozeCount >= 0) { |
| 4370 | sb.setLength(0); |
| 4371 | sb.append(prefix); |
| 4372 | sb.append(" Device deep doze discharge: "); |
| 4373 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4374 | sb.append(" mAh"); |
| 4375 | pw.println(sb.toString()); |
| 4376 | } |
| 4377 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4378 | pw.print(" Start clock time: "); |
| 4379 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4380 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4381 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4382 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4383 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4384 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4385 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4386 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4387 | rawRealtime, which); |
| 4388 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4389 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4390 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4391 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4392 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4393 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4394 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4395 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4396 | sb.append(prefix); |
| 4397 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4398 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4399 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4400 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4401 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4402 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4403 | pw.println(sb.toString()); |
| 4404 | sb.setLength(0); |
| 4405 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4406 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4407 | boolean didOne = false; |
| 4408 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4409 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4410 | if (time == 0) { |
| 4411 | continue; |
| 4412 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4413 | sb.append("\n "); |
| 4414 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4415 | didOne = true; |
| 4416 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4417 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4418 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4419 | sb.append("("); |
| 4420 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4421 | sb.append(")"); |
| 4422 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4423 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4424 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4425 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4426 | sb.setLength(0); |
| 4427 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4428 | sb.append(" Power save mode enabled: "); |
| 4429 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4430 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4431 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4432 | sb.append(")"); |
| 4433 | pw.println(sb.toString()); |
| 4434 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4435 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4436 | sb.setLength(0); |
| 4437 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4438 | sb.append(" Device light idling: "); |
| 4439 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4440 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4441 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4442 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4443 | sb.append("x"); |
| 4444 | pw.println(sb.toString()); |
| 4445 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4446 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4447 | sb.setLength(0); |
| 4448 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4449 | sb.append(" Idle mode light time: "); |
| 4450 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4451 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4452 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4453 | sb.append(") "); |
| 4454 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4455 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4456 | sb.append(" -- longest "); |
| 4457 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4458 | pw.println(sb.toString()); |
| 4459 | } |
| 4460 | if (deviceIdlingTime != 0) { |
| 4461 | sb.setLength(0); |
| 4462 | sb.append(prefix); |
| 4463 | sb.append(" Device full idling: "); |
| 4464 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4465 | sb.append("("); |
| 4466 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4467 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4468 | sb.append("x"); |
| 4469 | pw.println(sb.toString()); |
| 4470 | } |
| 4471 | if (deviceIdleModeFullTime != 0) { |
| 4472 | sb.setLength(0); |
| 4473 | sb.append(prefix); |
| 4474 | sb.append(" Idle mode full time: "); |
| 4475 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4476 | sb.append("("); |
| 4477 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4478 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4479 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4480 | sb.append("x"); |
| 4481 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4482 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4483 | pw.println(sb.toString()); |
| 4484 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4485 | if (phoneOnTime != 0) { |
| 4486 | sb.setLength(0); |
| 4487 | sb.append(prefix); |
| 4488 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4489 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4490 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4491 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4492 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4493 | if (connChanges != 0) { |
| 4494 | pw.print(prefix); |
| 4495 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4496 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4497 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4498 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4499 | long fullWakeLockTimeTotalMicros = 0; |
| 4500 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4501 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4502 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4503 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4504 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4505 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4506 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4507 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4508 | = u.getWakelockStats(); |
| 4509 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4510 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4511 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4512 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4513 | if (fullWakeTimer != null) { |
| 4514 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4515 | rawRealtime, which); |
| 4516 | } |
| 4517 | |
| 4518 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4519 | if (partialWakeTimer != null) { |
| 4520 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4521 | rawRealtime, which); |
| 4522 | if (totalTimeMicros > 0) { |
| 4523 | if (reqUid < 0) { |
| 4524 | // Only show the ordered list of all wake |
| 4525 | // locks if the caller is not asking for data |
| 4526 | // about a specific uid. |
| 4527 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4528 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4529 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4530 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | } |
| 4534 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4535 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4536 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4537 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4538 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4539 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4540 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4541 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4542 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4543 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4544 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4545 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4546 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4547 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4548 | sb.setLength(0); |
| 4549 | sb.append(prefix); |
| 4550 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4551 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4552 | pw.println(sb.toString()); |
| 4553 | } |
| 4554 | |
| 4555 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4556 | sb.setLength(0); |
| 4557 | sb.append(prefix); |
| 4558 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4559 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4560 | pw.println(sb.toString()); |
| 4561 | } |
| 4562 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 4563 | final long multicastWakeLockTimeTotalMicros = |
| 4564 | getWifiMulticastWakelockTime(rawRealtime, which); |
| 4565 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4566 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4567 | sb.setLength(0); |
| 4568 | sb.append(prefix); |
| 4569 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4570 | sb.append(multicastWakeLockCountTotal); |
| 4571 | pw.println(sb.toString()); |
| 4572 | |
| 4573 | sb.setLength(0); |
| 4574 | sb.append(prefix); |
| 4575 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4576 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4577 | pw.println(sb.toString()); |
| 4578 | } |
| 4579 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4580 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4581 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4582 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4583 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4584 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4585 | pw.println(sb.toString()); |
| 4586 | |
| 4587 | pw.print(prefix); |
| 4588 | sb.setLength(0); |
| 4589 | sb.append(prefix); |
| 4590 | sb.append(" Logging duration for connectivity statistics: "); |
| 4591 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4592 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4593 | |
| 4594 | sb.setLength(0); |
| 4595 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4596 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4597 | pw.println(sb.toString()); |
| 4598 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4599 | pw.print(prefix); |
| 4600 | sb.setLength(0); |
| 4601 | sb.append(prefix); |
| 4602 | sb.append(" Cellular kernel active time: "); |
| 4603 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4604 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4605 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4606 | sb.append(")"); |
| 4607 | pw.println(sb.toString()); |
| 4608 | |
| 4609 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4610 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4611 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4612 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4613 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4614 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4615 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4616 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4617 | didOne = false; |
| 4618 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4619 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4620 | if (time == 0) { |
| 4621 | continue; |
| 4622 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4623 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4624 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4625 | didOne = true; |
| 4626 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4627 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4628 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4629 | sb.append("("); |
| 4630 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4631 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4632 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4633 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4634 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4635 | |
| 4636 | sb.setLength(0); |
| 4637 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4638 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4639 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4640 | "very poor (less than -128dBm): ", |
| 4641 | "poor (-128dBm to -118dBm): ", |
| 4642 | "moderate (-118dBm to -108dBm): ", |
| 4643 | "good (-108dBm to -98dBm): ", |
| 4644 | "great (greater than -98dBm): "}; |
| 4645 | didOne = false; |
| 4646 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4647 | cellularRxSignalStrengthDescription.length); |
| 4648 | for (int i=0; i<numCellularRxBins; i++) { |
| 4649 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4650 | if (time == 0) { |
| 4651 | continue; |
| 4652 | } |
| 4653 | sb.append("\n "); |
| 4654 | sb.append(prefix); |
| 4655 | didOne = true; |
| 4656 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4657 | sb.append(" "); |
| 4658 | formatTimeMs(sb, time/1000); |
| 4659 | sb.append("("); |
| 4660 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4661 | sb.append(") "); |
| 4662 | } |
| 4663 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4664 | pw.println(sb.toString()); |
| 4665 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4666 | printControllerActivity(pw, sb, prefix, "Cellular", |
| 4667 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4668 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4669 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4670 | sb.setLength(0); |
| 4671 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4672 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4673 | pw.println(sb.toString()); |
| 4674 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4675 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4676 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4677 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4678 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4679 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4680 | sb.setLength(0); |
| 4681 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4682 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4683 | didOne = false; |
| 4684 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4685 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4686 | if (time == 0) { |
| 4687 | continue; |
| 4688 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4689 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4690 | didOne = true; |
| 4691 | sb.append(WIFI_STATE_NAMES[i]); |
| 4692 | sb.append(" "); |
| 4693 | formatTimeMs(sb, time/1000); |
| 4694 | sb.append("("); |
| 4695 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4696 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4697 | } |
| 4698 | if (!didOne) sb.append(" (no activity)"); |
| 4699 | pw.println(sb.toString()); |
| 4700 | |
| 4701 | sb.setLength(0); |
| 4702 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4703 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4704 | didOne = false; |
| 4705 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4706 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4707 | if (time == 0) { |
| 4708 | continue; |
| 4709 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4710 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4711 | didOne = true; |
| 4712 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4713 | sb.append(" "); |
| 4714 | formatTimeMs(sb, time/1000); |
| 4715 | sb.append("("); |
| 4716 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4717 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4718 | } |
| 4719 | if (!didOne) sb.append(" (no activity)"); |
| 4720 | pw.println(sb.toString()); |
| 4721 | |
| 4722 | sb.setLength(0); |
| 4723 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4724 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4725 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4726 | "very poor (less than -88.75dBm): ", |
| 4727 | "poor (-88.75 to -77.5dBm): ", |
| 4728 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4729 | "good (-66.25dBm to -55dBm): ", |
| 4730 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4731 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4732 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4733 | wifiRxSignalStrengthDescription.length); |
| 4734 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4735 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4736 | if (time == 0) { |
| 4737 | continue; |
| 4738 | } |
| 4739 | sb.append("\n "); |
| 4740 | sb.append(prefix); |
| 4741 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4742 | sb.append(" "); |
| 4743 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4744 | formatTimeMs(sb, time/1000); |
| 4745 | sb.append("("); |
| 4746 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4747 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4748 | } |
| 4749 | if (!didOne) sb.append(" (no activity)"); |
| 4750 | pw.println(sb.toString()); |
| 4751 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4752 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4753 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4754 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4755 | sb.setLength(0); |
| 4756 | sb.append(prefix); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame^] | 4757 | sb.append(" GPS Statistics:"); |
| 4758 | pw.println(sb.toString()); |
| 4759 | |
| 4760 | sb.setLength(0); |
| 4761 | sb.append(prefix); |
| 4762 | sb.append(" GPS signal quality (Top 4 Average CN0):"); |
| 4763 | final String[] gpsSignalQualityDescription = new String[]{ |
| 4764 | "poor (less than 20 dBHz): ", |
| 4765 | "good (greater than 20 dBHz): "}; |
| 4766 | final int numGpsSignalQualityBins = Math.min(GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS, |
| 4767 | gpsSignalQualityDescription.length); |
| 4768 | for (int i=0; i<numGpsSignalQualityBins; i++) { |
| 4769 | final long time = getGpsSignalQualityTime(i, rawRealtime, which); |
| 4770 | sb.append("\n "); |
| 4771 | sb.append(prefix); |
| 4772 | sb.append(" "); |
| 4773 | sb.append(gpsSignalQualityDescription[i]); |
| 4774 | formatTimeMs(sb, time/1000); |
| 4775 | sb.append("("); |
| 4776 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4777 | sb.append(") "); |
| 4778 | } |
| 4779 | pw.println(sb.toString()); |
| 4780 | |
| 4781 | final long gpsBatteryDrainMaMs = getGpsBatteryDrainMaMs(); |
| 4782 | if (gpsBatteryDrainMaMs > 0) { |
| 4783 | pw.print(prefix); |
| 4784 | sb.setLength(0); |
| 4785 | sb.append(prefix); |
| 4786 | sb.append(" Battery Drain (mAh): "); |
| 4787 | sb.append(Double.toString(((double) gpsBatteryDrainMaMs)/(3600 * 1000))); |
| 4788 | pw.println(sb.toString()); |
| 4789 | } |
| 4790 | |
| 4791 | pw.print(prefix); |
| 4792 | sb.setLength(0); |
| 4793 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4794 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4795 | pw.println(sb.toString()); |
| 4796 | pw.println(""); |
| 4797 | |
| 4798 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4799 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4800 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4801 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4802 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4803 | sb.setLength(0); |
| 4804 | sb.append(prefix); |
| 4805 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4806 | pw.println(sb.toString()); |
| 4807 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4808 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4809 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4810 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4811 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4812 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4813 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4814 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4815 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4816 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4817 | pw.println(getDischargeStartLevel()); |
| 4818 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4819 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4820 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4821 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4822 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4823 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4824 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4825 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4826 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4827 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4828 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4829 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4830 | pw.println(getDischargeAmountScreenOff()); |
| 4831 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4832 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4833 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4834 | } else { |
| 4835 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4836 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4837 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4838 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4839 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4840 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4841 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4842 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4843 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4844 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4845 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4846 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4847 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4848 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4849 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4850 | helper.create(this); |
| 4851 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4852 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4853 | if (sippers != null && sippers.size() > 0) { |
| 4854 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4855 | pw.print(prefix); pw.print(" Capacity: "); |
| 4856 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4857 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4858 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4859 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4860 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4861 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4862 | pw.println(); |
| 4863 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4864 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4865 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4866 | switch (bs.drainType) { |
| 4867 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4868 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4869 | break; |
| 4870 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4871 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4872 | break; |
| 4873 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4874 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4875 | break; |
| 4876 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4877 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4878 | break; |
| 4879 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4880 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4881 | break; |
| 4882 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4883 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4884 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4885 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4886 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4887 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4888 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4889 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4890 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4891 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4892 | break; |
| 4893 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4894 | pw.print(" User "); pw.print(bs.userId); |
| 4895 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4896 | break; |
| 4897 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4898 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4899 | break; |
| 4900 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4901 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4902 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4903 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4904 | pw.print(" Camera: "); |
| 4905 | break; |
| 4906 | default: |
| 4907 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4908 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4909 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4910 | printmAh(pw, bs.totalPowerMah); |
| 4911 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4912 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4913 | // If the usage (generic power) isn't the whole amount, we list out |
| 4914 | // what components are involved in the calculation. |
| 4915 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4916 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4917 | if (bs.usagePowerMah != 0) { |
| 4918 | pw.print(" usage="); |
| 4919 | printmAh(pw, bs.usagePowerMah); |
| 4920 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4921 | if (bs.cpuPowerMah != 0) { |
| 4922 | pw.print(" cpu="); |
| 4923 | printmAh(pw, bs.cpuPowerMah); |
| 4924 | } |
| 4925 | if (bs.wakeLockPowerMah != 0) { |
| 4926 | pw.print(" wake="); |
| 4927 | printmAh(pw, bs.wakeLockPowerMah); |
| 4928 | } |
| 4929 | if (bs.mobileRadioPowerMah != 0) { |
| 4930 | pw.print(" radio="); |
| 4931 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4932 | } |
| 4933 | if (bs.wifiPowerMah != 0) { |
| 4934 | pw.print(" wifi="); |
| 4935 | printmAh(pw, bs.wifiPowerMah); |
| 4936 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4937 | if (bs.bluetoothPowerMah != 0) { |
| 4938 | pw.print(" bt="); |
| 4939 | printmAh(pw, bs.bluetoothPowerMah); |
| 4940 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4941 | if (bs.gpsPowerMah != 0) { |
| 4942 | pw.print(" gps="); |
| 4943 | printmAh(pw, bs.gpsPowerMah); |
| 4944 | } |
| 4945 | if (bs.sensorPowerMah != 0) { |
| 4946 | pw.print(" sensor="); |
| 4947 | printmAh(pw, bs.sensorPowerMah); |
| 4948 | } |
| 4949 | if (bs.cameraPowerMah != 0) { |
| 4950 | pw.print(" camera="); |
| 4951 | printmAh(pw, bs.cameraPowerMah); |
| 4952 | } |
| 4953 | if (bs.flashlightPowerMah != 0) { |
| 4954 | pw.print(" flash="); |
| 4955 | printmAh(pw, bs.flashlightPowerMah); |
| 4956 | } |
| 4957 | pw.print(" )"); |
| 4958 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4959 | |
| 4960 | // If there is additional smearing information, include it. |
| 4961 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4962 | pw.print(" Including smearing: "); |
| 4963 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4964 | pw.print(" ("); |
| 4965 | if (bs.screenPowerMah != 0) { |
| 4966 | pw.print(" screen="); |
| 4967 | printmAh(pw, bs.screenPowerMah); |
| 4968 | } |
| 4969 | if (bs.proportionalSmearMah != 0) { |
| 4970 | pw.print(" proportional="); |
| 4971 | printmAh(pw, bs.proportionalSmearMah); |
| 4972 | } |
| 4973 | pw.print(" )"); |
| 4974 | } |
| 4975 | if (bs.shouldHide) { |
| 4976 | pw.print(" Excluded from smearing"); |
| 4977 | } |
| 4978 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4979 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4980 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4981 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4984 | sippers = helper.getMobilemsppList(); |
| 4985 | if (sippers != null && sippers.size() > 0) { |
| 4986 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4987 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4988 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4989 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4990 | sb.setLength(0); |
| 4991 | sb.append(prefix); sb.append(" Uid "); |
| 4992 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4993 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4994 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4995 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4996 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4997 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4998 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4999 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5000 | sb.setLength(0); |
| 5001 | sb.append(prefix); |
| 5002 | sb.append(" TOTAL TIME: "); |
| 5003 | formatTimeMs(sb, totalTime); |
| 5004 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 5005 | sb.append(")"); |
| 5006 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5007 | pw.println(); |
| 5008 | } |
| 5009 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5010 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 5011 | @Override |
| 5012 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 5013 | long lhsTime = lhs.mTime; |
| 5014 | long rhsTime = rhs.mTime; |
| 5015 | if (lhsTime < rhsTime) { |
| 5016 | return 1; |
| 5017 | } |
| 5018 | if (lhsTime > rhsTime) { |
| 5019 | return -1; |
| 5020 | } |
| 5021 | return 0; |
| 5022 | } |
| 5023 | }; |
| 5024 | |
| 5025 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5026 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 5027 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5028 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5029 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 5030 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 5031 | : kernelWakelocks.entrySet()) { |
| 5032 | final BatteryStats.Timer timer = ent.getValue(); |
| 5033 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5034 | if (totalTimeMillis > 0) { |
| 5035 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 5036 | } |
| 5037 | } |
| 5038 | if (ktimers.size() > 0) { |
| 5039 | Collections.sort(ktimers, timerComparator); |
| 5040 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 5041 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5042 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5043 | String linePrefix = ": "; |
| 5044 | sb.setLength(0); |
| 5045 | sb.append(prefix); |
| 5046 | sb.append(" Kernel Wake lock "); |
| 5047 | sb.append(timer.mName); |
| 5048 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 5049 | which, linePrefix); |
| 5050 | if (!linePrefix.equals(": ")) { |
| 5051 | sb.append(" realtime"); |
| 5052 | // Only print out wake locks that were held |
| 5053 | pw.println(sb.toString()); |
| 5054 | } |
| 5055 | } |
| 5056 | pw.println(); |
| 5057 | } |
| 5058 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5059 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5060 | if (timers.size() > 0) { |
| 5061 | Collections.sort(timers, timerComparator); |
| 5062 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 5063 | for (int i=0; i<timers.size(); i++) { |
| 5064 | TimerEntry timer = timers.get(i); |
| 5065 | sb.setLength(0); |
| 5066 | sb.append(" Wake lock "); |
| 5067 | UserHandle.formatUid(sb, timer.mId); |
| 5068 | sb.append(" "); |
| 5069 | sb.append(timer.mName); |
| 5070 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5071 | sb.append(" realtime"); |
| 5072 | pw.println(sb.toString()); |
| 5073 | } |
| 5074 | timers.clear(); |
| 5075 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5076 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5077 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5078 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5079 | if (wakeupReasons.size() > 0) { |
| 5080 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5081 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5082 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5083 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5084 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 5085 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5086 | } |
| 5087 | Collections.sort(reasons, timerComparator); |
| 5088 | for (int i=0; i<reasons.size(); i++) { |
| 5089 | TimerEntry timer = reasons.get(i); |
| 5090 | String linePrefix = ": "; |
| 5091 | sb.setLength(0); |
| 5092 | sb.append(prefix); |
| 5093 | sb.append(" Wakeup reason "); |
| 5094 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 5095 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 5096 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5097 | pw.println(sb.toString()); |
| 5098 | } |
| 5099 | pw.println(); |
| 5100 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 5101 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 5102 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5103 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5104 | if (mMemoryStats.size() > 0) { |
| 5105 | pw.println(" Memory Stats"); |
| 5106 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 5107 | sb.setLength(0); |
| 5108 | sb.append(" Bandwidth "); |
| 5109 | sb.append(mMemoryStats.keyAt(i)); |
| 5110 | sb.append(" Time "); |
| 5111 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 5112 | pw.println(sb.toString()); |
| 5113 | } |
| 5114 | pw.println(); |
| 5115 | } |
| 5116 | |
| 5117 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 5118 | if (rpmStats.size() > 0) { |
| 5119 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 5120 | if (rpmStats.size() > 0) { |
| 5121 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 5122 | final String timerName = ent.getKey(); |
| 5123 | final Timer timer = ent.getValue(); |
| 5124 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5125 | } |
| 5126 | } |
| 5127 | pw.println(); |
| 5128 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5129 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 5130 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5131 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5132 | pw.print(prefix); |
| 5133 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 5134 | if (screenOffRpmStats.size() > 0) { |
| 5135 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 5136 | final String timerName = ent.getKey(); |
| 5137 | final Timer timer = ent.getValue(); |
| 5138 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 5139 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5140 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 5141 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5142 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5145 | final long[] cpuFreqs = getCpuFreqs(); |
| 5146 | if (cpuFreqs != null) { |
| 5147 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5148 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5149 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 5150 | sb.append(" " + cpuFreqs[i]); |
| 5151 | } |
| 5152 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5153 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5154 | } |
| 5155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | for (int iu=0; iu<NU; iu++) { |
| 5157 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5158 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5159 | continue; |
| 5160 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5161 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5162 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5163 | |
| 5164 | pw.print(prefix); |
| 5165 | pw.print(" "); |
| 5166 | UserHandle.formatUid(pw, uid); |
| 5167 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5168 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5169 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5170 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5171 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5172 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5173 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5174 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5175 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5176 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5177 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5178 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5179 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5180 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5181 | |
| 5182 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5183 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5184 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5185 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5186 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5187 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5188 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5189 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5190 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5191 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5192 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5193 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5194 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5195 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5196 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5197 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5198 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5199 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5200 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5201 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5202 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5203 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5204 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5205 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5206 | sb.setLength(0); |
| 5207 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5208 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5209 | sb.append("("); |
| 5210 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5211 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5212 | long packets = mobileRxPackets + mobileTxPackets; |
| 5213 | if (packets == 0) { |
| 5214 | packets = 1; |
| 5215 | } |
| 5216 | sb.append(" @ "); |
| 5217 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5218 | sb.append(" mspp"); |
| 5219 | pw.println(sb.toString()); |
| 5220 | } |
| 5221 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5222 | if (mobileWakeup > 0) { |
| 5223 | sb.setLength(0); |
| 5224 | sb.append(prefix); |
| 5225 | sb.append(" Mobile radio AP wakeups: "); |
| 5226 | sb.append(mobileWakeup); |
| 5227 | pw.println(sb.toString()); |
| 5228 | } |
| 5229 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5230 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 5231 | u.getModemControllerActivity(), which); |
| 5232 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5233 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5234 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5235 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5236 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5237 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5238 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5239 | } |
| 5240 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5241 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5242 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5243 | || uidWifiRunningTime != 0) { |
| 5244 | sb.setLength(0); |
| 5245 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5246 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5247 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5248 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5249 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5250 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5251 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5252 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5253 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5254 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5255 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5256 | whichBatteryRealtime)); sb.append(") "); |
| 5257 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5258 | sb.append("x\n"); |
| 5259 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5260 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5261 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5262 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5263 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5264 | sb.append(") "); |
| 5265 | sb.append(wifiScanCount); |
| 5266 | sb.append("x\n"); |
| 5267 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5268 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5269 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5270 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5271 | sb.append(") "); |
| 5272 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5273 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5274 | pw.println(sb.toString()); |
| 5275 | } |
| 5276 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5277 | if (wifiWakeup > 0) { |
| 5278 | sb.setLength(0); |
| 5279 | sb.append(prefix); |
| 5280 | sb.append(" WiFi AP wakeups: "); |
| 5281 | sb.append(wifiWakeup); |
| 5282 | pw.println(sb.toString()); |
| 5283 | } |
| 5284 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5285 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 5286 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5287 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5288 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5289 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5290 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5291 | pw.print(formatBytesLocked(btTxBytes)); |
| 5292 | pw.println(" sent"); |
| 5293 | } |
| 5294 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5295 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5296 | if (bleTimer != null) { |
| 5297 | // Convert from microseconds to milliseconds with rounding |
| 5298 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5299 | / 1000; |
| 5300 | if (totalTimeMs != 0) { |
| 5301 | final int count = bleTimer.getCountLocked(which); |
| 5302 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5303 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5304 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5305 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5306 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5307 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5308 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5309 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5310 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5311 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5312 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5313 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5314 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5315 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5316 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5317 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5318 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5319 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5320 | final Timer unoptimizedScanTimerBg = |
| 5321 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5322 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5323 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5324 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5325 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5326 | |
| 5327 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5328 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5329 | sb.append(prefix); |
| 5330 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5331 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5332 | sb.append(" ("); |
| 5333 | sb.append(count); |
| 5334 | sb.append(" times)"); |
| 5335 | if (bleTimer.isRunningLocked()) { |
| 5336 | sb.append(" (currently running)"); |
| 5337 | } |
| 5338 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5339 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5340 | |
| 5341 | sb.append(prefix); |
| 5342 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5343 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5344 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5345 | sb.append(count); |
| 5346 | sb.append(" times)"); |
| 5347 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5348 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5349 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5350 | sb.append("\n"); |
| 5351 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5352 | sb.append(prefix); |
| 5353 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5354 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5355 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5356 | sb.append(countBg); |
| 5357 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5358 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5359 | sb.append(" (currently running in background)"); |
| 5360 | } |
| 5361 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5362 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5363 | |
| 5364 | sb.append(prefix); |
| 5365 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5366 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5367 | sb.append(" ("); |
| 5368 | sb.append(resultCountBg); |
| 5369 | sb.append(" in background)"); |
| 5370 | |
| 5371 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5372 | sb.append("\n"); |
| 5373 | sb.append(prefix); |
| 5374 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5375 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5376 | sb.append(" (max "); |
| 5377 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5378 | sb.append(")"); |
| 5379 | if (unoptimizedScanTimer != null |
| 5380 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5381 | sb.append(" (currently running unoptimized)"); |
| 5382 | } |
| 5383 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5384 | sb.append("\n"); |
| 5385 | sb.append(prefix); |
| 5386 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5387 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5388 | sb.append(" (max "); |
| 5389 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5390 | sb.append(")"); |
| 5391 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5392 | sb.append(" (currently running unoptimized in background)"); |
| 5393 | } |
| 5394 | } |
| 5395 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5396 | pw.println(sb.toString()); |
| 5397 | uidActivity = true; |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5402 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5403 | if (u.hasUserActivity()) { |
| 5404 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5405 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5406 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5407 | if (val != 0) { |
| 5408 | if (!hasData) { |
| 5409 | sb.setLength(0); |
| 5410 | sb.append(" User activity: "); |
| 5411 | hasData = true; |
| 5412 | } else { |
| 5413 | sb.append(", "); |
| 5414 | } |
| 5415 | sb.append(val); |
| 5416 | sb.append(" "); |
| 5417 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5418 | } |
| 5419 | } |
| 5420 | if (hasData) { |
| 5421 | pw.println(sb.toString()); |
| 5422 | } |
| 5423 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5424 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5425 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5426 | = u.getWakelockStats(); |
| 5427 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5428 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5429 | int countWakelock = 0; |
| 5430 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5431 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5432 | String linePrefix = ": "; |
| 5433 | sb.setLength(0); |
| 5434 | sb.append(prefix); |
| 5435 | sb.append(" Wake lock "); |
| 5436 | sb.append(wakelocks.keyAt(iw)); |
| 5437 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5438 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5439 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5440 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5441 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5442 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5443 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5444 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5445 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5446 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5447 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5448 | sb.append(" realtime"); |
| 5449 | pw.println(sb.toString()); |
| 5450 | uidActivity = true; |
| 5451 | countWakelock++; |
| 5452 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5453 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5454 | rawRealtime, which); |
| 5455 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5456 | rawRealtime, which); |
| 5457 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5458 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5459 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5460 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5461 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5462 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5463 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5464 | // pooled and therefore just a lower bound) |
| 5465 | long actualTotalPartialWakelock = 0; |
| 5466 | long actualBgPartialWakelock = 0; |
| 5467 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5468 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5469 | // Convert from microseconds to milliseconds with rounding |
| 5470 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5471 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5472 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5473 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5474 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5478 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5479 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5480 | sb.setLength(0); |
| 5481 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5482 | sb.append(" TOTAL wake: "); |
| 5483 | boolean needComma = false; |
| 5484 | if (totalFullWakelock != 0) { |
| 5485 | needComma = true; |
| 5486 | formatTimeMs(sb, totalFullWakelock); |
| 5487 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5488 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5489 | if (totalPartialWakelock != 0) { |
| 5490 | if (needComma) { |
| 5491 | sb.append(", "); |
| 5492 | } |
| 5493 | needComma = true; |
| 5494 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5495 | sb.append("blamed partial"); |
| 5496 | } |
| 5497 | if (actualTotalPartialWakelock != 0) { |
| 5498 | if (needComma) { |
| 5499 | sb.append(", "); |
| 5500 | } |
| 5501 | needComma = true; |
| 5502 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5503 | sb.append("actual partial"); |
| 5504 | } |
| 5505 | if (actualBgPartialWakelock != 0) { |
| 5506 | if (needComma) { |
| 5507 | sb.append(", "); |
| 5508 | } |
| 5509 | needComma = true; |
| 5510 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5511 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5512 | } |
| 5513 | if (totalWindowWakelock != 0) { |
| 5514 | if (needComma) { |
| 5515 | sb.append(", "); |
| 5516 | } |
| 5517 | needComma = true; |
| 5518 | formatTimeMs(sb, totalWindowWakelock); |
| 5519 | sb.append("window"); |
| 5520 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5521 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5522 | if (needComma) { |
| 5523 | sb.append(","); |
| 5524 | } |
| 5525 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5526 | formatTimeMs(sb, totalDrawWakelock); |
| 5527 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5528 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5529 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5530 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5534 | // Calculate multicast wakelock stats |
| 5535 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5536 | if (mcTimer != null) { |
| 5537 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5538 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5539 | |
| 5540 | if (multicastWakeLockTimeMicros > 0) { |
| 5541 | sb.setLength(0); |
| 5542 | sb.append(prefix); |
| 5543 | sb.append(" WiFi Multicast Wakelock"); |
| 5544 | sb.append(" count = "); |
| 5545 | sb.append(multicastWakeLockCount); |
| 5546 | sb.append(" time = "); |
| 5547 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5548 | pw.println(sb.toString()); |
| 5549 | } |
| 5550 | } |
| 5551 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5552 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5553 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5554 | final Timer timer = syncs.valueAt(isy); |
| 5555 | // Convert from microseconds to milliseconds with rounding |
| 5556 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5557 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5558 | final Timer bgTimer = timer.getSubTimer(); |
| 5559 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5560 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5561 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5562 | sb.setLength(0); |
| 5563 | sb.append(prefix); |
| 5564 | sb.append(" Sync "); |
| 5565 | sb.append(syncs.keyAt(isy)); |
| 5566 | sb.append(": "); |
| 5567 | if (totalTime != 0) { |
| 5568 | formatTimeMs(sb, totalTime); |
| 5569 | sb.append("realtime ("); |
| 5570 | sb.append(count); |
| 5571 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5572 | if (bgTime > 0) { |
| 5573 | sb.append(", "); |
| 5574 | formatTimeMs(sb, bgTime); |
| 5575 | sb.append("background ("); |
| 5576 | sb.append(bgCount); |
| 5577 | sb.append(" times)"); |
| 5578 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5579 | } else { |
| 5580 | sb.append("(not used)"); |
| 5581 | } |
| 5582 | pw.println(sb.toString()); |
| 5583 | uidActivity = true; |
| 5584 | } |
| 5585 | |
| 5586 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5587 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5588 | final Timer timer = jobs.valueAt(ij); |
| 5589 | // Convert from microseconds to milliseconds with rounding |
| 5590 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5591 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5592 | final Timer bgTimer = timer.getSubTimer(); |
| 5593 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5594 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5595 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5596 | sb.setLength(0); |
| 5597 | sb.append(prefix); |
| 5598 | sb.append(" Job "); |
| 5599 | sb.append(jobs.keyAt(ij)); |
| 5600 | sb.append(": "); |
| 5601 | if (totalTime != 0) { |
| 5602 | formatTimeMs(sb, totalTime); |
| 5603 | sb.append("realtime ("); |
| 5604 | sb.append(count); |
| 5605 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5606 | if (bgTime > 0) { |
| 5607 | sb.append(", "); |
| 5608 | formatTimeMs(sb, bgTime); |
| 5609 | sb.append("background ("); |
| 5610 | sb.append(bgCount); |
| 5611 | sb.append(" times)"); |
| 5612 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5613 | } else { |
| 5614 | sb.append("(not used)"); |
| 5615 | } |
| 5616 | pw.println(sb.toString()); |
| 5617 | uidActivity = true; |
| 5618 | } |
| 5619 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5620 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5621 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5622 | SparseIntArray types = completions.valueAt(ic); |
| 5623 | if (types != null) { |
| 5624 | pw.print(prefix); |
| 5625 | pw.print(" Job Completions "); |
| 5626 | pw.print(completions.keyAt(ic)); |
| 5627 | pw.print(":"); |
| 5628 | for (int it=0; it<types.size(); it++) { |
| 5629 | pw.print(" "); |
| 5630 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5631 | pw.print("("); |
| 5632 | pw.print(types.valueAt(it)); |
| 5633 | pw.print("x)"); |
| 5634 | } |
| 5635 | pw.println(); |
| 5636 | } |
| 5637 | } |
| 5638 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5639 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5640 | prefix, "Flashlight"); |
| 5641 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5642 | prefix, "Camera"); |
| 5643 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5644 | prefix, "Video"); |
| 5645 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5646 | prefix, "Audio"); |
| 5647 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5648 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5649 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5650 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5651 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5652 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5653 | sb.setLength(0); |
| 5654 | sb.append(prefix); |
| 5655 | sb.append(" Sensor "); |
| 5656 | int handle = se.getHandle(); |
| 5657 | if (handle == Uid.Sensor.GPS) { |
| 5658 | sb.append("GPS"); |
| 5659 | } else { |
| 5660 | sb.append(handle); |
| 5661 | } |
| 5662 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5663 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5664 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5665 | if (timer != null) { |
| 5666 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5667 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5668 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5669 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5670 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5671 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5672 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5673 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5674 | final long bgActualTime = bgTimer != null ? |
| 5675 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5676 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5677 | //timer.logState(); |
| 5678 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5679 | if (actualTime != totalTime) { |
| 5680 | formatTimeMs(sb, totalTime); |
| 5681 | sb.append("blamed realtime, "); |
| 5682 | } |
| 5683 | |
| 5684 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5685 | sb.append("realtime ("); |
| 5686 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5687 | sb.append(" times)"); |
| 5688 | |
| 5689 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5690 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5691 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5692 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5693 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5694 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5696 | } else { |
| 5697 | sb.append("(not used)"); |
| 5698 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5699 | } else { |
| 5700 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5701 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5702 | |
| 5703 | pw.println(sb.toString()); |
| 5704 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5705 | } |
| 5706 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5707 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5708 | "Vibrator"); |
| 5709 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5710 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5711 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5712 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5713 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5714 | long totalStateTime = 0; |
| 5715 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5716 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5717 | if (time > 0) { |
| 5718 | totalStateTime += time; |
| 5719 | sb.setLength(0); |
| 5720 | sb.append(prefix); |
| 5721 | sb.append(" "); |
| 5722 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5723 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5724 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5725 | pw.println(sb.toString()); |
| 5726 | uidActivity = true; |
| 5727 | } |
| 5728 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5729 | if (totalStateTime > 0) { |
| 5730 | sb.setLength(0); |
| 5731 | sb.append(prefix); |
| 5732 | sb.append(" Total running: "); |
| 5733 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5734 | pw.println(sb.toString()); |
| 5735 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5736 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5737 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5738 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5739 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5740 | sb.setLength(0); |
| 5741 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5742 | sb.append(" Total cpu time: u="); |
| 5743 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5744 | sb.append("s="); |
| 5745 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5746 | pw.println(sb.toString()); |
| 5747 | } |
| 5748 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5749 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5750 | if (cpuFreqTimes != null) { |
| 5751 | sb.setLength(0); |
| 5752 | sb.append(" Total cpu time per freq:"); |
| 5753 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5754 | sb.append(" " + cpuFreqTimes[i]); |
| 5755 | } |
| 5756 | pw.println(sb.toString()); |
| 5757 | } |
| 5758 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5759 | if (screenOffCpuFreqTimes != null) { |
| 5760 | sb.setLength(0); |
| 5761 | sb.append(" Total screen-off cpu time per freq:"); |
| 5762 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5763 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5764 | } |
| 5765 | pw.println(sb.toString()); |
| 5766 | } |
| 5767 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 5768 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 5769 | final long[] cpuTimes = u.getCpuFreqTimes(which, procState); |
| 5770 | if (cpuTimes != null) { |
| 5771 | sb.setLength(0); |
| 5772 | sb.append(" Cpu times per freq at state " |
| 5773 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5774 | for (int i = 0; i < cpuTimes.length; ++i) { |
| 5775 | sb.append(" " + cpuTimes[i]); |
| 5776 | } |
| 5777 | pw.println(sb.toString()); |
| 5778 | } |
| 5779 | |
| 5780 | final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState); |
| 5781 | if (screenOffCpuTimes != null) { |
| 5782 | sb.setLength(0); |
| 5783 | sb.append(" Screen-off cpu times per freq at state " |
| 5784 | + Uid.PROCESS_STATE_NAMES[procState] + ":"); |
| 5785 | for (int i = 0; i < screenOffCpuTimes.length; ++i) { |
| 5786 | sb.append(" " + screenOffCpuTimes[i]); |
| 5787 | } |
| 5788 | pw.println(sb.toString()); |
| 5789 | } |
| 5790 | } |
| 5791 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5792 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5793 | = u.getProcessStats(); |
| 5794 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5795 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5796 | long userTime; |
| 5797 | long systemTime; |
| 5798 | long foregroundTime; |
| 5799 | int starts; |
| 5800 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5802 | userTime = ps.getUserTime(which); |
| 5803 | systemTime = ps.getSystemTime(which); |
| 5804 | foregroundTime = ps.getForegroundTime(which); |
| 5805 | starts = ps.getStarts(which); |
| 5806 | final int numCrashes = ps.getNumCrashes(which); |
| 5807 | final int numAnrs = ps.getNumAnrs(which); |
| 5808 | numExcessive = which == STATS_SINCE_CHARGED |
| 5809 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5811 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5812 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5813 | sb.setLength(0); |
| 5814 | sb.append(prefix); sb.append(" Proc "); |
| 5815 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5816 | sb.append(prefix); sb.append(" CPU: "); |
| 5817 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5818 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5819 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5820 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5821 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5822 | boolean hasOne = false; |
| 5823 | if (starts != 0) { |
| 5824 | hasOne = true; |
| 5825 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5826 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5827 | if (numCrashes != 0) { |
| 5828 | if (hasOne) { |
| 5829 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5830 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5831 | hasOne = true; |
| 5832 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5833 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5834 | if (numAnrs != 0) { |
| 5835 | if (hasOne) { |
| 5836 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5838 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | } |
| 5840 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5841 | pw.println(sb.toString()); |
| 5842 | for (int e=0; e<numExcessive; e++) { |
| 5843 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5844 | if (ew != null) { |
| 5845 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5846 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5847 | pw.print("cpu"); |
| 5848 | } else { |
| 5849 | pw.print("unknown"); |
| 5850 | } |
| 5851 | pw.print(" use: "); |
| 5852 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5853 | pw.print(" over "); |
| 5854 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5855 | if (ew.overTime != 0) { |
| 5856 | pw.print(" ("); |
| 5857 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5858 | pw.println("%)"); |
| 5859 | } |
| 5860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | } |
| 5862 | uidActivity = true; |
| 5863 | } |
| 5864 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5865 | |
| 5866 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5867 | = u.getPackageStats(); |
| 5868 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5869 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5870 | pw.println(":"); |
| 5871 | boolean apkActivity = false; |
| 5872 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5873 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5874 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5875 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5876 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5877 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5878 | pw.println(" times"); |
| 5879 | apkActivity = true; |
| 5880 | } |
| 5881 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5882 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5883 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5884 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5885 | final int starts = ss.getStarts(which); |
| 5886 | final int launches = ss.getLaunches(which); |
| 5887 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5888 | sb.setLength(0); |
| 5889 | sb.append(prefix); sb.append(" Service "); |
| 5890 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5891 | sb.append(prefix); sb.append(" Created for: "); |
| 5892 | formatTimeMs(sb, startTime / 1000); |
| 5893 | sb.append("uptime\n"); |
| 5894 | sb.append(prefix); sb.append(" Starts: "); |
| 5895 | sb.append(starts); |
| 5896 | sb.append(", launches: "); sb.append(launches); |
| 5897 | pw.println(sb.toString()); |
| 5898 | apkActivity = true; |
| 5899 | } |
| 5900 | } |
| 5901 | if (!apkActivity) { |
| 5902 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5903 | } |
| 5904 | uidActivity = true; |
| 5905 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5906 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5907 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | } |
| 5911 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5912 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5913 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5914 | int diff = oldval ^ newval; |
| 5915 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5916 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5917 | for (int i=0; i<descriptions.length; i++) { |
| 5918 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5919 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5920 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5921 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5922 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5923 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5924 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5925 | didWake = true; |
| 5926 | pw.print("="); |
| 5927 | if (longNames) { |
| 5928 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5929 | pw.print(":\""); |
| 5930 | pw.print(wakelockTag.string); |
| 5931 | pw.print("\""); |
| 5932 | } else { |
| 5933 | pw.print(wakelockTag.poolIdx); |
| 5934 | } |
| 5935 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5936 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5937 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5938 | pw.print("="); |
| 5939 | int val = (newval&bd.mask)>>bd.shift; |
| 5940 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5941 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5942 | } else { |
| 5943 | pw.print(val); |
| 5944 | } |
| 5945 | } |
| 5946 | } |
| 5947 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5948 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5949 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5950 | if (longNames) { |
| 5951 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5952 | pw.print(":\""); |
| 5953 | pw.print(wakelockTag.string); |
| 5954 | pw.print("\""); |
| 5955 | } else { |
| 5956 | pw.print(wakelockTag.poolIdx); |
| 5957 | } |
| 5958 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5959 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5960 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5961 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 5962 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | public static class HistoryPrinter { |
| 5966 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5967 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5968 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5969 | int oldStatus = -1; |
| 5970 | int oldHealth = -1; |
| 5971 | int oldPlug = -1; |
| 5972 | int oldTemp = -1; |
| 5973 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5974 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5975 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5976 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5977 | void reset() { |
| 5978 | oldState = oldState2 = 0; |
| 5979 | oldLevel = -1; |
| 5980 | oldStatus = -1; |
| 5981 | oldHealth = -1; |
| 5982 | oldPlug = -1; |
| 5983 | oldTemp = -1; |
| 5984 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5985 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5986 | } |
| 5987 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5988 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5989 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5990 | if (!checkin) { |
| 5991 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5992 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5993 | pw.print(" ("); |
| 5994 | pw.print(rec.numReadInts); |
| 5995 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5996 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5997 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5998 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5999 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6000 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6001 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6002 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6003 | } |
| 6004 | lastTime = rec.time; |
| 6005 | } |
| 6006 | if (rec.cmd == HistoryItem.CMD_START) { |
| 6007 | if (checkin) { |
| 6008 | pw.print(":"); |
| 6009 | } |
| 6010 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6011 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6012 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 6013 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6014 | if (checkin) { |
| 6015 | pw.print(":"); |
| 6016 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6017 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 6018 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6019 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6020 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6021 | pw.print("TIME:"); |
| 6022 | if (checkin) { |
| 6023 | pw.println(rec.currentTime); |
| 6024 | } else { |
| 6025 | pw.print(" "); |
| 6026 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6027 | rec.currentTime).toString()); |
| 6028 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6029 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 6030 | if (checkin) { |
| 6031 | pw.print(":"); |
| 6032 | } |
| 6033 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6034 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 6035 | if (checkin) { |
| 6036 | pw.print(":"); |
| 6037 | } |
| 6038 | pw.println("*OVERFLOW*"); |
| 6039 | } else { |
| 6040 | if (!checkin) { |
| 6041 | if (rec.batteryLevel < 10) pw.print("00"); |
| 6042 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 6043 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6044 | if (verbose) { |
| 6045 | pw.print(" "); |
| 6046 | if (rec.states < 0) ; |
| 6047 | else if (rec.states < 0x10) pw.print("0000000"); |
| 6048 | else if (rec.states < 0x100) pw.print("000000"); |
| 6049 | else if (rec.states < 0x1000) pw.print("00000"); |
| 6050 | else if (rec.states < 0x10000) pw.print("0000"); |
| 6051 | else if (rec.states < 0x100000) pw.print("000"); |
| 6052 | else if (rec.states < 0x1000000) pw.print("00"); |
| 6053 | else if (rec.states < 0x10000000) pw.print("0"); |
| 6054 | pw.print(Integer.toHexString(rec.states)); |
| 6055 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6056 | } else { |
| 6057 | if (oldLevel != rec.batteryLevel) { |
| 6058 | oldLevel = rec.batteryLevel; |
| 6059 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 6060 | } |
| 6061 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6062 | if (oldStatus != rec.batteryStatus) { |
| 6063 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6064 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6065 | switch (oldStatus) { |
| 6066 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6067 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6068 | break; |
| 6069 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6070 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6071 | break; |
| 6072 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6073 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6074 | break; |
| 6075 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6076 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6077 | break; |
| 6078 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6079 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6080 | break; |
| 6081 | default: |
| 6082 | pw.print(oldStatus); |
| 6083 | break; |
| 6084 | } |
| 6085 | } |
| 6086 | if (oldHealth != rec.batteryHealth) { |
| 6087 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6088 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6089 | switch (oldHealth) { |
| 6090 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6091 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6092 | break; |
| 6093 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6094 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6095 | break; |
| 6096 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6097 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6098 | break; |
| 6099 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6100 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6101 | break; |
| 6102 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6103 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6104 | break; |
| 6105 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6106 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6107 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6108 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 6109 | pw.print(checkin ? "c" : "cold"); |
| 6110 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6111 | default: |
| 6112 | pw.print(oldHealth); |
| 6113 | break; |
| 6114 | } |
| 6115 | } |
| 6116 | if (oldPlug != rec.batteryPlugType) { |
| 6117 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6118 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6119 | switch (oldPlug) { |
| 6120 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6121 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6122 | break; |
| 6123 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6124 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6125 | break; |
| 6126 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6127 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6128 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6129 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6130 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 6131 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6132 | default: |
| 6133 | pw.print(oldPlug); |
| 6134 | break; |
| 6135 | } |
| 6136 | } |
| 6137 | if (oldTemp != rec.batteryTemperature) { |
| 6138 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6139 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6140 | pw.print(oldTemp); |
| 6141 | } |
| 6142 | if (oldVolt != rec.batteryVoltage) { |
| 6143 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6144 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6145 | pw.print(oldVolt); |
| 6146 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6147 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 6148 | if (oldChargeMAh != chargeMAh) { |
| 6149 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6150 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 6151 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 6152 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6153 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6154 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6155 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 6156 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6157 | if (rec.wakeReasonTag != null) { |
| 6158 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6159 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6160 | pw.print(rec.wakeReasonTag.poolIdx); |
| 6161 | } else { |
| 6162 | pw.print(" wake_reason="); |
| 6163 | pw.print(rec.wakeReasonTag.uid); |
| 6164 | pw.print(":\""); |
| 6165 | pw.print(rec.wakeReasonTag.string); |
| 6166 | pw.print("\""); |
| 6167 | } |
| 6168 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6169 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6170 | pw.print(checkin ? "," : " "); |
| 6171 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 6172 | pw.print("+"); |
| 6173 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 6174 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6175 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6176 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6177 | : HISTORY_EVENT_NAMES; |
| 6178 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6179 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6180 | if (idx >= 0 && idx < eventNames.length) { |
| 6181 | pw.print(eventNames[idx]); |
| 6182 | } else { |
| 6183 | pw.print(checkin ? "Ev" : "event"); |
| 6184 | pw.print(idx); |
| 6185 | } |
| 6186 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6187 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6188 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6189 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6190 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6191 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6192 | pw.print(":\""); |
| 6193 | pw.print(rec.eventTag.string); |
| 6194 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6195 | } |
| 6196 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6197 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6198 | if (rec.stepDetails != null) { |
| 6199 | if (!checkin) { |
| 6200 | pw.print(" Details: cpu="); |
| 6201 | pw.print(rec.stepDetails.userTime); |
| 6202 | pw.print("u+"); |
| 6203 | pw.print(rec.stepDetails.systemTime); |
| 6204 | pw.print("s"); |
| 6205 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6206 | pw.print(" ("); |
| 6207 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6208 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6209 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6210 | pw.print(", "); |
| 6211 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6212 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6213 | } |
| 6214 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6215 | pw.print(", "); |
| 6216 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6217 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6218 | } |
| 6219 | pw.print(')'); |
| 6220 | } |
| 6221 | pw.println(); |
| 6222 | pw.print(" /proc/stat="); |
| 6223 | pw.print(rec.stepDetails.statUserTime); |
| 6224 | pw.print(" usr, "); |
| 6225 | pw.print(rec.stepDetails.statSystemTime); |
| 6226 | pw.print(" sys, "); |
| 6227 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6228 | pw.print(" io, "); |
| 6229 | pw.print(rec.stepDetails.statIrqTime); |
| 6230 | pw.print(" irq, "); |
| 6231 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6232 | pw.print(" sirq, "); |
| 6233 | pw.print(rec.stepDetails.statIdlTime); |
| 6234 | pw.print(" idle"); |
| 6235 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6236 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6237 | + rec.stepDetails.statSoftIrqTime; |
| 6238 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6239 | if (total > 0) { |
| 6240 | pw.print(" ("); |
| 6241 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6242 | pw.print(String.format("%.1f%%", perc)); |
| 6243 | pw.print(" of "); |
| 6244 | StringBuilder sb = new StringBuilder(64); |
| 6245 | formatTimeMsNoSpace(sb, total*10); |
| 6246 | pw.print(sb); |
| 6247 | pw.print(")"); |
| 6248 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6249 | pw.print(", PlatformIdleStat "); |
| 6250 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6251 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6252 | |
| 6253 | pw.print(", SubsystemPowerState "); |
| 6254 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6255 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6256 | } else { |
| 6257 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6258 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6259 | pw.print(rec.stepDetails.userTime); |
| 6260 | pw.print(":"); |
| 6261 | pw.print(rec.stepDetails.systemTime); |
| 6262 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6263 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6264 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6265 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6266 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6267 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6268 | } |
| 6269 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6270 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6271 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6272 | } |
| 6273 | } |
| 6274 | pw.println(); |
| 6275 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6276 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6277 | pw.print(rec.stepDetails.statUserTime); |
| 6278 | pw.print(','); |
| 6279 | pw.print(rec.stepDetails.statSystemTime); |
| 6280 | pw.print(','); |
| 6281 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6282 | pw.print(','); |
| 6283 | pw.print(rec.stepDetails.statIrqTime); |
| 6284 | pw.print(','); |
| 6285 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6286 | pw.print(','); |
| 6287 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6288 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6289 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6290 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6291 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6292 | pw.print(','); |
| 6293 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6294 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6295 | |
| 6296 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6297 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6298 | } |
| 6299 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6300 | } |
| 6301 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6302 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6303 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6304 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6305 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6306 | |
| 6307 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6308 | UserHandle.formatUid(pw, uid); |
| 6309 | pw.print("="); |
| 6310 | pw.print(utime); |
| 6311 | pw.print("u+"); |
| 6312 | pw.print(stime); |
| 6313 | pw.print("s"); |
| 6314 | } |
| 6315 | |
| 6316 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6317 | pw.print('/'); |
| 6318 | pw.print(uid); |
| 6319 | pw.print(":"); |
| 6320 | pw.print(utime); |
| 6321 | pw.print(":"); |
| 6322 | pw.print(stime); |
| 6323 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6324 | } |
| 6325 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6326 | private void printSizeValue(PrintWriter pw, long size) { |
| 6327 | float result = size; |
| 6328 | String suffix = ""; |
| 6329 | if (result >= 10*1024) { |
| 6330 | suffix = "KB"; |
| 6331 | result = result / 1024; |
| 6332 | } |
| 6333 | if (result >= 10*1024) { |
| 6334 | suffix = "MB"; |
| 6335 | result = result / 1024; |
| 6336 | } |
| 6337 | if (result >= 10*1024) { |
| 6338 | suffix = "GB"; |
| 6339 | result = result / 1024; |
| 6340 | } |
| 6341 | if (result >= 10*1024) { |
| 6342 | suffix = "TB"; |
| 6343 | result = result / 1024; |
| 6344 | } |
| 6345 | if (result >= 10*1024) { |
| 6346 | suffix = "PB"; |
| 6347 | result = result / 1024; |
| 6348 | } |
| 6349 | pw.print((int)result); |
| 6350 | pw.print(suffix); |
| 6351 | } |
| 6352 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6353 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6354 | String label3, long estimatedTime) { |
| 6355 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6356 | return false; |
| 6357 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6358 | pw.print(label1); |
| 6359 | pw.print(label2); |
| 6360 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6361 | StringBuilder sb = new StringBuilder(64); |
| 6362 | formatTimeMs(sb, estimatedTime); |
| 6363 | pw.print(sb); |
| 6364 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6365 | return true; |
| 6366 | } |
| 6367 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6368 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6369 | LevelStepTracker steps, boolean checkin) { |
| 6370 | if (steps == null) { |
| 6371 | return false; |
| 6372 | } |
| 6373 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6374 | if (count <= 0) { |
| 6375 | return false; |
| 6376 | } |
| 6377 | if (!checkin) { |
| 6378 | pw.println(header); |
| 6379 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6380 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6381 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6382 | long duration = steps.getDurationAt(i); |
| 6383 | int level = steps.getLevelAt(i); |
| 6384 | long initMode = steps.getInitModeAt(i); |
| 6385 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6386 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6387 | lineArgs[0] = Long.toString(duration); |
| 6388 | lineArgs[1] = Integer.toString(level); |
| 6389 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6390 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6391 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6392 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6393 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6394 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6395 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6396 | } |
| 6397 | } else { |
| 6398 | lineArgs[2] = ""; |
| 6399 | } |
| 6400 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6401 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6402 | } else { |
| 6403 | lineArgs[3] = ""; |
| 6404 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6405 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6406 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6407 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6408 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6409 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6410 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6411 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6412 | pw.print(prefix); |
| 6413 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6414 | TimeUtils.formatDuration(duration, pw); |
| 6415 | pw.print(" to "); pw.print(level); |
| 6416 | boolean haveModes = false; |
| 6417 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6418 | pw.print(" ("); |
| 6419 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6420 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6421 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6422 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6423 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6424 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6425 | } |
| 6426 | haveModes = true; |
| 6427 | } |
| 6428 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6429 | pw.print(haveModes ? ", " : " ("); |
| 6430 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6431 | ? "power-save-on" : "power-save-off"); |
| 6432 | haveModes = true; |
| 6433 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6434 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6435 | pw.print(haveModes ? ", " : " ("); |
| 6436 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6437 | ? "device-idle-on" : "device-idle-off"); |
| 6438 | haveModes = true; |
| 6439 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6440 | if (haveModes) { |
| 6441 | pw.print(")"); |
| 6442 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6443 | pw.println(); |
| 6444 | } |
| 6445 | } |
| 6446 | return true; |
| 6447 | } |
| 6448 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6449 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6450 | LevelStepTracker steps) { |
| 6451 | if (steps == null) { |
| 6452 | return; |
| 6453 | } |
| 6454 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6455 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6456 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6457 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6458 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6459 | |
| 6460 | final long initMode = steps.getInitModeAt(i); |
| 6461 | final long modMode = steps.getModModeAt(i); |
| 6462 | |
| 6463 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6464 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6465 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6466 | case Display.STATE_OFF: |
| 6467 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6468 | break; |
| 6469 | case Display.STATE_ON: |
| 6470 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6471 | break; |
| 6472 | case Display.STATE_DOZE: |
| 6473 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6474 | break; |
| 6475 | case Display.STATE_DOZE_SUSPEND: |
| 6476 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6477 | break; |
| 6478 | default: |
| 6479 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6480 | break; |
| 6481 | } |
| 6482 | } |
| 6483 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6484 | |
| 6485 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6486 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6487 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6488 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6489 | } |
| 6490 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6491 | |
| 6492 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6493 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6494 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6495 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6496 | } |
| 6497 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6498 | |
| 6499 | proto.end(token); |
| 6500 | } |
| 6501 | } |
| 6502 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6503 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6504 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6505 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6506 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6507 | public static final int DUMP_VERBOSE = 1<<5; |
| 6508 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6509 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6510 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6511 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6512 | final HistoryItem rec = new HistoryItem(); |
| 6513 | long lastTime = -1; |
| 6514 | long baseTime = -1; |
| 6515 | boolean printed = false; |
| 6516 | HistoryEventTracker tracker = null; |
| 6517 | while (getNextHistoryLocked(rec)) { |
| 6518 | lastTime = rec.time; |
| 6519 | if (baseTime < 0) { |
| 6520 | baseTime = lastTime; |
| 6521 | } |
| 6522 | if (rec.time >= histStart) { |
| 6523 | if (histStart >= 0 && !printed) { |
| 6524 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6525 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6526 | || rec.cmd == HistoryItem.CMD_START |
| 6527 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6528 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6529 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6530 | (flags&DUMP_VERBOSE) != 0); |
| 6531 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6532 | } else if (rec.currentTime != 0) { |
| 6533 | printed = true; |
| 6534 | byte cmd = rec.cmd; |
| 6535 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6536 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6537 | (flags&DUMP_VERBOSE) != 0); |
| 6538 | rec.cmd = cmd; |
| 6539 | } |
| 6540 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6541 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6542 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6543 | (flags&DUMP_VERBOSE) != 0); |
| 6544 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6545 | } |
| 6546 | int oldEventCode = rec.eventCode; |
| 6547 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6548 | rec.eventTag = new HistoryTag(); |
| 6549 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6550 | HashMap<String, SparseIntArray> active |
| 6551 | = tracker.getStateForEvent(i); |
| 6552 | if (active == null) { |
| 6553 | continue; |
| 6554 | } |
| 6555 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6556 | : active.entrySet()) { |
| 6557 | SparseIntArray uids = ent.getValue(); |
| 6558 | for (int j=0; j<uids.size(); j++) { |
| 6559 | rec.eventCode = i; |
| 6560 | rec.eventTag.string = ent.getKey(); |
| 6561 | rec.eventTag.uid = uids.keyAt(j); |
| 6562 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6563 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6564 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6565 | rec.wakeReasonTag = null; |
| 6566 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6567 | } |
| 6568 | } |
| 6569 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6570 | rec.eventCode = oldEventCode; |
| 6571 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6572 | tracker = null; |
| 6573 | } |
| 6574 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6575 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6576 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6577 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6578 | // This is an attempt to aggregate the previous state and generate |
| 6579 | //Â fake events to reflect that state at the point where we start |
| 6580 | // 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] | 6581 | if (tracker == null) { |
| 6582 | tracker = new HistoryEventTracker(); |
| 6583 | } |
| 6584 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6585 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6586 | } |
| 6587 | } |
| 6588 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6589 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6590 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6591 | } |
| 6592 | } |
| 6593 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6594 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6595 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6596 | if (steps == null) { |
| 6597 | return; |
| 6598 | } |
| 6599 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6600 | if (timeRemaining >= 0) { |
| 6601 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6602 | tmpSb.setLength(0); |
| 6603 | formatTimeMs(tmpSb, timeRemaining); |
| 6604 | pw.print(tmpSb); |
| 6605 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6606 | pw.println(" steps)"); |
| 6607 | } |
| 6608 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6609 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6610 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6611 | if (estimatedTime > 0) { |
| 6612 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6613 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6614 | pw.print(" time: "); |
| 6615 | tmpSb.setLength(0); |
| 6616 | formatTimeMs(tmpSb, estimatedTime); |
| 6617 | pw.print(tmpSb); |
| 6618 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6619 | pw.println(" steps)"); |
| 6620 | } |
| 6621 | } |
| 6622 | } |
| 6623 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6624 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6625 | ArrayList<PackageChange> changes) { |
| 6626 | if (changes == null) { |
| 6627 | return; |
| 6628 | } |
| 6629 | pw.print(prefix); pw.println("Package changes:"); |
| 6630 | for (int i=0; i<changes.size(); i++) { |
| 6631 | PackageChange pc = changes.get(i); |
| 6632 | if (pc.mUpdate) { |
| 6633 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6634 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6635 | } else { |
| 6636 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6637 | } |
| 6638 | } |
| 6639 | } |
| 6640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | /** |
| 6642 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6643 | * |
| 6644 | * @param pw a Printer to receive the dump output. |
| 6645 | */ |
| 6646 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6647 | 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] | 6648 | prepareForDumpLocked(); |
| 6649 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6650 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6651 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6652 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6653 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6654 | final long historyTotalSize = getHistoryTotalSize(); |
| 6655 | final long historyUsedSize = getHistoryUsedSize(); |
| 6656 | if (startIteratingHistoryLocked()) { |
| 6657 | try { |
| 6658 | pw.print("Battery History ("); |
| 6659 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6660 | pw.print("% used, "); |
| 6661 | printSizeValue(pw, historyUsedSize); |
| 6662 | pw.print(" used of "); |
| 6663 | printSizeValue(pw, historyTotalSize); |
| 6664 | pw.print(", "); |
| 6665 | pw.print(getHistoryStringPoolSize()); |
| 6666 | pw.print(" strings using "); |
| 6667 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6668 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6669 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6670 | pw.println(); |
| 6671 | } finally { |
| 6672 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6673 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | if (startIteratingOldHistoryLocked()) { |
| 6677 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6678 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6679 | pw.println("Old battery History:"); |
| 6680 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6681 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6682 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6683 | if (baseTime < 0) { |
| 6684 | baseTime = rec.time; |
| 6685 | } |
| 6686 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6687 | } |
| 6688 | pw.println(); |
| 6689 | } finally { |
| 6690 | finishIteratingOldHistoryLocked(); |
| 6691 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6692 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6695 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6696 | return; |
| 6697 | } |
| 6698 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6699 | if (!filtering) { |
| 6700 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6701 | final int NU = uidStats.size(); |
| 6702 | boolean didPid = false; |
| 6703 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6704 | for (int i=0; i<NU; i++) { |
| 6705 | Uid uid = uidStats.valueAt(i); |
| 6706 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6707 | if (pids != null) { |
| 6708 | for (int j=0; j<pids.size(); j++) { |
| 6709 | Uid.Pid pid = pids.valueAt(j); |
| 6710 | if (!didPid) { |
| 6711 | pw.println("Per-PID Stats:"); |
| 6712 | didPid = true; |
| 6713 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6714 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6715 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6716 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6717 | pw.print(" wake time: "); |
| 6718 | TimeUtils.formatDuration(time, pw); |
| 6719 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6720 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6721 | } |
| 6722 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6723 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6724 | pw.println(); |
| 6725 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6729 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6730 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6731 | long timeRemaining = computeBatteryTimeRemaining( |
| 6732 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6733 | if (timeRemaining >= 0) { |
| 6734 | pw.print(" Estimated discharge time remaining: "); |
| 6735 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6736 | pw.println(); |
| 6737 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6738 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6739 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6740 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6741 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6742 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6743 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6744 | pw.println(); |
| 6745 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6746 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6747 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6748 | long timeRemaining = computeChargeTimeRemaining( |
| 6749 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6750 | if (timeRemaining >= 0) { |
| 6751 | pw.print(" Estimated charge time remaining: "); |
| 6752 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6753 | pw.println(); |
| 6754 | } |
| 6755 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6756 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6757 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6758 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6759 | pw.println("Daily stats:"); |
| 6760 | pw.print(" Current start time: "); |
| 6761 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6762 | getCurrentDailyStartTime()).toString()); |
| 6763 | pw.print(" Next min deadline: "); |
| 6764 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6765 | getNextMinDailyDeadline()).toString()); |
| 6766 | pw.print(" Next max deadline: "); |
| 6767 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6768 | getNextMaxDailyDeadline()).toString()); |
| 6769 | StringBuilder sb = new StringBuilder(64); |
| 6770 | int[] outInt = new int[1]; |
| 6771 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6772 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6773 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6774 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6775 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6776 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6777 | dsteps, false)) { |
| 6778 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6779 | sb, outInt); |
| 6780 | } |
| 6781 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6782 | csteps, false)) { |
| 6783 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6784 | sb, outInt); |
| 6785 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6786 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6787 | } else { |
| 6788 | pw.println(" Current daily steps:"); |
| 6789 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6790 | sb, outInt); |
| 6791 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6792 | sb, outInt); |
| 6793 | } |
| 6794 | } |
| 6795 | DailyItem dit; |
| 6796 | int curIndex = 0; |
| 6797 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6798 | curIndex++; |
| 6799 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6800 | pw.println(); |
| 6801 | } |
| 6802 | pw.print(" Daily from "); |
| 6803 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6804 | pw.print(" to "); |
| 6805 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6806 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6807 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6808 | if (dumpDurationSteps(pw, " ", |
| 6809 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6810 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6811 | sb, outInt); |
| 6812 | } |
| 6813 | if (dumpDurationSteps(pw, " ", |
| 6814 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6815 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6816 | sb, outInt); |
| 6817 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6818 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6819 | } else { |
| 6820 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6821 | sb, outInt); |
| 6822 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6823 | sb, outInt); |
| 6824 | } |
| 6825 | } |
| 6826 | pw.println(); |
| 6827 | } |
| 6828 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6829 | pw.println("Statistics since last charge:"); |
| 6830 | pw.println(" System starts: " + getStartCount() |
| 6831 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6832 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6833 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6834 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6837 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6838 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6840 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6841 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6842 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6843 | |
| 6844 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6845 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6846 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6847 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6848 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6849 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6850 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6851 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6852 | try { |
| 6853 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6854 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6855 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6856 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6857 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6858 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6859 | pw.print(",\""); |
| 6860 | String str = getHistoryTagPoolString(i); |
| 6861 | str = str.replace("\\", "\\\\"); |
| 6862 | str = str.replace("\"", "\\\""); |
| 6863 | pw.print(str); |
| 6864 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6865 | pw.println(); |
| 6866 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6867 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6868 | } finally { |
| 6869 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6870 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6871 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6872 | } |
| 6873 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6874 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6875 | return; |
| 6876 | } |
| 6877 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6878 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6879 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6880 | for (int i=0; i<apps.size(); i++) { |
| 6881 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6882 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6883 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6884 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6885 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6886 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6887 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6888 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6889 | } |
| 6890 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6891 | final int NU = uidStats.size(); |
| 6892 | String[] lineArgs = new String[2]; |
| 6893 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6894 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6895 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6896 | if (pkgs != null && !pkgs.second.value) { |
| 6897 | pkgs.second.value = true; |
| 6898 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6899 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6900 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6901 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6902 | (Object[])lineArgs); |
| 6903 | } |
| 6904 | } |
| 6905 | } |
| 6906 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6907 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6908 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6909 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6910 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6911 | if (timeRemaining >= 0) { |
| 6912 | lineArgs[0] = Long.toString(timeRemaining); |
| 6913 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6914 | (Object[])lineArgs); |
| 6915 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6916 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6917 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6918 | if (timeRemaining >= 0) { |
| 6919 | lineArgs[0] = Long.toString(timeRemaining); |
| 6920 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6921 | (Object[])lineArgs); |
| 6922 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6923 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6924 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6927 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6928 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6929 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6930 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6931 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6932 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6933 | prepareForDumpLocked(); |
| 6934 | |
| 6935 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6936 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6937 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6938 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6939 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6940 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6941 | |
| 6942 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6943 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 6944 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 6945 | helper.create(this); |
| 6946 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 6947 | |
| 6948 | dumpProtoAppsLocked(proto, helper, apps); |
| 6949 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | proto.end(bToken); |
| 6953 | proto.flush(); |
| 6954 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6955 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6956 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 6957 | List<ApplicationInfo> apps) { |
| 6958 | final int which = STATS_SINCE_CHARGED; |
| 6959 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 6960 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 6961 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 6962 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 6963 | |
| 6964 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 6965 | if (apps != null) { |
| 6966 | for (int i = 0; i < apps.size(); ++i) { |
| 6967 | ApplicationInfo ai = apps.get(i); |
| 6968 | int aid = UserHandle.getAppId(ai.uid); |
| 6969 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 6970 | if (pkgs == null) { |
| 6971 | pkgs = new ArrayList<String>(); |
| 6972 | aidToPackages.put(aid, pkgs); |
| 6973 | } |
| 6974 | pkgs.add(ai.packageName); |
| 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 6979 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 6980 | if (sippers != null) { |
| 6981 | for (int i = 0; i < sippers.size(); ++i) { |
| 6982 | final BatterySipper bs = sippers.get(i); |
| 6983 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 6984 | // Others are handled by dumpProtoSystemLocked() |
| 6985 | continue; |
| 6986 | } |
| 6987 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6992 | final int n = uidStats.size(); |
| 6993 | for (int iu = 0; iu < n; ++iu) { |
| 6994 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 6995 | final Uid u = uidStats.valueAt(iu); |
| 6996 | |
| 6997 | final int uid = uidStats.keyAt(iu); |
| 6998 | proto.write(UidProto.UID, uid); |
| 6999 | |
| 7000 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 7001 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 7002 | if (pkgs == null) { |
| 7003 | pkgs = new ArrayList<String>(); |
| 7004 | } |
| 7005 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 7006 | u.getPackageStats(); |
| 7007 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7008 | String pkg = packageStats.keyAt(ipkg); |
| 7009 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 7010 | packageStats.valueAt(ipkg).getServiceStats(); |
| 7011 | if (serviceStats.size() == 0) { |
| 7012 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 7013 | // example, "android") may be included in the packageStats that aren't part of |
| 7014 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 7015 | // These packages won't be a part in the pkgs List. |
| 7016 | continue; |
| 7017 | } |
| 7018 | |
| 7019 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7020 | proto.write(UidProto.Package.NAME, pkg); |
| 7021 | // Remove from the packages list since we're logging it here. |
| 7022 | pkgs.remove(pkg); |
| 7023 | |
| 7024 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 7025 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 7026 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 7027 | |
| 7028 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 7029 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 7030 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 7031 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 7032 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 7033 | |
| 7034 | proto.end(sToken); |
| 7035 | } |
| 7036 | proto.end(pToken); |
| 7037 | } |
| 7038 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 7039 | // from PackageManager data. Packages are only included in packageStats if there was |
| 7040 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 7041 | for (String p : pkgs) { |
| 7042 | final long pToken = proto.start(UidProto.PACKAGES); |
| 7043 | proto.write(UidProto.Package.NAME, p); |
| 7044 | proto.end(pToken); |
| 7045 | } |
| 7046 | |
| 7047 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 7048 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 7049 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 7050 | // Times are since reset (regardless of 'which') |
| 7051 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 7052 | final Timer bgTimer = timer.getSubTimer(); |
| 7053 | final long bgTimeMs = bgTimer != null |
| 7054 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 7055 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 7056 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 7057 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 7058 | proto.end(awToken); |
| 7059 | } |
| 7060 | |
| 7061 | // Audio (AUDIO_DATA) |
| 7062 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 7063 | |
| 7064 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 7065 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 7066 | u.getBluetoothControllerActivity(), which); |
| 7067 | |
| 7068 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 7069 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 7070 | if (bleTimer != null) { |
| 7071 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 7072 | |
| 7073 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 7074 | rawRealtimeUs, which); |
| 7075 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 7076 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 7077 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 7078 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 7079 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 7080 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 7081 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 7082 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 7083 | // Result counters |
| 7084 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 7085 | u.getBluetoothScanResultCounter() != null |
| 7086 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 7087 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 7088 | u.getBluetoothScanResultBgCounter() != null |
| 7089 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 7090 | |
| 7091 | proto.end(bmToken); |
| 7092 | } |
| 7093 | |
| 7094 | // Camera (CAMERA_DATA) |
| 7095 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 7096 | |
| 7097 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 7098 | final long cpuToken = proto.start(UidProto.CPU); |
| 7099 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 7100 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 7101 | |
| 7102 | final long[] cpuFreqs = getCpuFreqs(); |
| 7103 | if (cpuFreqs != null) { |
| 7104 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 7105 | // If total cpuFreqTimes is null, then we don't need to check for |
| 7106 | // screenOffCpuFreqTimes. |
| 7107 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 7108 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 7109 | if (screenOffCpuFreqTimeMs == null) { |
| 7110 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 7111 | } |
| 7112 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 7113 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 7114 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7115 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7116 | cpuFreqTimeMs[ic]); |
| 7117 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7118 | screenOffCpuFreqTimeMs[ic]); |
| 7119 | proto.end(cToken); |
| 7120 | } |
| 7121 | } |
| 7122 | } |
Sudheer Shanka | 6d658d7 | 2018-01-01 01:36:49 -0800 | [diff] [blame] | 7123 | |
| 7124 | for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) { |
| 7125 | final long[] timesMs = u.getCpuFreqTimes(which, procState); |
| 7126 | if (timesMs != null && timesMs.length == cpuFreqs.length) { |
| 7127 | long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState); |
| 7128 | if (screenOffTimesMs == null) { |
| 7129 | screenOffTimesMs = new long[timesMs.length]; |
| 7130 | } |
| 7131 | final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE); |
| 7132 | proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState); |
| 7133 | for (int ic = 0; ic < timesMs.length; ++ic) { |
| 7134 | long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY); |
| 7135 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 7136 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 7137 | timesMs[ic]); |
| 7138 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 7139 | screenOffTimesMs[ic]); |
| 7140 | proto.end(cToken); |
| 7141 | } |
| 7142 | proto.end(procToken); |
| 7143 | } |
| 7144 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7145 | proto.end(cpuToken); |
| 7146 | |
| 7147 | // Flashlight (FLASHLIGHT_DATA) |
| 7148 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 7149 | rawRealtimeUs, which); |
| 7150 | |
| 7151 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 7152 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 7153 | rawRealtimeUs, which); |
| 7154 | |
| 7155 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 7156 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 7157 | rawRealtimeUs, which); |
| 7158 | |
| 7159 | // Job completion (JOB_COMPLETION_DATA) |
| 7160 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 7161 | final int[] reasons = new int[]{ |
| 7162 | JobParameters.REASON_CANCELED, |
| 7163 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 7164 | JobParameters.REASON_PREEMPT, |
| 7165 | JobParameters.REASON_TIMEOUT, |
| 7166 | JobParameters.REASON_DEVICE_IDLE, |
| 7167 | }; |
| 7168 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 7169 | SparseIntArray types = completions.valueAt(ic); |
| 7170 | if (types != null) { |
| 7171 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 7172 | |
| 7173 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 7174 | |
| 7175 | for (int r : reasons) { |
| 7176 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 7177 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 7178 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 7179 | proto.end(rToken); |
| 7180 | } |
| 7181 | |
| 7182 | proto.end(jcToken); |
| 7183 | } |
| 7184 | } |
| 7185 | |
| 7186 | // Scheduled jobs (JOB_DATA) |
| 7187 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 7188 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 7189 | final Timer timer = jobs.valueAt(ij); |
| 7190 | final Timer bgTimer = timer.getSubTimer(); |
| 7191 | final long jToken = proto.start(UidProto.JOBS); |
| 7192 | |
| 7193 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 7194 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7195 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 7196 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7197 | |
| 7198 | proto.end(jToken); |
| 7199 | } |
| 7200 | |
| 7201 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7202 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7203 | u.getModemControllerActivity(), which); |
| 7204 | |
| 7205 | // Network stats (NETWORK_DATA) |
| 7206 | final long nToken = proto.start(UidProto.NETWORK); |
| 7207 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7208 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7209 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7210 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7211 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7212 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7213 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7214 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7215 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7216 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7217 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7218 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7219 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7220 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7221 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7222 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7223 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7224 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7225 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7226 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7227 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7228 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7229 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7230 | u.getMobileRadioActiveCount(which)); |
| 7231 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7232 | u.getMobileRadioApWakeupCount(which)); |
| 7233 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7234 | u.getWifiRadioApWakeupCount(which)); |
| 7235 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7236 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7237 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7238 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7239 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7240 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7241 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7242 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7243 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7244 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7245 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7246 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7247 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7248 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7249 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7250 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7251 | proto.end(nToken); |
| 7252 | |
| 7253 | // Power use item (POWER_USE_ITEM_DATA) |
| 7254 | BatterySipper bs = uidToSipper.get(uid); |
| 7255 | if (bs != null) { |
| 7256 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7257 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7258 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7259 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7260 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7261 | bs.proportionalSmearMah); |
| 7262 | proto.end(bsToken); |
| 7263 | } |
| 7264 | |
| 7265 | // Processes (PROCESS_DATA) |
| 7266 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7267 | u.getProcessStats(); |
| 7268 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7269 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7270 | final long prToken = proto.start(UidProto.PROCESS); |
| 7271 | |
| 7272 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7273 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7274 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7275 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7276 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7277 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7278 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7279 | |
| 7280 | proto.end(prToken); |
| 7281 | } |
| 7282 | |
| 7283 | // Sensors (SENSOR_DATA) |
| 7284 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7285 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7286 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7287 | final Timer timer = se.getSensorTime(); |
| 7288 | if (timer == null) { |
| 7289 | continue; |
| 7290 | } |
| 7291 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7292 | final int sensorNumber = sensors.keyAt(ise); |
| 7293 | final long seToken = proto.start(UidProto.SENSORS); |
| 7294 | |
| 7295 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7296 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7297 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7298 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7299 | |
| 7300 | proto.end(seToken); |
| 7301 | } |
| 7302 | |
| 7303 | // State times (STATE_TIME_DATA) |
| 7304 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7305 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7306 | if (durMs == 0) { |
| 7307 | continue; |
| 7308 | } |
| 7309 | final long stToken = proto.start(UidProto.STATES); |
| 7310 | proto.write(UidProto.StateTime.STATE, ips); |
| 7311 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7312 | proto.end(stToken); |
| 7313 | } |
| 7314 | |
| 7315 | // Syncs (SYNC_DATA) |
| 7316 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7317 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7318 | final Timer timer = syncs.valueAt(isy); |
| 7319 | final Timer bgTimer = timer.getSubTimer(); |
| 7320 | final long syToken = proto.start(UidProto.SYNCS); |
| 7321 | |
| 7322 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7323 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7324 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7325 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7326 | |
| 7327 | proto.end(syToken); |
| 7328 | } |
| 7329 | |
| 7330 | // User activity (USER_ACTIVITY_DATA) |
| 7331 | if (u.hasUserActivity()) { |
| 7332 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7333 | int val = u.getUserActivityCount(i, which); |
| 7334 | if (val != 0) { |
| 7335 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7336 | proto.write(UidProto.UserActivity.NAME, i); |
| 7337 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7338 | proto.end(uaToken); |
| 7339 | } |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | // Vibrator (VIBRATOR_DATA) |
| 7344 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7345 | |
| 7346 | // Video (VIDEO_DATA) |
| 7347 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7348 | |
| 7349 | // Wakelocks (WAKELOCK_DATA) |
| 7350 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7351 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7352 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7353 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7354 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7355 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7356 | rawRealtimeUs, which); |
| 7357 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7358 | if (pTimer != null) { |
| 7359 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7360 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7361 | rawRealtimeUs, which); |
| 7362 | } |
| 7363 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7364 | rawRealtimeUs, which); |
| 7365 | proto.end(wToken); |
| 7366 | } |
| 7367 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7368 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7369 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7370 | rawRealtimeUs, which); |
| 7371 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7372 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7373 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7374 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7375 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7376 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7377 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7378 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7379 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7380 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7381 | proto.end(waToken); |
| 7382 | } |
| 7383 | } |
| 7384 | |
| 7385 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7386 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7387 | u.getWifiControllerActivity(), which); |
| 7388 | |
| 7389 | // Wifi data (WIFI_DATA) |
| 7390 | final long wToken = proto.start(UidProto.WIFI); |
| 7391 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7392 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7393 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7394 | rawRealtimeUs, which); |
| 7395 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7396 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7397 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7398 | rawRealtimeUs, which); |
| 7399 | proto.end(wToken); |
| 7400 | |
| 7401 | proto.end(uTkn); |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7406 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7407 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7408 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7409 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7410 | final int which = STATS_SINCE_CHARGED; |
| 7411 | |
| 7412 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7413 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7414 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7415 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7416 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7417 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7418 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7419 | computeUptime(rawUptimeUs, which) / 1000); |
| 7420 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7421 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7422 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7423 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7424 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7425 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7426 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7427 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7428 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7429 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7430 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7431 | getEstimatedBatteryCapacity()); |
| 7432 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7433 | getMinLearnedBatteryCapacity()); |
| 7434 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7435 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7436 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7437 | |
| 7438 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7439 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7440 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7441 | getLowDischargeAmountSinceCharge()); |
| 7442 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7443 | getHighDischargeAmountSinceCharge()); |
| 7444 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7445 | getDischargeAmountScreenOnSinceCharge()); |
| 7446 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7447 | getDischargeAmountScreenOffSinceCharge()); |
| 7448 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7449 | getDischargeAmountScreenDozeSinceCharge()); |
| 7450 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7451 | getUahDischarge(which) / 1000); |
| 7452 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7453 | getUahDischargeScreenOff(which) / 1000); |
| 7454 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7455 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7456 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7457 | getUahDischargeLightDoze(which) / 1000); |
| 7458 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7459 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7460 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7461 | |
| 7462 | // Time remaining |
| 7463 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7464 | // 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] | 7465 | if (timeRemainingUs >= 0) { |
| 7466 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7467 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7468 | } else { |
| 7469 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7470 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7471 | if (timeRemainingUs >= 0) { |
| 7472 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7473 | } else { |
| 7474 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | // Charge step (CHARGE_STEP_DATA) |
| 7479 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7480 | |
| 7481 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7482 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7483 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7484 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7485 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7486 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7487 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7491 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7492 | |
| 7493 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7494 | final long[] cpuFreqs = getCpuFreqs(); |
| 7495 | if (cpuFreqs != null) { |
| 7496 | for (long i : cpuFreqs) { |
| 7497 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7498 | } |
| 7499 | } |
| 7500 | |
| 7501 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7502 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7503 | getBluetoothControllerActivity(), which); |
| 7504 | |
| 7505 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7506 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7507 | getModemControllerActivity(), which); |
| 7508 | |
| 7509 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7510 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7511 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7512 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7513 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7514 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7515 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7516 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7517 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7518 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7519 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7520 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7521 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7522 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7523 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7524 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7525 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7526 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7527 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7528 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7529 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7530 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7531 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7532 | |
| 7533 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7534 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7535 | getWifiControllerActivity(), which); |
| 7536 | |
| 7537 | |
| 7538 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7539 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7540 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7541 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7542 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7543 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7544 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7545 | |
| 7546 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7547 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7548 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7549 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7550 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7551 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7552 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7553 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | // Misc (MISC_DATA) |
| 7557 | // Calculate wakelock times across all uids. |
| 7558 | long fullWakeLockTimeTotalUs = 0; |
| 7559 | long partialWakeLockTimeTotalUs = 0; |
| 7560 | |
| 7561 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7562 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7563 | final Uid u = uidStats.valueAt(iu); |
| 7564 | |
| 7565 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7566 | u.getWakelockStats(); |
| 7567 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7568 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7569 | |
| 7570 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7571 | if (fullWakeTimer != null) { |
| 7572 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7573 | which); |
| 7574 | } |
| 7575 | |
| 7576 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7577 | if (partialWakeTimer != null) { |
| 7578 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7579 | rawRealtimeUs, which); |
| 7580 | } |
| 7581 | } |
| 7582 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7583 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7584 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7585 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7586 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7587 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7588 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7589 | fullWakeLockTimeTotalUs / 1000); |
| 7590 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7591 | partialWakeLockTimeTotalUs / 1000); |
| 7592 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7593 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7594 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7595 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7596 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7597 | getMobileRadioActiveCount(which)); |
| 7598 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7599 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7600 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7601 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7602 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7603 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7604 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7605 | getNumConnectivityChange(which)); |
| 7606 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7607 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7608 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7609 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7610 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7611 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7612 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7613 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7614 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7615 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7616 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7617 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7618 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7619 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7620 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7621 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7622 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7623 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7624 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7625 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7626 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7627 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7628 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 7629 | final long multicastWakeLockTimeTotalUs = |
| 7630 | getWifiMulticastWakelockTime(rawRealtimeUs, which); |
| 7631 | final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7632 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7633 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7634 | multicastWakeLockTimeTotalUs / 1000); |
| 7635 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7636 | multicastWakeLockCountTotal); |
| 7637 | proto.end(wmctToken); |
| 7638 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7639 | // Power use item (POWER_USE_ITEM_DATA) |
| 7640 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7641 | if (sippers != null) { |
| 7642 | for (int i = 0; i < sippers.size(); ++i) { |
| 7643 | final BatterySipper bs = sippers.get(i); |
| 7644 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7645 | int uid = 0; |
| 7646 | switch (bs.drainType) { |
| 7647 | case IDLE: |
| 7648 | n = SystemProto.PowerUseItem.IDLE; |
| 7649 | break; |
| 7650 | case CELL: |
| 7651 | n = SystemProto.PowerUseItem.CELL; |
| 7652 | break; |
| 7653 | case PHONE: |
| 7654 | n = SystemProto.PowerUseItem.PHONE; |
| 7655 | break; |
| 7656 | case WIFI: |
| 7657 | n = SystemProto.PowerUseItem.WIFI; |
| 7658 | break; |
| 7659 | case BLUETOOTH: |
| 7660 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7661 | break; |
| 7662 | case SCREEN: |
| 7663 | n = SystemProto.PowerUseItem.SCREEN; |
| 7664 | break; |
| 7665 | case FLASHLIGHT: |
| 7666 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7667 | break; |
| 7668 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7669 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7670 | continue; |
| 7671 | case USER: |
| 7672 | n = SystemProto.PowerUseItem.USER; |
| 7673 | uid = UserHandle.getUid(bs.userId, 0); |
| 7674 | break; |
| 7675 | case UNACCOUNTED: |
| 7676 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7677 | break; |
| 7678 | case OVERCOUNTED: |
| 7679 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7680 | break; |
| 7681 | case CAMERA: |
| 7682 | n = SystemProto.PowerUseItem.CAMERA; |
| 7683 | break; |
| 7684 | case MEMORY: |
| 7685 | n = SystemProto.PowerUseItem.MEMORY; |
| 7686 | break; |
| 7687 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7688 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7689 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7690 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7691 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7692 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7693 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7694 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7695 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7696 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7701 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7702 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7703 | helper.getPowerProfile().getBatteryCapacity()); |
| 7704 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7705 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7706 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7707 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7708 | |
| 7709 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7710 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7711 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7712 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7713 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7714 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7715 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7716 | ent.getValue(), rawRealtimeUs, which); |
| 7717 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7718 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7719 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7723 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7724 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7725 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7726 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7727 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7728 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7729 | } |
| 7730 | |
| 7731 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7732 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7733 | which); |
| 7734 | |
| 7735 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7736 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7737 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7738 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7739 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7740 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7741 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7742 | } |
| 7743 | |
| 7744 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7745 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7746 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7747 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7748 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7749 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7750 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7754 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7755 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7756 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7757 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7758 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7759 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7763 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7764 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7765 | proto.write(SystemProto.WifiState.NAME, i); |
| 7766 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7767 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7768 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7769 | } |
| 7770 | |
| 7771 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7772 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7773 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7774 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7775 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7776 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7777 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7778 | } |
| 7779 | |
| 7780 | proto.end(sToken); |
| 7781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7782 | } |