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