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 |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 225 | */ |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 226 | static final int CHECKIN_VERSION = 27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * 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] | 230 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 231 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 232 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 233 | private static final long BYTES_PER_KB = 1024; |
| 234 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 235 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 236 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 237 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 238 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 239 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 241 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 242 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 243 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 244 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 245 | // rpm line is: |
| 246 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 247 | // screen-off time, screen-off count |
| 248 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 249 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 250 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 251 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 252 | // fgs line is: |
| 253 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 254 | // foreground service time, count |
| 255 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 256 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 257 | // wl line is: |
| 258 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 259 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 260 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 261 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 262 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 263 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 264 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 265 | // awl line is: |
| 266 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 267 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 268 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 269 | private static final String SYNC_DATA = "sy"; |
| 270 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 271 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 272 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 273 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 274 | private static final String NETWORK_DATA = "nt"; |
| 275 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 276 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 277 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 278 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 279 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 280 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 281 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 282 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 283 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 284 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 285 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 286 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 287 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 288 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 289 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 290 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 291 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 292 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 293 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 294 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 295 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 296 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 297 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 298 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 299 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 300 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 301 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 302 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 303 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 304 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 305 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 306 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 307 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 308 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 309 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 310 | private static final String FLASHLIGHT_DATA = "fla"; |
| 311 | private static final String CAMERA_DATA = "cam"; |
| 312 | private static final String VIDEO_DATA = "vid"; |
| 313 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 315 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 316 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 317 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 319 | |
| 320 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 321 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 322 | * |
| 323 | * Other types might include times spent in foreground, background etc. |
| 324 | */ |
| 325 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 326 | |
| 327 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 328 | * State for keeping track of counting information. |
| 329 | */ |
| 330 | public static abstract class Counter { |
| 331 | |
| 332 | /** |
| 333 | * Returns the count associated with this Counter for the |
| 334 | * selected type of statistics. |
| 335 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 336 | * @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] | 337 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 338 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * Temporary for debugging. |
| 342 | */ |
| 343 | public abstract void logState(Printer pw, String prefix); |
| 344 | } |
| 345 | |
| 346 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 347 | * State for keeping track of long counting information. |
| 348 | */ |
| 349 | public static abstract class LongCounter { |
| 350 | |
| 351 | /** |
| 352 | * Returns the count associated with this Counter for the |
| 353 | * selected type of statistics. |
| 354 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 355 | * @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] | 356 | */ |
| 357 | public abstract long getCountLocked(int which); |
| 358 | |
| 359 | /** |
| 360 | * Temporary for debugging. |
| 361 | */ |
| 362 | public abstract void logState(Printer pw, String prefix); |
| 363 | } |
| 364 | |
| 365 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 366 | * State for keeping track of array of long counting information. |
| 367 | */ |
| 368 | public static abstract class LongCounterArray { |
| 369 | /** |
| 370 | * Returns the counts associated with this Counter for the |
| 371 | * selected type of statistics. |
| 372 | * |
| 373 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 374 | */ |
| 375 | public abstract long[] getCountsLocked(int which); |
| 376 | |
| 377 | /** |
| 378 | * Temporary for debugging. |
| 379 | */ |
| 380 | public abstract void logState(Printer pw, String prefix); |
| 381 | } |
| 382 | |
| 383 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 384 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 385 | * radio controller. |
| 386 | */ |
| 387 | public static abstract class ControllerActivityCounter { |
| 388 | /** |
| 389 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 390 | * idle state. |
| 391 | */ |
| 392 | public abstract LongCounter getIdleTimeCounter(); |
| 393 | |
| 394 | /** |
| 395 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 396 | * receive state. |
| 397 | */ |
| 398 | public abstract LongCounter getRxTimeCounter(); |
| 399 | |
| 400 | /** |
| 401 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 402 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 403 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 404 | * various transmit level states. |
| 405 | */ |
| 406 | public abstract LongCounter[] getTxTimeCounters(); |
| 407 | |
| 408 | /** |
| 409 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 410 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 411 | * yield a value of 0 if the device doesn't support power calculations. |
| 412 | */ |
| 413 | public abstract LongCounter getPowerCounter(); |
| 414 | } |
| 415 | |
| 416 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | * State for keeping track of timing information. |
| 418 | */ |
| 419 | public static abstract class Timer { |
| 420 | |
| 421 | /** |
| 422 | * Returns the count associated with this Timer for the |
| 423 | * selected type of statistics. |
| 424 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 425 | * @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] | 426 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 427 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * Returns the total time in microseconds associated with this Timer for the |
| 431 | * selected type of statistics. |
| 432 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 433 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 434 | * @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] | 435 | * @return a time in microseconds |
| 436 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 437 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 440 | * Returns the total time in microseconds associated with this Timer since the |
| 441 | * 'mark' was last set. |
| 442 | * |
| 443 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 444 | * @return a time in microseconds |
| 445 | */ |
| 446 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 447 | |
| 448 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 449 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 450 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 451 | |
| 452 | */ |
| 453 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 454 | return -1; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Returns the current time the timer has been active, if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 459 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 460 | */ |
| 461 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 462 | return -1; |
| 463 | } |
| 464 | |
| 465 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 466 | * Returns the current time the timer has been active, if it is being tracked. |
| 467 | * |
| 468 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 469 | * been on since reset. |
| 470 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 471 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 472 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 473 | * the actual total time. |
| 474 | * Not all Timer subclasses track the max, total, current durations. |
| 475 | */ |
| 476 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 477 | return -1; |
| 478 | } |
| 479 | |
| 480 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 481 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 482 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 483 | * |
| 484 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 485 | */ |
| 486 | public Timer getSubTimer() { |
| 487 | return null; |
| 488 | } |
| 489 | |
| 490 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 491 | * Returns whether the timer is currently running. Some types of timers |
| 492 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 493 | * and report false. |
| 494 | */ |
| 495 | public boolean isRunningLocked() { |
| 496 | return false; |
| 497 | } |
| 498 | |
| 499 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | * Temporary for debugging. |
| 501 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 502 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
| 506 | * The statistics associated with a particular uid. |
| 507 | */ |
| 508 | public static abstract class Uid { |
| 509 | |
| 510 | /** |
| 511 | * Returns a mapping containing wakelock statistics. |
| 512 | * |
| 513 | * @return a Map from Strings to Uid.Wakelock objects. |
| 514 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 515 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | |
| 517 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 518 | * Returns a mapping containing sync statistics. |
| 519 | * |
| 520 | * @return a Map from Strings to Timer objects. |
| 521 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 522 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 523 | |
| 524 | /** |
| 525 | * Returns a mapping containing scheduled job statistics. |
| 526 | * |
| 527 | * @return a Map from Strings to Timer objects. |
| 528 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 529 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 530 | |
| 531 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 532 | * Returns statistics about how jobs have completed. |
| 533 | * |
| 534 | * @return A Map of String job names to completion type -> count mapping. |
| 535 | */ |
| 536 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 537 | |
| 538 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | * The statistics associated with a particular wake lock. |
| 540 | */ |
| 541 | public static abstract class Wakelock { |
| 542 | public abstract Timer getWakeTime(int type); |
| 543 | } |
| 544 | |
| 545 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 546 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 547 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 548 | * wakelocks that overlap in time (and therefore over-counts). |
| 549 | */ |
| 550 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 551 | |
| 552 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | * Returns a mapping containing sensor statistics. |
| 554 | * |
| 555 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 556 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 557 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | |
| 559 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 560 | * Returns a mapping containing active process data. |
| 561 | */ |
| 562 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 564 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | * Returns a mapping containing process statistics. |
| 566 | * |
| 567 | * @return a Map from Strings to Uid.Proc objects. |
| 568 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 569 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | |
| 571 | /** |
| 572 | * Returns a mapping containing package statistics. |
| 573 | * |
| 574 | * @return a Map from Strings to Uid.Pkg objects. |
| 575 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 576 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 577 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 578 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 579 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 580 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 581 | |
| 582 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | * {@hide} |
| 584 | */ |
| 585 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 586 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 587 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 588 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 589 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 590 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 591 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 592 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 593 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 594 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 595 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 596 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 597 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 598 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 599 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 600 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 601 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 602 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 603 | public abstract int getWifiScanBackgroundCount(int which); |
| 604 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 605 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 606 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 607 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 608 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 609 | public abstract Timer getAudioTurnedOnTimer(); |
| 610 | public abstract Timer getVideoTurnedOnTimer(); |
| 611 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 612 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 613 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * Returns the timer keeping track of Foreground Service time |
| 617 | */ |
| 618 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 619 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 620 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 621 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 622 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 623 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 624 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 625 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 626 | public abstract long[] getCpuFreqTimes(int which); |
| 627 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 628 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 629 | // Note: the following times are disjoint. They can be added together to find the |
| 630 | // total time a uid has had any processes running at all. |
| 631 | |
| 632 | /** |
| 633 | * Time this uid has any processes in the top state (or above such as persistent). |
| 634 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 635 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 636 | /** |
| 637 | * Time this uid has any process with a started out bound foreground service, but |
| 638 | * none in the "top" state. |
| 639 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 640 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 641 | /** |
| 642 | * Time this uid has any process that is top while the device is sleeping, but none |
| 643 | * in the "foreground service" or better state. |
| 644 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 645 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 646 | /** |
| 647 | * Time this uid has any process in an active foreground state, but none in the |
| 648 | * "top sleeping" or better state. |
| 649 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 650 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 651 | /** |
| 652 | * Time this uid has any process in an active background state, but none in the |
| 653 | * "foreground" or better state. |
| 654 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 655 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 656 | /** |
| 657 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 658 | * other active states. |
| 659 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 660 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 661 | /** |
| 662 | * Total number of process states we track. |
| 663 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 664 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 665 | |
| 666 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 667 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 671 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 672 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 673 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 675 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 676 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 677 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 678 | * Note that these must match the constants in android.os.PowerManager. |
| 679 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 680 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 681 | */ |
| 682 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 683 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 684 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 685 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 686 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 687 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 688 | public abstract void noteUserActivityLocked(int type); |
| 689 | public abstract boolean hasUserActivity(); |
| 690 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 691 | |
| 692 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 693 | public abstract long getNetworkActivityBytes(int type, int which); |
| 694 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 695 | public abstract long getMobileRadioActiveTime(int which); |
| 696 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 697 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 698 | /** |
| 699 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 700 | */ |
| 701 | public abstract long getUserCpuTimeUs(int which); |
| 702 | |
| 703 | /** |
| 704 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 705 | */ |
| 706 | public abstract long getSystemCpuTimeUs(int which); |
| 707 | |
| 708 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 709 | * 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] | 710 | * given CPU cluster. |
| 711 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 712 | * @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] | 713 | * @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] | 714 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 715 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 716 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 717 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 718 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 719 | /** |
| 720 | * Returns the number of times this UID woke up the Application Processor to |
| 721 | * process a mobile radio packet. |
| 722 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 723 | */ |
| 724 | public abstract long getMobileRadioApWakeupCount(int which); |
| 725 | |
| 726 | /** |
| 727 | * Returns the number of times this UID woke up the Application Processor to |
| 728 | * process a WiFi packet. |
| 729 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 730 | */ |
| 731 | public abstract long getWifiRadioApWakeupCount(int which); |
| 732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 734 | /* |
| 735 | * FIXME: it's not correct to use this magic value because it |
| 736 | * could clash with a sensor handle (which are defined by |
| 737 | * the sensor HAL, and therefore out of our control |
| 738 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | // Magic sensor number for the GPS. |
| 740 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 745 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 746 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 747 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 750 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 751 | public int mWakeNesting; |
| 752 | public long mWakeSumMs; |
| 753 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 754 | } |
| 755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | /** |
| 757 | * The statistics associated with a particular process. |
| 758 | */ |
| 759 | public static abstract class Proc { |
| 760 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 761 | public static class ExcessivePower { |
| 762 | public static final int TYPE_WAKE = 1; |
| 763 | public static final int TYPE_CPU = 2; |
| 764 | |
| 765 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 766 | public long overTime; |
| 767 | public long usedTime; |
| 768 | } |
| 769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 771 | * Returns true if this process is still active in the battery stats. |
| 772 | */ |
| 773 | public abstract boolean isActive(); |
| 774 | |
| 775 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 776 | * 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] | 777 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 778 | * @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] | 779 | */ |
| 780 | public abstract long getUserTime(int which); |
| 781 | |
| 782 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 783 | * 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] | 784 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 785 | * @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] | 786 | */ |
| 787 | public abstract long getSystemTime(int which); |
| 788 | |
| 789 | /** |
| 790 | * Returns the number of times the process has been started. |
| 791 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 792 | * @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] | 793 | */ |
| 794 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 795 | |
| 796 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 797 | * Returns the number of times the process has crashed. |
| 798 | * |
| 799 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 800 | */ |
| 801 | public abstract int getNumCrashes(int which); |
| 802 | |
| 803 | /** |
| 804 | * Returns the number of times the process has ANRed. |
| 805 | * |
| 806 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 807 | */ |
| 808 | public abstract int getNumAnrs(int which); |
| 809 | |
| 810 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 811 | * 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] | 812 | * @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] | 813 | * @return foreground cpu time in microseconds |
| 814 | */ |
| 815 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 816 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 817 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 818 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 819 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /** |
| 823 | * The statistics associated with a particular package. |
| 824 | */ |
| 825 | public static abstract class Pkg { |
| 826 | |
| 827 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 828 | * Returns information about all wakeup alarms that have been triggered for this |
| 829 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 830 | * 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] | 831 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 832 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | |
| 834 | /** |
| 835 | * Returns a mapping containing service statistics. |
| 836 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 837 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | |
| 839 | /** |
| 840 | * The statistics associated with a particular service. |
| 841 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 842 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | |
| 844 | /** |
| 845 | * Returns the amount of time spent started. |
| 846 | * |
| 847 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 848 | * @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] | 849 | * @return |
| 850 | */ |
| 851 | public abstract long getStartTime(long batteryUptime, int which); |
| 852 | |
| 853 | /** |
| 854 | * Returns the total number of times startService() has been called. |
| 855 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 856 | * @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] | 857 | */ |
| 858 | public abstract int getStarts(int which); |
| 859 | |
| 860 | /** |
| 861 | * Returns the total number times the service has been launched. |
| 862 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 863 | * @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] | 864 | */ |
| 865 | public abstract int getLaunches(int which); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 870 | public static final class LevelStepTracker { |
| 871 | public long mLastStepTime = -1; |
| 872 | public int mNumStepDurations; |
| 873 | public final long[] mStepDurations; |
| 874 | |
| 875 | public LevelStepTracker(int maxLevelSteps) { |
| 876 | mStepDurations = new long[maxLevelSteps]; |
| 877 | } |
| 878 | |
| 879 | public LevelStepTracker(int numSteps, long[] steps) { |
| 880 | mNumStepDurations = numSteps; |
| 881 | mStepDurations = new long[numSteps]; |
| 882 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 883 | } |
| 884 | |
| 885 | public long getDurationAt(int index) { |
| 886 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 887 | } |
| 888 | |
| 889 | public int getLevelAt(int index) { |
| 890 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 891 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 892 | } |
| 893 | |
| 894 | public int getInitModeAt(int index) { |
| 895 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 896 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 897 | } |
| 898 | |
| 899 | public int getModModeAt(int index) { |
| 900 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 901 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 902 | } |
| 903 | |
| 904 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 905 | boolean hasData = false; |
| 906 | while (topOffset >= 0) { |
| 907 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 908 | topOffset -= 4; |
| 909 | if (!hasData && digit == 0) { |
| 910 | continue; |
| 911 | } |
| 912 | hasData = true; |
| 913 | if (digit >= 0 && digit <= 9) { |
| 914 | out.append((char)('0' + digit)); |
| 915 | } else { |
| 916 | out.append((char)('a' + digit - 10)); |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | public void encodeEntryAt(int index, StringBuilder out) { |
| 922 | long item = mStepDurations[index]; |
| 923 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 924 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 925 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 926 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 927 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 928 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 929 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 930 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 931 | case Display.STATE_OFF: out.append('f'); break; |
| 932 | case Display.STATE_ON: out.append('o'); break; |
| 933 | case Display.STATE_DOZE: out.append('d'); break; |
| 934 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 935 | } |
| 936 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 937 | out.append('p'); |
| 938 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 939 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 940 | out.append('i'); |
| 941 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 942 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 943 | case Display.STATE_OFF: out.append('F'); break; |
| 944 | case Display.STATE_ON: out.append('O'); break; |
| 945 | case Display.STATE_DOZE: out.append('D'); break; |
| 946 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 947 | } |
| 948 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 949 | out.append('P'); |
| 950 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 951 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 952 | out.append('I'); |
| 953 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 954 | out.append('-'); |
| 955 | appendHex(level, 4, out); |
| 956 | out.append('-'); |
| 957 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 958 | } |
| 959 | |
| 960 | public void decodeEntryAt(int index, String value) { |
| 961 | final int N = value.length(); |
| 962 | int i = 0; |
| 963 | char c; |
| 964 | long out = 0; |
| 965 | while (i < N && (c=value.charAt(i)) != '-') { |
| 966 | i++; |
| 967 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 968 | 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] | 969 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 970 | 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] | 971 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 972 | 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] | 973 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 974 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 975 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 976 | break; |
| 977 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 978 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 979 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 980 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 981 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 982 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 983 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 984 | break; |
| 985 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 986 | break; |
| 987 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 988 | break; |
| 989 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 990 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 991 | break; |
| 992 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 993 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 994 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 995 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 996 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 997 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1001 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1002 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1003 | i++; |
| 1004 | level <<= 4; |
| 1005 | if (c >= '0' && c <= '9') { |
| 1006 | level += c - '0'; |
| 1007 | } else if (c >= 'a' && c <= 'f') { |
| 1008 | level += c - 'a' + 10; |
| 1009 | } else if (c >= 'A' && c <= 'F') { |
| 1010 | level += c - 'A' + 10; |
| 1011 | } |
| 1012 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1013 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1014 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1015 | long duration = 0; |
| 1016 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1017 | i++; |
| 1018 | duration <<= 4; |
| 1019 | if (c >= '0' && c <= '9') { |
| 1020 | duration += c - '0'; |
| 1021 | } else if (c >= 'a' && c <= 'f') { |
| 1022 | duration += c - 'a' + 10; |
| 1023 | } else if (c >= 'A' && c <= 'F') { |
| 1024 | duration += c - 'A' + 10; |
| 1025 | } |
| 1026 | } |
| 1027 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1028 | } |
| 1029 | |
| 1030 | public void init() { |
| 1031 | mLastStepTime = -1; |
| 1032 | mNumStepDurations = 0; |
| 1033 | } |
| 1034 | |
| 1035 | public void clearTime() { |
| 1036 | mLastStepTime = -1; |
| 1037 | } |
| 1038 | |
| 1039 | public long computeTimePerLevel() { |
| 1040 | final long[] steps = mStepDurations; |
| 1041 | final int numSteps = mNumStepDurations; |
| 1042 | |
| 1043 | // For now we'll do a simple average across all steps. |
| 1044 | if (numSteps <= 0) { |
| 1045 | return -1; |
| 1046 | } |
| 1047 | long total = 0; |
| 1048 | for (int i=0; i<numSteps; i++) { |
| 1049 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1050 | } |
| 1051 | return total / numSteps; |
| 1052 | /* |
| 1053 | long[] buckets = new long[numSteps]; |
| 1054 | int numBuckets = 0; |
| 1055 | int numToAverage = 4; |
| 1056 | int i = 0; |
| 1057 | while (i < numSteps) { |
| 1058 | long totalTime = 0; |
| 1059 | int num = 0; |
| 1060 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1061 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1062 | num++; |
| 1063 | } |
| 1064 | buckets[numBuckets] = totalTime / num; |
| 1065 | numBuckets++; |
| 1066 | numToAverage *= 2; |
| 1067 | i += num; |
| 1068 | } |
| 1069 | if (numBuckets < 1) { |
| 1070 | return -1; |
| 1071 | } |
| 1072 | long averageTime = buckets[numBuckets-1]; |
| 1073 | for (i=numBuckets-2; i>=0; i--) { |
| 1074 | averageTime = (averageTime + buckets[i]) / 2; |
| 1075 | } |
| 1076 | return averageTime; |
| 1077 | */ |
| 1078 | } |
| 1079 | |
| 1080 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1081 | int[] outNumOfInterest) { |
| 1082 | final long[] steps = mStepDurations; |
| 1083 | final int count = mNumStepDurations; |
| 1084 | if (count <= 0) { |
| 1085 | return -1; |
| 1086 | } |
| 1087 | long total = 0; |
| 1088 | int numOfInterest = 0; |
| 1089 | for (int i=0; i<count; i++) { |
| 1090 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1091 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1092 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1093 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1094 | // If the modes of interest didn't change during this step period... |
| 1095 | if ((modMode&modesOfInterest) == 0) { |
| 1096 | // And the mode values during this period match those we are measuring... |
| 1097 | if ((initMode&modesOfInterest) == modeValues) { |
| 1098 | // Then this can be used to estimate the total time! |
| 1099 | numOfInterest++; |
| 1100 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | if (numOfInterest <= 0) { |
| 1105 | return -1; |
| 1106 | } |
| 1107 | |
| 1108 | if (outNumOfInterest != null) { |
| 1109 | outNumOfInterest[0] = numOfInterest; |
| 1110 | } |
| 1111 | |
| 1112 | // The estimated time is the average time we spend in each level, multipled |
| 1113 | // by 100 -- the total number of battery levels |
| 1114 | return (total / numOfInterest) * 100; |
| 1115 | } |
| 1116 | |
| 1117 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1118 | int stepCount = mNumStepDurations; |
| 1119 | final long lastStepTime = mLastStepTime; |
| 1120 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1121 | final long[] steps = mStepDurations; |
| 1122 | long duration = elapsedRealtime - lastStepTime; |
| 1123 | for (int i=0; i<numStepLevels; i++) { |
| 1124 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1125 | long thisDuration = duration / (numStepLevels-i); |
| 1126 | duration -= thisDuration; |
| 1127 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1128 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1129 | } |
| 1130 | steps[0] = thisDuration | modeBits; |
| 1131 | } |
| 1132 | stepCount += numStepLevels; |
| 1133 | if (stepCount > steps.length) { |
| 1134 | stepCount = steps.length; |
| 1135 | } |
| 1136 | } |
| 1137 | mNumStepDurations = stepCount; |
| 1138 | mLastStepTime = elapsedRealtime; |
| 1139 | } |
| 1140 | |
| 1141 | public void readFromParcel(Parcel in) { |
| 1142 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1143 | if (N > mStepDurations.length) { |
| 1144 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1145 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1146 | mNumStepDurations = N; |
| 1147 | for (int i=0; i<N; i++) { |
| 1148 | mStepDurations[i] = in.readLong(); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | public void writeToParcel(Parcel out) { |
| 1153 | final int N = mNumStepDurations; |
| 1154 | out.writeInt(N); |
| 1155 | for (int i=0; i<N; i++) { |
| 1156 | out.writeLong(mStepDurations[i]); |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1161 | public static final class PackageChange { |
| 1162 | public String mPackageName; |
| 1163 | public boolean mUpdate; |
| 1164 | public int mVersionCode; |
| 1165 | } |
| 1166 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1167 | public static final class DailyItem { |
| 1168 | public long mStartTime; |
| 1169 | public long mEndTime; |
| 1170 | public LevelStepTracker mDischargeSteps; |
| 1171 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1172 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1176 | |
| 1177 | public abstract long getCurrentDailyStartTime(); |
| 1178 | |
| 1179 | public abstract long getNextMinDailyDeadline(); |
| 1180 | |
| 1181 | public abstract long getNextMaxDailyDeadline(); |
| 1182 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1183 | public abstract long[] getCpuFreqs(); |
| 1184 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1185 | public final static class HistoryTag { |
| 1186 | public String string; |
| 1187 | public int uid; |
| 1188 | |
| 1189 | public int poolIdx; |
| 1190 | |
| 1191 | public void setTo(HistoryTag o) { |
| 1192 | string = o.string; |
| 1193 | uid = o.uid; |
| 1194 | poolIdx = o.poolIdx; |
| 1195 | } |
| 1196 | |
| 1197 | public void setTo(String _string, int _uid) { |
| 1198 | string = _string; |
| 1199 | uid = _uid; |
| 1200 | poolIdx = -1; |
| 1201 | } |
| 1202 | |
| 1203 | public void writeToParcel(Parcel dest, int flags) { |
| 1204 | dest.writeString(string); |
| 1205 | dest.writeInt(uid); |
| 1206 | } |
| 1207 | |
| 1208 | public void readFromParcel(Parcel src) { |
| 1209 | string = src.readString(); |
| 1210 | uid = src.readInt(); |
| 1211 | poolIdx = -1; |
| 1212 | } |
| 1213 | |
| 1214 | @Override |
| 1215 | public boolean equals(Object o) { |
| 1216 | if (this == o) return true; |
| 1217 | if (o == null || getClass() != o.getClass()) return false; |
| 1218 | |
| 1219 | HistoryTag that = (HistoryTag) o; |
| 1220 | |
| 1221 | if (uid != that.uid) return false; |
| 1222 | if (!string.equals(that.string)) return false; |
| 1223 | |
| 1224 | return true; |
| 1225 | } |
| 1226 | |
| 1227 | @Override |
| 1228 | public int hashCode() { |
| 1229 | int result = string.hashCode(); |
| 1230 | result = 31 * result + uid; |
| 1231 | return result; |
| 1232 | } |
| 1233 | } |
| 1234 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1235 | /** |
| 1236 | * Optional detailed information that can go into a history step. This is typically |
| 1237 | * generated each time the battery level changes. |
| 1238 | */ |
| 1239 | public final static class HistoryStepDetails { |
| 1240 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1241 | public int userTime; |
| 1242 | public int systemTime; |
| 1243 | |
| 1244 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1245 | public int appCpuUid1; |
| 1246 | public int appCpuUTime1; |
| 1247 | public int appCpuSTime1; |
| 1248 | public int appCpuUid2; |
| 1249 | public int appCpuUTime2; |
| 1250 | public int appCpuSTime2; |
| 1251 | public int appCpuUid3; |
| 1252 | public int appCpuUTime3; |
| 1253 | public int appCpuSTime3; |
| 1254 | |
| 1255 | // Information from /proc/stat |
| 1256 | public int statUserTime; |
| 1257 | public int statSystemTime; |
| 1258 | public int statIOWaitTime; |
| 1259 | public int statIrqTime; |
| 1260 | public int statSoftIrqTime; |
| 1261 | public int statIdlTime; |
| 1262 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1263 | // Platform-level low power state stats |
| 1264 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1265 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1266 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1267 | public HistoryStepDetails() { |
| 1268 | clear(); |
| 1269 | } |
| 1270 | |
| 1271 | public void clear() { |
| 1272 | userTime = systemTime = 0; |
| 1273 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1274 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1275 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1276 | } |
| 1277 | |
| 1278 | public void writeToParcel(Parcel out) { |
| 1279 | out.writeInt(userTime); |
| 1280 | out.writeInt(systemTime); |
| 1281 | out.writeInt(appCpuUid1); |
| 1282 | out.writeInt(appCpuUTime1); |
| 1283 | out.writeInt(appCpuSTime1); |
| 1284 | out.writeInt(appCpuUid2); |
| 1285 | out.writeInt(appCpuUTime2); |
| 1286 | out.writeInt(appCpuSTime2); |
| 1287 | out.writeInt(appCpuUid3); |
| 1288 | out.writeInt(appCpuUTime3); |
| 1289 | out.writeInt(appCpuSTime3); |
| 1290 | out.writeInt(statUserTime); |
| 1291 | out.writeInt(statSystemTime); |
| 1292 | out.writeInt(statIOWaitTime); |
| 1293 | out.writeInt(statIrqTime); |
| 1294 | out.writeInt(statSoftIrqTime); |
| 1295 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1296 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1297 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | public void readFromParcel(Parcel in) { |
| 1301 | userTime = in.readInt(); |
| 1302 | systemTime = in.readInt(); |
| 1303 | appCpuUid1 = in.readInt(); |
| 1304 | appCpuUTime1 = in.readInt(); |
| 1305 | appCpuSTime1 = in.readInt(); |
| 1306 | appCpuUid2 = in.readInt(); |
| 1307 | appCpuUTime2 = in.readInt(); |
| 1308 | appCpuSTime2 = in.readInt(); |
| 1309 | appCpuUid3 = in.readInt(); |
| 1310 | appCpuUTime3 = in.readInt(); |
| 1311 | appCpuSTime3 = in.readInt(); |
| 1312 | statUserTime = in.readInt(); |
| 1313 | statSystemTime = in.readInt(); |
| 1314 | statIOWaitTime = in.readInt(); |
| 1315 | statIrqTime = in.readInt(); |
| 1316 | statSoftIrqTime = in.readInt(); |
| 1317 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1318 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1319 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1323 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1324 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1325 | |
| 1326 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1327 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1328 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1329 | 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] | 1330 | public static final byte CMD_NULL = -1; |
| 1331 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1332 | public static final byte CMD_CURRENT_TIME = 5; |
| 1333 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1334 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1335 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1336 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1337 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1338 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1339 | /** |
| 1340 | * Return whether the command code is a delta data update. |
| 1341 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1342 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1343 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1346 | public byte batteryLevel; |
| 1347 | public byte batteryStatus; |
| 1348 | public byte batteryHealth; |
| 1349 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1350 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1351 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1352 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1353 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1354 | // The charge of the battery in micro-Ampere-hours. |
| 1355 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1356 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1357 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1358 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1359 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1360 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1361 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1362 | 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] | 1363 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1364 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1365 | 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] | 1366 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1367 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1368 | 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] | 1369 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1370 | // These states always appear directly in the first int token |
| 1371 | // of a delta change; they should be ones that change relatively |
| 1372 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1373 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1374 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1375 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1376 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1377 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1378 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1379 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1380 | // Do not use, this is used for coulomb delta count. |
| 1381 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1382 | // These are on the lower bits used for the command; if they change |
| 1383 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1384 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1385 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1386 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1387 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1388 | 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] | 1389 | public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1390 | // empty slot |
| 1391 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1392 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1393 | public static final int MOST_INTERESTING_STATES = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1394 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1395 | |
| 1396 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1397 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1398 | public int states; |
| 1399 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1400 | // Constants from WIFI_SUPPL_STATE_* |
| 1401 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1402 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1403 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1404 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1405 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1406 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1407 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1408 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1409 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1410 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1411 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1412 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1413 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1414 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1415 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1416 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1417 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1418 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1419 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1420 | |
| 1421 | public static final int MOST_INTERESTING_STATES2 = |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1422 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
| 1423 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1424 | |
| 1425 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1426 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1427 | public int states2; |
| 1428 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1429 | // The wake lock that was acquired at this point. |
| 1430 | public HistoryTag wakelockTag; |
| 1431 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1432 | // Kernel wakeup reason at this point. |
| 1433 | public HistoryTag wakeReasonTag; |
| 1434 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1435 | // Non-null when there is more detailed information at this step. |
| 1436 | public HistoryStepDetails stepDetails; |
| 1437 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1438 | public static final int EVENT_FLAG_START = 0x8000; |
| 1439 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1440 | |
| 1441 | // No event in this item. |
| 1442 | public static final int EVENT_NONE = 0x0000; |
| 1443 | // Event is about a process that is running. |
| 1444 | public static final int EVENT_PROC = 0x0001; |
| 1445 | // Event is about an application package that is in the foreground. |
| 1446 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1447 | // Event is about an application package that is at the top of the screen. |
| 1448 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1449 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1450 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1451 | // Events for all additional wake locks aquired/release within a wake block. |
| 1452 | // These are not generated by default. |
| 1453 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1454 | // Event is about an application executing a scheduled job. |
| 1455 | public static final int EVENT_JOB = 0x0006; |
| 1456 | // Events for users running. |
| 1457 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1458 | // Events for foreground user. |
| 1459 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1460 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1461 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1462 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1463 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1464 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1465 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1466 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1467 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1468 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1469 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1470 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1471 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1472 | // 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] | 1473 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1474 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1475 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1476 | // Event for a package being on the temporary whitelist. |
| 1477 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1478 | // Event for the screen waking up. |
| 1479 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1480 | // Event for the UID that woke up the application processor. |
| 1481 | // Used for wakeups coming from WiFi, modem, etc. |
| 1482 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1483 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1484 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1485 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1486 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1487 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1488 | // Mask to extract out only the type part of the event. |
| 1489 | 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] | 1490 | |
| 1491 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1492 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1493 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1494 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1495 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1496 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1497 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1498 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1499 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1500 | 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] | 1501 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1502 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1503 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1504 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1505 | public static final int EVENT_USER_FOREGROUND_START = |
| 1506 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1507 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1508 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1509 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1510 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1511 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1512 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1513 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1514 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1515 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1516 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1517 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1518 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1519 | |
| 1520 | // For CMD_EVENT. |
| 1521 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1522 | public HistoryTag eventTag; |
| 1523 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1524 | // 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] | 1525 | public long currentTime; |
| 1526 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1527 | // Meta-data when reading. |
| 1528 | public int numReadInts; |
| 1529 | |
| 1530 | // Pre-allocated objects. |
| 1531 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1532 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1533 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1534 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1535 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1536 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1537 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1538 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1539 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1540 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1541 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1542 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1543 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1544 | public int describeContents() { |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | public void writeToParcel(Parcel dest, int flags) { |
| 1549 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1550 | int bat = (((int)cmd)&0xff) |
| 1551 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1552 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1553 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1554 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1555 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1556 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1557 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1558 | dest.writeInt(bat); |
| 1559 | bat = (((int)batteryTemperature)&0xffff) |
| 1560 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1561 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1562 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1563 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1564 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1565 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1566 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1567 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1568 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1569 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1570 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1571 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1572 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1573 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1574 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1575 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1576 | dest.writeLong(currentTime); |
| 1577 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1578 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1579 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1580 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1581 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1582 | int bat = src.readInt(); |
| 1583 | cmd = (byte)(bat&0xff); |
| 1584 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1585 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1586 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1587 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1588 | int bat2 = src.readInt(); |
| 1589 | batteryTemperature = (short)(bat2&0xffff); |
| 1590 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1591 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1592 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1593 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1594 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1595 | wakelockTag = localWakelockTag; |
| 1596 | wakelockTag.readFromParcel(src); |
| 1597 | } else { |
| 1598 | wakelockTag = null; |
| 1599 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1600 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1601 | wakeReasonTag = localWakeReasonTag; |
| 1602 | wakeReasonTag.readFromParcel(src); |
| 1603 | } else { |
| 1604 | wakeReasonTag = null; |
| 1605 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1606 | if ((bat&0x40000000) != 0) { |
| 1607 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1608 | eventTag = localEventTag; |
| 1609 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1610 | } else { |
| 1611 | eventCode = EVENT_NONE; |
| 1612 | eventTag = null; |
| 1613 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1614 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1615 | currentTime = src.readLong(); |
| 1616 | } else { |
| 1617 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1618 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1619 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1622 | public void clear() { |
| 1623 | time = 0; |
| 1624 | cmd = CMD_NULL; |
| 1625 | batteryLevel = 0; |
| 1626 | batteryStatus = 0; |
| 1627 | batteryHealth = 0; |
| 1628 | batteryPlugType = 0; |
| 1629 | batteryTemperature = 0; |
| 1630 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1631 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1632 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1633 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1634 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1635 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1636 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1637 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1638 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1639 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1640 | public void setTo(HistoryItem o) { |
| 1641 | time = o.time; |
| 1642 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1643 | setToCommon(o); |
| 1644 | } |
| 1645 | |
| 1646 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1647 | this.time = time; |
| 1648 | this.cmd = cmd; |
| 1649 | setToCommon(o); |
| 1650 | } |
| 1651 | |
| 1652 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1653 | batteryLevel = o.batteryLevel; |
| 1654 | batteryStatus = o.batteryStatus; |
| 1655 | batteryHealth = o.batteryHealth; |
| 1656 | batteryPlugType = o.batteryPlugType; |
| 1657 | batteryTemperature = o.batteryTemperature; |
| 1658 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1659 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1660 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1661 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1662 | if (o.wakelockTag != null) { |
| 1663 | wakelockTag = localWakelockTag; |
| 1664 | wakelockTag.setTo(o.wakelockTag); |
| 1665 | } else { |
| 1666 | wakelockTag = null; |
| 1667 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1668 | if (o.wakeReasonTag != null) { |
| 1669 | wakeReasonTag = localWakeReasonTag; |
| 1670 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1671 | } else { |
| 1672 | wakeReasonTag = null; |
| 1673 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1674 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1675 | if (o.eventTag != null) { |
| 1676 | eventTag = localEventTag; |
| 1677 | eventTag.setTo(o.eventTag); |
| 1678 | } else { |
| 1679 | eventTag = null; |
| 1680 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1681 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1684 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1685 | return batteryLevel == o.batteryLevel |
| 1686 | && batteryStatus == o.batteryStatus |
| 1687 | && batteryHealth == o.batteryHealth |
| 1688 | && batteryPlugType == o.batteryPlugType |
| 1689 | && batteryTemperature == o.batteryTemperature |
| 1690 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1691 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1692 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1693 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1694 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1695 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1696 | |
| 1697 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1698 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1699 | return false; |
| 1700 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1701 | if (wakelockTag != o.wakelockTag) { |
| 1702 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1703 | return false; |
| 1704 | } |
| 1705 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1706 | return false; |
| 1707 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1708 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1709 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1710 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1711 | return false; |
| 1712 | } |
| 1713 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1714 | return false; |
| 1715 | } |
| 1716 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1717 | if (eventTag != o.eventTag) { |
| 1718 | if (eventTag == null || o.eventTag == null) { |
| 1719 | return false; |
| 1720 | } |
| 1721 | if (!eventTag.equals(o.eventTag)) { |
| 1722 | return false; |
| 1723 | } |
| 1724 | } |
| 1725 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1726 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1727 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1728 | |
| 1729 | public final static class HistoryEventTracker { |
| 1730 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1731 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1732 | |
| 1733 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1734 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1735 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1736 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1737 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1738 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1739 | mActiveEvents[idx] = active; |
| 1740 | } |
| 1741 | SparseIntArray uids = active.get(name); |
| 1742 | if (uids == null) { |
| 1743 | uids = new SparseIntArray(); |
| 1744 | active.put(name, uids); |
| 1745 | } |
| 1746 | if (uids.indexOfKey(uid) >= 0) { |
| 1747 | // Already set, nothing to do! |
| 1748 | return false; |
| 1749 | } |
| 1750 | uids.put(uid, poolIdx); |
| 1751 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1752 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1753 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1754 | if (active == null) { |
| 1755 | // not currently active, nothing to do. |
| 1756 | return false; |
| 1757 | } |
| 1758 | SparseIntArray uids = active.get(name); |
| 1759 | if (uids == null) { |
| 1760 | // not currently active, nothing to do. |
| 1761 | return false; |
| 1762 | } |
| 1763 | idx = uids.indexOfKey(uid); |
| 1764 | if (idx < 0) { |
| 1765 | // not currently active, nothing to do. |
| 1766 | return false; |
| 1767 | } |
| 1768 | uids.removeAt(idx); |
| 1769 | if (uids.size() <= 0) { |
| 1770 | active.remove(name); |
| 1771 | } |
| 1772 | } |
| 1773 | return true; |
| 1774 | } |
| 1775 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1776 | public void removeEvents(int code) { |
| 1777 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1778 | mActiveEvents[idx] = null; |
| 1779 | } |
| 1780 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1781 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1782 | return mActiveEvents[code]; |
| 1783 | } |
| 1784 | } |
| 1785 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1786 | public static final class BitDescription { |
| 1787 | public final int mask; |
| 1788 | public final int shift; |
| 1789 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1790 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1791 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1792 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1793 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1794 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1795 | this.mask = mask; |
| 1796 | this.shift = -1; |
| 1797 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1798 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1799 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1800 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1801 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1802 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1803 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1804 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1805 | this.mask = mask; |
| 1806 | this.shift = shift; |
| 1807 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1808 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1809 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1810 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1811 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1812 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1813 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1814 | /** |
| 1815 | * Don't allow any more batching in to the current history event. This |
| 1816 | * is called when printing partial histories, so to ensure that the next |
| 1817 | * history event will go in to a new batch after what was printed in the |
| 1818 | * last partial history. |
| 1819 | */ |
| 1820 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1821 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1822 | public abstract int getHistoryTotalSize(); |
| 1823 | |
| 1824 | public abstract int getHistoryUsedSize(); |
| 1825 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1826 | public abstract boolean startIteratingHistoryLocked(); |
| 1827 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1828 | public abstract int getHistoryStringPoolSize(); |
| 1829 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1830 | public abstract int getHistoryStringPoolBytes(); |
| 1831 | |
| 1832 | public abstract String getHistoryTagPoolString(int index); |
| 1833 | |
| 1834 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1835 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1836 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1837 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1838 | public abstract void finishIteratingHistoryLocked(); |
| 1839 | |
| 1840 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1841 | |
| 1842 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1843 | |
| 1844 | public abstract void finishIteratingOldHistoryLocked(); |
| 1845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1847 | * Return the base time offset for the battery history. |
| 1848 | */ |
| 1849 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1850 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1851 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | * Returns the number of times the device has been started. |
| 1853 | */ |
| 1854 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1857 | * 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] | 1858 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1859 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1860 | * {@hide} |
| 1861 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1862 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1863 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1864 | /** |
| 1865 | * Returns the number of times the screen was turned on. |
| 1866 | * |
| 1867 | * {@hide} |
| 1868 | */ |
| 1869 | public abstract int getScreenOnCount(int which); |
| 1870 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1871 | /** |
| 1872 | * Returns the time in microseconds that the screen has been dozing while the device was |
| 1873 | * running on battery. |
| 1874 | * |
| 1875 | * {@hide} |
| 1876 | */ |
| 1877 | public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which); |
| 1878 | |
| 1879 | /** |
| 1880 | * Returns the number of times the screen was turned dozing. |
| 1881 | * |
| 1882 | * {@hide} |
| 1883 | */ |
| 1884 | public abstract int getScreenDozeCount(int which); |
| 1885 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1886 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1887 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1888 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1889 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1890 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1891 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1892 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1893 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1894 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1895 | "dark", "dim", "medium", "light", "bright" |
| 1896 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1897 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1898 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1899 | "0", "1", "2", "3", "4" |
| 1900 | }; |
| 1901 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1902 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1903 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1904 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1905 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1906 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1907 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1908 | * {@hide} |
| 1909 | */ |
| 1910 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1911 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1914 | * 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] | 1915 | * running on battery. |
| 1916 | * |
| 1917 | * {@hide} |
| 1918 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1919 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1920 | |
| 1921 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1922 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1923 | * |
| 1924 | * {@hide} |
| 1925 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1926 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1927 | |
| 1928 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1929 | * Constant for device idle mode: not active. |
| 1930 | */ |
| 1931 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1932 | |
| 1933 | /** |
| 1934 | * Constant for device idle mode: active in lightweight mode. |
| 1935 | */ |
| 1936 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1937 | |
| 1938 | /** |
| 1939 | * Constant for device idle mode: active in full mode. |
| 1940 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1941 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1942 | |
| 1943 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1944 | * Returns the time in microseconds that device has been in idle mode while |
| 1945 | * running on battery. |
| 1946 | * |
| 1947 | * {@hide} |
| 1948 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1949 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1950 | |
| 1951 | /** |
| 1952 | * Returns the number of times that the devie has gone in to idle mode. |
| 1953 | * |
| 1954 | * {@hide} |
| 1955 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1956 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1957 | |
| 1958 | /** |
| 1959 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1960 | * mode, not in idle maintenance etc). |
| 1961 | */ |
| 1962 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1963 | |
| 1964 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1965 | * 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] | 1966 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1967 | * counts all of the time that we consider the device to be idle, whether or not |
| 1968 | * it is currently in the actual device idle mode. |
| 1969 | * |
| 1970 | * {@hide} |
| 1971 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1972 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1973 | |
| 1974 | /** |
| 1975 | * Returns the number of times that the devie has started idling. |
| 1976 | * |
| 1977 | * {@hide} |
| 1978 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1979 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1980 | |
| 1981 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1982 | * Returns the number of times that connectivity state changed. |
| 1983 | * |
| 1984 | * {@hide} |
| 1985 | */ |
| 1986 | public abstract int getNumConnectivityChange(int which); |
| 1987 | |
| 1988 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1989 | * 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] | 1990 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1991 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | * {@hide} |
| 1993 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1994 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1995 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1996 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1997 | * Returns the number of times a phone call was activated. |
| 1998 | * |
| 1999 | * {@hide} |
| 2000 | */ |
| 2001 | public abstract int getPhoneOnCount(int which); |
| 2002 | |
| 2003 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2004 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2005 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2006 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2007 | * {@hide} |
| 2008 | */ |
| 2009 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2010 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2011 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2012 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2013 | * Returns the time in microseconds that the phone has been trying to |
| 2014 | * acquire a signal. |
| 2015 | * |
| 2016 | * {@hide} |
| 2017 | */ |
| 2018 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2019 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2020 | |
| 2021 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2022 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2023 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2024 | * {@hide} |
| 2025 | */ |
| 2026 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2027 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2028 | /** |
| 2029 | * Returns the time in microseconds that the mobile network has been active |
| 2030 | * (in a high power state). |
| 2031 | * |
| 2032 | * {@hide} |
| 2033 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2034 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2035 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2036 | /** |
| 2037 | * Returns the number of times that the mobile network has transitioned to the |
| 2038 | * active state. |
| 2039 | * |
| 2040 | * {@hide} |
| 2041 | */ |
| 2042 | public abstract int getMobileRadioActiveCount(int which); |
| 2043 | |
| 2044 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2045 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2046 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2047 | * from the radio. |
| 2048 | * |
| 2049 | * {@hide} |
| 2050 | */ |
| 2051 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2052 | |
| 2053 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2054 | * Returns the time in microseconds that the mobile network has been active |
| 2055 | * (in a high power state) but not being able to blame on an app. |
| 2056 | * |
| 2057 | * {@hide} |
| 2058 | */ |
| 2059 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2060 | |
| 2061 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2062 | * 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] | 2063 | * |
| 2064 | * {@hide} |
| 2065 | */ |
| 2066 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2067 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2068 | public static final int DATA_CONNECTION_NONE = 0; |
| 2069 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2070 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2071 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2072 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2073 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2074 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2075 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2076 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2077 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2078 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2079 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2080 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2081 | public static final int DATA_CONNECTION_LTE = 13; |
| 2082 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2083 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2084 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2085 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2086 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2087 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2088 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2089 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2090 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2091 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2092 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2093 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2094 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2095 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2096 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2097 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2098 | * {@hide} |
| 2099 | */ |
| 2100 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2101 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2104 | * Returns the number of times the phone has entered the given data |
| 2105 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2106 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2107 | * {@hide} |
| 2108 | */ |
| 2109 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2110 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2111 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2112 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2113 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2114 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2115 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2116 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2117 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2118 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2119 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2120 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2121 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2122 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2123 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2124 | |
| 2125 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2126 | |
| 2127 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2128 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2129 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2130 | "group-handshake", "completed", "dormant", "uninit" |
| 2131 | }; |
| 2132 | |
| 2133 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2134 | "inv", "dsc", "dis", "inact", "scan", |
| 2135 | "auth", "ascing", "asced", "4-way", |
| 2136 | "group", "compl", "dorm", "uninit" |
| 2137 | }; |
| 2138 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2139 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2140 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2141 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2142 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2143 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2144 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2145 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2146 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2147 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2148 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2149 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2150 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2151 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2152 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2153 | new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2154 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2155 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2156 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2157 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2158 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2159 | new String[] {"in", "out", "emergency", "off"}, |
| 2160 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2161 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2162 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2163 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2164 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2165 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2166 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2167 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2168 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2169 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2170 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2171 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2172 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2173 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2174 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2175 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2176 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2177 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2178 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2179 | new String[] { "off", "light", "full", "???" }, |
| 2180 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2181 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2182 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2183 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2184 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2185 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2186 | new String[] { "0", "1", "2", "3", "4" }, |
| 2187 | new String[] { "0", "1", "2", "3", "4" }), |
| 2188 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2189 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2190 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2191 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2192 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2193 | }; |
| 2194 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2195 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2196 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2197 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2198 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2199 | }; |
| 2200 | |
| 2201 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2202 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2203 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2204 | "Esw", "Ewa", "Elw", "Eec" |
| 2205 | }; |
| 2206 | |
| 2207 | @FunctionalInterface |
| 2208 | public interface IntToString { |
| 2209 | String applyAsString(int val); |
| 2210 | } |
| 2211 | |
| 2212 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2213 | private static final IntToString sIntToString = Integer::toString; |
| 2214 | |
| 2215 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2216 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2217 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2218 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2219 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2220 | }; |
| 2221 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2222 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2223 | * 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] | 2224 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2225 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2226 | * {@hide} |
| 2227 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2228 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2229 | |
| 2230 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2231 | * 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] | 2232 | * been in the running state while the device was running on battery. |
| 2233 | * |
| 2234 | * {@hide} |
| 2235 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2236 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2237 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2238 | public static final int WIFI_STATE_OFF = 0; |
| 2239 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2240 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2241 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2242 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2243 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2244 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2245 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2246 | |
| 2247 | static final String[] WIFI_STATE_NAMES = { |
| 2248 | "off", "scanning", "no_net", "disconn", |
| 2249 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2250 | }; |
| 2251 | |
| 2252 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2253 | |
| 2254 | /** |
| 2255 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2256 | * |
| 2257 | * {@hide} |
| 2258 | */ |
| 2259 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2260 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2261 | |
| 2262 | /** |
| 2263 | * Returns the number of times that WiFi has entered the given state. |
| 2264 | * |
| 2265 | * {@hide} |
| 2266 | */ |
| 2267 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2268 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2269 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2270 | * Returns the time in microseconds that the wifi supplicant has been |
| 2271 | * in a given state. |
| 2272 | * |
| 2273 | * {@hide} |
| 2274 | */ |
| 2275 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2276 | |
| 2277 | /** |
| 2278 | * Returns the number of times that the wifi supplicant has transitioned |
| 2279 | * to a given state. |
| 2280 | * |
| 2281 | * {@hide} |
| 2282 | */ |
| 2283 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2284 | |
| 2285 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2286 | |
| 2287 | /** |
| 2288 | * Returns the time in microseconds that WIFI has been running with |
| 2289 | * the given signal strength. |
| 2290 | * |
| 2291 | * {@hide} |
| 2292 | */ |
| 2293 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2294 | long elapsedRealtimeUs, int which); |
| 2295 | |
| 2296 | /** |
| 2297 | * Returns the number of times WIFI has entered the given signal strength. |
| 2298 | * |
| 2299 | * {@hide} |
| 2300 | */ |
| 2301 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2302 | |
| 2303 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2304 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2305 | * running on battery. |
| 2306 | * |
| 2307 | * {@hide} |
| 2308 | */ |
| 2309 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2310 | |
| 2311 | /** |
| 2312 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2313 | * running on battery. |
| 2314 | * |
| 2315 | * {@hide} |
| 2316 | */ |
| 2317 | public abstract long getFlashlightOnCount(int which); |
| 2318 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2319 | /** |
| 2320 | * Returns the time in microseconds that the camera has been on while the device was |
| 2321 | * running on battery. |
| 2322 | * |
| 2323 | * {@hide} |
| 2324 | */ |
| 2325 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2326 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2327 | /** |
| 2328 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2329 | * on battery. |
| 2330 | * |
| 2331 | * {@hide} |
| 2332 | */ |
| 2333 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2334 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2335 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2336 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2337 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2338 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2339 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2340 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2341 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2342 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2343 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2344 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2345 | 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] | 2346 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2347 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2348 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2349 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2350 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2351 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2352 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2353 | * actual power data. |
| 2354 | */ |
| 2355 | public abstract boolean hasWifiActivityReporting(); |
| 2356 | |
| 2357 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2358 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2359 | * in various radio controller states, such as transmit, receive, and idle. |
| 2360 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2361 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2362 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2363 | |
| 2364 | /** |
| 2365 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2366 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2367 | * actual power data. |
| 2368 | */ |
| 2369 | public abstract boolean hasBluetoothActivityReporting(); |
| 2370 | |
| 2371 | /** |
| 2372 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2373 | * in various radio controller states, such as transmit, receive, and idle. |
| 2374 | * @return non-null {@link ControllerActivityCounter} |
| 2375 | */ |
| 2376 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2377 | |
| 2378 | /** |
| 2379 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2380 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2381 | * actual power data. |
| 2382 | */ |
| 2383 | public abstract boolean hasModemActivityReporting(); |
| 2384 | |
| 2385 | /** |
| 2386 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2387 | * in various radio controller states, such as transmit, receive, and idle. |
| 2388 | * @return non-null {@link ControllerActivityCounter} |
| 2389 | */ |
| 2390 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2391 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2392 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2393 | * Return the wall clock time when battery stats data collection started. |
| 2394 | */ |
| 2395 | public abstract long getStartClockTime(); |
| 2396 | |
| 2397 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2398 | * Return platform version tag that we were running in when the battery stats started. |
| 2399 | */ |
| 2400 | public abstract String getStartPlatformVersion(); |
| 2401 | |
| 2402 | /** |
| 2403 | * Return platform version tag that we were running in when the battery stats ended. |
| 2404 | */ |
| 2405 | public abstract String getEndPlatformVersion(); |
| 2406 | |
| 2407 | /** |
| 2408 | * Return the internal version code of the parcelled format. |
| 2409 | */ |
| 2410 | public abstract int getParcelVersion(); |
| 2411 | |
| 2412 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | * Return whether we are currently running on battery. |
| 2414 | */ |
| 2415 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | /** |
| 2418 | * Returns a SparseArray containing the statistics for each uid. |
| 2419 | */ |
| 2420 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2421 | |
| 2422 | /** |
| 2423 | * Returns the current battery uptime in microseconds. |
| 2424 | * |
| 2425 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2426 | */ |
| 2427 | public abstract long getBatteryUptime(long curTime); |
| 2428 | |
| 2429 | /** |
| 2430 | * Returns the current battery realtime in microseconds. |
| 2431 | * |
| 2432 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2433 | */ |
| 2434 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2435 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2436 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2437 | * 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] | 2438 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2439 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2440 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2441 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2442 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2443 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2444 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2445 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2446 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | |
| 2448 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2449 | * Get the amount the battery has discharged since the stats were |
| 2450 | * last reset after charging, as a lower-end approximation. |
| 2451 | */ |
| 2452 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2453 | |
| 2454 | /** |
| 2455 | * Get the amount the battery has discharged since the stats were |
| 2456 | * last reset after charging, as an upper-end approximation. |
| 2457 | */ |
| 2458 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2459 | |
| 2460 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2461 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2462 | */ |
| 2463 | public abstract int getDischargeAmount(int which); |
| 2464 | |
| 2465 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2466 | * Get the amount the battery has discharged while the screen was on, |
| 2467 | * since the last time power was unplugged. |
| 2468 | */ |
| 2469 | public abstract int getDischargeAmountScreenOn(); |
| 2470 | |
| 2471 | /** |
| 2472 | * Get the amount the battery has discharged while the screen was on, |
| 2473 | * since the last time the device was charged. |
| 2474 | */ |
| 2475 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2476 | |
| 2477 | /** |
| 2478 | * Get the amount the battery has discharged while the screen was off, |
| 2479 | * since the last time power was unplugged. |
| 2480 | */ |
| 2481 | public abstract int getDischargeAmountScreenOff(); |
| 2482 | |
| 2483 | /** |
| 2484 | * Get the amount the battery has discharged while the screen was off, |
| 2485 | * since the last time the device was charged. |
| 2486 | */ |
| 2487 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2488 | |
| 2489 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2490 | * Get the amount the battery has discharged while the screen was doze, |
| 2491 | * since the last time power was unplugged. |
| 2492 | */ |
| 2493 | public abstract int getDischargeAmountScreenDoze(); |
| 2494 | |
| 2495 | /** |
| 2496 | * Get the amount the battery has discharged while the screen was doze, |
| 2497 | * since the last time the device was charged. |
| 2498 | */ |
| 2499 | public abstract int getDischargeAmountScreenDozeSinceCharge(); |
| 2500 | |
| 2501 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | * Returns the total, last, or current battery uptime in microseconds. |
| 2503 | * |
| 2504 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2505 | * @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] | 2506 | */ |
| 2507 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2508 | |
| 2509 | /** |
| 2510 | * Returns the total, last, or current battery realtime in microseconds. |
| 2511 | * |
| 2512 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2513 | * @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] | 2514 | */ |
| 2515 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2516 | |
| 2517 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2518 | * 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] | 2519 | * |
| 2520 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2521 | * @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] | 2522 | */ |
| 2523 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2524 | |
| 2525 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2526 | * 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] | 2527 | * |
| 2528 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2529 | * @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] | 2530 | */ |
| 2531 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2532 | |
| 2533 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | * Returns the total, last, or current uptime in microseconds. |
| 2535 | * |
| 2536 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2537 | * @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] | 2538 | */ |
| 2539 | public abstract long computeUptime(long curTime, int which); |
| 2540 | |
| 2541 | /** |
| 2542 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2543 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2545 | * @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] | 2546 | */ |
| 2547 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2548 | |
| 2549 | /** |
| 2550 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2551 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2552 | * enough current data to make a decision, or the battery is currently |
| 2553 | * charging. |
| 2554 | * |
| 2555 | * @param curTime The current elepsed realtime in microseconds. |
| 2556 | */ |
| 2557 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2558 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2559 | // The part of a step duration that is the actual time. |
| 2560 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2561 | |
| 2562 | // Bits in a step duration that are the new battery level we are at. |
| 2563 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2564 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2565 | |
| 2566 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2567 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2568 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2569 | |
| 2570 | // Bits in a step duration that indicate which modes changed during that step. |
| 2571 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2572 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2573 | |
| 2574 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2575 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2576 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2577 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2578 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2579 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2580 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2581 | // Step duration mode: power save is on. |
| 2582 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2583 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2584 | // Step duration mode: device is currently in idle mode. |
| 2585 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2586 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2587 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2588 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2589 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2590 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2591 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2592 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2593 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2594 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2595 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2596 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2597 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2598 | }; |
| 2599 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2600 | (Display.STATE_OFF-1), |
| 2601 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2602 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2603 | (Display.STATE_ON-1), |
| 2604 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2605 | (Display.STATE_DOZE-1), |
| 2606 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2607 | (Display.STATE_DOZE_SUSPEND-1), |
| 2608 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2609 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2610 | }; |
| 2611 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2612 | "screen off", |
| 2613 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2614 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2615 | "screen on", |
| 2616 | "screen on power save", |
| 2617 | "screen doze", |
| 2618 | "screen doze power save", |
| 2619 | "screen doze-suspend", |
| 2620 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2621 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2622 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2623 | |
| 2624 | /** |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2625 | * 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] | 2626 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2627 | * a coulomb counter. |
| 2628 | */ |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 2629 | public abstract long getMahDischargeScreenOff(int which); |
| 2630 | |
| 2631 | /** |
| 2632 | * Return the amount of battery discharge while the screen was in doze mode, measured in |
| 2633 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2634 | * a coulomb counter. |
| 2635 | */ |
| 2636 | public abstract long getMahDischargeScreenDoze(int which); |
| 2637 | |
| 2638 | /** |
| 2639 | * Return the amount of battery discharge measured in micro-Ampere-hours. This will be |
| 2640 | * non-zero only if the device's battery has a coulomb counter. |
| 2641 | */ |
| 2642 | public abstract long getMahDischarge(int which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2643 | |
| 2644 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2645 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2646 | * declared by the PowerProfile. |
| 2647 | * @return The estimated battery capacity in mAh. |
| 2648 | */ |
| 2649 | public abstract int getEstimatedBatteryCapacity(); |
| 2650 | |
| 2651 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2652 | * @return The minimum learned battery capacity in uAh. |
| 2653 | */ |
| 2654 | public abstract int getMinLearnedBatteryCapacity(); |
| 2655 | |
| 2656 | /** |
| 2657 | * @return The maximum learned battery capacity in uAh. |
| 2658 | */ |
| 2659 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2660 | |
| 2661 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2662 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2663 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2664 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2665 | |
| 2666 | /** |
| 2667 | * Return the array of daily discharge step durations. |
| 2668 | */ |
| 2669 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2670 | |
| 2671 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2672 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2673 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2674 | * enough current data to make a decision, or the battery is currently |
| 2675 | * discharging. |
| 2676 | * |
| 2677 | * @param curTime The current elepsed realtime in microseconds. |
| 2678 | */ |
| 2679 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2680 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2681 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2682 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2683 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2684 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2685 | |
| 2686 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2687 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2688 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2689 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2690 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2691 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2692 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2693 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2694 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2695 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2697 | /** |
| 2698 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2699 | */ |
| 2700 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2701 | /** |
| 2702 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2703 | */ |
| 2704 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2705 | |
| 2706 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2707 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2708 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2709 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2710 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2711 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | long days = seconds / (60 * 60 * 24); |
| 2713 | if (days != 0) { |
| 2714 | out.append(days); |
| 2715 | out.append("d "); |
| 2716 | } |
| 2717 | long used = days * 60 * 60 * 24; |
| 2718 | |
| 2719 | long hours = (seconds - used) / (60 * 60); |
| 2720 | if (hours != 0 || used != 0) { |
| 2721 | out.append(hours); |
| 2722 | out.append("h "); |
| 2723 | } |
| 2724 | used += hours * 60 * 60; |
| 2725 | |
| 2726 | long mins = (seconds-used) / 60; |
| 2727 | if (mins != 0 || used != 0) { |
| 2728 | out.append(mins); |
| 2729 | out.append("m "); |
| 2730 | } |
| 2731 | used += mins * 60; |
| 2732 | |
| 2733 | if (seconds != 0 || used != 0) { |
| 2734 | out.append(seconds-used); |
| 2735 | out.append("s "); |
| 2736 | } |
| 2737 | } |
| 2738 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2739 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2741 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | sb.append(time - (sec * 1000)); |
| 2743 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | } |
| 2745 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2746 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2747 | long sec = time / 1000; |
| 2748 | formatTimeRaw(sb, sec); |
| 2749 | sb.append(time - (sec * 1000)); |
| 2750 | sb.append("ms"); |
| 2751 | } |
| 2752 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2753 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2755 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
| 2757 | float perc = ((float)num) / ((float)den) * 100; |
| 2758 | mFormatBuilder.setLength(0); |
| 2759 | mFormatter.format("%.1f%%", perc); |
| 2760 | return mFormatBuilder.toString(); |
| 2761 | } |
| 2762 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2763 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2764 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2765 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2766 | if (bytes < BYTES_PER_KB) { |
| 2767 | return bytes + "B"; |
| 2768 | } else if (bytes < BYTES_PER_MB) { |
| 2769 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2770 | return mFormatBuilder.toString(); |
| 2771 | } else if (bytes < BYTES_PER_GB){ |
| 2772 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2773 | return mFormatBuilder.toString(); |
| 2774 | } else { |
| 2775 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2776 | return mFormatBuilder.toString(); |
| 2777 | } |
| 2778 | } |
| 2779 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2780 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2781 | if (timer != null) { |
| 2782 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2783 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2784 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2785 | return totalTimeMillis; |
| 2786 | } |
| 2787 | return 0; |
| 2788 | } |
| 2789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | /** |
| 2791 | * |
| 2792 | * @param sb a StringBuilder object. |
| 2793 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2794 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2796 | * @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] | 2797 | * @param linePrefix a String to be prepended to each line of output. |
| 2798 | * @return the line prefix |
| 2799 | */ |
| 2800 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2801 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2804 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2805 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2806 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | if (totalTimeMillis != 0) { |
| 2808 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2809 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2810 | if (name != null) { |
| 2811 | sb.append(name); |
| 2812 | sb.append(' '); |
| 2813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2814 | sb.append('('); |
| 2815 | sb.append(count); |
| 2816 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2817 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2818 | if (maxDurationMs >= 0) { |
| 2819 | sb.append(" max="); |
| 2820 | sb.append(maxDurationMs); |
| 2821 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2822 | // Put actual time if it is available and different from totalTimeMillis. |
| 2823 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2824 | if (totalDurMs > totalTimeMillis) { |
| 2825 | sb.append(" actual="); |
| 2826 | sb.append(totalDurMs); |
| 2827 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2828 | if (timer.isRunningLocked()) { |
| 2829 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2830 | if (currentMs >= 0) { |
| 2831 | sb.append(" (running for "); |
| 2832 | sb.append(currentMs); |
| 2833 | sb.append("ms)"); |
| 2834 | } else { |
| 2835 | sb.append(" (running)"); |
| 2836 | } |
| 2837 | } |
| 2838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | return ", "; |
| 2840 | } |
| 2841 | } |
| 2842 | return linePrefix; |
| 2843 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2844 | |
| 2845 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2846 | * 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] | 2847 | * |
| 2848 | * @param pw a PrintWriter object to print to. |
| 2849 | * @param sb a StringBuilder object. |
| 2850 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2851 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2852 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2853 | * @param prefix a String to be prepended to each line of output. |
| 2854 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2855 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2856 | */ |
| 2857 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2858 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2859 | if (timer != null) { |
| 2860 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2861 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2862 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2863 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2864 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2865 | sb.setLength(0); |
| 2866 | sb.append(prefix); |
| 2867 | sb.append(" "); |
| 2868 | sb.append(type); |
| 2869 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2870 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2871 | sb.append("realtime ("); |
| 2872 | sb.append(count); |
| 2873 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2874 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2875 | if (maxDurationMs >= 0) { |
| 2876 | sb.append(" max="); |
| 2877 | sb.append(maxDurationMs); |
| 2878 | } |
| 2879 | if (timer.isRunningLocked()) { |
| 2880 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2881 | if (currentMs >= 0) { |
| 2882 | sb.append(" (running for "); |
| 2883 | sb.append(currentMs); |
| 2884 | sb.append("ms)"); |
| 2885 | } else { |
| 2886 | sb.append(" (running)"); |
| 2887 | } |
| 2888 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2889 | pw.println(sb.toString()); |
| 2890 | return true; |
| 2891 | } |
| 2892 | } |
| 2893 | return false; |
| 2894 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | /** |
| 2897 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2898 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | * @param sb a StringBuilder object. |
| 2900 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2901 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2903 | * @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] | 2904 | * @param linePrefix a String to be prepended to each line of output. |
| 2905 | * @return the line prefix |
| 2906 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2907 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2908 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | long totalTimeMicros = 0; |
| 2910 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 2911 | long max = 0; |
| 2912 | long current = 0; |
| 2913 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2915 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2916 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2917 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2918 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2919 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | } |
| 2921 | sb.append(linePrefix); |
| 2922 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2923 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2924 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2926 | sb.append(','); |
| 2927 | sb.append(current); |
| 2928 | sb.append(','); |
| 2929 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2930 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 2931 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 2932 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 2933 | if (name != null) { |
| 2934 | sb.append(','); |
| 2935 | sb.append(totalDuration); |
| 2936 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | return ","; |
| 2938 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2939 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2940 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2941 | String type) { |
| 2942 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2943 | pw.print(','); |
| 2944 | pw.print(uid); |
| 2945 | pw.print(','); |
| 2946 | pw.print(category); |
| 2947 | pw.print(','); |
| 2948 | pw.print(type); |
| 2949 | } |
| 2950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | /** |
| 2952 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2953 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | * @param pw the PageWriter to dump log to |
| 2955 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2956 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2957 | * @param args type-dependent data arguments |
| 2958 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2959 | 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] | 2960 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2961 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2962 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2963 | pw.print(','); |
| 2964 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2966 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2968 | |
| 2969 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2970 | * Dump a given timer stat for terse checkin mode. |
| 2971 | * |
| 2972 | * @param pw the PageWriter to dump log to |
| 2973 | * @param uid the UID to log |
| 2974 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2975 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2976 | * @param timer a {@link Timer} to dump stats for |
| 2977 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2978 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2979 | */ |
| 2980 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2981 | Timer timer, long rawRealtime, int which) { |
| 2982 | if (timer != null) { |
| 2983 | // Convert from microseconds to milliseconds with rounding |
| 2984 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2985 | / 1000; |
| 2986 | final int count = timer.getCountLocked(which); |
| 2987 | if (totalTime != 0) { |
| 2988 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | /** |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 2994 | * Dump a given timer stat to the proto stream. |
| 2995 | * |
| 2996 | * @param proto the ProtoOutputStream to log to |
| 2997 | * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK) |
| 2998 | * @param timer a {@link Timer} to dump stats for |
| 2999 | * @param rawRealtimeUs the current elapsed realtime of the system in microseconds |
| 3000 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 3001 | */ |
| 3002 | private static void dumpTimer(ProtoOutputStream proto, long fieldId, |
| 3003 | Timer timer, long rawRealtime, int which) { |
| 3004 | if (timer == null) { |
| 3005 | return; |
| 3006 | } |
| 3007 | // Convert from microseconds to milliseconds with rounding |
| 3008 | final long totalTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3009 | final int count = timer.getCountLocked(which); |
| 3010 | if (totalTimeMs != 0 || count != 0) { |
| 3011 | final long token = proto.start(fieldId); |
| 3012 | proto.write(TimerProto.DURATION_MS, totalTimeMs); |
| 3013 | proto.write(TimerProto.COUNT, count); |
| 3014 | proto.end(token); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3019 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 3020 | */ |
| 3021 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 3022 | if (counter == null) { |
| 3023 | return false; |
| 3024 | } |
| 3025 | |
| 3026 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 3027 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 3028 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 3029 | return true; |
| 3030 | } |
| 3031 | |
| 3032 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3033 | if (c.getCountLocked(which) != 0) { |
| 3034 | return true; |
| 3035 | } |
| 3036 | } |
| 3037 | return false; |
| 3038 | } |
| 3039 | |
| 3040 | /** |
| 3041 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3042 | * The order of the arguments in the final check in line is: |
| 3043 | * |
| 3044 | * idle, rx, power, tx... |
| 3045 | * |
| 3046 | * where tx... is one or more transmit level times. |
| 3047 | */ |
| 3048 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 3049 | String type, |
| 3050 | ControllerActivityCounter counter, |
| 3051 | int which) { |
| 3052 | if (!controllerActivityHasData(counter, which)) { |
| 3053 | return; |
| 3054 | } |
| 3055 | |
| 3056 | dumpLineHeader(pw, uid, category, type); |
| 3057 | pw.print(","); |
| 3058 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 3059 | pw.print(","); |
| 3060 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 3061 | pw.print(","); |
| 3062 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3063 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 3064 | pw.print(","); |
| 3065 | pw.print(c.getCountLocked(which)); |
| 3066 | } |
| 3067 | pw.println(); |
| 3068 | } |
| 3069 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 3070 | /** |
| 3071 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 3072 | */ |
| 3073 | private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId, |
| 3074 | ControllerActivityCounter counter, |
| 3075 | int which) { |
| 3076 | if (!controllerActivityHasData(counter, which)) { |
| 3077 | return; |
| 3078 | } |
| 3079 | |
| 3080 | final long cToken = proto.start(fieldId); |
| 3081 | |
| 3082 | proto.write(ControllerActivityProto.IDLE_DURATION_MS, |
| 3083 | counter.getIdleTimeCounter().getCountLocked(which)); |
| 3084 | proto.write(ControllerActivityProto.RX_DURATION_MS, |
| 3085 | counter.getRxTimeCounter().getCountLocked(which)); |
| 3086 | proto.write(ControllerActivityProto.POWER_MAH, |
| 3087 | counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 3088 | |
| 3089 | long tToken; |
| 3090 | LongCounter[] txCounters = counter.getTxTimeCounters(); |
| 3091 | for (int i = 0; i < txCounters.length; ++i) { |
| 3092 | LongCounter c = txCounters[i]; |
| 3093 | tToken = proto.start(ControllerActivityProto.TX); |
| 3094 | proto.write(ControllerActivityProto.TxLevel.LEVEL, i); |
| 3095 | proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which)); |
| 3096 | proto.end(tToken); |
| 3097 | } |
| 3098 | |
| 3099 | proto.end(cToken); |
| 3100 | } |
| 3101 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3102 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3103 | String prefix, String controllerName, |
| 3104 | ControllerActivityCounter counter, |
| 3105 | int which) { |
| 3106 | if (controllerActivityHasData(counter, which)) { |
| 3107 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3112 | String controllerName, |
| 3113 | ControllerActivityCounter counter, int which) { |
| 3114 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3115 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3116 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 3117 | long totalTxTimeMs = 0; |
| 3118 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3119 | totalTxTimeMs += txState.getCountLocked(which); |
| 3120 | } |
| 3121 | |
| 3122 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 3123 | |
| 3124 | sb.setLength(0); |
| 3125 | sb.append(prefix); |
| 3126 | sb.append(" "); |
| 3127 | sb.append(controllerName); |
| 3128 | sb.append(" Idle time: "); |
| 3129 | formatTimeMs(sb, idleTimeMs); |
| 3130 | sb.append("("); |
| 3131 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 3132 | sb.append(")"); |
| 3133 | pw.println(sb.toString()); |
| 3134 | |
| 3135 | sb.setLength(0); |
| 3136 | sb.append(prefix); |
| 3137 | sb.append(" "); |
| 3138 | sb.append(controllerName); |
| 3139 | sb.append(" Rx time: "); |
| 3140 | formatTimeMs(sb, rxTimeMs); |
| 3141 | sb.append("("); |
| 3142 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 3143 | sb.append(")"); |
| 3144 | pw.println(sb.toString()); |
| 3145 | |
| 3146 | sb.setLength(0); |
| 3147 | sb.append(prefix); |
| 3148 | sb.append(" "); |
| 3149 | sb.append(controllerName); |
| 3150 | sb.append(" Tx time: "); |
| 3151 | formatTimeMs(sb, totalTxTimeMs); |
| 3152 | sb.append("("); |
| 3153 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 3154 | sb.append(")"); |
| 3155 | pw.println(sb.toString()); |
| 3156 | |
| 3157 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 3158 | if (numTxLvls > 1) { |
| 3159 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3160 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3161 | sb.setLength(0); |
| 3162 | sb.append(prefix); |
| 3163 | sb.append(" ["); |
| 3164 | sb.append(lvl); |
| 3165 | sb.append("] "); |
| 3166 | formatTimeMs(sb, txLvlTimeMs); |
| 3167 | sb.append("("); |
| 3168 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 3169 | sb.append(")"); |
| 3170 | pw.println(sb.toString()); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | sb.setLength(0); |
| 3175 | sb.append(prefix); |
| 3176 | sb.append(" "); |
| 3177 | sb.append(controllerName); |
| 3178 | sb.append(" Power drain: ").append( |
| 3179 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 3180 | sb.append("mAh"); |
| 3181 | pw.println(sb.toString()); |
| 3182 | } |
| 3183 | |
| 3184 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3185 | * Temporary for settings. |
| 3186 | */ |
| 3187 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3188 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3189 | } |
| 3190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3191 | /** |
| 3192 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3193 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3196 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3197 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3199 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3200 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3203 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3204 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3205 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3206 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3208 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3209 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3210 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3211 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3212 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3213 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3214 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3215 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3216 | rawRealtime, which); |
| 3217 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3218 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3219 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3220 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3221 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3222 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3223 | final long dischargeCount = getMahDischarge(which); |
| 3224 | final long dischargeScreenOffCount = getMahDischargeScreenOff(which); |
| 3225 | final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3226 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3227 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3228 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3229 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3230 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3231 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3232 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3235 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3236 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3237 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3238 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3239 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3240 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3241 | getEstimatedBatteryCapacity(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3242 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(), |
| 3243 | screenDozeTime / 1000); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3244 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3245 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3246 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3247 | long fullWakeLockTimeTotal = 0; |
| 3248 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3249 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3250 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3251 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3252 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3253 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3254 | = u.getWakelockStats(); |
| 3255 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3256 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3257 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3258 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3259 | if (fullWakeTimer != null) { |
| 3260 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3261 | which); |
| 3262 | } |
| 3263 | |
| 3264 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3265 | if (partialWakeTimer != null) { |
| 3266 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3267 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3268 | } |
| 3269 | } |
| 3270 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3271 | |
| 3272 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3273 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3274 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3275 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3276 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3277 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3278 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3279 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3280 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3281 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3282 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3283 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3284 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3285 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3286 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3287 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3288 | // Dump Modem controller stats |
| 3289 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3290 | getModemControllerActivity(), which); |
| 3291 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3292 | // Dump Wifi controller stats |
| 3293 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3294 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3295 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3296 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3297 | |
| 3298 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3299 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3300 | |
| 3301 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3302 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3303 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | // Dump misc stats |
| 3306 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3307 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3308 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3309 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3310 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3311 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3312 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3313 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3314 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3315 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3316 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3317 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3318 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3319 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3320 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3321 | // Dump screen brightness stats |
| 3322 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3323 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3324 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3325 | } |
| 3326 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3327 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3328 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3329 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3330 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3331 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3332 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3333 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3334 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3335 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3336 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3337 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3338 | } |
| 3339 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3340 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3341 | // Dump network type stats |
| 3342 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3343 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3344 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3345 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3346 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3347 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3348 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3349 | } |
| 3350 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3351 | |
| 3352 | // Dump wifi state stats |
| 3353 | args = new Object[NUM_WIFI_STATES]; |
| 3354 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3355 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3356 | } |
| 3357 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3358 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3359 | args[i] = getWifiStateCount(i, which); |
| 3360 | } |
| 3361 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3362 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3363 | // Dump wifi suppl state stats |
| 3364 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3365 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3366 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3367 | } |
| 3368 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3369 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3370 | args[i] = getWifiSupplStateCount(i, which); |
| 3371 | } |
| 3372 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3373 | |
| 3374 | // Dump wifi signal strength stats |
| 3375 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3376 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3377 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3378 | } |
| 3379 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3380 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3381 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3382 | } |
| 3383 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3384 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3385 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3386 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3387 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3388 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3389 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3390 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3391 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3392 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3393 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3394 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3395 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
| 3396 | getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3397 | } else { |
| 3398 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3399 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3400 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3401 | getDischargeAmountScreenOffSinceCharge(), |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3402 | dischargeCount / 1000, dischargeScreenOffCount / 1000, |
| 3403 | getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3404 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3405 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3406 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3407 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3408 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3409 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3410 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3411 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3412 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3413 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3414 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3415 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3416 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3417 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3418 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3419 | // Not doing the regular wake lock formatting to remain compatible |
| 3420 | // with the old checkin format. |
| 3421 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3422 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3423 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3424 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3425 | } |
| 3426 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3427 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3428 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3429 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3430 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3431 | if (rpmStats.size() > 0) { |
| 3432 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3433 | sb.setLength(0); |
| 3434 | Timer totalTimer = ent.getValue(); |
| 3435 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3436 | int count = totalTimer.getCountLocked(which); |
| 3437 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3438 | long screenOffTimeMs = screenOffTimer != null |
| 3439 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3440 | int screenOffCount = screenOffTimer != null |
| 3441 | ? screenOffTimer.getCountLocked(which) : 0; |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3442 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 3443 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3444 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, |
| 3445 | screenOffCount); |
| 3446 | } else { |
| 3447 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3448 | "\"" + ent.getKey() + "\"", timeMs, count); |
| 3449 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3453 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3454 | helper.create(this); |
| 3455 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3456 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3457 | if (sippers != null && sippers.size() > 0) { |
| 3458 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3459 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3460 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3461 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3462 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3463 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3464 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3465 | int uid = 0; |
| 3466 | String label; |
| 3467 | switch (bs.drainType) { |
| 3468 | case IDLE: |
| 3469 | label="idle"; |
| 3470 | break; |
| 3471 | case CELL: |
| 3472 | label="cell"; |
| 3473 | break; |
| 3474 | case PHONE: |
| 3475 | label="phone"; |
| 3476 | break; |
| 3477 | case WIFI: |
| 3478 | label="wifi"; |
| 3479 | break; |
| 3480 | case BLUETOOTH: |
| 3481 | label="blue"; |
| 3482 | break; |
| 3483 | case SCREEN: |
| 3484 | label="scrn"; |
| 3485 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3486 | case FLASHLIGHT: |
| 3487 | label="flashlight"; |
| 3488 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3489 | case APP: |
| 3490 | uid = bs.uidObj.getUid(); |
| 3491 | label = "uid"; |
| 3492 | break; |
| 3493 | case USER: |
| 3494 | uid = UserHandle.getUid(bs.userId, 0); |
| 3495 | label = "user"; |
| 3496 | break; |
| 3497 | case UNACCOUNTED: |
| 3498 | label = "unacc"; |
| 3499 | break; |
| 3500 | case OVERCOUNTED: |
| 3501 | label = "over"; |
| 3502 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3503 | case CAMERA: |
| 3504 | label = "camera"; |
| 3505 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3506 | default: |
| 3507 | label = "???"; |
| 3508 | } |
| 3509 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3510 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3511 | bs.shouldHide ? 1 : 0, |
| 3512 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3513 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3517 | final long[] cpuFreqs = getCpuFreqs(); |
| 3518 | if (cpuFreqs != null) { |
| 3519 | sb.setLength(0); |
| 3520 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3521 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3522 | } |
| 3523 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3524 | } |
| 3525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | for (int iu = 0; iu < NU; iu++) { |
| 3527 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3528 | if (reqUid >= 0 && uid != reqUid) { |
| 3529 | continue; |
| 3530 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3531 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3534 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3535 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3536 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3537 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3538 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3539 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3540 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3541 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3542 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3543 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3544 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3545 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3546 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3547 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3548 | // Background data transfers |
| 3549 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3550 | which); |
| 3551 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3552 | which); |
| 3553 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3554 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3555 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3556 | which); |
| 3557 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3558 | which); |
| 3559 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3560 | which); |
| 3561 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3562 | which); |
| 3563 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3564 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3565 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3566 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3567 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3568 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3569 | || wifiBytesBgTx > 0 |
| 3570 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3571 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3572 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3573 | wifiBytesRx, wifiBytesTx, |
| 3574 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3575 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3576 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3577 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3578 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3579 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3580 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3581 | } |
| 3582 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3583 | // Dump modem controller data, per UID. |
| 3584 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3585 | u.getModemControllerActivity(), which); |
| 3586 | |
| 3587 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3588 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3589 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3590 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3591 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3592 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3593 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3594 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3595 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3596 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3597 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3598 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3599 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3600 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3601 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3602 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3603 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3606 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3607 | u.getWifiControllerActivity(), which); |
| 3608 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3609 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3610 | if (bleTimer != null) { |
| 3611 | // Convert from microseconds to milliseconds with rounding |
| 3612 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3613 | / 1000; |
| 3614 | if (totalTime != 0) { |
| 3615 | final int count = bleTimer.getCountLocked(which); |
| 3616 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3617 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3618 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3619 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3620 | final long actualTimeBg = bleTimerBg != null ? |
| 3621 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3622 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3623 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3624 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3625 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3626 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3627 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3628 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3629 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3630 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3631 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3632 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3633 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3634 | final Timer unoptimizedScanTimerBg = |
| 3635 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3636 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3637 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3638 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3639 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3640 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3641 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3642 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3643 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3644 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3645 | } |
| 3646 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3647 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3648 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3649 | u.getBluetoothControllerActivity(), which); |
| 3650 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3651 | if (u.hasUserActivity()) { |
| 3652 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3653 | boolean hasData = false; |
| 3654 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3655 | int val = u.getUserActivityCount(i, which); |
| 3656 | args[i] = val; |
| 3657 | if (val != 0) hasData = true; |
| 3658 | } |
| 3659 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3660 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3661 | } |
| 3662 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3663 | |
| 3664 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3665 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3666 | // Times are since reset (regardless of 'which') |
| 3667 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3668 | final Timer bgTimer = timer.getSubTimer(); |
| 3669 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3670 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3671 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3672 | } |
| 3673 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3674 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3675 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3676 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3677 | String linePrefix = ""; |
| 3678 | sb.setLength(0); |
| 3679 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3680 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3681 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3682 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3683 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3684 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3685 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3686 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3687 | rawRealtime, "w", which, linePrefix); |
| 3688 | |
| 3689 | // Only log if we had at lease one wakelock... |
| 3690 | if (sb.length() > 0) { |
| 3691 | String name = wakelocks.keyAt(iw); |
| 3692 | if (name.indexOf(',') >= 0) { |
| 3693 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3695 | if (name.indexOf('\n') >= 0) { |
| 3696 | name = name.replace('\n', '_'); |
| 3697 | } |
| 3698 | if (name.indexOf('\r') >= 0) { |
| 3699 | name = name.replace('\r', '_'); |
| 3700 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3701 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | } |
| 3703 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3704 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3705 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3706 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3707 | final Timer timer = syncs.valueAt(isy); |
| 3708 | // Convert from microseconds to milliseconds with rounding |
| 3709 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3710 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3711 | final Timer bgTimer = timer.getSubTimer(); |
| 3712 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3713 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3714 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3715 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3716 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3717 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3718 | } |
| 3719 | } |
| 3720 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3721 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3722 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3723 | final Timer timer = jobs.valueAt(ij); |
| 3724 | // Convert from microseconds to milliseconds with rounding |
| 3725 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3726 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3727 | final Timer bgTimer = timer.getSubTimer(); |
| 3728 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3729 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3730 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3731 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3732 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3733 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3737 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3738 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3739 | SparseIntArray types = completions.valueAt(ic); |
| 3740 | if (types != null) { |
| 3741 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3742 | "\"" + completions.keyAt(ic) + "\"", |
| 3743 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3744 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3745 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3746 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3747 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3748 | } |
| 3749 | } |
| 3750 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3751 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3752 | rawRealtime, which); |
| 3753 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3754 | rawRealtime, which); |
| 3755 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3756 | rawRealtime, which); |
| 3757 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3758 | rawRealtime, which); |
| 3759 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3760 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3761 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3762 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3763 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3764 | final int sensorNumber = sensors.keyAt(ise); |
| 3765 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3766 | if (timer != null) { |
| 3767 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3768 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3769 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3770 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3771 | final int count = timer.getCountLocked(which); |
| 3772 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3773 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3774 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3775 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3776 | final long bgActualTime = bgTimer != null ? |
| 3777 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3778 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3779 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3784 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3785 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3786 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 3787 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 3788 | rawRealtime, which); |
| 3789 | |
| 3790 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3791 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3792 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3793 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3794 | long totalStateTime = 0; |
| 3795 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3796 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3797 | totalStateTime += time; |
| 3798 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3799 | } |
| 3800 | if (totalStateTime > 0) { |
| 3801 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3802 | } |
| 3803 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3804 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3805 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3806 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3807 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3808 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3811 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 3812 | if (cpuFreqs != null) { |
| 3813 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3814 | // If total cpuFreqTimes is null, then we don't need to check for |
| 3815 | // screenOffCpuFreqTimes. |
| 3816 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 3817 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3818 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3819 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3820 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3821 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3822 | if (screenOffCpuFreqTimeMs != null) { |
| 3823 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3824 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3825 | } |
| 3826 | } else { |
| 3827 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3828 | sb.append(",0"); |
| 3829 | } |
| 3830 | } |
| 3831 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 3832 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3833 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3836 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3837 | = u.getProcessStats(); |
| 3838 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3839 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3840 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3841 | final long userMillis = ps.getUserTime(which); |
| 3842 | final long systemMillis = ps.getSystemTime(which); |
| 3843 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3844 | final int starts = ps.getStarts(which); |
| 3845 | final int numCrashes = ps.getNumCrashes(which); |
| 3846 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3847 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3848 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3849 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3850 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3851 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3855 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3856 | = u.getPackageStats(); |
| 3857 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3858 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3859 | int wakeups = 0; |
| 3860 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3861 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3862 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3863 | wakeups += count; |
| 3864 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3865 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3866 | } |
| 3867 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3868 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3869 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3870 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3871 | final int starts = ss.getStarts(which); |
| 3872 | final int launches = ss.getLaunches(which); |
| 3873 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3874 | dumpLine(pw, uid, category, APK_DATA, |
| 3875 | wakeups, // wakeup alarms |
| 3876 | packageStats.keyAt(ipkg), // Apk |
| 3877 | serviceStats.keyAt(isvc), // service |
| 3878 | startTime / 1000, // time spent started, in ms |
| 3879 | starts, |
| 3880 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | } |
| 3885 | } |
| 3886 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3887 | static final class TimerEntry { |
| 3888 | final String mName; |
| 3889 | final int mId; |
| 3890 | final BatteryStats.Timer mTimer; |
| 3891 | final long mTime; |
| 3892 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3893 | mName = name; |
| 3894 | mId = id; |
| 3895 | mTimer = timer; |
| 3896 | mTime = time; |
| 3897 | } |
| 3898 | } |
| 3899 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3900 | private void printmAh(PrintWriter printer, double power) { |
| 3901 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3902 | } |
| 3903 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3904 | private void printmAh(StringBuilder sb, double power) { |
| 3905 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3906 | } |
| 3907 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3908 | /** |
| 3909 | * Temporary for settings. |
| 3910 | */ |
| 3911 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3912 | int reqUid) { |
| 3913 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3914 | } |
| 3915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3917 | 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] | 3918 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3920 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3921 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | |
| 3924 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3925 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3926 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3927 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3928 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3929 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3930 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3931 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3932 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3933 | final long screenDozeTime = getScreenDozeTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3934 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3935 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3936 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3937 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3938 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3940 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3941 | if (estimatedBatteryCapacity > 0) { |
| 3942 | sb.setLength(0); |
| 3943 | sb.append(prefix); |
| 3944 | sb.append(" Estimated battery capacity: "); |
| 3945 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3946 | sb.append(" mAh"); |
| 3947 | pw.println(sb.toString()); |
| 3948 | } |
| 3949 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3950 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3951 | if (minLearnedBatteryCapacity > 0) { |
| 3952 | sb.setLength(0); |
| 3953 | sb.append(prefix); |
| 3954 | sb.append(" Min learned battery capacity: "); |
| 3955 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3956 | sb.append(" mAh"); |
| 3957 | pw.println(sb.toString()); |
| 3958 | } |
| 3959 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3960 | if (maxLearnedBatteryCapacity > 0) { |
| 3961 | sb.setLength(0); |
| 3962 | sb.append(prefix); |
| 3963 | sb.append(" Max learned battery capacity: "); |
| 3964 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3965 | sb.append(" mAh"); |
| 3966 | pw.println(sb.toString()); |
| 3967 | } |
| 3968 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3969 | sb.setLength(0); |
| 3970 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3971 | sb.append(" Time on battery: "); |
| 3972 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3973 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3974 | sb.append(") realtime, "); |
| 3975 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3976 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime)); |
| 3977 | sb.append(") uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3978 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3979 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3980 | sb.setLength(0); |
| 3981 | sb.append(prefix); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3982 | sb.append(" Time on battery screen off: "); |
| 3983 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3984 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime)); |
| 3985 | sb.append(") realtime, "); |
| 3986 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3987 | sb.append("("); |
| 3988 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime)); |
| 3989 | sb.append(") uptime"); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3990 | pw.println(sb.toString()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3991 | |
| 3992 | sb.setLength(0); |
| 3993 | sb.append(prefix); |
| 3994 | sb.append(" Time on battery screen doze: "); |
| 3995 | formatTimeMs(sb, screenDozeTime / 1000); sb.append("("); |
| 3996 | sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime)); |
| 3997 | sb.append(")"); |
| 3998 | pw.println(sb.toString()); |
| 3999 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4000 | sb.setLength(0); |
| 4001 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4002 | sb.append(" Total run time: "); |
| 4003 | formatTimeMs(sb, totalRealtime / 1000); |
| 4004 | sb.append("realtime, "); |
| 4005 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4006 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4007 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4008 | if (batteryTimeRemaining >= 0) { |
| 4009 | sb.setLength(0); |
| 4010 | sb.append(prefix); |
| 4011 | sb.append(" Battery time remaining: "); |
| 4012 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 4013 | pw.println(sb.toString()); |
| 4014 | } |
| 4015 | if (chargeTimeRemaining >= 0) { |
| 4016 | sb.setLength(0); |
| 4017 | sb.append(prefix); |
| 4018 | sb.append(" Charge time remaining: "); |
| 4019 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 4020 | pw.println(sb.toString()); |
| 4021 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4022 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4023 | final long dischargeCount = getMahDischarge(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4024 | if (dischargeCount >= 0) { |
| 4025 | sb.setLength(0); |
| 4026 | sb.append(prefix); |
| 4027 | sb.append(" Discharge: "); |
| 4028 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 4029 | sb.append(" mAh"); |
| 4030 | pw.println(sb.toString()); |
| 4031 | } |
| 4032 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4033 | final long dischargeScreenOffCount = getMahDischargeScreenOff(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4034 | if (dischargeScreenOffCount >= 0) { |
| 4035 | sb.setLength(0); |
| 4036 | sb.append(prefix); |
| 4037 | sb.append(" Screen off discharge: "); |
| 4038 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 4039 | sb.append(" mAh"); |
| 4040 | pw.println(sb.toString()); |
| 4041 | } |
| 4042 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4043 | final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which); |
| 4044 | if (dischargeScreenDozeCount >= 0) { |
| 4045 | sb.setLength(0); |
| 4046 | sb.append(prefix); |
| 4047 | sb.append(" Screen doze discharge: "); |
| 4048 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0)); |
| 4049 | sb.append(" mAh"); |
| 4050 | pw.println(sb.toString()); |
| 4051 | } |
| 4052 | |
| 4053 | final long dischargeScreenOnCount = |
| 4054 | dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 4055 | if (dischargeScreenOnCount >= 0) { |
| 4056 | sb.setLength(0); |
| 4057 | sb.append(prefix); |
| 4058 | sb.append(" Screen on discharge: "); |
| 4059 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 4060 | sb.append(" mAh"); |
| 4061 | pw.println(sb.toString()); |
| 4062 | } |
| 4063 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4064 | pw.print(" Start clock time: "); |
| 4065 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 4066 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4067 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4068 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4069 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4070 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 4071 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4072 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4073 | rawRealtime, which); |
| 4074 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 4075 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4076 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4077 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4078 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 4079 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 4080 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4081 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4082 | sb.append(prefix); |
| 4083 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 4084 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4085 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4086 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 4087 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4088 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4089 | pw.println(sb.toString()); |
| 4090 | sb.setLength(0); |
| 4091 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4092 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4093 | boolean didOne = false; |
| 4094 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4095 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4096 | if (time == 0) { |
| 4097 | continue; |
| 4098 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4099 | sb.append("\n "); |
| 4100 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4101 | didOne = true; |
| 4102 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 4103 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4104 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4105 | sb.append("("); |
| 4106 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 4107 | sb.append(")"); |
| 4108 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4109 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4110 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4111 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4112 | sb.setLength(0); |
| 4113 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4114 | sb.append(" Power save mode enabled: "); |
| 4115 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4116 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4117 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4118 | sb.append(")"); |
| 4119 | pw.println(sb.toString()); |
| 4120 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4121 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4122 | sb.setLength(0); |
| 4123 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4124 | sb.append(" Device light idling: "); |
| 4125 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4126 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4127 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4128 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4129 | sb.append("x"); |
| 4130 | pw.println(sb.toString()); |
| 4131 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4132 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4133 | sb.setLength(0); |
| 4134 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4135 | sb.append(" Idle mode light time: "); |
| 4136 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4137 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4138 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4139 | sb.append(") "); |
| 4140 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4141 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4142 | sb.append(" -- longest "); |
| 4143 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4144 | pw.println(sb.toString()); |
| 4145 | } |
| 4146 | if (deviceIdlingTime != 0) { |
| 4147 | sb.setLength(0); |
| 4148 | sb.append(prefix); |
| 4149 | sb.append(" Device full idling: "); |
| 4150 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4151 | sb.append("("); |
| 4152 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4153 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4154 | sb.append("x"); |
| 4155 | pw.println(sb.toString()); |
| 4156 | } |
| 4157 | if (deviceIdleModeFullTime != 0) { |
| 4158 | sb.setLength(0); |
| 4159 | sb.append(prefix); |
| 4160 | sb.append(" Idle mode full time: "); |
| 4161 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4162 | sb.append("("); |
| 4163 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4164 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4165 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4166 | sb.append("x"); |
| 4167 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4168 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4169 | pw.println(sb.toString()); |
| 4170 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4171 | if (phoneOnTime != 0) { |
| 4172 | sb.setLength(0); |
| 4173 | sb.append(prefix); |
| 4174 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4175 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4176 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4177 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4178 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4179 | if (connChanges != 0) { |
| 4180 | pw.print(prefix); |
| 4181 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4182 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4183 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4184 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4185 | long fullWakeLockTimeTotalMicros = 0; |
| 4186 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4187 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4188 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4189 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4190 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4191 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4192 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4193 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4194 | = u.getWakelockStats(); |
| 4195 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4196 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4197 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4198 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4199 | if (fullWakeTimer != null) { |
| 4200 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4201 | rawRealtime, which); |
| 4202 | } |
| 4203 | |
| 4204 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4205 | if (partialWakeTimer != null) { |
| 4206 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4207 | rawRealtime, which); |
| 4208 | if (totalTimeMicros > 0) { |
| 4209 | if (reqUid < 0) { |
| 4210 | // Only show the ordered list of all wake |
| 4211 | // locks if the caller is not asking for data |
| 4212 | // about a specific uid. |
| 4213 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4214 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4215 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4216 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | } |
| 4220 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4221 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4222 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4223 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4224 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4225 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4226 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4227 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4228 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4229 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4230 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4231 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4232 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4233 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4234 | sb.setLength(0); |
| 4235 | sb.append(prefix); |
| 4236 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4237 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4238 | pw.println(sb.toString()); |
| 4239 | } |
| 4240 | |
| 4241 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4242 | sb.setLength(0); |
| 4243 | sb.append(prefix); |
| 4244 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4245 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4246 | pw.println(sb.toString()); |
| 4247 | } |
| 4248 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4249 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4250 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 4251 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 4252 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 4253 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4254 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4255 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4256 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4257 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4258 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4259 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4260 | if (time == 0) { |
| 4261 | continue; |
| 4262 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4263 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4264 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4265 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4266 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4267 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4268 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4269 | sb.append("("); |
| 4270 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4271 | sb.append(") "); |
| 4272 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 4273 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4274 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4275 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4276 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4277 | |
| 4278 | sb.setLength(0); |
| 4279 | sb.append(prefix); |
| 4280 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4281 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4282 | pw.println(sb.toString()); |
| 4283 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4284 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4285 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4286 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4287 | didOne = false; |
| 4288 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4289 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4290 | if (time == 0) { |
| 4291 | continue; |
| 4292 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4293 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4294 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4295 | didOne = true; |
| 4296 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4297 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4298 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4299 | sb.append("("); |
| 4300 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4301 | sb.append(") "); |
| 4302 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 4303 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4304 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4305 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4306 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4307 | |
| 4308 | sb.setLength(0); |
| 4309 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4310 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4311 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4312 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4313 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4314 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 4315 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4316 | pw.println(sb.toString()); |
| 4317 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4318 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 4319 | if (mobileActiveUnknownTime != 0) { |
| 4320 | sb.setLength(0); |
| 4321 | sb.append(prefix); |
| 4322 | sb.append(" Mobile radio active unknown time: "); |
| 4323 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 4324 | sb.append("("); |
| 4325 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 4326 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 4327 | sb.append("x"); |
| 4328 | pw.println(sb.toString()); |
| 4329 | } |
| 4330 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4331 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 4332 | if (mobileActiveAdjustedTime != 0) { |
| 4333 | sb.setLength(0); |
| 4334 | sb.append(prefix); |
| 4335 | sb.append(" Mobile radio active adjusted time: "); |
| 4336 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 4337 | sb.append("("); |
| 4338 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 4339 | sb.append(")"); |
| 4340 | pw.println(sb.toString()); |
| 4341 | } |
| 4342 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4343 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 4344 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4345 | pw.print(prefix); |
| 4346 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 4347 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 4348 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 4349 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4350 | sb.setLength(0); |
| 4351 | sb.append(prefix); |
| 4352 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 4353 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 4354 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 4355 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4356 | sb.append(")"); |
| 4357 | pw.println(sb.toString()); |
| 4358 | |
| 4359 | sb.setLength(0); |
| 4360 | sb.append(prefix); |
| 4361 | sb.append(" Wifi states:"); |
| 4362 | didOne = false; |
| 4363 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4364 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4365 | if (time == 0) { |
| 4366 | continue; |
| 4367 | } |
| 4368 | sb.append("\n "); |
| 4369 | didOne = true; |
| 4370 | sb.append(WIFI_STATE_NAMES[i]); |
| 4371 | sb.append(" "); |
| 4372 | formatTimeMs(sb, time/1000); |
| 4373 | sb.append("("); |
| 4374 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4375 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4376 | sb.append(getWifiStateCount(i, which)); |
| 4377 | sb.append("x"); |
| 4378 | } |
| 4379 | if (!didOne) sb.append(" (no activity)"); |
| 4380 | pw.println(sb.toString()); |
| 4381 | |
| 4382 | sb.setLength(0); |
| 4383 | sb.append(prefix); |
| 4384 | sb.append(" Wifi supplicant states:"); |
| 4385 | didOne = false; |
| 4386 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4387 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4388 | if (time == 0) { |
| 4389 | continue; |
| 4390 | } |
| 4391 | sb.append("\n "); |
| 4392 | didOne = true; |
| 4393 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4394 | sb.append(" "); |
| 4395 | formatTimeMs(sb, time/1000); |
| 4396 | sb.append("("); |
| 4397 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4398 | sb.append(") "); |
| 4399 | sb.append(getWifiSupplStateCount(i, which)); |
| 4400 | sb.append("x"); |
| 4401 | } |
| 4402 | if (!didOne) sb.append(" (no activity)"); |
| 4403 | pw.println(sb.toString()); |
| 4404 | |
| 4405 | sb.setLength(0); |
| 4406 | sb.append(prefix); |
| 4407 | sb.append(" Wifi signal levels:"); |
| 4408 | didOne = false; |
| 4409 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4410 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4411 | if (time == 0) { |
| 4412 | continue; |
| 4413 | } |
| 4414 | sb.append("\n "); |
| 4415 | sb.append(prefix); |
| 4416 | didOne = true; |
| 4417 | sb.append("level("); |
| 4418 | sb.append(i); |
| 4419 | sb.append(") "); |
| 4420 | formatTimeMs(sb, time/1000); |
| 4421 | sb.append("("); |
| 4422 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4423 | sb.append(") "); |
| 4424 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4425 | sb.append("x"); |
| 4426 | } |
| 4427 | if (!didOne) sb.append(" (no activity)"); |
| 4428 | pw.println(sb.toString()); |
| 4429 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4430 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4431 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4432 | pw.print(prefix); |
| 4433 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4434 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4435 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4436 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4437 | sb.setLength(0); |
| 4438 | sb.append(prefix); |
| 4439 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4440 | pw.println(sb.toString()); |
| 4441 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4442 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4443 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4444 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4445 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4446 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4447 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4448 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4449 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4450 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4451 | pw.println(getDischargeStartLevel()); |
| 4452 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4453 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4454 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4455 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4456 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4457 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4458 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4459 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4460 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4461 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4462 | pw.println(getDischargeAmountScreenOn()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4463 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4464 | pw.println(getDischargeAmountScreenOff()); |
| 4465 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4466 | pw.println(getDischargeAmountScreenDoze()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4467 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4468 | } else { |
| 4469 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4470 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4471 | pw.println(getLowDischargeAmountSinceCharge()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4472 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4473 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4474 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4475 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4476 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4477 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
| 4478 | pw.print(prefix); pw.print(" Amount discharged while screen doze: "); |
| 4479 | pw.println(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4480 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4481 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4482 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4483 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4484 | helper.create(this); |
| 4485 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4486 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4487 | if (sippers != null && sippers.size() > 0) { |
| 4488 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4489 | pw.print(prefix); pw.print(" Capacity: "); |
| 4490 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4491 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4492 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4493 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4494 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4495 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4496 | pw.println(); |
| 4497 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4498 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4499 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4500 | switch (bs.drainType) { |
| 4501 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4502 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4503 | break; |
| 4504 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4505 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4506 | break; |
| 4507 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4508 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4509 | break; |
| 4510 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4511 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4512 | break; |
| 4513 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4514 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4515 | break; |
| 4516 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4517 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4518 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4519 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4520 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4521 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4522 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4523 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4524 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4525 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4526 | break; |
| 4527 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4528 | pw.print(" User "); pw.print(bs.userId); |
| 4529 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4530 | break; |
| 4531 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4532 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4533 | break; |
| 4534 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4535 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4536 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4537 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4538 | pw.print(" Camera: "); |
| 4539 | break; |
| 4540 | default: |
| 4541 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4542 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4543 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4544 | printmAh(pw, bs.totalPowerMah); |
| 4545 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4546 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4547 | // If the usage (generic power) isn't the whole amount, we list out |
| 4548 | // what components are involved in the calculation. |
| 4549 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4550 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4551 | if (bs.usagePowerMah != 0) { |
| 4552 | pw.print(" usage="); |
| 4553 | printmAh(pw, bs.usagePowerMah); |
| 4554 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4555 | if (bs.cpuPowerMah != 0) { |
| 4556 | pw.print(" cpu="); |
| 4557 | printmAh(pw, bs.cpuPowerMah); |
| 4558 | } |
| 4559 | if (bs.wakeLockPowerMah != 0) { |
| 4560 | pw.print(" wake="); |
| 4561 | printmAh(pw, bs.wakeLockPowerMah); |
| 4562 | } |
| 4563 | if (bs.mobileRadioPowerMah != 0) { |
| 4564 | pw.print(" radio="); |
| 4565 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4566 | } |
| 4567 | if (bs.wifiPowerMah != 0) { |
| 4568 | pw.print(" wifi="); |
| 4569 | printmAh(pw, bs.wifiPowerMah); |
| 4570 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4571 | if (bs.bluetoothPowerMah != 0) { |
| 4572 | pw.print(" bt="); |
| 4573 | printmAh(pw, bs.bluetoothPowerMah); |
| 4574 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4575 | if (bs.gpsPowerMah != 0) { |
| 4576 | pw.print(" gps="); |
| 4577 | printmAh(pw, bs.gpsPowerMah); |
| 4578 | } |
| 4579 | if (bs.sensorPowerMah != 0) { |
| 4580 | pw.print(" sensor="); |
| 4581 | printmAh(pw, bs.sensorPowerMah); |
| 4582 | } |
| 4583 | if (bs.cameraPowerMah != 0) { |
| 4584 | pw.print(" camera="); |
| 4585 | printmAh(pw, bs.cameraPowerMah); |
| 4586 | } |
| 4587 | if (bs.flashlightPowerMah != 0) { |
| 4588 | pw.print(" flash="); |
| 4589 | printmAh(pw, bs.flashlightPowerMah); |
| 4590 | } |
| 4591 | pw.print(" )"); |
| 4592 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4593 | |
| 4594 | // If there is additional smearing information, include it. |
| 4595 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4596 | pw.print(" Including smearing: "); |
| 4597 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4598 | pw.print(" ("); |
| 4599 | if (bs.screenPowerMah != 0) { |
| 4600 | pw.print(" screen="); |
| 4601 | printmAh(pw, bs.screenPowerMah); |
| 4602 | } |
| 4603 | if (bs.proportionalSmearMah != 0) { |
| 4604 | pw.print(" proportional="); |
| 4605 | printmAh(pw, bs.proportionalSmearMah); |
| 4606 | } |
| 4607 | pw.print(" )"); |
| 4608 | } |
| 4609 | if (bs.shouldHide) { |
| 4610 | pw.print(" Excluded from smearing"); |
| 4611 | } |
| 4612 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4613 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4614 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4615 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4616 | } |
| 4617 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4618 | sippers = helper.getMobilemsppList(); |
| 4619 | if (sippers != null && sippers.size() > 0) { |
| 4620 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4621 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4622 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4623 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4624 | sb.setLength(0); |
| 4625 | sb.append(prefix); sb.append(" Uid "); |
| 4626 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4627 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4628 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4629 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4630 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4631 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4632 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4633 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4634 | sb.setLength(0); |
| 4635 | sb.append(prefix); |
| 4636 | sb.append(" TOTAL TIME: "); |
| 4637 | formatTimeMs(sb, totalTime); |
| 4638 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4639 | sb.append(")"); |
| 4640 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4641 | pw.println(); |
| 4642 | } |
| 4643 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4644 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4645 | @Override |
| 4646 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4647 | long lhsTime = lhs.mTime; |
| 4648 | long rhsTime = rhs.mTime; |
| 4649 | if (lhsTime < rhsTime) { |
| 4650 | return 1; |
| 4651 | } |
| 4652 | if (lhsTime > rhsTime) { |
| 4653 | return -1; |
| 4654 | } |
| 4655 | return 0; |
| 4656 | } |
| 4657 | }; |
| 4658 | |
| 4659 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4660 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4661 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4662 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4663 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4664 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4665 | : kernelWakelocks.entrySet()) { |
| 4666 | final BatteryStats.Timer timer = ent.getValue(); |
| 4667 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4668 | if (totalTimeMillis > 0) { |
| 4669 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4670 | } |
| 4671 | } |
| 4672 | if (ktimers.size() > 0) { |
| 4673 | Collections.sort(ktimers, timerComparator); |
| 4674 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4675 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4676 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4677 | String linePrefix = ": "; |
| 4678 | sb.setLength(0); |
| 4679 | sb.append(prefix); |
| 4680 | sb.append(" Kernel Wake lock "); |
| 4681 | sb.append(timer.mName); |
| 4682 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4683 | which, linePrefix); |
| 4684 | if (!linePrefix.equals(": ")) { |
| 4685 | sb.append(" realtime"); |
| 4686 | // Only print out wake locks that were held |
| 4687 | pw.println(sb.toString()); |
| 4688 | } |
| 4689 | } |
| 4690 | pw.println(); |
| 4691 | } |
| 4692 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4693 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4694 | if (timers.size() > 0) { |
| 4695 | Collections.sort(timers, timerComparator); |
| 4696 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4697 | for (int i=0; i<timers.size(); i++) { |
| 4698 | TimerEntry timer = timers.get(i); |
| 4699 | sb.setLength(0); |
| 4700 | sb.append(" Wake lock "); |
| 4701 | UserHandle.formatUid(sb, timer.mId); |
| 4702 | sb.append(" "); |
| 4703 | sb.append(timer.mName); |
| 4704 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4705 | sb.append(" realtime"); |
| 4706 | pw.println(sb.toString()); |
| 4707 | } |
| 4708 | timers.clear(); |
| 4709 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4710 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4711 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4712 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4713 | if (wakeupReasons.size() > 0) { |
| 4714 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4715 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4716 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4717 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4718 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4719 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4720 | } |
| 4721 | Collections.sort(reasons, timerComparator); |
| 4722 | for (int i=0; i<reasons.size(); i++) { |
| 4723 | TimerEntry timer = reasons.get(i); |
| 4724 | String linePrefix = ": "; |
| 4725 | sb.setLength(0); |
| 4726 | sb.append(prefix); |
| 4727 | sb.append(" Wakeup reason "); |
| 4728 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4729 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4730 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4731 | pw.println(sb.toString()); |
| 4732 | } |
| 4733 | pw.println(); |
| 4734 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4735 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4736 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4737 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4738 | if (mMemoryStats.size() > 0) { |
| 4739 | pw.println(" Memory Stats"); |
| 4740 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4741 | sb.setLength(0); |
| 4742 | sb.append(" Bandwidth "); |
| 4743 | sb.append(mMemoryStats.keyAt(i)); |
| 4744 | sb.append(" Time "); |
| 4745 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4746 | pw.println(sb.toString()); |
| 4747 | } |
| 4748 | pw.println(); |
| 4749 | } |
| 4750 | |
| 4751 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 4752 | if (rpmStats.size() > 0) { |
| 4753 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 4754 | if (rpmStats.size() > 0) { |
| 4755 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 4756 | final String timerName = ent.getKey(); |
| 4757 | final Timer timer = ent.getValue(); |
| 4758 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4759 | } |
| 4760 | } |
| 4761 | pw.println(); |
| 4762 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4763 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 4764 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4765 | if (screenOffRpmStats.size() > 0) { |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4766 | pw.print(prefix); |
| 4767 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 4768 | if (screenOffRpmStats.size() > 0) { |
| 4769 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 4770 | final String timerName = ent.getKey(); |
| 4771 | final Timer timer = ent.getValue(); |
| 4772 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4773 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4774 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4775 | pw.println(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4776 | } |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4779 | final long[] cpuFreqs = getCpuFreqs(); |
| 4780 | if (cpuFreqs != null) { |
| 4781 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4782 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4783 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4784 | sb.append(" " + cpuFreqs[i]); |
| 4785 | } |
| 4786 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 4787 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4788 | } |
| 4789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | for (int iu=0; iu<NU; iu++) { |
| 4791 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4792 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4793 | continue; |
| 4794 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4795 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4796 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4797 | |
| 4798 | pw.print(prefix); |
| 4799 | pw.print(" "); |
| 4800 | UserHandle.formatUid(pw, uid); |
| 4801 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4803 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4804 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4805 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4806 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4807 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4808 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4809 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4810 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4811 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4812 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4813 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4814 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4815 | |
| 4816 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4817 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4818 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4819 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4820 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4821 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4822 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4823 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4824 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4825 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4826 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4827 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4828 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4829 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4830 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4831 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4832 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4833 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4834 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4835 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4836 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4837 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4839 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4840 | sb.setLength(0); |
| 4841 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4842 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4843 | sb.append("("); |
| 4844 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4845 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4846 | long packets = mobileRxPackets + mobileTxPackets; |
| 4847 | if (packets == 0) { |
| 4848 | packets = 1; |
| 4849 | } |
| 4850 | sb.append(" @ "); |
| 4851 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4852 | sb.append(" mspp"); |
| 4853 | pw.println(sb.toString()); |
| 4854 | } |
| 4855 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4856 | if (mobileWakeup > 0) { |
| 4857 | sb.setLength(0); |
| 4858 | sb.append(prefix); |
| 4859 | sb.append(" Mobile radio AP wakeups: "); |
| 4860 | sb.append(mobileWakeup); |
| 4861 | pw.println(sb.toString()); |
| 4862 | } |
| 4863 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4864 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4865 | u.getModemControllerActivity(), which); |
| 4866 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4867 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4868 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4869 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4870 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4871 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4872 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4875 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4876 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4877 | || uidWifiRunningTime != 0) { |
| 4878 | sb.setLength(0); |
| 4879 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4880 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4881 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4882 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4883 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4884 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4885 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4886 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4887 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4888 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4889 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4890 | whichBatteryRealtime)); sb.append(") "); |
| 4891 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4892 | sb.append("x\n"); |
| 4893 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4894 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4895 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4896 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4897 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4898 | sb.append(") "); |
| 4899 | sb.append(wifiScanCount); |
| 4900 | sb.append("x\n"); |
| 4901 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4902 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4903 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4904 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4905 | sb.append(") "); |
| 4906 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4907 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4908 | pw.println(sb.toString()); |
| 4909 | } |
| 4910 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4911 | if (wifiWakeup > 0) { |
| 4912 | sb.setLength(0); |
| 4913 | sb.append(prefix); |
| 4914 | sb.append(" WiFi AP wakeups: "); |
| 4915 | sb.append(wifiWakeup); |
| 4916 | pw.println(sb.toString()); |
| 4917 | } |
| 4918 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4919 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4920 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4921 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4922 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4923 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4924 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4925 | pw.print(formatBytesLocked(btTxBytes)); |
| 4926 | pw.println(" sent"); |
| 4927 | } |
| 4928 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4929 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4930 | if (bleTimer != null) { |
| 4931 | // Convert from microseconds to milliseconds with rounding |
| 4932 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4933 | / 1000; |
| 4934 | if (totalTimeMs != 0) { |
| 4935 | final int count = bleTimer.getCountLocked(which); |
| 4936 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4937 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4938 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4939 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4940 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4941 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4942 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4943 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4944 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4945 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 4946 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 4947 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 4948 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 4949 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 4950 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4951 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 4952 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 4953 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 4954 | final Timer unoptimizedScanTimerBg = |
| 4955 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 4956 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 4957 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4958 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 4959 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4960 | |
| 4961 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4962 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4963 | sb.append(prefix); |
| 4964 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4965 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4966 | sb.append(" ("); |
| 4967 | sb.append(count); |
| 4968 | sb.append(" times)"); |
| 4969 | if (bleTimer.isRunningLocked()) { |
| 4970 | sb.append(" (currently running)"); |
| 4971 | } |
| 4972 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4973 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4974 | |
| 4975 | sb.append(prefix); |
| 4976 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 4977 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 4978 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4979 | sb.append(count); |
| 4980 | sb.append(" times)"); |
| 4981 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4982 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4983 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4984 | sb.append("\n"); |
| 4985 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 4986 | sb.append(prefix); |
| 4987 | sb.append(" Bluetooth Scan (background realtime): "); |
| 4988 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 4989 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4990 | sb.append(countBg); |
| 4991 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4992 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 4993 | sb.append(" (currently running in background)"); |
| 4994 | } |
| 4995 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4996 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4997 | |
| 4998 | sb.append(prefix); |
| 4999 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5000 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5001 | sb.append(" ("); |
| 5002 | sb.append(resultCountBg); |
| 5003 | sb.append(" in background)"); |
| 5004 | |
| 5005 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 5006 | sb.append("\n"); |
| 5007 | sb.append(prefix); |
| 5008 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 5009 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 5010 | sb.append(" (max "); |
| 5011 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 5012 | sb.append(")"); |
| 5013 | if (unoptimizedScanTimer != null |
| 5014 | && unoptimizedScanTimer.isRunningLocked()) { |
| 5015 | sb.append(" (currently running unoptimized)"); |
| 5016 | } |
| 5017 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 5018 | sb.append("\n"); |
| 5019 | sb.append(prefix); |
| 5020 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 5021 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 5022 | sb.append(" (max "); |
| 5023 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 5024 | sb.append(")"); |
| 5025 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 5026 | sb.append(" (currently running unoptimized in background)"); |
| 5027 | } |
| 5028 | } |
| 5029 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5030 | pw.println(sb.toString()); |
| 5031 | uidActivity = true; |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5036 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5037 | if (u.hasUserActivity()) { |
| 5038 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 5039 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5040 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5041 | if (val != 0) { |
| 5042 | if (!hasData) { |
| 5043 | sb.setLength(0); |
| 5044 | sb.append(" User activity: "); |
| 5045 | hasData = true; |
| 5046 | } else { |
| 5047 | sb.append(", "); |
| 5048 | } |
| 5049 | sb.append(val); |
| 5050 | sb.append(" "); |
| 5051 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 5052 | } |
| 5053 | } |
| 5054 | if (hasData) { |
| 5055 | pw.println(sb.toString()); |
| 5056 | } |
| 5057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5059 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 5060 | = u.getWakelockStats(); |
| 5061 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5062 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5063 | int countWakelock = 0; |
| 5064 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 5065 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 5066 | String linePrefix = ": "; |
| 5067 | sb.setLength(0); |
| 5068 | sb.append(prefix); |
| 5069 | sb.append(" Wake lock "); |
| 5070 | sb.append(wakelocks.keyAt(iw)); |
| 5071 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 5072 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5073 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 5074 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5075 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 5076 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 5077 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5078 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 5079 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5080 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 5081 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5082 | sb.append(" realtime"); |
| 5083 | pw.println(sb.toString()); |
| 5084 | uidActivity = true; |
| 5085 | countWakelock++; |
| 5086 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5087 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 5088 | rawRealtime, which); |
| 5089 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 5090 | rawRealtime, which); |
| 5091 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 5092 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5093 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5094 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5095 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5096 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5097 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 5098 | // pooled and therefore just a lower bound) |
| 5099 | long actualTotalPartialWakelock = 0; |
| 5100 | long actualBgPartialWakelock = 0; |
| 5101 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 5102 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 5103 | // Convert from microseconds to milliseconds with rounding |
| 5104 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5105 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5106 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 5107 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5108 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 5112 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 5113 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5114 | sb.setLength(0); |
| 5115 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5116 | sb.append(" TOTAL wake: "); |
| 5117 | boolean needComma = false; |
| 5118 | if (totalFullWakelock != 0) { |
| 5119 | needComma = true; |
| 5120 | formatTimeMs(sb, totalFullWakelock); |
| 5121 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5122 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5123 | if (totalPartialWakelock != 0) { |
| 5124 | if (needComma) { |
| 5125 | sb.append(", "); |
| 5126 | } |
| 5127 | needComma = true; |
| 5128 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5129 | sb.append("blamed partial"); |
| 5130 | } |
| 5131 | if (actualTotalPartialWakelock != 0) { |
| 5132 | if (needComma) { |
| 5133 | sb.append(", "); |
| 5134 | } |
| 5135 | needComma = true; |
| 5136 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5137 | sb.append("actual partial"); |
| 5138 | } |
| 5139 | if (actualBgPartialWakelock != 0) { |
| 5140 | if (needComma) { |
| 5141 | sb.append(", "); |
| 5142 | } |
| 5143 | needComma = true; |
| 5144 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5145 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5146 | } |
| 5147 | if (totalWindowWakelock != 0) { |
| 5148 | if (needComma) { |
| 5149 | sb.append(", "); |
| 5150 | } |
| 5151 | needComma = true; |
| 5152 | formatTimeMs(sb, totalWindowWakelock); |
| 5153 | sb.append("window"); |
| 5154 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5155 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5156 | if (needComma) { |
| 5157 | sb.append(","); |
| 5158 | } |
| 5159 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5160 | formatTimeMs(sb, totalDrawWakelock); |
| 5161 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5162 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5163 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5164 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5165 | } |
| 5166 | } |
| 5167 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5168 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5169 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5170 | final Timer timer = syncs.valueAt(isy); |
| 5171 | // Convert from microseconds to milliseconds with rounding |
| 5172 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5173 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5174 | final Timer bgTimer = timer.getSubTimer(); |
| 5175 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5176 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5177 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5178 | sb.setLength(0); |
| 5179 | sb.append(prefix); |
| 5180 | sb.append(" Sync "); |
| 5181 | sb.append(syncs.keyAt(isy)); |
| 5182 | sb.append(": "); |
| 5183 | if (totalTime != 0) { |
| 5184 | formatTimeMs(sb, totalTime); |
| 5185 | sb.append("realtime ("); |
| 5186 | sb.append(count); |
| 5187 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5188 | if (bgTime > 0) { |
| 5189 | sb.append(", "); |
| 5190 | formatTimeMs(sb, bgTime); |
| 5191 | sb.append("background ("); |
| 5192 | sb.append(bgCount); |
| 5193 | sb.append(" times)"); |
| 5194 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5195 | } else { |
| 5196 | sb.append("(not used)"); |
| 5197 | } |
| 5198 | pw.println(sb.toString()); |
| 5199 | uidActivity = true; |
| 5200 | } |
| 5201 | |
| 5202 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5203 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5204 | final Timer timer = jobs.valueAt(ij); |
| 5205 | // Convert from microseconds to milliseconds with rounding |
| 5206 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5207 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5208 | final Timer bgTimer = timer.getSubTimer(); |
| 5209 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5210 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5211 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5212 | sb.setLength(0); |
| 5213 | sb.append(prefix); |
| 5214 | sb.append(" Job "); |
| 5215 | sb.append(jobs.keyAt(ij)); |
| 5216 | sb.append(": "); |
| 5217 | if (totalTime != 0) { |
| 5218 | formatTimeMs(sb, totalTime); |
| 5219 | sb.append("realtime ("); |
| 5220 | sb.append(count); |
| 5221 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5222 | if (bgTime > 0) { |
| 5223 | sb.append(", "); |
| 5224 | formatTimeMs(sb, bgTime); |
| 5225 | sb.append("background ("); |
| 5226 | sb.append(bgCount); |
| 5227 | sb.append(" times)"); |
| 5228 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5229 | } else { |
| 5230 | sb.append("(not used)"); |
| 5231 | } |
| 5232 | pw.println(sb.toString()); |
| 5233 | uidActivity = true; |
| 5234 | } |
| 5235 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5236 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5237 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5238 | SparseIntArray types = completions.valueAt(ic); |
| 5239 | if (types != null) { |
| 5240 | pw.print(prefix); |
| 5241 | pw.print(" Job Completions "); |
| 5242 | pw.print(completions.keyAt(ic)); |
| 5243 | pw.print(":"); |
| 5244 | for (int it=0; it<types.size(); it++) { |
| 5245 | pw.print(" "); |
| 5246 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5247 | pw.print("("); |
| 5248 | pw.print(types.valueAt(it)); |
| 5249 | pw.print("x)"); |
| 5250 | } |
| 5251 | pw.println(); |
| 5252 | } |
| 5253 | } |
| 5254 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5255 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5256 | prefix, "Flashlight"); |
| 5257 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5258 | prefix, "Camera"); |
| 5259 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5260 | prefix, "Video"); |
| 5261 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5262 | prefix, "Audio"); |
| 5263 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5264 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5265 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5266 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5267 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5268 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5269 | sb.setLength(0); |
| 5270 | sb.append(prefix); |
| 5271 | sb.append(" Sensor "); |
| 5272 | int handle = se.getHandle(); |
| 5273 | if (handle == Uid.Sensor.GPS) { |
| 5274 | sb.append("GPS"); |
| 5275 | } else { |
| 5276 | sb.append(handle); |
| 5277 | } |
| 5278 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5280 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5281 | if (timer != null) { |
| 5282 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5283 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5284 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5285 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5286 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5287 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5288 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5289 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5290 | final long bgActualTime = bgTimer != null ? |
| 5291 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5292 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5293 | //timer.logState(); |
| 5294 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5295 | if (actualTime != totalTime) { |
| 5296 | formatTimeMs(sb, totalTime); |
| 5297 | sb.append("blamed realtime, "); |
| 5298 | } |
| 5299 | |
| 5300 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5301 | sb.append("realtime ("); |
| 5302 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5303 | sb.append(" times)"); |
| 5304 | |
| 5305 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5306 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5307 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5308 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5309 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5310 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | } else { |
| 5313 | sb.append("(not used)"); |
| 5314 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5315 | } else { |
| 5316 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5317 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5318 | |
| 5319 | pw.println(sb.toString()); |
| 5320 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5321 | } |
| 5322 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5323 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5324 | "Vibrator"); |
| 5325 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5326 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5327 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5328 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5329 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5330 | long totalStateTime = 0; |
| 5331 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5332 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5333 | if (time > 0) { |
| 5334 | totalStateTime += time; |
| 5335 | sb.setLength(0); |
| 5336 | sb.append(prefix); |
| 5337 | sb.append(" "); |
| 5338 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5339 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5340 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5341 | pw.println(sb.toString()); |
| 5342 | uidActivity = true; |
| 5343 | } |
| 5344 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5345 | if (totalStateTime > 0) { |
| 5346 | sb.setLength(0); |
| 5347 | sb.append(prefix); |
| 5348 | sb.append(" Total running: "); |
| 5349 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5350 | pw.println(sb.toString()); |
| 5351 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5352 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5353 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5354 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5355 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5356 | sb.setLength(0); |
| 5357 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5358 | sb.append(" Total cpu time: u="); |
| 5359 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5360 | sb.append("s="); |
| 5361 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5362 | pw.println(sb.toString()); |
| 5363 | } |
| 5364 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5365 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5366 | if (cpuFreqTimes != null) { |
| 5367 | sb.setLength(0); |
| 5368 | sb.append(" Total cpu time per freq:"); |
| 5369 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5370 | sb.append(" " + cpuFreqTimes[i]); |
| 5371 | } |
| 5372 | pw.println(sb.toString()); |
| 5373 | } |
| 5374 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5375 | if (screenOffCpuFreqTimes != null) { |
| 5376 | sb.setLength(0); |
| 5377 | sb.append(" Total screen-off cpu time per freq:"); |
| 5378 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5379 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5380 | } |
| 5381 | pw.println(sb.toString()); |
| 5382 | } |
| 5383 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5384 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5385 | = u.getProcessStats(); |
| 5386 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5387 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5388 | long userTime; |
| 5389 | long systemTime; |
| 5390 | long foregroundTime; |
| 5391 | int starts; |
| 5392 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5394 | userTime = ps.getUserTime(which); |
| 5395 | systemTime = ps.getSystemTime(which); |
| 5396 | foregroundTime = ps.getForegroundTime(which); |
| 5397 | starts = ps.getStarts(which); |
| 5398 | final int numCrashes = ps.getNumCrashes(which); |
| 5399 | final int numAnrs = ps.getNumAnrs(which); |
| 5400 | numExcessive = which == STATS_SINCE_CHARGED |
| 5401 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5403 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5404 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5405 | sb.setLength(0); |
| 5406 | sb.append(prefix); sb.append(" Proc "); |
| 5407 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5408 | sb.append(prefix); sb.append(" CPU: "); |
| 5409 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5410 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5411 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5412 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5413 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5414 | boolean hasOne = false; |
| 5415 | if (starts != 0) { |
| 5416 | hasOne = true; |
| 5417 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5418 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5419 | if (numCrashes != 0) { |
| 5420 | if (hasOne) { |
| 5421 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5422 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5423 | hasOne = true; |
| 5424 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5425 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5426 | if (numAnrs != 0) { |
| 5427 | if (hasOne) { |
| 5428 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5429 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5430 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | } |
| 5432 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5433 | pw.println(sb.toString()); |
| 5434 | for (int e=0; e<numExcessive; e++) { |
| 5435 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5436 | if (ew != null) { |
| 5437 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5438 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5439 | pw.print("cpu"); |
| 5440 | } else { |
| 5441 | pw.print("unknown"); |
| 5442 | } |
| 5443 | pw.print(" use: "); |
| 5444 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5445 | pw.print(" over "); |
| 5446 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5447 | if (ew.overTime != 0) { |
| 5448 | pw.print(" ("); |
| 5449 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5450 | pw.println("%)"); |
| 5451 | } |
| 5452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5453 | } |
| 5454 | uidActivity = true; |
| 5455 | } |
| 5456 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5457 | |
| 5458 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5459 | = u.getPackageStats(); |
| 5460 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5461 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5462 | pw.println(":"); |
| 5463 | boolean apkActivity = false; |
| 5464 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5465 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5466 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5467 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5468 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5469 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5470 | pw.println(" times"); |
| 5471 | apkActivity = true; |
| 5472 | } |
| 5473 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5474 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5475 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5476 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5477 | final int starts = ss.getStarts(which); |
| 5478 | final int launches = ss.getLaunches(which); |
| 5479 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5480 | sb.setLength(0); |
| 5481 | sb.append(prefix); sb.append(" Service "); |
| 5482 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5483 | sb.append(prefix); sb.append(" Created for: "); |
| 5484 | formatTimeMs(sb, startTime / 1000); |
| 5485 | sb.append("uptime\n"); |
| 5486 | sb.append(prefix); sb.append(" Starts: "); |
| 5487 | sb.append(starts); |
| 5488 | sb.append(", launches: "); sb.append(launches); |
| 5489 | pw.println(sb.toString()); |
| 5490 | apkActivity = true; |
| 5491 | } |
| 5492 | } |
| 5493 | if (!apkActivity) { |
| 5494 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5495 | } |
| 5496 | uidActivity = true; |
| 5497 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5499 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5500 | } |
| 5501 | } |
| 5502 | } |
| 5503 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5504 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5505 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5506 | int diff = oldval ^ newval; |
| 5507 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5508 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5509 | for (int i=0; i<descriptions.length; i++) { |
| 5510 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5511 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5512 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5513 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5514 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5515 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5516 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5517 | didWake = true; |
| 5518 | pw.print("="); |
| 5519 | if (longNames) { |
| 5520 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5521 | pw.print(":\""); |
| 5522 | pw.print(wakelockTag.string); |
| 5523 | pw.print("\""); |
| 5524 | } else { |
| 5525 | pw.print(wakelockTag.poolIdx); |
| 5526 | } |
| 5527 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5528 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5529 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5530 | pw.print("="); |
| 5531 | int val = (newval&bd.mask)>>bd.shift; |
| 5532 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5533 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5534 | } else { |
| 5535 | pw.print(val); |
| 5536 | } |
| 5537 | } |
| 5538 | } |
| 5539 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5540 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5541 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5542 | if (longNames) { |
| 5543 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5544 | pw.print(":\""); |
| 5545 | pw.print(wakelockTag.string); |
| 5546 | pw.print("\""); |
| 5547 | } else { |
| 5548 | pw.print(wakelockTag.poolIdx); |
| 5549 | } |
| 5550 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5551 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5552 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5553 | public void prepareForDumpLocked() { |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 5554 | // We don't need to require subclasses implement this. |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | public static class HistoryPrinter { |
| 5558 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5559 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5560 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5561 | int oldStatus = -1; |
| 5562 | int oldHealth = -1; |
| 5563 | int oldPlug = -1; |
| 5564 | int oldTemp = -1; |
| 5565 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5566 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5567 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5568 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5569 | void reset() { |
| 5570 | oldState = oldState2 = 0; |
| 5571 | oldLevel = -1; |
| 5572 | oldStatus = -1; |
| 5573 | oldHealth = -1; |
| 5574 | oldPlug = -1; |
| 5575 | oldTemp = -1; |
| 5576 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5577 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5578 | } |
| 5579 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5580 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5581 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5582 | if (!checkin) { |
| 5583 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5584 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5585 | pw.print(" ("); |
| 5586 | pw.print(rec.numReadInts); |
| 5587 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5588 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5589 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5590 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5591 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5592 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5593 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5594 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5595 | } |
| 5596 | lastTime = rec.time; |
| 5597 | } |
| 5598 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5599 | if (checkin) { |
| 5600 | pw.print(":"); |
| 5601 | } |
| 5602 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5603 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5604 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5605 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5606 | if (checkin) { |
| 5607 | pw.print(":"); |
| 5608 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5609 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5610 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5611 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5612 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5613 | pw.print("TIME:"); |
| 5614 | if (checkin) { |
| 5615 | pw.println(rec.currentTime); |
| 5616 | } else { |
| 5617 | pw.print(" "); |
| 5618 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5619 | rec.currentTime).toString()); |
| 5620 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5621 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5622 | if (checkin) { |
| 5623 | pw.print(":"); |
| 5624 | } |
| 5625 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5626 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5627 | if (checkin) { |
| 5628 | pw.print(":"); |
| 5629 | } |
| 5630 | pw.println("*OVERFLOW*"); |
| 5631 | } else { |
| 5632 | if (!checkin) { |
| 5633 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5634 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5635 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5636 | if (verbose) { |
| 5637 | pw.print(" "); |
| 5638 | if (rec.states < 0) ; |
| 5639 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5640 | else if (rec.states < 0x100) pw.print("000000"); |
| 5641 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5642 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5643 | else if (rec.states < 0x100000) pw.print("000"); |
| 5644 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5645 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5646 | pw.print(Integer.toHexString(rec.states)); |
| 5647 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5648 | } else { |
| 5649 | if (oldLevel != rec.batteryLevel) { |
| 5650 | oldLevel = rec.batteryLevel; |
| 5651 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5652 | } |
| 5653 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5654 | if (oldStatus != rec.batteryStatus) { |
| 5655 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5656 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5657 | switch (oldStatus) { |
| 5658 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5659 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5660 | break; |
| 5661 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5662 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5663 | break; |
| 5664 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5665 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5666 | break; |
| 5667 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5668 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5669 | break; |
| 5670 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5671 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5672 | break; |
| 5673 | default: |
| 5674 | pw.print(oldStatus); |
| 5675 | break; |
| 5676 | } |
| 5677 | } |
| 5678 | if (oldHealth != rec.batteryHealth) { |
| 5679 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5680 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5681 | switch (oldHealth) { |
| 5682 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5683 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5684 | break; |
| 5685 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5686 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5687 | break; |
| 5688 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5689 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5690 | break; |
| 5691 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5692 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5693 | break; |
| 5694 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5695 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5696 | break; |
| 5697 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5698 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5699 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5700 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5701 | pw.print(checkin ? "c" : "cold"); |
| 5702 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5703 | default: |
| 5704 | pw.print(oldHealth); |
| 5705 | break; |
| 5706 | } |
| 5707 | } |
| 5708 | if (oldPlug != rec.batteryPlugType) { |
| 5709 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5710 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5711 | switch (oldPlug) { |
| 5712 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5713 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5714 | break; |
| 5715 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5716 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5717 | break; |
| 5718 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5719 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5720 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5721 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5722 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5723 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5724 | default: |
| 5725 | pw.print(oldPlug); |
| 5726 | break; |
| 5727 | } |
| 5728 | } |
| 5729 | if (oldTemp != rec.batteryTemperature) { |
| 5730 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5731 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5732 | pw.print(oldTemp); |
| 5733 | } |
| 5734 | if (oldVolt != rec.batteryVoltage) { |
| 5735 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5736 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5737 | pw.print(oldVolt); |
| 5738 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5739 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5740 | if (oldChargeMAh != chargeMAh) { |
| 5741 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5742 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5743 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5744 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5745 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5746 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5747 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5748 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5749 | if (rec.wakeReasonTag != null) { |
| 5750 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5751 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5752 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5753 | } else { |
| 5754 | pw.print(" wake_reason="); |
| 5755 | pw.print(rec.wakeReasonTag.uid); |
| 5756 | pw.print(":\""); |
| 5757 | pw.print(rec.wakeReasonTag.string); |
| 5758 | pw.print("\""); |
| 5759 | } |
| 5760 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5761 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5762 | pw.print(checkin ? "," : " "); |
| 5763 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5764 | pw.print("+"); |
| 5765 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5766 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5767 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5768 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5769 | : HISTORY_EVENT_NAMES; |
| 5770 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5771 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5772 | if (idx >= 0 && idx < eventNames.length) { |
| 5773 | pw.print(eventNames[idx]); |
| 5774 | } else { |
| 5775 | pw.print(checkin ? "Ev" : "event"); |
| 5776 | pw.print(idx); |
| 5777 | } |
| 5778 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5779 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5780 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5781 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5782 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5783 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5784 | pw.print(":\""); |
| 5785 | pw.print(rec.eventTag.string); |
| 5786 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5787 | } |
| 5788 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5789 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5790 | if (rec.stepDetails != null) { |
| 5791 | if (!checkin) { |
| 5792 | pw.print(" Details: cpu="); |
| 5793 | pw.print(rec.stepDetails.userTime); |
| 5794 | pw.print("u+"); |
| 5795 | pw.print(rec.stepDetails.systemTime); |
| 5796 | pw.print("s"); |
| 5797 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5798 | pw.print(" ("); |
| 5799 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5800 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5801 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5802 | pw.print(", "); |
| 5803 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5804 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5805 | } |
| 5806 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5807 | pw.print(", "); |
| 5808 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5809 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5810 | } |
| 5811 | pw.print(')'); |
| 5812 | } |
| 5813 | pw.println(); |
| 5814 | pw.print(" /proc/stat="); |
| 5815 | pw.print(rec.stepDetails.statUserTime); |
| 5816 | pw.print(" usr, "); |
| 5817 | pw.print(rec.stepDetails.statSystemTime); |
| 5818 | pw.print(" sys, "); |
| 5819 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5820 | pw.print(" io, "); |
| 5821 | pw.print(rec.stepDetails.statIrqTime); |
| 5822 | pw.print(" irq, "); |
| 5823 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5824 | pw.print(" sirq, "); |
| 5825 | pw.print(rec.stepDetails.statIdlTime); |
| 5826 | pw.print(" idle"); |
| 5827 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5828 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5829 | + rec.stepDetails.statSoftIrqTime; |
| 5830 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5831 | if (total > 0) { |
| 5832 | pw.print(" ("); |
| 5833 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5834 | pw.print(String.format("%.1f%%", perc)); |
| 5835 | pw.print(" of "); |
| 5836 | StringBuilder sb = new StringBuilder(64); |
| 5837 | formatTimeMsNoSpace(sb, total*10); |
| 5838 | pw.print(sb); |
| 5839 | pw.print(")"); |
| 5840 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5841 | pw.print(", PlatformIdleStat "); |
| 5842 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5843 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5844 | |
| 5845 | pw.print(", SubsystemPowerState "); |
| 5846 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5847 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5848 | } else { |
| 5849 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5850 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5851 | pw.print(rec.stepDetails.userTime); |
| 5852 | pw.print(":"); |
| 5853 | pw.print(rec.stepDetails.systemTime); |
| 5854 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5855 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5856 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5857 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5858 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5859 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5860 | } |
| 5861 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5862 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5863 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5864 | } |
| 5865 | } |
| 5866 | pw.println(); |
| 5867 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5868 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5869 | pw.print(rec.stepDetails.statUserTime); |
| 5870 | pw.print(','); |
| 5871 | pw.print(rec.stepDetails.statSystemTime); |
| 5872 | pw.print(','); |
| 5873 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5874 | pw.print(','); |
| 5875 | pw.print(rec.stepDetails.statIrqTime); |
| 5876 | pw.print(','); |
| 5877 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5878 | pw.print(','); |
| 5879 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5880 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5881 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5882 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 5883 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5884 | pw.print(','); |
| 5885 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5886 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5887 | |
| 5888 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5889 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5890 | } |
| 5891 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5892 | } |
| 5893 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5894 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5895 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5896 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5897 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5898 | |
| 5899 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5900 | UserHandle.formatUid(pw, uid); |
| 5901 | pw.print("="); |
| 5902 | pw.print(utime); |
| 5903 | pw.print("u+"); |
| 5904 | pw.print(stime); |
| 5905 | pw.print("s"); |
| 5906 | } |
| 5907 | |
| 5908 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5909 | pw.print('/'); |
| 5910 | pw.print(uid); |
| 5911 | pw.print(":"); |
| 5912 | pw.print(utime); |
| 5913 | pw.print(":"); |
| 5914 | pw.print(stime); |
| 5915 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5916 | } |
| 5917 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5918 | private void printSizeValue(PrintWriter pw, long size) { |
| 5919 | float result = size; |
| 5920 | String suffix = ""; |
| 5921 | if (result >= 10*1024) { |
| 5922 | suffix = "KB"; |
| 5923 | result = result / 1024; |
| 5924 | } |
| 5925 | if (result >= 10*1024) { |
| 5926 | suffix = "MB"; |
| 5927 | result = result / 1024; |
| 5928 | } |
| 5929 | if (result >= 10*1024) { |
| 5930 | suffix = "GB"; |
| 5931 | result = result / 1024; |
| 5932 | } |
| 5933 | if (result >= 10*1024) { |
| 5934 | suffix = "TB"; |
| 5935 | result = result / 1024; |
| 5936 | } |
| 5937 | if (result >= 10*1024) { |
| 5938 | suffix = "PB"; |
| 5939 | result = result / 1024; |
| 5940 | } |
| 5941 | pw.print((int)result); |
| 5942 | pw.print(suffix); |
| 5943 | } |
| 5944 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5945 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5946 | String label3, long estimatedTime) { |
| 5947 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5948 | return false; |
| 5949 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5950 | pw.print(label1); |
| 5951 | pw.print(label2); |
| 5952 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5953 | StringBuilder sb = new StringBuilder(64); |
| 5954 | formatTimeMs(sb, estimatedTime); |
| 5955 | pw.print(sb); |
| 5956 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5957 | return true; |
| 5958 | } |
| 5959 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5960 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5961 | LevelStepTracker steps, boolean checkin) { |
| 5962 | if (steps == null) { |
| 5963 | return false; |
| 5964 | } |
| 5965 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5966 | if (count <= 0) { |
| 5967 | return false; |
| 5968 | } |
| 5969 | if (!checkin) { |
| 5970 | pw.println(header); |
| 5971 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5972 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5973 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5974 | long duration = steps.getDurationAt(i); |
| 5975 | int level = steps.getLevelAt(i); |
| 5976 | long initMode = steps.getInitModeAt(i); |
| 5977 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5978 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5979 | lineArgs[0] = Long.toString(duration); |
| 5980 | lineArgs[1] = Integer.toString(level); |
| 5981 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5982 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5983 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5984 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5985 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5986 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5987 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5988 | } |
| 5989 | } else { |
| 5990 | lineArgs[2] = ""; |
| 5991 | } |
| 5992 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5993 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5994 | } else { |
| 5995 | lineArgs[3] = ""; |
| 5996 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5997 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5998 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5999 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6000 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6001 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6002 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 6003 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6004 | pw.print(prefix); |
| 6005 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6006 | TimeUtils.formatDuration(duration, pw); |
| 6007 | pw.print(" to "); pw.print(level); |
| 6008 | boolean haveModes = false; |
| 6009 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 6010 | pw.print(" ("); |
| 6011 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 6012 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 6013 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 6014 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 6015 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 6016 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6017 | } |
| 6018 | haveModes = true; |
| 6019 | } |
| 6020 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 6021 | pw.print(haveModes ? ", " : " ("); |
| 6022 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 6023 | ? "power-save-on" : "power-save-off"); |
| 6024 | haveModes = true; |
| 6025 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6026 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 6027 | pw.print(haveModes ? ", " : " ("); |
| 6028 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 6029 | ? "device-idle-on" : "device-idle-off"); |
| 6030 | haveModes = true; |
| 6031 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6032 | if (haveModes) { |
| 6033 | pw.print(")"); |
| 6034 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6035 | pw.println(); |
| 6036 | } |
| 6037 | } |
| 6038 | return true; |
| 6039 | } |
| 6040 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6041 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6042 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 6043 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 6044 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 6045 | public static final int DUMP_VERBOSE = 1<<5; |
| 6046 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6047 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6048 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 6049 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 6050 | final HistoryItem rec = new HistoryItem(); |
| 6051 | long lastTime = -1; |
| 6052 | long baseTime = -1; |
| 6053 | boolean printed = false; |
| 6054 | HistoryEventTracker tracker = null; |
| 6055 | while (getNextHistoryLocked(rec)) { |
| 6056 | lastTime = rec.time; |
| 6057 | if (baseTime < 0) { |
| 6058 | baseTime = lastTime; |
| 6059 | } |
| 6060 | if (rec.time >= histStart) { |
| 6061 | if (histStart >= 0 && !printed) { |
| 6062 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 6063 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 6064 | || rec.cmd == HistoryItem.CMD_START |
| 6065 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6066 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6067 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6068 | (flags&DUMP_VERBOSE) != 0); |
| 6069 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6070 | } else if (rec.currentTime != 0) { |
| 6071 | printed = true; |
| 6072 | byte cmd = rec.cmd; |
| 6073 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6074 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6075 | (flags&DUMP_VERBOSE) != 0); |
| 6076 | rec.cmd = cmd; |
| 6077 | } |
| 6078 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6079 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 6080 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6081 | (flags&DUMP_VERBOSE) != 0); |
| 6082 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 6083 | } |
| 6084 | int oldEventCode = rec.eventCode; |
| 6085 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6086 | rec.eventTag = new HistoryTag(); |
| 6087 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 6088 | HashMap<String, SparseIntArray> active |
| 6089 | = tracker.getStateForEvent(i); |
| 6090 | if (active == null) { |
| 6091 | continue; |
| 6092 | } |
| 6093 | for (HashMap.Entry<String, SparseIntArray> ent |
| 6094 | : active.entrySet()) { |
| 6095 | SparseIntArray uids = ent.getValue(); |
| 6096 | for (int j=0; j<uids.size(); j++) { |
| 6097 | rec.eventCode = i; |
| 6098 | rec.eventTag.string = ent.getKey(); |
| 6099 | rec.eventTag.uid = uids.keyAt(j); |
| 6100 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6101 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6102 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6103 | rec.wakeReasonTag = null; |
| 6104 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6105 | } |
| 6106 | } |
| 6107 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6108 | rec.eventCode = oldEventCode; |
| 6109 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6110 | tracker = null; |
| 6111 | } |
| 6112 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6113 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 6114 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 6115 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 6116 | // This is an attempt to aggregate the previous state and generate |
| 6117 | //Â fake events to reflect that state at the point where we start |
| 6118 | // 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] | 6119 | if (tracker == null) { |
| 6120 | tracker = new HistoryEventTracker(); |
| 6121 | } |
| 6122 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 6123 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 6124 | } |
| 6125 | } |
| 6126 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 6127 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6128 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 6129 | } |
| 6130 | } |
| 6131 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6132 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 6133 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6134 | if (steps == null) { |
| 6135 | return; |
| 6136 | } |
| 6137 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6138 | if (timeRemaining >= 0) { |
| 6139 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6140 | tmpSb.setLength(0); |
| 6141 | formatTimeMs(tmpSb, timeRemaining); |
| 6142 | pw.print(tmpSb); |
| 6143 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6144 | pw.println(" steps)"); |
| 6145 | } |
| 6146 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6147 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6148 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6149 | if (estimatedTime > 0) { |
| 6150 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6151 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6152 | pw.print(" time: "); |
| 6153 | tmpSb.setLength(0); |
| 6154 | formatTimeMs(tmpSb, estimatedTime); |
| 6155 | pw.print(tmpSb); |
| 6156 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6157 | pw.println(" steps)"); |
| 6158 | } |
| 6159 | } |
| 6160 | } |
| 6161 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6162 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6163 | ArrayList<PackageChange> changes) { |
| 6164 | if (changes == null) { |
| 6165 | return; |
| 6166 | } |
| 6167 | pw.print(prefix); pw.println("Package changes:"); |
| 6168 | for (int i=0; i<changes.size(); i++) { |
| 6169 | PackageChange pc = changes.get(i); |
| 6170 | if (pc.mUpdate) { |
| 6171 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6172 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6173 | } else { |
| 6174 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6175 | } |
| 6176 | } |
| 6177 | } |
| 6178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | /** |
| 6180 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6181 | * |
| 6182 | * @param pw a Printer to receive the dump output. |
| 6183 | */ |
| 6184 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6185 | 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] | 6186 | prepareForDumpLocked(); |
| 6187 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6188 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6189 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6190 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6191 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6192 | final long historyTotalSize = getHistoryTotalSize(); |
| 6193 | final long historyUsedSize = getHistoryUsedSize(); |
| 6194 | if (startIteratingHistoryLocked()) { |
| 6195 | try { |
| 6196 | pw.print("Battery History ("); |
| 6197 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6198 | pw.print("% used, "); |
| 6199 | printSizeValue(pw, historyUsedSize); |
| 6200 | pw.print(" used of "); |
| 6201 | printSizeValue(pw, historyTotalSize); |
| 6202 | pw.print(", "); |
| 6203 | pw.print(getHistoryStringPoolSize()); |
| 6204 | pw.print(" strings using "); |
| 6205 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6206 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6207 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6208 | pw.println(); |
| 6209 | } finally { |
| 6210 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6211 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | if (startIteratingOldHistoryLocked()) { |
| 6215 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6216 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6217 | pw.println("Old battery History:"); |
| 6218 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6219 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6220 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6221 | if (baseTime < 0) { |
| 6222 | baseTime = rec.time; |
| 6223 | } |
| 6224 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6225 | } |
| 6226 | pw.println(); |
| 6227 | } finally { |
| 6228 | finishIteratingOldHistoryLocked(); |
| 6229 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6230 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6231 | } |
| 6232 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6233 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6234 | return; |
| 6235 | } |
| 6236 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6237 | if (!filtering) { |
| 6238 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6239 | final int NU = uidStats.size(); |
| 6240 | boolean didPid = false; |
| 6241 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6242 | for (int i=0; i<NU; i++) { |
| 6243 | Uid uid = uidStats.valueAt(i); |
| 6244 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6245 | if (pids != null) { |
| 6246 | for (int j=0; j<pids.size(); j++) { |
| 6247 | Uid.Pid pid = pids.valueAt(j); |
| 6248 | if (!didPid) { |
| 6249 | pw.println("Per-PID Stats:"); |
| 6250 | didPid = true; |
| 6251 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6252 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6253 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6254 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6255 | pw.print(" wake time: "); |
| 6256 | TimeUtils.formatDuration(time, pw); |
| 6257 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6258 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6259 | } |
| 6260 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6261 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6262 | pw.println(); |
| 6263 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6264 | } |
| 6265 | |
| 6266 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6267 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6268 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6269 | long timeRemaining = computeBatteryTimeRemaining( |
| 6270 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6271 | if (timeRemaining >= 0) { |
| 6272 | pw.print(" Estimated discharge time remaining: "); |
| 6273 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6274 | pw.println(); |
| 6275 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6276 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6277 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6278 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6279 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6280 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6281 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6282 | pw.println(); |
| 6283 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6284 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6285 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6286 | long timeRemaining = computeChargeTimeRemaining( |
| 6287 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6288 | if (timeRemaining >= 0) { |
| 6289 | pw.print(" Estimated charge time remaining: "); |
| 6290 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6291 | pw.println(); |
| 6292 | } |
| 6293 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6294 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6295 | } |
| 6296 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 6297 | pw.println("Daily stats:"); |
| 6298 | pw.print(" Current start time: "); |
| 6299 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6300 | getCurrentDailyStartTime()).toString()); |
| 6301 | pw.print(" Next min deadline: "); |
| 6302 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6303 | getNextMinDailyDeadline()).toString()); |
| 6304 | pw.print(" Next max deadline: "); |
| 6305 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6306 | getNextMaxDailyDeadline()).toString()); |
| 6307 | StringBuilder sb = new StringBuilder(64); |
| 6308 | int[] outInt = new int[1]; |
| 6309 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6310 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6311 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6312 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6313 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6314 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6315 | dsteps, false)) { |
| 6316 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6317 | sb, outInt); |
| 6318 | } |
| 6319 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6320 | csteps, false)) { |
| 6321 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6322 | sb, outInt); |
| 6323 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6324 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6325 | } else { |
| 6326 | pw.println(" Current daily steps:"); |
| 6327 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6328 | sb, outInt); |
| 6329 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6330 | sb, outInt); |
| 6331 | } |
| 6332 | } |
| 6333 | DailyItem dit; |
| 6334 | int curIndex = 0; |
| 6335 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6336 | curIndex++; |
| 6337 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6338 | pw.println(); |
| 6339 | } |
| 6340 | pw.print(" Daily from "); |
| 6341 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6342 | pw.print(" to "); |
| 6343 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6344 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6345 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6346 | if (dumpDurationSteps(pw, " ", |
| 6347 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6348 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6349 | sb, outInt); |
| 6350 | } |
| 6351 | if (dumpDurationSteps(pw, " ", |
| 6352 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6353 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6354 | sb, outInt); |
| 6355 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6356 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6357 | } else { |
| 6358 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6359 | sb, outInt); |
| 6360 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6361 | sb, outInt); |
| 6362 | } |
| 6363 | } |
| 6364 | pw.println(); |
| 6365 | } |
| 6366 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6367 | pw.println("Statistics since last charge:"); |
| 6368 | pw.println(" System starts: " + getStartCount() |
| 6369 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6370 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6371 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6372 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6375 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 6376 | // This is called from BatteryStatsService. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6377 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6378 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6379 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6380 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6381 | |
| 6382 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6383 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6384 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6385 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6386 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6387 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 6388 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6389 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6390 | try { |
| 6391 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6392 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6393 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6394 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6395 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6396 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6397 | pw.print(",\""); |
| 6398 | String str = getHistoryTagPoolString(i); |
| 6399 | str = str.replace("\\", "\\\\"); |
| 6400 | str = str.replace("\"", "\\\""); |
| 6401 | pw.print(str); |
| 6402 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6403 | pw.println(); |
| 6404 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6405 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6406 | } finally { |
| 6407 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6408 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6409 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6410 | } |
| 6411 | |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 6412 | if ((flags & DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6413 | return; |
| 6414 | } |
| 6415 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6416 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6417 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6418 | for (int i=0; i<apps.size(); i++) { |
| 6419 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6420 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6421 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6422 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6423 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6424 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6425 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6426 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6427 | } |
| 6428 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6429 | final int NU = uidStats.size(); |
| 6430 | String[] lineArgs = new String[2]; |
| 6431 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6432 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6433 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6434 | if (pkgs != null && !pkgs.second.value) { |
| 6435 | pkgs.second.value = true; |
| 6436 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6437 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6438 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6439 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6440 | (Object[])lineArgs); |
| 6441 | } |
| 6442 | } |
| 6443 | } |
| 6444 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 6445 | if ((flags & DUMP_DAILY_ONLY) == 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6446 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6447 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6448 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6449 | if (timeRemaining >= 0) { |
| 6450 | lineArgs[0] = Long.toString(timeRemaining); |
| 6451 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6452 | (Object[])lineArgs); |
| 6453 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6454 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6455 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6456 | if (timeRemaining >= 0) { |
| 6457 | lineArgs[0] = Long.toString(timeRemaining); |
| 6458 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6459 | (Object[])lineArgs); |
| 6460 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6461 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6462 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6463 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | } |
Kweku Adams | 2f73ecd | 2017-09-27 16:59:19 -0700 | [diff] [blame^] | 6465 | |
| 6466 | /** Dump batterystats data to a proto. @hide */ |
| 6467 | public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps, |
| 6468 | int flags, long historyStart) { |
| 6469 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 6470 | final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS); |
| 6471 | prepareForDumpLocked(); |
| 6472 | |
| 6473 | proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION); |
| 6474 | proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion()); |
| 6475 | proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion()); |
| 6476 | proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion()); |
| 6477 | |
| 6478 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6479 | |
| 6480 | if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) { |
| 6481 | if (startIteratingHistoryLocked()) { |
| 6482 | // TODO: implement dumpProtoHistoryLocked(proto); |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) { |
| 6487 | // TODO: implement dumpProtoAppsLocked(proto, apps); |
| 6488 | // TODO: implement dumpProtoSystemLocked(proto); |
| 6489 | } |
| 6490 | |
| 6491 | proto.end(bToken); |
| 6492 | proto.flush(); |
| 6493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | } |