blob: d49c8be8bb362b9df305d0d805c1548aa52c19a0 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
20import java.util.Formatter;
21import java.util.Map;
22
23import android.util.Log;
24import android.util.Printer;
25import android.util.SparseArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070026import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28/**
29 * A class providing access to battery usage statistics, including information on
30 * wakelocks, processes, packages, and services. All times are represented in microseconds
31 * except where indicated otherwise.
32 * @hide
33 */
34public abstract class BatteryStats implements Parcelable {
35
36 private static final boolean LOCAL_LOGV = false;
37
38 /**
39 * A constant indicating a partial wake lock timer.
40 */
41 public static final int WAKE_TYPE_PARTIAL = 0;
42
43 /**
44 * A constant indicating a full wake lock timer.
45 */
46 public static final int WAKE_TYPE_FULL = 1;
47
48 /**
49 * A constant indicating a window wake lock timer.
50 */
51 public static final int WAKE_TYPE_WINDOW = 2;
52
53 /**
54 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
56 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070057
58 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070059 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070060 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070061 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070062
63 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070064 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070065 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070066 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070067
68 /**
69 * A constant indicating a scan wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070070 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070071 public static final int SCAN_WIFI_LOCK = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Robert Greenwalt5347bd42009-05-13 15:10:16 -070073 /**
74 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070075 */
76 public static final int WIFI_MULTICAST_ENABLED = 7;
77
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070079 * A constant indicating an audio turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070080 */
81 public static final int AUDIO_TURNED_ON = 7;
82
83 /**
84 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070085 */
86 public static final int VIDEO_TURNED_ON = 8;
87
88 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 * Include all of the data in the stats, including previously saved data.
90 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -070091 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 /**
94 * Include only the last run in the stats.
95 */
96 public static final int STATS_LAST = 1;
97
98 /**
99 * Include only the current run in the stats.
100 */
101 public static final int STATS_CURRENT = 2;
102
103 /**
104 * Include only the run since the last time the device was unplugged in the stats.
105 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700106 public static final int STATS_SINCE_UNPLUGGED = 3;
Evan Millare84de8d2009-04-02 22:16:12 -0700107
108 // NOTE: Update this list if you add/change any stats above.
109 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700110 // and "unplugged". They were shortened for efficiency sake.
Evan Millare84de8d2009-04-02 22:16:12 -0700111 private static final String[] STAT_NAMES = { "t", "l", "c", "u" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112
113 /**
114 * Bump the version on this if the checkin format changes.
115 */
Evan Millarc64edde2009-04-18 12:26:32 -0700116 private static final int BATTERY_STATS_CHECKIN_VERSION = 5;
Evan Millar22ac0432009-03-31 11:33:18 -0700117
118 private static final long BYTES_PER_KB = 1024;
119 private static final long BYTES_PER_MB = 1048576; // 1024^2
120 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
123 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700124 private static final String PROCESS_DATA = "pr";
125 private static final String SENSOR_DATA = "sr";
126 private static final String WAKELOCK_DATA = "wl";
Evan Millarc64edde2009-04-18 12:26:32 -0700127 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Evan Millare84de8d2009-04-02 22:16:12 -0700128 private static final String NETWORK_DATA = "nt";
129 private static final String USER_ACTIVITY_DATA = "ua";
130 private static final String BATTERY_DATA = "bt";
131 private static final String BATTERY_LEVEL_DATA = "lv";
132 private static final String WIFI_LOCK_DATA = "wfl";
133 private static final String MISC_DATA = "m";
134 private static final String SCREEN_BRIGHTNESS_DATA = "br";
135 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700136 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700137 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
138 private static final String DATA_CONNECTION_TIME_DATA = "dct";
139 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700141 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 private final Formatter mFormatter = new Formatter(mFormatBuilder);
143
144 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700145 * State for keeping track of counting information.
146 */
147 public static abstract class Counter {
148
149 /**
150 * Returns the count associated with this Counter for the
151 * selected type of statistics.
152 *
153 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
154 */
Evan Millarc64edde2009-04-18 12:26:32 -0700155 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700156
157 /**
158 * Temporary for debugging.
159 */
160 public abstract void logState(Printer pw, String prefix);
161 }
162
163 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 * State for keeping track of timing information.
165 */
166 public static abstract class Timer {
167
168 /**
169 * Returns the count associated with this Timer for the
170 * selected type of statistics.
171 *
172 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
173 */
Evan Millarc64edde2009-04-18 12:26:32 -0700174 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175
176 /**
177 * Returns the total time in microseconds associated with this Timer for the
178 * selected type of statistics.
179 *
180 * @param batteryRealtime system realtime on battery in microseconds
181 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
182 * @return a time in microseconds
183 */
Evan Millarc64edde2009-04-18 12:26:32 -0700184 public abstract long getTotalTimeLocked(long batteryRealtime, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /**
187 * Temporary for debugging.
188 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700189 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 }
191
192 /**
193 * The statistics associated with a particular uid.
194 */
195 public static abstract class Uid {
196
197 /**
198 * Returns a mapping containing wakelock statistics.
199 *
200 * @return a Map from Strings to Uid.Wakelock objects.
201 */
202 public abstract Map<String, ? extends Wakelock> getWakelockStats();
203
204 /**
205 * The statistics associated with a particular wake lock.
206 */
207 public static abstract class Wakelock {
208 public abstract Timer getWakeTime(int type);
209 }
210
211 /**
212 * Returns a mapping containing sensor statistics.
213 *
214 * @return a Map from Integer sensor ids to Uid.Sensor objects.
215 */
216 public abstract Map<Integer, ? extends Sensor> getSensorStats();
217
218 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700219 * Returns a mapping containing active process data.
220 */
221 public abstract SparseArray<? extends Pid> getPidStats();
222
223 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 * Returns a mapping containing process statistics.
225 *
226 * @return a Map from Strings to Uid.Proc objects.
227 */
228 public abstract Map<String, ? extends Proc> getProcessStats();
229
230 /**
231 * Returns a mapping containing package statistics.
232 *
233 * @return a Map from Strings to Uid.Pkg objects.
234 */
235 public abstract Map<String, ? extends Pkg> getPackageStats();
236
237 /**
238 * {@hide}
239 */
240 public abstract int getUid();
241
242 /**
243 * {@hide}
244 */
245 public abstract long getTcpBytesReceived(int which);
246
247 /**
248 * {@hide}
249 */
250 public abstract long getTcpBytesSent(int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700251
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700252 public abstract void noteWifiRunningLocked();
253 public abstract void noteWifiStoppedLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700254 public abstract void noteFullWifiLockAcquiredLocked();
255 public abstract void noteFullWifiLockReleasedLocked();
256 public abstract void noteScanWifiLockAcquiredLocked();
257 public abstract void noteScanWifiLockReleasedLocked();
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700258 public abstract void noteWifiMulticastEnabledLocked();
259 public abstract void noteWifiMulticastDisabledLocked();
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700260 public abstract void noteAudioTurnedOnLocked();
261 public abstract void noteAudioTurnedOffLocked();
262 public abstract void noteVideoTurnedOnLocked();
263 public abstract void noteVideoTurnedOffLocked();
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700264 public abstract long getWifiRunningTime(long batteryRealtime, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700265 public abstract long getFullWifiLockTime(long batteryRealtime, int which);
266 public abstract long getScanWifiLockTime(long batteryRealtime, int which);
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700267 public abstract long getWifiMulticastTime(long batteryRealtime,
268 int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700269 public abstract long getAudioTurnedOnTime(long batteryRealtime, int which);
270 public abstract long getVideoTurnedOnTime(long batteryRealtime, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271
Dianne Hackborn617f8772009-03-31 15:04:46 -0700272 /**
273 * Note that these must match the constants in android.os.LocalPowerManager.
274 */
275 static final String[] USER_ACTIVITY_TYPES = {
276 "other", "cheek", "touch", "long_touch", "touch_up", "button", "unknown"
277 };
278
279 public static final int NUM_USER_ACTIVITY_TYPES = 7;
280
281 public abstract void noteUserActivityLocked(int type);
282 public abstract boolean hasUserActivity();
283 public abstract int getUserActivityCount(int type, int which);
284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 public static abstract class Sensor {
286 // Magic sensor number for the GPS.
287 public static final int GPS = -10000;
288
289 public abstract int getHandle();
290
291 public abstract Timer getSensorTime();
292 }
293
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700294 public class Pid {
295 public long mWakeSum;
296 public long mWakeStart;
297 }
298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 /**
300 * The statistics associated with a particular process.
301 */
302 public static abstract class Proc {
303
Dianne Hackborn287952c2010-09-22 22:34:31 -0700304 public static class ExcessivePower {
305 public static final int TYPE_WAKE = 1;
306 public static final int TYPE_CPU = 2;
307
308 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700309 public long overTime;
310 public long usedTime;
311 }
312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 /**
314 * Returns the total time (in 1/100 sec) spent executing in user code.
315 *
316 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
317 */
318 public abstract long getUserTime(int which);
319
320 /**
321 * Returns the total time (in 1/100 sec) spent executing in system code.
322 *
323 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
324 */
325 public abstract long getSystemTime(int which);
326
327 /**
328 * Returns the number of times the process has been started.
329 *
330 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
331 */
332 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700333
334 /**
335 * Returns the cpu time spent in microseconds while the process was in the foreground.
336 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
337 * @return foreground cpu time in microseconds
338 */
339 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700340
341 /**
342 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
343 * @param speedStep the index of the CPU speed. This is not the actual speed of the
344 * CPU.
345 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
346 * @see BatteryStats#getCpuSpeedSteps()
347 */
348 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700349
Dianne Hackborn287952c2010-09-22 22:34:31 -0700350 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700351
Dianne Hackborn287952c2010-09-22 22:34:31 -0700352 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354
355 /**
356 * The statistics associated with a particular package.
357 */
358 public static abstract class Pkg {
359
360 /**
361 * Returns the number of times this package has done something that could wake up the
362 * device from sleep.
363 *
364 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
365 */
366 public abstract int getWakeups(int which);
367
368 /**
369 * Returns a mapping containing service statistics.
370 */
371 public abstract Map<String, ? extends Serv> getServiceStats();
372
373 /**
374 * The statistics associated with a particular service.
375 */
376 public abstract class Serv {
377
378 /**
379 * Returns the amount of time spent started.
380 *
381 * @param batteryUptime elapsed uptime on battery in microseconds.
382 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
383 * @return
384 */
385 public abstract long getStartTime(long batteryUptime, int which);
386
387 /**
388 * Returns the total number of times startService() has been called.
389 *
390 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
391 */
392 public abstract int getStarts(int which);
393
394 /**
395 * Returns the total number times the service has been launched.
396 *
397 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
398 */
399 public abstract int getLaunches(int which);
400 }
401 }
402 }
403
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700404 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700405 public HistoryItem next;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700406
407 public long time;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700408
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700409 public static final byte CMD_UPDATE = 0;
410 public static final byte CMD_START = 1;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700411 public static final byte CMD_OVERFLOW = 2;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700412
413 public byte cmd;
414
415 public byte batteryLevel;
416 public byte batteryStatus;
417 public byte batteryHealth;
418 public byte batteryPlugType;
419
420 public char batteryTemperature;
421 public char batteryVoltage;
422
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700423 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700424 public static final int STATE_BRIGHTNESS_MASK = 0x000000f;
425 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700426 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700427 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0;
428 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700429 // Constants from ServiceState.STATE_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700430 public static final int STATE_PHONE_STATE_MASK = 0x0000f00;
431 public static final int STATE_PHONE_STATE_SHIFT = 8;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700432 // Constants from DATA_CONNECTION_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700433 public static final int STATE_DATA_CONNECTION_MASK = 0x000f000;
434 public static final int STATE_DATA_CONNECTION_SHIFT = 12;
435
436 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30;
437 public static final int STATE_SCREEN_ON_FLAG = 1<<29;
438 public static final int STATE_GPS_ON_FLAG = 1<<28;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700439 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<27;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700440 public static final int STATE_PHONE_SCANNING_FLAG = 1<<26;
441 public static final int STATE_WIFI_ON_FLAG = 1<<25;
442 public static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
443 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<23;
444 public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<22;
445 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<21;
446 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<20;
447 public static final int STATE_AUDIO_ON_FLAG = 1<<19;
448 public static final int STATE_VIDEO_ON_FLAG = 1<<18;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700449 public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
450 public static final int STATE_SENSOR_ON_FLAG = 1<<16;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700451
452 public int states;
453
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700454 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700455 }
456
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700457 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700458 this.time = time;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700459 int bat = src.readInt();
460 cmd = (byte)(bat&0xff);
461 batteryLevel = (byte)((bat>>8)&0xff);
462 batteryStatus = (byte)((bat>>16)&0xf);
463 batteryHealth = (byte)((bat>>20)&0xf);
464 batteryPlugType = (byte)((bat>>24)&0xf);
465 bat = src.readInt();
466 batteryTemperature = (char)(bat&0xffff);
467 batteryVoltage = (char)((bat>>16)&0xffff);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700468 states = src.readInt();
469 }
470
471 public int describeContents() {
472 return 0;
473 }
474
475 public void writeToParcel(Parcel dest, int flags) {
476 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700477 int bat = (((int)cmd)&0xff)
478 | ((((int)batteryLevel)<<8)&0xff00)
479 | ((((int)batteryStatus)<<16)&0xf0000)
480 | ((((int)batteryHealth)<<20)&0xf00000)
481 | ((((int)batteryPlugType)<<24)&0xf000000);
482 dest.writeInt(bat);
483 bat = (((int)batteryTemperature)&0xffff)
484 | ((((int)batteryVoltage)<<16)&0xffff0000);
485 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700486 dest.writeInt(states);
487 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700488
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700489 public void setTo(HistoryItem o) {
490 time = o.time;
491 cmd = o.cmd;
492 batteryLevel = o.batteryLevel;
493 batteryStatus = o.batteryStatus;
494 batteryHealth = o.batteryHealth;
495 batteryPlugType = o.batteryPlugType;
496 batteryTemperature = o.batteryTemperature;
497 batteryVoltage = o.batteryVoltage;
498 states = o.states;
499 }
500
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700501 public void setTo(long time, byte cmd, HistoryItem o) {
502 this.time = time;
503 this.cmd = cmd;
504 batteryLevel = o.batteryLevel;
505 batteryStatus = o.batteryStatus;
506 batteryHealth = o.batteryHealth;
507 batteryPlugType = o.batteryPlugType;
508 batteryTemperature = o.batteryTemperature;
509 batteryVoltage = o.batteryVoltage;
510 states = o.states;
511 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700512
513 public boolean same(HistoryItem o) {
514 return batteryLevel == o.batteryLevel
515 && batteryStatus == o.batteryStatus
516 && batteryHealth == o.batteryHealth
517 && batteryPlugType == o.batteryPlugType
518 && batteryTemperature == o.batteryTemperature
519 && batteryVoltage == o.batteryVoltage
520 && states == o.states;
521 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700522 }
523
524 public static final class BitDescription {
525 public final int mask;
526 public final int shift;
527 public final String name;
528 public final String[] values;
529
530 public BitDescription(int mask, String name) {
531 this.mask = mask;
532 this.shift = -1;
533 this.name = name;
534 this.values = null;
535 }
536
537 public BitDescription(int mask, int shift, String name, String[] values) {
538 this.mask = mask;
539 this.shift = shift;
540 this.name = name;
541 this.values = values;
542 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700543 }
544
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700545 public abstract boolean startIteratingHistoryLocked();
546
547 public abstract boolean getNextHistoryLocked(HistoryItem out);
548
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700549 /**
550 * Return the current history of battery state changes.
551 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700552 public abstract HistoryItem getHistory();
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700555 * Return the base time offset for the battery history.
556 */
557 public abstract long getHistoryBaseTime();
558
559 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 * Returns the number of times the device has been started.
561 */
562 public abstract int getStartCount();
563
564 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700565 * Returns the time in microseconds that the screen has been on while the device was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 * running on battery.
567 *
568 * {@hide}
569 */
570 public abstract long getScreenOnTime(long batteryRealtime, int which);
571
Dianne Hackborn617f8772009-03-31 15:04:46 -0700572 public static final int SCREEN_BRIGHTNESS_DARK = 0;
573 public static final int SCREEN_BRIGHTNESS_DIM = 1;
574 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
575 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
576 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
577
578 static final String[] SCREEN_BRIGHTNESS_NAMES = {
579 "dark", "dim", "medium", "light", "bright"
580 };
581
582 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
583
584 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700585 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700586 * the given brightness
587 *
588 * {@hide}
589 */
590 public abstract long getScreenBrightnessTime(int brightnessBin,
591 long batteryRealtime, int which);
592
593 public abstract int getInputEventCount(int which);
594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700596 * Returns the time in microseconds that the phone has been on while the device was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 * running on battery.
598 *
599 * {@hide}
600 */
601 public abstract long getPhoneOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700602
Dianne Hackborn627bba72009-03-24 22:32:56 -0700603 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
604 public static final int SIGNAL_STRENGTH_POOR = 1;
605 public static final int SIGNAL_STRENGTH_MODERATE = 2;
606 public static final int SIGNAL_STRENGTH_GOOD = 3;
607 public static final int SIGNAL_STRENGTH_GREAT = 4;
608
609 static final String[] SIGNAL_STRENGTH_NAMES = {
610 "none", "poor", "moderate", "good", "great"
611 };
612
613 public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
614
615 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700616 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700617 * the given signal strength.
618 *
619 * {@hide}
620 */
621 public abstract long getPhoneSignalStrengthTime(int strengthBin,
622 long batteryRealtime, int which);
623
Dianne Hackborn617f8772009-03-31 15:04:46 -0700624 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -0700625 * Returns the time in microseconds that the phone has been trying to
626 * acquire a signal.
627 *
628 * {@hide}
629 */
630 public abstract long getPhoneSignalScanningTime(
631 long batteryRealtime, int which);
632
633 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700634 * Returns the number of times the phone has entered the given signal strength.
635 *
636 * {@hide}
637 */
638 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
639
Dianne Hackborn627bba72009-03-24 22:32:56 -0700640 public static final int DATA_CONNECTION_NONE = 0;
641 public static final int DATA_CONNECTION_GPRS = 1;
642 public static final int DATA_CONNECTION_EDGE = 2;
643 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700644 public static final int DATA_CONNECTION_CDMA = 4;
645 public static final int DATA_CONNECTION_EVDO_0 = 5;
646 public static final int DATA_CONNECTION_EVDO_A = 6;
647 public static final int DATA_CONNECTION_1xRTT = 7;
648 public static final int DATA_CONNECTION_HSDPA = 8;
649 public static final int DATA_CONNECTION_HSUPA = 9;
650 public static final int DATA_CONNECTION_HSPA = 10;
651 public static final int DATA_CONNECTION_IDEN = 11;
652 public static final int DATA_CONNECTION_EVDO_B = 12;
653 public static final int DATA_CONNECTION_OTHER = 13;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700654
655 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700656 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
657 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -0700658 };
659
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700660 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700661
662 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700663 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700664 * the given data connection.
665 *
666 * {@hide}
667 */
668 public abstract long getPhoneDataConnectionTime(int dataType,
669 long batteryRealtime, int which);
670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700672 * Returns the number of times the phone has entered the given data
673 * connection type.
674 *
675 * {@hide}
676 */
677 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700678
679 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
680 = new BitDescription[] {
681 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged"),
682 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen"),
683 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps"),
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700684 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700685 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning"),
686 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi"),
687 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running"),
688 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"),
689 new BitDescription(HistoryItem.STATE_WIFI_SCAN_LOCK_FLAG, "wifi_scan_lock"),
690 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"),
691 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"),
692 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"),
693 new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"),
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700694 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"),
695 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700696 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
697 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness",
698 SCREEN_BRIGHTNESS_NAMES),
699 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK,
700 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength",
701 SIGNAL_STRENGTH_NAMES),
702 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
703 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state",
704 new String[] {"in", "out", "emergency", "off"}),
705 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
706 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn",
707 DATA_CONNECTION_NAMES),
708 };
Dianne Hackborn617f8772009-03-31 15:04:46 -0700709
710 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700711 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700712 * running on battery.
713 *
714 * {@hide}
715 */
716 public abstract long getWifiOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700717
718 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700719 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700720 * been in the running state while the device was running on battery.
721 *
722 * {@hide}
723 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700724 public abstract long getGlobalWifiRunningTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700725
The Android Open Source Project10592532009-03-18 17:39:46 -0700726 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700727 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700728 * running on battery.
729 *
730 * {@hide}
731 */
732 public abstract long getBluetoothOnTime(long batteryRealtime, int which);
733
734 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 * Return whether we are currently running on battery.
736 */
737 public abstract boolean getIsOnBattery();
738
739 /**
740 * Returns a SparseArray containing the statistics for each uid.
741 */
742 public abstract SparseArray<? extends Uid> getUidStats();
743
744 /**
745 * Returns the current battery uptime in microseconds.
746 *
747 * @param curTime the amount of elapsed realtime in microseconds.
748 */
749 public abstract long getBatteryUptime(long curTime);
750
751 /**
Amith Yamasani3f7e35c2009-07-13 16:02:45 -0700752 * @deprecated use getRadioDataUptime
753 */
754 public long getRadioDataUptimeMs() {
755 return getRadioDataUptime() / 1000;
756 }
757
758 /**
759 * Returns the time that the radio was on for data transfers.
760 * @return the uptime in microseconds while unplugged
761 */
762 public abstract long getRadioDataUptime();
763
764 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 * Returns the current battery realtime in microseconds.
766 *
767 * @param curTime the amount of elapsed realtime in microseconds.
768 */
769 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -0700770
771 /**
Evan Millar633a1742009-04-02 16:36:33 -0700772 * Returns the battery percentage level at the last time the device was unplugged from power, or
773 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -0700774 */
Evan Millar633a1742009-04-02 16:36:33 -0700775 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -0700776
777 /**
Evan Millar633a1742009-04-02 16:36:33 -0700778 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
779 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -0700780 */
Evan Millar633a1742009-04-02 16:36:33 -0700781 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782
783 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700784 * Get the amount the battery has discharged since the stats were
785 * last reset after charging, as a lower-end approximation.
786 */
787 public abstract int getLowDischargeAmountSinceCharge();
788
789 /**
790 * Get the amount the battery has discharged since the stats were
791 * last reset after charging, as an upper-end approximation.
792 */
793 public abstract int getHighDischargeAmountSinceCharge();
794
795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 * Returns the total, last, or current battery uptime in microseconds.
797 *
798 * @param curTime the elapsed realtime in microseconds.
799 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
800 */
801 public abstract long computeBatteryUptime(long curTime, int which);
802
803 /**
804 * Returns the total, last, or current battery realtime in microseconds.
805 *
806 * @param curTime the current elapsed realtime in microseconds.
807 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
808 */
809 public abstract long computeBatteryRealtime(long curTime, int which);
810
811 /**
812 * Returns the total, last, or current uptime in microseconds.
813 *
814 * @param curTime the current elapsed realtime in microseconds.
815 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
816 */
817 public abstract long computeUptime(long curTime, int which);
818
819 /**
820 * Returns the total, last, or current realtime in microseconds.
821 * *
822 * @param curTime the current elapsed realtime in microseconds.
823 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
824 */
825 public abstract long computeRealtime(long curTime, int which);
Evan Millarc64edde2009-04-18 12:26:32 -0700826
827 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828
Amith Yamasanie43530a2009-08-21 13:11:37 -0700829 /** Returns the number of different speeds that the CPU can run at */
830 public abstract int getCpuSpeedSteps();
831
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700832 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 long days = seconds / (60 * 60 * 24);
834 if (days != 0) {
835 out.append(days);
836 out.append("d ");
837 }
838 long used = days * 60 * 60 * 24;
839
840 long hours = (seconds - used) / (60 * 60);
841 if (hours != 0 || used != 0) {
842 out.append(hours);
843 out.append("h ");
844 }
845 used += hours * 60 * 60;
846
847 long mins = (seconds-used) / 60;
848 if (mins != 0 || used != 0) {
849 out.append(mins);
850 out.append("m ");
851 }
852 used += mins * 60;
853
854 if (seconds != 0 || used != 0) {
855 out.append(seconds-used);
856 out.append("s ");
857 }
858 }
859
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700860 private final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700862 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 sb.append((time - (sec * 100)) * 10);
864 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 }
866
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700867 private final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700869 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 sb.append(time - (sec * 1000));
871 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 }
873
874 private final String formatRatioLocked(long num, long den) {
875 if (den == 0L) {
876 return "---%";
877 }
878 float perc = ((float)num) / ((float)den) * 100;
879 mFormatBuilder.setLength(0);
880 mFormatter.format("%.1f%%", perc);
881 return mFormatBuilder.toString();
882 }
883
Evan Millar22ac0432009-03-31 11:33:18 -0700884 private final String formatBytesLocked(long bytes) {
885 mFormatBuilder.setLength(0);
886
887 if (bytes < BYTES_PER_KB) {
888 return bytes + "B";
889 } else if (bytes < BYTES_PER_MB) {
890 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
891 return mFormatBuilder.toString();
892 } else if (bytes < BYTES_PER_GB){
893 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
894 return mFormatBuilder.toString();
895 } else {
896 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
897 return mFormatBuilder.toString();
898 }
899 }
900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 /**
902 *
903 * @param sb a StringBuilder object.
904 * @param timer a Timer object contining the wakelock times.
905 * @param batteryRealtime the current on-battery time in microseconds.
906 * @param name the name of the wakelock.
907 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
908 * @param linePrefix a String to be prepended to each line of output.
909 * @return the line prefix
910 */
911 private static final String printWakeLock(StringBuilder sb, Timer timer,
912 long batteryRealtime, String name, int which, String linePrefix) {
913
914 if (timer != null) {
915 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -0700916 long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
918
Evan Millarc64edde2009-04-18 12:26:32 -0700919 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 if (totalTimeMillis != 0) {
921 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700922 formatTimeMs(sb, totalTimeMillis);
923 if (name != null) sb.append(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 sb.append(' ');
925 sb.append('(');
926 sb.append(count);
927 sb.append(" times)");
928 return ", ";
929 }
930 }
931 return linePrefix;
932 }
933
934 /**
935 * Checkin version of wakelock printer. Prints simple comma-separated list.
936 *
937 * @param sb a StringBuilder object.
938 * @param timer a Timer object contining the wakelock times.
939 * @param now the current time in microseconds.
940 * @param name the name of the wakelock.
941 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
942 * @param linePrefix a String to be prepended to each line of output.
943 * @return the line prefix
944 */
945 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now,
Evan Millarc64edde2009-04-18 12:26:32 -0700946 String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 long totalTimeMicros = 0;
948 int count = 0;
949 if (timer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700950 totalTimeMicros = timer.getTotalTimeLocked(now, which);
951 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 }
953 sb.append(linePrefix);
954 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
955 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -0700956 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 sb.append(count);
958 return ",";
959 }
960
961 /**
962 * Dump a comma-separated line of values for terse checkin mode.
963 *
964 * @param pw the PageWriter to dump log to
965 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
966 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
967 * @param args type-dependent data arguments
968 */
969 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
970 Object... args ) {
971 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
972 pw.print(uid); pw.print(',');
973 pw.print(category); pw.print(',');
974 pw.print(type);
975
976 for (Object arg : args) {
977 pw.print(',');
978 pw.print(arg);
979 }
980 pw.print('\n');
981 }
982
983 /**
984 * Checkin server version of dump to produce more compact, computer-readable log.
985 *
986 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800988 public final void dumpCheckinLocked(PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 final long rawUptime = SystemClock.uptimeMillis() * 1000;
990 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
991 final long batteryUptime = getBatteryUptime(rawUptime);
992 final long batteryRealtime = getBatteryRealtime(rawRealtime);
993 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
994 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
995 final long totalRealtime = computeRealtime(rawRealtime, which);
996 final long totalUptime = computeUptime(rawUptime, which);
997 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
998 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700999 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001000 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001001 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002
1003 StringBuilder sb = new StringBuilder(128);
1004
Evan Millar22ac0432009-03-31 11:33:18 -07001005 SparseArray<? extends Uid> uidStats = getUidStats();
1006 final int NU = uidStats.size();
1007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 String category = STAT_NAMES[which];
1009
1010 // Dump "battery" stat
1011 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001012 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07001013 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
1014 totalRealtime / 1000, totalUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015
Evan Millar22ac0432009-03-31 11:33:18 -07001016 // Calculate total network and wakelock times across all uids.
1017 long rxTotal = 0;
1018 long txTotal = 0;
1019 long fullWakeLockTimeTotal = 0;
1020 long partialWakeLockTimeTotal = 0;
1021
1022 for (int iu = 0; iu < NU; iu++) {
1023 Uid u = uidStats.valueAt(iu);
1024 rxTotal += u.getTcpBytesReceived(which);
1025 txTotal += u.getTcpBytesSent(which);
1026
1027 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1028 if (wakelocks.size() > 0) {
1029 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1030 : wakelocks.entrySet()) {
1031 Uid.Wakelock wl = ent.getValue();
1032
1033 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1034 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001035 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001036 }
1037
1038 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1039 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001040 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001041 batteryRealtime, which);
1042 }
1043 }
1044 }
1045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 // Dump misc stats
1048 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001049 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Evan Millar22ac0432009-03-31 11:33:18 -07001050 wifiRunningTime / 1000, bluetoothOnTime / 1000, rxTotal, txTotal,
Dianne Hackborn617f8772009-03-31 15:04:46 -07001051 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
1052 getInputEventCount(which));
1053
1054 // Dump screen brightness stats
1055 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
1056 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1057 args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000;
1058 }
1059 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07001060
Dianne Hackborn627bba72009-03-24 22:32:56 -07001061 // Dump signal strength stats
Dianne Hackborn617f8772009-03-31 15:04:46 -07001062 args = new Object[NUM_SIGNAL_STRENGTH_BINS];
Dianne Hackborn627bba72009-03-24 22:32:56 -07001063 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1064 args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000;
1065 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001066 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001067 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
1068 getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001069 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1070 args[i] = getPhoneSignalStrengthCount(i, which);
1071 }
1072 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001073
1074 // Dump network type stats
1075 args = new Object[NUM_DATA_CONNECTION_TYPES];
1076 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1077 args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000;
1078 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001079 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
1080 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1081 args[i] = getPhoneDataConnectionCount(i, which);
1082 }
1083 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001084
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001085 if (which == STATS_SINCE_UNPLUGGED) {
Evan Millare84de8d2009-04-02 22:16:12 -07001086 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07001087 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001090 if (reqUid < 0) {
1091 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1092 if (kernelWakelocks.size() > 0) {
1093 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1094 sb.setLength(0);
1095 printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, "");
1096
1097 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
1098 sb.toString());
1099 }
Evan Millarc64edde2009-04-18 12:26:32 -07001100 }
1101 }
1102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 for (int iu = 0; iu < NU; iu++) {
1104 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001105 if (reqUid >= 0 && uid != reqUid) {
1106 continue;
1107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 Uid u = uidStats.valueAt(iu);
1109 // Dump Network stats per uid, if any
1110 long rx = u.getTcpBytesReceived(which);
1111 long tx = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001112 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1113 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001114 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 if (rx > 0 || tx > 0) dumpLine(pw, uid, category, NETWORK_DATA, rx, tx);
The Android Open Source Project10592532009-03-18 17:39:46 -07001117
Dianne Hackborn617f8772009-03-31 15:04:46 -07001118 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001119 || uidWifiRunningTime != 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001120 dumpLine(pw, uid, category, WIFI_LOCK_DATA,
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001121 fullWifiLockOnTime, scanWifiLockOnTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123
Dianne Hackborn617f8772009-03-31 15:04:46 -07001124 if (u.hasUserActivity()) {
1125 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
1126 boolean hasData = false;
1127 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
1128 int val = u.getUserActivityCount(i, which);
1129 args[i] = val;
1130 if (val != 0) hasData = true;
1131 }
1132 if (hasData) {
1133 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
1134 }
1135 }
1136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1138 if (wakelocks.size() > 0) {
1139 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1140 : wakelocks.entrySet()) {
1141 Uid.Wakelock wl = ent.getValue();
1142 String linePrefix = "";
1143 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07001144 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
1145 batteryRealtime, "f", which, linePrefix);
1146 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
1147 batteryRealtime, "p", which, linePrefix);
1148 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
1149 batteryRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150
1151 // Only log if we had at lease one wakelock...
1152 if (sb.length() > 0) {
1153 dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString());
1154 }
1155 }
1156 }
1157
1158 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1159 if (sensors.size() > 0) {
1160 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1161 : sensors.entrySet()) {
1162 Uid.Sensor se = ent.getValue();
1163 int sensorNumber = ent.getKey();
1164 Timer timer = se.getSensorTime();
1165 if (timer != null) {
1166 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001167 long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000;
1168 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 if (totalTime != 0) {
1170 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
1171 }
1172 }
1173 }
1174 }
1175
1176 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1177 if (processStats.size() > 0) {
1178 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1179 : processStats.entrySet()) {
1180 Uid.Proc ps = ent.getValue();
1181
1182 long userTime = ps.getUserTime(which);
1183 long systemTime = ps.getSystemTime(which);
1184 int starts = ps.getStarts(which);
1185
1186 if (userTime != 0 || systemTime != 0 || starts != 0) {
1187 dumpLine(pw, uid, category, PROCESS_DATA,
1188 ent.getKey(), // proc
1189 userTime * 10, // cpu time in ms
1190 systemTime * 10, // user time in ms
1191 starts); // process starts
1192 }
1193 }
1194 }
1195
1196 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1197 if (packageStats.size() > 0) {
1198 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1199 : packageStats.entrySet()) {
1200
1201 Uid.Pkg ps = ent.getValue();
1202 int wakeups = ps.getWakeups(which);
1203 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1204 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1205 : serviceStats.entrySet()) {
1206 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1207 long startTime = ss.getStartTime(batteryUptime, which);
1208 int starts = ss.getStarts(which);
1209 int launches = ss.getLaunches(which);
1210 if (startTime != 0 || starts != 0 || launches != 0) {
1211 dumpLine(pw, uid, category, APK_DATA,
1212 wakeups, // wakeup alarms
1213 ent.getKey(), // Apk
1214 sent.getKey(), // service
1215 startTime / 1000, // time spent started, in ms
1216 starts,
1217 launches);
1218 }
1219 }
1220 }
1221 }
1222 }
1223 }
1224
1225 @SuppressWarnings("unused")
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001226 public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1228 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1229 final long batteryUptime = getBatteryUptime(rawUptime);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001230 final long batteryRealtime = getBatteryRealtime(rawRealtime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231
1232 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1233 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1234 final long totalRealtime = computeRealtime(rawRealtime, which);
1235 final long totalUptime = computeUptime(rawUptime, which);
1236
1237 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07001238
1239 SparseArray<? extends Uid> uidStats = getUidStats();
1240 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001242 sb.setLength(0);
1243 sb.append(prefix);
1244 sb.append(" Time on battery: ");
1245 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
1246 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
1247 sb.append(") realtime, ");
1248 formatTimeMs(sb, whichBatteryUptime / 1000);
1249 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
1250 sb.append(") uptime");
1251 pw.println(sb.toString());
1252 sb.setLength(0);
1253 sb.append(prefix);
1254 sb.append(" Total run time: ");
1255 formatTimeMs(sb, totalRealtime / 1000);
1256 sb.append("realtime, ");
1257 formatTimeMs(sb, totalUptime / 1000);
1258 sb.append("uptime, ");
1259 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260
The Android Open Source Project10592532009-03-18 17:39:46 -07001261 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
1262 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001263 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001264 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
1265 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001266 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001267 sb.append(prefix);
1268 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
1269 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
1270 sb.append("), Input events: "); sb.append(getInputEventCount(which));
1271 sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
1272 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
1273 sb.append(")");
1274 pw.println(sb.toString());
1275 sb.setLength(0);
1276 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001277 sb.append(" Screen brightnesses: ");
1278 boolean didOne = false;
1279 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1280 final long time = getScreenBrightnessTime(i, batteryRealtime, which);
1281 if (time == 0) {
1282 continue;
1283 }
1284 if (didOne) sb.append(", ");
1285 didOne = true;
1286 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
1287 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001288 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001289 sb.append("(");
1290 sb.append(formatRatioLocked(time, screenOnTime));
1291 sb.append(")");
1292 }
1293 if (!didOne) sb.append("No activity");
1294 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001295
Evan Millar22ac0432009-03-31 11:33:18 -07001296 // Calculate total network and wakelock times across all uids.
1297 long rxTotal = 0;
1298 long txTotal = 0;
1299 long fullWakeLockTimeTotalMicros = 0;
1300 long partialWakeLockTimeTotalMicros = 0;
1301
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001302 if (reqUid < 0) {
1303 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1304 if (kernelWakelocks.size() > 0) {
1305 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1306
1307 String linePrefix = ": ";
1308 sb.setLength(0);
1309 sb.append(prefix);
1310 sb.append(" Kernel Wake lock ");
1311 sb.append(ent.getKey());
1312 linePrefix = printWakeLock(sb, ent.getValue(), batteryRealtime, null, which,
1313 linePrefix);
1314 if (!linePrefix.equals(": ")) {
1315 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001316 // Only print out wake locks that were held
1317 pw.println(sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001318 }
Evan Millarc64edde2009-04-18 12:26:32 -07001319 }
Evan Millarc64edde2009-04-18 12:26:32 -07001320 }
1321 }
1322
Evan Millar22ac0432009-03-31 11:33:18 -07001323 for (int iu = 0; iu < NU; iu++) {
1324 Uid u = uidStats.valueAt(iu);
1325 rxTotal += u.getTcpBytesReceived(which);
1326 txTotal += u.getTcpBytesSent(which);
1327
1328 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1329 if (wakelocks.size() > 0) {
1330 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1331 : wakelocks.entrySet()) {
1332 Uid.Wakelock wl = ent.getValue();
1333
1334 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1335 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001336 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001337 batteryRealtime, which);
1338 }
1339
1340 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1341 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001342 partialWakeLockTimeTotalMicros += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001343 batteryRealtime, which);
1344 }
1345 }
1346 }
1347 }
1348
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001349 pw.print(prefix);
1350 pw.print(" Total received: "); pw.print(formatBytesLocked(rxTotal));
1351 pw.print(", Total sent: "); pw.println(formatBytesLocked(txTotal));
1352 sb.setLength(0);
1353 sb.append(prefix);
1354 sb.append(" Total full wakelock time: "); formatTimeMs(sb,
1355 (fullWakeLockTimeTotalMicros + 500) / 1000);
1356 sb.append(", Total partial waklock time: "); formatTimeMs(sb,
1357 (partialWakeLockTimeTotalMicros + 500) / 1000);
1358 pw.println(sb.toString());
Evan Millar22ac0432009-03-31 11:33:18 -07001359
Dianne Hackborn627bba72009-03-24 22:32:56 -07001360 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001361 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001362 sb.append(" Signal levels: ");
1363 didOne = false;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001364 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1365 final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which);
1366 if (time == 0) {
1367 continue;
1368 }
1369 if (didOne) sb.append(", ");
1370 didOne = true;
1371 sb.append(SIGNAL_STRENGTH_NAMES[i]);
1372 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001373 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001374 sb.append("(");
1375 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001376 sb.append(") ");
1377 sb.append(getPhoneSignalStrengthCount(i, which));
1378 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001379 }
1380 if (!didOne) sb.append("No activity");
1381 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07001382
1383 sb.setLength(0);
1384 sb.append(prefix);
1385 sb.append(" Signal scanning time: ");
1386 formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
1387 pw.println(sb.toString());
1388
Dianne Hackborn627bba72009-03-24 22:32:56 -07001389 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001390 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001391 sb.append(" Radio types: ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001392 didOne = false;
1393 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1394 final long time = getPhoneDataConnectionTime(i, batteryRealtime, which);
1395 if (time == 0) {
1396 continue;
1397 }
1398 if (didOne) sb.append(", ");
1399 didOne = true;
1400 sb.append(DATA_CONNECTION_NAMES[i]);
1401 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001402 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001403 sb.append("(");
1404 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001405 sb.append(") ");
1406 sb.append(getPhoneDataConnectionCount(i, which));
1407 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001408 }
1409 if (!didOne) sb.append("No activity");
1410 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07001411
1412 sb.setLength(0);
1413 sb.append(prefix);
1414 sb.append(" Radio data uptime when unplugged: ");
1415 sb.append(getRadioDataUptime() / 1000);
1416 sb.append(" ms");
1417 pw.println(sb.toString());
1418
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001419 sb.setLength(0);
1420 sb.append(prefix);
1421 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
1422 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
1423 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
1424 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
1425 sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
1426 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
1427 sb.append(")");
1428 pw.println(sb.toString());
Dianne Hackborn617f8772009-03-31 15:04:46 -07001429
The Android Open Source Project10592532009-03-18 17:39:46 -07001430 pw.println(" ");
1431
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001432 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001433 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001434 pw.print(prefix); pw.println(" Device is currently unplugged");
1435 pw.print(prefix); pw.print(" Discharge cycle start level: ");
1436 pw.println(getDischargeStartLevel());
1437 pw.print(prefix); pw.print(" Discharge cycle current level: ");
1438 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07001439 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001440 pw.print(prefix); pw.println(" Device is currently plugged into power");
1441 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
1442 pw.println(getDischargeStartLevel());
1443 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
1444 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001445 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001446 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001447 } else {
1448 pw.print(prefix); pw.println(" Device battery use since last full charge");
1449 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
1450 pw.println(getLowDischargeAmountSinceCharge());
1451 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
1452 pw.println(getHighDischargeAmountSinceCharge());
1453 pw.println(" ");
The Android Open Source Project10592532009-03-18 17:39:46 -07001454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455
Evan Millar22ac0432009-03-31 11:33:18 -07001456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 for (int iu=0; iu<NU; iu++) {
1458 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001459 if (reqUid >= 0 && uid != reqUid) {
1460 continue;
1461 }
1462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 Uid u = uidStats.valueAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 pw.println(prefix + " #" + uid + ":");
1466 boolean uidActivity = false;
1467
1468 long tcpReceived = u.getTcpBytesReceived(which);
1469 long tcpSent = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001470 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1471 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001472 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 if (tcpReceived != 0 || tcpSent != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001475 pw.print(prefix); pw.print(" Network: ");
1476 pw.print(formatBytesLocked(tcpReceived)); pw.print(" received, ");
1477 pw.print(formatBytesLocked(tcpSent)); pw.println(" sent");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001479
1480 if (u.hasUserActivity()) {
1481 boolean hasData = false;
1482 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1483 int val = u.getUserActivityCount(i, which);
1484 if (val != 0) {
1485 if (!hasData) {
1486 sb.setLength(0);
1487 sb.append(" User activity: ");
1488 hasData = true;
1489 } else {
1490 sb.append(", ");
1491 }
1492 sb.append(val);
1493 sb.append(" ");
1494 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
1495 }
1496 }
1497 if (hasData) {
1498 pw.println(sb.toString());
1499 }
1500 }
1501
1502 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001503 || uidWifiRunningTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001504 sb.setLength(0);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001505 sb.append(prefix); sb.append(" Wifi Running: ");
1506 formatTimeMs(sb, uidWifiRunningTime / 1000);
1507 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001508 whichBatteryRealtime)); sb.append(")\n");
1509 sb.append(prefix); sb.append(" Full Wifi Lock: ");
1510 formatTimeMs(sb, fullWifiLockOnTime / 1000);
1511 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
1512 whichBatteryRealtime)); sb.append(")\n");
1513 sb.append(prefix); sb.append(" Scan Wifi Lock: ");
1514 formatTimeMs(sb, scanWifiLockOnTime / 1000);
1515 sb.append("("); sb.append(formatRatioLocked(scanWifiLockOnTime,
1516 whichBatteryRealtime)); sb.append(")");
1517 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519
1520 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1521 if (wakelocks.size() > 0) {
1522 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1523 : wakelocks.entrySet()) {
1524 Uid.Wakelock wl = ent.getValue();
1525 String linePrefix = ": ";
1526 sb.setLength(0);
1527 sb.append(prefix);
1528 sb.append(" Wake lock ");
1529 sb.append(ent.getKey());
1530 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime,
1531 "full", which, linePrefix);
1532 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime,
1533 "partial", which, linePrefix);
1534 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime,
1535 "window", which, linePrefix);
1536 if (!linePrefix.equals(": ")) {
1537 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001538 // Only print out wake locks that were held
1539 pw.println(sb.toString());
1540 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 }
1543 }
1544
1545 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1546 if (sensors.size() > 0) {
1547 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1548 : sensors.entrySet()) {
1549 Uid.Sensor se = ent.getValue();
1550 int sensorNumber = ent.getKey();
1551 sb.setLength(0);
1552 sb.append(prefix);
1553 sb.append(" Sensor ");
1554 int handle = se.getHandle();
1555 if (handle == Uid.Sensor.GPS) {
1556 sb.append("GPS");
1557 } else {
1558 sb.append(handle);
1559 }
1560 sb.append(": ");
1561
1562 Timer timer = se.getSensorTime();
1563 if (timer != null) {
1564 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001565 long totalTime = (timer.getTotalTimeLocked(
1566 batteryRealtime, which) + 500) / 1000;
1567 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 //timer.logState();
1569 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001570 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 sb.append("realtime (");
1572 sb.append(count);
1573 sb.append(" times)");
1574 } else {
1575 sb.append("(not used)");
1576 }
1577 } else {
1578 sb.append("(not used)");
1579 }
1580
1581 pw.println(sb.toString());
1582 uidActivity = true;
1583 }
1584 }
1585
1586 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1587 if (processStats.size() > 0) {
1588 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1589 : processStats.entrySet()) {
1590 Uid.Proc ps = ent.getValue();
1591 long userTime;
1592 long systemTime;
1593 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001594 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595
1596 userTime = ps.getUserTime(which);
1597 systemTime = ps.getSystemTime(which);
1598 starts = ps.getStarts(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001599 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07001600 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001602 if (userTime != 0 || systemTime != 0 || starts != 0
1603 || numExcessive != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001604 sb.setLength(0);
1605 sb.append(prefix); sb.append(" Proc ");
1606 sb.append(ent.getKey()); sb.append(":\n");
1607 sb.append(prefix); sb.append(" CPU: ");
1608 formatTime(sb, userTime); sb.append("usr + ");
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001609 formatTime(sb, systemTime); sb.append("krn");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001610 if (starts != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001611 sb.append("\n"); sb.append(prefix); sb.append(" ");
1612 sb.append(starts); sb.append(" proc starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001613 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001614 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001615 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07001616 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001617 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07001618 pw.print(prefix); pw.print(" * Killed for ");
1619 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
1620 pw.print("wake lock");
1621 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
1622 pw.print("cpu");
1623 } else {
1624 pw.print("unknown");
1625 }
1626 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07001627 TimeUtils.formatDuration(ew.usedTime, pw);
1628 pw.print(" over ");
1629 TimeUtils.formatDuration(ew.overTime, pw);
1630 pw.print(" (");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001631 pw.print((ew.usedTime*100)/ew.overTime);
1632 pw.println("%)");
1633 }
1634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 uidActivity = true;
1636 }
1637 }
1638 }
1639
1640 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1641 if (packageStats.size() > 0) {
1642 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1643 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001644 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 boolean apkActivity = false;
1646 Uid.Pkg ps = ent.getValue();
1647 int wakeups = ps.getWakeups(which);
1648 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001649 pw.print(prefix); pw.print(" ");
1650 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 apkActivity = true;
1652 }
1653 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1654 if (serviceStats.size() > 0) {
1655 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1656 : serviceStats.entrySet()) {
1657 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1658 long startTime = ss.getStartTime(batteryUptime, which);
1659 int starts = ss.getStarts(which);
1660 int launches = ss.getLaunches(which);
1661 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001662 sb.setLength(0);
1663 sb.append(prefix); sb.append(" Service ");
1664 sb.append(sent.getKey()); sb.append(":\n");
1665 sb.append(prefix); sb.append(" Created for: ");
1666 formatTimeMs(sb, startTime / 1000);
1667 sb.append(" uptime\n");
1668 sb.append(prefix); sb.append(" Starts: ");
1669 sb.append(starts);
1670 sb.append(", launches: "); sb.append(launches);
1671 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 apkActivity = true;
1673 }
1674 }
1675 }
1676 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001677 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 }
1679 uidActivity = true;
1680 }
1681 }
1682 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001683 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 }
1685 }
1686 }
1687
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001688 void printBitDescriptions(PrintWriter pw, int oldval, int newval, BitDescription[] descriptions) {
1689 int diff = oldval ^ newval;
1690 if (diff == 0) return;
1691 for (int i=0; i<descriptions.length; i++) {
1692 BitDescription bd = descriptions[i];
1693 if ((diff&bd.mask) != 0) {
1694 if (bd.shift < 0) {
1695 pw.print((newval&bd.mask) != 0 ? " +" : " -");
1696 pw.print(bd.name);
1697 } else {
1698 pw.print(" ");
1699 pw.print(bd.name);
1700 pw.print("=");
1701 int val = (newval&bd.mask)>>bd.shift;
1702 if (bd.values != null && val >= 0 && val < bd.values.length) {
1703 pw.print(bd.values[val]);
1704 } else {
1705 pw.print(val);
1706 }
1707 }
1708 }
1709 }
1710 }
1711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 /**
1713 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
1714 *
1715 * @param pw a Printer to receive the dump output.
1716 */
1717 @SuppressWarnings("unused")
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001718 public void dumpLocked(PrintWriter pw) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001719 final HistoryItem rec = new HistoryItem();
1720 if (startIteratingHistoryLocked()) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001721 pw.println("Battery History:");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001722 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001723 int oldState = 0;
1724 int oldStatus = -1;
1725 int oldHealth = -1;
1726 int oldPlug = -1;
1727 int oldTemp = -1;
1728 int oldVolt = -1;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001729 while (getNextHistoryLocked(rec)) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001730 pw.print(" ");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001731 TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001732 pw.print(" ");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001733 if (rec.cmd == HistoryItem.CMD_START) {
1734 pw.println(" START");
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001735 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
1736 pw.println(" *OVERFLOW*");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001737 } else {
1738 if (rec.batteryLevel < 10) pw.print("00");
1739 else if (rec.batteryLevel < 100) pw.print("0");
1740 pw.print(rec.batteryLevel);
1741 pw.print(" ");
1742 if (rec.states < 0x10) pw.print("0000000");
1743 else if (rec.states < 0x100) pw.print("000000");
1744 else if (rec.states < 0x1000) pw.print("00000");
1745 else if (rec.states < 0x10000) pw.print("0000");
1746 else if (rec.states < 0x100000) pw.print("000");
1747 else if (rec.states < 0x1000000) pw.print("00");
1748 else if (rec.states < 0x10000000) pw.print("0");
1749 pw.print(Integer.toHexString(rec.states));
1750 if (oldStatus != rec.batteryStatus) {
1751 oldStatus = rec.batteryStatus;
1752 pw.print(" status=");
1753 switch (oldStatus) {
1754 case BatteryManager.BATTERY_STATUS_UNKNOWN:
1755 pw.print("unknown");
1756 break;
1757 case BatteryManager.BATTERY_STATUS_CHARGING:
1758 pw.print("charging");
1759 break;
1760 case BatteryManager.BATTERY_STATUS_DISCHARGING:
1761 pw.print("discharging");
1762 break;
1763 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
1764 pw.print("not-charging");
1765 break;
1766 case BatteryManager.BATTERY_STATUS_FULL:
1767 pw.print("full");
1768 break;
1769 default:
1770 pw.print(oldStatus);
1771 break;
1772 }
1773 }
1774 if (oldHealth != rec.batteryHealth) {
1775 oldHealth = rec.batteryHealth;
1776 pw.print(" health=");
1777 switch (oldHealth) {
1778 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
1779 pw.print("unknown");
1780 break;
1781 case BatteryManager.BATTERY_HEALTH_GOOD:
1782 pw.print("good");
1783 break;
1784 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
1785 pw.print("overheat");
1786 break;
1787 case BatteryManager.BATTERY_HEALTH_DEAD:
1788 pw.print("dead");
1789 break;
1790 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
1791 pw.print("over-voltage");
1792 break;
1793 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
1794 pw.print("failure");
1795 break;
1796 default:
1797 pw.print(oldHealth);
1798 break;
1799 }
1800 }
1801 if (oldPlug != rec.batteryPlugType) {
1802 oldPlug = rec.batteryPlugType;
1803 pw.print(" plug=");
1804 switch (oldPlug) {
1805 case 0:
1806 pw.print("none");
1807 break;
1808 case BatteryManager.BATTERY_PLUGGED_AC:
1809 pw.print("ac");
1810 break;
1811 case BatteryManager.BATTERY_PLUGGED_USB:
1812 pw.print("usb");
1813 break;
1814 default:
1815 pw.print(oldPlug);
1816 break;
1817 }
1818 }
1819 if (oldTemp != rec.batteryTemperature) {
1820 oldTemp = rec.batteryTemperature;
1821 pw.print(" temp=");
1822 pw.print(oldTemp);
1823 }
1824 if (oldVolt != rec.batteryVoltage) {
1825 oldVolt = rec.batteryVoltage;
1826 pw.print(" volt=");
1827 pw.print(oldVolt);
1828 }
1829 printBitDescriptions(pw, oldState, rec.states,
1830 HISTORY_STATE_DESCRIPTIONS);
1831 pw.println();
1832 }
1833 oldState = rec.states;
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001834 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001835 pw.println("");
1836 }
1837
1838 SparseArray<? extends Uid> uidStats = getUidStats();
1839 final int NU = uidStats.size();
1840 boolean didPid = false;
1841 long nowRealtime = SystemClock.elapsedRealtime();
1842 StringBuilder sb = new StringBuilder(64);
1843 for (int i=0; i<NU; i++) {
1844 Uid uid = uidStats.valueAt(i);
1845 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
1846 if (pids != null) {
1847 for (int j=0; j<pids.size(); j++) {
1848 Uid.Pid pid = pids.valueAt(j);
1849 if (!didPid) {
1850 pw.println("Per-PID Stats:");
1851 didPid = true;
1852 }
1853 long time = pid.mWakeSum + (pid.mWakeStart != 0
1854 ? (nowRealtime - pid.mWakeStart) : 0);
1855 pw.print(" PID "); pw.print(pids.keyAt(j));
1856 pw.print(" wake time: ");
1857 TimeUtils.formatDuration(time, pw);
1858 pw.println("");
1859 }
1860 }
1861 }
1862 if (didPid) {
1863 pw.println("");
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001864 }
1865
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001866 pw.println("Statistics since last charge:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 pw.println(" System starts: " + getStartCount()
1868 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001869 dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 pw.println("");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001871 pw.println("Statistics since last unplugged:");
1872 dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001873 }
1874
1875 @SuppressWarnings("unused")
1876 public void dumpCheckinLocked(PrintWriter pw, String[] args) {
1877 boolean isUnpluggedOnly = false;
1878
1879 for (String arg : args) {
1880 if ("-u".equals(arg)) {
1881 if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data");
1882 isUnpluggedOnly = true;
1883 }
1884 }
1885
1886 if (isUnpluggedOnly) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001887 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 }
1889 else {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001890 dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
1891 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 }
1893 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894}