blob: 1e88c5647666f18f296cfbe2a0d4e92af506a1ca [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 Hackborn9adb9c32010-08-13 14:09:56 -0700304 public static class ExcessiveWake {
305 public long overTime;
306 public long usedTime;
307 }
308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 /**
310 * Returns the total time (in 1/100 sec) spent executing in user code.
311 *
312 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
313 */
314 public abstract long getUserTime(int which);
315
316 /**
317 * Returns the total time (in 1/100 sec) spent executing in system code.
318 *
319 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
320 */
321 public abstract long getSystemTime(int which);
322
323 /**
324 * Returns the number of times the process has been started.
325 *
326 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
327 */
328 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700329
330 /**
331 * Returns the cpu time spent in microseconds while the process was in the foreground.
332 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
333 * @return foreground cpu time in microseconds
334 */
335 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700336
337 /**
338 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
339 * @param speedStep the index of the CPU speed. This is not the actual speed of the
340 * CPU.
341 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
342 * @see BatteryStats#getCpuSpeedSteps()
343 */
344 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700345
346 public abstract int countExcessiveWakes();
347
348 public abstract ExcessiveWake getExcessiveWake(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 }
350
351 /**
352 * The statistics associated with a particular package.
353 */
354 public static abstract class Pkg {
355
356 /**
357 * Returns the number of times this package has done something that could wake up the
358 * device from sleep.
359 *
360 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
361 */
362 public abstract int getWakeups(int which);
363
364 /**
365 * Returns a mapping containing service statistics.
366 */
367 public abstract Map<String, ? extends Serv> getServiceStats();
368
369 /**
370 * The statistics associated with a particular service.
371 */
372 public abstract class Serv {
373
374 /**
375 * Returns the amount of time spent started.
376 *
377 * @param batteryUptime elapsed uptime on battery in microseconds.
378 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
379 * @return
380 */
381 public abstract long getStartTime(long batteryUptime, int which);
382
383 /**
384 * Returns the total number of times startService() has been called.
385 *
386 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
387 */
388 public abstract int getStarts(int which);
389
390 /**
391 * Returns the total number times the service has been launched.
392 *
393 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
394 */
395 public abstract int getLaunches(int which);
396 }
397 }
398 }
399
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700400 public final class HistoryItem implements Parcelable {
401 public HistoryItem next;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700402
403 public long time;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700404
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700405 public static final byte CMD_UPDATE = 0;
406 public static final byte CMD_START = 1;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700407 public static final byte CMD_OVERFLOW = 2;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700408
409 public byte cmd;
410
411 public byte batteryLevel;
412 public byte batteryStatus;
413 public byte batteryHealth;
414 public byte batteryPlugType;
415
416 public char batteryTemperature;
417 public char batteryVoltage;
418
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700419 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700420 public static final int STATE_BRIGHTNESS_MASK = 0x000000f;
421 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700422 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700423 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0;
424 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700425 // Constants from ServiceState.STATE_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700426 public static final int STATE_PHONE_STATE_MASK = 0x0000f00;
427 public static final int STATE_PHONE_STATE_SHIFT = 8;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700428 // Constants from DATA_CONNECTION_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700429 public static final int STATE_DATA_CONNECTION_MASK = 0x000f000;
430 public static final int STATE_DATA_CONNECTION_SHIFT = 12;
431
432 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30;
433 public static final int STATE_SCREEN_ON_FLAG = 1<<29;
434 public static final int STATE_GPS_ON_FLAG = 1<<28;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700435 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<27;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700436 public static final int STATE_PHONE_SCANNING_FLAG = 1<<26;
437 public static final int STATE_WIFI_ON_FLAG = 1<<25;
438 public static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
439 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<23;
440 public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<22;
441 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<21;
442 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<20;
443 public static final int STATE_AUDIO_ON_FLAG = 1<<19;
444 public static final int STATE_VIDEO_ON_FLAG = 1<<18;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700445 public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
446 public static final int STATE_SENSOR_ON_FLAG = 1<<16;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700447
448 public int states;
449
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700450 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700451 }
452
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700453 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700454 this.time = time;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700455 int bat = src.readInt();
456 cmd = (byte)(bat&0xff);
457 batteryLevel = (byte)((bat>>8)&0xff);
458 batteryStatus = (byte)((bat>>16)&0xf);
459 batteryHealth = (byte)((bat>>20)&0xf);
460 batteryPlugType = (byte)((bat>>24)&0xf);
461 bat = src.readInt();
462 batteryTemperature = (char)(bat&0xffff);
463 batteryVoltage = (char)((bat>>16)&0xffff);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700464 states = src.readInt();
465 }
466
467 public int describeContents() {
468 return 0;
469 }
470
471 public void writeToParcel(Parcel dest, int flags) {
472 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700473 int bat = (((int)cmd)&0xff)
474 | ((((int)batteryLevel)<<8)&0xff00)
475 | ((((int)batteryStatus)<<16)&0xf0000)
476 | ((((int)batteryHealth)<<20)&0xf00000)
477 | ((((int)batteryPlugType)<<24)&0xf000000);
478 dest.writeInt(bat);
479 bat = (((int)batteryTemperature)&0xffff)
480 | ((((int)batteryVoltage)<<16)&0xffff0000);
481 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700482 dest.writeInt(states);
483 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700484
485 public void setTo(long time, byte cmd, HistoryItem o) {
486 this.time = time;
487 this.cmd = cmd;
488 batteryLevel = o.batteryLevel;
489 batteryStatus = o.batteryStatus;
490 batteryHealth = o.batteryHealth;
491 batteryPlugType = o.batteryPlugType;
492 batteryTemperature = o.batteryTemperature;
493 batteryVoltage = o.batteryVoltage;
494 states = o.states;
495 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700496
497 public boolean same(HistoryItem o) {
498 return batteryLevel == o.batteryLevel
499 && batteryStatus == o.batteryStatus
500 && batteryHealth == o.batteryHealth
501 && batteryPlugType == o.batteryPlugType
502 && batteryTemperature == o.batteryTemperature
503 && batteryVoltage == o.batteryVoltage
504 && states == o.states;
505 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700506 }
507
508 public static final class BitDescription {
509 public final int mask;
510 public final int shift;
511 public final String name;
512 public final String[] values;
513
514 public BitDescription(int mask, String name) {
515 this.mask = mask;
516 this.shift = -1;
517 this.name = name;
518 this.values = null;
519 }
520
521 public BitDescription(int mask, int shift, String name, String[] values) {
522 this.mask = mask;
523 this.shift = shift;
524 this.name = name;
525 this.values = values;
526 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700527 }
528
529 /**
530 * Return the current history of battery state changes.
531 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700532 public abstract HistoryItem getHistory();
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700535 * Return the base time offset for the battery history.
536 */
537 public abstract long getHistoryBaseTime();
538
539 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 * Returns the number of times the device has been started.
541 */
542 public abstract int getStartCount();
543
544 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700545 * 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 -0800546 * running on battery.
547 *
548 * {@hide}
549 */
550 public abstract long getScreenOnTime(long batteryRealtime, int which);
551
Dianne Hackborn617f8772009-03-31 15:04:46 -0700552 public static final int SCREEN_BRIGHTNESS_DARK = 0;
553 public static final int SCREEN_BRIGHTNESS_DIM = 1;
554 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
555 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
556 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
557
558 static final String[] SCREEN_BRIGHTNESS_NAMES = {
559 "dark", "dim", "medium", "light", "bright"
560 };
561
562 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
563
564 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700565 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700566 * the given brightness
567 *
568 * {@hide}
569 */
570 public abstract long getScreenBrightnessTime(int brightnessBin,
571 long batteryRealtime, int which);
572
573 public abstract int getInputEventCount(int which);
574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700576 * 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 -0800577 * running on battery.
578 *
579 * {@hide}
580 */
581 public abstract long getPhoneOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700582
Dianne Hackborn627bba72009-03-24 22:32:56 -0700583 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
584 public static final int SIGNAL_STRENGTH_POOR = 1;
585 public static final int SIGNAL_STRENGTH_MODERATE = 2;
586 public static final int SIGNAL_STRENGTH_GOOD = 3;
587 public static final int SIGNAL_STRENGTH_GREAT = 4;
588
589 static final String[] SIGNAL_STRENGTH_NAMES = {
590 "none", "poor", "moderate", "good", "great"
591 };
592
593 public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
594
595 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700596 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700597 * the given signal strength.
598 *
599 * {@hide}
600 */
601 public abstract long getPhoneSignalStrengthTime(int strengthBin,
602 long batteryRealtime, int which);
603
Dianne Hackborn617f8772009-03-31 15:04:46 -0700604 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -0700605 * Returns the time in microseconds that the phone has been trying to
606 * acquire a signal.
607 *
608 * {@hide}
609 */
610 public abstract long getPhoneSignalScanningTime(
611 long batteryRealtime, int which);
612
613 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700614 * Returns the number of times the phone has entered the given signal strength.
615 *
616 * {@hide}
617 */
618 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
619
Dianne Hackborn627bba72009-03-24 22:32:56 -0700620 public static final int DATA_CONNECTION_NONE = 0;
621 public static final int DATA_CONNECTION_GPRS = 1;
622 public static final int DATA_CONNECTION_EDGE = 2;
623 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700624 public static final int DATA_CONNECTION_CDMA = 4;
625 public static final int DATA_CONNECTION_EVDO_0 = 5;
626 public static final int DATA_CONNECTION_EVDO_A = 6;
627 public static final int DATA_CONNECTION_1xRTT = 7;
628 public static final int DATA_CONNECTION_HSDPA = 8;
629 public static final int DATA_CONNECTION_HSUPA = 9;
630 public static final int DATA_CONNECTION_HSPA = 10;
631 public static final int DATA_CONNECTION_IDEN = 11;
632 public static final int DATA_CONNECTION_EVDO_B = 12;
633 public static final int DATA_CONNECTION_OTHER = 13;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700634
635 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700636 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
637 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -0700638 };
639
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700640 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700641
642 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700643 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700644 * the given data connection.
645 *
646 * {@hide}
647 */
648 public abstract long getPhoneDataConnectionTime(int dataType,
649 long batteryRealtime, int which);
650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700652 * Returns the number of times the phone has entered the given data
653 * connection type.
654 *
655 * {@hide}
656 */
657 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700658
659 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
660 = new BitDescription[] {
661 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged"),
662 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen"),
663 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps"),
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700664 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700665 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning"),
666 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi"),
667 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running"),
668 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"),
669 new BitDescription(HistoryItem.STATE_WIFI_SCAN_LOCK_FLAG, "wifi_scan_lock"),
670 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"),
671 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"),
672 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"),
673 new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"),
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700674 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"),
675 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700676 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
677 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness",
678 SCREEN_BRIGHTNESS_NAMES),
679 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK,
680 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength",
681 SIGNAL_STRENGTH_NAMES),
682 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
683 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state",
684 new String[] {"in", "out", "emergency", "off"}),
685 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
686 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn",
687 DATA_CONNECTION_NAMES),
688 };
Dianne Hackborn617f8772009-03-31 15:04:46 -0700689
690 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700691 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700692 * running on battery.
693 *
694 * {@hide}
695 */
696 public abstract long getWifiOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700697
698 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700699 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700700 * been in the running state while the device was running on battery.
701 *
702 * {@hide}
703 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700704 public abstract long getGlobalWifiRunningTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700705
The Android Open Source Project10592532009-03-18 17:39:46 -0700706 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700707 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700708 * running on battery.
709 *
710 * {@hide}
711 */
712 public abstract long getBluetoothOnTime(long batteryRealtime, int which);
713
714 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 * Return whether we are currently running on battery.
716 */
717 public abstract boolean getIsOnBattery();
718
719 /**
720 * Returns a SparseArray containing the statistics for each uid.
721 */
722 public abstract SparseArray<? extends Uid> getUidStats();
723
724 /**
725 * Returns the current battery uptime in microseconds.
726 *
727 * @param curTime the amount of elapsed realtime in microseconds.
728 */
729 public abstract long getBatteryUptime(long curTime);
730
731 /**
Amith Yamasani3f7e35c2009-07-13 16:02:45 -0700732 * @deprecated use getRadioDataUptime
733 */
734 public long getRadioDataUptimeMs() {
735 return getRadioDataUptime() / 1000;
736 }
737
738 /**
739 * Returns the time that the radio was on for data transfers.
740 * @return the uptime in microseconds while unplugged
741 */
742 public abstract long getRadioDataUptime();
743
744 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 * Returns the current battery realtime in microseconds.
746 *
747 * @param curTime the amount of elapsed realtime in microseconds.
748 */
749 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -0700750
751 /**
Evan Millar633a1742009-04-02 16:36:33 -0700752 * Returns the battery percentage level at the last time the device was unplugged from power, or
753 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -0700754 */
Evan Millar633a1742009-04-02 16:36:33 -0700755 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -0700756
757 /**
Evan Millar633a1742009-04-02 16:36:33 -0700758 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
759 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -0700760 */
Evan Millar633a1742009-04-02 16:36:33 -0700761 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762
763 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700764 * Get the amount the battery has discharged since the stats were
765 * last reset after charging, as a lower-end approximation.
766 */
767 public abstract int getLowDischargeAmountSinceCharge();
768
769 /**
770 * Get the amount the battery has discharged since the stats were
771 * last reset after charging, as an upper-end approximation.
772 */
773 public abstract int getHighDischargeAmountSinceCharge();
774
775 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 * Returns the total, last, or current battery uptime in microseconds.
777 *
778 * @param curTime the elapsed realtime in microseconds.
779 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
780 */
781 public abstract long computeBatteryUptime(long curTime, int which);
782
783 /**
784 * Returns the total, last, or current battery realtime in microseconds.
785 *
786 * @param curTime the current elapsed realtime in microseconds.
787 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
788 */
789 public abstract long computeBatteryRealtime(long curTime, int which);
790
791 /**
792 * Returns the total, last, or current uptime in microseconds.
793 *
794 * @param curTime the current elapsed realtime in microseconds.
795 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
796 */
797 public abstract long computeUptime(long curTime, int which);
798
799 /**
800 * Returns the total, last, or current realtime in microseconds.
801 * *
802 * @param curTime the current elapsed realtime in microseconds.
803 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
804 */
805 public abstract long computeRealtime(long curTime, int which);
Evan Millarc64edde2009-04-18 12:26:32 -0700806
807 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808
Amith Yamasanie43530a2009-08-21 13:11:37 -0700809 /** Returns the number of different speeds that the CPU can run at */
810 public abstract int getCpuSpeedSteps();
811
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700812 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 long days = seconds / (60 * 60 * 24);
814 if (days != 0) {
815 out.append(days);
816 out.append("d ");
817 }
818 long used = days * 60 * 60 * 24;
819
820 long hours = (seconds - used) / (60 * 60);
821 if (hours != 0 || used != 0) {
822 out.append(hours);
823 out.append("h ");
824 }
825 used += hours * 60 * 60;
826
827 long mins = (seconds-used) / 60;
828 if (mins != 0 || used != 0) {
829 out.append(mins);
830 out.append("m ");
831 }
832 used += mins * 60;
833
834 if (seconds != 0 || used != 0) {
835 out.append(seconds-used);
836 out.append("s ");
837 }
838 }
839
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700840 private final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700842 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 sb.append((time - (sec * 100)) * 10);
844 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 }
846
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700847 private final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700849 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 sb.append(time - (sec * 1000));
851 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853
854 private final String formatRatioLocked(long num, long den) {
855 if (den == 0L) {
856 return "---%";
857 }
858 float perc = ((float)num) / ((float)den) * 100;
859 mFormatBuilder.setLength(0);
860 mFormatter.format("%.1f%%", perc);
861 return mFormatBuilder.toString();
862 }
863
Evan Millar22ac0432009-03-31 11:33:18 -0700864 private final String formatBytesLocked(long bytes) {
865 mFormatBuilder.setLength(0);
866
867 if (bytes < BYTES_PER_KB) {
868 return bytes + "B";
869 } else if (bytes < BYTES_PER_MB) {
870 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
871 return mFormatBuilder.toString();
872 } else if (bytes < BYTES_PER_GB){
873 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
874 return mFormatBuilder.toString();
875 } else {
876 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
877 return mFormatBuilder.toString();
878 }
879 }
880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 /**
882 *
883 * @param sb a StringBuilder object.
884 * @param timer a Timer object contining the wakelock times.
885 * @param batteryRealtime the current on-battery time in microseconds.
886 * @param name the name of the wakelock.
887 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
888 * @param linePrefix a String to be prepended to each line of output.
889 * @return the line prefix
890 */
891 private static final String printWakeLock(StringBuilder sb, Timer timer,
892 long batteryRealtime, String name, int which, String linePrefix) {
893
894 if (timer != null) {
895 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -0700896 long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
898
Evan Millarc64edde2009-04-18 12:26:32 -0700899 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 if (totalTimeMillis != 0) {
901 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700902 formatTimeMs(sb, totalTimeMillis);
903 if (name != null) sb.append(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 sb.append(' ');
905 sb.append('(');
906 sb.append(count);
907 sb.append(" times)");
908 return ", ";
909 }
910 }
911 return linePrefix;
912 }
913
914 /**
915 * Checkin version of wakelock printer. Prints simple comma-separated list.
916 *
917 * @param sb a StringBuilder object.
918 * @param timer a Timer object contining the wakelock times.
919 * @param now the current time in microseconds.
920 * @param name the name of the wakelock.
921 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
922 * @param linePrefix a String to be prepended to each line of output.
923 * @return the line prefix
924 */
925 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now,
Evan Millarc64edde2009-04-18 12:26:32 -0700926 String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 long totalTimeMicros = 0;
928 int count = 0;
929 if (timer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700930 totalTimeMicros = timer.getTotalTimeLocked(now, which);
931 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
933 sb.append(linePrefix);
934 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
935 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -0700936 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 sb.append(count);
938 return ",";
939 }
940
941 /**
942 * Dump a comma-separated line of values for terse checkin mode.
943 *
944 * @param pw the PageWriter to dump log to
945 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
946 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
947 * @param args type-dependent data arguments
948 */
949 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
950 Object... args ) {
951 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
952 pw.print(uid); pw.print(',');
953 pw.print(category); pw.print(',');
954 pw.print(type);
955
956 for (Object arg : args) {
957 pw.print(',');
958 pw.print(arg);
959 }
960 pw.print('\n');
961 }
962
963 /**
964 * Checkin server version of dump to produce more compact, computer-readable log.
965 *
966 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800968 public final void dumpCheckinLocked(PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 final long rawUptime = SystemClock.uptimeMillis() * 1000;
970 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
971 final long batteryUptime = getBatteryUptime(rawUptime);
972 final long batteryRealtime = getBatteryRealtime(rawRealtime);
973 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
974 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
975 final long totalRealtime = computeRealtime(rawRealtime, which);
976 final long totalUptime = computeUptime(rawUptime, which);
977 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
978 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700979 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700980 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700981 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982
983 StringBuilder sb = new StringBuilder(128);
984
Evan Millar22ac0432009-03-31 11:33:18 -0700985 SparseArray<? extends Uid> uidStats = getUidStats();
986 final int NU = uidStats.size();
987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 String category = STAT_NAMES[which];
989
990 // Dump "battery" stat
991 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700992 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -0700993 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
994 totalRealtime / 1000, totalUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995
Evan Millar22ac0432009-03-31 11:33:18 -0700996 // Calculate total network and wakelock times across all uids.
997 long rxTotal = 0;
998 long txTotal = 0;
999 long fullWakeLockTimeTotal = 0;
1000 long partialWakeLockTimeTotal = 0;
1001
1002 for (int iu = 0; iu < NU; iu++) {
1003 Uid u = uidStats.valueAt(iu);
1004 rxTotal += u.getTcpBytesReceived(which);
1005 txTotal += u.getTcpBytesSent(which);
1006
1007 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1008 if (wakelocks.size() > 0) {
1009 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1010 : wakelocks.entrySet()) {
1011 Uid.Wakelock wl = ent.getValue();
1012
1013 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1014 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001015 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001016 }
1017
1018 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1019 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001020 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001021 batteryRealtime, which);
1022 }
1023 }
1024 }
1025 }
1026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 // Dump misc stats
1028 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001029 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Evan Millar22ac0432009-03-31 11:33:18 -07001030 wifiRunningTime / 1000, bluetoothOnTime / 1000, rxTotal, txTotal,
Dianne Hackborn617f8772009-03-31 15:04:46 -07001031 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
1032 getInputEventCount(which));
1033
1034 // Dump screen brightness stats
1035 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
1036 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1037 args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000;
1038 }
1039 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07001040
Dianne Hackborn627bba72009-03-24 22:32:56 -07001041 // Dump signal strength stats
Dianne Hackborn617f8772009-03-31 15:04:46 -07001042 args = new Object[NUM_SIGNAL_STRENGTH_BINS];
Dianne Hackborn627bba72009-03-24 22:32:56 -07001043 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1044 args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000;
1045 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001046 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001047 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
1048 getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001049 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1050 args[i] = getPhoneSignalStrengthCount(i, which);
1051 }
1052 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001053
1054 // Dump network type stats
1055 args = new Object[NUM_DATA_CONNECTION_TYPES];
1056 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1057 args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000;
1058 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001059 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
1060 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1061 args[i] = getPhoneDataConnectionCount(i, which);
1062 }
1063 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001064
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001065 if (which == STATS_SINCE_UNPLUGGED) {
Evan Millare84de8d2009-04-02 22:16:12 -07001066 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07001067 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001070 if (reqUid < 0) {
1071 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1072 if (kernelWakelocks.size() > 0) {
1073 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1074 sb.setLength(0);
1075 printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, "");
1076
1077 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
1078 sb.toString());
1079 }
Evan Millarc64edde2009-04-18 12:26:32 -07001080 }
1081 }
1082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 for (int iu = 0; iu < NU; iu++) {
1084 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001085 if (reqUid >= 0 && uid != reqUid) {
1086 continue;
1087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 Uid u = uidStats.valueAt(iu);
1089 // Dump Network stats per uid, if any
1090 long rx = u.getTcpBytesReceived(which);
1091 long tx = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001092 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1093 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001094 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 if (rx > 0 || tx > 0) dumpLine(pw, uid, category, NETWORK_DATA, rx, tx);
The Android Open Source Project10592532009-03-18 17:39:46 -07001097
Dianne Hackborn617f8772009-03-31 15:04:46 -07001098 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001099 || uidWifiRunningTime != 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001100 dumpLine(pw, uid, category, WIFI_LOCK_DATA,
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001101 fullWifiLockOnTime, scanWifiLockOnTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103
Dianne Hackborn617f8772009-03-31 15:04:46 -07001104 if (u.hasUserActivity()) {
1105 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
1106 boolean hasData = false;
1107 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
1108 int val = u.getUserActivityCount(i, which);
1109 args[i] = val;
1110 if (val != 0) hasData = true;
1111 }
1112 if (hasData) {
1113 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
1114 }
1115 }
1116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1118 if (wakelocks.size() > 0) {
1119 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1120 : wakelocks.entrySet()) {
1121 Uid.Wakelock wl = ent.getValue();
1122 String linePrefix = "";
1123 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07001124 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
1125 batteryRealtime, "f", which, linePrefix);
1126 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
1127 batteryRealtime, "p", which, linePrefix);
1128 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
1129 batteryRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130
1131 // Only log if we had at lease one wakelock...
1132 if (sb.length() > 0) {
1133 dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString());
1134 }
1135 }
1136 }
1137
1138 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1139 if (sensors.size() > 0) {
1140 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1141 : sensors.entrySet()) {
1142 Uid.Sensor se = ent.getValue();
1143 int sensorNumber = ent.getKey();
1144 Timer timer = se.getSensorTime();
1145 if (timer != null) {
1146 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001147 long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000;
1148 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 if (totalTime != 0) {
1150 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
1151 }
1152 }
1153 }
1154 }
1155
1156 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1157 if (processStats.size() > 0) {
1158 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1159 : processStats.entrySet()) {
1160 Uid.Proc ps = ent.getValue();
1161
1162 long userTime = ps.getUserTime(which);
1163 long systemTime = ps.getSystemTime(which);
1164 int starts = ps.getStarts(which);
1165
1166 if (userTime != 0 || systemTime != 0 || starts != 0) {
1167 dumpLine(pw, uid, category, PROCESS_DATA,
1168 ent.getKey(), // proc
1169 userTime * 10, // cpu time in ms
1170 systemTime * 10, // user time in ms
1171 starts); // process starts
1172 }
1173 }
1174 }
1175
1176 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1177 if (packageStats.size() > 0) {
1178 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1179 : packageStats.entrySet()) {
1180
1181 Uid.Pkg ps = ent.getValue();
1182 int wakeups = ps.getWakeups(which);
1183 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1184 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1185 : serviceStats.entrySet()) {
1186 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1187 long startTime = ss.getStartTime(batteryUptime, which);
1188 int starts = ss.getStarts(which);
1189 int launches = ss.getLaunches(which);
1190 if (startTime != 0 || starts != 0 || launches != 0) {
1191 dumpLine(pw, uid, category, APK_DATA,
1192 wakeups, // wakeup alarms
1193 ent.getKey(), // Apk
1194 sent.getKey(), // service
1195 startTime / 1000, // time spent started, in ms
1196 starts,
1197 launches);
1198 }
1199 }
1200 }
1201 }
1202 }
1203 }
1204
1205 @SuppressWarnings("unused")
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001206 public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1208 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1209 final long batteryUptime = getBatteryUptime(rawUptime);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001210 final long batteryRealtime = getBatteryRealtime(rawRealtime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211
1212 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1213 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1214 final long totalRealtime = computeRealtime(rawRealtime, which);
1215 final long totalUptime = computeUptime(rawUptime, which);
1216
1217 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07001218
1219 SparseArray<? extends Uid> uidStats = getUidStats();
1220 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001222 sb.setLength(0);
1223 sb.append(prefix);
1224 sb.append(" Time on battery: ");
1225 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
1226 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
1227 sb.append(") realtime, ");
1228 formatTimeMs(sb, whichBatteryUptime / 1000);
1229 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
1230 sb.append(") uptime");
1231 pw.println(sb.toString());
1232 sb.setLength(0);
1233 sb.append(prefix);
1234 sb.append(" Total run time: ");
1235 formatTimeMs(sb, totalRealtime / 1000);
1236 sb.append("realtime, ");
1237 formatTimeMs(sb, totalUptime / 1000);
1238 sb.append("uptime, ");
1239 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240
The Android Open Source Project10592532009-03-18 17:39:46 -07001241 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
1242 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001243 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001244 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
1245 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001246 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001247 sb.append(prefix);
1248 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
1249 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
1250 sb.append("), Input events: "); sb.append(getInputEventCount(which));
1251 sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
1252 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
1253 sb.append(")");
1254 pw.println(sb.toString());
1255 sb.setLength(0);
1256 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001257 sb.append(" Screen brightnesses: ");
1258 boolean didOne = false;
1259 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1260 final long time = getScreenBrightnessTime(i, batteryRealtime, which);
1261 if (time == 0) {
1262 continue;
1263 }
1264 if (didOne) sb.append(", ");
1265 didOne = true;
1266 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
1267 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001268 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001269 sb.append("(");
1270 sb.append(formatRatioLocked(time, screenOnTime));
1271 sb.append(")");
1272 }
1273 if (!didOne) sb.append("No activity");
1274 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001275
Evan Millar22ac0432009-03-31 11:33:18 -07001276 // Calculate total network and wakelock times across all uids.
1277 long rxTotal = 0;
1278 long txTotal = 0;
1279 long fullWakeLockTimeTotalMicros = 0;
1280 long partialWakeLockTimeTotalMicros = 0;
1281
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001282 if (reqUid < 0) {
1283 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1284 if (kernelWakelocks.size() > 0) {
1285 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1286
1287 String linePrefix = ": ";
1288 sb.setLength(0);
1289 sb.append(prefix);
1290 sb.append(" Kernel Wake lock ");
1291 sb.append(ent.getKey());
1292 linePrefix = printWakeLock(sb, ent.getValue(), batteryRealtime, null, which,
1293 linePrefix);
1294 if (!linePrefix.equals(": ")) {
1295 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001296 // Only print out wake locks that were held
1297 pw.println(sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001298 }
Evan Millarc64edde2009-04-18 12:26:32 -07001299 }
Evan Millarc64edde2009-04-18 12:26:32 -07001300 }
1301 }
1302
Evan Millar22ac0432009-03-31 11:33:18 -07001303 for (int iu = 0; iu < NU; iu++) {
1304 Uid u = uidStats.valueAt(iu);
1305 rxTotal += u.getTcpBytesReceived(which);
1306 txTotal += u.getTcpBytesSent(which);
1307
1308 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1309 if (wakelocks.size() > 0) {
1310 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1311 : wakelocks.entrySet()) {
1312 Uid.Wakelock wl = ent.getValue();
1313
1314 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1315 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001316 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001317 batteryRealtime, which);
1318 }
1319
1320 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1321 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001322 partialWakeLockTimeTotalMicros += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001323 batteryRealtime, which);
1324 }
1325 }
1326 }
1327 }
1328
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001329 pw.print(prefix);
1330 pw.print(" Total received: "); pw.print(formatBytesLocked(rxTotal));
1331 pw.print(", Total sent: "); pw.println(formatBytesLocked(txTotal));
1332 sb.setLength(0);
1333 sb.append(prefix);
1334 sb.append(" Total full wakelock time: "); formatTimeMs(sb,
1335 (fullWakeLockTimeTotalMicros + 500) / 1000);
1336 sb.append(", Total partial waklock time: "); formatTimeMs(sb,
1337 (partialWakeLockTimeTotalMicros + 500) / 1000);
1338 pw.println(sb.toString());
Evan Millar22ac0432009-03-31 11:33:18 -07001339
Dianne Hackborn627bba72009-03-24 22:32:56 -07001340 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001341 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001342 sb.append(" Signal levels: ");
1343 didOne = false;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001344 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1345 final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which);
1346 if (time == 0) {
1347 continue;
1348 }
1349 if (didOne) sb.append(", ");
1350 didOne = true;
1351 sb.append(SIGNAL_STRENGTH_NAMES[i]);
1352 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001353 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001354 sb.append("(");
1355 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001356 sb.append(") ");
1357 sb.append(getPhoneSignalStrengthCount(i, which));
1358 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001359 }
1360 if (!didOne) sb.append("No activity");
1361 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07001362
1363 sb.setLength(0);
1364 sb.append(prefix);
1365 sb.append(" Signal scanning time: ");
1366 formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
1367 pw.println(sb.toString());
1368
Dianne Hackborn627bba72009-03-24 22:32:56 -07001369 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001370 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001371 sb.append(" Radio types: ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001372 didOne = false;
1373 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1374 final long time = getPhoneDataConnectionTime(i, batteryRealtime, which);
1375 if (time == 0) {
1376 continue;
1377 }
1378 if (didOne) sb.append(", ");
1379 didOne = true;
1380 sb.append(DATA_CONNECTION_NAMES[i]);
1381 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001382 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001383 sb.append("(");
1384 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001385 sb.append(") ");
1386 sb.append(getPhoneDataConnectionCount(i, which));
1387 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001388 }
1389 if (!didOne) sb.append("No activity");
1390 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07001391
1392 sb.setLength(0);
1393 sb.append(prefix);
1394 sb.append(" Radio data uptime when unplugged: ");
1395 sb.append(getRadioDataUptime() / 1000);
1396 sb.append(" ms");
1397 pw.println(sb.toString());
1398
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001399 sb.setLength(0);
1400 sb.append(prefix);
1401 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
1402 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
1403 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
1404 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
1405 sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
1406 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
1407 sb.append(")");
1408 pw.println(sb.toString());
Dianne Hackborn617f8772009-03-31 15:04:46 -07001409
The Android Open Source Project10592532009-03-18 17:39:46 -07001410 pw.println(" ");
1411
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001412 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001413 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001414 pw.print(prefix); pw.println(" Device is currently unplugged");
1415 pw.print(prefix); pw.print(" Discharge cycle start level: ");
1416 pw.println(getDischargeStartLevel());
1417 pw.print(prefix); pw.print(" Discharge cycle current level: ");
1418 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07001419 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001420 pw.print(prefix); pw.println(" Device is currently plugged into power");
1421 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
1422 pw.println(getDischargeStartLevel());
1423 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
1424 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001425 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001426 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001427 } else {
1428 pw.print(prefix); pw.println(" Device battery use since last full charge");
1429 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
1430 pw.println(getLowDischargeAmountSinceCharge());
1431 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
1432 pw.println(getHighDischargeAmountSinceCharge());
1433 pw.println(" ");
The Android Open Source Project10592532009-03-18 17:39:46 -07001434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435
Evan Millar22ac0432009-03-31 11:33:18 -07001436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 for (int iu=0; iu<NU; iu++) {
1438 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001439 if (reqUid >= 0 && uid != reqUid) {
1440 continue;
1441 }
1442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 Uid u = uidStats.valueAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 pw.println(prefix + " #" + uid + ":");
1446 boolean uidActivity = false;
1447
1448 long tcpReceived = u.getTcpBytesReceived(which);
1449 long tcpSent = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001450 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1451 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001452 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 if (tcpReceived != 0 || tcpSent != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001455 pw.print(prefix); pw.print(" Network: ");
1456 pw.print(formatBytesLocked(tcpReceived)); pw.print(" received, ");
1457 pw.print(formatBytesLocked(tcpSent)); pw.println(" sent");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001459
1460 if (u.hasUserActivity()) {
1461 boolean hasData = false;
1462 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1463 int val = u.getUserActivityCount(i, which);
1464 if (val != 0) {
1465 if (!hasData) {
1466 sb.setLength(0);
1467 sb.append(" User activity: ");
1468 hasData = true;
1469 } else {
1470 sb.append(", ");
1471 }
1472 sb.append(val);
1473 sb.append(" ");
1474 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
1475 }
1476 }
1477 if (hasData) {
1478 pw.println(sb.toString());
1479 }
1480 }
1481
1482 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001483 || uidWifiRunningTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001484 sb.setLength(0);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001485 sb.append(prefix); sb.append(" Wifi Running: ");
1486 formatTimeMs(sb, uidWifiRunningTime / 1000);
1487 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001488 whichBatteryRealtime)); sb.append(")\n");
1489 sb.append(prefix); sb.append(" Full Wifi Lock: ");
1490 formatTimeMs(sb, fullWifiLockOnTime / 1000);
1491 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
1492 whichBatteryRealtime)); sb.append(")\n");
1493 sb.append(prefix); sb.append(" Scan Wifi Lock: ");
1494 formatTimeMs(sb, scanWifiLockOnTime / 1000);
1495 sb.append("("); sb.append(formatRatioLocked(scanWifiLockOnTime,
1496 whichBatteryRealtime)); sb.append(")");
1497 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499
1500 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1501 if (wakelocks.size() > 0) {
1502 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1503 : wakelocks.entrySet()) {
1504 Uid.Wakelock wl = ent.getValue();
1505 String linePrefix = ": ";
1506 sb.setLength(0);
1507 sb.append(prefix);
1508 sb.append(" Wake lock ");
1509 sb.append(ent.getKey());
1510 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime,
1511 "full", which, linePrefix);
1512 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime,
1513 "partial", which, linePrefix);
1514 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime,
1515 "window", which, linePrefix);
1516 if (!linePrefix.equals(": ")) {
1517 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001518 // Only print out wake locks that were held
1519 pw.println(sb.toString());
1520 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 }
1523 }
1524
1525 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1526 if (sensors.size() > 0) {
1527 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1528 : sensors.entrySet()) {
1529 Uid.Sensor se = ent.getValue();
1530 int sensorNumber = ent.getKey();
1531 sb.setLength(0);
1532 sb.append(prefix);
1533 sb.append(" Sensor ");
1534 int handle = se.getHandle();
1535 if (handle == Uid.Sensor.GPS) {
1536 sb.append("GPS");
1537 } else {
1538 sb.append(handle);
1539 }
1540 sb.append(": ");
1541
1542 Timer timer = se.getSensorTime();
1543 if (timer != null) {
1544 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001545 long totalTime = (timer.getTotalTimeLocked(
1546 batteryRealtime, which) + 500) / 1000;
1547 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 //timer.logState();
1549 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001550 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 sb.append("realtime (");
1552 sb.append(count);
1553 sb.append(" times)");
1554 } else {
1555 sb.append("(not used)");
1556 }
1557 } else {
1558 sb.append("(not used)");
1559 }
1560
1561 pw.println(sb.toString());
1562 uidActivity = true;
1563 }
1564 }
1565
1566 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1567 if (processStats.size() > 0) {
1568 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1569 : processStats.entrySet()) {
1570 Uid.Proc ps = ent.getValue();
1571 long userTime;
1572 long systemTime;
1573 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001574 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575
1576 userTime = ps.getUserTime(which);
1577 systemTime = ps.getSystemTime(which);
1578 starts = ps.getStarts(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001579 numExcessive = which == STATS_SINCE_CHARGED
1580 ? ps.countExcessiveWakes() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001582 if (userTime != 0 || systemTime != 0 || starts != 0
1583 || numExcessive != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001584 sb.setLength(0);
1585 sb.append(prefix); sb.append(" Proc ");
1586 sb.append(ent.getKey()); sb.append(":\n");
1587 sb.append(prefix); sb.append(" CPU: ");
1588 formatTime(sb, userTime); sb.append("usr + ");
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001589 formatTime(sb, systemTime); sb.append("krn");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001590 if (starts != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001591 sb.append("\n"); sb.append(prefix); sb.append(" ");
1592 sb.append(starts); sb.append(" proc starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001593 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001594 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001595 for (int e=0; e<numExcessive; e++) {
1596 Uid.Proc.ExcessiveWake ew = ps.getExcessiveWake(e);
1597 if (ew != null) {
1598 pw.print(prefix); pw.print(" * Killed for wake lock use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07001599 TimeUtils.formatDuration(ew.usedTime, pw);
1600 pw.print(" over ");
1601 TimeUtils.formatDuration(ew.overTime, pw);
1602 pw.print(" (");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001603 pw.print((ew.usedTime*100)/ew.overTime);
1604 pw.println("%)");
1605 }
1606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 uidActivity = true;
1608 }
1609 }
1610 }
1611
1612 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1613 if (packageStats.size() > 0) {
1614 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1615 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001616 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 boolean apkActivity = false;
1618 Uid.Pkg ps = ent.getValue();
1619 int wakeups = ps.getWakeups(which);
1620 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001621 pw.print(prefix); pw.print(" ");
1622 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 apkActivity = true;
1624 }
1625 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1626 if (serviceStats.size() > 0) {
1627 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1628 : serviceStats.entrySet()) {
1629 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1630 long startTime = ss.getStartTime(batteryUptime, which);
1631 int starts = ss.getStarts(which);
1632 int launches = ss.getLaunches(which);
1633 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001634 sb.setLength(0);
1635 sb.append(prefix); sb.append(" Service ");
1636 sb.append(sent.getKey()); sb.append(":\n");
1637 sb.append(prefix); sb.append(" Created for: ");
1638 formatTimeMs(sb, startTime / 1000);
1639 sb.append(" uptime\n");
1640 sb.append(prefix); sb.append(" Starts: ");
1641 sb.append(starts);
1642 sb.append(", launches: "); sb.append(launches);
1643 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 apkActivity = true;
1645 }
1646 }
1647 }
1648 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001649 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 }
1651 uidActivity = true;
1652 }
1653 }
1654 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001655 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
1657 }
1658 }
1659
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001660 void printBitDescriptions(PrintWriter pw, int oldval, int newval, BitDescription[] descriptions) {
1661 int diff = oldval ^ newval;
1662 if (diff == 0) return;
1663 for (int i=0; i<descriptions.length; i++) {
1664 BitDescription bd = descriptions[i];
1665 if ((diff&bd.mask) != 0) {
1666 if (bd.shift < 0) {
1667 pw.print((newval&bd.mask) != 0 ? " +" : " -");
1668 pw.print(bd.name);
1669 } else {
1670 pw.print(" ");
1671 pw.print(bd.name);
1672 pw.print("=");
1673 int val = (newval&bd.mask)>>bd.shift;
1674 if (bd.values != null && val >= 0 && val < bd.values.length) {
1675 pw.print(bd.values[val]);
1676 } else {
1677 pw.print(val);
1678 }
1679 }
1680 }
1681 }
1682 }
1683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 /**
1685 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
1686 *
1687 * @param pw a Printer to receive the dump output.
1688 */
1689 @SuppressWarnings("unused")
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001690 public void dumpLocked(PrintWriter pw) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001691 HistoryItem rec = getHistory();
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001692 if (rec != null) {
1693 pw.println("Battery History:");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001694 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001695 int oldState = 0;
1696 int oldStatus = -1;
1697 int oldHealth = -1;
1698 int oldPlug = -1;
1699 int oldTemp = -1;
1700 int oldVolt = -1;
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001701 while (rec != null) {
1702 pw.print(" ");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001703 TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001704 pw.print(" ");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001705 if (rec.cmd == HistoryItem.CMD_START) {
1706 pw.println(" START");
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001707 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
1708 pw.println(" *OVERFLOW*");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001709 } else {
1710 if (rec.batteryLevel < 10) pw.print("00");
1711 else if (rec.batteryLevel < 100) pw.print("0");
1712 pw.print(rec.batteryLevel);
1713 pw.print(" ");
1714 if (rec.states < 0x10) pw.print("0000000");
1715 else if (rec.states < 0x100) pw.print("000000");
1716 else if (rec.states < 0x1000) pw.print("00000");
1717 else if (rec.states < 0x10000) pw.print("0000");
1718 else if (rec.states < 0x100000) pw.print("000");
1719 else if (rec.states < 0x1000000) pw.print("00");
1720 else if (rec.states < 0x10000000) pw.print("0");
1721 pw.print(Integer.toHexString(rec.states));
1722 if (oldStatus != rec.batteryStatus) {
1723 oldStatus = rec.batteryStatus;
1724 pw.print(" status=");
1725 switch (oldStatus) {
1726 case BatteryManager.BATTERY_STATUS_UNKNOWN:
1727 pw.print("unknown");
1728 break;
1729 case BatteryManager.BATTERY_STATUS_CHARGING:
1730 pw.print("charging");
1731 break;
1732 case BatteryManager.BATTERY_STATUS_DISCHARGING:
1733 pw.print("discharging");
1734 break;
1735 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
1736 pw.print("not-charging");
1737 break;
1738 case BatteryManager.BATTERY_STATUS_FULL:
1739 pw.print("full");
1740 break;
1741 default:
1742 pw.print(oldStatus);
1743 break;
1744 }
1745 }
1746 if (oldHealth != rec.batteryHealth) {
1747 oldHealth = rec.batteryHealth;
1748 pw.print(" health=");
1749 switch (oldHealth) {
1750 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
1751 pw.print("unknown");
1752 break;
1753 case BatteryManager.BATTERY_HEALTH_GOOD:
1754 pw.print("good");
1755 break;
1756 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
1757 pw.print("overheat");
1758 break;
1759 case BatteryManager.BATTERY_HEALTH_DEAD:
1760 pw.print("dead");
1761 break;
1762 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
1763 pw.print("over-voltage");
1764 break;
1765 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
1766 pw.print("failure");
1767 break;
1768 default:
1769 pw.print(oldHealth);
1770 break;
1771 }
1772 }
1773 if (oldPlug != rec.batteryPlugType) {
1774 oldPlug = rec.batteryPlugType;
1775 pw.print(" plug=");
1776 switch (oldPlug) {
1777 case 0:
1778 pw.print("none");
1779 break;
1780 case BatteryManager.BATTERY_PLUGGED_AC:
1781 pw.print("ac");
1782 break;
1783 case BatteryManager.BATTERY_PLUGGED_USB:
1784 pw.print("usb");
1785 break;
1786 default:
1787 pw.print(oldPlug);
1788 break;
1789 }
1790 }
1791 if (oldTemp != rec.batteryTemperature) {
1792 oldTemp = rec.batteryTemperature;
1793 pw.print(" temp=");
1794 pw.print(oldTemp);
1795 }
1796 if (oldVolt != rec.batteryVoltage) {
1797 oldVolt = rec.batteryVoltage;
1798 pw.print(" volt=");
1799 pw.print(oldVolt);
1800 }
1801 printBitDescriptions(pw, oldState, rec.states,
1802 HISTORY_STATE_DESCRIPTIONS);
1803 pw.println();
1804 }
1805 oldState = rec.states;
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001806 rec = rec.next;
1807 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001808 pw.println("");
1809 }
1810
1811 SparseArray<? extends Uid> uidStats = getUidStats();
1812 final int NU = uidStats.size();
1813 boolean didPid = false;
1814 long nowRealtime = SystemClock.elapsedRealtime();
1815 StringBuilder sb = new StringBuilder(64);
1816 for (int i=0; i<NU; i++) {
1817 Uid uid = uidStats.valueAt(i);
1818 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
1819 if (pids != null) {
1820 for (int j=0; j<pids.size(); j++) {
1821 Uid.Pid pid = pids.valueAt(j);
1822 if (!didPid) {
1823 pw.println("Per-PID Stats:");
1824 didPid = true;
1825 }
1826 long time = pid.mWakeSum + (pid.mWakeStart != 0
1827 ? (nowRealtime - pid.mWakeStart) : 0);
1828 pw.print(" PID "); pw.print(pids.keyAt(j));
1829 pw.print(" wake time: ");
1830 TimeUtils.formatDuration(time, pw);
1831 pw.println("");
1832 }
1833 }
1834 }
1835 if (didPid) {
1836 pw.println("");
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001837 }
1838
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001839 pw.println("Statistics since last charge:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 pw.println(" System starts: " + getStartCount()
1841 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001842 dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 pw.println("");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001844 pw.println("Statistics since last unplugged:");
1845 dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 }
1847
1848 @SuppressWarnings("unused")
1849 public void dumpCheckinLocked(PrintWriter pw, String[] args) {
1850 boolean isUnpluggedOnly = false;
1851
1852 for (String arg : args) {
1853 if ("-u".equals(arg)) {
1854 if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data");
1855 isUnpluggedOnly = true;
1856 }
1857 }
1858
1859 if (isUnpluggedOnly) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001860 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 }
1862 else {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001863 dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
1864 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 }
1866 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867}