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; |
| 20 | import java.util.Formatter; |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import android.util.Log; |
| 24 | import android.util.Printer; |
| 25 | import android.util.SparseArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 26 | import android.util.TimeUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * A class providing access to battery usage statistics, including information on |
| 30 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 31 | * except where indicated otherwise. |
| 32 | * @hide |
| 33 | */ |
| 34 | public abstract class BatteryStats implements Parcelable { |
| 35 | |
| 36 | private static final boolean LOCAL_LOGV = false; |
| 37 | |
| 38 | /** |
| 39 | * A constant indicating a partial wake lock timer. |
| 40 | */ |
| 41 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 42 | |
| 43 | /** |
| 44 | * A constant indicating a full wake lock timer. |
| 45 | */ |
| 46 | public static final int WAKE_TYPE_FULL = 1; |
| 47 | |
| 48 | /** |
| 49 | * A constant indicating a window wake lock timer. |
| 50 | */ |
| 51 | public static final int WAKE_TYPE_WINDOW = 2; |
| 52 | |
| 53 | /** |
| 54 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | */ |
| 56 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 59 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 60 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 61 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 64 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 65 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 66 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * A constant indicating a scan wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 70 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 71 | public static final int SCAN_WIFI_LOCK = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 73 | /** |
| 74 | * A constant indicating a wifi multicast timer |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 75 | */ |
| 76 | public static final int WIFI_MULTICAST_ENABLED = 7; |
| 77 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 79 | * A constant indicating an audio turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 80 | */ |
| 81 | public static final int AUDIO_TURNED_ON = 7; |
| 82 | |
| 83 | /** |
| 84 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 85 | */ |
| 86 | public static final int VIDEO_TURNED_ON = 8; |
| 87 | |
| 88 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | * Include all of the data in the stats, including previously saved data. |
| 90 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 91 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Include only the last run in the stats. |
| 95 | */ |
| 96 | public static final int STATS_LAST = 1; |
| 97 | |
| 98 | /** |
| 99 | * Include only the current run in the stats. |
| 100 | */ |
| 101 | public static final int STATS_CURRENT = 2; |
| 102 | |
| 103 | /** |
| 104 | * Include only the run since the last time the device was unplugged in the stats. |
| 105 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 106 | public static final int STATS_SINCE_UNPLUGGED = 3; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 107 | |
| 108 | // NOTE: Update this list if you add/change any stats above. |
| 109 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 110 | // and "unplugged". They were shortened for efficiency sake. |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 111 | 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] | 112 | |
| 113 | /** |
| 114 | * Bump the version on this if the checkin format changes. |
| 115 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 116 | private static final int BATTERY_STATS_CHECKIN_VERSION = 5; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 117 | |
| 118 | private static final long BYTES_PER_KB = 1024; |
| 119 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 120 | 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] | 121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
| 123 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 124 | private static final String PROCESS_DATA = "pr"; |
| 125 | private static final String SENSOR_DATA = "sr"; |
| 126 | private static final String WAKELOCK_DATA = "wl"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 127 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 128 | private static final String NETWORK_DATA = "nt"; |
| 129 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 130 | private static final String BATTERY_DATA = "bt"; |
| 131 | private static final String BATTERY_LEVEL_DATA = "lv"; |
| 132 | private static final String WIFI_LOCK_DATA = "wfl"; |
| 133 | private static final String MISC_DATA = "m"; |
| 134 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 135 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 136 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 137 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 138 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 139 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 141 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 143 | |
| 144 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 145 | * State for keeping track of counting information. |
| 146 | */ |
| 147 | public static abstract class Counter { |
| 148 | |
| 149 | /** |
| 150 | * Returns the count associated with this Counter for the |
| 151 | * selected type of statistics. |
| 152 | * |
| 153 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 154 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 155 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Temporary for debugging. |
| 159 | */ |
| 160 | public abstract void logState(Printer pw, String prefix); |
| 161 | } |
| 162 | |
| 163 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | * State for keeping track of timing information. |
| 165 | */ |
| 166 | public static abstract class Timer { |
| 167 | |
| 168 | /** |
| 169 | * Returns the count associated with this Timer for the |
| 170 | * selected type of statistics. |
| 171 | * |
| 172 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 173 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 174 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * Returns the total time in microseconds associated with this Timer for the |
| 178 | * selected type of statistics. |
| 179 | * |
| 180 | * @param batteryRealtime system realtime on battery in microseconds |
| 181 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 182 | * @return a time in microseconds |
| 183 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 184 | public abstract long getTotalTimeLocked(long batteryRealtime, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** |
| 187 | * Temporary for debugging. |
| 188 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 189 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
| 193 | * The statistics associated with a particular uid. |
| 194 | */ |
| 195 | public static abstract class Uid { |
| 196 | |
| 197 | /** |
| 198 | * Returns a mapping containing wakelock statistics. |
| 199 | * |
| 200 | * @return a Map from Strings to Uid.Wakelock objects. |
| 201 | */ |
| 202 | public abstract Map<String, ? extends Wakelock> getWakelockStats(); |
| 203 | |
| 204 | /** |
| 205 | * The statistics associated with a particular wake lock. |
| 206 | */ |
| 207 | public static abstract class Wakelock { |
| 208 | public abstract Timer getWakeTime(int type); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Returns a mapping containing sensor statistics. |
| 213 | * |
| 214 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 215 | */ |
| 216 | public abstract Map<Integer, ? extends Sensor> getSensorStats(); |
| 217 | |
| 218 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 219 | * Returns a mapping containing active process data. |
| 220 | */ |
| 221 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 222 | |
| 223 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | * Returns a mapping containing process statistics. |
| 225 | * |
| 226 | * @return a Map from Strings to Uid.Proc objects. |
| 227 | */ |
| 228 | public abstract Map<String, ? extends Proc> getProcessStats(); |
| 229 | |
| 230 | /** |
| 231 | * Returns a mapping containing package statistics. |
| 232 | * |
| 233 | * @return a Map from Strings to Uid.Pkg objects. |
| 234 | */ |
| 235 | public abstract Map<String, ? extends Pkg> getPackageStats(); |
| 236 | |
| 237 | /** |
| 238 | * {@hide} |
| 239 | */ |
| 240 | public abstract int getUid(); |
| 241 | |
| 242 | /** |
| 243 | * {@hide} |
| 244 | */ |
| 245 | public abstract long getTcpBytesReceived(int which); |
| 246 | |
| 247 | /** |
| 248 | * {@hide} |
| 249 | */ |
| 250 | public abstract long getTcpBytesSent(int which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 251 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 252 | public abstract void noteWifiRunningLocked(); |
| 253 | public abstract void noteWifiStoppedLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 254 | public abstract void noteFullWifiLockAcquiredLocked(); |
| 255 | public abstract void noteFullWifiLockReleasedLocked(); |
| 256 | public abstract void noteScanWifiLockAcquiredLocked(); |
| 257 | public abstract void noteScanWifiLockReleasedLocked(); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 258 | public abstract void noteWifiMulticastEnabledLocked(); |
| 259 | public abstract void noteWifiMulticastDisabledLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 260 | public abstract void noteAudioTurnedOnLocked(); |
| 261 | public abstract void noteAudioTurnedOffLocked(); |
| 262 | public abstract void noteVideoTurnedOnLocked(); |
| 263 | public abstract void noteVideoTurnedOffLocked(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 264 | public abstract long getWifiRunningTime(long batteryRealtime, int which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 265 | public abstract long getFullWifiLockTime(long batteryRealtime, int which); |
| 266 | public abstract long getScanWifiLockTime(long batteryRealtime, int which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 267 | public abstract long getWifiMulticastTime(long batteryRealtime, |
| 268 | int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 269 | public abstract long getAudioTurnedOnTime(long batteryRealtime, int which); |
| 270 | public abstract long getVideoTurnedOnTime(long batteryRealtime, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 272 | /** |
| 273 | * Note that these must match the constants in android.os.LocalPowerManager. |
| 274 | */ |
| 275 | static final String[] USER_ACTIVITY_TYPES = { |
| 276 | "other", "cheek", "touch", "long_touch", "touch_up", "button", "unknown" |
| 277 | }; |
| 278 | |
| 279 | public static final int NUM_USER_ACTIVITY_TYPES = 7; |
| 280 | |
| 281 | public abstract void noteUserActivityLocked(int type); |
| 282 | public abstract boolean hasUserActivity(); |
| 283 | public abstract int getUserActivityCount(int type, int which); |
| 284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | public static abstract class Sensor { |
| 286 | // Magic sensor number for the GPS. |
| 287 | public static final int GPS = -10000; |
| 288 | |
| 289 | public abstract int getHandle(); |
| 290 | |
| 291 | public abstract Timer getSensorTime(); |
| 292 | } |
| 293 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 294 | public class Pid { |
| 295 | public long mWakeSum; |
| 296 | public long mWakeStart; |
| 297 | } |
| 298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | /** |
| 300 | * The statistics associated with a particular process. |
| 301 | */ |
| 302 | public static abstract class Proc { |
| 303 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 304 | public static class ExcessiveWake { |
| 305 | public long overTime; |
| 306 | public long usedTime; |
| 307 | } |
| 308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Returns the total time (in 1/100 sec) spent executing in user code. |
| 311 | * |
| 312 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 313 | */ |
| 314 | public abstract long getUserTime(int which); |
| 315 | |
| 316 | /** |
| 317 | * Returns the total time (in 1/100 sec) spent executing in system code. |
| 318 | * |
| 319 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 320 | */ |
| 321 | public abstract long getSystemTime(int which); |
| 322 | |
| 323 | /** |
| 324 | * Returns the number of times the process has been started. |
| 325 | * |
| 326 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 327 | */ |
| 328 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 329 | |
| 330 | /** |
| 331 | * Returns the cpu time spent in microseconds while the process was in the foreground. |
| 332 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 333 | * @return foreground cpu time in microseconds |
| 334 | */ |
| 335 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Returns the approximate cpu time spent in microseconds, at a certain CPU speed. |
| 339 | * @param speedStep the index of the CPU speed. This is not the actual speed of the |
| 340 | * CPU. |
| 341 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 342 | * @see BatteryStats#getCpuSpeedSteps() |
| 343 | */ |
| 344 | public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 345 | |
| 346 | public abstract int countExcessiveWakes(); |
| 347 | |
| 348 | public abstract ExcessiveWake getExcessiveWake(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
| 352 | * The statistics associated with a particular package. |
| 353 | */ |
| 354 | public static abstract class Pkg { |
| 355 | |
| 356 | /** |
| 357 | * Returns the number of times this package has done something that could wake up the |
| 358 | * device from sleep. |
| 359 | * |
| 360 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 361 | */ |
| 362 | public abstract int getWakeups(int which); |
| 363 | |
| 364 | /** |
| 365 | * Returns a mapping containing service statistics. |
| 366 | */ |
| 367 | public abstract Map<String, ? extends Serv> getServiceStats(); |
| 368 | |
| 369 | /** |
| 370 | * The statistics associated with a particular service. |
| 371 | */ |
| 372 | public abstract class Serv { |
| 373 | |
| 374 | /** |
| 375 | * Returns the amount of time spent started. |
| 376 | * |
| 377 | * @param batteryUptime elapsed uptime on battery in microseconds. |
| 378 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 379 | * @return |
| 380 | */ |
| 381 | public abstract long getStartTime(long batteryUptime, int which); |
| 382 | |
| 383 | /** |
| 384 | * Returns the total number of times startService() has been called. |
| 385 | * |
| 386 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 387 | */ |
| 388 | public abstract int getStarts(int which); |
| 389 | |
| 390 | /** |
| 391 | * Returns the total number times the service has been launched. |
| 392 | * |
| 393 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 394 | */ |
| 395 | public abstract int getLaunches(int which); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame^] | 400 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 401 | public HistoryItem next; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 402 | |
| 403 | public long time; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 404 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 405 | public static final byte CMD_UPDATE = 0; |
| 406 | public static final byte CMD_START = 1; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 407 | public static final byte CMD_OVERFLOW = 2; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 408 | |
| 409 | public byte cmd; |
| 410 | |
| 411 | public byte batteryLevel; |
| 412 | public byte batteryStatus; |
| 413 | public byte batteryHealth; |
| 414 | public byte batteryPlugType; |
| 415 | |
| 416 | public char batteryTemperature; |
| 417 | public char batteryVoltage; |
| 418 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 419 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 420 | public static final int STATE_BRIGHTNESS_MASK = 0x000000f; |
| 421 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 422 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 423 | public static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0; |
| 424 | public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 425 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 426 | public static final int STATE_PHONE_STATE_MASK = 0x0000f00; |
| 427 | public static final int STATE_PHONE_STATE_SHIFT = 8; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 428 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 429 | public static final int STATE_DATA_CONNECTION_MASK = 0x000f000; |
| 430 | public static final int STATE_DATA_CONNECTION_SHIFT = 12; |
| 431 | |
| 432 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30; |
| 433 | public static final int STATE_SCREEN_ON_FLAG = 1<<29; |
| 434 | public static final int STATE_GPS_ON_FLAG = 1<<28; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 435 | public static final int STATE_PHONE_IN_CALL_FLAG = 1<<27; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 436 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<26; |
| 437 | public static final int STATE_WIFI_ON_FLAG = 1<<25; |
| 438 | public static final int STATE_WIFI_RUNNING_FLAG = 1<<24; |
| 439 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<23; |
| 440 | public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<22; |
| 441 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<21; |
| 442 | public static final int STATE_BLUETOOTH_ON_FLAG = 1<<20; |
| 443 | public static final int STATE_AUDIO_ON_FLAG = 1<<19; |
| 444 | public static final int STATE_VIDEO_ON_FLAG = 1<<18; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 445 | public static final int STATE_WAKE_LOCK_FLAG = 1<<17; |
| 446 | public static final int STATE_SENSOR_ON_FLAG = 1<<16; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 447 | |
| 448 | public int states; |
| 449 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 450 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 453 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 454 | this.time = time; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 455 | int bat = src.readInt(); |
| 456 | cmd = (byte)(bat&0xff); |
| 457 | batteryLevel = (byte)((bat>>8)&0xff); |
| 458 | batteryStatus = (byte)((bat>>16)&0xf); |
| 459 | batteryHealth = (byte)((bat>>20)&0xf); |
| 460 | batteryPlugType = (byte)((bat>>24)&0xf); |
| 461 | bat = src.readInt(); |
| 462 | batteryTemperature = (char)(bat&0xffff); |
| 463 | batteryVoltage = (char)((bat>>16)&0xffff); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 464 | states = src.readInt(); |
| 465 | } |
| 466 | |
| 467 | public int describeContents() { |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | public void writeToParcel(Parcel dest, int flags) { |
| 472 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 473 | int bat = (((int)cmd)&0xff) |
| 474 | | ((((int)batteryLevel)<<8)&0xff00) |
| 475 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 476 | | ((((int)batteryHealth)<<20)&0xf00000) |
| 477 | | ((((int)batteryPlugType)<<24)&0xf000000); |
| 478 | dest.writeInt(bat); |
| 479 | bat = (((int)batteryTemperature)&0xffff) |
| 480 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 481 | dest.writeInt(bat); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 482 | dest.writeInt(states); |
| 483 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 484 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame^] | 485 | public void setTo(HistoryItem o) { |
| 486 | time = o.time; |
| 487 | cmd = o.cmd; |
| 488 | batteryLevel = o.batteryLevel; |
| 489 | batteryStatus = o.batteryStatus; |
| 490 | batteryHealth = o.batteryHealth; |
| 491 | batteryPlugType = o.batteryPlugType; |
| 492 | batteryTemperature = o.batteryTemperature; |
| 493 | batteryVoltage = o.batteryVoltage; |
| 494 | states = o.states; |
| 495 | } |
| 496 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 497 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 498 | this.time = time; |
| 499 | this.cmd = cmd; |
| 500 | batteryLevel = o.batteryLevel; |
| 501 | batteryStatus = o.batteryStatus; |
| 502 | batteryHealth = o.batteryHealth; |
| 503 | batteryPlugType = o.batteryPlugType; |
| 504 | batteryTemperature = o.batteryTemperature; |
| 505 | batteryVoltage = o.batteryVoltage; |
| 506 | states = o.states; |
| 507 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 508 | |
| 509 | public boolean same(HistoryItem o) { |
| 510 | return batteryLevel == o.batteryLevel |
| 511 | && batteryStatus == o.batteryStatus |
| 512 | && batteryHealth == o.batteryHealth |
| 513 | && batteryPlugType == o.batteryPlugType |
| 514 | && batteryTemperature == o.batteryTemperature |
| 515 | && batteryVoltage == o.batteryVoltage |
| 516 | && states == o.states; |
| 517 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | public static final class BitDescription { |
| 521 | public final int mask; |
| 522 | public final int shift; |
| 523 | public final String name; |
| 524 | public final String[] values; |
| 525 | |
| 526 | public BitDescription(int mask, String name) { |
| 527 | this.mask = mask; |
| 528 | this.shift = -1; |
| 529 | this.name = name; |
| 530 | this.values = null; |
| 531 | } |
| 532 | |
| 533 | public BitDescription(int mask, int shift, String name, String[] values) { |
| 534 | this.mask = mask; |
| 535 | this.shift = shift; |
| 536 | this.name = name; |
| 537 | this.values = values; |
| 538 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame^] | 541 | public abstract boolean startIteratingHistoryLocked(); |
| 542 | |
| 543 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 544 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 545 | /** |
| 546 | * Return the current history of battery state changes. |
| 547 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 548 | public abstract HistoryItem getHistory(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 551 | * Return the base time offset for the battery history. |
| 552 | */ |
| 553 | public abstract long getHistoryBaseTime(); |
| 554 | |
| 555 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | * Returns the number of times the device has been started. |
| 557 | */ |
| 558 | public abstract int getStartCount(); |
| 559 | |
| 560 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 561 | * 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] | 562 | * running on battery. |
| 563 | * |
| 564 | * {@hide} |
| 565 | */ |
| 566 | public abstract long getScreenOnTime(long batteryRealtime, int which); |
| 567 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 568 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 569 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 570 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 571 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 572 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 573 | |
| 574 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 575 | "dark", "dim", "medium", "light", "bright" |
| 576 | }; |
| 577 | |
| 578 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
| 579 | |
| 580 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 581 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 582 | * the given brightness |
| 583 | * |
| 584 | * {@hide} |
| 585 | */ |
| 586 | public abstract long getScreenBrightnessTime(int brightnessBin, |
| 587 | long batteryRealtime, int which); |
| 588 | |
| 589 | public abstract int getInputEventCount(int which); |
| 590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 592 | * 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] | 593 | * running on battery. |
| 594 | * |
| 595 | * {@hide} |
| 596 | */ |
| 597 | public abstract long getPhoneOnTime(long batteryRealtime, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 598 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 599 | public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; |
| 600 | public static final int SIGNAL_STRENGTH_POOR = 1; |
| 601 | public static final int SIGNAL_STRENGTH_MODERATE = 2; |
| 602 | public static final int SIGNAL_STRENGTH_GOOD = 3; |
| 603 | public static final int SIGNAL_STRENGTH_GREAT = 4; |
| 604 | |
| 605 | static final String[] SIGNAL_STRENGTH_NAMES = { |
| 606 | "none", "poor", "moderate", "good", "great" |
| 607 | }; |
| 608 | |
| 609 | public static final int NUM_SIGNAL_STRENGTH_BINS = 5; |
| 610 | |
| 611 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 612 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 613 | * the given signal strength. |
| 614 | * |
| 615 | * {@hide} |
| 616 | */ |
| 617 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
| 618 | long batteryRealtime, int which); |
| 619 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 620 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 621 | * Returns the time in microseconds that the phone has been trying to |
| 622 | * acquire a signal. |
| 623 | * |
| 624 | * {@hide} |
| 625 | */ |
| 626 | public abstract long getPhoneSignalScanningTime( |
| 627 | long batteryRealtime, int which); |
| 628 | |
| 629 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 630 | * Returns the number of times the phone has entered the given signal strength. |
| 631 | * |
| 632 | * {@hide} |
| 633 | */ |
| 634 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 635 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 636 | public static final int DATA_CONNECTION_NONE = 0; |
| 637 | public static final int DATA_CONNECTION_GPRS = 1; |
| 638 | public static final int DATA_CONNECTION_EDGE = 2; |
| 639 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 640 | public static final int DATA_CONNECTION_CDMA = 4; |
| 641 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 642 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 643 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 644 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 645 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 646 | public static final int DATA_CONNECTION_HSPA = 10; |
| 647 | public static final int DATA_CONNECTION_IDEN = 11; |
| 648 | public static final int DATA_CONNECTION_EVDO_B = 12; |
| 649 | public static final int DATA_CONNECTION_OTHER = 13; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 650 | |
| 651 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 652 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
| 653 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 654 | }; |
| 655 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 656 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 657 | |
| 658 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 659 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 660 | * the given data connection. |
| 661 | * |
| 662 | * {@hide} |
| 663 | */ |
| 664 | public abstract long getPhoneDataConnectionTime(int dataType, |
| 665 | long batteryRealtime, int which); |
| 666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 668 | * Returns the number of times the phone has entered the given data |
| 669 | * connection type. |
| 670 | * |
| 671 | * {@hide} |
| 672 | */ |
| 673 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 674 | |
| 675 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 676 | = new BitDescription[] { |
| 677 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged"), |
| 678 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen"), |
| 679 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps"), |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 680 | new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call"), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 681 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning"), |
| 682 | new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi"), |
| 683 | new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running"), |
| 684 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"), |
| 685 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_LOCK_FLAG, "wifi_scan_lock"), |
| 686 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"), |
| 687 | new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"), |
| 688 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"), |
| 689 | new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"), |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 690 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"), |
| 691 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 692 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 693 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", |
| 694 | SCREEN_BRIGHTNESS_NAMES), |
| 695 | new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK, |
| 696 | HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", |
| 697 | SIGNAL_STRENGTH_NAMES), |
| 698 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 699 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", |
| 700 | new String[] {"in", "out", "emergency", "off"}), |
| 701 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 702 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", |
| 703 | DATA_CONNECTION_NAMES), |
| 704 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 705 | |
| 706 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 707 | * 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] | 708 | * running on battery. |
| 709 | * |
| 710 | * {@hide} |
| 711 | */ |
| 712 | public abstract long getWifiOnTime(long batteryRealtime, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 713 | |
| 714 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 715 | * 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] | 716 | * been in the running state while the device was running on battery. |
| 717 | * |
| 718 | * {@hide} |
| 719 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 720 | public abstract long getGlobalWifiRunningTime(long batteryRealtime, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 721 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 722 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 723 | * 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] | 724 | * running on battery. |
| 725 | * |
| 726 | * {@hide} |
| 727 | */ |
| 728 | public abstract long getBluetoothOnTime(long batteryRealtime, int which); |
| 729 | |
| 730 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | * Return whether we are currently running on battery. |
| 732 | */ |
| 733 | public abstract boolean getIsOnBattery(); |
| 734 | |
| 735 | /** |
| 736 | * Returns a SparseArray containing the statistics for each uid. |
| 737 | */ |
| 738 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 739 | |
| 740 | /** |
| 741 | * Returns the current battery uptime in microseconds. |
| 742 | * |
| 743 | * @param curTime the amount of elapsed realtime in microseconds. |
| 744 | */ |
| 745 | public abstract long getBatteryUptime(long curTime); |
| 746 | |
| 747 | /** |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 748 | * @deprecated use getRadioDataUptime |
| 749 | */ |
| 750 | public long getRadioDataUptimeMs() { |
| 751 | return getRadioDataUptime() / 1000; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Returns the time that the radio was on for data transfers. |
| 756 | * @return the uptime in microseconds while unplugged |
| 757 | */ |
| 758 | public abstract long getRadioDataUptime(); |
| 759 | |
| 760 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | * Returns the current battery realtime in microseconds. |
| 762 | * |
| 763 | * @param curTime the amount of elapsed realtime in microseconds. |
| 764 | */ |
| 765 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 766 | |
| 767 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 768 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 769 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 770 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 771 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 772 | |
| 773 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 774 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 775 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 776 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 777 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | |
| 779 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 780 | * Get the amount the battery has discharged since the stats were |
| 781 | * last reset after charging, as a lower-end approximation. |
| 782 | */ |
| 783 | public abstract int getLowDischargeAmountSinceCharge(); |
| 784 | |
| 785 | /** |
| 786 | * Get the amount the battery has discharged since the stats were |
| 787 | * last reset after charging, as an upper-end approximation. |
| 788 | */ |
| 789 | public abstract int getHighDischargeAmountSinceCharge(); |
| 790 | |
| 791 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | * Returns the total, last, or current battery uptime in microseconds. |
| 793 | * |
| 794 | * @param curTime the elapsed realtime in microseconds. |
| 795 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 796 | */ |
| 797 | public abstract long computeBatteryUptime(long curTime, int which); |
| 798 | |
| 799 | /** |
| 800 | * Returns the total, last, or current battery realtime in microseconds. |
| 801 | * |
| 802 | * @param curTime the current elapsed realtime in microseconds. |
| 803 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 804 | */ |
| 805 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 806 | |
| 807 | /** |
| 808 | * Returns the total, last, or current uptime in microseconds. |
| 809 | * |
| 810 | * @param curTime the current elapsed realtime in microseconds. |
| 811 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 812 | */ |
| 813 | public abstract long computeUptime(long curTime, int which); |
| 814 | |
| 815 | /** |
| 816 | * Returns the total, last, or current realtime in microseconds. |
| 817 | * * |
| 818 | * @param curTime the current elapsed realtime in microseconds. |
| 819 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 820 | */ |
| 821 | public abstract long computeRealtime(long curTime, int which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 822 | |
| 823 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 825 | /** Returns the number of different speeds that the CPU can run at */ |
| 826 | public abstract int getCpuSpeedSteps(); |
| 827 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 828 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | long days = seconds / (60 * 60 * 24); |
| 830 | if (days != 0) { |
| 831 | out.append(days); |
| 832 | out.append("d "); |
| 833 | } |
| 834 | long used = days * 60 * 60 * 24; |
| 835 | |
| 836 | long hours = (seconds - used) / (60 * 60); |
| 837 | if (hours != 0 || used != 0) { |
| 838 | out.append(hours); |
| 839 | out.append("h "); |
| 840 | } |
| 841 | used += hours * 60 * 60; |
| 842 | |
| 843 | long mins = (seconds-used) / 60; |
| 844 | if (mins != 0 || used != 0) { |
| 845 | out.append(mins); |
| 846 | out.append("m "); |
| 847 | } |
| 848 | used += mins * 60; |
| 849 | |
| 850 | if (seconds != 0 || used != 0) { |
| 851 | out.append(seconds-used); |
| 852 | out.append("s "); |
| 853 | } |
| 854 | } |
| 855 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 856 | private final static void formatTime(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | long sec = time / 100; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 858 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | sb.append((time - (sec * 100)) * 10); |
| 860 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 863 | private final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 865 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | sb.append(time - (sec * 1000)); |
| 867 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | private final String formatRatioLocked(long num, long den) { |
| 871 | if (den == 0L) { |
| 872 | return "---%"; |
| 873 | } |
| 874 | float perc = ((float)num) / ((float)den) * 100; |
| 875 | mFormatBuilder.setLength(0); |
| 876 | mFormatter.format("%.1f%%", perc); |
| 877 | return mFormatBuilder.toString(); |
| 878 | } |
| 879 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 880 | private final String formatBytesLocked(long bytes) { |
| 881 | mFormatBuilder.setLength(0); |
| 882 | |
| 883 | if (bytes < BYTES_PER_KB) { |
| 884 | return bytes + "B"; |
| 885 | } else if (bytes < BYTES_PER_MB) { |
| 886 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 887 | return mFormatBuilder.toString(); |
| 888 | } else if (bytes < BYTES_PER_GB){ |
| 889 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 890 | return mFormatBuilder.toString(); |
| 891 | } else { |
| 892 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 893 | return mFormatBuilder.toString(); |
| 894 | } |
| 895 | } |
| 896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | /** |
| 898 | * |
| 899 | * @param sb a StringBuilder object. |
| 900 | * @param timer a Timer object contining the wakelock times. |
| 901 | * @param batteryRealtime the current on-battery time in microseconds. |
| 902 | * @param name the name of the wakelock. |
| 903 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 904 | * @param linePrefix a String to be prepended to each line of output. |
| 905 | * @return the line prefix |
| 906 | */ |
| 907 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
| 908 | long batteryRealtime, String name, int which, String linePrefix) { |
| 909 | |
| 910 | if (timer != null) { |
| 911 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 912 | long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 914 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 915 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | if (totalTimeMillis != 0) { |
| 917 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 918 | formatTimeMs(sb, totalTimeMillis); |
| 919 | if (name != null) sb.append(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | sb.append(' '); |
| 921 | sb.append('('); |
| 922 | sb.append(count); |
| 923 | sb.append(" times)"); |
| 924 | return ", "; |
| 925 | } |
| 926 | } |
| 927 | return linePrefix; |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 932 | * |
| 933 | * @param sb a StringBuilder object. |
| 934 | * @param timer a Timer object contining the wakelock times. |
| 935 | * @param now the current time in microseconds. |
| 936 | * @param name the name of the wakelock. |
| 937 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 938 | * @param linePrefix a String to be prepended to each line of output. |
| 939 | * @return the line prefix |
| 940 | */ |
| 941 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 942 | String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | long totalTimeMicros = 0; |
| 944 | int count = 0; |
| 945 | if (timer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 946 | totalTimeMicros = timer.getTotalTimeLocked(now, which); |
| 947 | count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | } |
| 949 | sb.append(linePrefix); |
| 950 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 951 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 952 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | sb.append(count); |
| 954 | return ","; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Dump a comma-separated line of values for terse checkin mode. |
| 959 | * |
| 960 | * @param pw the PageWriter to dump log to |
| 961 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 962 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 963 | * @param args type-dependent data arguments |
| 964 | */ |
| 965 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 966 | Object... args ) { |
| 967 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 968 | pw.print(uid); pw.print(','); |
| 969 | pw.print(category); pw.print(','); |
| 970 | pw.print(type); |
| 971 | |
| 972 | for (Object arg : args) { |
| 973 | pw.print(','); |
| 974 | pw.print(arg); |
| 975 | } |
| 976 | pw.print('\n'); |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 981 | * |
| 982 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | */ |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 984 | public final void dumpCheckinLocked(PrintWriter pw, int which, int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 986 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 987 | final long batteryUptime = getBatteryUptime(rawUptime); |
| 988 | final long batteryRealtime = getBatteryRealtime(rawRealtime); |
| 989 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 990 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 991 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 992 | final long totalUptime = computeUptime(rawUptime, which); |
| 993 | final long screenOnTime = getScreenOnTime(batteryRealtime, which); |
| 994 | final long phoneOnTime = getPhoneOnTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 995 | final long wifiOnTime = getWifiOnTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 996 | final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 997 | final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | |
| 999 | StringBuilder sb = new StringBuilder(128); |
| 1000 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1001 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1002 | final int NU = uidStats.size(); |
| 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | String category = STAT_NAMES[which]; |
| 1005 | |
| 1006 | // Dump "battery" stat |
| 1007 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1008 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1009 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
| 1010 | totalRealtime / 1000, totalUptime / 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1012 | // Calculate total network and wakelock times across all uids. |
| 1013 | long rxTotal = 0; |
| 1014 | long txTotal = 0; |
| 1015 | long fullWakeLockTimeTotal = 0; |
| 1016 | long partialWakeLockTimeTotal = 0; |
| 1017 | |
| 1018 | for (int iu = 0; iu < NU; iu++) { |
| 1019 | Uid u = uidStats.valueAt(iu); |
| 1020 | rxTotal += u.getTcpBytesReceived(which); |
| 1021 | txTotal += u.getTcpBytesSent(which); |
| 1022 | |
| 1023 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1024 | if (wakelocks.size() > 0) { |
| 1025 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1026 | : wakelocks.entrySet()) { |
| 1027 | Uid.Wakelock wl = ent.getValue(); |
| 1028 | |
| 1029 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 1030 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1031 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 1035 | if (partialWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1036 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1037 | batteryRealtime, which); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | // Dump misc stats |
| 1044 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1045 | screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1046 | wifiRunningTime / 1000, bluetoothOnTime / 1000, rxTotal, txTotal, |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1047 | fullWakeLockTimeTotal, partialWakeLockTimeTotal, |
| 1048 | getInputEventCount(which)); |
| 1049 | |
| 1050 | // Dump screen brightness stats |
| 1051 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 1052 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 1053 | args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000; |
| 1054 | } |
| 1055 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1056 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1057 | // Dump signal strength stats |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1058 | args = new Object[NUM_SIGNAL_STRENGTH_BINS]; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1059 | for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 1060 | args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000; |
| 1061 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1062 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1063 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
| 1064 | getPhoneSignalScanningTime(batteryRealtime, which) / 1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1065 | for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 1066 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 1067 | } |
| 1068 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1069 | |
| 1070 | // Dump network type stats |
| 1071 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 1072 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1073 | args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000; |
| 1074 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1075 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 1076 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1077 | args[i] = getPhoneDataConnectionCount(i, which); |
| 1078 | } |
| 1079 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1080 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1081 | if (which == STATS_SINCE_UNPLUGGED) { |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 1082 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1083 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1084 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1086 | if (reqUid < 0) { |
| 1087 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 1088 | if (kernelWakelocks.size() > 0) { |
| 1089 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
| 1090 | sb.setLength(0); |
| 1091 | printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, ""); |
| 1092 | |
| 1093 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
| 1094 | sb.toString()); |
| 1095 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | for (int iu = 0; iu < NU; iu++) { |
| 1100 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1101 | if (reqUid >= 0 && uid != reqUid) { |
| 1102 | continue; |
| 1103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | Uid u = uidStats.valueAt(iu); |
| 1105 | // Dump Network stats per uid, if any |
| 1106 | long rx = u.getTcpBytesReceived(which); |
| 1107 | long tx = u.getTcpBytesSent(which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1108 | long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which); |
| 1109 | long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1110 | long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | if (rx > 0 || tx > 0) dumpLine(pw, uid, category, NETWORK_DATA, rx, tx); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1113 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1114 | if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1115 | || uidWifiRunningTime != 0) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1116 | dumpLine(pw, uid, category, WIFI_LOCK_DATA, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1117 | fullWifiLockOnTime, scanWifiLockOnTime, uidWifiRunningTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1120 | if (u.hasUserActivity()) { |
| 1121 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 1122 | boolean hasData = false; |
| 1123 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 1124 | int val = u.getUserActivityCount(i, which); |
| 1125 | args[i] = val; |
| 1126 | if (val != 0) hasData = true; |
| 1127 | } |
| 1128 | if (hasData) { |
| 1129 | dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args); |
| 1130 | } |
| 1131 | } |
| 1132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1134 | if (wakelocks.size() > 0) { |
| 1135 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1136 | : wakelocks.entrySet()) { |
| 1137 | Uid.Wakelock wl = ent.getValue(); |
| 1138 | String linePrefix = ""; |
| 1139 | sb.setLength(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1140 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 1141 | batteryRealtime, "f", which, linePrefix); |
| 1142 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 1143 | batteryRealtime, "p", which, linePrefix); |
| 1144 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 1145 | batteryRealtime, "w", which, linePrefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | |
| 1147 | // Only log if we had at lease one wakelock... |
| 1148 | if (sb.length() > 0) { |
| 1149 | dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString()); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 1155 | if (sensors.size() > 0) { |
| 1156 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 1157 | : sensors.entrySet()) { |
| 1158 | Uid.Sensor se = ent.getValue(); |
| 1159 | int sensorNumber = ent.getKey(); |
| 1160 | Timer timer = se.getSensorTime(); |
| 1161 | if (timer != null) { |
| 1162 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1163 | long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000; |
| 1164 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | if (totalTime != 0) { |
| 1166 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count); |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 1173 | if (processStats.size() > 0) { |
| 1174 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 1175 | : processStats.entrySet()) { |
| 1176 | Uid.Proc ps = ent.getValue(); |
| 1177 | |
| 1178 | long userTime = ps.getUserTime(which); |
| 1179 | long systemTime = ps.getSystemTime(which); |
| 1180 | int starts = ps.getStarts(which); |
| 1181 | |
| 1182 | if (userTime != 0 || systemTime != 0 || starts != 0) { |
| 1183 | dumpLine(pw, uid, category, PROCESS_DATA, |
| 1184 | ent.getKey(), // proc |
| 1185 | userTime * 10, // cpu time in ms |
| 1186 | systemTime * 10, // user time in ms |
| 1187 | starts); // process starts |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 1193 | if (packageStats.size() > 0) { |
| 1194 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 1195 | : packageStats.entrySet()) { |
| 1196 | |
| 1197 | Uid.Pkg ps = ent.getValue(); |
| 1198 | int wakeups = ps.getWakeups(which); |
| 1199 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 1200 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 1201 | : serviceStats.entrySet()) { |
| 1202 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 1203 | long startTime = ss.getStartTime(batteryUptime, which); |
| 1204 | int starts = ss.getStarts(which); |
| 1205 | int launches = ss.getLaunches(which); |
| 1206 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 1207 | dumpLine(pw, uid, category, APK_DATA, |
| 1208 | wakeups, // wakeup alarms |
| 1209 | ent.getKey(), // Apk |
| 1210 | sent.getKey(), // service |
| 1211 | startTime / 1000, // time spent started, in ms |
| 1212 | starts, |
| 1213 | launches); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | @SuppressWarnings("unused") |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1222 | public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 1224 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 1225 | final long batteryUptime = getBatteryUptime(rawUptime); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1226 | final long batteryRealtime = getBatteryRealtime(rawRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | |
| 1228 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 1229 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 1230 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 1231 | final long totalUptime = computeUptime(rawUptime, which); |
| 1232 | |
| 1233 | StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1234 | |
| 1235 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1236 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1238 | sb.setLength(0); |
| 1239 | sb.append(prefix); |
| 1240 | sb.append(" Time on battery: "); |
| 1241 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 1242 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 1243 | sb.append(") realtime, "); |
| 1244 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 1245 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 1246 | sb.append(") uptime"); |
| 1247 | pw.println(sb.toString()); |
| 1248 | sb.setLength(0); |
| 1249 | sb.append(prefix); |
| 1250 | sb.append(" Total run time: "); |
| 1251 | formatTimeMs(sb, totalRealtime / 1000); |
| 1252 | sb.append("realtime, "); |
| 1253 | formatTimeMs(sb, totalUptime / 1000); |
| 1254 | sb.append("uptime, "); |
| 1255 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1257 | final long screenOnTime = getScreenOnTime(batteryRealtime, which); |
| 1258 | final long phoneOnTime = getPhoneOnTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1259 | final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1260 | final long wifiOnTime = getWifiOnTime(batteryRealtime, which); |
| 1261 | final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1262 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1263 | sb.append(prefix); |
| 1264 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 1265 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
| 1266 | sb.append("), Input events: "); sb.append(getInputEventCount(which)); |
| 1267 | sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 1268 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
| 1269 | sb.append(")"); |
| 1270 | pw.println(sb.toString()); |
| 1271 | sb.setLength(0); |
| 1272 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1273 | sb.append(" Screen brightnesses: "); |
| 1274 | boolean didOne = false; |
| 1275 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 1276 | final long time = getScreenBrightnessTime(i, batteryRealtime, which); |
| 1277 | if (time == 0) { |
| 1278 | continue; |
| 1279 | } |
| 1280 | if (didOne) sb.append(", "); |
| 1281 | didOne = true; |
| 1282 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 1283 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1284 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1285 | sb.append("("); |
| 1286 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 1287 | sb.append(")"); |
| 1288 | } |
| 1289 | if (!didOne) sb.append("No activity"); |
| 1290 | pw.println(sb.toString()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1291 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1292 | // Calculate total network and wakelock times across all uids. |
| 1293 | long rxTotal = 0; |
| 1294 | long txTotal = 0; |
| 1295 | long fullWakeLockTimeTotalMicros = 0; |
| 1296 | long partialWakeLockTimeTotalMicros = 0; |
| 1297 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1298 | if (reqUid < 0) { |
| 1299 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 1300 | if (kernelWakelocks.size() > 0) { |
| 1301 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
| 1302 | |
| 1303 | String linePrefix = ": "; |
| 1304 | sb.setLength(0); |
| 1305 | sb.append(prefix); |
| 1306 | sb.append(" Kernel Wake lock "); |
| 1307 | sb.append(ent.getKey()); |
| 1308 | linePrefix = printWakeLock(sb, ent.getValue(), batteryRealtime, null, which, |
| 1309 | linePrefix); |
| 1310 | if (!linePrefix.equals(": ")) { |
| 1311 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 1312 | // Only print out wake locks that were held |
| 1313 | pw.println(sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1314 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1315 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1319 | for (int iu = 0; iu < NU; iu++) { |
| 1320 | Uid u = uidStats.valueAt(iu); |
| 1321 | rxTotal += u.getTcpBytesReceived(which); |
| 1322 | txTotal += u.getTcpBytesSent(which); |
| 1323 | |
| 1324 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1325 | if (wakelocks.size() > 0) { |
| 1326 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1327 | : wakelocks.entrySet()) { |
| 1328 | Uid.Wakelock wl = ent.getValue(); |
| 1329 | |
| 1330 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 1331 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1332 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1333 | batteryRealtime, which); |
| 1334 | } |
| 1335 | |
| 1336 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 1337 | if (partialWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1338 | partialWakeLockTimeTotalMicros += partialWakeTimer.getTotalTimeLocked( |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1339 | batteryRealtime, which); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1345 | pw.print(prefix); |
| 1346 | pw.print(" Total received: "); pw.print(formatBytesLocked(rxTotal)); |
| 1347 | pw.print(", Total sent: "); pw.println(formatBytesLocked(txTotal)); |
| 1348 | sb.setLength(0); |
| 1349 | sb.append(prefix); |
| 1350 | sb.append(" Total full wakelock time: "); formatTimeMs(sb, |
| 1351 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 1352 | sb.append(", Total partial waklock time: "); formatTimeMs(sb, |
| 1353 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 1354 | pw.println(sb.toString()); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1355 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1356 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1357 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1358 | sb.append(" Signal levels: "); |
| 1359 | didOne = false; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1360 | for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 1361 | final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which); |
| 1362 | if (time == 0) { |
| 1363 | continue; |
| 1364 | } |
| 1365 | if (didOne) sb.append(", "); |
| 1366 | didOne = true; |
| 1367 | sb.append(SIGNAL_STRENGTH_NAMES[i]); |
| 1368 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1369 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1370 | sb.append("("); |
| 1371 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1372 | sb.append(") "); |
| 1373 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 1374 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1375 | } |
| 1376 | if (!didOne) sb.append("No activity"); |
| 1377 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1378 | |
| 1379 | sb.setLength(0); |
| 1380 | sb.append(prefix); |
| 1381 | sb.append(" Signal scanning time: "); |
| 1382 | formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000); |
| 1383 | pw.println(sb.toString()); |
| 1384 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1385 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1386 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1387 | sb.append(" Radio types: "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1388 | didOne = false; |
| 1389 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1390 | final long time = getPhoneDataConnectionTime(i, batteryRealtime, which); |
| 1391 | if (time == 0) { |
| 1392 | continue; |
| 1393 | } |
| 1394 | if (didOne) sb.append(", "); |
| 1395 | didOne = true; |
| 1396 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 1397 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1398 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1399 | sb.append("("); |
| 1400 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1401 | sb.append(") "); |
| 1402 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 1403 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1404 | } |
| 1405 | if (!didOne) sb.append("No activity"); |
| 1406 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1407 | |
| 1408 | sb.setLength(0); |
| 1409 | sb.append(prefix); |
| 1410 | sb.append(" Radio data uptime when unplugged: "); |
| 1411 | sb.append(getRadioDataUptime() / 1000); |
| 1412 | sb.append(" ms"); |
| 1413 | pw.println(sb.toString()); |
| 1414 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1415 | sb.setLength(0); |
| 1416 | sb.append(prefix); |
| 1417 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 1418 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 1419 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 1420 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
| 1421 | sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000); |
| 1422 | sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)); |
| 1423 | sb.append(")"); |
| 1424 | pw.println(sb.toString()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1425 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1426 | pw.println(" "); |
| 1427 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1428 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1429 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1430 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 1431 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 1432 | pw.println(getDischargeStartLevel()); |
| 1433 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 1434 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 1435 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1436 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 1437 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 1438 | pw.println(getDischargeStartLevel()); |
| 1439 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 1440 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1441 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1442 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1443 | } else { |
| 1444 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 1445 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 1446 | pw.println(getLowDischargeAmountSinceCharge()); |
| 1447 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 1448 | pw.println(getHighDischargeAmountSinceCharge()); |
| 1449 | pw.println(" "); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1450 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | for (int iu=0; iu<NU; iu++) { |
| 1454 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1455 | if (reqUid >= 0 && uid != reqUid) { |
| 1456 | continue; |
| 1457 | } |
| 1458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | pw.println(prefix + " #" + uid + ":"); |
| 1462 | boolean uidActivity = false; |
| 1463 | |
| 1464 | long tcpReceived = u.getTcpBytesReceived(which); |
| 1465 | long tcpSent = u.getTcpBytesSent(which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1466 | long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which); |
| 1467 | long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1468 | long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | if (tcpReceived != 0 || tcpSent != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1471 | pw.print(prefix); pw.print(" Network: "); |
| 1472 | pw.print(formatBytesLocked(tcpReceived)); pw.print(" received, "); |
| 1473 | pw.print(formatBytesLocked(tcpSent)); pw.println(" sent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1475 | |
| 1476 | if (u.hasUserActivity()) { |
| 1477 | boolean hasData = false; |
| 1478 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 1479 | int val = u.getUserActivityCount(i, which); |
| 1480 | if (val != 0) { |
| 1481 | if (!hasData) { |
| 1482 | sb.setLength(0); |
| 1483 | sb.append(" User activity: "); |
| 1484 | hasData = true; |
| 1485 | } else { |
| 1486 | sb.append(", "); |
| 1487 | } |
| 1488 | sb.append(val); |
| 1489 | sb.append(" "); |
| 1490 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 1491 | } |
| 1492 | } |
| 1493 | if (hasData) { |
| 1494 | pw.println(sb.toString()); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1499 | || uidWifiRunningTime != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1500 | sb.setLength(0); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1501 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 1502 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 1503 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1504 | whichBatteryRealtime)); sb.append(")\n"); |
| 1505 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 1506 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 1507 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 1508 | whichBatteryRealtime)); sb.append(")\n"); |
| 1509 | sb.append(prefix); sb.append(" Scan Wifi Lock: "); |
| 1510 | formatTimeMs(sb, scanWifiLockOnTime / 1000); |
| 1511 | sb.append("("); sb.append(formatRatioLocked(scanWifiLockOnTime, |
| 1512 | whichBatteryRealtime)); sb.append(")"); |
| 1513 | pw.println(sb.toString()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1514 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | |
| 1516 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1517 | if (wakelocks.size() > 0) { |
| 1518 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1519 | : wakelocks.entrySet()) { |
| 1520 | Uid.Wakelock wl = ent.getValue(); |
| 1521 | String linePrefix = ": "; |
| 1522 | sb.setLength(0); |
| 1523 | sb.append(prefix); |
| 1524 | sb.append(" Wake lock "); |
| 1525 | sb.append(ent.getKey()); |
| 1526 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime, |
| 1527 | "full", which, linePrefix); |
| 1528 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime, |
| 1529 | "partial", which, linePrefix); |
| 1530 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime, |
| 1531 | "window", which, linePrefix); |
| 1532 | if (!linePrefix.equals(": ")) { |
| 1533 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 1534 | // Only print out wake locks that were held |
| 1535 | pw.println(sb.toString()); |
| 1536 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 1542 | if (sensors.size() > 0) { |
| 1543 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 1544 | : sensors.entrySet()) { |
| 1545 | Uid.Sensor se = ent.getValue(); |
| 1546 | int sensorNumber = ent.getKey(); |
| 1547 | sb.setLength(0); |
| 1548 | sb.append(prefix); |
| 1549 | sb.append(" Sensor "); |
| 1550 | int handle = se.getHandle(); |
| 1551 | if (handle == Uid.Sensor.GPS) { |
| 1552 | sb.append("GPS"); |
| 1553 | } else { |
| 1554 | sb.append(handle); |
| 1555 | } |
| 1556 | sb.append(": "); |
| 1557 | |
| 1558 | Timer timer = se.getSensorTime(); |
| 1559 | if (timer != null) { |
| 1560 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1561 | long totalTime = (timer.getTotalTimeLocked( |
| 1562 | batteryRealtime, which) + 500) / 1000; |
| 1563 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | //timer.logState(); |
| 1565 | if (totalTime != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1566 | formatTimeMs(sb, totalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | sb.append("realtime ("); |
| 1568 | sb.append(count); |
| 1569 | sb.append(" times)"); |
| 1570 | } else { |
| 1571 | sb.append("(not used)"); |
| 1572 | } |
| 1573 | } else { |
| 1574 | sb.append("(not used)"); |
| 1575 | } |
| 1576 | |
| 1577 | pw.println(sb.toString()); |
| 1578 | uidActivity = true; |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 1583 | if (processStats.size() > 0) { |
| 1584 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 1585 | : processStats.entrySet()) { |
| 1586 | Uid.Proc ps = ent.getValue(); |
| 1587 | long userTime; |
| 1588 | long systemTime; |
| 1589 | int starts; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1590 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | |
| 1592 | userTime = ps.getUserTime(which); |
| 1593 | systemTime = ps.getSystemTime(which); |
| 1594 | starts = ps.getStarts(which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1595 | numExcessive = which == STATS_SINCE_CHARGED |
| 1596 | ? ps.countExcessiveWakes() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1598 | if (userTime != 0 || systemTime != 0 || starts != 0 |
| 1599 | || numExcessive != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1600 | sb.setLength(0); |
| 1601 | sb.append(prefix); sb.append(" Proc "); |
| 1602 | sb.append(ent.getKey()); sb.append(":\n"); |
| 1603 | sb.append(prefix); sb.append(" CPU: "); |
| 1604 | formatTime(sb, userTime); sb.append("usr + "); |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 1605 | formatTime(sb, systemTime); sb.append("krn"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1606 | if (starts != 0) { |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 1607 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 1608 | sb.append(starts); sb.append(" proc starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1609 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1610 | pw.println(sb.toString()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1611 | for (int e=0; e<numExcessive; e++) { |
| 1612 | Uid.Proc.ExcessiveWake ew = ps.getExcessiveWake(e); |
| 1613 | if (ew != null) { |
| 1614 | pw.print(prefix); pw.print(" * Killed for wake lock use: "); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 1615 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 1616 | pw.print(" over "); |
| 1617 | TimeUtils.formatDuration(ew.overTime, pw); |
| 1618 | pw.print(" ("); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1619 | pw.print((ew.usedTime*100)/ew.overTime); |
| 1620 | pw.println("%)"); |
| 1621 | } |
| 1622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | uidActivity = true; |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 1629 | if (packageStats.size() > 0) { |
| 1630 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 1631 | : packageStats.entrySet()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1632 | 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] | 1633 | boolean apkActivity = false; |
| 1634 | Uid.Pkg ps = ent.getValue(); |
| 1635 | int wakeups = ps.getWakeups(which); |
| 1636 | if (wakeups != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1637 | pw.print(prefix); pw.print(" "); |
| 1638 | pw.print(wakeups); pw.println(" wakeup alarms"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | apkActivity = true; |
| 1640 | } |
| 1641 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 1642 | if (serviceStats.size() > 0) { |
| 1643 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 1644 | : serviceStats.entrySet()) { |
| 1645 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 1646 | long startTime = ss.getStartTime(batteryUptime, which); |
| 1647 | int starts = ss.getStarts(which); |
| 1648 | int launches = ss.getLaunches(which); |
| 1649 | if (startTime != 0 || starts != 0 || launches != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1650 | sb.setLength(0); |
| 1651 | sb.append(prefix); sb.append(" Service "); |
| 1652 | sb.append(sent.getKey()); sb.append(":\n"); |
| 1653 | sb.append(prefix); sb.append(" Created for: "); |
| 1654 | formatTimeMs(sb, startTime / 1000); |
| 1655 | sb.append(" uptime\n"); |
| 1656 | sb.append(prefix); sb.append(" Starts: "); |
| 1657 | sb.append(starts); |
| 1658 | sb.append(", launches: "); sb.append(launches); |
| 1659 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | apkActivity = true; |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | if (!apkActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1665 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | } |
| 1667 | uidActivity = true; |
| 1668 | } |
| 1669 | } |
| 1670 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1671 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | } |
| 1675 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1676 | void printBitDescriptions(PrintWriter pw, int oldval, int newval, BitDescription[] descriptions) { |
| 1677 | int diff = oldval ^ newval; |
| 1678 | if (diff == 0) return; |
| 1679 | for (int i=0; i<descriptions.length; i++) { |
| 1680 | BitDescription bd = descriptions[i]; |
| 1681 | if ((diff&bd.mask) != 0) { |
| 1682 | if (bd.shift < 0) { |
| 1683 | pw.print((newval&bd.mask) != 0 ? " +" : " -"); |
| 1684 | pw.print(bd.name); |
| 1685 | } else { |
| 1686 | pw.print(" "); |
| 1687 | pw.print(bd.name); |
| 1688 | pw.print("="); |
| 1689 | int val = (newval&bd.mask)>>bd.shift; |
| 1690 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
| 1691 | pw.print(bd.values[val]); |
| 1692 | } else { |
| 1693 | pw.print(val); |
| 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | /** |
| 1701 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 1702 | * |
| 1703 | * @param pw a Printer to receive the dump output. |
| 1704 | */ |
| 1705 | @SuppressWarnings("unused") |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1706 | public void dumpLocked(PrintWriter pw) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame^] | 1707 | final HistoryItem rec = new HistoryItem(); |
| 1708 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1709 | pw.println("Battery History:"); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1710 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1711 | int oldState = 0; |
| 1712 | int oldStatus = -1; |
| 1713 | int oldHealth = -1; |
| 1714 | int oldPlug = -1; |
| 1715 | int oldTemp = -1; |
| 1716 | int oldVolt = -1; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame^] | 1717 | while (getNextHistoryLocked(rec)) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1718 | pw.print(" "); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1719 | TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1720 | pw.print(" "); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1721 | if (rec.cmd == HistoryItem.CMD_START) { |
| 1722 | pw.println(" START"); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1723 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 1724 | pw.println(" *OVERFLOW*"); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1725 | } else { |
| 1726 | if (rec.batteryLevel < 10) pw.print("00"); |
| 1727 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 1728 | pw.print(rec.batteryLevel); |
| 1729 | pw.print(" "); |
| 1730 | if (rec.states < 0x10) pw.print("0000000"); |
| 1731 | else if (rec.states < 0x100) pw.print("000000"); |
| 1732 | else if (rec.states < 0x1000) pw.print("00000"); |
| 1733 | else if (rec.states < 0x10000) pw.print("0000"); |
| 1734 | else if (rec.states < 0x100000) pw.print("000"); |
| 1735 | else if (rec.states < 0x1000000) pw.print("00"); |
| 1736 | else if (rec.states < 0x10000000) pw.print("0"); |
| 1737 | pw.print(Integer.toHexString(rec.states)); |
| 1738 | if (oldStatus != rec.batteryStatus) { |
| 1739 | oldStatus = rec.batteryStatus; |
| 1740 | pw.print(" status="); |
| 1741 | switch (oldStatus) { |
| 1742 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
| 1743 | pw.print("unknown"); |
| 1744 | break; |
| 1745 | case BatteryManager.BATTERY_STATUS_CHARGING: |
| 1746 | pw.print("charging"); |
| 1747 | break; |
| 1748 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
| 1749 | pw.print("discharging"); |
| 1750 | break; |
| 1751 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
| 1752 | pw.print("not-charging"); |
| 1753 | break; |
| 1754 | case BatteryManager.BATTERY_STATUS_FULL: |
| 1755 | pw.print("full"); |
| 1756 | break; |
| 1757 | default: |
| 1758 | pw.print(oldStatus); |
| 1759 | break; |
| 1760 | } |
| 1761 | } |
| 1762 | if (oldHealth != rec.batteryHealth) { |
| 1763 | oldHealth = rec.batteryHealth; |
| 1764 | pw.print(" health="); |
| 1765 | switch (oldHealth) { |
| 1766 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
| 1767 | pw.print("unknown"); |
| 1768 | break; |
| 1769 | case BatteryManager.BATTERY_HEALTH_GOOD: |
| 1770 | pw.print("good"); |
| 1771 | break; |
| 1772 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
| 1773 | pw.print("overheat"); |
| 1774 | break; |
| 1775 | case BatteryManager.BATTERY_HEALTH_DEAD: |
| 1776 | pw.print("dead"); |
| 1777 | break; |
| 1778 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
| 1779 | pw.print("over-voltage"); |
| 1780 | break; |
| 1781 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
| 1782 | pw.print("failure"); |
| 1783 | break; |
| 1784 | default: |
| 1785 | pw.print(oldHealth); |
| 1786 | break; |
| 1787 | } |
| 1788 | } |
| 1789 | if (oldPlug != rec.batteryPlugType) { |
| 1790 | oldPlug = rec.batteryPlugType; |
| 1791 | pw.print(" plug="); |
| 1792 | switch (oldPlug) { |
| 1793 | case 0: |
| 1794 | pw.print("none"); |
| 1795 | break; |
| 1796 | case BatteryManager.BATTERY_PLUGGED_AC: |
| 1797 | pw.print("ac"); |
| 1798 | break; |
| 1799 | case BatteryManager.BATTERY_PLUGGED_USB: |
| 1800 | pw.print("usb"); |
| 1801 | break; |
| 1802 | default: |
| 1803 | pw.print(oldPlug); |
| 1804 | break; |
| 1805 | } |
| 1806 | } |
| 1807 | if (oldTemp != rec.batteryTemperature) { |
| 1808 | oldTemp = rec.batteryTemperature; |
| 1809 | pw.print(" temp="); |
| 1810 | pw.print(oldTemp); |
| 1811 | } |
| 1812 | if (oldVolt != rec.batteryVoltage) { |
| 1813 | oldVolt = rec.batteryVoltage; |
| 1814 | pw.print(" volt="); |
| 1815 | pw.print(oldVolt); |
| 1816 | } |
| 1817 | printBitDescriptions(pw, oldState, rec.states, |
| 1818 | HISTORY_STATE_DESCRIPTIONS); |
| 1819 | pw.println(); |
| 1820 | } |
| 1821 | oldState = rec.states; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1822 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1823 | pw.println(""); |
| 1824 | } |
| 1825 | |
| 1826 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1827 | final int NU = uidStats.size(); |
| 1828 | boolean didPid = false; |
| 1829 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 1830 | StringBuilder sb = new StringBuilder(64); |
| 1831 | for (int i=0; i<NU; i++) { |
| 1832 | Uid uid = uidStats.valueAt(i); |
| 1833 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 1834 | if (pids != null) { |
| 1835 | for (int j=0; j<pids.size(); j++) { |
| 1836 | Uid.Pid pid = pids.valueAt(j); |
| 1837 | if (!didPid) { |
| 1838 | pw.println("Per-PID Stats:"); |
| 1839 | didPid = true; |
| 1840 | } |
| 1841 | long time = pid.mWakeSum + (pid.mWakeStart != 0 |
| 1842 | ? (nowRealtime - pid.mWakeStart) : 0); |
| 1843 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 1844 | pw.print(" wake time: "); |
| 1845 | TimeUtils.formatDuration(time, pw); |
| 1846 | pw.println(""); |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | if (didPid) { |
| 1851 | pw.println(""); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1854 | pw.println("Statistics since last charge:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | pw.println(" System starts: " + getStartCount() |
| 1856 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1857 | dumpLocked(pw, "", STATS_SINCE_CHARGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | pw.println(""); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1859 | pw.println("Statistics since last unplugged:"); |
| 1860 | dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | @SuppressWarnings("unused") |
| 1864 | public void dumpCheckinLocked(PrintWriter pw, String[] args) { |
| 1865 | boolean isUnpluggedOnly = false; |
| 1866 | |
| 1867 | for (String arg : args) { |
| 1868 | if ("-u".equals(arg)) { |
| 1869 | if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data"); |
| 1870 | isUnpluggedOnly = true; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | if (isUnpluggedOnly) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1875 | dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | } |
| 1877 | else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1878 | dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1); |
| 1879 | dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | } |
| 1881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | } |