Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 19 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 22 | import android.service.batterystats.BatteryStatsServiceDumpProto; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 23 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 24 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 25 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 26 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 27 | import android.util.MutableBoolean; |
| 28 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.util.Printer; |
| 30 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 31 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 32 | import android.util.TimeUtils; |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 33 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 35 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 36 | import com.android.internal.os.BatterySipper; |
| 37 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 39 | import java.io.FileDescriptor; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 40 | import java.io.PrintWriter; |
| 41 | import java.util.ArrayList; |
| 42 | import java.util.Collections; |
| 43 | import java.util.Comparator; |
| 44 | import java.util.Formatter; |
| 45 | import java.util.HashMap; |
| 46 | import java.util.List; |
| 47 | import java.util.Map; |
| 48 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | /** |
| 50 | * A class providing access to battery usage statistics, including information on |
| 51 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 52 | * except where indicated otherwise. |
| 53 | * @hide |
| 54 | */ |
| 55 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 56 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | private static final boolean LOCAL_LOGV = false; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 59 | /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */ |
| 60 | protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 61 | |
| 62 | /** @hide */ |
| 63 | public static final String SERVICE_NAME = "batterystats"; |
| 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | /** |
| 66 | * A constant indicating a partial wake lock timer. |
| 67 | */ |
| 68 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 69 | |
| 70 | /** |
| 71 | * A constant indicating a full wake lock timer. |
| 72 | */ |
| 73 | public static final int WAKE_TYPE_FULL = 1; |
| 74 | |
| 75 | /** |
| 76 | * A constant indicating a window wake lock timer. |
| 77 | */ |
| 78 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | /** |
| 81 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | */ |
| 83 | public static final int SENSOR = 3; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 85 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 86 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 87 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 88 | public static final int WIFI_RUNNING = 4; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 89 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 90 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 91 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 92 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 93 | public static final int FULL_WIFI_LOCK = 5; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 94 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 95 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 96 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 97 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 98 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 100 | /** |
| 101 | * A constant indicating a wifi multicast timer |
| 102 | */ |
| 103 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 106 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 107 | */ |
| 108 | public static final int VIDEO_TURNED_ON = 8; |
| 109 | |
| 110 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 111 | * A constant indicating a vibrator on timer |
| 112 | */ |
| 113 | public static final int VIBRATOR_ON = 9; |
| 114 | |
| 115 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 116 | * A constant indicating a foreground activity timer |
| 117 | */ |
| 118 | public static final int FOREGROUND_ACTIVITY = 10; |
| 119 | |
| 120 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 121 | * A constant indicating a wifi batched scan is active |
| 122 | */ |
| 123 | public static final int WIFI_BATCHED_SCAN = 11; |
| 124 | |
| 125 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 126 | * A constant indicating a process state timer |
| 127 | */ |
| 128 | public static final int PROCESS_STATE = 12; |
| 129 | |
| 130 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 131 | * A constant indicating a sync timer |
| 132 | */ |
| 133 | public static final int SYNC = 13; |
| 134 | |
| 135 | /** |
| 136 | * A constant indicating a job timer |
| 137 | */ |
| 138 | public static final int JOB = 14; |
| 139 | |
| 140 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 141 | * A constant indicating an audio turn on timer |
| 142 | */ |
| 143 | public static final int AUDIO_TURNED_ON = 15; |
| 144 | |
| 145 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 146 | * A constant indicating a flashlight turn on timer |
| 147 | */ |
| 148 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 149 | |
| 150 | /** |
| 151 | * A constant indicating a camera turn on timer |
| 152 | */ |
| 153 | public static final int CAMERA_TURNED_ON = 17; |
| 154 | |
| 155 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 156 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 157 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 158 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 161 | * A constant indicating a bluetooth scan timer. |
| 162 | */ |
| 163 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 164 | |
| 165 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 166 | * A constant indicating an aggregated partial wake lock timer. |
| 167 | */ |
| 168 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 169 | |
| 170 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 171 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 172 | */ |
| 173 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 174 | |
| 175 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 176 | * A constant indicating a foreground service timer |
| 177 | */ |
| 178 | public static final int FOREGROUND_SERVICE = 22; |
| 179 | |
| 180 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * Include all of the data in the stats, including previously saved data. |
| 182 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 183 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | * Include only the current run in the stats. |
| 187 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 188 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Include only the run since the last time the device was unplugged in the stats. |
| 192 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 193 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 194 | |
| 195 | // NOTE: Update this list if you add/change any stats above. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 196 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 197 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 198 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 201 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 202 | * |
| 203 | * New in version 19: |
| 204 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 205 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 206 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 207 | * New in version 21: |
| 208 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 209 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 210 | * - BLE scan result count |
| 211 | * - CPU frequency time per uid |
| 212 | * New in version 22: |
| 213 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 214 | * - Background partial wakelock time & count |
| 215 | * New in version 23: |
| 216 | * - Logging smeared power model values |
| 217 | * New in version 24: |
| 218 | * - Fixed bugs in background timers and BLE scan time |
| 219 | * New in version 25: |
| 220 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 221 | * New in version 26: |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 222 | * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly] |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 223 | * New in version 27: |
| 224 | * - Always On Display (screen doze mode) time and power |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 225 | * New in version 28: |
| 226 | * - Light/Deep Doze power |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 227 | * - WiFi Multicast Wakelock statistics (count & duration) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 228 | */ |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 229 | static final int CHECKIN_VERSION = 28; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * 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] | 233 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 234 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 235 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 236 | private static final long BYTES_PER_KB = 1024; |
| 237 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 238 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 239 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 240 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 241 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 242 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 244 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 245 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 246 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 247 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 248 | // rpm line is: |
| 249 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 250 | // screen-off time, screen-off count |
| 251 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 252 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 253 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 254 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 255 | // fgs line is: |
| 256 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 257 | // foreground service time, count |
| 258 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 259 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 260 | // wl line is: |
| 261 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 262 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 263 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 264 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 265 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 266 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 267 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 268 | // awl line is: |
| 269 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 270 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 271 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 272 | private static final String SYNC_DATA = "sy"; |
| 273 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 274 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 275 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 276 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 277 | private static final String NETWORK_DATA = "nt"; |
| 278 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 279 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 280 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 281 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 282 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 283 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 284 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 285 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 286 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 287 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 288 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 289 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 290 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 291 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 292 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 293 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 294 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 295 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 296 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 297 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 298 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 299 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 300 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 301 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 302 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 303 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 304 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 305 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 306 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 307 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 308 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 309 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 310 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 311 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 312 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 313 | private static final String FLASHLIGHT_DATA = "fla"; |
| 314 | private static final String CAMERA_DATA = "cam"; |
| 315 | private static final String VIDEO_DATA = "vid"; |
| 316 | private static final String AUDIO_DATA = "aud"; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 317 | private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; |
| 318 | private static final String WIFI_MULTICAST_DATA = "wmc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 320 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 321 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 322 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 324 | |
| 325 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 326 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 327 | * |
| 328 | * Other types might include times spent in foreground, background etc. |
| 329 | */ |
| 330 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 331 | |
| 332 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 333 | * State for keeping track of counting information. |
| 334 | */ |
| 335 | public static abstract class Counter { |
| 336 | |
| 337 | /** |
| 338 | * Returns the count associated with this Counter for the |
| 339 | * selected type of statistics. |
| 340 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 341 | * @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] | 342 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 343 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Temporary for debugging. |
| 347 | */ |
| 348 | public abstract void logState(Printer pw, String prefix); |
| 349 | } |
| 350 | |
| 351 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 352 | * State for keeping track of long counting information. |
| 353 | */ |
| 354 | public static abstract class LongCounter { |
| 355 | |
| 356 | /** |
| 357 | * Returns the count associated with this Counter for the |
| 358 | * selected type of statistics. |
| 359 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 360 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 361 | */ |
| 362 | public abstract long getCountLocked(int which); |
| 363 | |
| 364 | /** |
| 365 | * Temporary for debugging. |
| 366 | */ |
| 367 | public abstract void logState(Printer pw, String prefix); |
| 368 | } |
| 369 | |
| 370 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 371 | * State for keeping track of array of long counting information. |
| 372 | */ |
| 373 | public static abstract class LongCounterArray { |
| 374 | /** |
| 375 | * Returns the counts associated with this Counter for the |
| 376 | * selected type of statistics. |
| 377 | * |
| 378 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 379 | */ |
| 380 | public abstract long[] getCountsLocked(int which); |
| 381 | |
| 382 | /** |
| 383 | * Temporary for debugging. |
| 384 | */ |
| 385 | public abstract void logState(Printer pw, String prefix); |
| 386 | } |
| 387 | |
| 388 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 389 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 390 | * radio controller. |
| 391 | */ |
| 392 | public static abstract class ControllerActivityCounter { |
| 393 | /** |
| 394 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 395 | * idle state. |
| 396 | */ |
| 397 | public abstract LongCounter getIdleTimeCounter(); |
| 398 | |
| 399 | /** |
| 400 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 401 | * receive state. |
| 402 | */ |
| 403 | public abstract LongCounter getRxTimeCounter(); |
| 404 | |
| 405 | /** |
| 406 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 407 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 408 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 409 | * various transmit level states. |
| 410 | */ |
| 411 | public abstract LongCounter[] getTxTimeCounters(); |
| 412 | |
| 413 | /** |
| 414 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 415 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 416 | * yield a value of 0 if the device doesn't support power calculations. |
| 417 | */ |
| 418 | public abstract LongCounter getPowerCounter(); |
| 419 | } |
| 420 | |
| 421 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | * State for keeping track of timing information. |
| 423 | */ |
| 424 | public static abstract class Timer { |
| 425 | |
| 426 | /** |
| 427 | * Returns the count associated with this Timer for the |
| 428 | * selected type of statistics. |
| 429 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 430 | * @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] | 431 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 432 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * Returns the total time in microseconds associated with this Timer for the |
| 436 | * selected type of statistics. |
| 437 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 438 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 439 | * @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] | 440 | * @return a time in microseconds |
| 441 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 442 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 445 | * Returns the total time in microseconds associated with this Timer since the |
| 446 | * 'mark' was last set. |
| 447 | * |
| 448 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 449 | * @return a time in microseconds |
| 450 | */ |
| 451 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 452 | |
| 453 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 454 | * Returns the max duration if it is being tracked. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 455 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 456 | */ |
| 457 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 458 | return -1; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * 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] | 463 | * Not all Timer subclasses track the max, total, and current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 464 | */ |
| 465 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 466 | return -1; |
| 467 | } |
| 468 | |
| 469 | /** |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 470 | * 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] | 471 | * |
| 472 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 473 | * been on since reset. |
| 474 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 475 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 476 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 477 | * the actual total time. |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 478 | * Not all Timer subclasses track the max, total, and current durations. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 479 | */ |
| 480 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 485 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 486 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 487 | * |
| 488 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 489 | */ |
| 490 | public Timer getSubTimer() { |
| 491 | return null; |
| 492 | } |
| 493 | |
| 494 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 495 | * Returns whether the timer is currently running. Some types of timers |
| 496 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 497 | * and report false. |
| 498 | */ |
| 499 | public boolean isRunningLocked() { |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | * Temporary for debugging. |
| 505 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 506 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
| 510 | * The statistics associated with a particular uid. |
| 511 | */ |
| 512 | public static abstract class Uid { |
| 513 | |
| 514 | /** |
| 515 | * Returns a mapping containing wakelock statistics. |
| 516 | * |
| 517 | * @return a Map from Strings to Uid.Wakelock objects. |
| 518 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 519 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | |
| 521 | /** |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 522 | * Returns the WiFi Multicast Wakelock statistics. |
| 523 | * |
| 524 | * @return a Timer Object for the per uid Multicast statistics. |
| 525 | */ |
| 526 | public abstract Timer getMulticastWakelockStats(); |
| 527 | |
| 528 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 529 | * Returns a mapping containing sync statistics. |
| 530 | * |
| 531 | * @return a Map from Strings to Timer objects. |
| 532 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 533 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 534 | |
| 535 | /** |
| 536 | * Returns a mapping containing scheduled job statistics. |
| 537 | * |
| 538 | * @return a Map from Strings to Timer objects. |
| 539 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 540 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 541 | |
| 542 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 543 | * Returns statistics about how jobs have completed. |
| 544 | * |
| 545 | * @return A Map of String job names to completion type -> count mapping. |
| 546 | */ |
| 547 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 548 | |
| 549 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | * The statistics associated with a particular wake lock. |
| 551 | */ |
| 552 | public static abstract class Wakelock { |
| 553 | public abstract Timer getWakeTime(int type); |
| 554 | } |
| 555 | |
| 556 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 557 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 558 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 559 | * wakelocks that overlap in time (and therefore over-counts). |
| 560 | */ |
| 561 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 562 | |
| 563 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | * Returns a mapping containing sensor statistics. |
| 565 | * |
| 566 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 567 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 568 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | |
| 570 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 571 | * Returns a mapping containing active process data. |
| 572 | */ |
| 573 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 574 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 575 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | * Returns a mapping containing process statistics. |
| 577 | * |
| 578 | * @return a Map from Strings to Uid.Proc objects. |
| 579 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 580 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * Returns a mapping containing package statistics. |
| 584 | * |
| 585 | * @return a Map from Strings to Uid.Pkg objects. |
| 586 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 587 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 588 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 589 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 590 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 591 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 592 | |
| 593 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | * {@hide} |
| 595 | */ |
| 596 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 597 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 598 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 599 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 600 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 601 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 602 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 603 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 604 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 605 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 606 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 607 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 608 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 609 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 610 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 611 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 612 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 613 | public abstract int getWifiScanCount(int which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 614 | /** |
| 615 | * Returns the timer keeping track of wifi scans. |
| 616 | */ |
| 617 | public abstract Timer getWifiScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 618 | public abstract int getWifiScanBackgroundCount(int which); |
| 619 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 620 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Returns the timer keeping track of background wifi scans. |
| 623 | */ |
| 624 | public abstract Timer getWifiScanBackgroundTimer(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 625 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 626 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 627 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 628 | public abstract Timer getAudioTurnedOnTimer(); |
| 629 | public abstract Timer getVideoTurnedOnTimer(); |
| 630 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 631 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 632 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * Returns the timer keeping track of Foreground Service time |
| 636 | */ |
| 637 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 638 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 639 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 640 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 641 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 642 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 643 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 644 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 645 | public abstract long[] getCpuFreqTimes(int which); |
| 646 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 647 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 648 | // Note: the following times are disjoint. They can be added together to find the |
| 649 | // total time a uid has had any processes running at all. |
| 650 | |
| 651 | /** |
| 652 | * Time this uid has any processes in the top state (or above such as persistent). |
| 653 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 654 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 655 | /** |
| 656 | * Time this uid has any process with a started out bound foreground service, but |
| 657 | * none in the "top" state. |
| 658 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 659 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 660 | /** |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 661 | * Time this uid has any process in an active foreground state, but none in the |
| 662 | * "top sleeping" or better state. |
| 663 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame^] | 664 | public static final int PROCESS_STATE_FOREGROUND = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 665 | /** |
| 666 | * Time this uid has any process in an active background state, but none in the |
| 667 | * "foreground" or better state. |
| 668 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame^] | 669 | public static final int PROCESS_STATE_BACKGROUND = 3; |
| 670 | /** |
| 671 | * Time this uid has any process that is top while the device is sleeping, but not |
| 672 | * active for any other reason. We kind-of consider it a kind of cached process |
| 673 | * for execution restrictions. |
| 674 | */ |
| 675 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 676 | /** |
| 677 | * Time this uid has any process that is in the background but it has an activity |
| 678 | * marked as "can't save state". This is essentially a cached process, though the |
| 679 | * system will try much harder than normal to avoid killing it. |
| 680 | */ |
| 681 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 682 | /** |
| 683 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 684 | * other active states. |
| 685 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame^] | 686 | public static final int PROCESS_STATE_CACHED = 6; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 687 | /** |
| 688 | * Total number of process states we track. |
| 689 | */ |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame^] | 690 | public static final int NUM_PROCESS_STATE = 7; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 691 | |
| 692 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame^] | 693 | "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight", |
| 694 | "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 698 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 699 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 700 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 702 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 703 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 704 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 705 | * Note that these must match the constants in android.os.PowerManager. |
| 706 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 707 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 708 | */ |
| 709 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 710 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 711 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 712 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 713 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 714 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 715 | public abstract void noteUserActivityLocked(int type); |
| 716 | public abstract boolean hasUserActivity(); |
| 717 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 718 | |
| 719 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 720 | public abstract long getNetworkActivityBytes(int type, int which); |
| 721 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 722 | public abstract long getMobileRadioActiveTime(int which); |
| 723 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 724 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 725 | /** |
| 726 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 727 | */ |
| 728 | public abstract long getUserCpuTimeUs(int which); |
| 729 | |
| 730 | /** |
| 731 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 732 | */ |
| 733 | public abstract long getSystemCpuTimeUs(int which); |
| 734 | |
| 735 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 736 | * 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] | 737 | * given CPU cluster. |
| 738 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 739 | * @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] | 740 | * @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] | 741 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 742 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 743 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 744 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 745 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 746 | /** |
| 747 | * Returns the number of times this UID woke up the Application Processor to |
| 748 | * process a mobile radio packet. |
| 749 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 750 | */ |
| 751 | public abstract long getMobileRadioApWakeupCount(int which); |
| 752 | |
| 753 | /** |
| 754 | * Returns the number of times this UID woke up the Application Processor to |
| 755 | * process a WiFi packet. |
| 756 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 757 | */ |
| 758 | public abstract long getWifiRadioApWakeupCount(int which); |
| 759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 761 | /* |
| 762 | * FIXME: it's not correct to use this magic value because it |
| 763 | * could clash with a sensor handle (which are defined by |
| 764 | * the sensor HAL, and therefore out of our control |
| 765 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | // Magic sensor number for the GPS. |
| 767 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 772 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 773 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 774 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 777 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 778 | public int mWakeNesting; |
| 779 | public long mWakeSumMs; |
| 780 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 781 | } |
| 782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | /** |
| 784 | * The statistics associated with a particular process. |
| 785 | */ |
| 786 | public static abstract class Proc { |
| 787 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 788 | public static class ExcessivePower { |
| 789 | public static final int TYPE_WAKE = 1; |
| 790 | public static final int TYPE_CPU = 2; |
| 791 | |
| 792 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 793 | public long overTime; |
| 794 | public long usedTime; |
| 795 | } |
| 796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 798 | * Returns true if this process is still active in the battery stats. |
| 799 | */ |
| 800 | public abstract boolean isActive(); |
| 801 | |
| 802 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 803 | * 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] | 804 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 805 | * @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] | 806 | */ |
| 807 | public abstract long getUserTime(int which); |
| 808 | |
| 809 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 810 | * 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] | 811 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 812 | * @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] | 813 | */ |
| 814 | public abstract long getSystemTime(int which); |
| 815 | |
| 816 | /** |
| 817 | * Returns the number of times the process has been started. |
| 818 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 819 | * @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] | 820 | */ |
| 821 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 822 | |
| 823 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 824 | * Returns the number of times the process has crashed. |
| 825 | * |
| 826 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 827 | */ |
| 828 | public abstract int getNumCrashes(int which); |
| 829 | |
| 830 | /** |
| 831 | * Returns the number of times the process has ANRed. |
| 832 | * |
| 833 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 834 | */ |
| 835 | public abstract int getNumAnrs(int which); |
| 836 | |
| 837 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 838 | * 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] | 839 | * @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] | 840 | * @return foreground cpu time in microseconds |
| 841 | */ |
| 842 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 843 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 844 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 845 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 846 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /** |
| 850 | * The statistics associated with a particular package. |
| 851 | */ |
| 852 | public static abstract class Pkg { |
| 853 | |
| 854 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 855 | * Returns information about all wakeup alarms that have been triggered for this |
| 856 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 857 | * 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] | 858 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 859 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | |
| 861 | /** |
| 862 | * Returns a mapping containing service statistics. |
| 863 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 864 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | |
| 866 | /** |
| 867 | * The statistics associated with a particular service. |
| 868 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 869 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * Returns the amount of time spent started. |
| 873 | * |
| 874 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 875 | * @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] | 876 | * @return |
| 877 | */ |
| 878 | public abstract long getStartTime(long batteryUptime, int which); |
| 879 | |
| 880 | /** |
| 881 | * Returns the total number of times startService() has been called. |
| 882 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 883 | * @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] | 884 | */ |
| 885 | public abstract int getStarts(int which); |
| 886 | |
| 887 | /** |
| 888 | * Returns the total number times the service has been launched. |
| 889 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 890 | * @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] | 891 | */ |
| 892 | public abstract int getLaunches(int which); |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 897 | public static final class LevelStepTracker { |
| 898 | public long mLastStepTime = -1; |
| 899 | public int mNumStepDurations; |
| 900 | public final long[] mStepDurations; |
| 901 | |
| 902 | public LevelStepTracker(int maxLevelSteps) { |
| 903 | mStepDurations = new long[maxLevelSteps]; |
| 904 | } |
| 905 | |
| 906 | public LevelStepTracker(int numSteps, long[] steps) { |
| 907 | mNumStepDurations = numSteps; |
| 908 | mStepDurations = new long[numSteps]; |
| 909 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 910 | } |
| 911 | |
| 912 | public long getDurationAt(int index) { |
| 913 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 914 | } |
| 915 | |
| 916 | public int getLevelAt(int index) { |
| 917 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 918 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 919 | } |
| 920 | |
| 921 | public int getInitModeAt(int index) { |
| 922 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 923 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 924 | } |
| 925 | |
| 926 | public int getModModeAt(int index) { |
| 927 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 928 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 929 | } |
| 930 | |
| 931 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 932 | boolean hasData = false; |
| 933 | while (topOffset >= 0) { |
| 934 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 935 | topOffset -= 4; |
| 936 | if (!hasData && digit == 0) { |
| 937 | continue; |
| 938 | } |
| 939 | hasData = true; |
| 940 | if (digit >= 0 && digit <= 9) { |
| 941 | out.append((char)('0' + digit)); |
| 942 | } else { |
| 943 | out.append((char)('a' + digit - 10)); |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | public void encodeEntryAt(int index, StringBuilder out) { |
| 949 | long item = mStepDurations[index]; |
| 950 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 951 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 952 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 953 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 954 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 955 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 956 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 957 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 958 | case Display.STATE_OFF: out.append('f'); break; |
| 959 | case Display.STATE_ON: out.append('o'); break; |
| 960 | case Display.STATE_DOZE: out.append('d'); break; |
| 961 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 962 | } |
| 963 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 964 | out.append('p'); |
| 965 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 966 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 967 | out.append('i'); |
| 968 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 969 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 970 | case Display.STATE_OFF: out.append('F'); break; |
| 971 | case Display.STATE_ON: out.append('O'); break; |
| 972 | case Display.STATE_DOZE: out.append('D'); break; |
| 973 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 974 | } |
| 975 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 976 | out.append('P'); |
| 977 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 978 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 979 | out.append('I'); |
| 980 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 981 | out.append('-'); |
| 982 | appendHex(level, 4, out); |
| 983 | out.append('-'); |
| 984 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 985 | } |
| 986 | |
| 987 | public void decodeEntryAt(int index, String value) { |
| 988 | final int N = value.length(); |
| 989 | int i = 0; |
| 990 | char c; |
| 991 | long out = 0; |
| 992 | while (i < N && (c=value.charAt(i)) != '-') { |
| 993 | i++; |
| 994 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 995 | 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] | 996 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 997 | 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] | 998 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 999 | 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] | 1000 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1001 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1002 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1003 | break; |
| 1004 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1005 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1006 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1007 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1008 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 1009 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1010 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1011 | break; |
| 1012 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1013 | break; |
| 1014 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1015 | break; |
| 1016 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 1017 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1018 | break; |
| 1019 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 1020 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1021 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1022 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 1023 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 1024 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1028 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1029 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1030 | i++; |
| 1031 | level <<= 4; |
| 1032 | if (c >= '0' && c <= '9') { |
| 1033 | level += c - '0'; |
| 1034 | } else if (c >= 'a' && c <= 'f') { |
| 1035 | level += c - 'a' + 10; |
| 1036 | } else if (c >= 'A' && c <= 'F') { |
| 1037 | level += c - 'A' + 10; |
| 1038 | } |
| 1039 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1040 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1041 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1042 | long duration = 0; |
| 1043 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1044 | i++; |
| 1045 | duration <<= 4; |
| 1046 | if (c >= '0' && c <= '9') { |
| 1047 | duration += c - '0'; |
| 1048 | } else if (c >= 'a' && c <= 'f') { |
| 1049 | duration += c - 'a' + 10; |
| 1050 | } else if (c >= 'A' && c <= 'F') { |
| 1051 | duration += c - 'A' + 10; |
| 1052 | } |
| 1053 | } |
| 1054 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1055 | } |
| 1056 | |
| 1057 | public void init() { |
| 1058 | mLastStepTime = -1; |
| 1059 | mNumStepDurations = 0; |
| 1060 | } |
| 1061 | |
| 1062 | public void clearTime() { |
| 1063 | mLastStepTime = -1; |
| 1064 | } |
| 1065 | |
| 1066 | public long computeTimePerLevel() { |
| 1067 | final long[] steps = mStepDurations; |
| 1068 | final int numSteps = mNumStepDurations; |
| 1069 | |
| 1070 | // For now we'll do a simple average across all steps. |
| 1071 | if (numSteps <= 0) { |
| 1072 | return -1; |
| 1073 | } |
| 1074 | long total = 0; |
| 1075 | for (int i=0; i<numSteps; i++) { |
| 1076 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1077 | } |
| 1078 | return total / numSteps; |
| 1079 | /* |
| 1080 | long[] buckets = new long[numSteps]; |
| 1081 | int numBuckets = 0; |
| 1082 | int numToAverage = 4; |
| 1083 | int i = 0; |
| 1084 | while (i < numSteps) { |
| 1085 | long totalTime = 0; |
| 1086 | int num = 0; |
| 1087 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1088 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1089 | num++; |
| 1090 | } |
| 1091 | buckets[numBuckets] = totalTime / num; |
| 1092 | numBuckets++; |
| 1093 | numToAverage *= 2; |
| 1094 | i += num; |
| 1095 | } |
| 1096 | if (numBuckets < 1) { |
| 1097 | return -1; |
| 1098 | } |
| 1099 | long averageTime = buckets[numBuckets-1]; |
| 1100 | for (i=numBuckets-2; i>=0; i--) { |
| 1101 | averageTime = (averageTime + buckets[i]) / 2; |
| 1102 | } |
| 1103 | return averageTime; |
| 1104 | */ |
| 1105 | } |
| 1106 | |
| 1107 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1108 | int[] outNumOfInterest) { |
| 1109 | final long[] steps = mStepDurations; |
| 1110 | final int count = mNumStepDurations; |
| 1111 | if (count <= 0) { |
| 1112 | return -1; |
| 1113 | } |
| 1114 | long total = 0; |
| 1115 | int numOfInterest = 0; |
| 1116 | for (int i=0; i<count; i++) { |
| 1117 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1118 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1119 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1120 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1121 | // If the modes of interest didn't change during this step period... |
| 1122 | if ((modMode&modesOfInterest) == 0) { |
| 1123 | // And the mode values during this period match those we are measuring... |
| 1124 | if ((initMode&modesOfInterest) == modeValues) { |
| 1125 | // Then this can be used to estimate the total time! |
| 1126 | numOfInterest++; |
| 1127 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | if (numOfInterest <= 0) { |
| 1132 | return -1; |
| 1133 | } |
| 1134 | |
| 1135 | if (outNumOfInterest != null) { |
| 1136 | outNumOfInterest[0] = numOfInterest; |
| 1137 | } |
| 1138 | |
| 1139 | // The estimated time is the average time we spend in each level, multipled |
| 1140 | // by 100 -- the total number of battery levels |
| 1141 | return (total / numOfInterest) * 100; |
| 1142 | } |
| 1143 | |
| 1144 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1145 | int stepCount = mNumStepDurations; |
| 1146 | final long lastStepTime = mLastStepTime; |
| 1147 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1148 | final long[] steps = mStepDurations; |
| 1149 | long duration = elapsedRealtime - lastStepTime; |
| 1150 | for (int i=0; i<numStepLevels; i++) { |
| 1151 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1152 | long thisDuration = duration / (numStepLevels-i); |
| 1153 | duration -= thisDuration; |
| 1154 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1155 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1156 | } |
| 1157 | steps[0] = thisDuration | modeBits; |
| 1158 | } |
| 1159 | stepCount += numStepLevels; |
| 1160 | if (stepCount > steps.length) { |
| 1161 | stepCount = steps.length; |
| 1162 | } |
| 1163 | } |
| 1164 | mNumStepDurations = stepCount; |
| 1165 | mLastStepTime = elapsedRealtime; |
| 1166 | } |
| 1167 | |
| 1168 | public void readFromParcel(Parcel in) { |
| 1169 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1170 | if (N > mStepDurations.length) { |
| 1171 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1172 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1173 | mNumStepDurations = N; |
| 1174 | for (int i=0; i<N; i++) { |
| 1175 | mStepDurations[i] = in.readLong(); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | public void writeToParcel(Parcel out) { |
| 1180 | final int N = mNumStepDurations; |
| 1181 | out.writeInt(N); |
| 1182 | for (int i=0; i<N; i++) { |
| 1183 | out.writeLong(mStepDurations[i]); |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1188 | public static final class PackageChange { |
| 1189 | public String mPackageName; |
| 1190 | public boolean mUpdate; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1191 | public long mVersionCode; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1194 | public static final class DailyItem { |
| 1195 | public long mStartTime; |
| 1196 | public long mEndTime; |
| 1197 | public LevelStepTracker mDischargeSteps; |
| 1198 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1199 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1203 | |
| 1204 | public abstract long getCurrentDailyStartTime(); |
| 1205 | |
| 1206 | public abstract long getNextMinDailyDeadline(); |
| 1207 | |
| 1208 | public abstract long getNextMaxDailyDeadline(); |
| 1209 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1210 | public abstract long[] getCpuFreqs(); |
| 1211 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1212 | public final static class HistoryTag { |
| 1213 | public String string; |
| 1214 | public int uid; |
| 1215 | |
| 1216 | public int poolIdx; |
| 1217 | |
| 1218 | public void setTo(HistoryTag o) { |
| 1219 | string = o.string; |
| 1220 | uid = o.uid; |
| 1221 | poolIdx = o.poolIdx; |
| 1222 | } |
| 1223 | |
| 1224 | public void setTo(String _string, int _uid) { |
| 1225 | string = _string; |
| 1226 | uid = _uid; |
| 1227 | poolIdx = -1; |
| 1228 | } |
| 1229 | |
| 1230 | public void writeToParcel(Parcel dest, int flags) { |
| 1231 | dest.writeString(string); |
| 1232 | dest.writeInt(uid); |
| 1233 | } |
| 1234 | |
| 1235 | public void readFromParcel(Parcel src) { |
| 1236 | string = src.readString(); |
| 1237 | uid = src.readInt(); |
| 1238 | poolIdx = -1; |
| 1239 | } |
| 1240 | |
| 1241 | @Override |
| 1242 | public boolean equals(Object o) { |
| 1243 | if (this == o) return true; |
| 1244 | if (o == null || getClass() != o.getClass()) return false; |
| 1245 | |
| 1246 | HistoryTag that = (HistoryTag) o; |
| 1247 | |
| 1248 | if (uid != that.uid) return false; |
| 1249 | if (!string.equals(that.string)) return false; |
| 1250 | |
| 1251 | return true; |
| 1252 | } |
| 1253 | |
| 1254 | @Override |
| 1255 | public int hashCode() { |
| 1256 | int result = string.hashCode(); |
| 1257 | result = 31 * result + uid; |
| 1258 | return result; |
| 1259 | } |
| 1260 | } |
| 1261 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1262 | /** |
| 1263 | * Optional detailed information that can go into a history step. This is typically |
| 1264 | * generated each time the battery level changes. |
| 1265 | */ |
| 1266 | public final static class HistoryStepDetails { |
| 1267 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1268 | public int userTime; |
| 1269 | public int systemTime; |
| 1270 | |
| 1271 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1272 | public int appCpuUid1; |
| 1273 | public int appCpuUTime1; |
| 1274 | public int appCpuSTime1; |
| 1275 | public int appCpuUid2; |
| 1276 | public int appCpuUTime2; |
| 1277 | public int appCpuSTime2; |
| 1278 | public int appCpuUid3; |
| 1279 | public int appCpuUTime3; |
| 1280 | public int appCpuSTime3; |
| 1281 | |
| 1282 | // Information from /proc/stat |
| 1283 | public int statUserTime; |
| 1284 | public int statSystemTime; |
| 1285 | public int statIOWaitTime; |
| 1286 | public int statIrqTime; |
| 1287 | public int statSoftIrqTime; |
| 1288 | public int statIdlTime; |
| 1289 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1290 | // Platform-level low power state stats |
| 1291 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1292 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1293 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1294 | public HistoryStepDetails() { |
| 1295 | clear(); |
| 1296 | } |
| 1297 | |
| 1298 | public void clear() { |
| 1299 | userTime = systemTime = 0; |
| 1300 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1301 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1302 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1303 | } |
| 1304 | |
| 1305 | public void writeToParcel(Parcel out) { |
| 1306 | out.writeInt(userTime); |
| 1307 | out.writeInt(systemTime); |
| 1308 | out.writeInt(appCpuUid1); |
| 1309 | out.writeInt(appCpuUTime1); |
| 1310 | out.writeInt(appCpuSTime1); |
| 1311 | out.writeInt(appCpuUid2); |
| 1312 | out.writeInt(appCpuUTime2); |
| 1313 | out.writeInt(appCpuSTime2); |
| 1314 | out.writeInt(appCpuUid3); |
| 1315 | out.writeInt(appCpuUTime3); |
| 1316 | out.writeInt(appCpuSTime3); |
| 1317 | out.writeInt(statUserTime); |
| 1318 | out.writeInt(statSystemTime); |
| 1319 | out.writeInt(statIOWaitTime); |
| 1320 | out.writeInt(statIrqTime); |
| 1321 | out.writeInt(statSoftIrqTime); |
| 1322 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1323 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1324 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | public void readFromParcel(Parcel in) { |
| 1328 | userTime = in.readInt(); |
| 1329 | systemTime = in.readInt(); |
| 1330 | appCpuUid1 = in.readInt(); |
| 1331 | appCpuUTime1 = in.readInt(); |
| 1332 | appCpuSTime1 = in.readInt(); |
| 1333 | appCpuUid2 = in.readInt(); |
| 1334 | appCpuUTime2 = in.readInt(); |
| 1335 | appCpuSTime2 = in.readInt(); |
| 1336 | appCpuUid3 = in.readInt(); |
| 1337 | appCpuUTime3 = in.readInt(); |
| 1338 | appCpuSTime3 = in.readInt(); |
| 1339 | statUserTime = in.readInt(); |
| 1340 | statSystemTime = in.readInt(); |
| 1341 | statIOWaitTime = in.readInt(); |
| 1342 | statIrqTime = in.readInt(); |
| 1343 | statSoftIrqTime = in.readInt(); |
| 1344 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1345 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1346 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1350 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1351 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1352 | |
| 1353 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1354 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1355 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1356 | 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] | 1357 | public static final byte CMD_NULL = -1; |
| 1358 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1359 | public static final byte CMD_CURRENT_TIME = 5; |
| 1360 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1361 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1362 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1363 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1364 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1365 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1366 | /** |
| 1367 | * Return whether the command code is a delta data update. |
| 1368 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1369 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1370 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1373 | public byte batteryLevel; |
| 1374 | public byte batteryStatus; |
| 1375 | public byte batteryHealth; |
| 1376 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1377 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1378 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1379 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1380 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1381 | // The charge of the battery in micro-Ampere-hours. |
| 1382 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1383 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1384 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1385 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1386 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1387 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1388 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1389 | 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] | 1390 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1391 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1392 | 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] | 1393 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1394 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1395 | 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] | 1396 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1397 | // These states always appear directly in the first int token |
| 1398 | // of a delta change; they should be ones that change relatively |
| 1399 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1400 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1401 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1402 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1403 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1404 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1405 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1406 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1407 | // Do not use, this is used for coulomb delta count. |
| 1408 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1409 | // These are on the lower bits used for the command; if they change |
| 1410 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1411 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1412 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1413 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1414 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1415 | 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] | 1416 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1417 | // empty slot |
| 1418 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1419 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1420 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1421 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1422 | |
| 1423 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1424 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1425 | public int states; |
| 1426 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1427 | // Constants from WIFI_SUPPL_STATE_* |
| 1428 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1429 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1430 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1431 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1432 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1433 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1434 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1435 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1436 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1437 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1438 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1439 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1440 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1441 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1442 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1443 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1444 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1445 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1446 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1447 | |
| 1448 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1449 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1450 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1451 | |
| 1452 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1453 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1454 | public int states2; |
| 1455 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1456 | // The wake lock that was acquired at this point. |
| 1457 | public HistoryTag wakelockTag; |
| 1458 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1459 | // Kernel wakeup reason at this point. |
| 1460 | public HistoryTag wakeReasonTag; |
| 1461 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1462 | // Non-null when there is more detailed information at this step. |
| 1463 | public HistoryStepDetails stepDetails; |
| 1464 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1465 | public static final int EVENT_FLAG_START = 0x8000; |
| 1466 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1467 | |
| 1468 | // No event in this item. |
| 1469 | public static final int EVENT_NONE = 0x0000; |
| 1470 | // Event is about a process that is running. |
| 1471 | public static final int EVENT_PROC = 0x0001; |
| 1472 | // Event is about an application package that is in the foreground. |
| 1473 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1474 | // Event is about an application package that is at the top of the screen. |
| 1475 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1476 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1477 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1478 | // Events for all additional wake locks aquired/release within a wake block. |
| 1479 | // These are not generated by default. |
| 1480 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1481 | // Event is about an application executing a scheduled job. |
| 1482 | public static final int EVENT_JOB = 0x0006; |
| 1483 | // Events for users running. |
| 1484 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1485 | // Events for foreground user. |
| 1486 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1487 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1488 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1489 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1490 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1491 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1492 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1493 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1494 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1495 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1496 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1497 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1498 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1499 | // 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] | 1500 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1501 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1502 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1503 | // Event for a package being on the temporary whitelist. |
| 1504 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1505 | // Event for the screen waking up. |
| 1506 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1507 | // Event for the UID that woke up the application processor. |
| 1508 | // Used for wakeups coming from WiFi, modem, etc. |
| 1509 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1510 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1511 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1512 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1513 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1514 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1515 | // Mask to extract out only the type part of the event. |
| 1516 | 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] | 1517 | |
| 1518 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1519 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1520 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1521 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1522 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1523 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1524 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1525 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1526 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1527 | 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] | 1528 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1529 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1530 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1531 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1532 | public static final int EVENT_USER_FOREGROUND_START = |
| 1533 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1534 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1535 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1536 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1537 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1538 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1539 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1540 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1541 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1542 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1543 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1544 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1545 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1546 | |
| 1547 | // For CMD_EVENT. |
| 1548 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1549 | public HistoryTag eventTag; |
| 1550 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1551 | // 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] | 1552 | public long currentTime; |
| 1553 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1554 | // Meta-data when reading. |
| 1555 | public int numReadInts; |
| 1556 | |
| 1557 | // Pre-allocated objects. |
| 1558 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1559 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1560 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1561 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1562 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1563 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1564 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1565 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1566 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1567 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1568 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1569 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1570 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1571 | public int describeContents() { |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | public void writeToParcel(Parcel dest, int flags) { |
| 1576 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1577 | int bat = (((int)cmd)&0xff) |
| 1578 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1579 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1580 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1581 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1582 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1583 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1584 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1585 | dest.writeInt(bat); |
| 1586 | bat = (((int)batteryTemperature)&0xffff) |
| 1587 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1588 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1589 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1590 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1591 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1592 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1593 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1594 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1595 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1596 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1597 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1598 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1599 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1600 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1601 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1602 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1603 | dest.writeLong(currentTime); |
| 1604 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1605 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1606 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1607 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1608 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1609 | int bat = src.readInt(); |
| 1610 | cmd = (byte)(bat&0xff); |
| 1611 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1612 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1613 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1614 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1615 | int bat2 = src.readInt(); |
| 1616 | batteryTemperature = (short)(bat2&0xffff); |
| 1617 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1618 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1619 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1620 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1621 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1622 | wakelockTag = localWakelockTag; |
| 1623 | wakelockTag.readFromParcel(src); |
| 1624 | } else { |
| 1625 | wakelockTag = null; |
| 1626 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1627 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1628 | wakeReasonTag = localWakeReasonTag; |
| 1629 | wakeReasonTag.readFromParcel(src); |
| 1630 | } else { |
| 1631 | wakeReasonTag = null; |
| 1632 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1633 | if ((bat&0x40000000) != 0) { |
| 1634 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1635 | eventTag = localEventTag; |
| 1636 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1637 | } else { |
| 1638 | eventCode = EVENT_NONE; |
| 1639 | eventTag = null; |
| 1640 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1641 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1642 | currentTime = src.readLong(); |
| 1643 | } else { |
| 1644 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1645 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1646 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1649 | public void clear() { |
| 1650 | time = 0; |
| 1651 | cmd = CMD_NULL; |
| 1652 | batteryLevel = 0; |
| 1653 | batteryStatus = 0; |
| 1654 | batteryHealth = 0; |
| 1655 | batteryPlugType = 0; |
| 1656 | batteryTemperature = 0; |
| 1657 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1658 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1659 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1660 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1661 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1662 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1663 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1664 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1665 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1666 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1667 | public void setTo(HistoryItem o) { |
| 1668 | time = o.time; |
| 1669 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1670 | setToCommon(o); |
| 1671 | } |
| 1672 | |
| 1673 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1674 | this.time = time; |
| 1675 | this.cmd = cmd; |
| 1676 | setToCommon(o); |
| 1677 | } |
| 1678 | |
| 1679 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1680 | batteryLevel = o.batteryLevel; |
| 1681 | batteryStatus = o.batteryStatus; |
| 1682 | batteryHealth = o.batteryHealth; |
| 1683 | batteryPlugType = o.batteryPlugType; |
| 1684 | batteryTemperature = o.batteryTemperature; |
| 1685 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1686 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1687 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1688 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1689 | if (o.wakelockTag != null) { |
| 1690 | wakelockTag = localWakelockTag; |
| 1691 | wakelockTag.setTo(o.wakelockTag); |
| 1692 | } else { |
| 1693 | wakelockTag = null; |
| 1694 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1695 | if (o.wakeReasonTag != null) { |
| 1696 | wakeReasonTag = localWakeReasonTag; |
| 1697 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1698 | } else { |
| 1699 | wakeReasonTag = null; |
| 1700 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1701 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1702 | if (o.eventTag != null) { |
| 1703 | eventTag = localEventTag; |
| 1704 | eventTag.setTo(o.eventTag); |
| 1705 | } else { |
| 1706 | eventTag = null; |
| 1707 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1708 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1711 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1712 | return batteryLevel == o.batteryLevel |
| 1713 | && batteryStatus == o.batteryStatus |
| 1714 | && batteryHealth == o.batteryHealth |
| 1715 | && batteryPlugType == o.batteryPlugType |
| 1716 | && batteryTemperature == o.batteryTemperature |
| 1717 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1718 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1719 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1720 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1721 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1722 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1723 | |
| 1724 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1725 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1728 | if (wakelockTag != o.wakelockTag) { |
| 1729 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1730 | return false; |
| 1731 | } |
| 1732 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1733 | return false; |
| 1734 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1735 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1736 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1737 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1738 | return false; |
| 1739 | } |
| 1740 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1741 | return false; |
| 1742 | } |
| 1743 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1744 | if (eventTag != o.eventTag) { |
| 1745 | if (eventTag == null || o.eventTag == null) { |
| 1746 | return false; |
| 1747 | } |
| 1748 | if (!eventTag.equals(o.eventTag)) { |
| 1749 | return false; |
| 1750 | } |
| 1751 | } |
| 1752 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1753 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1754 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1755 | |
| 1756 | public final static class HistoryEventTracker { |
| 1757 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1758 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1759 | |
| 1760 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1761 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1762 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1763 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1764 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1765 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1766 | mActiveEvents[idx] = active; |
| 1767 | } |
| 1768 | SparseIntArray uids = active.get(name); |
| 1769 | if (uids == null) { |
| 1770 | uids = new SparseIntArray(); |
| 1771 | active.put(name, uids); |
| 1772 | } |
| 1773 | if (uids.indexOfKey(uid) >= 0) { |
| 1774 | // Already set, nothing to do! |
| 1775 | return false; |
| 1776 | } |
| 1777 | uids.put(uid, poolIdx); |
| 1778 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1779 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1780 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1781 | if (active == null) { |
| 1782 | // not currently active, nothing to do. |
| 1783 | return false; |
| 1784 | } |
| 1785 | SparseIntArray uids = active.get(name); |
| 1786 | if (uids == null) { |
| 1787 | // not currently active, nothing to do. |
| 1788 | return false; |
| 1789 | } |
| 1790 | idx = uids.indexOfKey(uid); |
| 1791 | if (idx < 0) { |
| 1792 | // not currently active, nothing to do. |
| 1793 | return false; |
| 1794 | } |
| 1795 | uids.removeAt(idx); |
| 1796 | if (uids.size() <= 0) { |
| 1797 | active.remove(name); |
| 1798 | } |
| 1799 | } |
| 1800 | return true; |
| 1801 | } |
| 1802 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1803 | public void removeEvents(int code) { |
| 1804 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1805 | mActiveEvents[idx] = null; |
| 1806 | } |
| 1807 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1808 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1809 | return mActiveEvents[code]; |
| 1810 | } |
| 1811 | } |
| 1812 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1813 | public static final class BitDescription { |
| 1814 | public final int mask; |
| 1815 | public final int shift; |
| 1816 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1817 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1818 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1819 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1820 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1821 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1822 | this.mask = mask; |
| 1823 | this.shift = -1; |
| 1824 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1825 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1826 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1827 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1828 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1829 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1830 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1831 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1832 | this.mask = mask; |
| 1833 | this.shift = shift; |
| 1834 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1835 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1836 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1837 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1838 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1839 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1840 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1841 | /** |
| 1842 | * Don't allow any more batching in to the current history event. This |
| 1843 | * is called when printing partial histories, so to ensure that the next |
| 1844 | * history event will go in to a new batch after what was printed in the |
| 1845 | * last partial history. |
| 1846 | */ |
| 1847 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1848 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1849 | public abstract int getHistoryTotalSize(); |
| 1850 | |
| 1851 | public abstract int getHistoryUsedSize(); |
| 1852 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1853 | public abstract boolean startIteratingHistoryLocked(); |
| 1854 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1855 | public abstract int getHistoryStringPoolSize(); |
| 1856 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1857 | public abstract int getHistoryStringPoolBytes(); |
| 1858 | |
| 1859 | public abstract String getHistoryTagPoolString(int index); |
| 1860 | |
| 1861 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1862 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1863 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1864 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1865 | public abstract void finishIteratingHistoryLocked(); |
| 1866 | |
| 1867 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1868 | |
| 1869 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1870 | |
| 1871 | public abstract void finishIteratingOldHistoryLocked(); |
| 1872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1874 | * Return the base time offset for the battery history. |
| 1875 | */ |
| 1876 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1877 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1878 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | * Returns the number of times the device has been started. |
| 1880 | */ |
| 1881 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1884 | * 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] | 1885 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1886 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | * {@hide} |
| 1888 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1889 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1890 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1891 | /** |
| 1892 | * Returns the number of times the screen was turned on. |
| 1893 | * |
| 1894 | * {@hide} |
| 1895 | */ |
| 1896 | public abstract int getScreenOnCount(int which); |
| 1897 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1898 | /** |
| 1899 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1900 | * running on battery. |
| 1901 | * |
| 1902 | * {@hide} |
| 1903 | */ |
| 1904 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1905 | |
| 1906 | /** |
| 1907 | * Returns the number of times the screen was turned dozing. |
| 1908 | * |
| 1909 | * {@hide} |
| 1910 | */ |
| 1911 | public abstract int getScreenDozeCount(int which); |
| 1912 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1913 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1914 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1915 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1916 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1917 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1918 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1919 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1920 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1921 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1922 | "dark", "dim", "medium", "light", "bright" |
| 1923 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1924 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1925 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1926 | "0", "1", "2", "3", "4" |
| 1927 | }; |
| 1928 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1929 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1930 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1931 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1932 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1933 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1934 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1935 | * {@hide} |
| 1936 | */ |
| 1937 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1938 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 1941 | * Returns the {@link Timer} object that tracks the given screen brightness. |
| 1942 | * |
| 1943 | * {@hide} |
| 1944 | */ |
| 1945 | public abstract Timer getScreenBrightnessTimer(int brightnessBin); |
| 1946 | |
| 1947 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1948 | * 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] | 1949 | * running on battery. |
| 1950 | * |
| 1951 | * {@hide} |
| 1952 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1953 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1954 | |
| 1955 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1956 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1957 | * |
| 1958 | * {@hide} |
| 1959 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1960 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1961 | |
| 1962 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1963 | * Constant for device idle mode: not active. |
| 1964 | */ |
| 1965 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1966 | |
| 1967 | /** |
| 1968 | * Constant for device idle mode: active in lightweight mode. |
| 1969 | */ |
| 1970 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1971 | |
| 1972 | /** |
| 1973 | * Constant for device idle mode: active in full mode. |
| 1974 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1975 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1976 | |
| 1977 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1978 | * Returns the time in microseconds that device has been in idle mode while |
| 1979 | * running on battery. |
| 1980 | * |
| 1981 | * {@hide} |
| 1982 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1983 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1984 | |
| 1985 | /** |
| 1986 | * Returns the number of times that the devie has gone in to idle mode. |
| 1987 | * |
| 1988 | * {@hide} |
| 1989 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1990 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1991 | |
| 1992 | /** |
| 1993 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1994 | * mode, not in idle maintenance etc). |
| 1995 | */ |
| 1996 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1997 | |
| 1998 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1999 | * 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] | 2000 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2001 | * counts all of the time that we consider the device to be idle, whether or not |
| 2002 | * it is currently in the actual device idle mode. |
| 2003 | * |
| 2004 | * {@hide} |
| 2005 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2006 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2007 | |
| 2008 | /** |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 2009 | * Returns the number of times that the device has started idling. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2010 | * |
| 2011 | * {@hide} |
| 2012 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2013 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2014 | |
| 2015 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2016 | * Returns the number of times that connectivity state changed. |
| 2017 | * |
| 2018 | * {@hide} |
| 2019 | */ |
| 2020 | public abstract int getNumConnectivityChange(int which); |
| 2021 | |
| 2022 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2023 | * 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] | 2024 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2025 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | * {@hide} |
| 2027 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2028 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2029 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2030 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2031 | * Returns the number of times a phone call was activated. |
| 2032 | * |
| 2033 | * {@hide} |
| 2034 | */ |
| 2035 | public abstract int getPhoneOnCount(int which); |
| 2036 | |
| 2037 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2038 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2039 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2040 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2041 | * {@hide} |
| 2042 | */ |
| 2043 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2044 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2045 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2046 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2047 | * Returns the time in microseconds that the phone has been trying to |
| 2048 | * acquire a signal. |
| 2049 | * |
| 2050 | * {@hide} |
| 2051 | */ |
| 2052 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2053 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2054 | |
| 2055 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2056 | * Returns the {@link Timer} object that tracks how much the phone has been trying to |
| 2057 | * acquire a signal. |
| 2058 | * |
| 2059 | * {@hide} |
| 2060 | */ |
| 2061 | public abstract Timer getPhoneSignalScanningTimer(); |
| 2062 | |
| 2063 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2064 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2065 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2066 | * {@hide} |
| 2067 | */ |
| 2068 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2069 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2070 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2071 | * Return the {@link Timer} object used to track the given signal strength's duration and |
| 2072 | * counts. |
| 2073 | */ |
| 2074 | protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin); |
| 2075 | |
| 2076 | /** |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2077 | * Returns the time in microseconds that the mobile network has been active |
| 2078 | * (in a high power state). |
| 2079 | * |
| 2080 | * {@hide} |
| 2081 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2082 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2083 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2084 | /** |
| 2085 | * Returns the number of times that the mobile network has transitioned to the |
| 2086 | * active state. |
| 2087 | * |
| 2088 | * {@hide} |
| 2089 | */ |
| 2090 | public abstract int getMobileRadioActiveCount(int which); |
| 2091 | |
| 2092 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2093 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2094 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2095 | * from the radio. |
| 2096 | * |
| 2097 | * {@hide} |
| 2098 | */ |
| 2099 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2100 | |
| 2101 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2102 | * Returns the time in microseconds that the mobile network has been active |
| 2103 | * (in a high power state) but not being able to blame on an app. |
| 2104 | * |
| 2105 | * {@hide} |
| 2106 | */ |
| 2107 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2108 | |
| 2109 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2110 | * 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] | 2111 | * |
| 2112 | * {@hide} |
| 2113 | */ |
| 2114 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2115 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2116 | public static final int DATA_CONNECTION_NONE = 0; |
| 2117 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2118 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2119 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2120 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2121 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2122 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2123 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2124 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2125 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2126 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2127 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2128 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2129 | public static final int DATA_CONNECTION_LTE = 13; |
| 2130 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2131 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2132 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2133 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2134 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2135 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2136 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2137 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2138 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2139 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2140 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2141 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2142 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2143 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2144 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2145 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2146 | * {@hide} |
| 2147 | */ |
| 2148 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2149 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 data |
| 2153 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2154 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2155 | * {@hide} |
| 2156 | */ |
| 2157 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2158 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2159 | /** |
| 2160 | * Returns the {@link Timer} object that tracks the phone's data connection type stats. |
| 2161 | */ |
| 2162 | public abstract Timer getPhoneDataConnectionTimer(int dataType); |
| 2163 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2164 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2165 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2166 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2167 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2168 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2169 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2170 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2171 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2172 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2173 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2174 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2175 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2176 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2177 | |
| 2178 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2179 | |
| 2180 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2181 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2182 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2183 | "group-handshake", "completed", "dormant", "uninit" |
| 2184 | }; |
| 2185 | |
| 2186 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2187 | "inv", "dsc", "dis", "inact", "scan", |
| 2188 | "auth", "ascing", "asced", "4-way", |
| 2189 | "group", "compl", "dorm", "uninit" |
| 2190 | }; |
| 2191 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2192 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2193 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2194 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2195 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2196 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2197 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2198 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2199 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2200 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2201 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2202 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2203 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2204 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2205 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2206 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2207 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2208 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2209 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2210 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2211 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2212 | new String[] {"in", "out", "emergency", "off"}, |
| 2213 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2214 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2215 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2216 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2217 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2218 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2219 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2220 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2221 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2222 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2223 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2224 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2225 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2226 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2227 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2228 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2229 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2230 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2231 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2232 | new String[] { "off", "light", "full", "???" }, |
| 2233 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2234 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2235 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2236 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2237 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2238 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2239 | new String[] { "0", "1", "2", "3", "4" }, |
| 2240 | new String[] { "0", "1", "2", "3", "4" }), |
| 2241 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2242 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2243 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2244 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2245 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2246 | }; |
| 2247 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2248 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2249 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2250 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2251 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2252 | }; |
| 2253 | |
| 2254 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2255 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2256 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2257 | "Esw", "Ewa", "Elw", "Eec" |
| 2258 | }; |
| 2259 | |
| 2260 | @FunctionalInterface |
| 2261 | public interface IntToString { |
| 2262 | String applyAsString(int val); |
| 2263 | } |
| 2264 | |
| 2265 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2266 | private static final IntToString sIntToString = Integer::toString; |
| 2267 | |
| 2268 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2269 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2270 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2271 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2272 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2273 | }; |
| 2274 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2275 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2276 | * 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] | 2277 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2278 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2279 | * {@hide} |
| 2280 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2281 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2282 | |
| 2283 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2284 | * 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] | 2285 | * been in the running state while the device was running on battery. |
| 2286 | * |
| 2287 | * {@hide} |
| 2288 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2289 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2290 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2291 | public static final int WIFI_STATE_OFF = 0; |
| 2292 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2293 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2294 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2295 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2296 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2297 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2298 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2299 | |
| 2300 | static final String[] WIFI_STATE_NAMES = { |
| 2301 | "off", "scanning", "no_net", "disconn", |
| 2302 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2303 | }; |
| 2304 | |
| 2305 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2306 | |
| 2307 | /** |
| 2308 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2309 | * |
| 2310 | * {@hide} |
| 2311 | */ |
| 2312 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2313 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2314 | |
| 2315 | /** |
| 2316 | * Returns the number of times that WiFi has entered the given state. |
| 2317 | * |
| 2318 | * {@hide} |
| 2319 | */ |
| 2320 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2321 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2322 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2323 | * Returns the {@link Timer} object that tracks the given WiFi state. |
| 2324 | * |
| 2325 | * {@hide} |
| 2326 | */ |
| 2327 | public abstract Timer getWifiStateTimer(int wifiState); |
| 2328 | |
| 2329 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2330 | * Returns the time in microseconds that the wifi supplicant has been |
| 2331 | * in a given state. |
| 2332 | * |
| 2333 | * {@hide} |
| 2334 | */ |
| 2335 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2336 | |
| 2337 | /** |
| 2338 | * Returns the number of times that the wifi supplicant has transitioned |
| 2339 | * to a given state. |
| 2340 | * |
| 2341 | * {@hide} |
| 2342 | */ |
| 2343 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2344 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2345 | /** |
| 2346 | * Returns the {@link Timer} object that tracks the given wifi supplicant state. |
| 2347 | * |
| 2348 | * {@hide} |
| 2349 | */ |
| 2350 | public abstract Timer getWifiSupplStateTimer(int state); |
| 2351 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2352 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2353 | |
| 2354 | /** |
| 2355 | * Returns the time in microseconds that WIFI has been running with |
| 2356 | * the given signal strength. |
| 2357 | * |
| 2358 | * {@hide} |
| 2359 | */ |
| 2360 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2361 | long elapsedRealtimeUs, int which); |
| 2362 | |
| 2363 | /** |
| 2364 | * Returns the number of times WIFI has entered the given signal strength. |
| 2365 | * |
| 2366 | * {@hide} |
| 2367 | */ |
| 2368 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2369 | |
| 2370 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2371 | * Returns the {@link Timer} object that tracks the given WIFI signal strength. |
| 2372 | * |
| 2373 | * {@hide} |
| 2374 | */ |
| 2375 | public abstract Timer getWifiSignalStrengthTimer(int strengthBin); |
| 2376 | |
| 2377 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2378 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2379 | * running on battery. |
| 2380 | * |
| 2381 | * {@hide} |
| 2382 | */ |
| 2383 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2384 | |
| 2385 | /** |
| 2386 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2387 | * running on battery. |
| 2388 | * |
| 2389 | * {@hide} |
| 2390 | */ |
| 2391 | public abstract long getFlashlightOnCount(int which); |
| 2392 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2393 | /** |
| 2394 | * Returns the time in microseconds that the camera has been on while the device was |
| 2395 | * running on battery. |
| 2396 | * |
| 2397 | * {@hide} |
| 2398 | */ |
| 2399 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2400 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2401 | /** |
| 2402 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2403 | * on battery. |
| 2404 | * |
| 2405 | * {@hide} |
| 2406 | */ |
| 2407 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2408 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2409 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2410 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2411 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2412 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2413 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2414 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2415 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2416 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2417 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2418 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2419 | 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] | 2420 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2421 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2422 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2423 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2424 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2425 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2426 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2427 | * actual power data. |
| 2428 | */ |
| 2429 | public abstract boolean hasWifiActivityReporting(); |
| 2430 | |
| 2431 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2432 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2433 | * in various radio controller states, such as transmit, receive, and idle. |
| 2434 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2435 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2436 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2437 | |
| 2438 | /** |
| 2439 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2440 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2441 | * actual power data. |
| 2442 | */ |
| 2443 | public abstract boolean hasBluetoothActivityReporting(); |
| 2444 | |
| 2445 | /** |
| 2446 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2447 | * in various radio controller states, such as transmit, receive, and idle. |
| 2448 | * @return non-null {@link ControllerActivityCounter} |
| 2449 | */ |
| 2450 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2451 | |
| 2452 | /** |
| 2453 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2454 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2455 | * actual power data. |
| 2456 | */ |
| 2457 | public abstract boolean hasModemActivityReporting(); |
| 2458 | |
| 2459 | /** |
| 2460 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2461 | * in various radio controller states, such as transmit, receive, and idle. |
| 2462 | * @return non-null {@link ControllerActivityCounter} |
| 2463 | */ |
| 2464 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2465 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2466 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2467 | * Return the wall clock time when battery stats data collection started. |
| 2468 | */ |
| 2469 | public abstract long getStartClockTime(); |
| 2470 | |
| 2471 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2472 | * Return platform version tag that we were running in when the battery stats started. |
| 2473 | */ |
| 2474 | public abstract String getStartPlatformVersion(); |
| 2475 | |
| 2476 | /** |
| 2477 | * Return platform version tag that we were running in when the battery stats ended. |
| 2478 | */ |
| 2479 | public abstract String getEndPlatformVersion(); |
| 2480 | |
| 2481 | /** |
| 2482 | * Return the internal version code of the parcelled format. |
| 2483 | */ |
| 2484 | public abstract int getParcelVersion(); |
| 2485 | |
| 2486 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | * Return whether we are currently running on battery. |
| 2488 | */ |
| 2489 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | /** |
| 2492 | * Returns a SparseArray containing the statistics for each uid. |
| 2493 | */ |
| 2494 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2495 | |
| 2496 | /** |
| 2497 | * Returns the current battery uptime in microseconds. |
| 2498 | * |
| 2499 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2500 | */ |
| 2501 | public abstract long getBatteryUptime(long curTime); |
| 2502 | |
| 2503 | /** |
| 2504 | * Returns the current battery realtime in microseconds. |
| 2505 | * |
| 2506 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2507 | */ |
| 2508 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2509 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2510 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2511 | * 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] | 2512 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2513 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2514 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2515 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2516 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2517 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2518 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2519 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2520 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | |
| 2522 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2523 | * Get the amount the battery has discharged since the stats were |
| 2524 | * last reset after charging, as a lower-end approximation. |
| 2525 | */ |
| 2526 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2527 | |
| 2528 | /** |
| 2529 | * Get the amount the battery has discharged since the stats were |
| 2530 | * last reset after charging, as an upper-end approximation. |
| 2531 | */ |
| 2532 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2533 | |
| 2534 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2535 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2536 | */ |
| 2537 | public abstract int getDischargeAmount(int which); |
| 2538 | |
| 2539 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2540 | * Get the amount the battery has discharged while the screen was on, |
| 2541 | * since the last time power was unplugged. |
| 2542 | */ |
| 2543 | public abstract int getDischargeAmountScreenOn(); |
| 2544 | |
| 2545 | /** |
| 2546 | * Get the amount the battery has discharged while the screen was on, |
| 2547 | * since the last time the device was charged. |
| 2548 | */ |
| 2549 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2550 | |
| 2551 | /** |
| 2552 | * Get the amount the battery has discharged while the screen was off, |
| 2553 | * since the last time power was unplugged. |
| 2554 | */ |
| 2555 | public abstract int getDischargeAmountScreenOff(); |
| 2556 | |
| 2557 | /** |
| 2558 | * Get the amount the battery has discharged while the screen was off, |
| 2559 | * since the last time the device was charged. |
| 2560 | */ |
| 2561 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2562 | |
| 2563 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2564 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2565 | * since the last time power was unplugged. |
| 2566 | */ |
| 2567 | public abstract int getDischargeAmountScreenDoze(); |
| 2568 | |
| 2569 | /** |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2570 | * Get the amount the battery has discharged while the screen was dozing, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2571 | * since the last time the device was charged. |
| 2572 | */ |
| 2573 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2574 | |
| 2575 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | * Returns the total, last, or current battery uptime in microseconds. |
| 2577 | * |
| 2578 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2579 | * @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] | 2580 | */ |
| 2581 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2582 | |
| 2583 | /** |
| 2584 | * Returns the total, last, or current battery realtime in microseconds. |
| 2585 | * |
| 2586 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2587 | * @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] | 2588 | */ |
| 2589 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2590 | |
| 2591 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2592 | * 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] | 2593 | * |
| 2594 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2595 | * @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] | 2596 | */ |
| 2597 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2598 | |
| 2599 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2600 | * 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] | 2601 | * |
| 2602 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2603 | * @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] | 2604 | */ |
| 2605 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2606 | |
| 2607 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | * Returns the total, last, or current uptime in microseconds. |
| 2609 | * |
| 2610 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2611 | * @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] | 2612 | */ |
| 2613 | public abstract long computeUptime(long curTime, int which); |
| 2614 | |
| 2615 | /** |
| 2616 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2617 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2619 | * @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] | 2620 | */ |
| 2621 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2622 | |
| 2623 | /** |
| 2624 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2625 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2626 | * enough current data to make a decision, or the battery is currently |
| 2627 | * charging. |
| 2628 | * |
| 2629 | * @param curTime The current elepsed realtime in microseconds. |
| 2630 | */ |
| 2631 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2632 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2633 | // The part of a step duration that is the actual time. |
| 2634 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2635 | |
| 2636 | // Bits in a step duration that are the new battery level we are at. |
| 2637 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2638 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2639 | |
| 2640 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2641 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2642 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2643 | |
| 2644 | // Bits in a step duration that indicate which modes changed during that step. |
| 2645 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2646 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2647 | |
| 2648 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2649 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2650 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2651 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2652 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2653 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2654 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2655 | // Step duration mode: power save is on. |
| 2656 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2657 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2658 | // Step duration mode: device is currently in idle mode. |
| 2659 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2660 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2661 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2662 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2663 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2664 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2665 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2666 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2667 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2668 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2669 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2670 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2671 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2672 | }; |
| 2673 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2674 | (Display.STATE_OFF-1), |
| 2675 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2676 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2677 | (Display.STATE_ON-1), |
| 2678 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2679 | (Display.STATE_DOZE-1), |
| 2680 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2681 | (Display.STATE_DOZE_SUSPEND-1), |
| 2682 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2683 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2684 | }; |
| 2685 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2686 | "screen off", |
| 2687 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2688 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2689 | "screen on", |
| 2690 | "screen on power save", |
| 2691 | "screen doze", |
| 2692 | "screen doze power save", |
| 2693 | "screen doze-suspend", |
| 2694 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2695 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2696 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2697 | |
| 2698 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2699 | * 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] | 2700 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2701 | * a coulomb counter. |
| 2702 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2703 | public abstract long getUahDischargeScreenOff(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2704 | |
| 2705 | /** |
| 2706 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2707 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2708 | * a coulomb counter. |
| 2709 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2710 | public abstract long getUahDischargeScreenDoze(int which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2711 | |
| 2712 | /** |
| 2713 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2714 | * non-zero only if the device's battery has a coulomb counter. |
| 2715 | */ |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 2716 | public abstract long getUahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2717 | |
| 2718 | /** |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 2719 | * @return the amount of battery discharge while the device is in light idle mode, measured in |
| 2720 | * micro-Ampere-hours. |
| 2721 | */ |
| 2722 | public abstract long getUahDischargeLightDoze(int which); |
| 2723 | |
| 2724 | /** |
| 2725 | * @return the amount of battery discharge while the device is in deep idle mode, measured in |
| 2726 | * micro-Ampere-hours. |
| 2727 | */ |
| 2728 | public abstract long getUahDischargeDeepDoze(int which); |
| 2729 | |
| 2730 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2731 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2732 | * declared by the PowerProfile. |
| 2733 | * @return The estimated battery capacity in mAh. |
| 2734 | */ |
| 2735 | public abstract int getEstimatedBatteryCapacity(); |
| 2736 | |
| 2737 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2738 | * @return The minimum learned battery capacity in uAh. |
| 2739 | */ |
| 2740 | public abstract int getMinLearnedBatteryCapacity(); |
| 2741 | |
| 2742 | /** |
| 2743 | * @return The maximum learned battery capacity in uAh. |
| 2744 | */ |
| 2745 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2746 | |
| 2747 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2748 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2749 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2750 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2751 | |
| 2752 | /** |
| 2753 | * Return the array of daily discharge step durations. |
| 2754 | */ |
| 2755 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2756 | |
| 2757 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2758 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2759 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2760 | * enough current data to make a decision, or the battery is currently |
| 2761 | * discharging. |
| 2762 | * |
| 2763 | * @param curTime The current elepsed realtime in microseconds. |
| 2764 | */ |
| 2765 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2766 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2767 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2768 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2769 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2770 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2771 | |
| 2772 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2773 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2774 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2775 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2776 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2777 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2778 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2779 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2780 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2781 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2783 | /** |
| 2784 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2785 | */ |
| 2786 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2787 | /** |
| 2788 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2789 | */ |
| 2790 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2791 | |
| 2792 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2793 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2794 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2795 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2796 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2797 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | long days = seconds / (60 * 60 * 24); |
| 2799 | if (days != 0) { |
| 2800 | out.append(days); |
| 2801 | out.append("d "); |
| 2802 | } |
| 2803 | long used = days * 60 * 60 * 24; |
| 2804 | |
| 2805 | long hours = (seconds - used) / (60 * 60); |
| 2806 | if (hours != 0 || used != 0) { |
| 2807 | out.append(hours); |
| 2808 | out.append("h "); |
| 2809 | } |
| 2810 | used += hours * 60 * 60; |
| 2811 | |
| 2812 | long mins = (seconds-used) / 60; |
| 2813 | if (mins != 0 || used != 0) { |
| 2814 | out.append(mins); |
| 2815 | out.append("m "); |
| 2816 | } |
| 2817 | used += mins * 60; |
| 2818 | |
| 2819 | if (seconds != 0 || used != 0) { |
| 2820 | out.append(seconds-used); |
| 2821 | out.append("s "); |
| 2822 | } |
| 2823 | } |
| 2824 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2825 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2827 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2828 | sb.append(time - (sec * 1000)); |
| 2829 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2830 | } |
| 2831 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2832 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2833 | long sec = time / 1000; |
| 2834 | formatTimeRaw(sb, sec); |
| 2835 | sb.append(time - (sec * 1000)); |
| 2836 | sb.append("ms"); |
| 2837 | } |
| 2838 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2839 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2841 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | } |
| 2843 | float perc = ((float)num) / ((float)den) * 100; |
| 2844 | mFormatBuilder.setLength(0); |
| 2845 | mFormatter.format("%.1f%%", perc); |
| 2846 | return mFormatBuilder.toString(); |
| 2847 | } |
| 2848 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2849 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2850 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2851 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2852 | if (bytes < BYTES_PER_KB) { |
| 2853 | return bytes + "B"; |
| 2854 | } else if (bytes < BYTES_PER_MB) { |
| 2855 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2856 | return mFormatBuilder.toString(); |
| 2857 | } else if (bytes < BYTES_PER_GB){ |
| 2858 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2859 | return mFormatBuilder.toString(); |
| 2860 | } else { |
| 2861 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2862 | return mFormatBuilder.toString(); |
| 2863 | } |
| 2864 | } |
| 2865 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 2866 | private static long roundUsToMs(long timeUs) { |
| 2867 | return (timeUs + 500) / 1000; |
| 2868 | } |
| 2869 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2870 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2871 | if (timer != null) { |
| 2872 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2873 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2874 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2875 | return totalTimeMillis; |
| 2876 | } |
| 2877 | return 0; |
| 2878 | } |
| 2879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | /** |
| 2881 | * |
| 2882 | * @param sb a StringBuilder object. |
| 2883 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2884 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2886 | * @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] | 2887 | * @param linePrefix a String to be prepended to each line of output. |
| 2888 | * @return the line prefix |
| 2889 | */ |
| 2890 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2891 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2894 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2895 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2896 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | if (totalTimeMillis != 0) { |
| 2898 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2899 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2900 | if (name != null) { |
| 2901 | sb.append(name); |
| 2902 | sb.append(' '); |
| 2903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | sb.append('('); |
| 2905 | sb.append(count); |
| 2906 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2907 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2908 | if (maxDurationMs >= 0) { |
| 2909 | sb.append(" max="); |
| 2910 | sb.append(maxDurationMs); |
| 2911 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2912 | // Put actual time if it is available and different from totalTimeMillis. |
| 2913 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2914 | if (totalDurMs > totalTimeMillis) { |
| 2915 | sb.append(" actual="); |
| 2916 | sb.append(totalDurMs); |
| 2917 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2918 | if (timer.isRunningLocked()) { |
| 2919 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2920 | if (currentMs >= 0) { |
| 2921 | sb.append(" (running for "); |
| 2922 | sb.append(currentMs); |
| 2923 | sb.append("ms)"); |
| 2924 | } else { |
| 2925 | sb.append(" (running)"); |
| 2926 | } |
| 2927 | } |
| 2928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | return ", "; |
| 2930 | } |
| 2931 | } |
| 2932 | return linePrefix; |
| 2933 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2934 | |
| 2935 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2936 | * 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] | 2937 | * |
| 2938 | * @param pw a PrintWriter object to print to. |
| 2939 | * @param sb a StringBuilder object. |
| 2940 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2941 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2942 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2943 | * @param prefix a String to be prepended to each line of output. |
| 2944 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2945 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2946 | */ |
| 2947 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2948 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2949 | if (timer != null) { |
| 2950 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2951 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2952 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2953 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2954 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2955 | sb.setLength(0); |
| 2956 | sb.append(prefix); |
| 2957 | sb.append(" "); |
| 2958 | sb.append(type); |
| 2959 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2960 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2961 | sb.append("realtime ("); |
| 2962 | sb.append(count); |
| 2963 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2964 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2965 | if (maxDurationMs >= 0) { |
| 2966 | sb.append(" max="); |
| 2967 | sb.append(maxDurationMs); |
| 2968 | } |
| 2969 | if (timer.isRunningLocked()) { |
| 2970 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2971 | if (currentMs >= 0) { |
| 2972 | sb.append(" (running for "); |
| 2973 | sb.append(currentMs); |
| 2974 | sb.append("ms)"); |
| 2975 | } else { |
| 2976 | sb.append(" (running)"); |
| 2977 | } |
| 2978 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2979 | pw.println(sb.toString()); |
| 2980 | return true; |
| 2981 | } |
| 2982 | } |
| 2983 | return false; |
| 2984 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | /** |
| 2987 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2988 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | * @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 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 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2997 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2998 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | long totalTimeMicros = 0; |
| 3000 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 3001 | long max = 0; |
| 3002 | long current = 0; |
| 3003 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3005 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3006 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3007 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 3008 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3009 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | } |
| 3011 | sb.append(linePrefix); |
| 3012 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 3013 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3014 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 3016 | sb.append(','); |
| 3017 | sb.append(current); |
| 3018 | sb.append(','); |
| 3019 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3020 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 3021 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 3022 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 3023 | if (name != null) { |
| 3024 | sb.append(','); |
| 3025 | sb.append(totalDuration); |
| 3026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | return ","; |
| 3028 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 3029 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3030 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 3031 | String type) { |
| 3032 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 3033 | pw.print(','); |
| 3034 | pw.print(uid); |
| 3035 | pw.print(','); |
| 3036 | pw.print(category); |
| 3037 | pw.print(','); |
| 3038 | pw.print(type); |
| 3039 | } |
| 3040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | /** |
| 3042 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3043 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3044 | * @param pw the PageWriter to dump log to |
| 3045 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3046 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3047 | * @param args type-dependent data arguments |
| 3048 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3049 | 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] | 3050 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3051 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3052 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3053 | pw.print(','); |
| 3054 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3056 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3058 | |
| 3059 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3060 | * Dump a given timer stat for terse checkin mode. |
| 3061 | * |
| 3062 | * @param pw the PageWriter to dump log to |
| 3063 | * @param uid the UID to log |
| 3064 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 3065 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 3066 | * @param timer a {@link Timer} to dump stats for |
| 3067 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 3068 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3069 | */ |
| 3070 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 3071 | Timer timer, long rawRealtime, int which) { |
| 3072 | if (timer != null) { |
| 3073 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3074 | final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which)); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3075 | final int count = timer.getCountLocked(which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3076 | if (totalTime != 0 || count != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3077 | dumpLine(pw, uid, category, type, totalTime, count); |
| 3078 | } |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3083 | * Dump a given timer stat to the proto stream. |
| 3084 | * |
| 3085 | * @param proto the ProtoOutputStream to log to |
| 3086 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 3087 | * @param timer a {@link Timer} to dump stats for |
| 3088 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3089 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3090 | */ |
| 3091 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3092 | Timer timer, long rawRealtimeUs, int which) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3093 | if (timer == null) { |
| 3094 | return; |
| 3095 | } |
| 3096 | // Convert from microseconds to milliseconds with rounding |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3097 | final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which)); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3098 | final int count = timer.getCountLocked(which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3099 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000); |
| 3100 | final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000); |
| 3101 | final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000); |
| 3102 | if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1 |
| 3103 | || totalDurationMs != -1) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3104 | final long token = proto.start(fieldId); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3105 | proto.write(TimerProto.DURATION_MS, timeMs); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3106 | proto.write(TimerProto.COUNT, count); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3107 | // These values will be -1 for timers that don't implement the functionality. |
| 3108 | if (maxDurationMs != -1) { |
| 3109 | proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs); |
| 3110 | } |
| 3111 | if (curDurationMs != -1) { |
| 3112 | proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs); |
| 3113 | } |
| 3114 | if (totalDurationMs != -1) { |
| 3115 | proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs); |
| 3116 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3117 | proto.end(token); |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3122 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3123 | */ |
| 3124 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3125 | if (counter == null) { |
| 3126 | return false; |
| 3127 | } |
| 3128 | |
| 3129 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3130 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3131 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3132 | return true; |
| 3133 | } |
| 3134 | |
| 3135 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3136 | if (c.getCountLocked(which) != 0) { |
| 3137 | return true; |
| 3138 | } |
| 3139 | } |
| 3140 | return false; |
| 3141 | } |
| 3142 | |
| 3143 | /** |
| 3144 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3145 | * The order of the arguments in the final check in line is: |
| 3146 | * |
| 3147 | * idle, rx, power, tx... |
| 3148 | * |
| 3149 | * where tx... is one or more transmit level times. |
| 3150 | */ |
| 3151 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3152 | String type, |
| 3153 | ControllerActivityCounter counter, |
| 3154 | int which) { |
| 3155 | if (!controllerActivityHasData(counter, which)) { |
| 3156 | return; |
| 3157 | } |
| 3158 | |
| 3159 | dumpLineHeader(pw, uid, category, type); |
| 3160 | pw.print(","); |
| 3161 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3162 | pw.print(","); |
| 3163 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3164 | pw.print(","); |
| 3165 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3166 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3167 | pw.print(","); |
| 3168 | pw.print(c.getCountLocked(which)); |
| 3169 | } |
| 3170 | pw.println(); |
| 3171 | } |
| 3172 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 3173 | /** |
| 3174 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3175 | */ |
| 3176 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3177 | ControllerActivityCounter counter, |
| 3178 | int which) { |
| 3179 | if (!controllerActivityHasData(counter, which)) { |
| 3180 | return; |
| 3181 | } |
| 3182 | |
| 3183 | final long cToken = proto.start(fieldId); |
| 3184 | |
| 3185 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3186 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3187 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3188 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3189 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3190 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3191 | |
| 3192 | long tToken; |
| 3193 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3194 | for (int i = 0; i < txCounters.length; ++i) { |
| 3195 | LongCounter c = txCounters[i]; |
| 3196 | tToken = proto.start(ControllerActivityProto.TX); |
| 3197 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3198 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3199 | proto.end(tToken); |
| 3200 | } |
| 3201 | |
| 3202 | proto.end(cToken); |
| 3203 | } |
| 3204 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3205 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3206 | String prefix, String controllerName, |
| 3207 | ControllerActivityCounter counter, |
| 3208 | int which) { |
| 3209 | if (controllerActivityHasData(counter, which)) { |
| 3210 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3215 | String controllerName, |
| 3216 | ControllerActivityCounter counter, int which) { |
| 3217 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3218 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3219 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3220 | // Battery real time |
| 3221 | final long totalControllerActivityTimeMs |
| 3222 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3223 | long totalTxTimeMs = 0; |
| 3224 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3225 | totalTxTimeMs += txState.getCountLocked(which); |
| 3226 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3227 | final long sleepTimeMs |
| 3228 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3229 | |
| 3230 | sb.setLength(0); |
| 3231 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3232 | sb.append(" "); |
| 3233 | sb.append(controllerName); |
| 3234 | sb.append(" Sleep time: "); |
| 3235 | formatTimeMs(sb, sleepTimeMs); |
| 3236 | sb.append("("); |
| 3237 | sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs)); |
| 3238 | sb.append(")"); |
| 3239 | pw.println(sb.toString()); |
| 3240 | |
| 3241 | sb.setLength(0); |
| 3242 | sb.append(prefix); |
| 3243 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3244 | sb.append(controllerName); |
| 3245 | sb.append(" Idle time: "); |
| 3246 | formatTimeMs(sb, idleTimeMs); |
| 3247 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3248 | sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3249 | sb.append(")"); |
| 3250 | pw.println(sb.toString()); |
| 3251 | |
| 3252 | sb.setLength(0); |
| 3253 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3254 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3255 | sb.append(controllerName); |
| 3256 | sb.append(" Rx time: "); |
| 3257 | formatTimeMs(sb, rxTimeMs); |
| 3258 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3259 | sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3260 | sb.append(")"); |
| 3261 | pw.println(sb.toString()); |
| 3262 | |
| 3263 | sb.setLength(0); |
| 3264 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3265 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3266 | sb.append(controllerName); |
| 3267 | sb.append(" Tx time: "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3268 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3269 | String [] powerLevel; |
| 3270 | switch(controllerName) { |
| 3271 | case "Cellular": |
| 3272 | powerLevel = new String[] { |
| 3273 | " less than 0dBm: ", |
| 3274 | " 0dBm to 8dBm: ", |
| 3275 | " 8dBm to 15dBm: ", |
| 3276 | " 15dBm to 20dBm: ", |
| 3277 | " above 20dBm: "}; |
| 3278 | break; |
| 3279 | default: |
| 3280 | powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"}; |
| 3281 | break; |
| 3282 | } |
| 3283 | final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3284 | if (numTxLvls > 1) { |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3285 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3286 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3287 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3288 | sb.setLength(0); |
| 3289 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3290 | sb.append(" "); |
| 3291 | sb.append(powerLevel[lvl]); |
| 3292 | sb.append(" "); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3293 | formatTimeMs(sb, txLvlTimeMs); |
| 3294 | sb.append("("); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3295 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3296 | sb.append(")"); |
| 3297 | pw.println(sb.toString()); |
| 3298 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3299 | } else { |
| 3300 | final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 3301 | formatTimeMs(sb, txLvlTimeMs); |
| 3302 | sb.append("("); |
| 3303 | sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs)); |
| 3304 | sb.append(")"); |
| 3305 | pw.println(sb.toString()); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3306 | } |
| 3307 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3308 | if (powerDrainMaMs > 0) { |
| 3309 | sb.setLength(0); |
| 3310 | sb.append(prefix); |
| 3311 | sb.append(" "); |
| 3312 | sb.append(controllerName); |
| 3313 | sb.append(" Battery drain: ").append( |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3314 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 3315 | sb.append("mAh"); |
| 3316 | pw.println(sb.toString()); |
| 3317 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3321 | * Temporary for settings. |
| 3322 | */ |
| 3323 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3324 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3325 | } |
| 3326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | /** |
| 3328 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3329 | * |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3330 | * 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] | 3331 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3332 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3333 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3335 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 3336 | final long rawRealtime = rawRealtimeMs * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3339 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3340 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3341 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3342 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3344 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3345 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3346 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3347 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3348 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3349 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3350 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3351 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3352 | rawRealtime, which); |
| 3353 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3354 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3355 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3356 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3357 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3358 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3359 | final long dischargeCount = getUahDischarge(which); |
| 3360 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
| 3361 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3362 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 3363 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3364 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3365 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3366 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3367 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3368 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3369 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3370 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3373 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3374 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3375 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3376 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3377 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3378 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3379 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3380 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3381 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3382 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3383 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3384 | // Calculate both wakelock and wifi multicast wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3385 | long fullWakeLockTimeTotal = 0; |
| 3386 | long partialWakeLockTimeTotal = 0; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3387 | long multicastWakeLockTimeTotalMicros = 0; |
| 3388 | int multicastWakeLockCountTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3389 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3390 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3391 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3392 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3393 | // First calculating the wakelock stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3394 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3395 | = u.getWakelockStats(); |
| 3396 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3397 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3398 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3399 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3400 | if (fullWakeTimer != null) { |
| 3401 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3402 | which); |
| 3403 | } |
| 3404 | |
| 3405 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3406 | if (partialWakeTimer != null) { |
| 3407 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3408 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3409 | } |
| 3410 | } |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3411 | |
| 3412 | // Now calculating the wifi multicast wakelock stats |
| 3413 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3414 | if (mcTimer != null) { |
| 3415 | multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 3416 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 3417 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3418 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3419 | |
| 3420 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3421 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3422 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3423 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3424 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3425 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3426 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3427 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3428 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3429 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3430 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3431 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3432 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3433 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3434 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3435 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3436 | // Dump Modem controller stats |
| 3437 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3438 | getModemControllerActivity(), which); |
| 3439 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3440 | // Dump Wifi controller stats |
| 3441 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3442 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3443 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3444 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3445 | |
| 3446 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3447 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3448 | |
| 3449 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3450 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3451 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | // Dump misc stats |
| 3454 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3455 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3456 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3457 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3458 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3459 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3460 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3461 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3462 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3463 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3464 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3465 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3466 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3467 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3468 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3469 | // Dump screen brightness stats |
| 3470 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3471 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3472 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3473 | } |
| 3474 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3475 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3476 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3477 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3478 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3479 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3480 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3481 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3482 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3483 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3484 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3485 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3486 | } |
| 3487 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3488 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3489 | // Dump network type stats |
| 3490 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3491 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3492 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3493 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3494 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3495 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3496 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3497 | } |
| 3498 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3499 | |
| 3500 | // Dump wifi state stats |
| 3501 | args = new Object[NUM_WIFI_STATES]; |
| 3502 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3503 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3504 | } |
| 3505 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3506 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3507 | args[i] = getWifiStateCount(i, which); |
| 3508 | } |
| 3509 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3510 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3511 | // Dump wifi suppl state stats |
| 3512 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3513 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3514 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3515 | } |
| 3516 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3517 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3518 | args[i] = getWifiSupplStateCount(i, which); |
| 3519 | } |
| 3520 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3521 | |
| 3522 | // Dump wifi signal strength stats |
| 3523 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3524 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3525 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3526 | } |
| 3527 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3528 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3529 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3530 | } |
| 3531 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3532 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3533 | // Dump Multicast total stats |
| 3534 | dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, |
| 3535 | multicastWakeLockTimeTotalMicros / 1000, |
| 3536 | multicastWakeLockCountTotal); |
| 3537 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3538 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3539 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3540 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3541 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3542 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3543 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3544 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3545 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3546 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3547 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3548 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3549 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000, |
| 3550 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3551 | } else { |
| 3552 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3553 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3554 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3555 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3556 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 3557 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000, |
| 3558 | dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3559 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3560 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3561 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3562 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3563 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3564 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3565 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3566 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3567 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3568 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3569 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3570 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3571 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3572 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3573 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3574 | // Not doing the regular wake lock formatting to remain compatible |
| 3575 | // with the old checkin format. |
| 3576 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3577 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3578 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3579 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3580 | } |
| 3581 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3582 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3583 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3584 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3585 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3586 | if (rpmStats.size() > 0) { |
| 3587 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3588 | sb.setLength(0); |
| 3589 | Timer totalTimer = ent.getValue(); |
| 3590 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3591 | int count = totalTimer.getCountLocked(which); |
| 3592 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3593 | long screenOffTimeMs = screenOffTimer != null |
| 3594 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3595 | int screenOffCount = screenOffTimer != null |
| 3596 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3597 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3598 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3599 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3600 | screenOffCount); |
| 3601 | } else { |
| 3602 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3603 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3604 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3608 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3609 | helper.create(this); |
| 3610 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3611 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3612 | if (sippers != null && sippers.size() > 0) { |
| 3613 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3614 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3615 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3616 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3617 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3618 | int uid = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3619 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3620 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3621 | String label; |
| 3622 | switch (bs.drainType) { |
| 3623 | case IDLE: |
| 3624 | label="idle"; |
| 3625 | break; |
| 3626 | case CELL: |
| 3627 | label="cell"; |
| 3628 | break; |
| 3629 | case PHONE: |
| 3630 | label="phone"; |
| 3631 | break; |
| 3632 | case WIFI: |
| 3633 | label="wifi"; |
| 3634 | break; |
| 3635 | case BLUETOOTH: |
| 3636 | label="blue"; |
| 3637 | break; |
| 3638 | case SCREEN: |
| 3639 | label="scrn"; |
| 3640 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3641 | case FLASHLIGHT: |
| 3642 | label="flashlight"; |
| 3643 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3644 | case APP: |
| 3645 | uid = bs.uidObj.getUid(); |
| 3646 | label = "uid"; |
| 3647 | break; |
| 3648 | case USER: |
| 3649 | uid = UserHandle.getUid(bs.userId, 0); |
| 3650 | label = "user"; |
| 3651 | break; |
| 3652 | case UNACCOUNTED: |
| 3653 | label = "unacc"; |
| 3654 | break; |
| 3655 | case OVERCOUNTED: |
| 3656 | label = "over"; |
| 3657 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3658 | case CAMERA: |
| 3659 | label = "camera"; |
| 3660 | break; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3661 | case MEMORY: |
| 3662 | label = "memory"; |
| 3663 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3664 | default: |
| 3665 | label = "???"; |
| 3666 | } |
| 3667 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3668 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3669 | bs.shouldHide ? 1 : 0, |
| 3670 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3671 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3675 | final long[] cpuFreqs = getCpuFreqs(); |
| 3676 | if (cpuFreqs != null) { |
| 3677 | sb.setLength(0); |
| 3678 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3679 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3680 | } |
| 3681 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3682 | } |
| 3683 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 3684 | // Dump stats per UID. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | for (int iu = 0; iu < NU; iu++) { |
| 3686 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3687 | if (reqUid >= 0 && uid != reqUid) { |
| 3688 | continue; |
| 3689 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3690 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3692 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3693 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3694 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3695 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3696 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3697 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3698 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3699 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3700 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3701 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3702 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3703 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3704 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3705 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3706 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3707 | // Background data transfers |
| 3708 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3709 | which); |
| 3710 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3711 | which); |
| 3712 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3713 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3714 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3715 | which); |
| 3716 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3717 | which); |
| 3718 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3719 | which); |
| 3720 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3721 | which); |
| 3722 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3723 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3724 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3725 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3726 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3727 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3728 | || wifiBytesBgTx > 0 |
| 3729 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3730 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3731 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3732 | wifiBytesRx, wifiBytesTx, |
| 3733 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3734 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3735 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3736 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3737 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3738 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3739 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3742 | // Dump modem controller data, per UID. |
| 3743 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3744 | u.getModemControllerActivity(), which); |
| 3745 | |
| 3746 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3747 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3748 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3749 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3750 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3751 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3752 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3753 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3754 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3755 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3756 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3757 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3758 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3759 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3760 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3761 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3762 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3763 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3765 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3766 | u.getWifiControllerActivity(), which); |
| 3767 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3768 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3769 | if (bleTimer != null) { |
| 3770 | // Convert from microseconds to milliseconds with rounding |
| 3771 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3772 | / 1000; |
| 3773 | if (totalTime != 0) { |
| 3774 | final int count = bleTimer.getCountLocked(which); |
| 3775 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3776 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3777 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3778 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3779 | final long actualTimeBg = bleTimerBg != null ? |
| 3780 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3781 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3782 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3783 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3784 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3785 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3786 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3787 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3788 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3789 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3790 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3791 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3792 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3793 | final Timer unoptimizedScanTimerBg = |
| 3794 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3795 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3796 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3797 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3798 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3799 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3800 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3801 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3802 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3803 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3804 | } |
| 3805 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3806 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3807 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3808 | u.getBluetoothControllerActivity(), which); |
| 3809 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3810 | if (u.hasUserActivity()) { |
| 3811 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3812 | boolean hasData = false; |
| 3813 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3814 | int val = u.getUserActivityCount(i, which); |
| 3815 | args[i] = val; |
| 3816 | if (val != 0) hasData = true; |
| 3817 | } |
| 3818 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3819 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3820 | } |
| 3821 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3822 | |
| 3823 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3824 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3825 | // Times are since reset (regardless of 'which') |
| 3826 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3827 | final Timer bgTimer = timer.getSubTimer(); |
| 3828 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3829 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3830 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3831 | } |
| 3832 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3833 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3834 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3835 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3836 | String linePrefix = ""; |
| 3837 | sb.setLength(0); |
| 3838 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3839 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3840 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3841 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3842 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3843 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3844 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3845 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3846 | rawRealtime, "w", which, linePrefix); |
| 3847 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 3848 | // Only log if we had at least one wakelock... |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3849 | if (sb.length() > 0) { |
| 3850 | String name = wakelocks.keyAt(iw); |
| 3851 | if (name.indexOf(',') >= 0) { |
| 3852 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3854 | if (name.indexOf('\n') >= 0) { |
| 3855 | name = name.replace('\n', '_'); |
| 3856 | } |
| 3857 | if (name.indexOf('\r') >= 0) { |
| 3858 | name = name.replace('\r', '_'); |
| 3859 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3860 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | } |
| 3862 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3863 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 3864 | // WiFi Multicast Wakelock Statistics |
| 3865 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 3866 | if (mcTimer != null) { |
| 3867 | final long totalMcWakelockTimeMs = |
| 3868 | mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; |
| 3869 | final int countMcWakelock = mcTimer.getCountLocked(which); |
| 3870 | if(totalMcWakelockTimeMs > 0) { |
| 3871 | dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, |
| 3872 | totalMcWakelockTimeMs, countMcWakelock); |
| 3873 | } |
| 3874 | } |
| 3875 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3876 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3877 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3878 | final Timer timer = syncs.valueAt(isy); |
| 3879 | // Convert from microseconds to milliseconds with rounding |
| 3880 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3881 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3882 | final Timer bgTimer = timer.getSubTimer(); |
| 3883 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3884 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3885 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3886 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3887 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3888 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3892 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3893 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3894 | final Timer timer = jobs.valueAt(ij); |
| 3895 | // Convert from microseconds to milliseconds with rounding |
| 3896 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3897 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3898 | final Timer bgTimer = timer.getSubTimer(); |
| 3899 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3900 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3901 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3902 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3903 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3904 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3908 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3909 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3910 | SparseIntArray types = completions.valueAt(ic); |
| 3911 | if (types != null) { |
| 3912 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3913 | "\"" + completions.keyAt(ic) + "\"", |
| 3914 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3915 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3916 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3917 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3918 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3919 | } |
| 3920 | } |
| 3921 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3922 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3923 | rawRealtime, which); |
| 3924 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3925 | rawRealtime, which); |
| 3926 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3927 | rawRealtime, which); |
| 3928 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3929 | rawRealtime, which); |
| 3930 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3931 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3932 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3933 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3934 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3935 | final int sensorNumber = sensors.keyAt(ise); |
| 3936 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3937 | if (timer != null) { |
| 3938 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3939 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3940 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3941 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3942 | final int count = timer.getCountLocked(which); |
| 3943 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3944 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3945 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3946 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3947 | final long bgActualTime = bgTimer != null ? |
| 3948 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3949 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3950 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3951 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3955 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3956 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3957 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 3958 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 3959 | rawRealtime, which); |
| 3960 | |
| 3961 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3962 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3963 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3964 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3965 | long totalStateTime = 0; |
| 3966 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3967 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3968 | totalStateTime += time; |
| 3969 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3970 | } |
| 3971 | if (totalStateTime > 0) { |
| 3972 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3973 | } |
| 3974 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3975 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3976 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3977 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3978 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3979 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3982 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 3983 | if (cpuFreqs != null) { |
| 3984 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3985 | // If total cpuFreqTimes is null, then we don't need to check for |
| 3986 | // screenOffCpuFreqTimes. |
| 3987 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 3988 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3989 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3990 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3991 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3992 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3993 | if (screenOffCpuFreqTimeMs != null) { |
| 3994 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3995 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3996 | } |
| 3997 | } else { |
| 3998 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3999 | sb.append(",0"); |
| 4000 | } |
| 4001 | } |
| 4002 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 4003 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4004 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4007 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4008 | = u.getProcessStats(); |
| 4009 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4010 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4011 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4012 | final long userMillis = ps.getUserTime(which); |
| 4013 | final long systemMillis = ps.getSystemTime(which); |
| 4014 | final long foregroundMillis = ps.getForegroundTime(which); |
| 4015 | final int starts = ps.getStarts(which); |
| 4016 | final int numCrashes = ps.getNumCrashes(which); |
| 4017 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4018 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4019 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 4020 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 4021 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 4022 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | } |
| 4024 | } |
| 4025 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4026 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4027 | = u.getPackageStats(); |
| 4028 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4029 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4030 | int wakeups = 0; |
| 4031 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4032 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 4033 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 4034 | wakeups += count; |
| 4035 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 4036 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4037 | } |
| 4038 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4039 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4040 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4041 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4042 | final int starts = ss.getStarts(which); |
| 4043 | final int launches = ss.getLaunches(which); |
| 4044 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4045 | dumpLine(pw, uid, category, APK_DATA, |
| 4046 | wakeups, // wakeup alarms |
| 4047 | packageStats.keyAt(ipkg), // Apk |
| 4048 | serviceStats.keyAt(isvc), // service |
| 4049 | startTime / 1000, // time spent started, in ms |
| 4050 | starts, |
| 4051 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4058 | static final class TimerEntry { |
| 4059 | final String mName; |
| 4060 | final int mId; |
| 4061 | final BatteryStats.Timer mTimer; |
| 4062 | final long mTime; |
| 4063 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 4064 | mName = name; |
| 4065 | mId = id; |
| 4066 | mTimer = timer; |
| 4067 | mTime = time; |
| 4068 | } |
| 4069 | } |
| 4070 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4071 | private void printmAh(PrintWriter printer, double power) { |
| 4072 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 4073 | } |
| 4074 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4075 | private void printmAh(StringBuilder sb, double power) { |
| 4076 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 4077 | } |
| 4078 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4079 | /** |
| 4080 | * Temporary for settings. |
| 4081 | */ |
| 4082 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 4083 | int reqUid) { |
| 4084 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 4085 | } |
| 4086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4088 | 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] | 4089 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4090 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 4091 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4092 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | |
| 4095 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 4096 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 4097 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 4098 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4099 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 4100 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 4101 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4102 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 4103 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4104 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4105 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4106 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4107 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4108 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4109 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 4111 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 4112 | if (estimatedBatteryCapacity > 0) { |
| 4113 | sb.setLength(0); |
| 4114 | sb.append(prefix); |
| 4115 | sb.append(" Estimated battery capacity: "); |
| 4116 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 4117 | sb.append(" mAh"); |
| 4118 | pw.println(sb.toString()); |
| 4119 | } |
| 4120 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 4121 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 4122 | if (minLearnedBatteryCapacity > 0) { |
| 4123 | sb.setLength(0); |
| 4124 | sb.append(prefix); |
| 4125 | sb.append(" Min learned battery capacity: "); |
| 4126 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 4127 | sb.append(" mAh"); |
| 4128 | pw.println(sb.toString()); |
| 4129 | } |
| 4130 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 4131 | if (maxLearnedBatteryCapacity > 0) { |
| 4132 | sb.setLength(0); |
| 4133 | sb.append(prefix); |
| 4134 | sb.append(" Max learned battery capacity: "); |
| 4135 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 4136 | sb.append(" mAh"); |
| 4137 | pw.println(sb.toString()); |
| 4138 | } |
| 4139 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4140 | sb.setLength(0); |
| 4141 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4142 | sb.append(" Time on battery: "); |
| 4143 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 4144 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 4145 | sb.append(") realtime, "); |
| 4146 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 4147 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 4148 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4149 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4150 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4151 | sb.setLength(0); |
| 4152 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4153 | sb.append(" Time on battery screen off: "); |
| 4154 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 4155 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 4156 | sb.append(") realtime, "); |
| 4157 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 4158 | sb.append("("); |
| 4159 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 4160 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4161 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4162 | |
| 4163 | sb.setLength(0); |
| 4164 | sb.append(prefix); |
| 4165 | sb.append(" Time on battery screen doze: "); |
| 4166 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 4167 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 4168 | sb.append(")"); |
| 4169 | pw.println(sb.toString()); |
| 4170 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4171 | sb.setLength(0); |
| 4172 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4173 | sb.append(" Total run time: "); |
| 4174 | formatTimeMs(sb, totalRealtime / 1000); |
| 4175 | sb.append("realtime, "); |
| 4176 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4177 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4178 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4179 | if (batteryTimeRemaining >= 0) { |
| 4180 | sb.setLength(0); |
| 4181 | sb.append(prefix); |
| 4182 | sb.append(" Battery time remaining: "); |
| 4183 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4184 | pw.println(sb.toString()); |
| 4185 | } |
| 4186 | if (chargeTimeRemaining >= 0) { |
| 4187 | sb.setLength(0); |
| 4188 | sb.append(prefix); |
| 4189 | sb.append(" Charge time remaining: "); |
| 4190 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4191 | pw.println(sb.toString()); |
| 4192 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4193 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4194 | final long dischargeCount = getUahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4195 | if (dischargeCount >= 0) { |
| 4196 | sb.setLength(0); |
| 4197 | sb.append(prefix); |
| 4198 | sb.append(" Discharge: "); |
| 4199 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4200 | sb.append(" mAh"); |
| 4201 | pw.println(sb.toString()); |
| 4202 | } |
| 4203 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4204 | final long dischargeScreenOffCount = getUahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4205 | if (dischargeScreenOffCount >= 0) { |
| 4206 | sb.setLength(0); |
| 4207 | sb.append(prefix); |
| 4208 | sb.append(" Screen off discharge: "); |
| 4209 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4210 | sb.append(" mAh"); |
| 4211 | pw.println(sb.toString()); |
| 4212 | } |
| 4213 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 4214 | final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4215 | if (dischargeScreenDozeCount >= 0) { |
| 4216 | sb.setLength(0); |
| 4217 | sb.append(prefix); |
| 4218 | sb.append(" Screen doze discharge: "); |
| 4219 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4220 | sb.append(" mAh"); |
| 4221 | pw.println(sb.toString()); |
| 4222 | } |
| 4223 | |
| 4224 | final long dischargeScreenOnCount = |
| 4225 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4226 | if (dischargeScreenOnCount >= 0) { |
| 4227 | sb.setLength(0); |
| 4228 | sb.append(prefix); |
| 4229 | sb.append(" Screen on discharge: "); |
| 4230 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4231 | sb.append(" mAh"); |
| 4232 | pw.println(sb.toString()); |
| 4233 | } |
| 4234 | |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 4235 | final long dischargeLightDozeCount = getUahDischargeLightDoze(which); |
| 4236 | if (dischargeLightDozeCount >= 0) { |
| 4237 | sb.setLength(0); |
| 4238 | sb.append(prefix); |
| 4239 | sb.append(" Device light doze discharge: "); |
| 4240 | sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0)); |
| 4241 | sb.append(" mAh"); |
| 4242 | pw.println(sb.toString()); |
| 4243 | } |
| 4244 | |
| 4245 | final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which); |
| 4246 | if (dischargeDeepDozeCount >= 0) { |
| 4247 | sb.setLength(0); |
| 4248 | sb.append(prefix); |
| 4249 | sb.append(" Device deep doze discharge: "); |
| 4250 | sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0)); |
| 4251 | sb.append(" mAh"); |
| 4252 | pw.println(sb.toString()); |
| 4253 | } |
| 4254 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4255 | pw.print(" Start clock time: "); |
| 4256 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4257 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4258 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4259 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4260 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4261 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4262 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4263 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4264 | rawRealtime, which); |
| 4265 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4266 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4267 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4268 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4269 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4270 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4271 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4272 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4273 | sb.append(prefix); |
| 4274 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4275 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4276 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4277 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4278 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4279 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4280 | pw.println(sb.toString()); |
| 4281 | sb.setLength(0); |
| 4282 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4283 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4284 | boolean didOne = false; |
| 4285 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4286 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4287 | if (time == 0) { |
| 4288 | continue; |
| 4289 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4290 | sb.append("\n "); |
| 4291 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4292 | didOne = true; |
| 4293 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4294 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4295 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4296 | sb.append("("); |
| 4297 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4298 | sb.append(")"); |
| 4299 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4300 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4301 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4302 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4303 | sb.setLength(0); |
| 4304 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4305 | sb.append(" Power save mode enabled: "); |
| 4306 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4307 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4308 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4309 | sb.append(")"); |
| 4310 | pw.println(sb.toString()); |
| 4311 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4312 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4313 | sb.setLength(0); |
| 4314 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4315 | sb.append(" Device light idling: "); |
| 4316 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4317 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4318 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4319 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4320 | sb.append("x"); |
| 4321 | pw.println(sb.toString()); |
| 4322 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4323 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4324 | sb.setLength(0); |
| 4325 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4326 | sb.append(" Idle mode light time: "); |
| 4327 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4328 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4329 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4330 | sb.append(") "); |
| 4331 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4332 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4333 | sb.append(" -- longest "); |
| 4334 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4335 | pw.println(sb.toString()); |
| 4336 | } |
| 4337 | if (deviceIdlingTime != 0) { |
| 4338 | sb.setLength(0); |
| 4339 | sb.append(prefix); |
| 4340 | sb.append(" Device full idling: "); |
| 4341 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4342 | sb.append("("); |
| 4343 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4344 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4345 | sb.append("x"); |
| 4346 | pw.println(sb.toString()); |
| 4347 | } |
| 4348 | if (deviceIdleModeFullTime != 0) { |
| 4349 | sb.setLength(0); |
| 4350 | sb.append(prefix); |
| 4351 | sb.append(" Idle mode full time: "); |
| 4352 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4353 | sb.append("("); |
| 4354 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4355 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4356 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4357 | sb.append("x"); |
| 4358 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4359 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4360 | pw.println(sb.toString()); |
| 4361 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4362 | if (phoneOnTime != 0) { |
| 4363 | sb.setLength(0); |
| 4364 | sb.append(prefix); |
| 4365 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4366 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4367 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4368 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4369 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4370 | if (connChanges != 0) { |
| 4371 | pw.print(prefix); |
| 4372 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4373 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4374 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4375 | // Calculate both wakelock and wifi multicast wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4376 | long fullWakeLockTimeTotalMicros = 0; |
| 4377 | long partialWakeLockTimeTotalMicros = 0; |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4378 | long multicastWakeLockTimeTotalMicros = 0; |
| 4379 | int multicastWakeLockCountTotal = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4380 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4381 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4382 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4383 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4384 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4385 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4386 | // First calculate wakelock statistics |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4387 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4388 | = u.getWakelockStats(); |
| 4389 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4390 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4391 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4392 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4393 | if (fullWakeTimer != null) { |
| 4394 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4395 | rawRealtime, which); |
| 4396 | } |
| 4397 | |
| 4398 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4399 | if (partialWakeTimer != null) { |
| 4400 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4401 | rawRealtime, which); |
| 4402 | if (totalTimeMicros > 0) { |
| 4403 | if (reqUid < 0) { |
| 4404 | // Only show the ordered list of all wake |
| 4405 | // locks if the caller is not asking for data |
| 4406 | // about a specific uid. |
| 4407 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4408 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4409 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4410 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4411 | } |
| 4412 | } |
| 4413 | } |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4414 | |
| 4415 | // Next calculate wifi multicast wakelock statistics |
| 4416 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 4417 | if (mcTimer != null) { |
| 4418 | multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 4419 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 4420 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4421 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4422 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4423 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4424 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4425 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4426 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4427 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4428 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4429 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4430 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4431 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4432 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4433 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4434 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4435 | sb.setLength(0); |
| 4436 | sb.append(prefix); |
| 4437 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4438 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4439 | pw.println(sb.toString()); |
| 4440 | } |
| 4441 | |
| 4442 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4443 | sb.setLength(0); |
| 4444 | sb.append(prefix); |
| 4445 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4446 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4447 | pw.println(sb.toString()); |
| 4448 | } |
| 4449 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 4450 | if (multicastWakeLockTimeTotalMicros != 0) { |
| 4451 | sb.setLength(0); |
| 4452 | sb.append(prefix); |
| 4453 | sb.append(" Total WiFi Multicast wakelock Count: "); |
| 4454 | sb.append(multicastWakeLockCountTotal); |
| 4455 | pw.println(sb.toString()); |
| 4456 | |
| 4457 | sb.setLength(0); |
| 4458 | sb.append(prefix); |
| 4459 | sb.append(" Total WiFi Multicast wakelock time: "); |
| 4460 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); |
| 4461 | pw.println(sb.toString()); |
| 4462 | } |
| 4463 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4464 | pw.println(""); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4465 | pw.print(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4466 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4467 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4468 | sb.append(" CONNECTIVITY POWER SUMMARY START"); |
| 4469 | pw.println(sb.toString()); |
| 4470 | |
| 4471 | pw.print(prefix); |
| 4472 | sb.setLength(0); |
| 4473 | sb.append(prefix); |
| 4474 | sb.append(" Logging duration for connectivity statistics: "); |
| 4475 | formatTimeMs(sb, whichBatteryRealtime / 1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4476 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4477 | |
| 4478 | sb.setLength(0); |
| 4479 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4480 | sb.append(" Cellular Statistics:"); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4481 | pw.println(sb.toString()); |
| 4482 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4483 | pw.print(prefix); |
| 4484 | sb.setLength(0); |
| 4485 | sb.append(prefix); |
| 4486 | sb.append(" Cellular kernel active time: "); |
| 4487 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
| 4488 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4489 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4490 | sb.append(")"); |
| 4491 | pw.println(sb.toString()); |
| 4492 | |
| 4493 | pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes)); |
| 4494 | pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes)); |
| 4495 | pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets); |
| 4496 | pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets); |
| 4497 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4498 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4499 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4500 | sb.append(" Cellular Radio Access Technology:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4501 | didOne = false; |
| 4502 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4503 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4504 | if (time == 0) { |
| 4505 | continue; |
| 4506 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4507 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4508 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4509 | didOne = true; |
| 4510 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4511 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4512 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4513 | sb.append("("); |
| 4514 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4515 | sb.append(") "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4516 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4517 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4518 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4519 | |
| 4520 | sb.setLength(0); |
| 4521 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4522 | sb.append(" Cellular Rx signal strength (RSRP):"); |
| 4523 | final String[] cellularRxSignalStrengthDescription = new String[]{ |
| 4524 | "very poor (less than -128dBm): ", |
| 4525 | "poor (-128dBm to -118dBm): ", |
| 4526 | "moderate (-118dBm to -108dBm): ", |
| 4527 | "good (-108dBm to -98dBm): ", |
| 4528 | "great (greater than -98dBm): "}; |
| 4529 | didOne = false; |
| 4530 | final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS, |
| 4531 | cellularRxSignalStrengthDescription.length); |
| 4532 | for (int i=0; i<numCellularRxBins; i++) { |
| 4533 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
| 4534 | if (time == 0) { |
| 4535 | continue; |
| 4536 | } |
| 4537 | sb.append("\n "); |
| 4538 | sb.append(prefix); |
| 4539 | didOne = true; |
| 4540 | sb.append(cellularRxSignalStrengthDescription[i]); |
| 4541 | sb.append(" "); |
| 4542 | formatTimeMs(sb, time/1000); |
| 4543 | sb.append("("); |
| 4544 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4545 | sb.append(") "); |
| 4546 | } |
| 4547 | if (!didOne) sb.append(" (no activity)"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4548 | pw.println(sb.toString()); |
| 4549 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4550 | printControllerActivity(pw, sb, prefix, "Cellular", |
| 4551 | getModemControllerActivity(), which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4552 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4553 | pw.print(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4554 | sb.setLength(0); |
| 4555 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4556 | sb.append(" Wifi Statistics:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4557 | pw.println(sb.toString()); |
| 4558 | |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4559 | pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes)); |
| 4560 | pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes)); |
| 4561 | pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets); |
| 4562 | pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets); |
| 4563 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4564 | sb.setLength(0); |
| 4565 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4566 | sb.append(" Wifi states:"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4567 | didOne = false; |
| 4568 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4569 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4570 | if (time == 0) { |
| 4571 | continue; |
| 4572 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4573 | sb.append("\n "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4574 | didOne = true; |
| 4575 | sb.append(WIFI_STATE_NAMES[i]); |
| 4576 | sb.append(" "); |
| 4577 | formatTimeMs(sb, time/1000); |
| 4578 | sb.append("("); |
| 4579 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4580 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4581 | } |
| 4582 | if (!didOne) sb.append(" (no activity)"); |
| 4583 | pw.println(sb.toString()); |
| 4584 | |
| 4585 | sb.setLength(0); |
| 4586 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4587 | sb.append(" Wifi supplicant states:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4588 | didOne = false; |
| 4589 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4590 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4591 | if (time == 0) { |
| 4592 | continue; |
| 4593 | } |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4594 | sb.append("\n "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4595 | didOne = true; |
| 4596 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4597 | sb.append(" "); |
| 4598 | formatTimeMs(sb, time/1000); |
| 4599 | sb.append("("); |
| 4600 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4601 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4602 | } |
| 4603 | if (!didOne) sb.append(" (no activity)"); |
| 4604 | pw.println(sb.toString()); |
| 4605 | |
| 4606 | sb.setLength(0); |
| 4607 | sb.append(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4608 | sb.append(" Wifi Rx signal strength (RSSI):"); |
| 4609 | final String[] wifiRxSignalStrengthDescription = new String[]{ |
| 4610 | "very poor (less than -88.75dBm): ", |
| 4611 | "poor (-88.75 to -77.5dBm): ", |
| 4612 | "moderate (-77.5dBm to -66.25dBm): ", |
| 4613 | "good (-66.25dBm to -55dBm): ", |
| 4614 | "great (greater than -55dBm): "}; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4615 | didOne = false; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4616 | final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS, |
| 4617 | wifiRxSignalStrengthDescription.length); |
| 4618 | for (int i=0; i<numWifiRxBins; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4619 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4620 | if (time == 0) { |
| 4621 | continue; |
| 4622 | } |
| 4623 | sb.append("\n "); |
| 4624 | sb.append(prefix); |
| 4625 | didOne = true; |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4626 | sb.append(" "); |
| 4627 | sb.append(wifiRxSignalStrengthDescription[i]); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4628 | formatTimeMs(sb, time/1000); |
| 4629 | sb.append("("); |
| 4630 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4631 | sb.append(") "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4632 | } |
| 4633 | if (!didOne) sb.append(" (no activity)"); |
| 4634 | pw.println(sb.toString()); |
| 4635 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4636 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4637 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4638 | pw.print(prefix); |
Siddharth Ray | 3c648c4 | 2017-10-02 17:30:58 -0700 | [diff] [blame] | 4639 | sb.setLength(0); |
| 4640 | sb.append(prefix); |
| 4641 | sb.append(" CONNECTIVITY POWER SUMMARY END"); |
| 4642 | pw.println(sb.toString()); |
| 4643 | pw.println(""); |
| 4644 | |
| 4645 | pw.print(prefix); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4646 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4647 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4648 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4649 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4650 | sb.setLength(0); |
| 4651 | sb.append(prefix); |
| 4652 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4653 | pw.println(sb.toString()); |
| 4654 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4655 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4656 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4657 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4658 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4659 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4660 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4661 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4662 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4663 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4664 | pw.println(getDischargeStartLevel()); |
| 4665 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4666 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4667 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4668 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4669 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4670 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4671 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4672 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4673 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4674 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4675 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4676 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4677 | pw.println(getDischargeAmountScreenOff()); |
| 4678 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4679 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4680 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4681 | } else { |
| 4682 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4683 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4684 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4685 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4686 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4687 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4688 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4689 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4690 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4691 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4692 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4693 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4694 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4695 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4696 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4697 | helper.create(this); |
| 4698 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4699 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4700 | if (sippers != null && sippers.size() > 0) { |
| 4701 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4702 | pw.print(prefix); pw.print(" Capacity: "); |
| 4703 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4704 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4705 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4706 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4707 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4708 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4709 | pw.println(); |
| 4710 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4711 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4712 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4713 | switch (bs.drainType) { |
| 4714 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4715 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4716 | break; |
| 4717 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4718 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4719 | break; |
| 4720 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4721 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4722 | break; |
| 4723 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4724 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4725 | break; |
| 4726 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4727 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4728 | break; |
| 4729 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4730 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4731 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4732 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4733 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4734 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4735 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4736 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4737 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4738 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4739 | break; |
| 4740 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4741 | pw.print(" User "); pw.print(bs.userId); |
| 4742 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4743 | break; |
| 4744 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4745 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4746 | break; |
| 4747 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4748 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4749 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4750 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4751 | pw.print(" Camera: "); |
| 4752 | break; |
| 4753 | default: |
| 4754 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4755 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4756 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4757 | printmAh(pw, bs.totalPowerMah); |
| 4758 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4759 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4760 | // If the usage (generic power) isn't the whole amount, we list out |
| 4761 | // what components are involved in the calculation. |
| 4762 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4763 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4764 | if (bs.usagePowerMah != 0) { |
| 4765 | pw.print(" usage="); |
| 4766 | printmAh(pw, bs.usagePowerMah); |
| 4767 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4768 | if (bs.cpuPowerMah != 0) { |
| 4769 | pw.print(" cpu="); |
| 4770 | printmAh(pw, bs.cpuPowerMah); |
| 4771 | } |
| 4772 | if (bs.wakeLockPowerMah != 0) { |
| 4773 | pw.print(" wake="); |
| 4774 | printmAh(pw, bs.wakeLockPowerMah); |
| 4775 | } |
| 4776 | if (bs.mobileRadioPowerMah != 0) { |
| 4777 | pw.print(" radio="); |
| 4778 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4779 | } |
| 4780 | if (bs.wifiPowerMah != 0) { |
| 4781 | pw.print(" wifi="); |
| 4782 | printmAh(pw, bs.wifiPowerMah); |
| 4783 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4784 | if (bs.bluetoothPowerMah != 0) { |
| 4785 | pw.print(" bt="); |
| 4786 | printmAh(pw, bs.bluetoothPowerMah); |
| 4787 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4788 | if (bs.gpsPowerMah != 0) { |
| 4789 | pw.print(" gps="); |
| 4790 | printmAh(pw, bs.gpsPowerMah); |
| 4791 | } |
| 4792 | if (bs.sensorPowerMah != 0) { |
| 4793 | pw.print(" sensor="); |
| 4794 | printmAh(pw, bs.sensorPowerMah); |
| 4795 | } |
| 4796 | if (bs.cameraPowerMah != 0) { |
| 4797 | pw.print(" camera="); |
| 4798 | printmAh(pw, bs.cameraPowerMah); |
| 4799 | } |
| 4800 | if (bs.flashlightPowerMah != 0) { |
| 4801 | pw.print(" flash="); |
| 4802 | printmAh(pw, bs.flashlightPowerMah); |
| 4803 | } |
| 4804 | pw.print(" )"); |
| 4805 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4806 | |
| 4807 | // If there is additional smearing information, include it. |
| 4808 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4809 | pw.print(" Including smearing: "); |
| 4810 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4811 | pw.print(" ("); |
| 4812 | if (bs.screenPowerMah != 0) { |
| 4813 | pw.print(" screen="); |
| 4814 | printmAh(pw, bs.screenPowerMah); |
| 4815 | } |
| 4816 | if (bs.proportionalSmearMah != 0) { |
| 4817 | pw.print(" proportional="); |
| 4818 | printmAh(pw, bs.proportionalSmearMah); |
| 4819 | } |
| 4820 | pw.print(" )"); |
| 4821 | } |
| 4822 | if (bs.shouldHide) { |
| 4823 | pw.print(" Excluded from smearing"); |
| 4824 | } |
| 4825 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4826 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4827 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4828 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4829 | } |
| 4830 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4831 | sippers = helper.getMobilemsppList(); |
| 4832 | if (sippers != null && sippers.size() > 0) { |
| 4833 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4834 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4835 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4836 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4837 | sb.setLength(0); |
| 4838 | sb.append(prefix); sb.append(" Uid "); |
| 4839 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4840 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4841 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4842 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4843 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4844 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4845 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4846 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4847 | sb.setLength(0); |
| 4848 | sb.append(prefix); |
| 4849 | sb.append(" TOTAL TIME: "); |
| 4850 | formatTimeMs(sb, totalTime); |
| 4851 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4852 | sb.append(")"); |
| 4853 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4854 | pw.println(); |
| 4855 | } |
| 4856 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4857 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4858 | @Override |
| 4859 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4860 | long lhsTime = lhs.mTime; |
| 4861 | long rhsTime = rhs.mTime; |
| 4862 | if (lhsTime < rhsTime) { |
| 4863 | return 1; |
| 4864 | } |
| 4865 | if (lhsTime > rhsTime) { |
| 4866 | return -1; |
| 4867 | } |
| 4868 | return 0; |
| 4869 | } |
| 4870 | }; |
| 4871 | |
| 4872 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4873 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4874 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4875 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4876 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4877 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4878 | : kernelWakelocks.entrySet()) { |
| 4879 | final BatteryStats.Timer timer = ent.getValue(); |
| 4880 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4881 | if (totalTimeMillis > 0) { |
| 4882 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4883 | } |
| 4884 | } |
| 4885 | if (ktimers.size() > 0) { |
| 4886 | Collections.sort(ktimers, timerComparator); |
| 4887 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4888 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4889 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4890 | String linePrefix = ": "; |
| 4891 | sb.setLength(0); |
| 4892 | sb.append(prefix); |
| 4893 | sb.append(" Kernel Wake lock "); |
| 4894 | sb.append(timer.mName); |
| 4895 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4896 | which, linePrefix); |
| 4897 | if (!linePrefix.equals(": ")) { |
| 4898 | sb.append(" realtime"); |
| 4899 | // Only print out wake locks that were held |
| 4900 | pw.println(sb.toString()); |
| 4901 | } |
| 4902 | } |
| 4903 | pw.println(); |
| 4904 | } |
| 4905 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4906 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4907 | if (timers.size() > 0) { |
| 4908 | Collections.sort(timers, timerComparator); |
| 4909 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4910 | for (int i=0; i<timers.size(); i++) { |
| 4911 | TimerEntry timer = timers.get(i); |
| 4912 | sb.setLength(0); |
| 4913 | sb.append(" Wake lock "); |
| 4914 | UserHandle.formatUid(sb, timer.mId); |
| 4915 | sb.append(" "); |
| 4916 | sb.append(timer.mName); |
| 4917 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4918 | sb.append(" realtime"); |
| 4919 | pw.println(sb.toString()); |
| 4920 | } |
| 4921 | timers.clear(); |
| 4922 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4923 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4924 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4925 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4926 | if (wakeupReasons.size() > 0) { |
| 4927 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4928 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4929 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4930 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4931 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4932 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4933 | } |
| 4934 | Collections.sort(reasons, timerComparator); |
| 4935 | for (int i=0; i<reasons.size(); i++) { |
| 4936 | TimerEntry timer = reasons.get(i); |
| 4937 | String linePrefix = ": "; |
| 4938 | sb.setLength(0); |
| 4939 | sb.append(prefix); |
| 4940 | sb.append(" Wakeup reason "); |
| 4941 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4942 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4943 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4944 | pw.println(sb.toString()); |
| 4945 | } |
| 4946 | pw.println(); |
| 4947 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4948 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4949 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4950 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4951 | if (mMemoryStats.size() > 0) { |
| 4952 | pw.println(" Memory Stats"); |
| 4953 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4954 | sb.setLength(0); |
| 4955 | sb.append(" Bandwidth "); |
| 4956 | sb.append(mMemoryStats.keyAt(i)); |
| 4957 | sb.append(" Time "); |
| 4958 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4959 | pw.println(sb.toString()); |
| 4960 | } |
| 4961 | pw.println(); |
| 4962 | } |
| 4963 | |
| 4964 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 4965 | if (rpmStats.size() > 0) { |
| 4966 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 4967 | if (rpmStats.size() > 0) { |
| 4968 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 4969 | final String timerName = ent.getKey(); |
| 4970 | final Timer timer = ent.getValue(); |
| 4971 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4972 | } |
| 4973 | } |
| 4974 | pw.println(); |
| 4975 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4976 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 4977 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4978 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4979 | pw.print(prefix); |
| 4980 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 4981 | if (screenOffRpmStats.size() > 0) { |
| 4982 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 4983 | final String timerName = ent.getKey(); |
| 4984 | final Timer timer = ent.getValue(); |
| 4985 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4986 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4987 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4988 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4989 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4992 | final long[] cpuFreqs = getCpuFreqs(); |
| 4993 | if (cpuFreqs != null) { |
| 4994 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4995 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4996 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4997 | sb.append(" " + cpuFreqs[i]); |
| 4998 | } |
| 4999 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 5000 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5003 | for (int iu=0; iu<NU; iu++) { |
| 5004 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5005 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5006 | continue; |
| 5007 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5008 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5009 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 5010 | |
| 5011 | pw.print(prefix); |
| 5012 | pw.print(" "); |
| 5013 | UserHandle.formatUid(pw, uid); |
| 5014 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5016 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5017 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 5018 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 5019 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 5020 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5021 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 5022 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 5023 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5024 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 5025 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5026 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 5027 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5028 | |
| 5029 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 5030 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 5031 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5032 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 5033 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 5034 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5035 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 5036 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5037 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 5038 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5039 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5040 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5041 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 5042 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 5043 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5044 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 5045 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5046 | pw.print(prefix); pw.print(" Mobile network: "); |
| 5047 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5048 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 5049 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 5050 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5051 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5052 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 5053 | sb.setLength(0); |
| 5054 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 5055 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 5056 | sb.append("("); |
| 5057 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 5058 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 5059 | long packets = mobileRxPackets + mobileTxPackets; |
| 5060 | if (packets == 0) { |
| 5061 | packets = 1; |
| 5062 | } |
| 5063 | sb.append(" @ "); |
| 5064 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 5065 | sb.append(" mspp"); |
| 5066 | pw.println(sb.toString()); |
| 5067 | } |
| 5068 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5069 | if (mobileWakeup > 0) { |
| 5070 | sb.setLength(0); |
| 5071 | sb.append(prefix); |
| 5072 | sb.append(" Mobile radio AP wakeups: "); |
| 5073 | sb.append(mobileWakeup); |
| 5074 | pw.println(sb.toString()); |
| 5075 | } |
| 5076 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5077 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 5078 | u.getModemControllerActivity(), which); |
| 5079 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5080 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5081 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 5082 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5083 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 5084 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 5085 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5088 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5089 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5090 | || uidWifiRunningTime != 0) { |
| 5091 | sb.setLength(0); |
| 5092 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 5093 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 5094 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 5095 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5096 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5097 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 5098 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 5099 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5100 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5101 | formatTimeMs(sb, wifiScanTime / 1000); |
| 5102 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5103 | whichBatteryRealtime)); sb.append(") "); |
| 5104 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5105 | sb.append("x\n"); |
| 5106 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 5107 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 5108 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 5109 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 5110 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5111 | sb.append(") "); |
| 5112 | sb.append(wifiScanCount); |
| 5113 | sb.append("x\n"); |
| 5114 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 5115 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 5116 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 5117 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 5118 | sb.append(") "); |
| 5119 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5120 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5121 | pw.println(sb.toString()); |
| 5122 | } |
| 5123 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5124 | if (wifiWakeup > 0) { |
| 5125 | sb.setLength(0); |
| 5126 | sb.append(prefix); |
| 5127 | sb.append(" WiFi AP wakeups: "); |
| 5128 | sb.append(wifiWakeup); |
| 5129 | pw.println(sb.toString()); |
| 5130 | } |
| 5131 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5132 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 5133 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 5134 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5135 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 5136 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 5137 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 5138 | pw.print(formatBytesLocked(btTxBytes)); |
| 5139 | pw.println(" sent"); |
| 5140 | } |
| 5141 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5142 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 5143 | if (bleTimer != null) { |
| 5144 | // Convert from microseconds to milliseconds with rounding |
| 5145 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5146 | / 1000; |
| 5147 | if (totalTimeMs != 0) { |
| 5148 | final int count = bleTimer.getCountLocked(which); |
| 5149 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 5150 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5151 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5152 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5153 | final long actualTimeMsBg = bleTimerBg != null ? |
| 5154 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5155 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5156 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 5157 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5158 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 5159 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 5160 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 5161 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 5162 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 5163 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5164 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 5165 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 5166 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 5167 | final Timer unoptimizedScanTimerBg = |
| 5168 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 5169 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 5170 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5171 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 5172 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5173 | |
| 5174 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5175 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5176 | sb.append(prefix); |
| 5177 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5178 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5179 | sb.append(" ("); |
| 5180 | sb.append(count); |
| 5181 | sb.append(" times)"); |
| 5182 | if (bleTimer.isRunningLocked()) { |
| 5183 | sb.append(" (currently running)"); |
| 5184 | } |
| 5185 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5186 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5187 | |
| 5188 | sb.append(prefix); |
| 5189 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 5190 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 5191 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5192 | sb.append(count); |
| 5193 | sb.append(" times)"); |
| 5194 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5195 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5196 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5197 | sb.append("\n"); |
| 5198 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 5199 | sb.append(prefix); |
| 5200 | sb.append(" Bluetooth Scan (background realtime): "); |
| 5201 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 5202 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5203 | sb.append(countBg); |
| 5204 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5205 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 5206 | sb.append(" (currently running in background)"); |
| 5207 | } |
| 5208 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5209 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5210 | |
| 5211 | sb.append(prefix); |
| 5212 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5213 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5214 | sb.append(" ("); |
| 5215 | sb.append(resultCountBg); |
| 5216 | sb.append(" in background)"); |
| 5217 | |
| 5218 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5219 | sb.append("\n"); |
| 5220 | sb.append(prefix); |
| 5221 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5222 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5223 | sb.append(" (max "); |
| 5224 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5225 | sb.append(")"); |
| 5226 | if (unoptimizedScanTimer != null |
| 5227 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5228 | sb.append(" (currently running unoptimized)"); |
| 5229 | } |
| 5230 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5231 | sb.append("\n"); |
| 5232 | sb.append(prefix); |
| 5233 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5234 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5235 | sb.append(" (max "); |
| 5236 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5237 | sb.append(")"); |
| 5238 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5239 | sb.append(" (currently running unoptimized in background)"); |
| 5240 | } |
| 5241 | } |
| 5242 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5243 | pw.println(sb.toString()); |
| 5244 | uidActivity = true; |
| 5245 | } |
| 5246 | } |
| 5247 | |
| 5248 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5249 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5250 | if (u.hasUserActivity()) { |
| 5251 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5252 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5253 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5254 | if (val != 0) { |
| 5255 | if (!hasData) { |
| 5256 | sb.setLength(0); |
| 5257 | sb.append(" User activity: "); |
| 5258 | hasData = true; |
| 5259 | } else { |
| 5260 | sb.append(", "); |
| 5261 | } |
| 5262 | sb.append(val); |
| 5263 | sb.append(" "); |
| 5264 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5265 | } |
| 5266 | } |
| 5267 | if (hasData) { |
| 5268 | pw.println(sb.toString()); |
| 5269 | } |
| 5270 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5272 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5273 | = u.getWakelockStats(); |
| 5274 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5275 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5276 | int countWakelock = 0; |
| 5277 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5278 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5279 | String linePrefix = ": "; |
| 5280 | sb.setLength(0); |
| 5281 | sb.append(prefix); |
| 5282 | sb.append(" Wake lock "); |
| 5283 | sb.append(wakelocks.keyAt(iw)); |
| 5284 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5285 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5286 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5287 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5288 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5289 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5290 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5291 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5292 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5293 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5294 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5295 | sb.append(" realtime"); |
| 5296 | pw.println(sb.toString()); |
| 5297 | uidActivity = true; |
| 5298 | countWakelock++; |
| 5299 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5300 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5301 | rawRealtime, which); |
| 5302 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5303 | rawRealtime, which); |
| 5304 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5305 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5306 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5307 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5308 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5309 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5310 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5311 | // pooled and therefore just a lower bound) |
| 5312 | long actualTotalPartialWakelock = 0; |
| 5313 | long actualBgPartialWakelock = 0; |
| 5314 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5315 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5316 | // Convert from microseconds to milliseconds with rounding |
| 5317 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5318 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5319 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5320 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5321 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5325 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5326 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5327 | sb.setLength(0); |
| 5328 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5329 | sb.append(" TOTAL wake: "); |
| 5330 | boolean needComma = false; |
| 5331 | if (totalFullWakelock != 0) { |
| 5332 | needComma = true; |
| 5333 | formatTimeMs(sb, totalFullWakelock); |
| 5334 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5335 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5336 | if (totalPartialWakelock != 0) { |
| 5337 | if (needComma) { |
| 5338 | sb.append(", "); |
| 5339 | } |
| 5340 | needComma = true; |
| 5341 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5342 | sb.append("blamed partial"); |
| 5343 | } |
| 5344 | if (actualTotalPartialWakelock != 0) { |
| 5345 | if (needComma) { |
| 5346 | sb.append(", "); |
| 5347 | } |
| 5348 | needComma = true; |
| 5349 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5350 | sb.append("actual partial"); |
| 5351 | } |
| 5352 | if (actualBgPartialWakelock != 0) { |
| 5353 | if (needComma) { |
| 5354 | sb.append(", "); |
| 5355 | } |
| 5356 | needComma = true; |
| 5357 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5358 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5359 | } |
| 5360 | if (totalWindowWakelock != 0) { |
| 5361 | if (needComma) { |
| 5362 | sb.append(", "); |
| 5363 | } |
| 5364 | needComma = true; |
| 5365 | formatTimeMs(sb, totalWindowWakelock); |
| 5366 | sb.append("window"); |
| 5367 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5368 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5369 | if (needComma) { |
| 5370 | sb.append(","); |
| 5371 | } |
| 5372 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5373 | formatTimeMs(sb, totalDrawWakelock); |
| 5374 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5375 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5376 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5377 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 5381 | // Calculate multicast wakelock stats |
| 5382 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 5383 | if (mcTimer != null) { |
| 5384 | final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); |
| 5385 | final int multicastWakeLockCount = mcTimer.getCountLocked(which); |
| 5386 | |
| 5387 | if (multicastWakeLockTimeMicros > 0) { |
| 5388 | sb.setLength(0); |
| 5389 | sb.append(prefix); |
| 5390 | sb.append(" WiFi Multicast Wakelock"); |
| 5391 | sb.append(" count = "); |
| 5392 | sb.append(multicastWakeLockCount); |
| 5393 | sb.append(" time = "); |
| 5394 | formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); |
| 5395 | pw.println(sb.toString()); |
| 5396 | } |
| 5397 | } |
| 5398 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5399 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5400 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5401 | final Timer timer = syncs.valueAt(isy); |
| 5402 | // Convert from microseconds to milliseconds with rounding |
| 5403 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5404 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5405 | final Timer bgTimer = timer.getSubTimer(); |
| 5406 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5407 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5408 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5409 | sb.setLength(0); |
| 5410 | sb.append(prefix); |
| 5411 | sb.append(" Sync "); |
| 5412 | sb.append(syncs.keyAt(isy)); |
| 5413 | sb.append(": "); |
| 5414 | if (totalTime != 0) { |
| 5415 | formatTimeMs(sb, totalTime); |
| 5416 | sb.append("realtime ("); |
| 5417 | sb.append(count); |
| 5418 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5419 | if (bgTime > 0) { |
| 5420 | sb.append(", "); |
| 5421 | formatTimeMs(sb, bgTime); |
| 5422 | sb.append("background ("); |
| 5423 | sb.append(bgCount); |
| 5424 | sb.append(" times)"); |
| 5425 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5426 | } else { |
| 5427 | sb.append("(not used)"); |
| 5428 | } |
| 5429 | pw.println(sb.toString()); |
| 5430 | uidActivity = true; |
| 5431 | } |
| 5432 | |
| 5433 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5434 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5435 | final Timer timer = jobs.valueAt(ij); |
| 5436 | // Convert from microseconds to milliseconds with rounding |
| 5437 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5438 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5439 | final Timer bgTimer = timer.getSubTimer(); |
| 5440 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5441 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5442 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5443 | sb.setLength(0); |
| 5444 | sb.append(prefix); |
| 5445 | sb.append(" Job "); |
| 5446 | sb.append(jobs.keyAt(ij)); |
| 5447 | sb.append(": "); |
| 5448 | if (totalTime != 0) { |
| 5449 | formatTimeMs(sb, totalTime); |
| 5450 | sb.append("realtime ("); |
| 5451 | sb.append(count); |
| 5452 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5453 | if (bgTime > 0) { |
| 5454 | sb.append(", "); |
| 5455 | formatTimeMs(sb, bgTime); |
| 5456 | sb.append("background ("); |
| 5457 | sb.append(bgCount); |
| 5458 | sb.append(" times)"); |
| 5459 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5460 | } else { |
| 5461 | sb.append("(not used)"); |
| 5462 | } |
| 5463 | pw.println(sb.toString()); |
| 5464 | uidActivity = true; |
| 5465 | } |
| 5466 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5467 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5468 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5469 | SparseIntArray types = completions.valueAt(ic); |
| 5470 | if (types != null) { |
| 5471 | pw.print(prefix); |
| 5472 | pw.print(" Job Completions "); |
| 5473 | pw.print(completions.keyAt(ic)); |
| 5474 | pw.print(":"); |
| 5475 | for (int it=0; it<types.size(); it++) { |
| 5476 | pw.print(" "); |
| 5477 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5478 | pw.print("("); |
| 5479 | pw.print(types.valueAt(it)); |
| 5480 | pw.print("x)"); |
| 5481 | } |
| 5482 | pw.println(); |
| 5483 | } |
| 5484 | } |
| 5485 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5486 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5487 | prefix, "Flashlight"); |
| 5488 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5489 | prefix, "Camera"); |
| 5490 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5491 | prefix, "Video"); |
| 5492 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5493 | prefix, "Audio"); |
| 5494 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5495 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5496 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5497 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5498 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5499 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5500 | sb.setLength(0); |
| 5501 | sb.append(prefix); |
| 5502 | sb.append(" Sensor "); |
| 5503 | int handle = se.getHandle(); |
| 5504 | if (handle == Uid.Sensor.GPS) { |
| 5505 | sb.append("GPS"); |
| 5506 | } else { |
| 5507 | sb.append(handle); |
| 5508 | } |
| 5509 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5511 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5512 | if (timer != null) { |
| 5513 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5514 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5515 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5516 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5517 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5518 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5519 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5520 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5521 | final long bgActualTime = bgTimer != null ? |
| 5522 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5523 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5524 | //timer.logState(); |
| 5525 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5526 | if (actualTime != totalTime) { |
| 5527 | formatTimeMs(sb, totalTime); |
| 5528 | sb.append("blamed realtime, "); |
| 5529 | } |
| 5530 | |
| 5531 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5532 | sb.append("realtime ("); |
| 5533 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5534 | sb.append(" times)"); |
| 5535 | |
| 5536 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5537 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5538 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5539 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5540 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5541 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5542 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | } else { |
| 5544 | sb.append("(not used)"); |
| 5545 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5546 | } else { |
| 5547 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5548 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5549 | |
| 5550 | pw.println(sb.toString()); |
| 5551 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5554 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5555 | "Vibrator"); |
| 5556 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5557 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5558 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5559 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5560 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5561 | long totalStateTime = 0; |
| 5562 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5563 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5564 | if (time > 0) { |
| 5565 | totalStateTime += time; |
| 5566 | sb.setLength(0); |
| 5567 | sb.append(prefix); |
| 5568 | sb.append(" "); |
| 5569 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5570 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5571 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5572 | pw.println(sb.toString()); |
| 5573 | uidActivity = true; |
| 5574 | } |
| 5575 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5576 | if (totalStateTime > 0) { |
| 5577 | sb.setLength(0); |
| 5578 | sb.append(prefix); |
| 5579 | sb.append(" Total running: "); |
| 5580 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5581 | pw.println(sb.toString()); |
| 5582 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5583 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5584 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5585 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5586 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5587 | sb.setLength(0); |
| 5588 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5589 | sb.append(" Total cpu time: u="); |
| 5590 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5591 | sb.append("s="); |
| 5592 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5593 | pw.println(sb.toString()); |
| 5594 | } |
| 5595 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5596 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5597 | if (cpuFreqTimes != null) { |
| 5598 | sb.setLength(0); |
| 5599 | sb.append(" Total cpu time per freq:"); |
| 5600 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5601 | sb.append(" " + cpuFreqTimes[i]); |
| 5602 | } |
| 5603 | pw.println(sb.toString()); |
| 5604 | } |
| 5605 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5606 | if (screenOffCpuFreqTimes != null) { |
| 5607 | sb.setLength(0); |
| 5608 | sb.append(" Total screen-off cpu time per freq:"); |
| 5609 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5610 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5611 | } |
| 5612 | pw.println(sb.toString()); |
| 5613 | } |
| 5614 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5615 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5616 | = u.getProcessStats(); |
| 5617 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5618 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5619 | long userTime; |
| 5620 | long systemTime; |
| 5621 | long foregroundTime; |
| 5622 | int starts; |
| 5623 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5624 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5625 | userTime = ps.getUserTime(which); |
| 5626 | systemTime = ps.getSystemTime(which); |
| 5627 | foregroundTime = ps.getForegroundTime(which); |
| 5628 | starts = ps.getStarts(which); |
| 5629 | final int numCrashes = ps.getNumCrashes(which); |
| 5630 | final int numAnrs = ps.getNumAnrs(which); |
| 5631 | numExcessive = which == STATS_SINCE_CHARGED |
| 5632 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5634 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5635 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5636 | sb.setLength(0); |
| 5637 | sb.append(prefix); sb.append(" Proc "); |
| 5638 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5639 | sb.append(prefix); sb.append(" CPU: "); |
| 5640 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5641 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5642 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5643 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5644 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5645 | boolean hasOne = false; |
| 5646 | if (starts != 0) { |
| 5647 | hasOne = true; |
| 5648 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5649 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5650 | if (numCrashes != 0) { |
| 5651 | if (hasOne) { |
| 5652 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5653 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5654 | hasOne = true; |
| 5655 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5656 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5657 | if (numAnrs != 0) { |
| 5658 | if (hasOne) { |
| 5659 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5661 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5662 | } |
| 5663 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5664 | pw.println(sb.toString()); |
| 5665 | for (int e=0; e<numExcessive; e++) { |
| 5666 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5667 | if (ew != null) { |
| 5668 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5669 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5670 | pw.print("cpu"); |
| 5671 | } else { |
| 5672 | pw.print("unknown"); |
| 5673 | } |
| 5674 | pw.print(" use: "); |
| 5675 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5676 | pw.print(" over "); |
| 5677 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5678 | if (ew.overTime != 0) { |
| 5679 | pw.print(" ("); |
| 5680 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5681 | pw.println("%)"); |
| 5682 | } |
| 5683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | } |
| 5685 | uidActivity = true; |
| 5686 | } |
| 5687 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5688 | |
| 5689 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5690 | = u.getPackageStats(); |
| 5691 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5692 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5693 | pw.println(":"); |
| 5694 | boolean apkActivity = false; |
| 5695 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5696 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5697 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5698 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5699 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5700 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5701 | pw.println(" times"); |
| 5702 | apkActivity = true; |
| 5703 | } |
| 5704 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5705 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5706 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5707 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5708 | final int starts = ss.getStarts(which); |
| 5709 | final int launches = ss.getLaunches(which); |
| 5710 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5711 | sb.setLength(0); |
| 5712 | sb.append(prefix); sb.append(" Service "); |
| 5713 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5714 | sb.append(prefix); sb.append(" Created for: "); |
| 5715 | formatTimeMs(sb, startTime / 1000); |
| 5716 | sb.append("uptime\n"); |
| 5717 | sb.append(prefix); sb.append(" Starts: "); |
| 5718 | sb.append(starts); |
| 5719 | sb.append(", launches: "); sb.append(launches); |
| 5720 | pw.println(sb.toString()); |
| 5721 | apkActivity = true; |
| 5722 | } |
| 5723 | } |
| 5724 | if (!apkActivity) { |
| 5725 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5726 | } |
| 5727 | uidActivity = true; |
| 5728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5730 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5731 | } |
| 5732 | } |
| 5733 | } |
| 5734 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5735 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5736 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5737 | int diff = oldval ^ newval; |
| 5738 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5739 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5740 | for (int i=0; i<descriptions.length; i++) { |
| 5741 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5742 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5743 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5744 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5745 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5746 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5747 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5748 | didWake = true; |
| 5749 | pw.print("="); |
| 5750 | if (longNames) { |
| 5751 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5752 | pw.print(":\""); |
| 5753 | pw.print(wakelockTag.string); |
| 5754 | pw.print("\""); |
| 5755 | } else { |
| 5756 | pw.print(wakelockTag.poolIdx); |
| 5757 | } |
| 5758 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5759 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5760 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5761 | pw.print("="); |
| 5762 | int val = (newval&bd.mask)>>bd.shift; |
| 5763 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5764 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5765 | } else { |
| 5766 | pw.print(val); |
| 5767 | } |
| 5768 | } |
| 5769 | } |
| 5770 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5771 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5772 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5773 | if (longNames) { |
| 5774 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5775 | pw.print(":\""); |
| 5776 | pw.print(wakelockTag.string); |
| 5777 | pw.print("\""); |
| 5778 | } else { |
| 5779 | pw.print(wakelockTag.poolIdx); |
| 5780 | } |
| 5781 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5782 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5783 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5784 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 5785 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | public static class HistoryPrinter { |
| 5789 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5790 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5791 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5792 | int oldStatus = -1; |
| 5793 | int oldHealth = -1; |
| 5794 | int oldPlug = -1; |
| 5795 | int oldTemp = -1; |
| 5796 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5797 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5798 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5799 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5800 | void reset() { |
| 5801 | oldState = oldState2 = 0; |
| 5802 | oldLevel = -1; |
| 5803 | oldStatus = -1; |
| 5804 | oldHealth = -1; |
| 5805 | oldPlug = -1; |
| 5806 | oldTemp = -1; |
| 5807 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5808 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5811 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5812 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5813 | if (!checkin) { |
| 5814 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5815 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5816 | pw.print(" ("); |
| 5817 | pw.print(rec.numReadInts); |
| 5818 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5819 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5820 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5821 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5822 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5823 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5824 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5825 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5826 | } |
| 5827 | lastTime = rec.time; |
| 5828 | } |
| 5829 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5830 | if (checkin) { |
| 5831 | pw.print(":"); |
| 5832 | } |
| 5833 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5834 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5835 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5836 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5837 | if (checkin) { |
| 5838 | pw.print(":"); |
| 5839 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5840 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5841 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5842 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5843 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5844 | pw.print("TIME:"); |
| 5845 | if (checkin) { |
| 5846 | pw.println(rec.currentTime); |
| 5847 | } else { |
| 5848 | pw.print(" "); |
| 5849 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5850 | rec.currentTime).toString()); |
| 5851 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5852 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5853 | if (checkin) { |
| 5854 | pw.print(":"); |
| 5855 | } |
| 5856 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5857 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5858 | if (checkin) { |
| 5859 | pw.print(":"); |
| 5860 | } |
| 5861 | pw.println("*OVERFLOW*"); |
| 5862 | } else { |
| 5863 | if (!checkin) { |
| 5864 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5865 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5866 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5867 | if (verbose) { |
| 5868 | pw.print(" "); |
| 5869 | if (rec.states < 0) ; |
| 5870 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5871 | else if (rec.states < 0x100) pw.print("000000"); |
| 5872 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5873 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5874 | else if (rec.states < 0x100000) pw.print("000"); |
| 5875 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5876 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5877 | pw.print(Integer.toHexString(rec.states)); |
| 5878 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5879 | } else { |
| 5880 | if (oldLevel != rec.batteryLevel) { |
| 5881 | oldLevel = rec.batteryLevel; |
| 5882 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5883 | } |
| 5884 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5885 | if (oldStatus != rec.batteryStatus) { |
| 5886 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5887 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5888 | switch (oldStatus) { |
| 5889 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5890 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5891 | break; |
| 5892 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5893 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5894 | break; |
| 5895 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5896 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5897 | break; |
| 5898 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5899 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5900 | break; |
| 5901 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5902 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5903 | break; |
| 5904 | default: |
| 5905 | pw.print(oldStatus); |
| 5906 | break; |
| 5907 | } |
| 5908 | } |
| 5909 | if (oldHealth != rec.batteryHealth) { |
| 5910 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5911 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5912 | switch (oldHealth) { |
| 5913 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5914 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5915 | break; |
| 5916 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5917 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5918 | break; |
| 5919 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5920 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5921 | break; |
| 5922 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5923 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5924 | break; |
| 5925 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5926 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5927 | break; |
| 5928 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5929 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5930 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5931 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5932 | pw.print(checkin ? "c" : "cold"); |
| 5933 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5934 | default: |
| 5935 | pw.print(oldHealth); |
| 5936 | break; |
| 5937 | } |
| 5938 | } |
| 5939 | if (oldPlug != rec.batteryPlugType) { |
| 5940 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5941 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5942 | switch (oldPlug) { |
| 5943 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5944 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5945 | break; |
| 5946 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5947 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5948 | break; |
| 5949 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5950 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5951 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5952 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5953 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5954 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5955 | default: |
| 5956 | pw.print(oldPlug); |
| 5957 | break; |
| 5958 | } |
| 5959 | } |
| 5960 | if (oldTemp != rec.batteryTemperature) { |
| 5961 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5962 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5963 | pw.print(oldTemp); |
| 5964 | } |
| 5965 | if (oldVolt != rec.batteryVoltage) { |
| 5966 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5967 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5968 | pw.print(oldVolt); |
| 5969 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5970 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5971 | if (oldChargeMAh != chargeMAh) { |
| 5972 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5973 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5974 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5975 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5976 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5977 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5978 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5979 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5980 | if (rec.wakeReasonTag != null) { |
| 5981 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5982 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5983 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5984 | } else { |
| 5985 | pw.print(" wake_reason="); |
| 5986 | pw.print(rec.wakeReasonTag.uid); |
| 5987 | pw.print(":\""); |
| 5988 | pw.print(rec.wakeReasonTag.string); |
| 5989 | pw.print("\""); |
| 5990 | } |
| 5991 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5992 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5993 | pw.print(checkin ? "," : " "); |
| 5994 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5995 | pw.print("+"); |
| 5996 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5997 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5998 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5999 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 6000 | : HISTORY_EVENT_NAMES; |
| 6001 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 6002 | | HistoryItem.EVENT_FLAG_FINISH); |
| 6003 | if (idx >= 0 && idx < eventNames.length) { |
| 6004 | pw.print(eventNames[idx]); |
| 6005 | } else { |
| 6006 | pw.print(checkin ? "Ev" : "event"); |
| 6007 | pw.print(idx); |
| 6008 | } |
| 6009 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6010 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6011 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6012 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 6013 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 6014 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6015 | pw.print(":\""); |
| 6016 | pw.print(rec.eventTag.string); |
| 6017 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6018 | } |
| 6019 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6020 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6021 | if (rec.stepDetails != null) { |
| 6022 | if (!checkin) { |
| 6023 | pw.print(" Details: cpu="); |
| 6024 | pw.print(rec.stepDetails.userTime); |
| 6025 | pw.print("u+"); |
| 6026 | pw.print(rec.stepDetails.systemTime); |
| 6027 | pw.print("s"); |
| 6028 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6029 | pw.print(" ("); |
| 6030 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 6031 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6032 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6033 | pw.print(", "); |
| 6034 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 6035 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6036 | } |
| 6037 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6038 | pw.print(", "); |
| 6039 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 6040 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6041 | } |
| 6042 | pw.print(')'); |
| 6043 | } |
| 6044 | pw.println(); |
| 6045 | pw.print(" /proc/stat="); |
| 6046 | pw.print(rec.stepDetails.statUserTime); |
| 6047 | pw.print(" usr, "); |
| 6048 | pw.print(rec.stepDetails.statSystemTime); |
| 6049 | pw.print(" sys, "); |
| 6050 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6051 | pw.print(" io, "); |
| 6052 | pw.print(rec.stepDetails.statIrqTime); |
| 6053 | pw.print(" irq, "); |
| 6054 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6055 | pw.print(" sirq, "); |
| 6056 | pw.print(rec.stepDetails.statIdlTime); |
| 6057 | pw.print(" idle"); |
| 6058 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 6059 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 6060 | + rec.stepDetails.statSoftIrqTime; |
| 6061 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 6062 | if (total > 0) { |
| 6063 | pw.print(" ("); |
| 6064 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 6065 | pw.print(String.format("%.1f%%", perc)); |
| 6066 | pw.print(" of "); |
| 6067 | StringBuilder sb = new StringBuilder(64); |
| 6068 | formatTimeMsNoSpace(sb, total*10); |
| 6069 | pw.print(sb); |
| 6070 | pw.print(")"); |
| 6071 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6072 | pw.print(", PlatformIdleStat "); |
| 6073 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6074 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6075 | |
| 6076 | pw.print(", SubsystemPowerState "); |
| 6077 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6078 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6079 | } else { |
| 6080 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6081 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 6082 | pw.print(rec.stepDetails.userTime); |
| 6083 | pw.print(":"); |
| 6084 | pw.print(rec.stepDetails.systemTime); |
| 6085 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 6086 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 6087 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 6088 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 6089 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 6090 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 6091 | } |
| 6092 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 6093 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 6094 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 6095 | } |
| 6096 | } |
| 6097 | pw.println(); |
| 6098 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6099 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 6100 | pw.print(rec.stepDetails.statUserTime); |
| 6101 | pw.print(','); |
| 6102 | pw.print(rec.stepDetails.statSystemTime); |
| 6103 | pw.print(','); |
| 6104 | pw.print(rec.stepDetails.statIOWaitTime); |
| 6105 | pw.print(','); |
| 6106 | pw.print(rec.stepDetails.statIrqTime); |
| 6107 | pw.print(','); |
| 6108 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 6109 | pw.print(','); |
| 6110 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 6111 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6112 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 6113 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 6114 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6115 | pw.print(','); |
| 6116 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 6117 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 6118 | |
| 6119 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 6120 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 6121 | } |
| 6122 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6123 | } |
| 6124 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6125 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6126 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6127 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6128 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6129 | |
| 6130 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6131 | UserHandle.formatUid(pw, uid); |
| 6132 | pw.print("="); |
| 6133 | pw.print(utime); |
| 6134 | pw.print("u+"); |
| 6135 | pw.print(stime); |
| 6136 | pw.print("s"); |
| 6137 | } |
| 6138 | |
| 6139 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 6140 | pw.print('/'); |
| 6141 | pw.print(uid); |
| 6142 | pw.print(":"); |
| 6143 | pw.print(utime); |
| 6144 | pw.print(":"); |
| 6145 | pw.print(stime); |
| 6146 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6147 | } |
| 6148 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6149 | private void printSizeValue(PrintWriter pw, long size) { |
| 6150 | float result = size; |
| 6151 | String suffix = ""; |
| 6152 | if (result >= 10*1024) { |
| 6153 | suffix = "KB"; |
| 6154 | result = result / 1024; |
| 6155 | } |
| 6156 | if (result >= 10*1024) { |
| 6157 | suffix = "MB"; |
| 6158 | result = result / 1024; |
| 6159 | } |
| 6160 | if (result >= 10*1024) { |
| 6161 | suffix = "GB"; |
| 6162 | result = result / 1024; |
| 6163 | } |
| 6164 | if (result >= 10*1024) { |
| 6165 | suffix = "TB"; |
| 6166 | result = result / 1024; |
| 6167 | } |
| 6168 | if (result >= 10*1024) { |
| 6169 | suffix = "PB"; |
| 6170 | result = result / 1024; |
| 6171 | } |
| 6172 | pw.print((int)result); |
| 6173 | pw.print(suffix); |
| 6174 | } |
| 6175 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6176 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 6177 | String label3, long estimatedTime) { |
| 6178 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6179 | return false; |
| 6180 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6181 | pw.print(label1); |
| 6182 | pw.print(label2); |
| 6183 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6184 | StringBuilder sb = new StringBuilder(64); |
| 6185 | formatTimeMs(sb, estimatedTime); |
| 6186 | pw.print(sb); |
| 6187 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 6188 | return true; |
| 6189 | } |
| 6190 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6191 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 6192 | LevelStepTracker steps, boolean checkin) { |
| 6193 | if (steps == null) { |
| 6194 | return false; |
| 6195 | } |
| 6196 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6197 | if (count <= 0) { |
| 6198 | return false; |
| 6199 | } |
| 6200 | if (!checkin) { |
| 6201 | pw.println(header); |
| 6202 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6203 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6204 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6205 | long duration = steps.getDurationAt(i); |
| 6206 | int level = steps.getLevelAt(i); |
| 6207 | long initMode = steps.getInitModeAt(i); |
| 6208 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6209 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6210 | lineArgs[0] = Long.toString(duration); |
| 6211 | lineArgs[1] = Integer.toString(level); |
| 6212 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6213 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6214 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 6215 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 6216 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 6217 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6218 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6219 | } |
| 6220 | } else { |
| 6221 | lineArgs[2] = ""; |
| 6222 | } |
| 6223 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6224 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 6225 | } else { |
| 6226 | lineArgs[3] = ""; |
| 6227 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6228 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6229 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6230 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6231 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6232 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6233 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6234 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6235 | pw.print(prefix); |
| 6236 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6237 | TimeUtils.formatDuration(duration, pw); |
| 6238 | pw.print(" to "); pw.print(level); |
| 6239 | boolean haveModes = false; |
| 6240 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6241 | pw.print(" ("); |
| 6242 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6243 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6244 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6245 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6246 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6247 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6248 | } |
| 6249 | haveModes = true; |
| 6250 | } |
| 6251 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6252 | pw.print(haveModes ? ", " : " ("); |
| 6253 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6254 | ? "power-save-on" : "power-save-off"); |
| 6255 | haveModes = true; |
| 6256 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6257 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6258 | pw.print(haveModes ? ", " : " ("); |
| 6259 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6260 | ? "device-idle-on" : "device-idle-off"); |
| 6261 | haveModes = true; |
| 6262 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6263 | if (haveModes) { |
| 6264 | pw.print(")"); |
| 6265 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6266 | pw.println(); |
| 6267 | } |
| 6268 | } |
| 6269 | return true; |
| 6270 | } |
| 6271 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6272 | private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId, |
| 6273 | LevelStepTracker steps) { |
| 6274 | if (steps == null) { |
| 6275 | return; |
| 6276 | } |
| 6277 | int count = steps.mNumStepDurations; |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6278 | for (int i = 0; i < count; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6279 | long token = proto.start(fieldId); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6280 | proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i)); |
| 6281 | proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i)); |
| 6282 | |
| 6283 | final long initMode = steps.getInitModeAt(i); |
| 6284 | final long modMode = steps.getModModeAt(i); |
| 6285 | |
| 6286 | int ds = SystemProto.BatteryLevelStep.DS_MIXED; |
| 6287 | if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6288 | switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6289 | case Display.STATE_OFF: |
| 6290 | ds = SystemProto.BatteryLevelStep.DS_OFF; |
| 6291 | break; |
| 6292 | case Display.STATE_ON: |
| 6293 | ds = SystemProto.BatteryLevelStep.DS_ON; |
| 6294 | break; |
| 6295 | case Display.STATE_DOZE: |
| 6296 | ds = SystemProto.BatteryLevelStep.DS_DOZE; |
| 6297 | break; |
| 6298 | case Display.STATE_DOZE_SUSPEND: |
| 6299 | ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND; |
| 6300 | break; |
| 6301 | default: |
| 6302 | ds = SystemProto.BatteryLevelStep.DS_ERROR; |
| 6303 | break; |
| 6304 | } |
| 6305 | } |
| 6306 | proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds); |
| 6307 | |
| 6308 | int psm = SystemProto.BatteryLevelStep.PSM_MIXED; |
| 6309 | if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6310 | psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6311 | ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF; |
| 6312 | } |
| 6313 | proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm); |
| 6314 | |
| 6315 | int im = SystemProto.BatteryLevelStep.IM_MIXED; |
| 6316 | if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6317 | im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6318 | ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF; |
| 6319 | } |
| 6320 | proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im); |
| 6321 | |
| 6322 | proto.end(token); |
| 6323 | } |
| 6324 | } |
| 6325 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6326 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6327 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6328 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6329 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6330 | public static final int DUMP_VERBOSE = 1<<5; |
| 6331 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6332 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6333 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6334 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6335 | final HistoryItem rec = new HistoryItem(); |
| 6336 | long lastTime = -1; |
| 6337 | long baseTime = -1; |
| 6338 | boolean printed = false; |
| 6339 | HistoryEventTracker tracker = null; |
| 6340 | while (getNextHistoryLocked(rec)) { |
| 6341 | lastTime = rec.time; |
| 6342 | if (baseTime < 0) { |
| 6343 | baseTime = lastTime; |
| 6344 | } |
| 6345 | if (rec.time >= histStart) { |
| 6346 | if (histStart >= 0 && !printed) { |
| 6347 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6348 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6349 | || rec.cmd == HistoryItem.CMD_START |
| 6350 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6351 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6352 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6353 | (flags&DUMP_VERBOSE) != 0); |
| 6354 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6355 | } else if (rec.currentTime != 0) { |
| 6356 | printed = true; |
| 6357 | byte cmd = rec.cmd; |
| 6358 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6359 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6360 | (flags&DUMP_VERBOSE) != 0); |
| 6361 | rec.cmd = cmd; |
| 6362 | } |
| 6363 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6364 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6365 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6366 | (flags&DUMP_VERBOSE) != 0); |
| 6367 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6368 | } |
| 6369 | int oldEventCode = rec.eventCode; |
| 6370 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6371 | rec.eventTag = new HistoryTag(); |
| 6372 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6373 | HashMap<String, SparseIntArray> active |
| 6374 | = tracker.getStateForEvent(i); |
| 6375 | if (active == null) { |
| 6376 | continue; |
| 6377 | } |
| 6378 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6379 | : active.entrySet()) { |
| 6380 | SparseIntArray uids = ent.getValue(); |
| 6381 | for (int j=0; j<uids.size(); j++) { |
| 6382 | rec.eventCode = i; |
| 6383 | rec.eventTag.string = ent.getKey(); |
| 6384 | rec.eventTag.uid = uids.keyAt(j); |
| 6385 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6386 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6387 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6388 | rec.wakeReasonTag = null; |
| 6389 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6390 | } |
| 6391 | } |
| 6392 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6393 | rec.eventCode = oldEventCode; |
| 6394 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6395 | tracker = null; |
| 6396 | } |
| 6397 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6398 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6399 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6400 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6401 | // This is an attempt to aggregate the previous state and generate |
| 6402 | //Â fake events to reflect that state at the point where we start |
| 6403 | // 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] | 6404 | if (tracker == null) { |
| 6405 | tracker = new HistoryEventTracker(); |
| 6406 | } |
| 6407 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6408 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6409 | } |
| 6410 | } |
| 6411 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6412 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6413 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6414 | } |
| 6415 | } |
| 6416 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6417 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6418 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6419 | if (steps == null) { |
| 6420 | return; |
| 6421 | } |
| 6422 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6423 | if (timeRemaining >= 0) { |
| 6424 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6425 | tmpSb.setLength(0); |
| 6426 | formatTimeMs(tmpSb, timeRemaining); |
| 6427 | pw.print(tmpSb); |
| 6428 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6429 | pw.println(" steps)"); |
| 6430 | } |
| 6431 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6432 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6433 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6434 | if (estimatedTime > 0) { |
| 6435 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6436 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6437 | pw.print(" time: "); |
| 6438 | tmpSb.setLength(0); |
| 6439 | formatTimeMs(tmpSb, estimatedTime); |
| 6440 | pw.print(tmpSb); |
| 6441 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6442 | pw.println(" steps)"); |
| 6443 | } |
| 6444 | } |
| 6445 | } |
| 6446 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6447 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6448 | ArrayList<PackageChange> changes) { |
| 6449 | if (changes == null) { |
| 6450 | return; |
| 6451 | } |
| 6452 | pw.print(prefix); pw.println("Package changes:"); |
| 6453 | for (int i=0; i<changes.size(); i++) { |
| 6454 | PackageChange pc = changes.get(i); |
| 6455 | if (pc.mUpdate) { |
| 6456 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6457 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6458 | } else { |
| 6459 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6460 | } |
| 6461 | } |
| 6462 | } |
| 6463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | /** |
| 6465 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6466 | * |
| 6467 | * @param pw a Printer to receive the dump output. |
| 6468 | */ |
| 6469 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6470 | 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] | 6471 | prepareForDumpLocked(); |
| 6472 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6473 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6474 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6475 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6476 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6477 | final long historyTotalSize = getHistoryTotalSize(); |
| 6478 | final long historyUsedSize = getHistoryUsedSize(); |
| 6479 | if (startIteratingHistoryLocked()) { |
| 6480 | try { |
| 6481 | pw.print("Battery History ("); |
| 6482 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6483 | pw.print("% used, "); |
| 6484 | printSizeValue(pw, historyUsedSize); |
| 6485 | pw.print(" used of "); |
| 6486 | printSizeValue(pw, historyTotalSize); |
| 6487 | pw.print(", "); |
| 6488 | pw.print(getHistoryStringPoolSize()); |
| 6489 | pw.print(" strings using "); |
| 6490 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6491 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6492 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6493 | pw.println(); |
| 6494 | } finally { |
| 6495 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6496 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6497 | } |
| 6498 | |
| 6499 | if (startIteratingOldHistoryLocked()) { |
| 6500 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6501 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6502 | pw.println("Old battery History:"); |
| 6503 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6504 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6505 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6506 | if (baseTime < 0) { |
| 6507 | baseTime = rec.time; |
| 6508 | } |
| 6509 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6510 | } |
| 6511 | pw.println(); |
| 6512 | } finally { |
| 6513 | finishIteratingOldHistoryLocked(); |
| 6514 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6515 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6516 | } |
| 6517 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6518 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6519 | return; |
| 6520 | } |
| 6521 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6522 | if (!filtering) { |
| 6523 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6524 | final int NU = uidStats.size(); |
| 6525 | boolean didPid = false; |
| 6526 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6527 | for (int i=0; i<NU; i++) { |
| 6528 | Uid uid = uidStats.valueAt(i); |
| 6529 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6530 | if (pids != null) { |
| 6531 | for (int j=0; j<pids.size(); j++) { |
| 6532 | Uid.Pid pid = pids.valueAt(j); |
| 6533 | if (!didPid) { |
| 6534 | pw.println("Per-PID Stats:"); |
| 6535 | didPid = true; |
| 6536 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6537 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6538 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6539 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6540 | pw.print(" wake time: "); |
| 6541 | TimeUtils.formatDuration(time, pw); |
| 6542 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6543 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6544 | } |
| 6545 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6546 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6547 | pw.println(); |
| 6548 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6552 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6553 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6554 | long timeRemaining = computeBatteryTimeRemaining( |
| 6555 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6556 | if (timeRemaining >= 0) { |
| 6557 | pw.print(" Estimated discharge time remaining: "); |
| 6558 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6559 | pw.println(); |
| 6560 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6561 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6562 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6563 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6564 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6565 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6566 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6567 | pw.println(); |
| 6568 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6569 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6570 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6571 | long timeRemaining = computeChargeTimeRemaining( |
| 6572 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6573 | if (timeRemaining >= 0) { |
| 6574 | pw.print(" Estimated charge time remaining: "); |
| 6575 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6576 | pw.println(); |
| 6577 | } |
| 6578 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6579 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6580 | } |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 6581 | if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6582 | pw.println("Daily stats:"); |
| 6583 | pw.print(" Current start time: "); |
| 6584 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6585 | getCurrentDailyStartTime()).toString()); |
| 6586 | pw.print(" Next min deadline: "); |
| 6587 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6588 | getNextMinDailyDeadline()).toString()); |
| 6589 | pw.print(" Next max deadline: "); |
| 6590 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6591 | getNextMaxDailyDeadline()).toString()); |
| 6592 | StringBuilder sb = new StringBuilder(64); |
| 6593 | int[] outInt = new int[1]; |
| 6594 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6595 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6596 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6597 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6598 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6599 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6600 | dsteps, false)) { |
| 6601 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6602 | sb, outInt); |
| 6603 | } |
| 6604 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6605 | csteps, false)) { |
| 6606 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6607 | sb, outInt); |
| 6608 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6609 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6610 | } else { |
| 6611 | pw.println(" Current daily steps:"); |
| 6612 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6613 | sb, outInt); |
| 6614 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6615 | sb, outInt); |
| 6616 | } |
| 6617 | } |
| 6618 | DailyItem dit; |
| 6619 | int curIndex = 0; |
| 6620 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6621 | curIndex++; |
| 6622 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6623 | pw.println(); |
| 6624 | } |
| 6625 | pw.print(" Daily from "); |
| 6626 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6627 | pw.print(" to "); |
| 6628 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6629 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6630 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6631 | if (dumpDurationSteps(pw, " ", |
| 6632 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6633 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6634 | sb, outInt); |
| 6635 | } |
| 6636 | if (dumpDurationSteps(pw, " ", |
| 6637 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6638 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6639 | sb, outInt); |
| 6640 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6641 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6642 | } else { |
| 6643 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6644 | sb, outInt); |
| 6645 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6646 | sb, outInt); |
| 6647 | } |
| 6648 | } |
| 6649 | pw.println(); |
| 6650 | } |
| 6651 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6652 | pw.println("Statistics since last charge:"); |
| 6653 | pw.println(" System starts: " + getStartCount() |
| 6654 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6655 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6656 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6657 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6660 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6661 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6663 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6664 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6665 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6666 | |
| 6667 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6668 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6669 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6670 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6671 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6672 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6673 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6674 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6675 | try { |
| 6676 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6677 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6678 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6679 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6680 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6681 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6682 | pw.print(",\""); |
| 6683 | String str = getHistoryTagPoolString(i); |
| 6684 | str = str.replace("\\", "\\\\"); |
| 6685 | str = str.replace("\"", "\\\""); |
| 6686 | pw.print(str); |
| 6687 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6688 | pw.println(); |
| 6689 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6690 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6691 | } finally { |
| 6692 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6693 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6694 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6695 | } |
| 6696 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6697 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6698 | return; |
| 6699 | } |
| 6700 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6701 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6702 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6703 | for (int i=0; i<apps.size(); i++) { |
| 6704 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6705 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6706 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6707 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6708 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6709 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6710 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6711 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6712 | } |
| 6713 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6714 | final int NU = uidStats.size(); |
| 6715 | String[] lineArgs = new String[2]; |
| 6716 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6717 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6718 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6719 | if (pkgs != null && !pkgs.second.value) { |
| 6720 | pkgs.second.value = true; |
| 6721 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6722 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6723 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6724 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6725 | (Object[])lineArgs); |
| 6726 | } |
| 6727 | } |
| 6728 | } |
| 6729 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6730 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6731 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6732 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6733 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6734 | if (timeRemaining >= 0) { |
| 6735 | lineArgs[0] = Long.toString(timeRemaining); |
| 6736 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6737 | (Object[])lineArgs); |
| 6738 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6739 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6740 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6741 | if (timeRemaining >= 0) { |
| 6742 | lineArgs[0] = Long.toString(timeRemaining); |
| 6743 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6744 | (Object[])lineArgs); |
| 6745 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6746 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6747 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6750 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6751 | /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6752 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6753 | int flags) { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6754 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6755 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6756 | prepareForDumpLocked(); |
| 6757 | |
| 6758 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6759 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6760 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6761 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6762 | |
Kweku Adams | 6ccebf2 | 2017-12-11 12:30:35 -0800 | [diff] [blame] | 6763 | // History intentionally not included in proto dump. |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6764 | |
| 6765 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6766 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, |
| 6767 | (flags & DUMP_DEVICE_WIFI_ONLY) != 0); |
| 6768 | helper.create(this); |
| 6769 | helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL); |
| 6770 | |
| 6771 | dumpProtoAppsLocked(proto, helper, apps); |
| 6772 | dumpProtoSystemLocked(proto, helper); |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | proto.end(bToken); |
| 6776 | proto.flush(); |
| 6777 | } |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6778 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 6779 | private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper, |
| 6780 | List<ApplicationInfo> apps) { |
| 6781 | final int which = STATS_SINCE_CHARGED; |
| 6782 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 6783 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 6784 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 6785 | final long batteryUptimeUs = getBatteryUptime(rawUptimeUs); |
| 6786 | |
| 6787 | SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>(); |
| 6788 | if (apps != null) { |
| 6789 | for (int i = 0; i < apps.size(); ++i) { |
| 6790 | ApplicationInfo ai = apps.get(i); |
| 6791 | int aid = UserHandle.getAppId(ai.uid); |
| 6792 | ArrayList<String> pkgs = aidToPackages.get(aid); |
| 6793 | if (pkgs == null) { |
| 6794 | pkgs = new ArrayList<String>(); |
| 6795 | aidToPackages.put(aid, pkgs); |
| 6796 | } |
| 6797 | pkgs.add(ai.packageName); |
| 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | SparseArray<BatterySipper> uidToSipper = new SparseArray<>(); |
| 6802 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 6803 | if (sippers != null) { |
| 6804 | for (int i = 0; i < sippers.size(); ++i) { |
| 6805 | final BatterySipper bs = sippers.get(i); |
| 6806 | if (bs.drainType != BatterySipper.DrainType.APP) { |
| 6807 | // Others are handled by dumpProtoSystemLocked() |
| 6808 | continue; |
| 6809 | } |
| 6810 | uidToSipper.put(bs.uidObj.getUid(), bs); |
| 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6815 | final int n = uidStats.size(); |
| 6816 | for (int iu = 0; iu < n; ++iu) { |
| 6817 | final long uTkn = proto.start(BatteryStatsProto.UIDS); |
| 6818 | final Uid u = uidStats.valueAt(iu); |
| 6819 | |
| 6820 | final int uid = uidStats.keyAt(iu); |
| 6821 | proto.write(UidProto.UID, uid); |
| 6822 | |
| 6823 | // Print packages and apk stats (UID_DATA & APK_DATA) |
| 6824 | ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid)); |
| 6825 | if (pkgs == null) { |
| 6826 | pkgs = new ArrayList<String>(); |
| 6827 | } |
| 6828 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = |
| 6829 | u.getPackageStats(); |
| 6830 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 6831 | String pkg = packageStats.keyAt(ipkg); |
| 6832 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = |
| 6833 | packageStats.valueAt(ipkg).getServiceStats(); |
| 6834 | if (serviceStats.size() == 0) { |
| 6835 | // Due to the way ActivityManagerService logs wakeup alarms, some packages (for |
| 6836 | // example, "android") may be included in the packageStats that aren't part of |
| 6837 | // the UID. If they don't have any services, then they shouldn't be listed here. |
| 6838 | // These packages won't be a part in the pkgs List. |
| 6839 | continue; |
| 6840 | } |
| 6841 | |
| 6842 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6843 | proto.write(UidProto.Package.NAME, pkg); |
| 6844 | // Remove from the packages list since we're logging it here. |
| 6845 | pkgs.remove(pkg); |
| 6846 | |
| 6847 | for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) { |
| 6848 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 6849 | long sToken = proto.start(UidProto.Package.SERVICES); |
| 6850 | |
| 6851 | proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc)); |
| 6852 | proto.write(UidProto.Package.Service.START_DURATION_MS, |
| 6853 | roundUsToMs(ss.getStartTime(batteryUptimeUs, which))); |
| 6854 | proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which)); |
| 6855 | proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which)); |
| 6856 | |
| 6857 | proto.end(sToken); |
| 6858 | } |
| 6859 | proto.end(pToken); |
| 6860 | } |
| 6861 | // Print any remaining packages that weren't in the packageStats map. pkgs is pulled |
| 6862 | // from PackageManager data. Packages are only included in packageStats if there was |
| 6863 | // specific data tracked for them (services and wakeup alarms, etc.). |
| 6864 | for (String p : pkgs) { |
| 6865 | final long pToken = proto.start(UidProto.PACKAGES); |
| 6866 | proto.write(UidProto.Package.NAME, p); |
| 6867 | proto.end(pToken); |
| 6868 | } |
| 6869 | |
| 6870 | // Total wakelock data (AGGREGATED_WAKELOCK_DATA) |
| 6871 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 6872 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 6873 | // Times are since reset (regardless of 'which') |
| 6874 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 6875 | final Timer bgTimer = timer.getSubTimer(); |
| 6876 | final long bgTimeMs = bgTimer != null |
| 6877 | ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 6878 | final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK); |
| 6879 | proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs); |
| 6880 | proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs); |
| 6881 | proto.end(awToken); |
| 6882 | } |
| 6883 | |
| 6884 | // Audio (AUDIO_DATA) |
| 6885 | dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which); |
| 6886 | |
| 6887 | // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA) |
| 6888 | dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER, |
| 6889 | u.getBluetoothControllerActivity(), which); |
| 6890 | |
| 6891 | // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked) |
| 6892 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 6893 | if (bleTimer != null) { |
| 6894 | final long bmToken = proto.start(UidProto.BLUETOOTH_MISC); |
| 6895 | |
| 6896 | dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer, |
| 6897 | rawRealtimeUs, which); |
| 6898 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN, |
| 6899 | u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which); |
| 6900 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 6901 | dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN, |
| 6902 | u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which); |
| 6903 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 6904 | dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN, |
| 6905 | u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which); |
| 6906 | // Result counters |
| 6907 | proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT, |
| 6908 | u.getBluetoothScanResultCounter() != null |
| 6909 | ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0); |
| 6910 | proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT, |
| 6911 | u.getBluetoothScanResultBgCounter() != null |
| 6912 | ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0); |
| 6913 | |
| 6914 | proto.end(bmToken); |
| 6915 | } |
| 6916 | |
| 6917 | // Camera (CAMERA_DATA) |
| 6918 | dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which); |
| 6919 | |
| 6920 | // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA) |
| 6921 | final long cpuToken = proto.start(UidProto.CPU); |
| 6922 | proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which))); |
| 6923 | proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which))); |
| 6924 | |
| 6925 | final long[] cpuFreqs = getCpuFreqs(); |
| 6926 | if (cpuFreqs != null) { |
| 6927 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 6928 | // If total cpuFreqTimes is null, then we don't need to check for |
| 6929 | // screenOffCpuFreqTimes. |
| 6930 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 6931 | long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 6932 | if (screenOffCpuFreqTimeMs == null) { |
| 6933 | screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length]; |
| 6934 | } |
| 6935 | for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) { |
| 6936 | long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY); |
| 6937 | proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1); |
| 6938 | proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS, |
| 6939 | cpuFreqTimeMs[ic]); |
| 6940 | proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS, |
| 6941 | screenOffCpuFreqTimeMs[ic]); |
| 6942 | proto.end(cToken); |
| 6943 | } |
| 6944 | } |
| 6945 | } |
| 6946 | proto.end(cpuToken); |
| 6947 | |
| 6948 | // Flashlight (FLASHLIGHT_DATA) |
| 6949 | dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(), |
| 6950 | rawRealtimeUs, which); |
| 6951 | |
| 6952 | // Foreground activity (FOREGROUND_ACTIVITY_DATA) |
| 6953 | dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(), |
| 6954 | rawRealtimeUs, which); |
| 6955 | |
| 6956 | // Foreground service (FOREGROUND_SERVICE_DATA) |
| 6957 | dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(), |
| 6958 | rawRealtimeUs, which); |
| 6959 | |
| 6960 | // Job completion (JOB_COMPLETION_DATA) |
| 6961 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 6962 | final int[] reasons = new int[]{ |
| 6963 | JobParameters.REASON_CANCELED, |
| 6964 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, |
| 6965 | JobParameters.REASON_PREEMPT, |
| 6966 | JobParameters.REASON_TIMEOUT, |
| 6967 | JobParameters.REASON_DEVICE_IDLE, |
| 6968 | }; |
| 6969 | for (int ic = 0; ic < completions.size(); ++ic) { |
| 6970 | SparseIntArray types = completions.valueAt(ic); |
| 6971 | if (types != null) { |
| 6972 | final long jcToken = proto.start(UidProto.JOB_COMPLETION); |
| 6973 | |
| 6974 | proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic)); |
| 6975 | |
| 6976 | for (int r : reasons) { |
| 6977 | long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT); |
| 6978 | proto.write(UidProto.JobCompletion.ReasonCount.NAME, r); |
| 6979 | proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0)); |
| 6980 | proto.end(rToken); |
| 6981 | } |
| 6982 | |
| 6983 | proto.end(jcToken); |
| 6984 | } |
| 6985 | } |
| 6986 | |
| 6987 | // Scheduled jobs (JOB_DATA) |
| 6988 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 6989 | for (int ij = jobs.size() - 1; ij >= 0; --ij) { |
| 6990 | final Timer timer = jobs.valueAt(ij); |
| 6991 | final Timer bgTimer = timer.getSubTimer(); |
| 6992 | final long jToken = proto.start(UidProto.JOBS); |
| 6993 | |
| 6994 | proto.write(UidProto.Job.NAME, jobs.keyAt(ij)); |
| 6995 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 6996 | dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which); |
| 6997 | dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 6998 | |
| 6999 | proto.end(jToken); |
| 7000 | } |
| 7001 | |
| 7002 | // Modem Controller (MODEM_CONTROLLER_DATA) |
| 7003 | dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER, |
| 7004 | u.getModemControllerActivity(), which); |
| 7005 | |
| 7006 | // Network stats (NETWORK_DATA) |
| 7007 | final long nToken = proto.start(UidProto.NETWORK); |
| 7008 | proto.write(UidProto.Network.MOBILE_BYTES_RX, |
| 7009 | u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7010 | proto.write(UidProto.Network.MOBILE_BYTES_TX, |
| 7011 | u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7012 | proto.write(UidProto.Network.WIFI_BYTES_RX, |
| 7013 | u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7014 | proto.write(UidProto.Network.WIFI_BYTES_TX, |
| 7015 | u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7016 | proto.write(UidProto.Network.BT_BYTES_RX, |
| 7017 | u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7018 | proto.write(UidProto.Network.BT_BYTES_TX, |
| 7019 | u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
| 7020 | proto.write(UidProto.Network.MOBILE_PACKETS_RX, |
| 7021 | u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7022 | proto.write(UidProto.Network.MOBILE_PACKETS_TX, |
| 7023 | u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7024 | proto.write(UidProto.Network.WIFI_PACKETS_RX, |
| 7025 | u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7026 | proto.write(UidProto.Network.WIFI_PACKETS_TX, |
| 7027 | u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7028 | proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS, |
| 7029 | roundUsToMs(u.getMobileRadioActiveTime(which))); |
| 7030 | proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT, |
| 7031 | u.getMobileRadioActiveCount(which)); |
| 7032 | proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT, |
| 7033 | u.getMobileRadioApWakeupCount(which)); |
| 7034 | proto.write(UidProto.Network.WIFI_WAKEUP_COUNT, |
| 7035 | u.getWifiRadioApWakeupCount(which)); |
| 7036 | proto.write(UidProto.Network.MOBILE_BYTES_BG_RX, |
| 7037 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7038 | proto.write(UidProto.Network.MOBILE_BYTES_BG_TX, |
| 7039 | u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7040 | proto.write(UidProto.Network.WIFI_BYTES_BG_RX, |
| 7041 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7042 | proto.write(UidProto.Network.WIFI_BYTES_BG_TX, |
| 7043 | u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7044 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX, |
| 7045 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which)); |
| 7046 | proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX, |
| 7047 | u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which)); |
| 7048 | proto.write(UidProto.Network.WIFI_PACKETS_BG_RX, |
| 7049 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which)); |
| 7050 | proto.write(UidProto.Network.WIFI_PACKETS_BG_TX, |
| 7051 | u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which)); |
| 7052 | proto.end(nToken); |
| 7053 | |
| 7054 | // Power use item (POWER_USE_ITEM_DATA) |
| 7055 | BatterySipper bs = uidToSipper.get(uid); |
| 7056 | if (bs != null) { |
| 7057 | final long bsToken = proto.start(UidProto.POWER_USE_ITEM); |
| 7058 | proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7059 | proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7060 | proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7061 | proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7062 | bs.proportionalSmearMah); |
| 7063 | proto.end(bsToken); |
| 7064 | } |
| 7065 | |
| 7066 | // Processes (PROCESS_DATA) |
| 7067 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = |
| 7068 | u.getProcessStats(); |
| 7069 | for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) { |
| 7070 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 7071 | final long prToken = proto.start(UidProto.PROCESS); |
| 7072 | |
| 7073 | proto.write(UidProto.Process.NAME, processStats.keyAt(ipr)); |
| 7074 | proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which)); |
| 7075 | proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which)); |
| 7076 | proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which)); |
| 7077 | proto.write(UidProto.Process.START_COUNT, ps.getStarts(which)); |
| 7078 | proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which)); |
| 7079 | proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which)); |
| 7080 | |
| 7081 | proto.end(prToken); |
| 7082 | } |
| 7083 | |
| 7084 | // Sensors (SENSOR_DATA) |
| 7085 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 7086 | for (int ise = 0; ise < sensors.size(); ++ise) { |
| 7087 | final Uid.Sensor se = sensors.valueAt(ise); |
| 7088 | final Timer timer = se.getSensorTime(); |
| 7089 | if (timer == null) { |
| 7090 | continue; |
| 7091 | } |
| 7092 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 7093 | final int sensorNumber = sensors.keyAt(ise); |
| 7094 | final long seToken = proto.start(UidProto.SENSORS); |
| 7095 | |
| 7096 | proto.write(UidProto.Sensor.ID, sensorNumber); |
| 7097 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7098 | dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which); |
| 7099 | dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7100 | |
| 7101 | proto.end(seToken); |
| 7102 | } |
| 7103 | |
| 7104 | // State times (STATE_TIME_DATA) |
| 7105 | for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) { |
| 7106 | long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which)); |
| 7107 | if (durMs == 0) { |
| 7108 | continue; |
| 7109 | } |
| 7110 | final long stToken = proto.start(UidProto.STATES); |
| 7111 | proto.write(UidProto.StateTime.STATE, ips); |
| 7112 | proto.write(UidProto.StateTime.DURATION_MS, durMs); |
| 7113 | proto.end(stToken); |
| 7114 | } |
| 7115 | |
| 7116 | // Syncs (SYNC_DATA) |
| 7117 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 7118 | for (int isy = syncs.size() - 1; isy >= 0; --isy) { |
| 7119 | final Timer timer = syncs.valueAt(isy); |
| 7120 | final Timer bgTimer = timer.getSubTimer(); |
| 7121 | final long syToken = proto.start(UidProto.SYNCS); |
| 7122 | |
| 7123 | proto.write(UidProto.Sync.NAME, syncs.keyAt(isy)); |
| 7124 | // Background uses totalDurationMsLocked, while total uses totalTimeLocked |
| 7125 | dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which); |
| 7126 | dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which); |
| 7127 | |
| 7128 | proto.end(syToken); |
| 7129 | } |
| 7130 | |
| 7131 | // User activity (USER_ACTIVITY_DATA) |
| 7132 | if (u.hasUserActivity()) { |
| 7133 | for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) { |
| 7134 | int val = u.getUserActivityCount(i, which); |
| 7135 | if (val != 0) { |
| 7136 | final long uaToken = proto.start(UidProto.USER_ACTIVITY); |
| 7137 | proto.write(UidProto.UserActivity.NAME, i); |
| 7138 | proto.write(UidProto.UserActivity.COUNT, val); |
| 7139 | proto.end(uaToken); |
| 7140 | } |
| 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | // Vibrator (VIBRATOR_DATA) |
| 7145 | dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which); |
| 7146 | |
| 7147 | // Video (VIDEO_DATA) |
| 7148 | dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which); |
| 7149 | |
| 7150 | // Wakelocks (WAKELOCK_DATA) |
| 7151 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 7152 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7153 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7154 | final long wToken = proto.start(UidProto.WAKELOCKS); |
| 7155 | proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw)); |
| 7156 | dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL), |
| 7157 | rawRealtimeUs, which); |
| 7158 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7159 | if (pTimer != null) { |
| 7160 | dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which); |
| 7161 | dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(), |
| 7162 | rawRealtimeUs, which); |
| 7163 | } |
| 7164 | dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 7165 | rawRealtimeUs, which); |
| 7166 | proto.end(wToken); |
| 7167 | } |
| 7168 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7169 | // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) |
| 7170 | dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), |
| 7171 | rawRealtimeUs, which); |
| 7172 | |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7173 | // Wakeup alarms (WAKEUP_ALARM_DATA) |
| 7174 | for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { |
| 7175 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 7176 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 7177 | for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) { |
| 7178 | final long waToken = proto.start(UidProto.WAKEUP_ALARM); |
| 7179 | proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa)); |
| 7180 | proto.write(UidProto.WakeupAlarm.COUNT, |
| 7181 | alarms.valueAt(iwa).getCountLocked(which)); |
| 7182 | proto.end(waToken); |
| 7183 | } |
| 7184 | } |
| 7185 | |
| 7186 | // Wifi Controller (WIFI_CONTROLLER_DATA) |
| 7187 | dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER, |
| 7188 | u.getWifiControllerActivity(), which); |
| 7189 | |
| 7190 | // Wifi data (WIFI_DATA) |
| 7191 | final long wToken = proto.start(UidProto.WIFI); |
| 7192 | proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS, |
| 7193 | roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which))); |
| 7194 | dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(), |
| 7195 | rawRealtimeUs, which); |
| 7196 | proto.write(UidProto.Wifi.RUNNING_DURATION_MS, |
| 7197 | roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which))); |
| 7198 | dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(), |
| 7199 | rawRealtimeUs, which); |
| 7200 | proto.end(wToken); |
| 7201 | |
| 7202 | proto.end(uTkn); |
| 7203 | } |
| 7204 | } |
| 7205 | |
| 7206 | private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) { |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7207 | final long sToken = proto.start(BatteryStatsProto.SYSTEM); |
| 7208 | final long rawUptimeUs = SystemClock.uptimeMillis() * 1000; |
| 7209 | final long rawRealtimeMs = SystemClock.elapsedRealtime(); |
| 7210 | final long rawRealtimeUs = rawRealtimeMs * 1000; |
| 7211 | final int which = STATS_SINCE_CHARGED; |
| 7212 | |
| 7213 | // Battery data (BATTERY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7214 | final long bToken = proto.start(SystemProto.BATTERY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7215 | proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime()); |
| 7216 | proto.write(SystemProto.Battery.START_COUNT, getStartCount()); |
| 7217 | proto.write(SystemProto.Battery.TOTAL_REALTIME_MS, |
| 7218 | computeRealtime(rawRealtimeUs, which) / 1000); |
| 7219 | proto.write(SystemProto.Battery.TOTAL_UPTIME_MS, |
| 7220 | computeUptime(rawUptimeUs, which) / 1000); |
| 7221 | proto.write(SystemProto.Battery.BATTERY_REALTIME_MS, |
| 7222 | computeBatteryRealtime(rawRealtimeUs, which) / 1000); |
| 7223 | proto.write(SystemProto.Battery.BATTERY_UPTIME_MS, |
| 7224 | computeBatteryUptime(rawUptimeUs, which) / 1000); |
| 7225 | proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS, |
| 7226 | computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000); |
| 7227 | proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS, |
| 7228 | computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000); |
| 7229 | proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS, |
| 7230 | getScreenDozeTime(rawRealtimeUs, which) / 1000); |
| 7231 | proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH, |
| 7232 | getEstimatedBatteryCapacity()); |
| 7233 | proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH, |
| 7234 | getMinLearnedBatteryCapacity()); |
| 7235 | proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH, |
| 7236 | getMaxLearnedBatteryCapacity()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7237 | proto.end(bToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7238 | |
| 7239 | // Battery discharge (BATTERY_DISCHARGE_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7240 | final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7241 | proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE, |
| 7242 | getLowDischargeAmountSinceCharge()); |
| 7243 | proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE, |
| 7244 | getHighDischargeAmountSinceCharge()); |
| 7245 | proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE, |
| 7246 | getDischargeAmountScreenOnSinceCharge()); |
| 7247 | proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE, |
| 7248 | getDischargeAmountScreenOffSinceCharge()); |
| 7249 | proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE, |
| 7250 | getDischargeAmountScreenDozeSinceCharge()); |
| 7251 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH, |
| 7252 | getUahDischarge(which) / 1000); |
| 7253 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF, |
| 7254 | getUahDischargeScreenOff(which) / 1000); |
| 7255 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE, |
| 7256 | getUahDischargeScreenDoze(which) / 1000); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 7257 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE, |
| 7258 | getUahDischargeLightDoze(which) / 1000); |
| 7259 | proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE, |
| 7260 | getUahDischargeDeepDoze(which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7261 | proto.end(bdToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7262 | |
| 7263 | // Time remaining |
| 7264 | long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7265 | // 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] | 7266 | if (timeRemainingUs >= 0) { |
| 7267 | // Charge time remaining (CHARGE_TIME_REMAIN_DATA) |
| 7268 | proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7269 | } else { |
| 7270 | timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs); |
| 7271 | // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA) |
| 7272 | if (timeRemainingUs >= 0) { |
| 7273 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000); |
| 7274 | } else { |
| 7275 | proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1); |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | // Charge step (CHARGE_STEP_DATA) |
| 7280 | dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker()); |
| 7281 | |
| 7282 | // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA) |
| 7283 | for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7284 | final long pdcToken = proto.start(SystemProto.DATA_CONNECTION); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7285 | proto.write(SystemProto.DataConnection.NAME, i); |
| 7286 | dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i), |
| 7287 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7288 | proto.end(pdcToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7289 | } |
| 7290 | |
| 7291 | // Discharge step (DISCHARGE_STEP_DATA) |
| 7292 | dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker()); |
| 7293 | |
| 7294 | // CPU frequencies (GLOBAL_CPU_FREQ_DATA) |
| 7295 | final long[] cpuFreqs = getCpuFreqs(); |
| 7296 | if (cpuFreqs != null) { |
| 7297 | for (long i : cpuFreqs) { |
| 7298 | proto.write(SystemProto.CPU_FREQUENCY, i); |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA) |
| 7303 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER, |
| 7304 | getBluetoothControllerActivity(), which); |
| 7305 | |
| 7306 | // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA) |
| 7307 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER, |
| 7308 | getModemControllerActivity(), which); |
| 7309 | |
| 7310 | // Global network data (GLOBAL_NETWORK_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7311 | final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7312 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX, |
| 7313 | getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 7314 | proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX, |
| 7315 | getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 7316 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX, |
| 7317 | getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 7318 | proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX, |
| 7319 | getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 7320 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX, |
| 7321 | getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 7322 | proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX, |
| 7323 | getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 7324 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX, |
| 7325 | getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 7326 | proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX, |
| 7327 | getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 7328 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX, |
| 7329 | getNetworkActivityBytes(NETWORK_BT_RX_DATA, which)); |
| 7330 | proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX, |
| 7331 | getNetworkActivityBytes(NETWORK_BT_TX_DATA, which)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7332 | proto.end(gnToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7333 | |
| 7334 | // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA) |
| 7335 | dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER, |
| 7336 | getWifiControllerActivity(), which); |
| 7337 | |
| 7338 | |
| 7339 | // Global wifi (GLOBAL_WIFI_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7340 | final long gwToken = proto.start(SystemProto.GLOBAL_WIFI); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7341 | proto.write(SystemProto.GlobalWifi.ON_DURATION_MS, |
| 7342 | getWifiOnTime(rawRealtimeUs, which) / 1000); |
| 7343 | proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS, |
| 7344 | getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7345 | proto.end(gwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7346 | |
| 7347 | // Kernel wakelock (KERNEL_WAKELOCK_DATA) |
| 7348 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
| 7349 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7350 | final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7351 | proto.write(SystemProto.KernelWakelock.NAME, ent.getKey()); |
| 7352 | dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(), |
| 7353 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7354 | proto.end(kwToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7355 | } |
| 7356 | |
| 7357 | // Misc (MISC_DATA) |
| 7358 | // Calculate wakelock times across all uids. |
| 7359 | long fullWakeLockTimeTotalUs = 0; |
| 7360 | long partialWakeLockTimeTotalUs = 0; |
| 7361 | |
| 7362 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
| 7363 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7364 | final Uid u = uidStats.valueAt(iu); |
| 7365 | |
| 7366 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = |
| 7367 | u.getWakelockStats(); |
| 7368 | for (int iw = wakelocks.size() - 1; iw >= 0; --iw) { |
| 7369 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 7370 | |
| 7371 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 7372 | if (fullWakeTimer != null) { |
| 7373 | fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs, |
| 7374 | which); |
| 7375 | } |
| 7376 | |
| 7377 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 7378 | if (partialWakeTimer != null) { |
| 7379 | partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked( |
| 7380 | rawRealtimeUs, which); |
| 7381 | } |
| 7382 | } |
| 7383 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7384 | final long mToken = proto.start(SystemProto.MISC); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7385 | proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS, |
| 7386 | getScreenOnTime(rawRealtimeUs, which) / 1000); |
| 7387 | proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS, |
| 7388 | getPhoneOnTime(rawRealtimeUs, which) / 1000); |
| 7389 | proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS, |
| 7390 | fullWakeLockTimeTotalUs / 1000); |
| 7391 | proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS, |
| 7392 | partialWakeLockTimeTotalUs / 1000); |
| 7393 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS, |
| 7394 | getMobileRadioActiveTime(rawRealtimeUs, which) / 1000); |
| 7395 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS, |
| 7396 | getMobileRadioActiveAdjustedTime(which) / 1000); |
| 7397 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT, |
| 7398 | getMobileRadioActiveCount(which)); |
| 7399 | proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS, |
| 7400 | getMobileRadioActiveUnknownTime(which) / 1000); |
| 7401 | proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS, |
| 7402 | getInteractiveTime(rawRealtimeUs, which) / 1000); |
| 7403 | proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS, |
| 7404 | getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000); |
| 7405 | proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES, |
| 7406 | getNumConnectivityChange(which)); |
| 7407 | proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS, |
| 7408 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7409 | proto.write(SystemProto.Misc.DEEP_DOZE_COUNT, |
| 7410 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7411 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS, |
| 7412 | getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000); |
| 7413 | proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT, |
| 7414 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
| 7415 | proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS, |
| 7416 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
| 7417 | proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS, |
| 7418 | getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7419 | proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT, |
| 7420 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7421 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS, |
| 7422 | getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000); |
| 7423 | proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT, |
| 7424 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
| 7425 | proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS, |
| 7426 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7427 | proto.end(mToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7428 | |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7429 | // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) |
| 7430 | // Calculate multicast wakelock stats across all uids. |
| 7431 | long multicastWakeLockTimeTotalUs = 0; |
| 7432 | int multicastWakeLockCountTotal = 0; |
| 7433 | |
| 7434 | for (int iu = 0; iu < uidStats.size(); iu++) { |
| 7435 | final Uid u = uidStats.valueAt(iu); |
| 7436 | |
| 7437 | final Timer mcTimer = u.getMulticastWakelockStats(); |
| 7438 | |
| 7439 | if (mcTimer != null) { |
| 7440 | multicastWakeLockTimeTotalUs += |
| 7441 | mcTimer.getTotalTimeLocked(rawRealtimeUs, which); |
| 7442 | multicastWakeLockCountTotal += mcTimer.getCountLocked(which); |
| 7443 | } |
| 7444 | } |
| 7445 | |
| 7446 | final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); |
| 7447 | proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, |
| 7448 | multicastWakeLockTimeTotalUs / 1000); |
| 7449 | proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, |
| 7450 | multicastWakeLockCountTotal); |
| 7451 | proto.end(wmctToken); |
| 7452 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7453 | // Power use item (POWER_USE_ITEM_DATA) |
| 7454 | final List<BatterySipper> sippers = helper.getUsageList(); |
| 7455 | if (sippers != null) { |
| 7456 | for (int i = 0; i < sippers.size(); ++i) { |
| 7457 | final BatterySipper bs = sippers.get(i); |
| 7458 | int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER; |
| 7459 | int uid = 0; |
| 7460 | switch (bs.drainType) { |
| 7461 | case IDLE: |
| 7462 | n = SystemProto.PowerUseItem.IDLE; |
| 7463 | break; |
| 7464 | case CELL: |
| 7465 | n = SystemProto.PowerUseItem.CELL; |
| 7466 | break; |
| 7467 | case PHONE: |
| 7468 | n = SystemProto.PowerUseItem.PHONE; |
| 7469 | break; |
| 7470 | case WIFI: |
| 7471 | n = SystemProto.PowerUseItem.WIFI; |
| 7472 | break; |
| 7473 | case BLUETOOTH: |
| 7474 | n = SystemProto.PowerUseItem.BLUETOOTH; |
| 7475 | break; |
| 7476 | case SCREEN: |
| 7477 | n = SystemProto.PowerUseItem.SCREEN; |
| 7478 | break; |
| 7479 | case FLASHLIGHT: |
| 7480 | n = SystemProto.PowerUseItem.FLASHLIGHT; |
| 7481 | break; |
| 7482 | case APP: |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7483 | // dumpProtoAppsLocked will handle this. |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7484 | continue; |
| 7485 | case USER: |
| 7486 | n = SystemProto.PowerUseItem.USER; |
| 7487 | uid = UserHandle.getUid(bs.userId, 0); |
| 7488 | break; |
| 7489 | case UNACCOUNTED: |
| 7490 | n = SystemProto.PowerUseItem.UNACCOUNTED; |
| 7491 | break; |
| 7492 | case OVERCOUNTED: |
| 7493 | n = SystemProto.PowerUseItem.OVERCOUNTED; |
| 7494 | break; |
| 7495 | case CAMERA: |
| 7496 | n = SystemProto.PowerUseItem.CAMERA; |
| 7497 | break; |
| 7498 | case MEMORY: |
| 7499 | n = SystemProto.PowerUseItem.MEMORY; |
| 7500 | break; |
| 7501 | } |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7502 | final long puiToken = proto.start(SystemProto.POWER_USE_ITEM); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7503 | proto.write(SystemProto.PowerUseItem.NAME, n); |
| 7504 | proto.write(SystemProto.PowerUseItem.UID, uid); |
| 7505 | proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah); |
| 7506 | proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide); |
| 7507 | proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah); |
| 7508 | proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH, |
| 7509 | bs.proportionalSmearMah); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7510 | proto.end(puiToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | // Power use summary (POWER_USE_SUMMARY_DATA) |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7515 | final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7516 | proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH, |
| 7517 | helper.getPowerProfile().getBatteryCapacity()); |
| 7518 | proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower()); |
| 7519 | proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower()); |
| 7520 | proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower()); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7521 | proto.end(pusToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7522 | |
| 7523 | // RPM stats (RESOURCE_POWER_MANAGER_DATA) |
| 7524 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 7525 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 7526 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7527 | final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7528 | proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey()); |
| 7529 | dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL, |
| 7530 | ent.getValue(), rawRealtimeUs, which); |
| 7531 | dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF, |
| 7532 | screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7533 | proto.end(rpmToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7534 | } |
| 7535 | |
| 7536 | // Screen brightness (SCREEN_BRIGHTNESS_DATA) |
| 7537 | for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7538 | final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7539 | proto.write(SystemProto.ScreenBrightness.NAME, i); |
| 7540 | dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i), |
| 7541 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7542 | proto.end(sbToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7543 | } |
| 7544 | |
| 7545 | // Signal scanning time (SIGNAL_SCANNING_TIME_DATA) |
| 7546 | dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs, |
| 7547 | which); |
| 7548 | |
| 7549 | // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA) |
| 7550 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7551 | final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7552 | proto.write(SystemProto.PhoneSignalStrength.NAME, i); |
| 7553 | dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i), |
| 7554 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7555 | proto.end(pssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | // Wakeup reasons (WAKEUP_REASON_DATA) |
| 7559 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
| 7560 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7561 | final long wrToken = proto.start(SystemProto.WAKEUP_REASON); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7562 | proto.write(SystemProto.WakeupReason.NAME, ent.getKey()); |
| 7563 | dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7564 | proto.end(wrToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7565 | } |
| 7566 | |
| 7567 | // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA) |
| 7568 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7569 | final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7570 | proto.write(SystemProto.WifiSignalStrength.NAME, i); |
| 7571 | dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i), |
| 7572 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7573 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7574 | } |
| 7575 | |
| 7576 | // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA) |
| 7577 | for (int i = 0; i < NUM_WIFI_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7578 | final long wsToken = proto.start(SystemProto.WIFI_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7579 | proto.write(SystemProto.WifiState.NAME, i); |
| 7580 | dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i), |
| 7581 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7582 | proto.end(wsToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA) |
| 7586 | for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) { |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7587 | final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7588 | proto.write(SystemProto.WifiSupplicantState.NAME, i); |
| 7589 | dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i), |
| 7590 | rawRealtimeUs, which); |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7591 | proto.end(wssToken); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | proto.end(sToken); |
| 7595 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | } |