blob: 4adeaeb217c8a0aac5fac7cb67b4cbcccd13f71d [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;
26
27/**
28 * A class providing access to battery usage statistics, including information on
29 * wakelocks, processes, packages, and services. All times are represented in microseconds
30 * except where indicated otherwise.
31 * @hide
32 */
33public abstract class BatteryStats implements Parcelable {
34
35 private static final boolean LOCAL_LOGV = false;
36
37 /**
38 * A constant indicating a partial wake lock timer.
39 */
40 public static final int WAKE_TYPE_PARTIAL = 0;
41
42 /**
43 * A constant indicating a full wake lock timer.
44 */
45 public static final int WAKE_TYPE_FULL = 1;
46
47 /**
48 * A constant indicating a window wake lock timer.
49 */
50 public static final int WAKE_TYPE_WINDOW = 2;
51
52 /**
53 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
55 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070056
57 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -070058 * A constant indicating a a wifi turn on timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070059 */
60 public static final int WIFI_TURNED_ON = 4;
61
62 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070063 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070064 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070065 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070066
67 /**
68 * A constant indicating a scan wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070069 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070070 public static final int SCAN_WIFI_LOCK = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
Robert Greenwalt5347bd42009-05-13 15:10:16 -070072 /**
73 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070074 */
75 public static final int WIFI_MULTICAST_ENABLED = 7;
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070078 * A constant indicating an audio turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070079 */
80 public static final int AUDIO_TURNED_ON = 7;
81
82 /**
83 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070084 */
85 public static final int VIDEO_TURNED_ON = 8;
86
87 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 * Include all of the data in the stats, including previously saved data.
89 */
90 public static final int STATS_TOTAL = 0;
91
92 /**
93 * Include only the last run in the stats.
94 */
95 public static final int STATS_LAST = 1;
96
97 /**
98 * Include only the current run in the stats.
99 */
100 public static final int STATS_CURRENT = 2;
101
102 /**
103 * Include only the run since the last time the device was unplugged in the stats.
104 */
105 public static final int STATS_UNPLUGGED = 3;
Evan Millare84de8d2009-04-02 22:16:12 -0700106
107 // NOTE: Update this list if you add/change any stats above.
108 // These characters are supposed to represent "total", "last", "current",
109 // and "unplugged". They were shortened for effeciency sake.
110 private static final String[] STAT_NAMES = { "t", "l", "c", "u" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111
112 /**
113 * Bump the version on this if the checkin format changes.
114 */
Evan Millarc64edde2009-04-18 12:26:32 -0700115 private static final int BATTERY_STATS_CHECKIN_VERSION = 5;
Evan Millar22ac0432009-03-31 11:33:18 -0700116
117 private static final long BYTES_PER_KB = 1024;
118 private static final long BYTES_PER_MB = 1048576; // 1024^2
119 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
122 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700123 private static final String PROCESS_DATA = "pr";
124 private static final String SENSOR_DATA = "sr";
125 private static final String WAKELOCK_DATA = "wl";
Evan Millarc64edde2009-04-18 12:26:32 -0700126 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Evan Millare84de8d2009-04-02 22:16:12 -0700127 private static final String NETWORK_DATA = "nt";
128 private static final String USER_ACTIVITY_DATA = "ua";
129 private static final String BATTERY_DATA = "bt";
130 private static final String BATTERY_LEVEL_DATA = "lv";
131 private static final String WIFI_LOCK_DATA = "wfl";
132 private static final String MISC_DATA = "m";
133 private static final String SCREEN_BRIGHTNESS_DATA = "br";
134 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700135 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700136 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
137 private static final String DATA_CONNECTION_TIME_DATA = "dct";
138 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700140 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 private final Formatter mFormatter = new Formatter(mFormatBuilder);
142
143 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700144 * State for keeping track of counting information.
145 */
146 public static abstract class Counter {
147
148 /**
149 * Returns the count associated with this Counter for the
150 * selected type of statistics.
151 *
152 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
153 */
Evan Millarc64edde2009-04-18 12:26:32 -0700154 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700155
156 /**
157 * Temporary for debugging.
158 */
159 public abstract void logState(Printer pw, String prefix);
160 }
161
162 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 * State for keeping track of timing information.
164 */
165 public static abstract class Timer {
166
167 /**
168 * Returns the count associated with this Timer for the
169 * selected type of statistics.
170 *
171 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
172 */
Evan Millarc64edde2009-04-18 12:26:32 -0700173 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174
175 /**
176 * Returns the total time in microseconds associated with this Timer for the
177 * selected type of statistics.
178 *
179 * @param batteryRealtime system realtime on battery in microseconds
180 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
181 * @return a time in microseconds
182 */
Evan Millarc64edde2009-04-18 12:26:32 -0700183 public abstract long getTotalTimeLocked(long batteryRealtime, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /**
186 * Temporary for debugging.
187 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700188 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 }
190
191 /**
192 * The statistics associated with a particular uid.
193 */
194 public static abstract class Uid {
195
196 /**
197 * Returns a mapping containing wakelock statistics.
198 *
199 * @return a Map from Strings to Uid.Wakelock objects.
200 */
201 public abstract Map<String, ? extends Wakelock> getWakelockStats();
202
203 /**
204 * The statistics associated with a particular wake lock.
205 */
206 public static abstract class Wakelock {
207 public abstract Timer getWakeTime(int type);
208 }
209
210 /**
211 * Returns a mapping containing sensor statistics.
212 *
213 * @return a Map from Integer sensor ids to Uid.Sensor objects.
214 */
215 public abstract Map<Integer, ? extends Sensor> getSensorStats();
216
217 /**
218 * Returns a mapping containing process statistics.
219 *
220 * @return a Map from Strings to Uid.Proc objects.
221 */
222 public abstract Map<String, ? extends Proc> getProcessStats();
223
224 /**
225 * Returns a mapping containing package statistics.
226 *
227 * @return a Map from Strings to Uid.Pkg objects.
228 */
229 public abstract Map<String, ? extends Pkg> getPackageStats();
230
231 /**
232 * {@hide}
233 */
234 public abstract int getUid();
235
236 /**
237 * {@hide}
238 */
239 public abstract long getTcpBytesReceived(int which);
240
241 /**
242 * {@hide}
243 */
244 public abstract long getTcpBytesSent(int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700245
Dianne Hackborn617f8772009-03-31 15:04:46 -0700246 public abstract void noteWifiTurnedOnLocked();
247 public abstract void noteWifiTurnedOffLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700248 public abstract void noteFullWifiLockAcquiredLocked();
249 public abstract void noteFullWifiLockReleasedLocked();
250 public abstract void noteScanWifiLockAcquiredLocked();
251 public abstract void noteScanWifiLockReleasedLocked();
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700252 public abstract void noteWifiMulticastEnabledLocked();
253 public abstract void noteWifiMulticastDisabledLocked();
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700254 public abstract void noteAudioTurnedOnLocked();
255 public abstract void noteAudioTurnedOffLocked();
256 public abstract void noteVideoTurnedOnLocked();
257 public abstract void noteVideoTurnedOffLocked();
Dianne Hackborn617f8772009-03-31 15:04:46 -0700258 public abstract long getWifiTurnedOnTime(long batteryRealtime, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700259 public abstract long getFullWifiLockTime(long batteryRealtime, int which);
260 public abstract long getScanWifiLockTime(long batteryRealtime, int which);
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700261 public abstract long getWifiMulticastTime(long batteryRealtime,
262 int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700263 public abstract long getAudioTurnedOnTime(long batteryRealtime, int which);
264 public abstract long getVideoTurnedOnTime(long batteryRealtime, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265
Dianne Hackborn617f8772009-03-31 15:04:46 -0700266 /**
267 * Note that these must match the constants in android.os.LocalPowerManager.
268 */
269 static final String[] USER_ACTIVITY_TYPES = {
270 "other", "cheek", "touch", "long_touch", "touch_up", "button", "unknown"
271 };
272
273 public static final int NUM_USER_ACTIVITY_TYPES = 7;
274
275 public abstract void noteUserActivityLocked(int type);
276 public abstract boolean hasUserActivity();
277 public abstract int getUserActivityCount(int type, int which);
278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 public static abstract class Sensor {
280 // Magic sensor number for the GPS.
281 public static final int GPS = -10000;
282
283 public abstract int getHandle();
284
285 public abstract Timer getSensorTime();
286 }
287
288 /**
289 * The statistics associated with a particular process.
290 */
291 public static abstract class Proc {
292
293 /**
294 * Returns the total time (in 1/100 sec) spent executing in user code.
295 *
296 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
297 */
298 public abstract long getUserTime(int which);
299
300 /**
301 * Returns the total time (in 1/100 sec) spent executing in system code.
302 *
303 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
304 */
305 public abstract long getSystemTime(int which);
306
307 /**
308 * Returns the number of times the process has been started.
309 *
310 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
311 */
312 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700313
314 /**
315 * Returns the cpu time spent in microseconds while the process was in the foreground.
316 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
317 * @return foreground cpu time in microseconds
318 */
319 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700320
321 /**
322 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
323 * @param speedStep the index of the CPU speed. This is not the actual speed of the
324 * CPU.
325 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
326 * @see BatteryStats#getCpuSpeedSteps()
327 */
328 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 }
330
331 /**
332 * The statistics associated with a particular package.
333 */
334 public static abstract class Pkg {
335
336 /**
337 * Returns the number of times this package has done something that could wake up the
338 * device from sleep.
339 *
340 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
341 */
342 public abstract int getWakeups(int which);
343
344 /**
345 * Returns a mapping containing service statistics.
346 */
347 public abstract Map<String, ? extends Serv> getServiceStats();
348
349 /**
350 * The statistics associated with a particular service.
351 */
352 public abstract class Serv {
353
354 /**
355 * Returns the amount of time spent started.
356 *
357 * @param batteryUptime elapsed uptime on battery in microseconds.
358 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
359 * @return
360 */
361 public abstract long getStartTime(long batteryUptime, int which);
362
363 /**
364 * Returns the total number of times startService() has been called.
365 *
366 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
367 */
368 public abstract int getStarts(int which);
369
370 /**
371 * Returns the total number times the service has been launched.
372 *
373 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
374 */
375 public abstract int getLaunches(int which);
376 }
377 }
378 }
379
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700380 public final class BatteryHistoryRecord implements Parcelable {
381 public BatteryHistoryRecord next;
382
383 public long time;
384 public byte batteryLevel;
385
386 public static final int STATE_SCREEN_MASK = 0x000000f;
387 public static final int STATE_SCREEN_SHIFT = 0;
388 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0;
389 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
390 public static final int STATE_PHONE_STATE_MASK = 0x0000f00;
391 public static final int STATE_PHONE_STATE_SHIFT = 8;
392 public static final int STATE_DATA_CONNECTION_MASK = 0x000f000;
393 public static final int STATE_DATA_CONNECTION_SHIFT = 12;
394
395 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30;
396 public static final int STATE_SCREEN_ON_FLAG = 1<<29;
397 public static final int STATE_GPS_ON_FLAG = 1<<28;
398 public static final int STATE_PHONE_ON_FLAG = 1<<27;
399 public static final int STATE_WIFI_ON_FLAG = 1<<26;
400 public static final int STATE_WIFI_RUNNING_FLAG = 1<<25;
401 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<24;
402 public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<23;
403 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<22;
404 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<21;
405 public static final int STATE_AUDIO_ON_FLAG = 1<<20;
406 public static final int STATE_VIDEO_ON_FLAG = 1<<19;
407
408 public int states;
409
410 public BatteryHistoryRecord() {
411 }
412
413 public BatteryHistoryRecord(long time, Parcel src) {
414 this.time = time;
415 batteryLevel = (byte)src.readInt();
416 states = src.readInt();
417 }
418
419 public int describeContents() {
420 return 0;
421 }
422
423 public void writeToParcel(Parcel dest, int flags) {
424 dest.writeLong(time);
425 dest.writeInt(batteryLevel);
426 dest.writeInt(states);
427 }
428 }
429
430 /**
431 * Return the current history of battery state changes.
432 */
433 public abstract BatteryHistoryRecord getHistory();
434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 /**
436 * Returns the number of times the device has been started.
437 */
438 public abstract int getStartCount();
439
440 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700441 * 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 -0800442 * running on battery.
443 *
444 * {@hide}
445 */
446 public abstract long getScreenOnTime(long batteryRealtime, int which);
447
Dianne Hackborn617f8772009-03-31 15:04:46 -0700448 public static final int SCREEN_BRIGHTNESS_DARK = 0;
449 public static final int SCREEN_BRIGHTNESS_DIM = 1;
450 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
451 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
452 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
453
454 static final String[] SCREEN_BRIGHTNESS_NAMES = {
455 "dark", "dim", "medium", "light", "bright"
456 };
457
458 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
459
460 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700461 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700462 * the given brightness
463 *
464 * {@hide}
465 */
466 public abstract long getScreenBrightnessTime(int brightnessBin,
467 long batteryRealtime, int which);
468
469 public abstract int getInputEventCount(int which);
470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700472 * 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 -0800473 * running on battery.
474 *
475 * {@hide}
476 */
477 public abstract long getPhoneOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700478
Dianne Hackborn627bba72009-03-24 22:32:56 -0700479 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
480 public static final int SIGNAL_STRENGTH_POOR = 1;
481 public static final int SIGNAL_STRENGTH_MODERATE = 2;
482 public static final int SIGNAL_STRENGTH_GOOD = 3;
483 public static final int SIGNAL_STRENGTH_GREAT = 4;
484
485 static final String[] SIGNAL_STRENGTH_NAMES = {
486 "none", "poor", "moderate", "good", "great"
487 };
488
489 public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
490
491 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700492 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700493 * the given signal strength.
494 *
495 * {@hide}
496 */
497 public abstract long getPhoneSignalStrengthTime(int strengthBin,
498 long batteryRealtime, int which);
499
Dianne Hackborn617f8772009-03-31 15:04:46 -0700500 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -0700501 * Returns the time in microseconds that the phone has been trying to
502 * acquire a signal.
503 *
504 * {@hide}
505 */
506 public abstract long getPhoneSignalScanningTime(
507 long batteryRealtime, int which);
508
509 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700510 * Returns the number of times the phone has entered the given signal strength.
511 *
512 * {@hide}
513 */
514 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
515
Dianne Hackborn627bba72009-03-24 22:32:56 -0700516 public static final int DATA_CONNECTION_NONE = 0;
517 public static final int DATA_CONNECTION_GPRS = 1;
518 public static final int DATA_CONNECTION_EDGE = 2;
519 public static final int DATA_CONNECTION_UMTS = 3;
520 public static final int DATA_CONNECTION_OTHER = 4;
521
522 static final String[] DATA_CONNECTION_NAMES = {
523 "none", "gprs", "edge", "umts", "other"
524 };
525
526 public static final int NUM_DATA_CONNECTION_TYPES = 5;
527
528 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700529 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700530 * the given data connection.
531 *
532 * {@hide}
533 */
534 public abstract long getPhoneDataConnectionTime(int dataType,
535 long batteryRealtime, int which);
536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700538 * Returns the number of times the phone has entered the given data
539 * connection type.
540 *
541 * {@hide}
542 */
543 public abstract int getPhoneDataConnectionCount(int dataType, int which);
544
545 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700546 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700547 * running on battery.
548 *
549 * {@hide}
550 */
551 public abstract long getWifiOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700552
553 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700554 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700555 * been in the running state while the device was running on battery.
556 *
557 * {@hide}
558 */
559 public abstract long getWifiRunningTime(long batteryRealtime, int which);
560
The Android Open Source Project10592532009-03-18 17:39:46 -0700561 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700562 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700563 * running on battery.
564 *
565 * {@hide}
566 */
567 public abstract long getBluetoothOnTime(long batteryRealtime, int which);
568
569 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 * Return whether we are currently running on battery.
571 */
572 public abstract boolean getIsOnBattery();
573
574 /**
575 * Returns a SparseArray containing the statistics for each uid.
576 */
577 public abstract SparseArray<? extends Uid> getUidStats();
578
579 /**
580 * Returns the current battery uptime in microseconds.
581 *
582 * @param curTime the amount of elapsed realtime in microseconds.
583 */
584 public abstract long getBatteryUptime(long curTime);
585
586 /**
Amith Yamasani3f7e35c2009-07-13 16:02:45 -0700587 * @deprecated use getRadioDataUptime
588 */
589 public long getRadioDataUptimeMs() {
590 return getRadioDataUptime() / 1000;
591 }
592
593 /**
594 * Returns the time that the radio was on for data transfers.
595 * @return the uptime in microseconds while unplugged
596 */
597 public abstract long getRadioDataUptime();
598
599 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 * Returns the current battery realtime in microseconds.
601 *
602 * @param curTime the amount of elapsed realtime in microseconds.
603 */
604 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -0700605
606 /**
Evan Millar633a1742009-04-02 16:36:33 -0700607 * Returns the battery percentage level at the last time the device was unplugged from power, or
608 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -0700609 */
Evan Millar633a1742009-04-02 16:36:33 -0700610 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -0700611
612 /**
Evan Millar633a1742009-04-02 16:36:33 -0700613 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
614 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -0700615 */
Evan Millar633a1742009-04-02 16:36:33 -0700616 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617
618 /**
619 * Returns the total, last, or current battery uptime in microseconds.
620 *
621 * @param curTime the elapsed realtime in microseconds.
622 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
623 */
624 public abstract long computeBatteryUptime(long curTime, int which);
625
626 /**
627 * Returns the total, last, or current battery realtime in microseconds.
628 *
629 * @param curTime the current elapsed realtime in microseconds.
630 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
631 */
632 public abstract long computeBatteryRealtime(long curTime, int which);
633
634 /**
635 * Returns the total, last, or current uptime in microseconds.
636 *
637 * @param curTime the current elapsed realtime in microseconds.
638 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
639 */
640 public abstract long computeUptime(long curTime, int which);
641
642 /**
643 * Returns the total, last, or current realtime in microseconds.
644 * *
645 * @param curTime the current elapsed realtime in microseconds.
646 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
647 */
648 public abstract long computeRealtime(long curTime, int which);
Evan Millarc64edde2009-04-18 12:26:32 -0700649
650 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651
Amith Yamasanie43530a2009-08-21 13:11:37 -0700652 /** Returns the number of different speeds that the CPU can run at */
653 public abstract int getCpuSpeedSteps();
654
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700655 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 long days = seconds / (60 * 60 * 24);
657 if (days != 0) {
658 out.append(days);
659 out.append("d ");
660 }
661 long used = days * 60 * 60 * 24;
662
663 long hours = (seconds - used) / (60 * 60);
664 if (hours != 0 || used != 0) {
665 out.append(hours);
666 out.append("h ");
667 }
668 used += hours * 60 * 60;
669
670 long mins = (seconds-used) / 60;
671 if (mins != 0 || used != 0) {
672 out.append(mins);
673 out.append("m ");
674 }
675 used += mins * 60;
676
677 if (seconds != 0 || used != 0) {
678 out.append(seconds-used);
679 out.append("s ");
680 }
681 }
682
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700683 private final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700685 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 sb.append((time - (sec * 100)) * 10);
687 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 }
689
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700690 private final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700692 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 sb.append(time - (sec * 1000));
694 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 }
696
697 private final String formatRatioLocked(long num, long den) {
698 if (den == 0L) {
699 return "---%";
700 }
701 float perc = ((float)num) / ((float)den) * 100;
702 mFormatBuilder.setLength(0);
703 mFormatter.format("%.1f%%", perc);
704 return mFormatBuilder.toString();
705 }
706
Evan Millar22ac0432009-03-31 11:33:18 -0700707 private final String formatBytesLocked(long bytes) {
708 mFormatBuilder.setLength(0);
709
710 if (bytes < BYTES_PER_KB) {
711 return bytes + "B";
712 } else if (bytes < BYTES_PER_MB) {
713 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
714 return mFormatBuilder.toString();
715 } else if (bytes < BYTES_PER_GB){
716 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
717 return mFormatBuilder.toString();
718 } else {
719 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
720 return mFormatBuilder.toString();
721 }
722 }
723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 /**
725 *
726 * @param sb a StringBuilder object.
727 * @param timer a Timer object contining the wakelock times.
728 * @param batteryRealtime the current on-battery time in microseconds.
729 * @param name the name of the wakelock.
730 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
731 * @param linePrefix a String to be prepended to each line of output.
732 * @return the line prefix
733 */
734 private static final String printWakeLock(StringBuilder sb, Timer timer,
735 long batteryRealtime, String name, int which, String linePrefix) {
736
737 if (timer != null) {
738 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -0700739 long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
741
Evan Millarc64edde2009-04-18 12:26:32 -0700742 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 if (totalTimeMillis != 0) {
744 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700745 formatTimeMs(sb, totalTimeMillis);
746 if (name != null) sb.append(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 sb.append(' ');
748 sb.append('(');
749 sb.append(count);
750 sb.append(" times)");
751 return ", ";
752 }
753 }
754 return linePrefix;
755 }
756
757 /**
758 * Checkin version of wakelock printer. Prints simple comma-separated list.
759 *
760 * @param sb a StringBuilder object.
761 * @param timer a Timer object contining the wakelock times.
762 * @param now the current time in microseconds.
763 * @param name the name of the wakelock.
764 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
765 * @param linePrefix a String to be prepended to each line of output.
766 * @return the line prefix
767 */
768 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now,
Evan Millarc64edde2009-04-18 12:26:32 -0700769 String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 long totalTimeMicros = 0;
771 int count = 0;
772 if (timer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700773 totalTimeMicros = timer.getTotalTimeLocked(now, which);
774 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
776 sb.append(linePrefix);
777 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
778 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -0700779 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 sb.append(count);
781 return ",";
782 }
783
784 /**
785 * Dump a comma-separated line of values for terse checkin mode.
786 *
787 * @param pw the PageWriter to dump log to
788 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
789 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
790 * @param args type-dependent data arguments
791 */
792 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
793 Object... args ) {
794 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
795 pw.print(uid); pw.print(',');
796 pw.print(category); pw.print(',');
797 pw.print(type);
798
799 for (Object arg : args) {
800 pw.print(',');
801 pw.print(arg);
802 }
803 pw.print('\n');
804 }
805
806 /**
807 * Checkin server version of dump to produce more compact, computer-readable log.
808 *
809 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800811 public final void dumpCheckinLocked(PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 final long rawUptime = SystemClock.uptimeMillis() * 1000;
813 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
814 final long batteryUptime = getBatteryUptime(rawUptime);
815 final long batteryRealtime = getBatteryRealtime(rawRealtime);
816 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
817 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
818 final long totalRealtime = computeRealtime(rawRealtime, which);
819 final long totalUptime = computeUptime(rawUptime, which);
820 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
821 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700822 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700823 final long wifiRunningTime = getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700824 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825
826 StringBuilder sb = new StringBuilder(128);
827
Evan Millar22ac0432009-03-31 11:33:18 -0700828 SparseArray<? extends Uid> uidStats = getUidStats();
829 final int NU = uidStats.size();
830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 String category = STAT_NAMES[which];
832
833 // Dump "battery" stat
834 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
835 which == STATS_TOTAL ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -0700836 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
837 totalRealtime / 1000, totalUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838
Evan Millar22ac0432009-03-31 11:33:18 -0700839 // Calculate total network and wakelock times across all uids.
840 long rxTotal = 0;
841 long txTotal = 0;
842 long fullWakeLockTimeTotal = 0;
843 long partialWakeLockTimeTotal = 0;
844
845 for (int iu = 0; iu < NU; iu++) {
846 Uid u = uidStats.valueAt(iu);
847 rxTotal += u.getTcpBytesReceived(which);
848 txTotal += u.getTcpBytesSent(which);
849
850 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
851 if (wakelocks.size() > 0) {
852 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
853 : wakelocks.entrySet()) {
854 Uid.Wakelock wl = ent.getValue();
855
856 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
857 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700858 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -0700859 }
860
861 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
862 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700863 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -0700864 batteryRealtime, which);
865 }
866 }
867 }
868 }
869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 // Dump misc stats
871 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700872 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Evan Millar22ac0432009-03-31 11:33:18 -0700873 wifiRunningTime / 1000, bluetoothOnTime / 1000, rxTotal, txTotal,
Dianne Hackborn617f8772009-03-31 15:04:46 -0700874 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
875 getInputEventCount(which));
876
877 // Dump screen brightness stats
878 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
879 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
880 args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000;
881 }
882 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -0700883
Dianne Hackborn627bba72009-03-24 22:32:56 -0700884 // Dump signal strength stats
Dianne Hackborn617f8772009-03-31 15:04:46 -0700885 args = new Object[NUM_SIGNAL_STRENGTH_BINS];
Dianne Hackborn627bba72009-03-24 22:32:56 -0700886 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
887 args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000;
888 }
Dianne Hackborn617f8772009-03-31 15:04:46 -0700889 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -0700890 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
891 getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700892 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
893 args[i] = getPhoneSignalStrengthCount(i, which);
894 }
895 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700896
897 // Dump network type stats
898 args = new Object[NUM_DATA_CONNECTION_TYPES];
899 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
900 args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000;
901 }
Dianne Hackborn617f8772009-03-31 15:04:46 -0700902 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
903 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
904 args[i] = getPhoneDataConnectionCount(i, which);
905 }
906 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700907
The Android Open Source Project10592532009-03-18 17:39:46 -0700908 if (which == STATS_UNPLUGGED) {
Evan Millare84de8d2009-04-02 22:16:12 -0700909 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -0700910 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -0700911 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800913 if (reqUid < 0) {
914 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
915 if (kernelWakelocks.size() > 0) {
916 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
917 sb.setLength(0);
918 printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, "");
919
920 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
921 sb.toString());
922 }
Evan Millarc64edde2009-04-18 12:26:32 -0700923 }
924 }
925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 for (int iu = 0; iu < NU; iu++) {
927 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800928 if (reqUid >= 0 && uid != reqUid) {
929 continue;
930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 Uid u = uidStats.valueAt(iu);
932 // Dump Network stats per uid, if any
933 long rx = u.getTcpBytesReceived(which);
934 long tx = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700935 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
936 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700937 long wifiTurnedOnTime = u.getWifiTurnedOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 if (rx > 0 || tx > 0) dumpLine(pw, uid, category, NETWORK_DATA, rx, tx);
The Android Open Source Project10592532009-03-18 17:39:46 -0700940
Dianne Hackborn617f8772009-03-31 15:04:46 -0700941 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
942 || wifiTurnedOnTime != 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700943 dumpLine(pw, uid, category, WIFI_LOCK_DATA,
Dianne Hackborn617f8772009-03-31 15:04:46 -0700944 fullWifiLockOnTime, scanWifiLockOnTime, wifiTurnedOnTime);
The Android Open Source Project10592532009-03-18 17:39:46 -0700945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946
Dianne Hackborn617f8772009-03-31 15:04:46 -0700947 if (u.hasUserActivity()) {
948 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
949 boolean hasData = false;
950 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
951 int val = u.getUserActivityCount(i, which);
952 args[i] = val;
953 if (val != 0) hasData = true;
954 }
955 if (hasData) {
956 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
957 }
958 }
959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
961 if (wakelocks.size() > 0) {
962 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
963 : wakelocks.entrySet()) {
964 Uid.Wakelock wl = ent.getValue();
965 String linePrefix = "";
966 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -0700967 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
968 batteryRealtime, "f", which, linePrefix);
969 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
970 batteryRealtime, "p", which, linePrefix);
971 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
972 batteryRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973
974 // Only log if we had at lease one wakelock...
975 if (sb.length() > 0) {
976 dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString());
977 }
978 }
979 }
980
981 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
982 if (sensors.size() > 0) {
983 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
984 : sensors.entrySet()) {
985 Uid.Sensor se = ent.getValue();
986 int sensorNumber = ent.getKey();
987 Timer timer = se.getSensorTime();
988 if (timer != null) {
989 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -0700990 long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000;
991 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 if (totalTime != 0) {
993 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
994 }
995 }
996 }
997 }
998
999 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1000 if (processStats.size() > 0) {
1001 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1002 : processStats.entrySet()) {
1003 Uid.Proc ps = ent.getValue();
1004
1005 long userTime = ps.getUserTime(which);
1006 long systemTime = ps.getSystemTime(which);
1007 int starts = ps.getStarts(which);
1008
1009 if (userTime != 0 || systemTime != 0 || starts != 0) {
1010 dumpLine(pw, uid, category, PROCESS_DATA,
1011 ent.getKey(), // proc
1012 userTime * 10, // cpu time in ms
1013 systemTime * 10, // user time in ms
1014 starts); // process starts
1015 }
1016 }
1017 }
1018
1019 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1020 if (packageStats.size() > 0) {
1021 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1022 : packageStats.entrySet()) {
1023
1024 Uid.Pkg ps = ent.getValue();
1025 int wakeups = ps.getWakeups(which);
1026 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1027 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1028 : serviceStats.entrySet()) {
1029 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1030 long startTime = ss.getStartTime(batteryUptime, which);
1031 int starts = ss.getStarts(which);
1032 int launches = ss.getLaunches(which);
1033 if (startTime != 0 || starts != 0 || launches != 0) {
1034 dumpLine(pw, uid, category, APK_DATA,
1035 wakeups, // wakeup alarms
1036 ent.getKey(), // Apk
1037 sent.getKey(), // service
1038 startTime / 1000, // time spent started, in ms
1039 starts,
1040 launches);
1041 }
1042 }
1043 }
1044 }
1045 }
1046 }
1047
1048 @SuppressWarnings("unused")
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001049 public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1051 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1052 final long batteryUptime = getBatteryUptime(rawUptime);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001053 final long batteryRealtime = getBatteryRealtime(rawRealtime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054
1055 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1056 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1057 final long totalRealtime = computeRealtime(rawRealtime, which);
1058 final long totalUptime = computeUptime(rawUptime, which);
1059
1060 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07001061
1062 SparseArray<? extends Uid> uidStats = getUidStats();
1063 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001065 sb.setLength(0);
1066 sb.append(prefix);
1067 sb.append(" Time on battery: ");
1068 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
1069 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
1070 sb.append(") realtime, ");
1071 formatTimeMs(sb, whichBatteryUptime / 1000);
1072 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
1073 sb.append(") uptime");
1074 pw.println(sb.toString());
1075 sb.setLength(0);
1076 sb.append(prefix);
1077 sb.append(" Total run time: ");
1078 formatTimeMs(sb, totalRealtime / 1000);
1079 sb.append("realtime, ");
1080 formatTimeMs(sb, totalUptime / 1000);
1081 sb.append("uptime, ");
1082 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083
The Android Open Source Project10592532009-03-18 17:39:46 -07001084 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
1085 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001086 final long wifiRunningTime = getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001087 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
1088 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001089 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001090 sb.append(prefix);
1091 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
1092 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
1093 sb.append("), Input events: "); sb.append(getInputEventCount(which));
1094 sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
1095 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
1096 sb.append(")");
1097 pw.println(sb.toString());
1098 sb.setLength(0);
1099 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001100 sb.append(" Screen brightnesses: ");
1101 boolean didOne = false;
1102 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1103 final long time = getScreenBrightnessTime(i, batteryRealtime, which);
1104 if (time == 0) {
1105 continue;
1106 }
1107 if (didOne) sb.append(", ");
1108 didOne = true;
1109 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
1110 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001111 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001112 sb.append("(");
1113 sb.append(formatRatioLocked(time, screenOnTime));
1114 sb.append(")");
1115 }
1116 if (!didOne) sb.append("No activity");
1117 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001118
Evan Millar22ac0432009-03-31 11:33:18 -07001119 // Calculate total network and wakelock times across all uids.
1120 long rxTotal = 0;
1121 long txTotal = 0;
1122 long fullWakeLockTimeTotalMicros = 0;
1123 long partialWakeLockTimeTotalMicros = 0;
1124
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001125 if (reqUid < 0) {
1126 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1127 if (kernelWakelocks.size() > 0) {
1128 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1129
1130 String linePrefix = ": ";
1131 sb.setLength(0);
1132 sb.append(prefix);
1133 sb.append(" Kernel Wake lock ");
1134 sb.append(ent.getKey());
1135 linePrefix = printWakeLock(sb, ent.getValue(), batteryRealtime, null, which,
1136 linePrefix);
1137 if (!linePrefix.equals(": ")) {
1138 sb.append(" realtime");
1139 } else {
1140 sb.append(": (nothing executed)");
1141 }
1142 pw.println(sb.toString());
Evan Millarc64edde2009-04-18 12:26:32 -07001143 }
Evan Millarc64edde2009-04-18 12:26:32 -07001144 }
1145 }
1146
Evan Millar22ac0432009-03-31 11:33:18 -07001147 for (int iu = 0; iu < NU; iu++) {
1148 Uid u = uidStats.valueAt(iu);
1149 rxTotal += u.getTcpBytesReceived(which);
1150 txTotal += u.getTcpBytesSent(which);
1151
1152 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1153 if (wakelocks.size() > 0) {
1154 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1155 : wakelocks.entrySet()) {
1156 Uid.Wakelock wl = ent.getValue();
1157
1158 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1159 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001160 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001161 batteryRealtime, which);
1162 }
1163
1164 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1165 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001166 partialWakeLockTimeTotalMicros += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001167 batteryRealtime, which);
1168 }
1169 }
1170 }
1171 }
1172
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001173 pw.print(prefix);
1174 pw.print(" Total received: "); pw.print(formatBytesLocked(rxTotal));
1175 pw.print(", Total sent: "); pw.println(formatBytesLocked(txTotal));
1176 sb.setLength(0);
1177 sb.append(prefix);
1178 sb.append(" Total full wakelock time: "); formatTimeMs(sb,
1179 (fullWakeLockTimeTotalMicros + 500) / 1000);
1180 sb.append(", Total partial waklock time: "); formatTimeMs(sb,
1181 (partialWakeLockTimeTotalMicros + 500) / 1000);
1182 pw.println(sb.toString());
Evan Millar22ac0432009-03-31 11:33:18 -07001183
Dianne Hackborn627bba72009-03-24 22:32:56 -07001184 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001185 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001186 sb.append(" Signal levels: ");
1187 didOne = false;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001188 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1189 final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which);
1190 if (time == 0) {
1191 continue;
1192 }
1193 if (didOne) sb.append(", ");
1194 didOne = true;
1195 sb.append(SIGNAL_STRENGTH_NAMES[i]);
1196 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001197 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001198 sb.append("(");
1199 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001200 sb.append(") ");
1201 sb.append(getPhoneSignalStrengthCount(i, which));
1202 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001203 }
1204 if (!didOne) sb.append("No activity");
1205 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07001206
1207 sb.setLength(0);
1208 sb.append(prefix);
1209 sb.append(" Signal scanning time: ");
1210 formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
1211 pw.println(sb.toString());
1212
Dianne Hackborn627bba72009-03-24 22:32:56 -07001213 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001214 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001215 sb.append(" Radio types: ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001216 didOne = false;
1217 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1218 final long time = getPhoneDataConnectionTime(i, batteryRealtime, which);
1219 if (time == 0) {
1220 continue;
1221 }
1222 if (didOne) sb.append(", ");
1223 didOne = true;
1224 sb.append(DATA_CONNECTION_NAMES[i]);
1225 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001226 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001227 sb.append("(");
1228 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001229 sb.append(") ");
1230 sb.append(getPhoneDataConnectionCount(i, which));
1231 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001232 }
1233 if (!didOne) sb.append("No activity");
1234 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07001235
1236 sb.setLength(0);
1237 sb.append(prefix);
1238 sb.append(" Radio data uptime when unplugged: ");
1239 sb.append(getRadioDataUptime() / 1000);
1240 sb.append(" ms");
1241 pw.println(sb.toString());
1242
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001243 sb.setLength(0);
1244 sb.append(prefix);
1245 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
1246 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
1247 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
1248 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
1249 sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
1250 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
1251 sb.append(")");
1252 pw.println(sb.toString());
Dianne Hackborn617f8772009-03-31 15:04:46 -07001253
The Android Open Source Project10592532009-03-18 17:39:46 -07001254 pw.println(" ");
1255
1256 if (which == STATS_UNPLUGGED) {
1257 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001258 pw.print(prefix); pw.println(" Device is currently unplugged");
1259 pw.print(prefix); pw.print(" Discharge cycle start level: ");
1260 pw.println(getDischargeStartLevel());
1261 pw.print(prefix); pw.print(" Discharge cycle current level: ");
1262 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001263 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001264 pw.print(prefix); pw.println(" Device is currently plugged into power");
1265 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
1266 pw.println(getDischargeStartLevel());
1267 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
1268 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001269 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001270 pw.println(" ");
The Android Open Source Project10592532009-03-18 17:39:46 -07001271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272
Evan Millar22ac0432009-03-31 11:33:18 -07001273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 for (int iu=0; iu<NU; iu++) {
1275 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001276 if (reqUid >= 0 && uid != reqUid) {
1277 continue;
1278 }
1279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 Uid u = uidStats.valueAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 pw.println(prefix + " #" + uid + ":");
1283 boolean uidActivity = false;
1284
1285 long tcpReceived = u.getTcpBytesReceived(which);
1286 long tcpSent = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001287 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1288 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001289 long wifiTurnedOnTime = u.getWifiTurnedOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 if (tcpReceived != 0 || tcpSent != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001292 pw.print(prefix); pw.print(" Network: ");
1293 pw.print(formatBytesLocked(tcpReceived)); pw.print(" received, ");
1294 pw.print(formatBytesLocked(tcpSent)); pw.println(" sent");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001296
1297 if (u.hasUserActivity()) {
1298 boolean hasData = false;
1299 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1300 int val = u.getUserActivityCount(i, which);
1301 if (val != 0) {
1302 if (!hasData) {
1303 sb.setLength(0);
1304 sb.append(" User activity: ");
1305 hasData = true;
1306 } else {
1307 sb.append(", ");
1308 }
1309 sb.append(val);
1310 sb.append(" ");
1311 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
1312 }
1313 }
1314 if (hasData) {
1315 pw.println(sb.toString());
1316 }
1317 }
1318
1319 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
1320 || wifiTurnedOnTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001321 sb.setLength(0);
1322 sb.append(prefix); sb.append(" Turned Wifi On: ");
1323 formatTimeMs(sb, wifiTurnedOnTime / 1000);
1324 sb.append("("); sb.append(formatRatioLocked(wifiTurnedOnTime,
1325 whichBatteryRealtime)); sb.append(")\n");
1326 sb.append(prefix); sb.append(" Full Wifi Lock: ");
1327 formatTimeMs(sb, fullWifiLockOnTime / 1000);
1328 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
1329 whichBatteryRealtime)); sb.append(")\n");
1330 sb.append(prefix); sb.append(" Scan Wifi Lock: ");
1331 formatTimeMs(sb, scanWifiLockOnTime / 1000);
1332 sb.append("("); sb.append(formatRatioLocked(scanWifiLockOnTime,
1333 whichBatteryRealtime)); sb.append(")");
1334 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336
1337 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1338 if (wakelocks.size() > 0) {
1339 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1340 : wakelocks.entrySet()) {
1341 Uid.Wakelock wl = ent.getValue();
1342 String linePrefix = ": ";
1343 sb.setLength(0);
1344 sb.append(prefix);
1345 sb.append(" Wake lock ");
1346 sb.append(ent.getKey());
1347 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime,
1348 "full", which, linePrefix);
1349 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime,
1350 "partial", which, linePrefix);
1351 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime,
1352 "window", which, linePrefix);
1353 if (!linePrefix.equals(": ")) {
1354 sb.append(" realtime");
1355 } else {
1356 sb.append(": (nothing executed)");
1357 }
1358 pw.println(sb.toString());
1359 uidActivity = true;
1360 }
1361 }
1362
1363 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1364 if (sensors.size() > 0) {
1365 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1366 : sensors.entrySet()) {
1367 Uid.Sensor se = ent.getValue();
1368 int sensorNumber = ent.getKey();
1369 sb.setLength(0);
1370 sb.append(prefix);
1371 sb.append(" Sensor ");
1372 int handle = se.getHandle();
1373 if (handle == Uid.Sensor.GPS) {
1374 sb.append("GPS");
1375 } else {
1376 sb.append(handle);
1377 }
1378 sb.append(": ");
1379
1380 Timer timer = se.getSensorTime();
1381 if (timer != null) {
1382 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001383 long totalTime = (timer.getTotalTimeLocked(
1384 batteryRealtime, which) + 500) / 1000;
1385 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 //timer.logState();
1387 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001388 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 sb.append("realtime (");
1390 sb.append(count);
1391 sb.append(" times)");
1392 } else {
1393 sb.append("(not used)");
1394 }
1395 } else {
1396 sb.append("(not used)");
1397 }
1398
1399 pw.println(sb.toString());
1400 uidActivity = true;
1401 }
1402 }
1403
1404 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1405 if (processStats.size() > 0) {
1406 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1407 : processStats.entrySet()) {
1408 Uid.Proc ps = ent.getValue();
1409 long userTime;
1410 long systemTime;
1411 int starts;
1412
1413 userTime = ps.getUserTime(which);
1414 systemTime = ps.getSystemTime(which);
1415 starts = ps.getStarts(which);
1416
1417 if (userTime != 0 || systemTime != 0 || starts != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001418 sb.setLength(0);
1419 sb.append(prefix); sb.append(" Proc ");
1420 sb.append(ent.getKey()); sb.append(":\n");
1421 sb.append(prefix); sb.append(" CPU: ");
1422 formatTime(sb, userTime); sb.append("usr + ");
1423 formatTime(sb, systemTime); sb.append("krn\n");
1424 sb.append(prefix); sb.append(" "); sb.append(starts);
1425 sb.append(" proc starts");
1426 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 uidActivity = true;
1428 }
1429 }
1430 }
1431
1432 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1433 if (packageStats.size() > 0) {
1434 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1435 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001436 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 boolean apkActivity = false;
1438 Uid.Pkg ps = ent.getValue();
1439 int wakeups = ps.getWakeups(which);
1440 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001441 pw.print(prefix); pw.print(" ");
1442 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 apkActivity = true;
1444 }
1445 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1446 if (serviceStats.size() > 0) {
1447 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1448 : serviceStats.entrySet()) {
1449 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1450 long startTime = ss.getStartTime(batteryUptime, which);
1451 int starts = ss.getStarts(which);
1452 int launches = ss.getLaunches(which);
1453 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001454 sb.setLength(0);
1455 sb.append(prefix); sb.append(" Service ");
1456 sb.append(sent.getKey()); sb.append(":\n");
1457 sb.append(prefix); sb.append(" Created for: ");
1458 formatTimeMs(sb, startTime / 1000);
1459 sb.append(" uptime\n");
1460 sb.append(prefix); sb.append(" Starts: ");
1461 sb.append(starts);
1462 sb.append(", launches: "); sb.append(launches);
1463 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 apkActivity = true;
1465 }
1466 }
1467 }
1468 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001469 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 }
1471 uidActivity = true;
1472 }
1473 }
1474 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001475 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 }
1477 }
1478 }
1479
1480 /**
1481 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
1482 *
1483 * @param pw a Printer to receive the dump output.
1484 */
1485 @SuppressWarnings("unused")
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001486 public void dumpLocked(PrintWriter pw) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001487 BatteryHistoryRecord rec = getHistory();
1488 if (rec != null) {
1489 pw.println("Battery History:");
1490 while (rec != null) {
1491 pw.print(" ");
1492 pw.print(rec.time);
1493 pw.print(" ");
1494 pw.print(rec.batteryLevel);
1495 pw.print(" ");
1496 pw.println(Integer.toHexString(rec.states));
1497 rec = rec.next;
1498 }
1499 }
1500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 pw.println("Total Statistics (Current and Historic):");
1502 pw.println(" System starts: " + getStartCount()
1503 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001504 dumpLocked(pw, "", STATS_TOTAL, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 pw.println("");
1506 pw.println("Last Run Statistics (Previous run of system):");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001507 dumpLocked(pw, "", STATS_LAST, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 pw.println("");
1509 pw.println("Current Battery Statistics (Currently running system):");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001510 dumpLocked(pw, "", STATS_CURRENT, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 pw.println("");
1512 pw.println("Unplugged Statistics (Since last unplugged from power):");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001513 dumpLocked(pw, "", STATS_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 }
1515
1516 @SuppressWarnings("unused")
1517 public void dumpCheckinLocked(PrintWriter pw, String[] args) {
1518 boolean isUnpluggedOnly = false;
1519
1520 for (String arg : args) {
1521 if ("-u".equals(arg)) {
1522 if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data");
1523 isUnpluggedOnly = true;
1524 }
1525 }
1526
1527 if (isUnpluggedOnly) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001528 dumpCheckinLocked(pw, STATS_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 }
1530 else {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001531 dumpCheckinLocked(pw, STATS_TOTAL, -1);
1532 dumpCheckinLocked(pw, STATS_LAST, -1);
1533 dumpCheckinLocked(pw, STATS_UNPLUGGED, -1);
1534 dumpCheckinLocked(pw, STATS_CURRENT, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 }
1536 }
1537
1538}