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 | |
| 19 | import java.io.PrintWriter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 21 | import java.util.Collections; |
| 22 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import java.util.Formatter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 24 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import java.util.Map; |
| 26 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 29 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame^] | 30 | import android.text.format.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.Printer; |
| 32 | import android.util.SparseArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 33 | import android.util.TimeUtils; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 34 | import com.android.internal.os.BatterySipper; |
| 35 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * A class providing access to battery usage statistics, including information on |
| 39 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 40 | * except where indicated otherwise. |
| 41 | * @hide |
| 42 | */ |
| 43 | public abstract class BatteryStats implements Parcelable { |
| 44 | |
| 45 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 46 | |
| 47 | /** @hide */ |
| 48 | public static final String SERVICE_NAME = "batterystats"; |
| 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | /** |
| 51 | * A constant indicating a partial wake lock timer. |
| 52 | */ |
| 53 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 54 | |
| 55 | /** |
| 56 | * A constant indicating a full wake lock timer. |
| 57 | */ |
| 58 | public static final int WAKE_TYPE_FULL = 1; |
| 59 | |
| 60 | /** |
| 61 | * A constant indicating a window wake lock timer. |
| 62 | */ |
| 63 | public static final int WAKE_TYPE_WINDOW = 2; |
| 64 | |
| 65 | /** |
| 66 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | */ |
| 68 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 71 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 72 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 73 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 76 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 77 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 78 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 81 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 82 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 83 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 85 | /** |
| 86 | * A constant indicating a wifi multicast timer |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 87 | */ |
| 88 | public static final int WIFI_MULTICAST_ENABLED = 7; |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 91 | * A constant indicating an audio turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 92 | */ |
| 93 | public static final int AUDIO_TURNED_ON = 7; |
| 94 | |
| 95 | /** |
| 96 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 97 | */ |
| 98 | public static final int VIDEO_TURNED_ON = 8; |
| 99 | |
| 100 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 101 | * A constant indicating a vibrator on timer |
| 102 | */ |
| 103 | public static final int VIBRATOR_ON = 9; |
| 104 | |
| 105 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 106 | * A constant indicating a foreground activity timer |
| 107 | */ |
| 108 | public static final int FOREGROUND_ACTIVITY = 10; |
| 109 | |
| 110 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 111 | * A constant indicating a wifi batched scan is active |
| 112 | */ |
| 113 | public static final int WIFI_BATCHED_SCAN = 11; |
| 114 | |
| 115 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * Include all of the data in the stats, including previously saved data. |
| 117 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 118 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Include only the last run in the stats. |
| 122 | */ |
| 123 | public static final int STATS_LAST = 1; |
| 124 | |
| 125 | /** |
| 126 | * Include only the current run in the stats. |
| 127 | */ |
| 128 | public static final int STATS_CURRENT = 2; |
| 129 | |
| 130 | /** |
| 131 | * Include only the run since the last time the device was unplugged in the stats. |
| 132 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 133 | public static final int STATS_SINCE_UNPLUGGED = 3; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 134 | |
| 135 | // NOTE: Update this list if you add/change any stats above. |
| 136 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 137 | // and "unplugged". They were shortened for efficiency sake. |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 138 | private static final String[] STAT_NAMES = { "t", "l", "c", "u" }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Bump the version on this if the checkin format changes. |
| 142 | */ |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 143 | private static final int BATTERY_STATS_CHECKIN_VERSION = 7; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 144 | |
| 145 | private static final long BYTES_PER_KB = 1024; |
| 146 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 147 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 150 | private static final String UID_DATA = "uid"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 152 | private static final String PROCESS_DATA = "pr"; |
| 153 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 154 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 155 | private static final String FOREGROUND_DATA = "fg"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 156 | private static final String WAKELOCK_DATA = "wl"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 157 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 158 | private static final String NETWORK_DATA = "nt"; |
| 159 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 160 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 161 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 162 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 163 | private static final String WIFI_DATA = "wfl"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 164 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 165 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 166 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 167 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 168 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 169 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 170 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 171 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 172 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 173 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 174 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 175 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 177 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 179 | |
| 180 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 181 | * State for keeping track of counting information. |
| 182 | */ |
| 183 | public static abstract class Counter { |
| 184 | |
| 185 | /** |
| 186 | * Returns the count associated with this Counter for the |
| 187 | * selected type of statistics. |
| 188 | * |
| 189 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 190 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 191 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * Temporary for debugging. |
| 195 | */ |
| 196 | public abstract void logState(Printer pw, String prefix); |
| 197 | } |
| 198 | |
| 199 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * State for keeping track of timing information. |
| 201 | */ |
| 202 | public static abstract class Timer { |
| 203 | |
| 204 | /** |
| 205 | * Returns the count associated with this Timer for the |
| 206 | * selected type of statistics. |
| 207 | * |
| 208 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 209 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 210 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * Returns the total time in microseconds associated with this Timer for the |
| 214 | * selected type of statistics. |
| 215 | * |
| 216 | * @param batteryRealtime system realtime on battery in microseconds |
| 217 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 218 | * @return a time in microseconds |
| 219 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 220 | public abstract long getTotalTimeLocked(long batteryRealtime, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | /** |
| 223 | * Temporary for debugging. |
| 224 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 225 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
| 229 | * The statistics associated with a particular uid. |
| 230 | */ |
| 231 | public static abstract class Uid { |
| 232 | |
| 233 | /** |
| 234 | * Returns a mapping containing wakelock statistics. |
| 235 | * |
| 236 | * @return a Map from Strings to Uid.Wakelock objects. |
| 237 | */ |
| 238 | public abstract Map<String, ? extends Wakelock> getWakelockStats(); |
| 239 | |
| 240 | /** |
| 241 | * The statistics associated with a particular wake lock. |
| 242 | */ |
| 243 | public static abstract class Wakelock { |
| 244 | public abstract Timer getWakeTime(int type); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Returns a mapping containing sensor statistics. |
| 249 | * |
| 250 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 251 | */ |
| 252 | public abstract Map<Integer, ? extends Sensor> getSensorStats(); |
| 253 | |
| 254 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 255 | * Returns a mapping containing active process data. |
| 256 | */ |
| 257 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 258 | |
| 259 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | * Returns a mapping containing process statistics. |
| 261 | * |
| 262 | * @return a Map from Strings to Uid.Proc objects. |
| 263 | */ |
| 264 | public abstract Map<String, ? extends Proc> getProcessStats(); |
| 265 | |
| 266 | /** |
| 267 | * Returns a mapping containing package statistics. |
| 268 | * |
| 269 | * @return a Map from Strings to Uid.Pkg objects. |
| 270 | */ |
| 271 | public abstract Map<String, ? extends Pkg> getPackageStats(); |
| 272 | |
| 273 | /** |
| 274 | * {@hide} |
| 275 | */ |
| 276 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 277 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 278 | public abstract void noteWifiRunningLocked(); |
| 279 | public abstract void noteWifiStoppedLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 280 | public abstract void noteFullWifiLockAcquiredLocked(); |
| 281 | public abstract void noteFullWifiLockReleasedLocked(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 282 | public abstract void noteWifiScanStartedLocked(); |
| 283 | public abstract void noteWifiScanStoppedLocked(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 284 | public abstract void noteWifiBatchedScanStartedLocked(int csph); |
| 285 | public abstract void noteWifiBatchedScanStoppedLocked(); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 286 | public abstract void noteWifiMulticastEnabledLocked(); |
| 287 | public abstract void noteWifiMulticastDisabledLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 288 | public abstract void noteAudioTurnedOnLocked(); |
| 289 | public abstract void noteAudioTurnedOffLocked(); |
| 290 | public abstract void noteVideoTurnedOnLocked(); |
| 291 | public abstract void noteVideoTurnedOffLocked(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 292 | public abstract void noteActivityResumedLocked(); |
| 293 | public abstract void noteActivityPausedLocked(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 294 | public abstract long getWifiRunningTime(long batteryRealtime, int which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 295 | public abstract long getFullWifiLockTime(long batteryRealtime, int which); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 296 | public abstract long getWifiScanTime(long batteryRealtime, int which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 297 | public abstract long getWifiBatchedScanTime(int csphBin, long batteryRealtime, int which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 298 | public abstract long getWifiMulticastTime(long batteryRealtime, |
| 299 | int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 300 | public abstract long getAudioTurnedOnTime(long batteryRealtime, int which); |
| 301 | public abstract long getVideoTurnedOnTime(long batteryRealtime, int which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 302 | public abstract Timer getForegroundActivityTimer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 303 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 305 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 306 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 307 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 308 | * Note that these must match the constants in android.os.PowerManager. |
| 309 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 310 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 311 | */ |
| 312 | static final String[] USER_ACTIVITY_TYPES = { |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 313 | "other", "button", "touch" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 316 | public static final int NUM_USER_ACTIVITY_TYPES = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 317 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 318 | public abstract void noteUserActivityLocked(int type); |
| 319 | public abstract boolean hasUserActivity(); |
| 320 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 321 | |
| 322 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 323 | public abstract long getNetworkActivityBytes(int type, int which); |
| 324 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 327 | /* |
| 328 | * FIXME: it's not correct to use this magic value because it |
| 329 | * could clash with a sensor handle (which are defined by |
| 330 | * the sensor HAL, and therefore out of our control |
| 331 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | // Magic sensor number for the GPS. |
| 333 | public static final int GPS = -10000; |
| 334 | |
| 335 | public abstract int getHandle(); |
| 336 | |
| 337 | public abstract Timer getSensorTime(); |
| 338 | } |
| 339 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 340 | public class Pid { |
| 341 | public long mWakeSum; |
| 342 | public long mWakeStart; |
| 343 | } |
| 344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | /** |
| 346 | * The statistics associated with a particular process. |
| 347 | */ |
| 348 | public static abstract class Proc { |
| 349 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 350 | public static class ExcessivePower { |
| 351 | public static final int TYPE_WAKE = 1; |
| 352 | public static final int TYPE_CPU = 2; |
| 353 | |
| 354 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 355 | public long overTime; |
| 356 | public long usedTime; |
| 357 | } |
| 358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 360 | * Returns true if this process is still active in the battery stats. |
| 361 | */ |
| 362 | public abstract boolean isActive(); |
| 363 | |
| 364 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | * Returns the total time (in 1/100 sec) spent executing in user code. |
| 366 | * |
| 367 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 368 | */ |
| 369 | public abstract long getUserTime(int which); |
| 370 | |
| 371 | /** |
| 372 | * Returns the total time (in 1/100 sec) spent executing in system code. |
| 373 | * |
| 374 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 375 | */ |
| 376 | public abstract long getSystemTime(int which); |
| 377 | |
| 378 | /** |
| 379 | * Returns the number of times the process has been started. |
| 380 | * |
| 381 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 382 | */ |
| 383 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 384 | |
| 385 | /** |
| 386 | * Returns the cpu time spent in microseconds while the process was in the foreground. |
| 387 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 388 | * @return foreground cpu time in microseconds |
| 389 | */ |
| 390 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 391 | |
| 392 | /** |
| 393 | * Returns the approximate cpu time spent in microseconds, at a certain CPU speed. |
| 394 | * @param speedStep the index of the CPU speed. This is not the actual speed of the |
| 395 | * CPU. |
| 396 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 397 | * @see BatteryStats#getCpuSpeedSteps() |
| 398 | */ |
| 399 | public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 400 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 401 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 402 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 403 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /** |
| 407 | * The statistics associated with a particular package. |
| 408 | */ |
| 409 | public static abstract class Pkg { |
| 410 | |
| 411 | /** |
| 412 | * Returns the number of times this package has done something that could wake up the |
| 413 | * device from sleep. |
| 414 | * |
| 415 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 416 | */ |
| 417 | public abstract int getWakeups(int which); |
| 418 | |
| 419 | /** |
| 420 | * Returns a mapping containing service statistics. |
| 421 | */ |
| 422 | public abstract Map<String, ? extends Serv> getServiceStats(); |
| 423 | |
| 424 | /** |
| 425 | * The statistics associated with a particular service. |
| 426 | */ |
| 427 | public abstract class Serv { |
| 428 | |
| 429 | /** |
| 430 | * Returns the amount of time spent started. |
| 431 | * |
| 432 | * @param batteryUptime elapsed uptime on battery in microseconds. |
| 433 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 434 | * @return |
| 435 | */ |
| 436 | public abstract long getStartTime(long batteryUptime, int which); |
| 437 | |
| 438 | /** |
| 439 | * Returns the total number of times startService() has been called. |
| 440 | * |
| 441 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 442 | */ |
| 443 | public abstract int getStarts(int which); |
| 444 | |
| 445 | /** |
| 446 | * Returns the total number times the service has been launched. |
| 447 | * |
| 448 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 449 | */ |
| 450 | public abstract int getLaunches(int which); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 455 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 456 | public HistoryItem next; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 457 | |
| 458 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 459 | |
| 460 | // The command codes 0-3 can be written with delta updates; all others require |
| 461 | // that a full entry be written. |
| 462 | public static final byte CMD_UPDATE = 0; |
| 463 | public static final byte CMD_EVENT = 1; |
| 464 | public static final byte CMD_NULL = -1; |
| 465 | public static final byte CMD_START = 4; |
| 466 | public static final byte CMD_OVERFLOW = 5; |
| 467 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 468 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 469 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 470 | /** |
| 471 | * Return whether the command code is a delta data update. |
| 472 | */ |
| 473 | public static boolean isDeltaData(byte cmd) { |
| 474 | return cmd >= 0 && cmd <= 3; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Return whether the command code is a delta data update. |
| 479 | */ |
| 480 | public boolean isDeltaData() { |
| 481 | return cmd >= 0 && cmd <= 3; |
| 482 | } |
| 483 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 484 | public byte batteryLevel; |
| 485 | public byte batteryStatus; |
| 486 | public byte batteryHealth; |
| 487 | public byte batteryPlugType; |
| 488 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 489 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 490 | public char batteryVoltage; |
| 491 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 492 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 493 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 494 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 495 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 496 | public static final int STATE_SIGNAL_STRENGTH_SHIFT = 3; |
| 497 | public static final int STATE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_SIGNAL_STRENGTH_SHIFT; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 498 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 499 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 500 | 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] | 501 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 502 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
| 503 | public static final int STATE_DATA_CONNECTION_MASK = 0x1f; |
| 504 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 505 | // These states always appear directly in the first int token |
| 506 | // of a delta change; they should be ones that change relatively |
| 507 | // frequently. |
| 508 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
| 509 | public static final int STATE_SENSOR_ON_FLAG = 1<<29; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 510 | public static final int STATE_GPS_ON_FLAG = 1<<28; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 511 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<27; |
| 512 | public static final int STATE_WIFI_RUNNING_FLAG = 1<<26; |
| 513 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 514 | public static final int STATE_WIFI_SCAN_FLAG = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 515 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23; |
| 516 | // These are on the lower bits used for the command; if they change |
| 517 | // we need to write another int of data. |
| 518 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
| 519 | public static final int STATE_VIDEO_ON_FLAG = 1<<21; |
| 520 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; |
| 521 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; |
| 522 | public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18; |
| 523 | public static final int STATE_WIFI_ON_FLAG = 1<<17; |
| 524 | public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 525 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 526 | public static final int MOST_INTERESTING_STATES = |
| 527 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG |
| 528 | | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG; |
| 529 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 530 | public int states; |
| 531 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 532 | public static final int EVENT_NONE = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 533 | public static final int EVENT_PROC_STARTED = 1; |
| 534 | public static final int EVENT_PROC_FINISHED = 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 535 | |
| 536 | // For CMD_EVENT. |
| 537 | public int eventCode; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 538 | public String eventName; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 539 | public int eventNameIdx; // only filled in when iterating. |
| 540 | public int eventUid; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 541 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 542 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 545 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 546 | this.time = time; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 547 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | public int describeContents() { |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | public void writeToParcel(Parcel dest, int flags) { |
| 555 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 556 | int bat = (((int)cmd)&0xff) |
| 557 | | ((((int)batteryLevel)<<8)&0xff00) |
| 558 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 559 | | ((((int)batteryHealth)<<20)&0xf00000) |
| 560 | | ((((int)batteryPlugType)<<24)&0xf000000); |
| 561 | dest.writeInt(bat); |
| 562 | bat = (((int)batteryTemperature)&0xffff) |
| 563 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 564 | dest.writeInt(bat); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 565 | dest.writeInt(states); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 566 | if (cmd == CMD_EVENT) { |
| 567 | dest.writeInt(eventCode); |
| 568 | dest.writeInt(eventUid); |
| 569 | dest.writeString(eventName); |
| 570 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 571 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 572 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 573 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 574 | int bat = src.readInt(); |
| 575 | cmd = (byte)(bat&0xff); |
| 576 | batteryLevel = (byte)((bat>>8)&0xff); |
| 577 | batteryStatus = (byte)((bat>>16)&0xf); |
| 578 | batteryHealth = (byte)((bat>>20)&0xf); |
| 579 | batteryPlugType = (byte)((bat>>24)&0xf); |
| 580 | bat = src.readInt(); |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 581 | batteryTemperature = (short)(bat&0xffff); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 582 | batteryVoltage = (char)((bat>>16)&0xffff); |
| 583 | states = src.readInt(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 584 | if (cmd == CMD_EVENT) { |
| 585 | eventCode = src.readInt(); |
| 586 | eventUid = src.readInt(); |
| 587 | eventName = src.readString(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 588 | eventNameIdx = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 589 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 590 | eventCode = EVENT_NONE; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 591 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 594 | public void clear() { |
| 595 | time = 0; |
| 596 | cmd = CMD_NULL; |
| 597 | batteryLevel = 0; |
| 598 | batteryStatus = 0; |
| 599 | batteryHealth = 0; |
| 600 | batteryPlugType = 0; |
| 601 | batteryTemperature = 0; |
| 602 | batteryVoltage = 0; |
| 603 | states = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 604 | eventCode = EVENT_NONE; |
| 605 | eventUid = 0; |
| 606 | eventName = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 609 | public void setTo(HistoryItem o) { |
| 610 | time = o.time; |
| 611 | cmd = o.cmd; |
| 612 | batteryLevel = o.batteryLevel; |
| 613 | batteryStatus = o.batteryStatus; |
| 614 | batteryHealth = o.batteryHealth; |
| 615 | batteryPlugType = o.batteryPlugType; |
| 616 | batteryTemperature = o.batteryTemperature; |
| 617 | batteryVoltage = o.batteryVoltage; |
| 618 | states = o.states; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 619 | eventCode = o.eventCode; |
| 620 | eventUid = o.eventUid; |
| 621 | eventName = o.eventName; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 622 | eventNameIdx = o.eventNameIdx; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 625 | public void setTo(long time, byte cmd, int eventCode, int eventUid, String eventName, |
| 626 | HistoryItem o) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 627 | this.time = time; |
| 628 | this.cmd = cmd; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 629 | this.eventCode = eventCode; |
| 630 | this.eventUid = eventUid; |
| 631 | this.eventName = eventName; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 632 | this.eventNameIdx = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 633 | batteryLevel = o.batteryLevel; |
| 634 | batteryStatus = o.batteryStatus; |
| 635 | batteryHealth = o.batteryHealth; |
| 636 | batteryPlugType = o.batteryPlugType; |
| 637 | batteryTemperature = o.batteryTemperature; |
| 638 | batteryVoltage = o.batteryVoltage; |
| 639 | states = o.states; |
| 640 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 641 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 642 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 643 | return batteryLevel == o.batteryLevel |
| 644 | && batteryStatus == o.batteryStatus |
| 645 | && batteryHealth == o.batteryHealth |
| 646 | && batteryPlugType == o.batteryPlugType |
| 647 | && batteryTemperature == o.batteryTemperature |
| 648 | && batteryVoltage == o.batteryVoltage |
| 649 | && states == o.states; |
| 650 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 651 | |
| 652 | public boolean same(HistoryItem o) { |
| 653 | if (!sameNonEvent(o) || eventCode != o.eventCode || eventUid != o.eventUid) { |
| 654 | return false; |
| 655 | } |
| 656 | if (eventName == o.eventName) { |
| 657 | return true; |
| 658 | } |
| 659 | return eventName != null && o.eventName != null && eventName.equals(o.eventName); |
| 660 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | public static final class BitDescription { |
| 664 | public final int mask; |
| 665 | public final int shift; |
| 666 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 667 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 668 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 669 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 670 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 671 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 672 | this.mask = mask; |
| 673 | this.shift = -1; |
| 674 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 675 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 676 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 677 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 680 | public BitDescription(int mask, int shift, String name, String shortName, |
| 681 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 682 | this.mask = mask; |
| 683 | this.shift = shift; |
| 684 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 685 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 686 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 687 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 688 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 691 | public abstract boolean startIteratingHistoryLocked(); |
| 692 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 693 | public abstract int getHistoryStringPoolSize(); |
| 694 | |
| 695 | public abstract String getHistoryStringPoolItem(int index); |
| 696 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 697 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 698 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 699 | public abstract void finishIteratingHistoryLocked(); |
| 700 | |
| 701 | public abstract boolean startIteratingOldHistoryLocked(); |
| 702 | |
| 703 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 704 | |
| 705 | public abstract void finishIteratingOldHistoryLocked(); |
| 706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 708 | * Return the base time offset for the battery history. |
| 709 | */ |
| 710 | public abstract long getHistoryBaseTime(); |
| 711 | |
| 712 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | * Returns the number of times the device has been started. |
| 714 | */ |
| 715 | public abstract int getStartCount(); |
| 716 | |
| 717 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 718 | * 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] | 719 | * running on battery. |
| 720 | * |
| 721 | * {@hide} |
| 722 | */ |
| 723 | public abstract long getScreenOnTime(long batteryRealtime, int which); |
| 724 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 725 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 726 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 727 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 728 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 729 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 730 | |
| 731 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 732 | "dark", "dim", "medium", "light", "bright" |
| 733 | }; |
| 734 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 735 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 736 | "0", "1", "2", "3", "4" |
| 737 | }; |
| 738 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 739 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
| 740 | |
| 741 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 742 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 743 | * the given brightness |
| 744 | * |
| 745 | * {@hide} |
| 746 | */ |
| 747 | public abstract long getScreenBrightnessTime(int brightnessBin, |
| 748 | long batteryRealtime, int which); |
| 749 | |
| 750 | public abstract int getInputEventCount(int which); |
| 751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 753 | * 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] | 754 | * running on battery. |
| 755 | * |
| 756 | * {@hide} |
| 757 | */ |
| 758 | public abstract long getPhoneOnTime(long batteryRealtime, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 759 | |
| 760 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 761 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 762 | * the given signal strength. |
| 763 | * |
| 764 | * {@hide} |
| 765 | */ |
| 766 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
| 767 | long batteryRealtime, int which); |
| 768 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 769 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 770 | * Returns the time in microseconds that the phone has been trying to |
| 771 | * acquire a signal. |
| 772 | * |
| 773 | * {@hide} |
| 774 | */ |
| 775 | public abstract long getPhoneSignalScanningTime( |
| 776 | long batteryRealtime, int which); |
| 777 | |
| 778 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 779 | * Returns the number of times the phone has entered the given signal strength. |
| 780 | * |
| 781 | * {@hide} |
| 782 | */ |
| 783 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 784 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 785 | public static final int DATA_CONNECTION_NONE = 0; |
| 786 | public static final int DATA_CONNECTION_GPRS = 1; |
| 787 | public static final int DATA_CONNECTION_EDGE = 2; |
| 788 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 789 | public static final int DATA_CONNECTION_CDMA = 4; |
| 790 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 791 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 792 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 793 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 794 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 795 | public static final int DATA_CONNECTION_HSPA = 10; |
| 796 | public static final int DATA_CONNECTION_IDEN = 11; |
| 797 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 798 | public static final int DATA_CONNECTION_LTE = 13; |
| 799 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 800 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 801 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 802 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 803 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 804 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 805 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 806 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 807 | }; |
| 808 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 809 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 810 | |
| 811 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 812 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 813 | * the given data connection. |
| 814 | * |
| 815 | * {@hide} |
| 816 | */ |
| 817 | public abstract long getPhoneDataConnectionTime(int dataType, |
| 818 | long batteryRealtime, int which); |
| 819 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 821 | * Returns the number of times the phone has entered the given data |
| 822 | * connection type. |
| 823 | * |
| 824 | * {@hide} |
| 825 | */ |
| 826 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 827 | |
| 828 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 829 | = new BitDescription[] { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 830 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
| 831 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 832 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
| 833 | new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 834 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
| 835 | new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"), |
| 836 | new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), |
| 837 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 838 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 839 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
| 840 | new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
| 841 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
| 842 | new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video", "v"), |
| 843 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 844 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 845 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 846 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 847 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 848 | new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 849 | HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", "Pss", |
| 850 | SignalStrength.SIGNAL_STRENGTH_NAMES, new String[] { |
| 851 | "0", "1", "2", "3", "4" |
| 852 | }), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 853 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 854 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 855 | new String[] {"in", "out", "emergency", "off"}, |
| 856 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 857 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 858 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 859 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 860 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 861 | |
| 862 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 863 | * 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] | 864 | * running on battery. |
| 865 | * |
| 866 | * {@hide} |
| 867 | */ |
| 868 | public abstract long getWifiOnTime(long batteryRealtime, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 869 | |
| 870 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 871 | * 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] | 872 | * been in the running state while the device was running on battery. |
| 873 | * |
| 874 | * {@hide} |
| 875 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 876 | public abstract long getGlobalWifiRunningTime(long batteryRealtime, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 877 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 878 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 879 | * Returns the time in microseconds that bluetooth has been on while the device was |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 880 | * running on battery. |
| 881 | * |
| 882 | * {@hide} |
| 883 | */ |
| 884 | public abstract long getBluetoothOnTime(long batteryRealtime, int which); |
| 885 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 886 | public abstract int getBluetoothPingCount(); |
| 887 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 888 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 889 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 890 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 891 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 892 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 893 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 894 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 895 | public abstract long getNetworkActivityBytes(int type, int which); |
| 896 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 897 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 898 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame^] | 899 | * Return the wall clock time when battery stats data collection started. |
| 900 | */ |
| 901 | public abstract long getStartClockTime(); |
| 902 | |
| 903 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | * Return whether we are currently running on battery. |
| 905 | */ |
| 906 | public abstract boolean getIsOnBattery(); |
| 907 | |
| 908 | /** |
| 909 | * Returns a SparseArray containing the statistics for each uid. |
| 910 | */ |
| 911 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 912 | |
| 913 | /** |
| 914 | * Returns the current battery uptime in microseconds. |
| 915 | * |
| 916 | * @param curTime the amount of elapsed realtime in microseconds. |
| 917 | */ |
| 918 | public abstract long getBatteryUptime(long curTime); |
| 919 | |
| 920 | /** |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 921 | * @deprecated use getRadioDataUptime |
| 922 | */ |
| 923 | public long getRadioDataUptimeMs() { |
| 924 | return getRadioDataUptime() / 1000; |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * Returns the time that the radio was on for data transfers. |
| 929 | * @return the uptime in microseconds while unplugged |
| 930 | */ |
| 931 | public abstract long getRadioDataUptime(); |
| 932 | |
| 933 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | * Returns the current battery realtime in microseconds. |
| 935 | * |
| 936 | * @param curTime the amount of elapsed realtime in microseconds. |
| 937 | */ |
| 938 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 939 | |
| 940 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 941 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 942 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 943 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 944 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 945 | |
| 946 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 947 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 948 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 949 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 950 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | |
| 952 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 953 | * Get the amount the battery has discharged since the stats were |
| 954 | * last reset after charging, as a lower-end approximation. |
| 955 | */ |
| 956 | public abstract int getLowDischargeAmountSinceCharge(); |
| 957 | |
| 958 | /** |
| 959 | * Get the amount the battery has discharged since the stats were |
| 960 | * last reset after charging, as an upper-end approximation. |
| 961 | */ |
| 962 | public abstract int getHighDischargeAmountSinceCharge(); |
| 963 | |
| 964 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 965 | * Get the amount the battery has discharged while the screen was on, |
| 966 | * since the last time power was unplugged. |
| 967 | */ |
| 968 | public abstract int getDischargeAmountScreenOn(); |
| 969 | |
| 970 | /** |
| 971 | * Get the amount the battery has discharged while the screen was on, |
| 972 | * since the last time the device was charged. |
| 973 | */ |
| 974 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 975 | |
| 976 | /** |
| 977 | * Get the amount the battery has discharged while the screen was off, |
| 978 | * since the last time power was unplugged. |
| 979 | */ |
| 980 | public abstract int getDischargeAmountScreenOff(); |
| 981 | |
| 982 | /** |
| 983 | * Get the amount the battery has discharged while the screen was off, |
| 984 | * since the last time the device was charged. |
| 985 | */ |
| 986 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 987 | |
| 988 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | * Returns the total, last, or current battery uptime in microseconds. |
| 990 | * |
| 991 | * @param curTime the elapsed realtime in microseconds. |
| 992 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 993 | */ |
| 994 | public abstract long computeBatteryUptime(long curTime, int which); |
| 995 | |
| 996 | /** |
| 997 | * Returns the total, last, or current battery realtime in microseconds. |
| 998 | * |
| 999 | * @param curTime the current elapsed realtime in microseconds. |
| 1000 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1001 | */ |
| 1002 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 1003 | |
| 1004 | /** |
| 1005 | * Returns the total, last, or current uptime in microseconds. |
| 1006 | * |
| 1007 | * @param curTime the current elapsed realtime in microseconds. |
| 1008 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1009 | */ |
| 1010 | public abstract long computeUptime(long curTime, int which); |
| 1011 | |
| 1012 | /** |
| 1013 | * Returns the total, last, or current realtime in microseconds. |
| 1014 | * * |
| 1015 | * @param curTime the current elapsed realtime in microseconds. |
| 1016 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1017 | */ |
| 1018 | public abstract long computeRealtime(long curTime, int which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1019 | |
| 1020 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1022 | /** Returns the number of different speeds that the CPU can run at */ |
| 1023 | public abstract int getCpuSpeedSteps(); |
| 1024 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1025 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 1026 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1027 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | long days = seconds / (60 * 60 * 24); |
| 1029 | if (days != 0) { |
| 1030 | out.append(days); |
| 1031 | out.append("d "); |
| 1032 | } |
| 1033 | long used = days * 60 * 60 * 24; |
| 1034 | |
| 1035 | long hours = (seconds - used) / (60 * 60); |
| 1036 | if (hours != 0 || used != 0) { |
| 1037 | out.append(hours); |
| 1038 | out.append("h "); |
| 1039 | } |
| 1040 | used += hours * 60 * 60; |
| 1041 | |
| 1042 | long mins = (seconds-used) / 60; |
| 1043 | if (mins != 0 || used != 0) { |
| 1044 | out.append(mins); |
| 1045 | out.append("m "); |
| 1046 | } |
| 1047 | used += mins * 60; |
| 1048 | |
| 1049 | if (seconds != 0 || used != 0) { |
| 1050 | out.append(seconds-used); |
| 1051 | out.append("s "); |
| 1052 | } |
| 1053 | } |
| 1054 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1055 | private final static void formatTime(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | long sec = time / 100; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1057 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | sb.append((time - (sec * 100)) * 10); |
| 1059 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1062 | private final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1064 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | sb.append(time - (sec * 1000)); |
| 1066 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | private final String formatRatioLocked(long num, long den) { |
| 1070 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1071 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | } |
| 1073 | float perc = ((float)num) / ((float)den) * 100; |
| 1074 | mFormatBuilder.setLength(0); |
| 1075 | mFormatter.format("%.1f%%", perc); |
| 1076 | return mFormatBuilder.toString(); |
| 1077 | } |
| 1078 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1079 | private final String formatBytesLocked(long bytes) { |
| 1080 | mFormatBuilder.setLength(0); |
| 1081 | |
| 1082 | if (bytes < BYTES_PER_KB) { |
| 1083 | return bytes + "B"; |
| 1084 | } else if (bytes < BYTES_PER_MB) { |
| 1085 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 1086 | return mFormatBuilder.toString(); |
| 1087 | } else if (bytes < BYTES_PER_GB){ |
| 1088 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 1089 | return mFormatBuilder.toString(); |
| 1090 | } else { |
| 1091 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 1092 | return mFormatBuilder.toString(); |
| 1093 | } |
| 1094 | } |
| 1095 | |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 1096 | private static long computeWakeLock(Timer timer, long batteryRealtime, int which) { |
| 1097 | if (timer != null) { |
| 1098 | // Convert from microseconds to milliseconds with rounding |
| 1099 | long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which); |
| 1100 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 1101 | return totalTimeMillis; |
| 1102 | } |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | /** |
| 1107 | * |
| 1108 | * @param sb a StringBuilder object. |
| 1109 | * @param timer a Timer object contining the wakelock times. |
| 1110 | * @param batteryRealtime the current on-battery time in microseconds. |
| 1111 | * @param name the name of the wakelock. |
| 1112 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1113 | * @param linePrefix a String to be prepended to each line of output. |
| 1114 | * @return the line prefix |
| 1115 | */ |
| 1116 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
| 1117 | long batteryRealtime, String name, int which, String linePrefix) { |
| 1118 | |
| 1119 | if (timer != null) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 1120 | long totalTimeMillis = computeWakeLock(timer, batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1122 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | if (totalTimeMillis != 0) { |
| 1124 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1125 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1126 | if (name != null) { |
| 1127 | sb.append(name); |
| 1128 | sb.append(' '); |
| 1129 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | sb.append('('); |
| 1131 | sb.append(count); |
| 1132 | sb.append(" times)"); |
| 1133 | return ", "; |
| 1134 | } |
| 1135 | } |
| 1136 | return linePrefix; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 1141 | * |
| 1142 | * @param sb a StringBuilder object. |
| 1143 | * @param timer a Timer object contining the wakelock times. |
| 1144 | * @param now the current time in microseconds. |
| 1145 | * @param name the name of the wakelock. |
| 1146 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1147 | * @param linePrefix a String to be prepended to each line of output. |
| 1148 | * @return the line prefix |
| 1149 | */ |
| 1150 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1151 | String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | long totalTimeMicros = 0; |
| 1153 | int count = 0; |
| 1154 | if (timer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1155 | totalTimeMicros = timer.getTotalTimeLocked(now, which); |
| 1156 | count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | sb.append(linePrefix); |
| 1159 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 1160 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1161 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | sb.append(count); |
| 1163 | return ","; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Dump a comma-separated line of values for terse checkin mode. |
| 1168 | * |
| 1169 | * @param pw the PageWriter to dump log to |
| 1170 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 1171 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 1172 | * @param args type-dependent data arguments |
| 1173 | */ |
| 1174 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 1175 | Object... args ) { |
| 1176 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 1177 | pw.print(uid); pw.print(','); |
| 1178 | pw.print(category); pw.print(','); |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1179 | pw.print(type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | |
| 1181 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1182 | pw.print(','); |
| 1183 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1185 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 1190 | * |
| 1191 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | */ |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1193 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 1195 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 1196 | final long batteryUptime = getBatteryUptime(rawUptime); |
| 1197 | final long batteryRealtime = getBatteryRealtime(rawRealtime); |
| 1198 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 1199 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 1200 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 1201 | final long totalUptime = computeUptime(rawUptime, which); |
| 1202 | final long screenOnTime = getScreenOnTime(batteryRealtime, which); |
| 1203 | final long phoneOnTime = getPhoneOnTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1204 | final long wifiOnTime = getWifiOnTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1205 | final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1206 | final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | |
| 1208 | StringBuilder sb = new StringBuilder(128); |
| 1209 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1210 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1211 | final int NU = uidStats.size(); |
| 1212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | // Dump "battery" stat |
| 1216 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1217 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1218 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame^] | 1219 | totalRealtime / 1000, totalUptime / 1000, |
| 1220 | getStartClockTime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1221 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1222 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1223 | long fullWakeLockTimeTotal = 0; |
| 1224 | long partialWakeLockTimeTotal = 0; |
| 1225 | |
| 1226 | for (int iu = 0; iu < NU; iu++) { |
| 1227 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1228 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1229 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1230 | if (wakelocks.size() > 0) { |
| 1231 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1232 | : wakelocks.entrySet()) { |
| 1233 | Uid.Wakelock wl = ent.getValue(); |
| 1234 | |
| 1235 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 1236 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1237 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 1241 | if (partialWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1242 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1243 | batteryRealtime, which); |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1249 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1250 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1251 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1252 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1253 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1254 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 1255 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1256 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 1257 | |
| 1258 | // Dump network stats |
| 1259 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 1260 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
| 1261 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets); |
| 1262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | // Dump misc stats |
| 1264 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1265 | screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1266 | wifiRunningTime / 1000, bluetoothOnTime / 1000, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1267 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1268 | fullWakeLockTimeTotal, partialWakeLockTimeTotal, |
| 1269 | getInputEventCount(which)); |
| 1270 | |
| 1271 | // Dump screen brightness stats |
| 1272 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 1273 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 1274 | args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000; |
| 1275 | } |
| 1276 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1277 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1278 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1279 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 1280 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1281 | args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000; |
| 1282 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1283 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1284 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
| 1285 | getPhoneSignalScanningTime(batteryRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1286 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1287 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 1288 | } |
| 1289 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1290 | |
| 1291 | // Dump network type stats |
| 1292 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 1293 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1294 | args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000; |
| 1295 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1296 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 1297 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1298 | args[i] = getPhoneDataConnectionCount(i, which); |
| 1299 | } |
| 1300 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1301 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1302 | if (which == STATS_SINCE_UNPLUGGED) { |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 1303 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1304 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1307 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1308 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 1309 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 1310 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 1311 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 1312 | } else { |
| 1313 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 1314 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
| 1315 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 1316 | } |
| 1317 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1318 | if (reqUid < 0) { |
| 1319 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 1320 | if (kernelWakelocks.size() > 0) { |
| 1321 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
| 1322 | sb.setLength(0); |
| 1323 | printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, ""); |
| 1324 | |
| 1325 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
| 1326 | sb.toString()); |
| 1327 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1331 | BatteryStatsHelper helper = new BatteryStatsHelper(context); |
| 1332 | helper.create(this); |
| 1333 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 1334 | List<BatterySipper> sippers = helper.getUsageList(); |
| 1335 | if (sippers != null && sippers.size() > 0) { |
| 1336 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 1337 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1338 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1339 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 1340 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 1341 | for (int i=0; i<sippers.size(); i++) { |
| 1342 | BatterySipper bs = sippers.get(i); |
| 1343 | int uid = 0; |
| 1344 | String label; |
| 1345 | switch (bs.drainType) { |
| 1346 | case IDLE: |
| 1347 | label="idle"; |
| 1348 | break; |
| 1349 | case CELL: |
| 1350 | label="cell"; |
| 1351 | break; |
| 1352 | case PHONE: |
| 1353 | label="phone"; |
| 1354 | break; |
| 1355 | case WIFI: |
| 1356 | label="wifi"; |
| 1357 | break; |
| 1358 | case BLUETOOTH: |
| 1359 | label="blue"; |
| 1360 | break; |
| 1361 | case SCREEN: |
| 1362 | label="scrn"; |
| 1363 | break; |
| 1364 | case APP: |
| 1365 | uid = bs.uidObj.getUid(); |
| 1366 | label = "uid"; |
| 1367 | break; |
| 1368 | case USER: |
| 1369 | uid = UserHandle.getUid(bs.userId, 0); |
| 1370 | label = "user"; |
| 1371 | break; |
| 1372 | case UNACCOUNTED: |
| 1373 | label = "unacc"; |
| 1374 | break; |
| 1375 | case OVERCOUNTED: |
| 1376 | label = "over"; |
| 1377 | break; |
| 1378 | default: |
| 1379 | label = "???"; |
| 1380 | } |
| 1381 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
| 1382 | BatteryStatsHelper.makemAh(bs.value)); |
| 1383 | } |
| 1384 | } |
| 1385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | for (int iu = 0; iu < NU; iu++) { |
| 1387 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1388 | if (reqUid >= 0 && uid != reqUid) { |
| 1389 | continue; |
| 1390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | Uid u = uidStats.valueAt(iu); |
| 1392 | // Dump Network stats per uid, if any |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1393 | long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1394 | long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1395 | long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1396 | long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1397 | long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1398 | long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 1399 | long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1400 | long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1401 | long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1402 | long wifiScanTime = u.getWifiScanTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1403 | long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1404 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1405 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 1406 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
| 1407 | || wifiPacketsTx > 0) { |
| 1408 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 1409 | wifiBytesRx, wifiBytesTx, |
| 1410 | mobilePacketsRx, mobilePacketsTx, |
| 1411 | wifiPacketsRx, wifiPacketsTx); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1414 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1415 | || uidWifiRunningTime != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1416 | dumpLine(pw, uid, category, WIFI_DATA, |
| 1417 | fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1420 | if (u.hasUserActivity()) { |
| 1421 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 1422 | boolean hasData = false; |
| 1423 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 1424 | int val = u.getUserActivityCount(i, which); |
| 1425 | args[i] = val; |
| 1426 | if (val != 0) hasData = true; |
| 1427 | } |
| 1428 | if (hasData) { |
| 1429 | dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args); |
| 1430 | } |
| 1431 | } |
| 1432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1434 | if (wakelocks.size() > 0) { |
| 1435 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1436 | : wakelocks.entrySet()) { |
| 1437 | Uid.Wakelock wl = ent.getValue(); |
| 1438 | String linePrefix = ""; |
| 1439 | sb.setLength(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1440 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 1441 | batteryRealtime, "f", which, linePrefix); |
| 1442 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 1443 | batteryRealtime, "p", which, linePrefix); |
| 1444 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 1445 | batteryRealtime, "w", which, linePrefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | |
| 1447 | // Only log if we had at lease one wakelock... |
| 1448 | if (sb.length() > 0) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1449 | String name = ent.getKey(); |
| 1450 | if (name.indexOf(',') >= 0) { |
| 1451 | name = name.replace(',', '_'); |
| 1452 | } |
| 1453 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 1459 | if (sensors.size() > 0) { |
| 1460 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 1461 | : sensors.entrySet()) { |
| 1462 | Uid.Sensor se = ent.getValue(); |
| 1463 | int sensorNumber = ent.getKey(); |
| 1464 | Timer timer = se.getSensorTime(); |
| 1465 | if (timer != null) { |
| 1466 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1467 | long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000; |
| 1468 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | if (totalTime != 0) { |
| 1470 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count); |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1476 | Timer vibTimer = u.getVibratorOnTimer(); |
| 1477 | if (vibTimer != null) { |
| 1478 | // Convert from microseconds to milliseconds with rounding |
| 1479 | long totalTime = (vibTimer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000; |
| 1480 | int count = vibTimer.getCountLocked(which); |
| 1481 | if (totalTime != 0) { |
| 1482 | dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count); |
| 1483 | } |
| 1484 | } |
| 1485 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1486 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 1487 | if (fgTimer != null) { |
| 1488 | // Convert from microseconds to milliseconds with rounding |
| 1489 | long totalTime = (fgTimer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000; |
| 1490 | int count = fgTimer.getCountLocked(which); |
| 1491 | if (totalTime != 0) { |
| 1492 | dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count); |
| 1493 | } |
| 1494 | } |
| 1495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 1497 | if (processStats.size() > 0) { |
| 1498 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 1499 | : processStats.entrySet()) { |
| 1500 | Uid.Proc ps = ent.getValue(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1501 | |
| 1502 | final long userMillis = ps.getUserTime(which) * 10; |
| 1503 | final long systemMillis = ps.getSystemTime(which) * 10; |
| 1504 | final long foregroundMillis = ps.getForegroundTime(which) * 10; |
| 1505 | final long starts = ps.getStarts(which); |
| 1506 | |
| 1507 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 1508 | || starts != 0) { |
| 1509 | dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis, |
| 1510 | systemMillis, foregroundMillis, starts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 1516 | if (packageStats.size() > 0) { |
| 1517 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 1518 | : packageStats.entrySet()) { |
| 1519 | |
| 1520 | Uid.Pkg ps = ent.getValue(); |
| 1521 | int wakeups = ps.getWakeups(which); |
| 1522 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 1523 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 1524 | : serviceStats.entrySet()) { |
| 1525 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 1526 | long startTime = ss.getStartTime(batteryUptime, which); |
| 1527 | int starts = ss.getStarts(which); |
| 1528 | int launches = ss.getLaunches(which); |
| 1529 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 1530 | dumpLine(pw, uid, category, APK_DATA, |
| 1531 | wakeups, // wakeup alarms |
| 1532 | ent.getKey(), // Apk |
| 1533 | sent.getKey(), // service |
| 1534 | startTime / 1000, // time spent started, in ms |
| 1535 | starts, |
| 1536 | launches); |
| 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | } |
| 1543 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1544 | static final class TimerEntry { |
| 1545 | final String mName; |
| 1546 | final int mId; |
| 1547 | final BatteryStats.Timer mTimer; |
| 1548 | final long mTime; |
| 1549 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 1550 | mName = name; |
| 1551 | mId = id; |
| 1552 | mTimer = timer; |
| 1553 | mTime = time; |
| 1554 | } |
| 1555 | } |
| 1556 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1557 | private void printmAh(PrintWriter printer, double power) { |
| 1558 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 1559 | } |
| 1560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1562 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, |
| 1563 | int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 1565 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 1566 | final long batteryUptime = getBatteryUptime(rawUptime); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1567 | final long batteryRealtime = getBatteryRealtime(rawRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | |
| 1569 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 1570 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 1571 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 1572 | final long totalUptime = computeUptime(rawUptime, which); |
| 1573 | |
| 1574 | StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1575 | |
| 1576 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1577 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1579 | sb.setLength(0); |
| 1580 | sb.append(prefix); |
| 1581 | sb.append(" Time on battery: "); |
| 1582 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 1583 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 1584 | sb.append(") realtime, "); |
| 1585 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 1586 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 1587 | sb.append(") uptime"); |
| 1588 | pw.println(sb.toString()); |
| 1589 | sb.setLength(0); |
| 1590 | sb.append(prefix); |
| 1591 | sb.append(" Total run time: "); |
| 1592 | formatTimeMs(sb, totalRealtime / 1000); |
| 1593 | sb.append("realtime, "); |
| 1594 | formatTimeMs(sb, totalUptime / 1000); |
| 1595 | sb.append("uptime, "); |
| 1596 | pw.println(sb.toString()); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame^] | 1597 | pw.print(" Start clock time: "); |
| 1598 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 1599 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1600 | final long screenOnTime = getScreenOnTime(batteryRealtime, which); |
| 1601 | final long phoneOnTime = getPhoneOnTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1602 | final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1603 | final long wifiOnTime = getWifiOnTime(batteryRealtime, which); |
| 1604 | final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1605 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1606 | sb.append(prefix); |
| 1607 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 1608 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
| 1609 | sb.append("), Input events: "); sb.append(getInputEventCount(which)); |
| 1610 | sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 1611 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
| 1612 | sb.append(")"); |
| 1613 | pw.println(sb.toString()); |
| 1614 | sb.setLength(0); |
| 1615 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1616 | sb.append(" Screen brightnesses: "); |
| 1617 | boolean didOne = false; |
| 1618 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 1619 | final long time = getScreenBrightnessTime(i, batteryRealtime, which); |
| 1620 | if (time == 0) { |
| 1621 | continue; |
| 1622 | } |
| 1623 | if (didOne) sb.append(", "); |
| 1624 | didOne = true; |
| 1625 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 1626 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1627 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1628 | sb.append("("); |
| 1629 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 1630 | sb.append(")"); |
| 1631 | } |
| 1632 | if (!didOne) sb.append("No activity"); |
| 1633 | pw.println(sb.toString()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1634 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1635 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1636 | long fullWakeLockTimeTotalMicros = 0; |
| 1637 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1638 | |
| 1639 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 1640 | @Override |
| 1641 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 1642 | long lhsTime = lhs.mTime; |
| 1643 | long rhsTime = rhs.mTime; |
| 1644 | if (lhsTime < rhsTime) { |
| 1645 | return 1; |
| 1646 | } |
| 1647 | if (lhsTime > rhsTime) { |
| 1648 | return -1; |
| 1649 | } |
| 1650 | return 0; |
| 1651 | } |
| 1652 | }; |
| 1653 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1654 | if (reqUid < 0) { |
| 1655 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 1656 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1657 | final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1658 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1659 | BatteryStats.Timer timer = ent.getValue(); |
| 1660 | long totalTimeMillis = computeWakeLock(timer, batteryRealtime, which); |
| 1661 | if (totalTimeMillis > 0) { |
| 1662 | timers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 1663 | } |
| 1664 | } |
| 1665 | Collections.sort(timers, timerComparator); |
| 1666 | for (int i=0; i<timers.size(); i++) { |
| 1667 | TimerEntry timer = timers.get(i); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1668 | String linePrefix = ": "; |
| 1669 | sb.setLength(0); |
| 1670 | sb.append(prefix); |
| 1671 | sb.append(" Kernel Wake lock "); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1672 | sb.append(timer.mName); |
| 1673 | linePrefix = printWakeLock(sb, timer.mTimer, batteryRealtime, null, |
| 1674 | which, linePrefix); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1675 | if (!linePrefix.equals(": ")) { |
| 1676 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 1677 | // Only print out wake locks that were held |
| 1678 | pw.println(sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1679 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1680 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1681 | } |
| 1682 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1683 | |
| 1684 | final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); |
| 1685 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1686 | for (int iu = 0; iu < NU; iu++) { |
| 1687 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1688 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1689 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1690 | if (wakelocks.size() > 0) { |
| 1691 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1692 | : wakelocks.entrySet()) { |
| 1693 | Uid.Wakelock wl = ent.getValue(); |
| 1694 | |
| 1695 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 1696 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1697 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1698 | batteryRealtime, which); |
| 1699 | } |
| 1700 | |
| 1701 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 1702 | if (partialWakeTimer != null) { |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1703 | long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1704 | batteryRealtime, which); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1705 | if (totalTimeMicros > 0) { |
| 1706 | if (reqUid < 0) { |
| 1707 | // Only show the ordered list of all wake |
| 1708 | // locks if the caller is not asking for data |
| 1709 | // about a specific uid. |
| 1710 | timers.add(new TimerEntry(ent.getKey(), u.getUid(), |
| 1711 | partialWakeTimer, totalTimeMicros)); |
| 1712 | } |
| 1713 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
| 1714 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1720 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1721 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1722 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1723 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1724 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1725 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 1726 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1727 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 1728 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1729 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1730 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 1731 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 1732 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 1733 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1734 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1735 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 1736 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 1737 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 1738 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1739 | sb.setLength(0); |
| 1740 | sb.append(prefix); |
| 1741 | sb.append(" Total full wakelock time: "); formatTimeMs(sb, |
| 1742 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1743 | sb.append(", Total partial wakelock time: "); formatTimeMs(sb, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1744 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 1745 | pw.println(sb.toString()); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1746 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1747 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1748 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1749 | sb.append(" Signal levels: "); |
| 1750 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1751 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1752 | final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which); |
| 1753 | if (time == 0) { |
| 1754 | continue; |
| 1755 | } |
| 1756 | if (didOne) sb.append(", "); |
| 1757 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1758 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1759 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1760 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1761 | sb.append("("); |
| 1762 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1763 | sb.append(") "); |
| 1764 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 1765 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1766 | } |
| 1767 | if (!didOne) sb.append("No activity"); |
| 1768 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1769 | |
| 1770 | sb.setLength(0); |
| 1771 | sb.append(prefix); |
| 1772 | sb.append(" Signal scanning time: "); |
| 1773 | formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000); |
| 1774 | pw.println(sb.toString()); |
| 1775 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1776 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1777 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1778 | sb.append(" Radio types: "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1779 | didOne = false; |
| 1780 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1781 | final long time = getPhoneDataConnectionTime(i, batteryRealtime, which); |
| 1782 | if (time == 0) { |
| 1783 | continue; |
| 1784 | } |
| 1785 | if (didOne) sb.append(", "); |
| 1786 | didOne = true; |
| 1787 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 1788 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1789 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1790 | sb.append("("); |
| 1791 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1792 | sb.append(") "); |
| 1793 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 1794 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1795 | } |
| 1796 | if (!didOne) sb.append("No activity"); |
| 1797 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1798 | |
| 1799 | sb.setLength(0); |
| 1800 | sb.append(prefix); |
| 1801 | sb.append(" Radio data uptime when unplugged: "); |
| 1802 | sb.append(getRadioDataUptime() / 1000); |
| 1803 | sb.append(" ms"); |
| 1804 | pw.println(sb.toString()); |
| 1805 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1806 | sb.setLength(0); |
| 1807 | sb.append(prefix); |
| 1808 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 1809 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 1810 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 1811 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
| 1812 | sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000); |
| 1813 | sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)); |
| 1814 | sb.append(")"); |
| 1815 | pw.println(sb.toString()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1816 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1817 | pw.println(" "); |
| 1818 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1819 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1820 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1821 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 1822 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 1823 | pw.println(getDischargeStartLevel()); |
| 1824 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 1825 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 1826 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1827 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 1828 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 1829 | pw.println(getDischargeStartLevel()); |
| 1830 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 1831 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1832 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1833 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 1834 | pw.println(getDischargeAmountScreenOn()); |
| 1835 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 1836 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1837 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1838 | } else { |
| 1839 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 1840 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 1841 | pw.println(getLowDischargeAmountSinceCharge()); |
| 1842 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 1843 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1844 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 1845 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 1846 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 1847 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1848 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1849 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1850 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1851 | BatteryStatsHelper helper = new BatteryStatsHelper(context); |
| 1852 | helper.create(this); |
| 1853 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 1854 | List<BatterySipper> sippers = helper.getUsageList(); |
| 1855 | if (sippers != null && sippers.size() > 0) { |
| 1856 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 1857 | pw.print(prefix); pw.print(" Capacity: "); |
| 1858 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1859 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1860 | pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 1861 | pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower()); |
| 1862 | pw.println(); |
| 1863 | for (int i=0; i<sippers.size(); i++) { |
| 1864 | BatterySipper bs = sippers.get(i); |
| 1865 | switch (bs.drainType) { |
| 1866 | case IDLE: |
| 1867 | pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value); |
| 1868 | pw.println(); |
| 1869 | break; |
| 1870 | case CELL: |
| 1871 | pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value); |
| 1872 | pw.println(); |
| 1873 | break; |
| 1874 | case PHONE: |
| 1875 | pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value); |
| 1876 | pw.println(); |
| 1877 | break; |
| 1878 | case WIFI: |
| 1879 | pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value); |
| 1880 | pw.println(); |
| 1881 | break; |
| 1882 | case BLUETOOTH: |
| 1883 | pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value); |
| 1884 | pw.println(); |
| 1885 | break; |
| 1886 | case SCREEN: |
| 1887 | pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value); |
| 1888 | pw.println(); |
| 1889 | break; |
| 1890 | case APP: |
| 1891 | pw.print(prefix); pw.print(" Uid "); pw.print(bs.uidObj.getUid()); |
| 1892 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 1893 | break; |
| 1894 | case USER: |
| 1895 | pw.print(prefix); pw.print(" User "); pw.print(bs.userId); |
| 1896 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 1897 | break; |
| 1898 | case UNACCOUNTED: |
| 1899 | pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value); |
| 1900 | pw.println(); |
| 1901 | break; |
| 1902 | case OVERCOUNTED: |
| 1903 | pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value); |
| 1904 | pw.println(); |
| 1905 | break; |
| 1906 | } |
| 1907 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1908 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1911 | if (timers.size() > 0) { |
| 1912 | Collections.sort(timers, timerComparator); |
| 1913 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 1914 | for (int i=0; i<timers.size(); i++) { |
| 1915 | TimerEntry timer = timers.get(i); |
| 1916 | sb.setLength(0); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 1917 | sb.append(" Wake lock "); |
| 1918 | UserHandle.formatUid(sb, timer.mId); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1919 | sb.append(" "); |
| 1920 | sb.append(timer.mName); |
| 1921 | printWakeLock(sb, timer.mTimer, batteryRealtime, null, which, ": "); |
| 1922 | sb.append(" realtime"); |
| 1923 | pw.println(sb.toString()); |
| 1924 | } |
| 1925 | timers.clear(); |
| 1926 | pw.println(); |
| 1927 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | for (int iu=0; iu<NU; iu++) { |
| 1930 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 1931 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1932 | continue; |
| 1933 | } |
| 1934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 1936 | |
| 1937 | pw.print(prefix); |
| 1938 | pw.print(" "); |
| 1939 | UserHandle.formatUid(pw, uid); |
| 1940 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | boolean uidActivity = false; |
| 1942 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1943 | long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1944 | long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1945 | long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1946 | long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1947 | long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1948 | long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 1949 | long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1950 | long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1951 | long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1952 | long wifiScanTime = u.getWifiScanTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1953 | long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1954 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1955 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 1956 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1957 | pw.print(prefix); pw.print(" Mobile network: "); |
| 1958 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1959 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 1960 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 1961 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1963 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1964 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 1965 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1966 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 1967 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 1968 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1971 | if (u.hasUserActivity()) { |
| 1972 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 1973 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1974 | int val = u.getUserActivityCount(i, which); |
| 1975 | if (val != 0) { |
| 1976 | if (!hasData) { |
| 1977 | sb.setLength(0); |
| 1978 | sb.append(" User activity: "); |
| 1979 | hasData = true; |
| 1980 | } else { |
| 1981 | sb.append(", "); |
| 1982 | } |
| 1983 | sb.append(val); |
| 1984 | sb.append(" "); |
| 1985 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 1986 | } |
| 1987 | } |
| 1988 | if (hasData) { |
| 1989 | pw.println(sb.toString()); |
| 1990 | } |
| 1991 | } |
| 1992 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1993 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1994 | || uidWifiRunningTime != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1995 | sb.setLength(0); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1996 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 1997 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 1998 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1999 | whichBatteryRealtime)); sb.append(")\n"); |
| 2000 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2001 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 2002 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2003 | whichBatteryRealtime)); sb.append(")\n"); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2004 | sb.append(prefix); sb.append(" Wifi Scan: "); |
| 2005 | formatTimeMs(sb, wifiScanTime / 1000); |
| 2006 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2007 | whichBatteryRealtime)); sb.append(")"); |
| 2008 | pw.println(sb.toString()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | |
| 2011 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 2012 | if (wakelocks.size() > 0) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2013 | long totalFull = 0, totalPartial = 0, totalWindow = 0; |
| 2014 | int count = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 2016 | : wakelocks.entrySet()) { |
| 2017 | Uid.Wakelock wl = ent.getValue(); |
| 2018 | String linePrefix = ": "; |
| 2019 | sb.setLength(0); |
| 2020 | sb.append(prefix); |
| 2021 | sb.append(" Wake lock "); |
| 2022 | sb.append(ent.getKey()); |
| 2023 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime, |
| 2024 | "full", which, linePrefix); |
| 2025 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime, |
| 2026 | "partial", which, linePrefix); |
| 2027 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime, |
| 2028 | "window", which, linePrefix); |
| 2029 | if (!linePrefix.equals(": ")) { |
| 2030 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 2031 | // Only print out wake locks that were held |
| 2032 | pw.println(sb.toString()); |
| 2033 | uidActivity = true; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2034 | count++; |
| 2035 | } |
| 2036 | totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 2037 | batteryRealtime, which); |
| 2038 | totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 2039 | batteryRealtime, which); |
| 2040 | totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 2041 | batteryRealtime, which); |
| 2042 | } |
| 2043 | if (count > 1) { |
| 2044 | if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) { |
| 2045 | sb.setLength(0); |
| 2046 | sb.append(prefix); |
| 2047 | sb.append(" TOTAL wake: "); |
| 2048 | boolean needComma = false; |
| 2049 | if (totalFull != 0) { |
| 2050 | needComma = true; |
| 2051 | formatTimeMs(sb, totalFull); |
| 2052 | sb.append("full"); |
| 2053 | } |
| 2054 | if (totalPartial != 0) { |
| 2055 | if (needComma) { |
| 2056 | sb.append(", "); |
| 2057 | } |
| 2058 | needComma = true; |
| 2059 | formatTimeMs(sb, totalPartial); |
| 2060 | sb.append("partial"); |
| 2061 | } |
| 2062 | if (totalWindow != 0) { |
| 2063 | if (needComma) { |
| 2064 | sb.append(", "); |
| 2065 | } |
| 2066 | needComma = true; |
| 2067 | formatTimeMs(sb, totalWindow); |
| 2068 | sb.append("window"); |
| 2069 | } |
| 2070 | sb.append(" realtime"); |
| 2071 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 2077 | if (sensors.size() > 0) { |
| 2078 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 2079 | : sensors.entrySet()) { |
| 2080 | Uid.Sensor se = ent.getValue(); |
| 2081 | int sensorNumber = ent.getKey(); |
| 2082 | sb.setLength(0); |
| 2083 | sb.append(prefix); |
| 2084 | sb.append(" Sensor "); |
| 2085 | int handle = se.getHandle(); |
| 2086 | if (handle == Uid.Sensor.GPS) { |
| 2087 | sb.append("GPS"); |
| 2088 | } else { |
| 2089 | sb.append(handle); |
| 2090 | } |
| 2091 | sb.append(": "); |
| 2092 | |
| 2093 | Timer timer = se.getSensorTime(); |
| 2094 | if (timer != null) { |
| 2095 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2096 | long totalTime = (timer.getTotalTimeLocked( |
| 2097 | batteryRealtime, which) + 500) / 1000; |
| 2098 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | //timer.logState(); |
| 2100 | if (totalTime != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2101 | formatTimeMs(sb, totalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | sb.append("realtime ("); |
| 2103 | sb.append(count); |
| 2104 | sb.append(" times)"); |
| 2105 | } else { |
| 2106 | sb.append("(not used)"); |
| 2107 | } |
| 2108 | } else { |
| 2109 | sb.append("(not used)"); |
| 2110 | } |
| 2111 | |
| 2112 | pw.println(sb.toString()); |
| 2113 | uidActivity = true; |
| 2114 | } |
| 2115 | } |
| 2116 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2117 | Timer vibTimer = u.getVibratorOnTimer(); |
| 2118 | if (vibTimer != null) { |
| 2119 | // Convert from microseconds to milliseconds with rounding |
| 2120 | long totalTime = (vibTimer.getTotalTimeLocked( |
| 2121 | batteryRealtime, which) + 500) / 1000; |
| 2122 | int count = vibTimer.getCountLocked(which); |
| 2123 | //timer.logState(); |
| 2124 | if (totalTime != 0) { |
| 2125 | sb.setLength(0); |
| 2126 | sb.append(prefix); |
| 2127 | sb.append(" Vibrator: "); |
| 2128 | formatTimeMs(sb, totalTime); |
| 2129 | sb.append("realtime ("); |
| 2130 | sb.append(count); |
| 2131 | sb.append(" times)"); |
| 2132 | pw.println(sb.toString()); |
| 2133 | uidActivity = true; |
| 2134 | } |
| 2135 | } |
| 2136 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2137 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 2138 | if (fgTimer != null) { |
| 2139 | // Convert from microseconds to milliseconds with rounding |
| 2140 | long totalTime = (fgTimer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000; |
| 2141 | int count = fgTimer.getCountLocked(which); |
| 2142 | if (totalTime != 0) { |
| 2143 | sb.setLength(0); |
| 2144 | sb.append(prefix); |
| 2145 | sb.append(" Foreground activities: "); |
| 2146 | formatTimeMs(sb, totalTime); |
| 2147 | sb.append("realtime ("); |
| 2148 | sb.append(count); |
| 2149 | sb.append(" times)"); |
| 2150 | pw.println(sb.toString()); |
| 2151 | uidActivity = true; |
| 2152 | } |
| 2153 | } |
| 2154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 2156 | if (processStats.size() > 0) { |
| 2157 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 2158 | : processStats.entrySet()) { |
| 2159 | Uid.Proc ps = ent.getValue(); |
| 2160 | long userTime; |
| 2161 | long systemTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2162 | long foregroundTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | int starts; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2164 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | |
| 2166 | userTime = ps.getUserTime(which); |
| 2167 | systemTime = ps.getSystemTime(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2168 | foregroundTime = ps.getForegroundTime(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | starts = ps.getStarts(which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2170 | numExcessive = which == STATS_SINCE_CHARGED |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2171 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2173 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2174 | || numExcessive != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2175 | sb.setLength(0); |
| 2176 | sb.append(prefix); sb.append(" Proc "); |
| 2177 | sb.append(ent.getKey()); sb.append(":\n"); |
| 2178 | sb.append(prefix); sb.append(" CPU: "); |
| 2179 | formatTime(sb, userTime); sb.append("usr + "); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2180 | formatTime(sb, systemTime); sb.append("krn ; "); |
| 2181 | formatTime(sb, foregroundTime); sb.append("fg"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2182 | if (starts != 0) { |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 2183 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 2184 | sb.append(starts); sb.append(" proc starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2185 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2186 | pw.println(sb.toString()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2187 | for (int e=0; e<numExcessive; e++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2188 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2189 | if (ew != null) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2190 | pw.print(prefix); pw.print(" * Killed for "); |
| 2191 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 2192 | pw.print("wake lock"); |
| 2193 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 2194 | pw.print("cpu"); |
| 2195 | } else { |
| 2196 | pw.print("unknown"); |
| 2197 | } |
| 2198 | pw.print(" use: "); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2199 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 2200 | pw.print(" over "); |
| 2201 | TimeUtils.formatDuration(ew.overTime, pw); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2202 | if (ew.overTime != 0) { |
| 2203 | pw.print(" ("); |
| 2204 | pw.print((ew.usedTime*100)/ew.overTime); |
| 2205 | pw.println("%)"); |
| 2206 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2207 | } |
| 2208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | uidActivity = true; |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 2215 | if (packageStats.size() > 0) { |
| 2216 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 2217 | : packageStats.entrySet()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2218 | pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | boolean apkActivity = false; |
| 2220 | Uid.Pkg ps = ent.getValue(); |
| 2221 | int wakeups = ps.getWakeups(which); |
| 2222 | if (wakeups != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2223 | pw.print(prefix); pw.print(" "); |
| 2224 | pw.print(wakeups); pw.println(" wakeup alarms"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | apkActivity = true; |
| 2226 | } |
| 2227 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 2228 | if (serviceStats.size() > 0) { |
| 2229 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 2230 | : serviceStats.entrySet()) { |
| 2231 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 2232 | long startTime = ss.getStartTime(batteryUptime, which); |
| 2233 | int starts = ss.getStarts(which); |
| 2234 | int launches = ss.getLaunches(which); |
| 2235 | if (startTime != 0 || starts != 0 || launches != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2236 | sb.setLength(0); |
| 2237 | sb.append(prefix); sb.append(" Service "); |
| 2238 | sb.append(sent.getKey()); sb.append(":\n"); |
| 2239 | sb.append(prefix); sb.append(" Created for: "); |
| 2240 | formatTimeMs(sb, startTime / 1000); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2241 | sb.append("uptime\n"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2242 | sb.append(prefix); sb.append(" Starts: "); |
| 2243 | sb.append(starts); |
| 2244 | sb.append(", launches: "); sb.append(launches); |
| 2245 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | apkActivity = true; |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | if (!apkActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2251 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | } |
| 2253 | uidActivity = true; |
| 2254 | } |
| 2255 | } |
| 2256 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2257 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2262 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, |
| 2263 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2264 | int diff = oldval ^ newval; |
| 2265 | if (diff == 0) return; |
| 2266 | for (int i=0; i<descriptions.length; i++) { |
| 2267 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2268 | int mask = bd.mask; |
| 2269 | if (bd.shift > 0) { |
| 2270 | mask <<= bd.shift; |
| 2271 | } |
| 2272 | if ((diff&mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2273 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2274 | if (bd.shift < 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2275 | pw.print((newval&mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2276 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2277 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2278 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2279 | pw.print("="); |
| 2280 | int val = (newval&bd.mask)>>bd.shift; |
| 2281 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2282 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2283 | } else { |
| 2284 | pw.print(val); |
| 2285 | } |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | } |
| 2290 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2291 | public void prepareForDumpLocked() { |
| 2292 | } |
| 2293 | |
| 2294 | public static class HistoryPrinter { |
| 2295 | int oldState = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2296 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2297 | int oldStatus = -1; |
| 2298 | int oldHealth = -1; |
| 2299 | int oldPlug = -1; |
| 2300 | int oldTemp = -1; |
| 2301 | int oldVolt = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2302 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2303 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2304 | public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin) { |
| 2305 | if (!checkin) { |
| 2306 | pw.print(" "); |
| 2307 | TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2308 | pw.print(" "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2309 | } else { |
| 2310 | if (lastTime < 0) { |
| 2311 | pw.print("@"); |
| 2312 | pw.print(rec.time-now); |
| 2313 | } else { |
| 2314 | pw.print(rec.time-lastTime); |
| 2315 | } |
| 2316 | lastTime = rec.time; |
| 2317 | } |
| 2318 | if (rec.cmd == HistoryItem.CMD_START) { |
| 2319 | if (checkin) { |
| 2320 | pw.print(":"); |
| 2321 | } |
| 2322 | pw.println("START"); |
| 2323 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 2324 | if (checkin) { |
| 2325 | pw.print(":"); |
| 2326 | } |
| 2327 | pw.println("*OVERFLOW*"); |
| 2328 | } else { |
| 2329 | if (!checkin) { |
| 2330 | if (rec.batteryLevel < 10) pw.print("00"); |
| 2331 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 2332 | pw.print(rec.batteryLevel); |
| 2333 | pw.print(" "); |
| 2334 | if (rec.states < 0x10) pw.print("0000000"); |
| 2335 | else if (rec.states < 0x100) pw.print("000000"); |
| 2336 | else if (rec.states < 0x1000) pw.print("00000"); |
| 2337 | else if (rec.states < 0x10000) pw.print("0000"); |
| 2338 | else if (rec.states < 0x100000) pw.print("000"); |
| 2339 | else if (rec.states < 0x1000000) pw.print("00"); |
| 2340 | else if (rec.states < 0x10000000) pw.print("0"); |
| 2341 | pw.print(Integer.toHexString(rec.states)); |
| 2342 | } else { |
| 2343 | if (oldLevel != rec.batteryLevel) { |
| 2344 | oldLevel = rec.batteryLevel; |
| 2345 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 2346 | } |
| 2347 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2348 | if (oldStatus != rec.batteryStatus) { |
| 2349 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2350 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2351 | switch (oldStatus) { |
| 2352 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2353 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2354 | break; |
| 2355 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2356 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2357 | break; |
| 2358 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2359 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2360 | break; |
| 2361 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2362 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2363 | break; |
| 2364 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2365 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2366 | break; |
| 2367 | default: |
| 2368 | pw.print(oldStatus); |
| 2369 | break; |
| 2370 | } |
| 2371 | } |
| 2372 | if (oldHealth != rec.batteryHealth) { |
| 2373 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2374 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2375 | switch (oldHealth) { |
| 2376 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2377 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2378 | break; |
| 2379 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2380 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2381 | break; |
| 2382 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2383 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2384 | break; |
| 2385 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2386 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2387 | break; |
| 2388 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2389 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2390 | break; |
| 2391 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2392 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2393 | break; |
| 2394 | default: |
| 2395 | pw.print(oldHealth); |
| 2396 | break; |
| 2397 | } |
| 2398 | } |
| 2399 | if (oldPlug != rec.batteryPlugType) { |
| 2400 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2401 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2402 | switch (oldPlug) { |
| 2403 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2404 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2405 | break; |
| 2406 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2407 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2408 | break; |
| 2409 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2410 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2411 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 2412 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2413 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 2414 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2415 | default: |
| 2416 | pw.print(oldPlug); |
| 2417 | break; |
| 2418 | } |
| 2419 | } |
| 2420 | if (oldTemp != rec.batteryTemperature) { |
| 2421 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2422 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2423 | pw.print(oldTemp); |
| 2424 | } |
| 2425 | if (oldVolt != rec.batteryVoltage) { |
| 2426 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2427 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2428 | pw.print(oldVolt); |
| 2429 | } |
| 2430 | printBitDescriptions(pw, oldState, rec.states, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2431 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2432 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
| 2433 | switch (rec.eventCode) { |
| 2434 | case HistoryItem.EVENT_PROC_STARTED: |
| 2435 | pw.print(checkin ? ",PrSt=" : " procstart="); |
| 2436 | break; |
| 2437 | case HistoryItem.EVENT_PROC_FINISHED: |
| 2438 | pw.print(checkin ? ",PrFn=" : " procfin="); |
| 2439 | break; |
| 2440 | default: |
| 2441 | if (checkin) { |
| 2442 | pw.print(",?cmd_"); |
| 2443 | pw.print(rec.eventCode); |
| 2444 | pw.print("="); |
| 2445 | } else { |
| 2446 | pw.print(" cmd_"); |
| 2447 | pw.print(rec.eventCode); |
| 2448 | pw.print("="); |
| 2449 | } |
| 2450 | break; |
| 2451 | } |
| 2452 | if (checkin) { |
| 2453 | pw.print(rec.eventUid); |
| 2454 | } else { |
| 2455 | UserHandle.formatUid(pw, rec.eventUid); |
| 2456 | } |
| 2457 | pw.print(":"); |
| 2458 | if (checkin) { |
| 2459 | pw.print(rec.eventNameIdx); |
| 2460 | } else { |
| 2461 | pw.print(rec.eventName); |
| 2462 | } |
| 2463 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2464 | pw.println(); |
| 2465 | } |
| 2466 | oldState = rec.states; |
| 2467 | } |
| 2468 | } |
| 2469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | /** |
| 2471 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 2472 | * |
| 2473 | * @param pw a Printer to receive the dump output. |
| 2474 | */ |
| 2475 | @SuppressWarnings("unused") |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2476 | public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, |
| 2477 | boolean historyOnly) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2478 | prepareForDumpLocked(); |
| 2479 | |
| 2480 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 2481 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2482 | final HistoryItem rec = new HistoryItem(); |
| 2483 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2484 | pw.println("Battery History:"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2485 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2486 | while (getNextHistoryLocked(rec)) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2487 | hprinter.printNextItem(pw, rec, now, false); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2488 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2489 | finishIteratingHistoryLocked(); |
| 2490 | pw.println(""); |
| 2491 | } |
| 2492 | |
| 2493 | if (startIteratingOldHistoryLocked()) { |
| 2494 | pw.println("Old battery History:"); |
| 2495 | HistoryPrinter hprinter = new HistoryPrinter(); |
| 2496 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2497 | hprinter.printNextItem(pw, rec, now, false); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2498 | } |
| 2499 | finishIteratingOldHistoryLocked(); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2500 | pw.println(""); |
| 2501 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2502 | |
| 2503 | if (historyOnly) { |
| 2504 | return; |
| 2505 | } |
| 2506 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2507 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 2508 | final int NU = uidStats.size(); |
| 2509 | boolean didPid = false; |
| 2510 | long nowRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 2511 | for (int i=0; i<NU; i++) { |
| 2512 | Uid uid = uidStats.valueAt(i); |
| 2513 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 2514 | if (pids != null) { |
| 2515 | for (int j=0; j<pids.size(); j++) { |
| 2516 | Uid.Pid pid = pids.valueAt(j); |
| 2517 | if (!didPid) { |
| 2518 | pw.println("Per-PID Stats:"); |
| 2519 | didPid = true; |
| 2520 | } |
| 2521 | long time = pid.mWakeSum + (pid.mWakeStart != 0 |
| 2522 | ? (nowRealtime - pid.mWakeStart) : 0); |
| 2523 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 2524 | pw.print(" wake time: "); |
| 2525 | TimeUtils.formatDuration(time, pw); |
| 2526 | pw.println(""); |
| 2527 | } |
| 2528 | } |
| 2529 | } |
| 2530 | if (didPid) { |
| 2531 | pw.println(""); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2532 | } |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 2533 | |
| 2534 | if (!isUnpluggedOnly) { |
| 2535 | pw.println("Statistics since last charge:"); |
| 2536 | pw.println(" System starts: " + getStartCount() |
| 2537 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2538 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 2539 | pw.println(""); |
| 2540 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2541 | pw.println("Statistics since last unplugged:"); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2542 | dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2546 | public void dumpCheckinLocked(Context context, |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 2547 | PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly, |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2548 | boolean includeHistory, boolean historyOnly) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2549 | prepareForDumpLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2551 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 2552 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2553 | if (includeHistory || historyOnly) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 2554 | final HistoryItem rec = new HistoryItem(); |
| 2555 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2556 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 2557 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 2558 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 2559 | pw.print(i); |
| 2560 | pw.print(','); |
| 2561 | pw.print(getHistoryStringPoolItem(i)); |
| 2562 | pw.println(); |
| 2563 | } |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 2564 | HistoryPrinter hprinter = new HistoryPrinter(); |
| 2565 | while (getNextHistoryLocked(rec)) { |
| 2566 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 2567 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2568 | hprinter.printNextItem(pw, rec, now, true); |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 2569 | } |
| 2570 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2571 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2574 | if (historyOnly) { |
| 2575 | return; |
| 2576 | } |
| 2577 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2578 | if (apps != null) { |
| 2579 | SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); |
| 2580 | for (int i=0; i<apps.size(); i++) { |
| 2581 | ApplicationInfo ai = apps.get(i); |
| 2582 | ArrayList<String> pkgs = uids.get(ai.uid); |
| 2583 | if (pkgs == null) { |
| 2584 | pkgs = new ArrayList<String>(); |
| 2585 | uids.put(ai.uid, pkgs); |
| 2586 | } |
| 2587 | pkgs.add(ai.packageName); |
| 2588 | } |
| 2589 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 2590 | final int NU = uidStats.size(); |
| 2591 | String[] lineArgs = new String[2]; |
| 2592 | for (int i=0; i<NU; i++) { |
| 2593 | int uid = uidStats.keyAt(i); |
| 2594 | ArrayList<String> pkgs = uids.get(uid); |
| 2595 | if (pkgs != null) { |
| 2596 | for (int j=0; j<pkgs.size(); j++) { |
| 2597 | lineArgs[0] = Integer.toString(uid); |
| 2598 | lineArgs[1] = pkgs.get(j); |
| 2599 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 2600 | (Object[])lineArgs); |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| 2604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | if (isUnpluggedOnly) { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2606 | dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | } |
| 2608 | else { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2609 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); |
| 2610 | dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | } |
| 2612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | } |