blob: 49afeeb4642a24118099800a9c26b0455304f935 [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
Dianne Hackborn94326cb2017-06-28 16:17:20 -070019import android.app.job.JobParameters;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080020import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080021import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080022import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080023import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070024import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070025import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070026import android.util.MutableBoolean;
27import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.util.Printer;
29import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070030import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070031import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070032import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080033
Dianne Hackborna7c837f2014-01-15 16:20:44 -080034import com.android.internal.os.BatterySipper;
35import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -070037import java.io.PrintWriter;
38import java.util.ArrayList;
39import java.util.Collections;
40import java.util.Comparator;
41import java.util.Formatter;
42import java.util.HashMap;
43import java.util.List;
44import java.util.Map;
45
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046/**
47 * A class providing access to battery usage statistics, including information on
48 * wakelocks, processes, packages, and services. All times are represented in microseconds
49 * except where indicated otherwise.
50 * @hide
51 */
52public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070053 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070056
57 /** @hide */
58 public static final String SERVICE_NAME = "batterystats";
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 /**
61 * A constant indicating a partial wake lock timer.
62 */
63 public static final int WAKE_TYPE_PARTIAL = 0;
64
65 /**
66 * A constant indicating a full wake lock timer.
67 */
68 public static final int WAKE_TYPE_FULL = 1;
69
70 /**
71 * A constant indicating a window wake lock timer.
72 */
73 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 /**
76 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 */
78 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070079
80 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070081 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070082 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070083 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070084
85 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070086 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070087 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070088 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070089
90 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070091 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070092 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070093 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
Dianne Hackborn62793e42015-03-09 11:15:41 -070095 /**
96 * A constant indicating a wifi multicast timer
97 */
98 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700101 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700102 */
103 public static final int VIDEO_TURNED_ON = 8;
104
105 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800106 * A constant indicating a vibrator on timer
107 */
108 public static final int VIBRATOR_ON = 9;
109
110 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700111 * A constant indicating a foreground activity timer
112 */
113 public static final int FOREGROUND_ACTIVITY = 10;
114
115 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700116 * A constant indicating a wifi batched scan is active
117 */
118 public static final int WIFI_BATCHED_SCAN = 11;
119
120 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700121 * A constant indicating a process state timer
122 */
123 public static final int PROCESS_STATE = 12;
124
125 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700126 * A constant indicating a sync timer
127 */
128 public static final int SYNC = 13;
129
130 /**
131 * A constant indicating a job timer
132 */
133 public static final int JOB = 14;
134
135 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800136 * A constant indicating an audio turn on timer
137 */
138 public static final int AUDIO_TURNED_ON = 15;
139
140 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700141 * A constant indicating a flashlight turn on timer
142 */
143 public static final int FLASHLIGHT_TURNED_ON = 16;
144
145 /**
146 * A constant indicating a camera turn on timer
147 */
148 public static final int CAMERA_TURNED_ON = 17;
149
150 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700151 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700152 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700153 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700154
155 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800156 * A constant indicating a bluetooth scan timer.
157 */
158 public static final int BLUETOOTH_SCAN_ON = 19;
159
160 /**
Bookatzc8c44962017-05-11 12:12:54 -0700161 * A constant indicating an aggregated partial wake lock timer.
162 */
163 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
164
165 /**
Bookatzb1f04f32017-05-19 13:57:32 -0700166 * A constant indicating a bluetooth scan timer for unoptimized scans.
167 */
168 public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21;
169
170 /**
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700171 * A constant indicating a foreground service timer
172 */
173 public static final int FOREGROUND_SERVICE = 22;
174
175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 * Include all of the data in the stats, including previously saved data.
177 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700178 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179
180 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 * Include only the current run in the stats.
182 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700183 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184
185 /**
186 * Include only the run since the last time the device was unplugged in the stats.
187 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700188 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700189
190 // NOTE: Update this list if you add/change any stats above.
191 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700192 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700193 private static final String[] STAT_NAMES = { "l", "c", "u" };
194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700196 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700197 *
198 * New in version 19:
199 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800200 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700201 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700202 * New in version 21:
203 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700204 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700205 * - BLE scan result count
206 * - CPU frequency time per uid
207 * New in version 22:
208 * - BLE scan result background count, BLE unoptimized scan time
Bookatz98d4d5c2017-08-01 19:07:54 -0700209 * - Background partial wakelock time & count
210 * New in version 23:
211 * - Logging smeared power model values
212 * New in version 24:
213 * - Fixed bugs in background timers and BLE scan time
214 * New in version 25:
215 * - Package wakeup alarms are now on screen-off timebase
Bookatz50df7112017-08-04 14:53:26 -0700216 * New in version 26:
217 * - Resource power manager (rpm) states
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700218 */
Bookatz50df7112017-08-04 14:53:26 -0700219 static final String CHECKIN_VERSION = "26";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700220
221 /**
222 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700224 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700225
Evan Millar22ac0432009-03-31 11:33:18 -0700226 private static final long BYTES_PER_KB = 1024;
227 private static final long BYTES_PER_MB = 1048576; // 1024^2
228 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700229
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700230 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800231 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700232 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700234 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700235 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700236 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
237 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700238 // rpm line is:
239 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
240 // screen-off time, screen-off count
241 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700242 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800243 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700244 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
245 // fgs line is:
246 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
247 // foreground service time, count
248 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700249 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700250 // wl line is:
251 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700252 // full totalTime, 'f', count, current duration, max duration, total duration,
253 // partial totalTime, 'p', count, current duration, max duration, total duration,
254 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
255 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700256 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700257 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700258 // awl line is:
259 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
260 // cumulative partial wakelock duration, cumulative background partial wakelock duration
261 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700262 private static final String SYNC_DATA = "sy";
263 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700264 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700265 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700266 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700267 private static final String NETWORK_DATA = "nt";
268 private static final String USER_ACTIVITY_DATA = "ua";
269 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800270 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700271 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700272 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700273 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800274 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
275 private static final String WIFI_CONTROLLER_DATA = "wfcd";
276 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
277 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700278 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700279 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800280 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800281 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
282 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800283 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700284 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700285 private static final String SCREEN_BRIGHTNESS_DATA = "br";
286 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700287 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700288 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
289 private static final String DATA_CONNECTION_TIME_DATA = "dct";
290 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800291 private static final String WIFI_STATE_TIME_DATA = "wst";
292 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700293 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
294 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
295 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
296 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800297 private static final String POWER_USE_SUMMARY_DATA = "pws";
298 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700299 private static final String DISCHARGE_STEP_DATA = "dsd";
300 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700301 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
302 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700303 private static final String FLASHLIGHT_DATA = "fla";
304 private static final String CAMERA_DATA = "cam";
305 private static final String VIDEO_DATA = "vid";
306 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307
Adam Lesinski010bf372016-04-11 12:18:18 -0700308 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
309
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700310 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 private final Formatter mFormatter = new Formatter(mFormatBuilder);
312
313 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700314 * Indicates times spent by the uid at each cpu frequency in all process states.
315 *
316 * Other types might include times spent in foreground, background etc.
317 */
318 private final String UID_TIMES_TYPE_ALL = "A";
319
320 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700321 * State for keeping track of counting information.
322 */
323 public static abstract class Counter {
324
325 /**
326 * Returns the count associated with this Counter for the
327 * selected type of statistics.
328 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700329 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700330 */
Evan Millarc64edde2009-04-18 12:26:32 -0700331 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700332
333 /**
334 * Temporary for debugging.
335 */
336 public abstract void logState(Printer pw, String prefix);
337 }
338
339 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700340 * State for keeping track of long counting information.
341 */
342 public static abstract class LongCounter {
343
344 /**
345 * Returns the count associated with this Counter for the
346 * selected type of statistics.
347 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700348 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700349 */
350 public abstract long getCountLocked(int which);
351
352 /**
353 * Temporary for debugging.
354 */
355 public abstract void logState(Printer pw, String prefix);
356 }
357
358 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700359 * State for keeping track of array of long counting information.
360 */
361 public static abstract class LongCounterArray {
362 /**
363 * Returns the counts associated with this Counter for the
364 * selected type of statistics.
365 *
366 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
367 */
368 public abstract long[] getCountsLocked(int which);
369
370 /**
371 * Temporary for debugging.
372 */
373 public abstract void logState(Printer pw, String prefix);
374 }
375
376 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800377 * Container class that aggregates counters for transmit, receive, and idle state of a
378 * radio controller.
379 */
380 public static abstract class ControllerActivityCounter {
381 /**
382 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
383 * idle state.
384 */
385 public abstract LongCounter getIdleTimeCounter();
386
387 /**
388 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
389 * receive state.
390 */
391 public abstract LongCounter getRxTimeCounter();
392
393 /**
394 * An array of {@link LongCounter}, representing various transmit levels, where each level
395 * may draw a different amount of power. The levels themselves are controller-specific.
396 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
397 * various transmit level states.
398 */
399 public abstract LongCounter[] getTxTimeCounters();
400
401 /**
402 * @return a non-null {@link LongCounter} representing the power consumed by the controller
403 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
404 * yield a value of 0 if the device doesn't support power calculations.
405 */
406 public abstract LongCounter getPowerCounter();
407 }
408
409 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 * State for keeping track of timing information.
411 */
412 public static abstract class Timer {
413
414 /**
415 * Returns the count associated with this Timer for the
416 * selected type of statistics.
417 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700418 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 */
Evan Millarc64edde2009-04-18 12:26:32 -0700420 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421
422 /**
423 * Returns the total time in microseconds associated with this Timer for the
424 * selected type of statistics.
425 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800426 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700427 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 * @return a time in microseconds
429 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800430 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700433 * Returns the total time in microseconds associated with this Timer since the
434 * 'mark' was last set.
435 *
436 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
437 * @return a time in microseconds
438 */
439 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
440
441 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700442 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800443 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700444
445 */
446 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
447 return -1;
448 }
449
450 /**
451 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800452 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700453 */
454 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
455 return -1;
456 }
457
458 /**
Bookatz867c0d72017-03-07 18:23:42 -0800459 * Returns the current time the timer has been active, if it is being tracked.
460 *
461 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
462 * been on since reset.
463 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
464 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
465 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
466 * the actual total time.
467 * Not all Timer subclasses track the max, total, current durations.
468 */
469 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
470 return -1;
471 }
472
473 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700474 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
475 * used, for example, for tracking background usage. Secondary timers are never pooled.
476 *
477 * Not all Timer subclasses have a secondary timer; those that don't return null.
478 */
479 public Timer getSubTimer() {
480 return null;
481 }
482
483 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700484 * Returns whether the timer is currently running. Some types of timers
485 * (e.g. BatchTimers) don't know whether the event is currently active,
486 * and report false.
487 */
488 public boolean isRunningLocked() {
489 return false;
490 }
491
492 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 * Temporary for debugging.
494 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700495 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
497
498 /**
499 * The statistics associated with a particular uid.
500 */
501 public static abstract class Uid {
502
503 /**
504 * Returns a mapping containing wakelock statistics.
505 *
506 * @return a Map from Strings to Uid.Wakelock objects.
507 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700508 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509
510 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700511 * Returns a mapping containing sync statistics.
512 *
513 * @return a Map from Strings to Timer objects.
514 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700515 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700516
517 /**
518 * Returns a mapping containing scheduled job statistics.
519 *
520 * @return a Map from Strings to Timer objects.
521 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700522 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700523
524 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700525 * Returns statistics about how jobs have completed.
526 *
527 * @return A Map of String job names to completion type -> count mapping.
528 */
529 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
530
531 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 * The statistics associated with a particular wake lock.
533 */
534 public static abstract class Wakelock {
535 public abstract Timer getWakeTime(int type);
536 }
537
538 /**
Bookatzc8c44962017-05-11 12:12:54 -0700539 * The cumulative time the uid spent holding any partial wakelocks. This will generally
540 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
541 * wakelocks that overlap in time (and therefore over-counts).
542 */
543 public abstract Timer getAggregatedPartialWakelockTimer();
544
545 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 * Returns a mapping containing sensor statistics.
547 *
548 * @return a Map from Integer sensor ids to Uid.Sensor objects.
549 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700550 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551
552 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700553 * Returns a mapping containing active process data.
554 */
555 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700556
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700557 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 * Returns a mapping containing process statistics.
559 *
560 * @return a Map from Strings to Uid.Proc objects.
561 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700562 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563
564 /**
565 * Returns a mapping containing package statistics.
566 *
567 * @return a Map from Strings to Uid.Pkg objects.
568 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700569 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700570
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800571 public abstract ControllerActivityCounter getWifiControllerActivity();
572 public abstract ControllerActivityCounter getBluetoothControllerActivity();
573 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800574
575 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 * {@hide}
577 */
578 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700579
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800580 public abstract void noteWifiRunningLocked(long elapsedRealtime);
581 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
582 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
583 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
584 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
585 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
586 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
587 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
588 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
589 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800590 public abstract void noteActivityResumedLocked(long elapsedRealtime);
591 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800592 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
593 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
594 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700595 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800596 public abstract int getWifiScanBackgroundCount(int which);
597 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
598 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800599 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700600 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800601 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700602 public abstract Timer getAudioTurnedOnTimer();
603 public abstract Timer getVideoTurnedOnTimer();
604 public abstract Timer getFlashlightTurnedOnTimer();
605 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700606 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700607
608 /**
609 * Returns the timer keeping track of Foreground Service time
610 */
611 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800612 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800613 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700614 public abstract Timer getBluetoothUnoptimizedScanTimer();
615 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700616 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700617 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700618
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700619 public abstract long[] getCpuFreqTimes(int which);
620 public abstract long[] getScreenOffCpuFreqTimes(int which);
621
Dianne Hackborna0200e32016-03-30 18:01:41 -0700622 // Note: the following times are disjoint. They can be added together to find the
623 // total time a uid has had any processes running at all.
624
625 /**
626 * Time this uid has any processes in the top state (or above such as persistent).
627 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800628 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700629 /**
630 * Time this uid has any process with a started out bound foreground service, but
631 * none in the "top" state.
632 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800633 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700634 /**
635 * Time this uid has any process that is top while the device is sleeping, but none
636 * in the "foreground service" or better state.
637 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800638 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700639 /**
640 * Time this uid has any process in an active foreground state, but none in the
641 * "top sleeping" or better state.
642 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800643 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700644 /**
645 * Time this uid has any process in an active background state, but none in the
646 * "foreground" or better state.
647 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800648 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700649 /**
650 * Time this uid has any processes that are sitting around cached, not in one of the
651 * other active states.
652 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800653 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700654 /**
655 * Total number of process states we track.
656 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800657 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700658
659 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800660 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700661 };
662
663 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800664 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700665
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800666 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667
Robert Greenwalta029ea12013-09-25 16:38:12 -0700668 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
669
Dianne Hackborn617f8772009-03-31 15:04:46 -0700670 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700671 * Note that these must match the constants in android.os.PowerManager.
672 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
673 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700674 */
675 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700676 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700677 };
Bookatzc8c44962017-05-11 12:12:54 -0700678
Phil Weaverda80d672016-03-15 16:25:46 -0700679 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700680
Dianne Hackborn617f8772009-03-31 15:04:46 -0700681 public abstract void noteUserActivityLocked(int type);
682 public abstract boolean hasUserActivity();
683 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700684
685 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800686 public abstract long getNetworkActivityBytes(int type, int which);
687 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800688 public abstract long getMobileRadioActiveTime(int which);
689 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700690
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700691 /**
692 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
693 */
694 public abstract long getUserCpuTimeUs(int which);
695
696 /**
697 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
698 */
699 public abstract long getSystemCpuTimeUs(int which);
700
701 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700702 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700703 * given CPU cluster.
704 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700705 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700706 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700707 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
708 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700709 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700710 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700711
Adam Lesinski5f056f62016-07-14 16:56:08 -0700712 /**
713 * Returns the number of times this UID woke up the Application Processor to
714 * process a mobile radio packet.
715 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
716 */
717 public abstract long getMobileRadioApWakeupCount(int which);
718
719 /**
720 * Returns the number of times this UID woke up the Application Processor to
721 * process a WiFi packet.
722 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
723 */
724 public abstract long getWifiRadioApWakeupCount(int which);
725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800727 /*
728 * FIXME: it's not correct to use this magic value because it
729 * could clash with a sensor handle (which are defined by
730 * the sensor HAL, and therefore out of our control
731 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 // Magic sensor number for the GPS.
733 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800738
Bookatz867c0d72017-03-07 18:23:42 -0800739 /** Returns a Timer for sensor usage when app is in the background. */
740 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700743 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800744 public int mWakeNesting;
745 public long mWakeSumMs;
746 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700747 }
748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 /**
750 * The statistics associated with a particular process.
751 */
752 public static abstract class Proc {
753
Dianne Hackborn287952c2010-09-22 22:34:31 -0700754 public static class ExcessivePower {
755 public static final int TYPE_WAKE = 1;
756 public static final int TYPE_CPU = 2;
757
758 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700759 public long overTime;
760 public long usedTime;
761 }
762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800764 * Returns true if this process is still active in the battery stats.
765 */
766 public abstract boolean isActive();
767
768 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700769 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700771 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 */
773 public abstract long getUserTime(int which);
774
775 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700776 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700778 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 */
780 public abstract long getSystemTime(int which);
781
782 /**
783 * Returns the number of times the process has been started.
784 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700785 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 */
787 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700788
789 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800790 * Returns the number of times the process has crashed.
791 *
792 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
793 */
794 public abstract int getNumCrashes(int which);
795
796 /**
797 * Returns the number of times the process has ANRed.
798 *
799 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
800 */
801 public abstract int getNumAnrs(int which);
802
803 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700804 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700805 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700806 * @return foreground cpu time in microseconds
807 */
808 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700809
Dianne Hackborn287952c2010-09-22 22:34:31 -0700810 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700811
Dianne Hackborn287952c2010-09-22 22:34:31 -0700812 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 }
814
815 /**
816 * The statistics associated with a particular package.
817 */
818 public static abstract class Pkg {
819
820 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700821 * Returns information about all wakeup alarms that have been triggered for this
822 * package. The mapping keys are tag names for the alarms, the counter contains
823 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700825 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826
827 /**
828 * Returns a mapping containing service statistics.
829 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700830 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831
832 /**
833 * The statistics associated with a particular service.
834 */
Joe Onoratoabded112016-02-08 16:49:39 -0800835 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836
837 /**
838 * Returns the amount of time spent started.
839 *
840 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700841 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 * @return
843 */
844 public abstract long getStartTime(long batteryUptime, int which);
845
846 /**
847 * Returns the total number of times startService() has been called.
848 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700849 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 */
851 public abstract int getStarts(int which);
852
853 /**
854 * Returns the total number times the service has been launched.
855 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700856 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 */
858 public abstract int getLaunches(int which);
859 }
860 }
861 }
862
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800863 public static final class LevelStepTracker {
864 public long mLastStepTime = -1;
865 public int mNumStepDurations;
866 public final long[] mStepDurations;
867
868 public LevelStepTracker(int maxLevelSteps) {
869 mStepDurations = new long[maxLevelSteps];
870 }
871
872 public LevelStepTracker(int numSteps, long[] steps) {
873 mNumStepDurations = numSteps;
874 mStepDurations = new long[numSteps];
875 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
876 }
877
878 public long getDurationAt(int index) {
879 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
880 }
881
882 public int getLevelAt(int index) {
883 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
884 >> STEP_LEVEL_LEVEL_SHIFT);
885 }
886
887 public int getInitModeAt(int index) {
888 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
889 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
890 }
891
892 public int getModModeAt(int index) {
893 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
894 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
895 }
896
897 private void appendHex(long val, int topOffset, StringBuilder out) {
898 boolean hasData = false;
899 while (topOffset >= 0) {
900 int digit = (int)( (val>>topOffset) & 0xf );
901 topOffset -= 4;
902 if (!hasData && digit == 0) {
903 continue;
904 }
905 hasData = true;
906 if (digit >= 0 && digit <= 9) {
907 out.append((char)('0' + digit));
908 } else {
909 out.append((char)('a' + digit - 10));
910 }
911 }
912 }
913
914 public void encodeEntryAt(int index, StringBuilder out) {
915 long item = mStepDurations[index];
916 long duration = item & STEP_LEVEL_TIME_MASK;
917 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
918 >> STEP_LEVEL_LEVEL_SHIFT);
919 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
920 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
921 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
922 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
923 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
924 case Display.STATE_OFF: out.append('f'); break;
925 case Display.STATE_ON: out.append('o'); break;
926 case Display.STATE_DOZE: out.append('d'); break;
927 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
928 }
929 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
930 out.append('p');
931 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700932 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
933 out.append('i');
934 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800935 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
936 case Display.STATE_OFF: out.append('F'); break;
937 case Display.STATE_ON: out.append('O'); break;
938 case Display.STATE_DOZE: out.append('D'); break;
939 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
940 }
941 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
942 out.append('P');
943 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700944 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
945 out.append('I');
946 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800947 out.append('-');
948 appendHex(level, 4, out);
949 out.append('-');
950 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
951 }
952
953 public void decodeEntryAt(int index, String value) {
954 final int N = value.length();
955 int i = 0;
956 char c;
957 long out = 0;
958 while (i < N && (c=value.charAt(i)) != '-') {
959 i++;
960 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800961 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800962 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800963 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800964 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800965 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800966 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800967 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
968 << STEP_LEVEL_INITIAL_MODE_SHIFT);
969 break;
970 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
971 << STEP_LEVEL_INITIAL_MODE_SHIFT);
972 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700973 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
974 << STEP_LEVEL_INITIAL_MODE_SHIFT);
975 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800976 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
977 break;
978 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
979 break;
980 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
981 break;
982 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
983 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
984 break;
985 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
986 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800987 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700988 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
989 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
990 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800991 }
992 }
993 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800994 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800995 while (i < N && (c=value.charAt(i)) != '-') {
996 i++;
997 level <<= 4;
998 if (c >= '0' && c <= '9') {
999 level += c - '0';
1000 } else if (c >= 'a' && c <= 'f') {
1001 level += c - 'a' + 10;
1002 } else if (c >= 'A' && c <= 'F') {
1003 level += c - 'A' + 10;
1004 }
1005 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001006 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001007 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1008 long duration = 0;
1009 while (i < N && (c=value.charAt(i)) != '-') {
1010 i++;
1011 duration <<= 4;
1012 if (c >= '0' && c <= '9') {
1013 duration += c - '0';
1014 } else if (c >= 'a' && c <= 'f') {
1015 duration += c - 'a' + 10;
1016 } else if (c >= 'A' && c <= 'F') {
1017 duration += c - 'A' + 10;
1018 }
1019 }
1020 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1021 }
1022
1023 public void init() {
1024 mLastStepTime = -1;
1025 mNumStepDurations = 0;
1026 }
1027
1028 public void clearTime() {
1029 mLastStepTime = -1;
1030 }
1031
1032 public long computeTimePerLevel() {
1033 final long[] steps = mStepDurations;
1034 final int numSteps = mNumStepDurations;
1035
1036 // For now we'll do a simple average across all steps.
1037 if (numSteps <= 0) {
1038 return -1;
1039 }
1040 long total = 0;
1041 for (int i=0; i<numSteps; i++) {
1042 total += steps[i] & STEP_LEVEL_TIME_MASK;
1043 }
1044 return total / numSteps;
1045 /*
1046 long[] buckets = new long[numSteps];
1047 int numBuckets = 0;
1048 int numToAverage = 4;
1049 int i = 0;
1050 while (i < numSteps) {
1051 long totalTime = 0;
1052 int num = 0;
1053 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1054 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1055 num++;
1056 }
1057 buckets[numBuckets] = totalTime / num;
1058 numBuckets++;
1059 numToAverage *= 2;
1060 i += num;
1061 }
1062 if (numBuckets < 1) {
1063 return -1;
1064 }
1065 long averageTime = buckets[numBuckets-1];
1066 for (i=numBuckets-2; i>=0; i--) {
1067 averageTime = (averageTime + buckets[i]) / 2;
1068 }
1069 return averageTime;
1070 */
1071 }
1072
1073 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1074 int[] outNumOfInterest) {
1075 final long[] steps = mStepDurations;
1076 final int count = mNumStepDurations;
1077 if (count <= 0) {
1078 return -1;
1079 }
1080 long total = 0;
1081 int numOfInterest = 0;
1082 for (int i=0; i<count; i++) {
1083 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1084 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1085 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1086 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1087 // If the modes of interest didn't change during this step period...
1088 if ((modMode&modesOfInterest) == 0) {
1089 // And the mode values during this period match those we are measuring...
1090 if ((initMode&modesOfInterest) == modeValues) {
1091 // Then this can be used to estimate the total time!
1092 numOfInterest++;
1093 total += steps[i] & STEP_LEVEL_TIME_MASK;
1094 }
1095 }
1096 }
1097 if (numOfInterest <= 0) {
1098 return -1;
1099 }
1100
1101 if (outNumOfInterest != null) {
1102 outNumOfInterest[0] = numOfInterest;
1103 }
1104
1105 // The estimated time is the average time we spend in each level, multipled
1106 // by 100 -- the total number of battery levels
1107 return (total / numOfInterest) * 100;
1108 }
1109
1110 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1111 int stepCount = mNumStepDurations;
1112 final long lastStepTime = mLastStepTime;
1113 if (lastStepTime >= 0 && numStepLevels > 0) {
1114 final long[] steps = mStepDurations;
1115 long duration = elapsedRealtime - lastStepTime;
1116 for (int i=0; i<numStepLevels; i++) {
1117 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1118 long thisDuration = duration / (numStepLevels-i);
1119 duration -= thisDuration;
1120 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1121 thisDuration = STEP_LEVEL_TIME_MASK;
1122 }
1123 steps[0] = thisDuration | modeBits;
1124 }
1125 stepCount += numStepLevels;
1126 if (stepCount > steps.length) {
1127 stepCount = steps.length;
1128 }
1129 }
1130 mNumStepDurations = stepCount;
1131 mLastStepTime = elapsedRealtime;
1132 }
1133
1134 public void readFromParcel(Parcel in) {
1135 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001136 if (N > mStepDurations.length) {
1137 throw new ParcelFormatException("more step durations than available: " + N);
1138 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001139 mNumStepDurations = N;
1140 for (int i=0; i<N; i++) {
1141 mStepDurations[i] = in.readLong();
1142 }
1143 }
1144
1145 public void writeToParcel(Parcel out) {
1146 final int N = mNumStepDurations;
1147 out.writeInt(N);
1148 for (int i=0; i<N; i++) {
1149 out.writeLong(mStepDurations[i]);
1150 }
1151 }
1152 }
1153
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001154 public static final class PackageChange {
1155 public String mPackageName;
1156 public boolean mUpdate;
1157 public int mVersionCode;
1158 }
1159
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001160 public static final class DailyItem {
1161 public long mStartTime;
1162 public long mEndTime;
1163 public LevelStepTracker mDischargeSteps;
1164 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001165 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001166 }
1167
1168 public abstract DailyItem getDailyItemLocked(int daysAgo);
1169
1170 public abstract long getCurrentDailyStartTime();
1171
1172 public abstract long getNextMinDailyDeadline();
1173
1174 public abstract long getNextMaxDailyDeadline();
1175
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001176 public abstract long[] getCpuFreqs();
1177
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001178 public final static class HistoryTag {
1179 public String string;
1180 public int uid;
1181
1182 public int poolIdx;
1183
1184 public void setTo(HistoryTag o) {
1185 string = o.string;
1186 uid = o.uid;
1187 poolIdx = o.poolIdx;
1188 }
1189
1190 public void setTo(String _string, int _uid) {
1191 string = _string;
1192 uid = _uid;
1193 poolIdx = -1;
1194 }
1195
1196 public void writeToParcel(Parcel dest, int flags) {
1197 dest.writeString(string);
1198 dest.writeInt(uid);
1199 }
1200
1201 public void readFromParcel(Parcel src) {
1202 string = src.readString();
1203 uid = src.readInt();
1204 poolIdx = -1;
1205 }
1206
1207 @Override
1208 public boolean equals(Object o) {
1209 if (this == o) return true;
1210 if (o == null || getClass() != o.getClass()) return false;
1211
1212 HistoryTag that = (HistoryTag) o;
1213
1214 if (uid != that.uid) return false;
1215 if (!string.equals(that.string)) return false;
1216
1217 return true;
1218 }
1219
1220 @Override
1221 public int hashCode() {
1222 int result = string.hashCode();
1223 result = 31 * result + uid;
1224 return result;
1225 }
1226 }
1227
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001228 /**
1229 * Optional detailed information that can go into a history step. This is typically
1230 * generated each time the battery level changes.
1231 */
1232 public final static class HistoryStepDetails {
1233 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1234 public int userTime;
1235 public int systemTime;
1236
1237 // Top three apps using CPU in the last step, with times in 1/100 second.
1238 public int appCpuUid1;
1239 public int appCpuUTime1;
1240 public int appCpuSTime1;
1241 public int appCpuUid2;
1242 public int appCpuUTime2;
1243 public int appCpuSTime2;
1244 public int appCpuUid3;
1245 public int appCpuUTime3;
1246 public int appCpuSTime3;
1247
1248 // Information from /proc/stat
1249 public int statUserTime;
1250 public int statSystemTime;
1251 public int statIOWaitTime;
1252 public int statIrqTime;
1253 public int statSoftIrqTime;
1254 public int statIdlTime;
1255
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001256 // Platform-level low power state stats
1257 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001258 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001259
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001260 public HistoryStepDetails() {
1261 clear();
1262 }
1263
1264 public void clear() {
1265 userTime = systemTime = 0;
1266 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1267 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1268 = appCpuUTime3 = appCpuSTime3 = 0;
1269 }
1270
1271 public void writeToParcel(Parcel out) {
1272 out.writeInt(userTime);
1273 out.writeInt(systemTime);
1274 out.writeInt(appCpuUid1);
1275 out.writeInt(appCpuUTime1);
1276 out.writeInt(appCpuSTime1);
1277 out.writeInt(appCpuUid2);
1278 out.writeInt(appCpuUTime2);
1279 out.writeInt(appCpuSTime2);
1280 out.writeInt(appCpuUid3);
1281 out.writeInt(appCpuUTime3);
1282 out.writeInt(appCpuSTime3);
1283 out.writeInt(statUserTime);
1284 out.writeInt(statSystemTime);
1285 out.writeInt(statIOWaitTime);
1286 out.writeInt(statIrqTime);
1287 out.writeInt(statSoftIrqTime);
1288 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001289 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001290 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001291 }
1292
1293 public void readFromParcel(Parcel in) {
1294 userTime = in.readInt();
1295 systemTime = in.readInt();
1296 appCpuUid1 = in.readInt();
1297 appCpuUTime1 = in.readInt();
1298 appCpuSTime1 = in.readInt();
1299 appCpuUid2 = in.readInt();
1300 appCpuUTime2 = in.readInt();
1301 appCpuSTime2 = in.readInt();
1302 appCpuUid3 = in.readInt();
1303 appCpuUTime3 = in.readInt();
1304 appCpuSTime3 = in.readInt();
1305 statUserTime = in.readInt();
1306 statSystemTime = in.readInt();
1307 statIOWaitTime = in.readInt();
1308 statIrqTime = in.readInt();
1309 statSoftIrqTime = in.readInt();
1310 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001311 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001312 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001313 }
1314 }
1315
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001316 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001317 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001318
1319 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001320 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001321
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001322 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001323 public static final byte CMD_NULL = -1;
1324 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001325 public static final byte CMD_CURRENT_TIME = 5;
1326 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001327 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001328 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001329
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001330 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001331
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001332 /**
1333 * Return whether the command code is a delta data update.
1334 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001335 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001336 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001337 }
1338
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001339 public byte batteryLevel;
1340 public byte batteryStatus;
1341 public byte batteryHealth;
1342 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001343
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001344 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001345 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001346
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001347 // The charge of the battery in micro-Ampere-hours.
1348 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001349
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001350 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001351 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001352 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001353 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001354 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1355 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001356 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001357 public static final int STATE_PHONE_STATE_SHIFT = 6;
1358 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001359 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001360 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001361 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001362
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001363 // These states always appear directly in the first int token
1364 // of a delta change; they should be ones that change relatively
1365 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001366 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1367 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001368 public static final int STATE_GPS_ON_FLAG = 1<<29;
1369 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001370 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001371 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001372 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001373 // Do not use, this is used for coulomb delta count.
1374 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001375 // These are on the lower bits used for the command; if they change
1376 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001377 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001378 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001379 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001380 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1381 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1382 // empty slot
1383 // empty slot
1384 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001385
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001386 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001387 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1388
1389 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001390
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001391 public int states;
1392
Dianne Hackborn3251b902014-06-20 14:40:53 -07001393 // Constants from WIFI_SUPPL_STATE_*
1394 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1395 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1396 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1397 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1398 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1399 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1400
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001401 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001402 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1403 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1404 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001405 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001406 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1407 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1408 public static final int STATE2_CHARGING_FLAG = 1<<24;
1409 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1410 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1411 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001412 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001413
1414 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001415 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001416 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1417
1418 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001419
Dianne Hackborn40c87252014-03-19 16:55:40 -07001420 public int states2;
1421
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001422 // The wake lock that was acquired at this point.
1423 public HistoryTag wakelockTag;
1424
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001425 // Kernel wakeup reason at this point.
1426 public HistoryTag wakeReasonTag;
1427
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001428 // Non-null when there is more detailed information at this step.
1429 public HistoryStepDetails stepDetails;
1430
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001431 public static final int EVENT_FLAG_START = 0x8000;
1432 public static final int EVENT_FLAG_FINISH = 0x4000;
1433
1434 // No event in this item.
1435 public static final int EVENT_NONE = 0x0000;
1436 // Event is about a process that is running.
1437 public static final int EVENT_PROC = 0x0001;
1438 // Event is about an application package that is in the foreground.
1439 public static final int EVENT_FOREGROUND = 0x0002;
1440 // Event is about an application package that is at the top of the screen.
1441 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001442 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001443 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001444 // Events for all additional wake locks aquired/release within a wake block.
1445 // These are not generated by default.
1446 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001447 // Event is about an application executing a scheduled job.
1448 public static final int EVENT_JOB = 0x0006;
1449 // Events for users running.
1450 public static final int EVENT_USER_RUNNING = 0x0007;
1451 // Events for foreground user.
1452 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001453 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001454 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001455 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001456 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001457 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001458 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001459 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001460 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001461 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001462 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001463 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001464 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001465 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001466 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001467 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001468 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001469 // Event for a package being on the temporary whitelist.
1470 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001471 // Event for the screen waking up.
1472 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001473 // Event for the UID that woke up the application processor.
1474 // Used for wakeups coming from WiFi, modem, etc.
1475 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001476 // Event for reporting that a specific partial wake lock has been held for a long duration.
1477 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001478
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001479 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001480 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001481 // Mask to extract out only the type part of the event.
1482 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001483
1484 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1485 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1486 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1487 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1488 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1489 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001490 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1491 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001492 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1493 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001494 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1495 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1496 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1497 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1498 public static final int EVENT_USER_FOREGROUND_START =
1499 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1500 public static final int EVENT_USER_FOREGROUND_FINISH =
1501 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001502 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1503 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001504 public static final int EVENT_TEMP_WHITELIST_START =
1505 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1506 public static final int EVENT_TEMP_WHITELIST_FINISH =
1507 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001508 public static final int EVENT_LONG_WAKE_LOCK_START =
1509 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1510 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1511 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001512
1513 // For CMD_EVENT.
1514 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001515 public HistoryTag eventTag;
1516
Dianne Hackborn9a755432014-05-15 17:05:22 -07001517 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001518 public long currentTime;
1519
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001520 // Meta-data when reading.
1521 public int numReadInts;
1522
1523 // Pre-allocated objects.
1524 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001525 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001526 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001527
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001528 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001529 }
Bookatzc8c44962017-05-11 12:12:54 -07001530
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001531 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001532 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001533 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001534 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001535 }
Bookatzc8c44962017-05-11 12:12:54 -07001536
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001537 public int describeContents() {
1538 return 0;
1539 }
1540
1541 public void writeToParcel(Parcel dest, int flags) {
1542 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001543 int bat = (((int)cmd)&0xff)
1544 | ((((int)batteryLevel)<<8)&0xff00)
1545 | ((((int)batteryStatus)<<16)&0xf0000)
1546 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001547 | ((((int)batteryPlugType)<<24)&0xf000000)
1548 | (wakelockTag != null ? 0x10000000 : 0)
1549 | (wakeReasonTag != null ? 0x20000000 : 0)
1550 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001551 dest.writeInt(bat);
1552 bat = (((int)batteryTemperature)&0xffff)
1553 | ((((int)batteryVoltage)<<16)&0xffff0000);
1554 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001555 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001556 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001557 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001558 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001559 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001560 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001561 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001562 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001563 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001564 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001565 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001566 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001567 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001568 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001569 dest.writeLong(currentTime);
1570 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001571 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001572
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001573 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001574 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001575 int bat = src.readInt();
1576 cmd = (byte)(bat&0xff);
1577 batteryLevel = (byte)((bat>>8)&0xff);
1578 batteryStatus = (byte)((bat>>16)&0xf);
1579 batteryHealth = (byte)((bat>>20)&0xf);
1580 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001581 int bat2 = src.readInt();
1582 batteryTemperature = (short)(bat2&0xffff);
1583 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001584 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001585 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001586 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001587 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001588 wakelockTag = localWakelockTag;
1589 wakelockTag.readFromParcel(src);
1590 } else {
1591 wakelockTag = null;
1592 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001593 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001594 wakeReasonTag = localWakeReasonTag;
1595 wakeReasonTag.readFromParcel(src);
1596 } else {
1597 wakeReasonTag = null;
1598 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001599 if ((bat&0x40000000) != 0) {
1600 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001601 eventTag = localEventTag;
1602 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001603 } else {
1604 eventCode = EVENT_NONE;
1605 eventTag = null;
1606 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001607 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001608 currentTime = src.readLong();
1609 } else {
1610 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001611 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001612 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001613 }
1614
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001615 public void clear() {
1616 time = 0;
1617 cmd = CMD_NULL;
1618 batteryLevel = 0;
1619 batteryStatus = 0;
1620 batteryHealth = 0;
1621 batteryPlugType = 0;
1622 batteryTemperature = 0;
1623 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001624 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001625 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001626 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001627 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001628 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001629 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001630 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001631 }
Bookatzc8c44962017-05-11 12:12:54 -07001632
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001633 public void setTo(HistoryItem o) {
1634 time = o.time;
1635 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001636 setToCommon(o);
1637 }
1638
1639 public void setTo(long time, byte cmd, HistoryItem o) {
1640 this.time = time;
1641 this.cmd = cmd;
1642 setToCommon(o);
1643 }
1644
1645 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001646 batteryLevel = o.batteryLevel;
1647 batteryStatus = o.batteryStatus;
1648 batteryHealth = o.batteryHealth;
1649 batteryPlugType = o.batteryPlugType;
1650 batteryTemperature = o.batteryTemperature;
1651 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001652 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001653 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001654 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001655 if (o.wakelockTag != null) {
1656 wakelockTag = localWakelockTag;
1657 wakelockTag.setTo(o.wakelockTag);
1658 } else {
1659 wakelockTag = null;
1660 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001661 if (o.wakeReasonTag != null) {
1662 wakeReasonTag = localWakeReasonTag;
1663 wakeReasonTag.setTo(o.wakeReasonTag);
1664 } else {
1665 wakeReasonTag = null;
1666 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001667 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001668 if (o.eventTag != null) {
1669 eventTag = localEventTag;
1670 eventTag.setTo(o.eventTag);
1671 } else {
1672 eventTag = null;
1673 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001674 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001675 }
1676
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001677 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001678 return batteryLevel == o.batteryLevel
1679 && batteryStatus == o.batteryStatus
1680 && batteryHealth == o.batteryHealth
1681 && batteryPlugType == o.batteryPlugType
1682 && batteryTemperature == o.batteryTemperature
1683 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001684 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001685 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001686 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001687 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001688 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001689
1690 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001691 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001692 return false;
1693 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001694 if (wakelockTag != o.wakelockTag) {
1695 if (wakelockTag == null || o.wakelockTag == null) {
1696 return false;
1697 }
1698 if (!wakelockTag.equals(o.wakelockTag)) {
1699 return false;
1700 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001701 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001702 if (wakeReasonTag != o.wakeReasonTag) {
1703 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1704 return false;
1705 }
1706 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1707 return false;
1708 }
1709 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001710 if (eventTag != o.eventTag) {
1711 if (eventTag == null || o.eventTag == null) {
1712 return false;
1713 }
1714 if (!eventTag.equals(o.eventTag)) {
1715 return false;
1716 }
1717 }
1718 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001719 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001720 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001721
1722 public final static class HistoryEventTracker {
1723 private final HashMap<String, SparseIntArray>[] mActiveEvents
1724 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1725
1726 public boolean updateState(int code, String name, int uid, int poolIdx) {
1727 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1728 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1729 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1730 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001731 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001732 mActiveEvents[idx] = active;
1733 }
1734 SparseIntArray uids = active.get(name);
1735 if (uids == null) {
1736 uids = new SparseIntArray();
1737 active.put(name, uids);
1738 }
1739 if (uids.indexOfKey(uid) >= 0) {
1740 // Already set, nothing to do!
1741 return false;
1742 }
1743 uids.put(uid, poolIdx);
1744 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1745 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1746 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1747 if (active == null) {
1748 // not currently active, nothing to do.
1749 return false;
1750 }
1751 SparseIntArray uids = active.get(name);
1752 if (uids == null) {
1753 // not currently active, nothing to do.
1754 return false;
1755 }
1756 idx = uids.indexOfKey(uid);
1757 if (idx < 0) {
1758 // not currently active, nothing to do.
1759 return false;
1760 }
1761 uids.removeAt(idx);
1762 if (uids.size() <= 0) {
1763 active.remove(name);
1764 }
1765 }
1766 return true;
1767 }
1768
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001769 public void removeEvents(int code) {
1770 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1771 mActiveEvents[idx] = null;
1772 }
1773
Dianne Hackborn37de0982014-05-09 09:32:18 -07001774 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1775 return mActiveEvents[code];
1776 }
1777 }
1778
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001779 public static final class BitDescription {
1780 public final int mask;
1781 public final int shift;
1782 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001783 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001784 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001785 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001786
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001787 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001788 this.mask = mask;
1789 this.shift = -1;
1790 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001791 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001792 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001793 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001794 }
Bookatzc8c44962017-05-11 12:12:54 -07001795
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001796 public BitDescription(int mask, int shift, String name, String shortName,
1797 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001798 this.mask = mask;
1799 this.shift = shift;
1800 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001801 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001802 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001803 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001804 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001805 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001806
Dianne Hackbornfc064132014-06-02 12:42:12 -07001807 /**
1808 * Don't allow any more batching in to the current history event. This
1809 * is called when printing partial histories, so to ensure that the next
1810 * history event will go in to a new batch after what was printed in the
1811 * last partial history.
1812 */
1813 public abstract void commitCurrentHistoryBatchLocked();
1814
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001815 public abstract int getHistoryTotalSize();
1816
1817 public abstract int getHistoryUsedSize();
1818
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001819 public abstract boolean startIteratingHistoryLocked();
1820
Dianne Hackborn099bc622014-01-22 13:39:16 -08001821 public abstract int getHistoryStringPoolSize();
1822
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001823 public abstract int getHistoryStringPoolBytes();
1824
1825 public abstract String getHistoryTagPoolString(int index);
1826
1827 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001828
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001829 public abstract boolean getNextHistoryLocked(HistoryItem out);
1830
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001831 public abstract void finishIteratingHistoryLocked();
1832
1833 public abstract boolean startIteratingOldHistoryLocked();
1834
1835 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1836
1837 public abstract void finishIteratingOldHistoryLocked();
1838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001840 * Return the base time offset for the battery history.
1841 */
1842 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001843
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001844 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 * Returns the number of times the device has been started.
1846 */
1847 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001850 * 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 -08001851 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001852 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 * {@hide}
1854 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001855 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001856
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001857 /**
1858 * Returns the number of times the screen was turned on.
1859 *
1860 * {@hide}
1861 */
1862 public abstract int getScreenOnCount(int which);
1863
Jeff Browne95c3cd2014-05-02 16:59:26 -07001864 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1865
Dianne Hackborn617f8772009-03-31 15:04:46 -07001866 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1867 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1868 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1869 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1870 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001871
Dianne Hackborn617f8772009-03-31 15:04:46 -07001872 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1873 "dark", "dim", "medium", "light", "bright"
1874 };
Bookatzc8c44962017-05-11 12:12:54 -07001875
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001876 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1877 "0", "1", "2", "3", "4"
1878 };
1879
Dianne Hackborn617f8772009-03-31 15:04:46 -07001880 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001881
Dianne Hackborn617f8772009-03-31 15:04:46 -07001882 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001883 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001884 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001885 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001886 * {@hide}
1887 */
1888 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001889 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001892 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001893 * running on battery.
1894 *
1895 * {@hide}
1896 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001897 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001898
1899 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001900 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001901 *
1902 * {@hide}
1903 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001904 public abstract int getPowerSaveModeEnabledCount(int which);
1905
1906 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001907 * Constant for device idle mode: not active.
1908 */
1909 public static final int DEVICE_IDLE_MODE_OFF = 0;
1910
1911 /**
1912 * Constant for device idle mode: active in lightweight mode.
1913 */
1914 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1915
1916 /**
1917 * Constant for device idle mode: active in full mode.
1918 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001919 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001920
1921 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001922 * Returns the time in microseconds that device has been in idle mode while
1923 * running on battery.
1924 *
1925 * {@hide}
1926 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001927 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001928
1929 /**
1930 * Returns the number of times that the devie has gone in to idle mode.
1931 *
1932 * {@hide}
1933 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001934 public abstract int getDeviceIdleModeCount(int mode, int which);
1935
1936 /**
1937 * Return the longest duration we spent in a particular device idle mode (fully in the
1938 * mode, not in idle maintenance etc).
1939 */
1940 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001941
1942 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001943 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001944 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001945 * counts all of the time that we consider the device to be idle, whether or not
1946 * it is currently in the actual device idle mode.
1947 *
1948 * {@hide}
1949 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001950 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001951
1952 /**
1953 * Returns the number of times that the devie has started idling.
1954 *
1955 * {@hide}
1956 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001957 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001958
1959 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001960 * Returns the number of times that connectivity state changed.
1961 *
1962 * {@hide}
1963 */
1964 public abstract int getNumConnectivityChange(int which);
1965
1966 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001967 * 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 -08001968 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001969 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 * {@hide}
1971 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001972 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001973
Dianne Hackborn627bba72009-03-24 22:32:56 -07001974 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001975 * Returns the number of times a phone call was activated.
1976 *
1977 * {@hide}
1978 */
1979 public abstract int getPhoneOnCount(int which);
1980
1981 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001982 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001983 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001984 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001985 * {@hide}
1986 */
1987 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001988 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001989
Dianne Hackborn617f8772009-03-31 15:04:46 -07001990 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001991 * Returns the time in microseconds that the phone has been trying to
1992 * acquire a signal.
1993 *
1994 * {@hide}
1995 */
1996 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001997 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001998
1999 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002000 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002001 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002002 * {@hide}
2003 */
2004 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2005
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002006 /**
2007 * Returns the time in microseconds that the mobile network has been active
2008 * (in a high power state).
2009 *
2010 * {@hide}
2011 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002012 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002013
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002014 /**
2015 * Returns the number of times that the mobile network has transitioned to the
2016 * active state.
2017 *
2018 * {@hide}
2019 */
2020 public abstract int getMobileRadioActiveCount(int which);
2021
2022 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002023 * Returns the time in microseconds that is the difference between the mobile radio
2024 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2025 * from the radio.
2026 *
2027 * {@hide}
2028 */
2029 public abstract long getMobileRadioActiveAdjustedTime(int which);
2030
2031 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002032 * Returns the time in microseconds that the mobile network has been active
2033 * (in a high power state) but not being able to blame on an app.
2034 *
2035 * {@hide}
2036 */
2037 public abstract long getMobileRadioActiveUnknownTime(int which);
2038
2039 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002040 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002041 *
2042 * {@hide}
2043 */
2044 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002045
Dianne Hackborn627bba72009-03-24 22:32:56 -07002046 public static final int DATA_CONNECTION_NONE = 0;
2047 public static final int DATA_CONNECTION_GPRS = 1;
2048 public static final int DATA_CONNECTION_EDGE = 2;
2049 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002050 public static final int DATA_CONNECTION_CDMA = 4;
2051 public static final int DATA_CONNECTION_EVDO_0 = 5;
2052 public static final int DATA_CONNECTION_EVDO_A = 6;
2053 public static final int DATA_CONNECTION_1xRTT = 7;
2054 public static final int DATA_CONNECTION_HSDPA = 8;
2055 public static final int DATA_CONNECTION_HSUPA = 9;
2056 public static final int DATA_CONNECTION_HSPA = 10;
2057 public static final int DATA_CONNECTION_IDEN = 11;
2058 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002059 public static final int DATA_CONNECTION_LTE = 13;
2060 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002061 public static final int DATA_CONNECTION_HSPAP = 15;
2062 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002063
Dianne Hackborn627bba72009-03-24 22:32:56 -07002064 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002065 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002066 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002067 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002068 };
Bookatzc8c44962017-05-11 12:12:54 -07002069
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002070 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002071
Dianne Hackborn627bba72009-03-24 22:32:56 -07002072 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002073 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002074 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002075 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002076 * {@hide}
2077 */
2078 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002079 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002082 * Returns the number of times the phone has entered the given data
2083 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002084 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002085 * {@hide}
2086 */
2087 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002088
Dianne Hackborn3251b902014-06-20 14:40:53 -07002089 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2090 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2091 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2092 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2093 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2094 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2095 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2096 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2097 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2098 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2099 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2100 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2101 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2102
2103 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2104
2105 static final String[] WIFI_SUPPL_STATE_NAMES = {
2106 "invalid", "disconn", "disabled", "inactive", "scanning",
2107 "authenticating", "associating", "associated", "4-way-handshake",
2108 "group-handshake", "completed", "dormant", "uninit"
2109 };
2110
2111 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2112 "inv", "dsc", "dis", "inact", "scan",
2113 "auth", "ascing", "asced", "4-way",
2114 "group", "compl", "dorm", "uninit"
2115 };
2116
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002117 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2118 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002119 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002120 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2121 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002122 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002123 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2124 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2125 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002126 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002127 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002128 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002129 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002130 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2131 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002132 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2133 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2134 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2135 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2136 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2137 new String[] {"in", "out", "emergency", "off"},
2138 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002139 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2140 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2141 SignalStrength.SIGNAL_STRENGTH_NAMES,
2142 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002143 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2144 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2145 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002146 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002147
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002148 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2149 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002150 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002151 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002152 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002153 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002154 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002155 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2156 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2157 new String[] { "off", "light", "full", "???" },
2158 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002159 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2160 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2161 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002162 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2163 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2164 new String[] { "0", "1", "2", "3", "4" },
2165 new String[] { "0", "1", "2", "3", "4" }),
2166 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2167 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2168 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002169 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002170 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002171 };
2172
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002173 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002174 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002175 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2176 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002177 };
2178
2179 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002180 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002181 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002182 "Esw", "Ewa", "Elw", "Eec"
2183 };
2184
2185 @FunctionalInterface
2186 public interface IntToString {
2187 String applyAsString(int val);
2188 }
2189
2190 private static final IntToString sUidToString = UserHandle::formatUid;
2191 private static final IntToString sIntToString = Integer::toString;
2192
2193 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2194 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2195 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2196 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2197 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002198 };
2199
Dianne Hackborn617f8772009-03-31 15:04:46 -07002200 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002201 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002202 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002203 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002204 * {@hide}
2205 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002206 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002207
2208 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002209 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002210 * been in the running state while the device was running on battery.
2211 *
2212 * {@hide}
2213 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002214 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002215
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002216 public static final int WIFI_STATE_OFF = 0;
2217 public static final int WIFI_STATE_OFF_SCANNING = 1;
2218 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2219 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2220 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2221 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2222 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2223 public static final int WIFI_STATE_SOFT_AP = 7;
2224
2225 static final String[] WIFI_STATE_NAMES = {
2226 "off", "scanning", "no_net", "disconn",
2227 "sta", "p2p", "sta_p2p", "soft_ap"
2228 };
2229
2230 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2231
2232 /**
2233 * Returns the time in microseconds that WiFi has been running in the given state.
2234 *
2235 * {@hide}
2236 */
2237 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002238 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002239
2240 /**
2241 * Returns the number of times that WiFi has entered the given state.
2242 *
2243 * {@hide}
2244 */
2245 public abstract int getWifiStateCount(int wifiState, int which);
2246
The Android Open Source Project10592532009-03-18 17:39:46 -07002247 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002248 * Returns the time in microseconds that the wifi supplicant has been
2249 * in a given state.
2250 *
2251 * {@hide}
2252 */
2253 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2254
2255 /**
2256 * Returns the number of times that the wifi supplicant has transitioned
2257 * to a given state.
2258 *
2259 * {@hide}
2260 */
2261 public abstract int getWifiSupplStateCount(int state, int which);
2262
2263 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2264
2265 /**
2266 * Returns the time in microseconds that WIFI has been running with
2267 * the given signal strength.
2268 *
2269 * {@hide}
2270 */
2271 public abstract long getWifiSignalStrengthTime(int strengthBin,
2272 long elapsedRealtimeUs, int which);
2273
2274 /**
2275 * Returns the number of times WIFI has entered the given signal strength.
2276 *
2277 * {@hide}
2278 */
2279 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2280
2281 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002282 * Returns the time in microseconds that the flashlight has been on while the device was
2283 * running on battery.
2284 *
2285 * {@hide}
2286 */
2287 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2288
2289 /**
2290 * Returns the number of times that the flashlight has been turned on while the device was
2291 * running on battery.
2292 *
2293 * {@hide}
2294 */
2295 public abstract long getFlashlightOnCount(int which);
2296
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002297 /**
2298 * Returns the time in microseconds that the camera has been on while the device was
2299 * running on battery.
2300 *
2301 * {@hide}
2302 */
2303 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2304
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002305 /**
2306 * Returns the time in microseconds that bluetooth scans were running while the device was
2307 * on battery.
2308 *
2309 * {@hide}
2310 */
2311 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002312
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002313 public static final int NETWORK_MOBILE_RX_DATA = 0;
2314 public static final int NETWORK_MOBILE_TX_DATA = 1;
2315 public static final int NETWORK_WIFI_RX_DATA = 2;
2316 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002317 public static final int NETWORK_BT_RX_DATA = 4;
2318 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002319 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2320 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2321 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2322 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2323 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002324
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002325 public abstract long getNetworkActivityBytes(int type, int which);
2326 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002327
Adam Lesinskie08af192015-03-25 16:42:59 -07002328 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002329 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002330 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002331 * actual power data.
2332 */
2333 public abstract boolean hasWifiActivityReporting();
2334
2335 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002336 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2337 * in various radio controller states, such as transmit, receive, and idle.
2338 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002339 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002340 public abstract ControllerActivityCounter getWifiControllerActivity();
2341
2342 /**
2343 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2344 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2345 * actual power data.
2346 */
2347 public abstract boolean hasBluetoothActivityReporting();
2348
2349 /**
2350 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2351 * in various radio controller states, such as transmit, receive, and idle.
2352 * @return non-null {@link ControllerActivityCounter}
2353 */
2354 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2355
2356 /**
2357 * Returns true if the BatteryStats object has detailed modem power reports.
2358 * When true, calling {@link #getModemControllerActivity()} will yield the
2359 * actual power data.
2360 */
2361 public abstract boolean hasModemActivityReporting();
2362
2363 /**
2364 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2365 * in various radio controller states, such as transmit, receive, and idle.
2366 * @return non-null {@link ControllerActivityCounter}
2367 */
2368 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002369
The Android Open Source Project10592532009-03-18 17:39:46 -07002370 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002371 * Return the wall clock time when battery stats data collection started.
2372 */
2373 public abstract long getStartClockTime();
2374
2375 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002376 * Return platform version tag that we were running in when the battery stats started.
2377 */
2378 public abstract String getStartPlatformVersion();
2379
2380 /**
2381 * Return platform version tag that we were running in when the battery stats ended.
2382 */
2383 public abstract String getEndPlatformVersion();
2384
2385 /**
2386 * Return the internal version code of the parcelled format.
2387 */
2388 public abstract int getParcelVersion();
2389
2390 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 * Return whether we are currently running on battery.
2392 */
2393 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 /**
2396 * Returns a SparseArray containing the statistics for each uid.
2397 */
2398 public abstract SparseArray<? extends Uid> getUidStats();
2399
2400 /**
2401 * Returns the current battery uptime in microseconds.
2402 *
2403 * @param curTime the amount of elapsed realtime in microseconds.
2404 */
2405 public abstract long getBatteryUptime(long curTime);
2406
2407 /**
2408 * Returns the current battery realtime in microseconds.
2409 *
2410 * @param curTime the amount of elapsed realtime in microseconds.
2411 */
2412 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002413
The Android Open Source Project10592532009-03-18 17:39:46 -07002414 /**
Evan Millar633a1742009-04-02 16:36:33 -07002415 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002416 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002417 */
Evan Millar633a1742009-04-02 16:36:33 -07002418 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002419
The Android Open Source Project10592532009-03-18 17:39:46 -07002420 /**
Evan Millar633a1742009-04-02 16:36:33 -07002421 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2422 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002423 */
Evan Millar633a1742009-04-02 16:36:33 -07002424 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425
2426 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002427 * Get the amount the battery has discharged since the stats were
2428 * last reset after charging, as a lower-end approximation.
2429 */
2430 public abstract int getLowDischargeAmountSinceCharge();
2431
2432 /**
2433 * Get the amount the battery has discharged since the stats were
2434 * last reset after charging, as an upper-end approximation.
2435 */
2436 public abstract int getHighDischargeAmountSinceCharge();
2437
2438 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002439 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2440 */
2441 public abstract int getDischargeAmount(int which);
2442
2443 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002444 * Get the amount the battery has discharged while the screen was on,
2445 * since the last time power was unplugged.
2446 */
2447 public abstract int getDischargeAmountScreenOn();
2448
2449 /**
2450 * Get the amount the battery has discharged while the screen was on,
2451 * since the last time the device was charged.
2452 */
2453 public abstract int getDischargeAmountScreenOnSinceCharge();
2454
2455 /**
2456 * Get the amount the battery has discharged while the screen was off,
2457 * since the last time power was unplugged.
2458 */
2459 public abstract int getDischargeAmountScreenOff();
2460
2461 /**
2462 * Get the amount the battery has discharged while the screen was off,
2463 * since the last time the device was charged.
2464 */
2465 public abstract int getDischargeAmountScreenOffSinceCharge();
2466
2467 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 * Returns the total, last, or current battery uptime in microseconds.
2469 *
2470 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002471 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 */
2473 public abstract long computeBatteryUptime(long curTime, int which);
2474
2475 /**
2476 * Returns the total, last, or current battery realtime in microseconds.
2477 *
2478 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002479 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 */
2481 public abstract long computeBatteryRealtime(long curTime, int which);
2482
2483 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002484 * Returns the total, last, or current battery screen off uptime in microseconds.
2485 *
2486 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002487 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002488 */
2489 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2490
2491 /**
2492 * Returns the total, last, or current battery screen off realtime in microseconds.
2493 *
2494 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002495 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002496 */
2497 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2498
2499 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 * Returns the total, last, or current uptime in microseconds.
2501 *
2502 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002503 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 */
2505 public abstract long computeUptime(long curTime, int which);
2506
2507 /**
2508 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002509 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002511 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 */
2513 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002514
2515 /**
2516 * Compute an approximation for how much run time (in microseconds) is remaining on
2517 * the battery. Returns -1 if no time can be computed: either there is not
2518 * enough current data to make a decision, or the battery is currently
2519 * charging.
2520 *
2521 * @param curTime The current elepsed realtime in microseconds.
2522 */
2523 public abstract long computeBatteryTimeRemaining(long curTime);
2524
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002525 // The part of a step duration that is the actual time.
2526 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2527
2528 // Bits in a step duration that are the new battery level we are at.
2529 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002530 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002531
2532 // Bits in a step duration that are the initial mode we were in at that step.
2533 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002534 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002535
2536 // Bits in a step duration that indicate which modes changed during that step.
2537 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002538 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002539
2540 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2541 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2542
Santos Cordone94f0502017-02-24 12:31:20 -08002543 // The largest value for screen state that is tracked in battery states. Any values above
2544 // this should be mapped back to one of the tracked values before being tracked here.
2545 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2546
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002547 // Step duration mode: power save is on.
2548 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2549
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002550 // Step duration mode: device is currently in idle mode.
2551 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2552
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002553 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2554 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002555 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2556 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002557 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2558 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2559 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2560 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2561 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002562 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2563 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002564 };
2565 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2566 (Display.STATE_OFF-1),
2567 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002568 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002569 (Display.STATE_ON-1),
2570 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2571 (Display.STATE_DOZE-1),
2572 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2573 (Display.STATE_DOZE_SUSPEND-1),
2574 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002575 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002576 };
2577 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2578 "screen off",
2579 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002580 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002581 "screen on",
2582 "screen on power save",
2583 "screen doze",
2584 "screen doze power save",
2585 "screen doze-suspend",
2586 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002587 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002588 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002589
2590 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002591 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2592 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2593 * a coulomb counter.
2594 */
2595 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2596
2597 /**
2598 * Return the counter keeping track of the amount of battery discharge measured in
2599 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2600 * a coulomb counter.
2601 */
2602 public abstract LongCounter getDischargeCoulombCounter();
2603
2604 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002605 * Returns the estimated real battery capacity, which may be less than the capacity
2606 * declared by the PowerProfile.
2607 * @return The estimated battery capacity in mAh.
2608 */
2609 public abstract int getEstimatedBatteryCapacity();
2610
2611 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002612 * @return The minimum learned battery capacity in uAh.
2613 */
2614 public abstract int getMinLearnedBatteryCapacity();
2615
2616 /**
2617 * @return The maximum learned battery capacity in uAh.
2618 */
2619 public abstract int getMaxLearnedBatteryCapacity() ;
2620
2621 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002622 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002623 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002624 public abstract LevelStepTracker getDischargeLevelStepTracker();
2625
2626 /**
2627 * Return the array of daily discharge step durations.
2628 */
2629 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002630
2631 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002632 * Compute an approximation for how much time (in microseconds) remains until the battery
2633 * is fully charged. Returns -1 if no time can be computed: either there is not
2634 * enough current data to make a decision, or the battery is currently
2635 * discharging.
2636 *
2637 * @param curTime The current elepsed realtime in microseconds.
2638 */
2639 public abstract long computeChargeTimeRemaining(long curTime);
2640
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002641 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002642 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002643 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002644 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002645
2646 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002647 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002648 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002649 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002650
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002651 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2652
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002653 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002654
Evan Millarc64edde2009-04-18 12:26:32 -07002655 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656
Bookatz50df7112017-08-04 14:53:26 -07002657 /**
2658 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2659 */
2660 public abstract Map<String, ? extends Timer> getRpmStats();
2661 /**
2662 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2663 */
2664 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2665
2666
James Carr2dd7e5e2016-07-20 18:48:39 -07002667 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2668
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002669 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2670
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002671 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 long days = seconds / (60 * 60 * 24);
2673 if (days != 0) {
2674 out.append(days);
2675 out.append("d ");
2676 }
2677 long used = days * 60 * 60 * 24;
2678
2679 long hours = (seconds - used) / (60 * 60);
2680 if (hours != 0 || used != 0) {
2681 out.append(hours);
2682 out.append("h ");
2683 }
2684 used += hours * 60 * 60;
2685
2686 long mins = (seconds-used) / 60;
2687 if (mins != 0 || used != 0) {
2688 out.append(mins);
2689 out.append("m ");
2690 }
2691 used += mins * 60;
2692
2693 if (seconds != 0 || used != 0) {
2694 out.append(seconds-used);
2695 out.append("s ");
2696 }
2697 }
2698
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002699 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002701 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 sb.append(time - (sec * 1000));
2703 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 }
2705
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002706 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002707 long sec = time / 1000;
2708 formatTimeRaw(sb, sec);
2709 sb.append(time - (sec * 1000));
2710 sb.append("ms");
2711 }
2712
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002713 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002715 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 }
2717 float perc = ((float)num) / ((float)den) * 100;
2718 mFormatBuilder.setLength(0);
2719 mFormatter.format("%.1f%%", perc);
2720 return mFormatBuilder.toString();
2721 }
2722
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002723 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002724 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002725
Evan Millar22ac0432009-03-31 11:33:18 -07002726 if (bytes < BYTES_PER_KB) {
2727 return bytes + "B";
2728 } else if (bytes < BYTES_PER_MB) {
2729 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2730 return mFormatBuilder.toString();
2731 } else if (bytes < BYTES_PER_GB){
2732 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2733 return mFormatBuilder.toString();
2734 } else {
2735 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2736 return mFormatBuilder.toString();
2737 }
2738 }
2739
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002740 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002741 if (timer != null) {
2742 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002743 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002744 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2745 return totalTimeMillis;
2746 }
2747 return 0;
2748 }
2749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 /**
2751 *
2752 * @param sb a StringBuilder object.
2753 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002754 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002756 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 * @param linePrefix a String to be prepended to each line of output.
2758 * @return the line prefix
2759 */
2760 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002761 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002764 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002765
Evan Millarc64edde2009-04-18 12:26:32 -07002766 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 if (totalTimeMillis != 0) {
2768 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002769 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002770 if (name != null) {
2771 sb.append(name);
2772 sb.append(' ');
2773 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 sb.append('(');
2775 sb.append(count);
2776 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002777 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2778 if (maxDurationMs >= 0) {
2779 sb.append(" max=");
2780 sb.append(maxDurationMs);
2781 }
Bookatz506a8182017-05-01 14:18:42 -07002782 // Put actual time if it is available and different from totalTimeMillis.
2783 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2784 if (totalDurMs > totalTimeMillis) {
2785 sb.append(" actual=");
2786 sb.append(totalDurMs);
2787 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002788 if (timer.isRunningLocked()) {
2789 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2790 if (currentMs >= 0) {
2791 sb.append(" (running for ");
2792 sb.append(currentMs);
2793 sb.append("ms)");
2794 } else {
2795 sb.append(" (running)");
2796 }
2797 }
2798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 return ", ";
2800 }
2801 }
2802 return linePrefix;
2803 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002804
2805 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002806 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002807 *
2808 * @param pw a PrintWriter object to print to.
2809 * @param sb a StringBuilder object.
2810 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002811 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002812 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2813 * @param prefix a String to be prepended to each line of output.
2814 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002815 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002816 */
2817 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002818 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002819 if (timer != null) {
2820 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002821 final long totalTimeMs = (timer.getTotalTimeLocked(
2822 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002823 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002824 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002825 sb.setLength(0);
2826 sb.append(prefix);
2827 sb.append(" ");
2828 sb.append(type);
2829 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002830 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002831 sb.append("realtime (");
2832 sb.append(count);
2833 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002834 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2835 if (maxDurationMs >= 0) {
2836 sb.append(" max=");
2837 sb.append(maxDurationMs);
2838 }
2839 if (timer.isRunningLocked()) {
2840 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2841 if (currentMs >= 0) {
2842 sb.append(" (running for ");
2843 sb.append(currentMs);
2844 sb.append("ms)");
2845 } else {
2846 sb.append(" (running)");
2847 }
2848 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002849 pw.println(sb.toString());
2850 return true;
2851 }
2852 }
2853 return false;
2854 }
Bookatzc8c44962017-05-11 12:12:54 -07002855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 /**
2857 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002858 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 * @param sb a StringBuilder object.
2860 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002861 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002863 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 * @param linePrefix a String to be prepended to each line of output.
2865 * @return the line prefix
2866 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002867 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2868 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 long totalTimeMicros = 0;
2870 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002871 long max = 0;
2872 long current = 0;
2873 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002875 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002876 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002877 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2878 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002879 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 }
2881 sb.append(linePrefix);
2882 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2883 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002884 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002886 sb.append(',');
2887 sb.append(current);
2888 sb.append(',');
2889 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002890 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2891 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2892 // totalDuration independent of totalTimeMicros (since they are not pooled).
2893 if (name != null) {
2894 sb.append(',');
2895 sb.append(totalDuration);
2896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 return ",";
2898 }
Bookatz506a8182017-05-01 14:18:42 -07002899
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002900 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2901 String type) {
2902 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2903 pw.print(',');
2904 pw.print(uid);
2905 pw.print(',');
2906 pw.print(category);
2907 pw.print(',');
2908 pw.print(type);
2909 }
2910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 /**
2912 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002913 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 * @param pw the PageWriter to dump log to
2915 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2916 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2917 * @param args type-dependent data arguments
2918 */
Bookatzc8c44962017-05-11 12:12:54 -07002919 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002921 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002922 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002923 pw.print(',');
2924 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002926 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002928
2929 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002930 * Dump a given timer stat for terse checkin mode.
2931 *
2932 * @param pw the PageWriter to dump log to
2933 * @param uid the UID to log
2934 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2935 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2936 * @param timer a {@link Timer} to dump stats for
2937 * @param rawRealtime the current elapsed realtime of the system in microseconds
2938 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2939 */
2940 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2941 Timer timer, long rawRealtime, int which) {
2942 if (timer != null) {
2943 // Convert from microseconds to milliseconds with rounding
2944 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2945 / 1000;
2946 final int count = timer.getCountLocked(which);
2947 if (totalTime != 0) {
2948 dumpLine(pw, uid, category, type, totalTime, count);
2949 }
2950 }
2951 }
2952
2953 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002954 * Checks if the ControllerActivityCounter has any data worth dumping.
2955 */
2956 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2957 if (counter == null) {
2958 return false;
2959 }
2960
2961 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2962 || counter.getRxTimeCounter().getCountLocked(which) != 0
2963 || counter.getPowerCounter().getCountLocked(which) != 0) {
2964 return true;
2965 }
2966
2967 for (LongCounter c : counter.getTxTimeCounters()) {
2968 if (c.getCountLocked(which) != 0) {
2969 return true;
2970 }
2971 }
2972 return false;
2973 }
2974
2975 /**
2976 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2977 * The order of the arguments in the final check in line is:
2978 *
2979 * idle, rx, power, tx...
2980 *
2981 * where tx... is one or more transmit level times.
2982 */
2983 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2984 String type,
2985 ControllerActivityCounter counter,
2986 int which) {
2987 if (!controllerActivityHasData(counter, which)) {
2988 return;
2989 }
2990
2991 dumpLineHeader(pw, uid, category, type);
2992 pw.print(",");
2993 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2994 pw.print(",");
2995 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2996 pw.print(",");
2997 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2998 for (LongCounter c : counter.getTxTimeCounters()) {
2999 pw.print(",");
3000 pw.print(c.getCountLocked(which));
3001 }
3002 pw.println();
3003 }
3004
3005 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3006 String prefix, String controllerName,
3007 ControllerActivityCounter counter,
3008 int which) {
3009 if (controllerActivityHasData(counter, which)) {
3010 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3011 }
3012 }
3013
3014 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3015 String controllerName,
3016 ControllerActivityCounter counter, int which) {
3017 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3018 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3019 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
3020 long totalTxTimeMs = 0;
3021 for (LongCounter txState : counter.getTxTimeCounters()) {
3022 totalTxTimeMs += txState.getCountLocked(which);
3023 }
3024
3025 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
3026
3027 sb.setLength(0);
3028 sb.append(prefix);
3029 sb.append(" ");
3030 sb.append(controllerName);
3031 sb.append(" Idle time: ");
3032 formatTimeMs(sb, idleTimeMs);
3033 sb.append("(");
3034 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
3035 sb.append(")");
3036 pw.println(sb.toString());
3037
3038 sb.setLength(0);
3039 sb.append(prefix);
3040 sb.append(" ");
3041 sb.append(controllerName);
3042 sb.append(" Rx time: ");
3043 formatTimeMs(sb, rxTimeMs);
3044 sb.append("(");
3045 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
3046 sb.append(")");
3047 pw.println(sb.toString());
3048
3049 sb.setLength(0);
3050 sb.append(prefix);
3051 sb.append(" ");
3052 sb.append(controllerName);
3053 sb.append(" Tx time: ");
3054 formatTimeMs(sb, totalTxTimeMs);
3055 sb.append("(");
3056 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
3057 sb.append(")");
3058 pw.println(sb.toString());
3059
3060 final int numTxLvls = counter.getTxTimeCounters().length;
3061 if (numTxLvls > 1) {
3062 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3063 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3064 sb.setLength(0);
3065 sb.append(prefix);
3066 sb.append(" [");
3067 sb.append(lvl);
3068 sb.append("] ");
3069 formatTimeMs(sb, txLvlTimeMs);
3070 sb.append("(");
3071 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3072 sb.append(")");
3073 pw.println(sb.toString());
3074 }
3075 }
3076
3077 sb.setLength(0);
3078 sb.append(prefix);
3079 sb.append(" ");
3080 sb.append(controllerName);
3081 sb.append(" Power drain: ").append(
3082 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3083 sb.append("mAh");
3084 pw.println(sb.toString());
3085 }
3086
3087 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003088 * Temporary for settings.
3089 */
3090 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3091 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3092 }
3093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 /**
3095 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003096 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003099 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3100 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3102 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003103 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3106 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003107 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3108 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3109 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 final long totalRealtime = computeRealtime(rawRealtime, which);
3111 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003112 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003113 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003114 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003115 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3116 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003117 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003118 rawRealtime, which);
3119 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3120 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003121 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003122 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003123 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003124 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003125 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3126 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3127 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003128
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003129 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003130
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003131 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003132 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003133
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003134 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003137 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003138 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003139 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003140 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003141 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003142 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003143 getEstimatedBatteryCapacity(),
3144 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003145
Bookatzc8c44962017-05-11 12:12:54 -07003146
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003147 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003148 long fullWakeLockTimeTotal = 0;
3149 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003150
Evan Millar22ac0432009-03-31 11:33:18 -07003151 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003152 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003153
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003154 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3155 = u.getWakelockStats();
3156 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3157 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003158
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003159 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3160 if (fullWakeTimer != null) {
3161 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3162 which);
3163 }
3164
3165 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3166 if (partialWakeTimer != null) {
3167 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3168 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003169 }
3170 }
3171 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003172
3173 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003174 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3175 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3176 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3177 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3178 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3179 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3180 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3181 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003182 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3183 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003184 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3185 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003186 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3187 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003188
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003189 // Dump Modem controller stats
3190 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3191 getModemControllerActivity(), which);
3192
Adam Lesinskie283d332015-04-16 12:29:25 -07003193 // Dump Wifi controller stats
3194 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3195 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003196 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003197 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003198
3199 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3200 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003201
3202 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003203 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3204 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 // Dump misc stats
3207 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003208 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003209 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003210 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003211 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003212 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003213 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3214 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003215 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003216 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3217 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3218 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3219 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003220 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003221
Dianne Hackborn617f8772009-03-31 15:04:46 -07003222 // Dump screen brightness stats
3223 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3224 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003225 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003226 }
3227 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003228
Dianne Hackborn627bba72009-03-24 22:32:56 -07003229 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003230 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3231 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003232 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003233 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003234 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003235 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003236 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003237 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003238 args[i] = getPhoneSignalStrengthCount(i, which);
3239 }
3240 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003241
Dianne Hackborn627bba72009-03-24 22:32:56 -07003242 // Dump network type stats
3243 args = new Object[NUM_DATA_CONNECTION_TYPES];
3244 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003245 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003246 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003247 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3248 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3249 args[i] = getPhoneDataConnectionCount(i, which);
3250 }
3251 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003252
3253 // Dump wifi state stats
3254 args = new Object[NUM_WIFI_STATES];
3255 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003256 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003257 }
3258 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3259 for (int i=0; i<NUM_WIFI_STATES; i++) {
3260 args[i] = getWifiStateCount(i, which);
3261 }
3262 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3263
Dianne Hackborn3251b902014-06-20 14:40:53 -07003264 // Dump wifi suppl state stats
3265 args = new Object[NUM_WIFI_SUPPL_STATES];
3266 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3267 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3268 }
3269 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3270 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3271 args[i] = getWifiSupplStateCount(i, which);
3272 }
3273 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3274
3275 // Dump wifi signal strength stats
3276 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3277 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3278 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3279 }
3280 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3281 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3282 args[i] = getWifiSignalStrengthCount(i, which);
3283 }
3284 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3285
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003286 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003287 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003288 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003289 }
Bookatzc8c44962017-05-11 12:12:54 -07003290
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003291 if (which == STATS_SINCE_UNPLUGGED) {
3292 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3293 getDischargeStartLevel()-getDischargeCurrentLevel(),
3294 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003295 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3296 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003297 } else {
3298 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3299 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003300 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003301 getDischargeAmountScreenOffSinceCharge(),
3302 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003303 }
Bookatzc8c44962017-05-11 12:12:54 -07003304
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003305 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003306 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003307 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003308 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003309 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003310 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003311 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3312 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003313 }
Evan Millarc64edde2009-04-18 12:26:32 -07003314 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003315 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003316 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003317 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3318 // Not doing the regular wake lock formatting to remain compatible
3319 // with the old checkin format.
3320 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3321 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003322 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003323 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003324 }
3325 }
Evan Millarc64edde2009-04-18 12:26:32 -07003326 }
Bookatzc8c44962017-05-11 12:12:54 -07003327
Bookatz50df7112017-08-04 14:53:26 -07003328 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3329 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3330 if (rpmStats.size() > 0) {
3331 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3332 sb.setLength(0);
3333 Timer totalTimer = ent.getValue();
3334 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3335 int count = totalTimer.getCountLocked(which);
3336 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3337 long screenOffTimeMs = screenOffTimer != null
3338 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3339 int screenOffCount = screenOffTimer != null
3340 ? screenOffTimer.getCountLocked(which) : 0;
3341 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3342 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, screenOffCount);
3343 }
3344 }
3345
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003346 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003347 helper.create(this);
3348 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003349 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003350 if (sippers != null && sippers.size() > 0) {
3351 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3352 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003353 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003354 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3355 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3356 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003357 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003358 int uid = 0;
3359 String label;
3360 switch (bs.drainType) {
3361 case IDLE:
3362 label="idle";
3363 break;
3364 case CELL:
3365 label="cell";
3366 break;
3367 case PHONE:
3368 label="phone";
3369 break;
3370 case WIFI:
3371 label="wifi";
3372 break;
3373 case BLUETOOTH:
3374 label="blue";
3375 break;
3376 case SCREEN:
3377 label="scrn";
3378 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003379 case FLASHLIGHT:
3380 label="flashlight";
3381 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003382 case APP:
3383 uid = bs.uidObj.getUid();
3384 label = "uid";
3385 break;
3386 case USER:
3387 uid = UserHandle.getUid(bs.userId, 0);
3388 label = "user";
3389 break;
3390 case UNACCOUNTED:
3391 label = "unacc";
3392 break;
3393 case OVERCOUNTED:
3394 label = "over";
3395 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003396 case CAMERA:
3397 label = "camera";
3398 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003399 default:
3400 label = "???";
3401 }
3402 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003403 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3404 bs.shouldHide ? 1 : 0,
3405 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3406 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003407 }
3408 }
3409
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003410 final long[] cpuFreqs = getCpuFreqs();
3411 if (cpuFreqs != null) {
3412 sb.setLength(0);
3413 for (int i = 0; i < cpuFreqs.length; ++i) {
3414 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3415 }
3416 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3417 }
3418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 for (int iu = 0; iu < NU; iu++) {
3420 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003421 if (reqUid >= 0 && uid != reqUid) {
3422 continue;
3423 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003424 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003427 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3428 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3429 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3430 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3431 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3432 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3433 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3434 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003435 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003436 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3437 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003438 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003439 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3440 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003441 // Background data transfers
3442 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3443 which);
3444 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3445 which);
3446 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3447 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3448 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3449 which);
3450 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3451 which);
3452 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3453 which);
3454 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3455 which);
3456
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003457 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3458 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003459 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003460 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3461 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3462 || wifiBytesBgTx > 0
3463 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3464 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003465 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3466 wifiBytesRx, wifiBytesTx,
3467 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003468 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003469 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003470 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3471 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3472 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3473 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003474 }
3475
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003476 // Dump modem controller data, per UID.
3477 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3478 u.getModemControllerActivity(), which);
3479
3480 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003481 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3482 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3483 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003484 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3485 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003486 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3487 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3488 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003489 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003490 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003491 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3492 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003493 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3494 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003495 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003496 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003499 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3500 u.getWifiControllerActivity(), which);
3501
Bookatz867c0d72017-03-07 18:23:42 -08003502 final Timer bleTimer = u.getBluetoothScanTimer();
3503 if (bleTimer != null) {
3504 // Convert from microseconds to milliseconds with rounding
3505 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3506 / 1000;
3507 if (totalTime != 0) {
3508 final int count = bleTimer.getCountLocked(which);
3509 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3510 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003511 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3512 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3513 final long actualTimeBg = bleTimerBg != null ?
3514 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003515 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003516 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3517 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003518 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3519 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3520 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3521 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3522 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3523 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3524 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3525 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3526 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3527 final Timer unoptimizedScanTimerBg =
3528 u.getBluetoothUnoptimizedScanBackgroundTimer();
3529 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3530 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3531 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3532 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3533
Bookatz867c0d72017-03-07 18:23:42 -08003534 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003535 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3536 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3537 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003538 }
3539 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003540
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003541 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3542 u.getBluetoothControllerActivity(), which);
3543
Dianne Hackborn617f8772009-03-31 15:04:46 -07003544 if (u.hasUserActivity()) {
3545 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3546 boolean hasData = false;
3547 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3548 int val = u.getUserActivityCount(i, which);
3549 args[i] = val;
3550 if (val != 0) hasData = true;
3551 }
3552 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003553 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003554 }
3555 }
Bookatzc8c44962017-05-11 12:12:54 -07003556
3557 if (u.getAggregatedPartialWakelockTimer() != null) {
3558 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003559 // Times are since reset (regardless of 'which')
3560 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003561 final Timer bgTimer = timer.getSubTimer();
3562 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003563 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003564 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3565 }
3566
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003567 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3568 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3569 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3570 String linePrefix = "";
3571 sb.setLength(0);
3572 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3573 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003574 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3575 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003576 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003577 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3578 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003579 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3580 rawRealtime, "w", which, linePrefix);
3581
3582 // Only log if we had at lease one wakelock...
3583 if (sb.length() > 0) {
3584 String name = wakelocks.keyAt(iw);
3585 if (name.indexOf(',') >= 0) {
3586 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 }
Yi Jin02483362017-08-04 11:30:44 -07003588 if (name.indexOf('\n') >= 0) {
3589 name = name.replace('\n', '_');
3590 }
3591 if (name.indexOf('\r') >= 0) {
3592 name = name.replace('\r', '_');
3593 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003594 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 }
3596 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003597
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003598 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3599 for (int isy=syncs.size()-1; isy>=0; isy--) {
3600 final Timer timer = syncs.valueAt(isy);
3601 // Convert from microseconds to milliseconds with rounding
3602 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3603 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003604 final Timer bgTimer = timer.getSubTimer();
3605 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003606 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003607 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003608 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003609 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003610 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003611 }
3612 }
3613
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003614 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3615 for (int ij=jobs.size()-1; ij>=0; ij--) {
3616 final Timer timer = jobs.valueAt(ij);
3617 // Convert from microseconds to milliseconds with rounding
3618 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3619 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003620 final Timer bgTimer = timer.getSubTimer();
3621 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003622 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003623 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003624 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003625 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003626 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003627 }
3628 }
3629
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003630 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3631 for (int ic=completions.size()-1; ic>=0; ic--) {
3632 SparseIntArray types = completions.valueAt(ic);
3633 if (types != null) {
3634 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3635 "\"" + completions.keyAt(ic) + "\"",
3636 types.get(JobParameters.REASON_CANCELED, 0),
3637 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3638 types.get(JobParameters.REASON_PREEMPT, 0),
3639 types.get(JobParameters.REASON_TIMEOUT, 0),
3640 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3641 }
3642 }
3643
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003644 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3645 rawRealtime, which);
3646 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3647 rawRealtime, which);
3648 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3649 rawRealtime, which);
3650 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3651 rawRealtime, which);
3652
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003653 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3654 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003655 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003656 final Uid.Sensor se = sensors.valueAt(ise);
3657 final int sensorNumber = sensors.keyAt(ise);
3658 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003659 if (timer != null) {
3660 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003661 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3662 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003663 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003664 final int count = timer.getCountLocked(which);
3665 final Timer bgTimer = se.getSensorBackgroundTime();
3666 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003667 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3668 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3669 final long bgActualTime = bgTimer != null ?
3670 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3671 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3672 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 }
3675 }
3676
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003677 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3678 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003679
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003680 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3681 rawRealtime, which);
3682
3683 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003684 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003685
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003686 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003687 long totalStateTime = 0;
3688 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003689 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3690 totalStateTime += time;
3691 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003692 }
3693 if (totalStateTime > 0) {
3694 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3695 }
3696
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003697 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3698 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003699 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003700 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003701 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003702 }
3703
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003704 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3705 if (cpuFreqs != null) {
3706 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3707 // If total cpuFreqTimes is null, then we don't need to check for
3708 // screenOffCpuFreqTimes.
3709 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3710 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003711 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003712 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003713 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003714 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3715 if (screenOffCpuFreqTimeMs != null) {
3716 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3717 sb.append("," + screenOffCpuFreqTimeMs[i]);
3718 }
3719 } else {
3720 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3721 sb.append(",0");
3722 }
3723 }
3724 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3725 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003726 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003727 }
3728
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003729 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3730 = u.getProcessStats();
3731 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3732 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003733
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003734 final long userMillis = ps.getUserTime(which);
3735 final long systemMillis = ps.getSystemTime(which);
3736 final long foregroundMillis = ps.getForegroundTime(which);
3737 final int starts = ps.getStarts(which);
3738 final int numCrashes = ps.getNumCrashes(which);
3739 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003740
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003741 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3742 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003743 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3744 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 }
3746 }
3747
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003748 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3749 = u.getPackageStats();
3750 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3751 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3752 int wakeups = 0;
3753 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3754 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003755 int count = alarms.valueAt(iwa).getCountLocked(which);
3756 wakeups += count;
3757 String name = alarms.keyAt(iwa).replace(',', '_');
3758 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003759 }
3760 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3761 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3762 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3763 final long startTime = ss.getStartTime(batteryUptime, which);
3764 final int starts = ss.getStarts(which);
3765 final int launches = ss.getLaunches(which);
3766 if (startTime != 0 || starts != 0 || launches != 0) {
3767 dumpLine(pw, uid, category, APK_DATA,
3768 wakeups, // wakeup alarms
3769 packageStats.keyAt(ipkg), // Apk
3770 serviceStats.keyAt(isvc), // service
3771 startTime / 1000, // time spent started, in ms
3772 starts,
3773 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 }
3775 }
3776 }
3777 }
3778 }
3779
Dianne Hackborn81038902012-11-26 17:04:09 -08003780 static final class TimerEntry {
3781 final String mName;
3782 final int mId;
3783 final BatteryStats.Timer mTimer;
3784 final long mTime;
3785 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3786 mName = name;
3787 mId = id;
3788 mTimer = timer;
3789 mTime = time;
3790 }
3791 }
3792
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003793 private void printmAh(PrintWriter printer, double power) {
3794 printer.print(BatteryStatsHelper.makemAh(power));
3795 }
3796
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003797 private void printmAh(StringBuilder sb, double power) {
3798 sb.append(BatteryStatsHelper.makemAh(power));
3799 }
3800
Dianne Hackbornd953c532014-08-16 18:17:38 -07003801 /**
3802 * Temporary for settings.
3803 */
3804 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3805 int reqUid) {
3806 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3807 }
3808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003810 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003811 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3813 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003814 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816
3817 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3818 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3819 final long totalRealtime = computeRealtime(rawRealtime, which);
3820 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003821 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3822 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3823 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003824 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3825 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003826
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003827 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003828
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003829 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003830 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003832 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3833 if (estimatedBatteryCapacity > 0) {
3834 sb.setLength(0);
3835 sb.append(prefix);
3836 sb.append(" Estimated battery capacity: ");
3837 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3838 sb.append(" mAh");
3839 pw.println(sb.toString());
3840 }
3841
Jocelyn Dangc627d102017-04-14 13:15:14 -07003842 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3843 if (minLearnedBatteryCapacity > 0) {
3844 sb.setLength(0);
3845 sb.append(prefix);
3846 sb.append(" Min learned battery capacity: ");
3847 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3848 sb.append(" mAh");
3849 pw.println(sb.toString());
3850 }
3851 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3852 if (maxLearnedBatteryCapacity > 0) {
3853 sb.setLength(0);
3854 sb.append(prefix);
3855 sb.append(" Max learned battery capacity: ");
3856 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3857 sb.append(" mAh");
3858 pw.println(sb.toString());
3859 }
3860
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003861 sb.setLength(0);
3862 sb.append(prefix);
3863 sb.append(" Time on battery: ");
3864 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3865 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3866 sb.append(") realtime, ");
3867 formatTimeMs(sb, whichBatteryUptime / 1000);
3868 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3869 sb.append(") uptime");
3870 pw.println(sb.toString());
3871 sb.setLength(0);
3872 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003873 sb.append(" Time on battery screen off: ");
3874 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3875 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3876 sb.append(") realtime, ");
3877 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3878 sb.append("(");
3879 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3880 sb.append(") uptime");
3881 pw.println(sb.toString());
3882 sb.setLength(0);
3883 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003884 sb.append(" Total run time: ");
3885 formatTimeMs(sb, totalRealtime / 1000);
3886 sb.append("realtime, ");
3887 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003888 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003889 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003890 if (batteryTimeRemaining >= 0) {
3891 sb.setLength(0);
3892 sb.append(prefix);
3893 sb.append(" Battery time remaining: ");
3894 formatTimeMs(sb, batteryTimeRemaining / 1000);
3895 pw.println(sb.toString());
3896 }
3897 if (chargeTimeRemaining >= 0) {
3898 sb.setLength(0);
3899 sb.append(prefix);
3900 sb.append(" Charge time remaining: ");
3901 formatTimeMs(sb, chargeTimeRemaining / 1000);
3902 pw.println(sb.toString());
3903 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003904
3905 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3906 final long dischargeCount = dischargeCounter.getCountLocked(which);
3907 if (dischargeCount >= 0) {
3908 sb.setLength(0);
3909 sb.append(prefix);
3910 sb.append(" Discharge: ");
3911 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3912 sb.append(" mAh");
3913 pw.println(sb.toString());
3914 }
3915
3916 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3917 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3918 if (dischargeScreenOffCount >= 0) {
3919 sb.setLength(0);
3920 sb.append(prefix);
3921 sb.append(" Screen off discharge: ");
3922 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3923 sb.append(" mAh");
3924 pw.println(sb.toString());
3925 }
3926
3927 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3928 if (dischargeScreenOnCount >= 0) {
3929 sb.setLength(0);
3930 sb.append(prefix);
3931 sb.append(" Screen on discharge: ");
3932 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3933 sb.append(" mAh");
3934 pw.println(sb.toString());
3935 }
3936
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003937 pw.print(" Start clock time: ");
3938 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3939
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003940 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003941 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003942 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003943 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3944 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003945 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003946 rawRealtime, which);
3947 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3948 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003949 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003950 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003951 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3952 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3953 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003954 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003955 sb.append(prefix);
3956 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3957 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003958 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003959 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3960 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003961 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003962 pw.println(sb.toString());
3963 sb.setLength(0);
3964 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003965 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003966 boolean didOne = false;
3967 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003968 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003969 if (time == 0) {
3970 continue;
3971 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003972 sb.append("\n ");
3973 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003974 didOne = true;
3975 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3976 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003977 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003978 sb.append("(");
3979 sb.append(formatRatioLocked(time, screenOnTime));
3980 sb.append(")");
3981 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003982 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003983 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003984 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003985 sb.setLength(0);
3986 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003987 sb.append(" Power save mode enabled: ");
3988 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003989 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003990 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003991 sb.append(")");
3992 pw.println(sb.toString());
3993 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003994 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003995 sb.setLength(0);
3996 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003997 sb.append(" Device light idling: ");
3998 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003999 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004000 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4001 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004002 sb.append("x");
4003 pw.println(sb.toString());
4004 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004005 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004006 sb.setLength(0);
4007 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004008 sb.append(" Idle mode light time: ");
4009 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004010 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004011 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4012 sb.append(") ");
4013 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004014 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004015 sb.append(" -- longest ");
4016 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4017 pw.println(sb.toString());
4018 }
4019 if (deviceIdlingTime != 0) {
4020 sb.setLength(0);
4021 sb.append(prefix);
4022 sb.append(" Device full idling: ");
4023 formatTimeMs(sb, deviceIdlingTime / 1000);
4024 sb.append("(");
4025 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004026 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004027 sb.append("x");
4028 pw.println(sb.toString());
4029 }
4030 if (deviceIdleModeFullTime != 0) {
4031 sb.setLength(0);
4032 sb.append(prefix);
4033 sb.append(" Idle mode full time: ");
4034 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4035 sb.append("(");
4036 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4037 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004038 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004039 sb.append("x");
4040 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004041 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004042 pw.println(sb.toString());
4043 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004044 if (phoneOnTime != 0) {
4045 sb.setLength(0);
4046 sb.append(prefix);
4047 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4048 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004049 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004050 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004051 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004052 if (connChanges != 0) {
4053 pw.print(prefix);
4054 pw.print(" Connectivity changes: "); pw.println(connChanges);
4055 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004056
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004057 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004058 long fullWakeLockTimeTotalMicros = 0;
4059 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004060
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004061 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004062
Evan Millar22ac0432009-03-31 11:33:18 -07004063 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004064 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004065
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004066 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4067 = u.getWakelockStats();
4068 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4069 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004070
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004071 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4072 if (fullWakeTimer != null) {
4073 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4074 rawRealtime, which);
4075 }
4076
4077 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4078 if (partialWakeTimer != null) {
4079 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4080 rawRealtime, which);
4081 if (totalTimeMicros > 0) {
4082 if (reqUid < 0) {
4083 // Only show the ordered list of all wake
4084 // locks if the caller is not asking for data
4085 // about a specific uid.
4086 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4087 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004088 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004089 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004090 }
4091 }
4092 }
4093 }
Bookatzc8c44962017-05-11 12:12:54 -07004094
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004095 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4096 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4097 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4098 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4099 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4100 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4101 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4102 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004103 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4104 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004105
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004106 if (fullWakeLockTimeTotalMicros != 0) {
4107 sb.setLength(0);
4108 sb.append(prefix);
4109 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4110 (fullWakeLockTimeTotalMicros + 500) / 1000);
4111 pw.println(sb.toString());
4112 }
4113
4114 if (partialWakeLockTimeTotalMicros != 0) {
4115 sb.setLength(0);
4116 sb.append(prefix);
4117 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4118 (partialWakeLockTimeTotalMicros + 500) / 1000);
4119 pw.println(sb.toString());
4120 }
4121
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004122 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004123 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4124 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4125 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4126 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004127 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004128 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004129 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004130 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004131 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004132 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004133 if (time == 0) {
4134 continue;
4135 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004136 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004137 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004138 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004139 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004140 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004141 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004142 sb.append("(");
4143 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004144 sb.append(") ");
4145 sb.append(getPhoneSignalStrengthCount(i, which));
4146 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004147 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004148 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004149 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004150
4151 sb.setLength(0);
4152 sb.append(prefix);
4153 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004154 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004155 pw.println(sb.toString());
4156
Dianne Hackborn627bba72009-03-24 22:32:56 -07004157 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004158 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004159 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004160 didOne = false;
4161 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004162 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004163 if (time == 0) {
4164 continue;
4165 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004166 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004167 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004168 didOne = true;
4169 sb.append(DATA_CONNECTION_NAMES[i]);
4170 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004171 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004172 sb.append("(");
4173 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004174 sb.append(") ");
4175 sb.append(getPhoneDataConnectionCount(i, which));
4176 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004177 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004178 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004179 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004180
4181 sb.setLength(0);
4182 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004183 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004184 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004185 formatTimeMs(sb, mobileActiveTime / 1000);
4186 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4187 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4188 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004189 pw.println(sb.toString());
4190
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004191 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4192 if (mobileActiveUnknownTime != 0) {
4193 sb.setLength(0);
4194 sb.append(prefix);
4195 sb.append(" Mobile radio active unknown time: ");
4196 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4197 sb.append("(");
4198 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4199 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4200 sb.append("x");
4201 pw.println(sb.toString());
4202 }
4203
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004204 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4205 if (mobileActiveAdjustedTime != 0) {
4206 sb.setLength(0);
4207 sb.append(prefix);
4208 sb.append(" Mobile radio active adjusted time: ");
4209 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4210 sb.append("(");
4211 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4212 sb.append(")");
4213 pw.println(sb.toString());
4214 }
4215
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004216 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4217
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004218 pw.print(prefix);
4219 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4220 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4221 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4222 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004223 sb.setLength(0);
4224 sb.append(prefix);
4225 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4226 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4227 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4228 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004229 sb.append(")");
4230 pw.println(sb.toString());
4231
4232 sb.setLength(0);
4233 sb.append(prefix);
4234 sb.append(" Wifi states:");
4235 didOne = false;
4236 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004237 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004238 if (time == 0) {
4239 continue;
4240 }
4241 sb.append("\n ");
4242 didOne = true;
4243 sb.append(WIFI_STATE_NAMES[i]);
4244 sb.append(" ");
4245 formatTimeMs(sb, time/1000);
4246 sb.append("(");
4247 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4248 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004249 sb.append(getWifiStateCount(i, which));
4250 sb.append("x");
4251 }
4252 if (!didOne) sb.append(" (no activity)");
4253 pw.println(sb.toString());
4254
4255 sb.setLength(0);
4256 sb.append(prefix);
4257 sb.append(" Wifi supplicant states:");
4258 didOne = false;
4259 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4260 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4261 if (time == 0) {
4262 continue;
4263 }
4264 sb.append("\n ");
4265 didOne = true;
4266 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4267 sb.append(" ");
4268 formatTimeMs(sb, time/1000);
4269 sb.append("(");
4270 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4271 sb.append(") ");
4272 sb.append(getWifiSupplStateCount(i, which));
4273 sb.append("x");
4274 }
4275 if (!didOne) sb.append(" (no activity)");
4276 pw.println(sb.toString());
4277
4278 sb.setLength(0);
4279 sb.append(prefix);
4280 sb.append(" Wifi signal levels:");
4281 didOne = false;
4282 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4283 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4284 if (time == 0) {
4285 continue;
4286 }
4287 sb.append("\n ");
4288 sb.append(prefix);
4289 didOne = true;
4290 sb.append("level(");
4291 sb.append(i);
4292 sb.append(") ");
4293 formatTimeMs(sb, time/1000);
4294 sb.append("(");
4295 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4296 sb.append(") ");
4297 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004298 sb.append("x");
4299 }
4300 if (!didOne) sb.append(" (no activity)");
4301 pw.println(sb.toString());
4302
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004303 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004304
Adam Lesinski50e47602015-12-04 17:04:54 -08004305 pw.print(prefix);
4306 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4307 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4308
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004309 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4310 sb.setLength(0);
4311 sb.append(prefix);
4312 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4313 pw.println(sb.toString());
4314
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004315 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4316 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004317
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004318 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004319
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004320 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004321 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004322 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004323 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004324 pw.println(getDischargeStartLevel());
4325 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4326 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004327 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004328 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004329 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004330 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004331 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004332 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004333 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004334 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4335 pw.println(getDischargeAmountScreenOn());
4336 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4337 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004338 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004339 } else {
4340 pw.print(prefix); pw.println(" Device battery use since last full charge");
4341 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4342 pw.println(getLowDischargeAmountSinceCharge());
4343 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4344 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004345 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4346 pw.println(getDischargeAmountScreenOnSinceCharge());
4347 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4348 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004349 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004350 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004351
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004352 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004353 helper.create(this);
4354 helper.refreshStats(which, UserHandle.USER_ALL);
4355 List<BatterySipper> sippers = helper.getUsageList();
4356 if (sippers != null && sippers.size() > 0) {
4357 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4358 pw.print(prefix); pw.print(" Capacity: ");
4359 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004360 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004361 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4362 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4363 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4364 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004365 pw.println();
4366 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004367 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004368 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004369 switch (bs.drainType) {
4370 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004371 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004372 break;
4373 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004374 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004375 break;
4376 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004377 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004378 break;
4379 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004380 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004381 break;
4382 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004383 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004384 break;
4385 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004386 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004387 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004388 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004389 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004390 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004391 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004392 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004393 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004394 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004395 break;
4396 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004397 pw.print(" User "); pw.print(bs.userId);
4398 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004399 break;
4400 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004401 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004402 break;
4403 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004404 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004405 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004406 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004407 pw.print(" Camera: ");
4408 break;
4409 default:
4410 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004411 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004412 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004413 printmAh(pw, bs.totalPowerMah);
4414
Adam Lesinski57123002015-06-12 16:12:07 -07004415 if (bs.usagePowerMah != bs.totalPowerMah) {
4416 // If the usage (generic power) isn't the whole amount, we list out
4417 // what components are involved in the calculation.
4418
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004419 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004420 if (bs.usagePowerMah != 0) {
4421 pw.print(" usage=");
4422 printmAh(pw, bs.usagePowerMah);
4423 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004424 if (bs.cpuPowerMah != 0) {
4425 pw.print(" cpu=");
4426 printmAh(pw, bs.cpuPowerMah);
4427 }
4428 if (bs.wakeLockPowerMah != 0) {
4429 pw.print(" wake=");
4430 printmAh(pw, bs.wakeLockPowerMah);
4431 }
4432 if (bs.mobileRadioPowerMah != 0) {
4433 pw.print(" radio=");
4434 printmAh(pw, bs.mobileRadioPowerMah);
4435 }
4436 if (bs.wifiPowerMah != 0) {
4437 pw.print(" wifi=");
4438 printmAh(pw, bs.wifiPowerMah);
4439 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004440 if (bs.bluetoothPowerMah != 0) {
4441 pw.print(" bt=");
4442 printmAh(pw, bs.bluetoothPowerMah);
4443 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004444 if (bs.gpsPowerMah != 0) {
4445 pw.print(" gps=");
4446 printmAh(pw, bs.gpsPowerMah);
4447 }
4448 if (bs.sensorPowerMah != 0) {
4449 pw.print(" sensor=");
4450 printmAh(pw, bs.sensorPowerMah);
4451 }
4452 if (bs.cameraPowerMah != 0) {
4453 pw.print(" camera=");
4454 printmAh(pw, bs.cameraPowerMah);
4455 }
4456 if (bs.flashlightPowerMah != 0) {
4457 pw.print(" flash=");
4458 printmAh(pw, bs.flashlightPowerMah);
4459 }
4460 pw.print(" )");
4461 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004462
4463 // If there is additional smearing information, include it.
4464 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4465 pw.print(" Including smearing: ");
4466 printmAh(pw, bs.totalSmearedPowerMah);
4467 pw.print(" (");
4468 if (bs.screenPowerMah != 0) {
4469 pw.print(" screen=");
4470 printmAh(pw, bs.screenPowerMah);
4471 }
4472 if (bs.proportionalSmearMah != 0) {
4473 pw.print(" proportional=");
4474 printmAh(pw, bs.proportionalSmearMah);
4475 }
4476 pw.print(" )");
4477 }
4478 if (bs.shouldHide) {
4479 pw.print(" Excluded from smearing");
4480 }
4481
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004482 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004483 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004484 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004485 }
4486
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004487 sippers = helper.getMobilemsppList();
4488 if (sippers != null && sippers.size() > 0) {
4489 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004490 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004491 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004492 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004493 sb.setLength(0);
4494 sb.append(prefix); sb.append(" Uid ");
4495 UserHandle.formatUid(sb, bs.uidObj.getUid());
4496 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4497 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4498 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004499 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004500 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004501 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004502 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004503 sb.setLength(0);
4504 sb.append(prefix);
4505 sb.append(" TOTAL TIME: ");
4506 formatTimeMs(sb, totalTime);
4507 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4508 sb.append(")");
4509 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004510 pw.println();
4511 }
4512
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004513 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4514 @Override
4515 public int compare(TimerEntry lhs, TimerEntry rhs) {
4516 long lhsTime = lhs.mTime;
4517 long rhsTime = rhs.mTime;
4518 if (lhsTime < rhsTime) {
4519 return 1;
4520 }
4521 if (lhsTime > rhsTime) {
4522 return -1;
4523 }
4524 return 0;
4525 }
4526 };
4527
4528 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004529 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4530 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004531 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004532 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4533 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4534 : kernelWakelocks.entrySet()) {
4535 final BatteryStats.Timer timer = ent.getValue();
4536 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004537 if (totalTimeMillis > 0) {
4538 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4539 }
4540 }
4541 if (ktimers.size() > 0) {
4542 Collections.sort(ktimers, timerComparator);
4543 pw.print(prefix); pw.println(" All kernel wake locks:");
4544 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004545 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004546 String linePrefix = ": ";
4547 sb.setLength(0);
4548 sb.append(prefix);
4549 sb.append(" Kernel Wake lock ");
4550 sb.append(timer.mName);
4551 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4552 which, linePrefix);
4553 if (!linePrefix.equals(": ")) {
4554 sb.append(" realtime");
4555 // Only print out wake locks that were held
4556 pw.println(sb.toString());
4557 }
4558 }
4559 pw.println();
4560 }
4561 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004562
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004563 if (timers.size() > 0) {
4564 Collections.sort(timers, timerComparator);
4565 pw.print(prefix); pw.println(" All partial wake locks:");
4566 for (int i=0; i<timers.size(); i++) {
4567 TimerEntry timer = timers.get(i);
4568 sb.setLength(0);
4569 sb.append(" Wake lock ");
4570 UserHandle.formatUid(sb, timer.mId);
4571 sb.append(" ");
4572 sb.append(timer.mName);
4573 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4574 sb.append(" realtime");
4575 pw.println(sb.toString());
4576 }
4577 timers.clear();
4578 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004579 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004580
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004581 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004582 if (wakeupReasons.size() > 0) {
4583 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004584 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004585 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004586 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004587 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4588 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004589 }
4590 Collections.sort(reasons, timerComparator);
4591 for (int i=0; i<reasons.size(); i++) {
4592 TimerEntry timer = reasons.get(i);
4593 String linePrefix = ": ";
4594 sb.setLength(0);
4595 sb.append(prefix);
4596 sb.append(" Wakeup reason ");
4597 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004598 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4599 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004600 pw.println(sb.toString());
4601 }
4602 pw.println();
4603 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004604 }
Evan Millar22ac0432009-03-31 11:33:18 -07004605
James Carr2dd7e5e2016-07-20 18:48:39 -07004606 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004607 if (mMemoryStats.size() > 0) {
4608 pw.println(" Memory Stats");
4609 for (int i = 0; i < mMemoryStats.size(); i++) {
4610 sb.setLength(0);
4611 sb.append(" Bandwidth ");
4612 sb.append(mMemoryStats.keyAt(i));
4613 sb.append(" Time ");
4614 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4615 pw.println(sb.toString());
4616 }
4617 pw.println();
4618 }
4619
4620 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4621 if (rpmStats.size() > 0) {
4622 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4623 if (rpmStats.size() > 0) {
4624 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4625 final String timerName = ent.getKey();
4626 final Timer timer = ent.getValue();
4627 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4628 }
4629 }
4630 pw.println();
4631 }
4632 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
4633 if (screenOffRpmStats.size() > 0) {
4634 pw.print(prefix);
4635 pw.println(" Resource Power Manager Stats for when screen was off");
4636 if (screenOffRpmStats.size() > 0) {
4637 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4638 final String timerName = ent.getKey();
4639 final Timer timer = ent.getValue();
4640 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4641 }
4642 }
4643 pw.println();
James Carr2dd7e5e2016-07-20 18:48:39 -07004644 }
4645
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004646 final long[] cpuFreqs = getCpuFreqs();
4647 if (cpuFreqs != null) {
4648 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004649 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004650 for (int i = 0; i < cpuFreqs.length; ++i) {
4651 sb.append(" " + cpuFreqs[i]);
4652 }
4653 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07004654 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004655 }
4656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 for (int iu=0; iu<NU; iu++) {
4658 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004659 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004660 continue;
4661 }
Bookatzc8c44962017-05-11 12:12:54 -07004662
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004663 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004664
4665 pw.print(prefix);
4666 pw.print(" ");
4667 UserHandle.formatUid(pw, uid);
4668 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004670
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004671 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4672 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4673 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4674 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004675 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4676 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4677
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004678 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4679 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004680 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4681 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004682
4683 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4684 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4685
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004686 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4687 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4688 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004689 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4690 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4691 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4692 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004693 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004694
Adam Lesinski5f056f62016-07-14 16:56:08 -07004695 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4696 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4697
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004698 if (mobileRxBytes > 0 || mobileTxBytes > 0
4699 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004700 pw.print(prefix); pw.print(" Mobile network: ");
4701 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004702 pw.print(formatBytesLocked(mobileTxBytes));
4703 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4704 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004706 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4707 sb.setLength(0);
4708 sb.append(prefix); sb.append(" Mobile radio active: ");
4709 formatTimeMs(sb, uidMobileActiveTime / 1000);
4710 sb.append("(");
4711 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4712 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4713 long packets = mobileRxPackets + mobileTxPackets;
4714 if (packets == 0) {
4715 packets = 1;
4716 }
4717 sb.append(" @ ");
4718 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4719 sb.append(" mspp");
4720 pw.println(sb.toString());
4721 }
4722
Adam Lesinski5f056f62016-07-14 16:56:08 -07004723 if (mobileWakeup > 0) {
4724 sb.setLength(0);
4725 sb.append(prefix);
4726 sb.append(" Mobile radio AP wakeups: ");
4727 sb.append(mobileWakeup);
4728 pw.println(sb.toString());
4729 }
4730
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004731 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4732 u.getModemControllerActivity(), which);
4733
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004734 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004735 pw.print(prefix); pw.print(" Wi-Fi network: ");
4736 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004737 pw.print(formatBytesLocked(wifiTxBytes));
4738 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4739 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004740 }
4741
Dianne Hackborn62793e42015-03-09 11:15:41 -07004742 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004743 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004744 || uidWifiRunningTime != 0) {
4745 sb.setLength(0);
4746 sb.append(prefix); sb.append(" Wifi Running: ");
4747 formatTimeMs(sb, uidWifiRunningTime / 1000);
4748 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4749 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004750 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004751 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4752 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4753 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004754 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004755 formatTimeMs(sb, wifiScanTime / 1000);
4756 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004757 whichBatteryRealtime)); sb.append(") ");
4758 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004759 sb.append("x\n");
4760 // actual and background times are unpooled and since reset (regardless of 'which')
4761 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4762 formatTimeMs(sb, wifiScanActualTime / 1000);
4763 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4764 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4765 sb.append(") ");
4766 sb.append(wifiScanCount);
4767 sb.append("x\n");
4768 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4769 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4770 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4771 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4772 sb.append(") ");
4773 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004774 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004775 pw.println(sb.toString());
4776 }
4777
Adam Lesinski5f056f62016-07-14 16:56:08 -07004778 if (wifiWakeup > 0) {
4779 sb.setLength(0);
4780 sb.append(prefix);
4781 sb.append(" WiFi AP wakeups: ");
4782 sb.append(wifiWakeup);
4783 pw.println(sb.toString());
4784 }
4785
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004786 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4787 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004788
Adam Lesinski50e47602015-12-04 17:04:54 -08004789 if (btRxBytes > 0 || btTxBytes > 0) {
4790 pw.print(prefix); pw.print(" Bluetooth network: ");
4791 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4792 pw.print(formatBytesLocked(btTxBytes));
4793 pw.println(" sent");
4794 }
4795
Bookatz867c0d72017-03-07 18:23:42 -08004796 final Timer bleTimer = u.getBluetoothScanTimer();
4797 if (bleTimer != null) {
4798 // Convert from microseconds to milliseconds with rounding
4799 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4800 / 1000;
4801 if (totalTimeMs != 0) {
4802 final int count = bleTimer.getCountLocked(which);
4803 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4804 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004805 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4806 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4807 final long actualTimeMsBg = bleTimerBg != null ?
4808 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004809 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004810 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4811 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004812 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4813 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4814 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4815 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
4816 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
4817 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4818 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
4819 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
4820 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
4821 final Timer unoptimizedScanTimerBg =
4822 u.getBluetoothUnoptimizedScanBackgroundTimer();
4823 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
4824 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4825 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
4826 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004827
4828 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08004829 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07004830 sb.append(prefix);
4831 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08004832 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07004833 sb.append(" (");
4834 sb.append(count);
4835 sb.append(" times)");
4836 if (bleTimer.isRunningLocked()) {
4837 sb.append(" (currently running)");
4838 }
4839 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004840 }
Bookatzb1f04f32017-05-19 13:57:32 -07004841
4842 sb.append(prefix);
4843 sb.append(" Bluetooth Scan (total actual realtime): ");
4844 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
4845 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004846 sb.append(count);
4847 sb.append(" times)");
4848 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07004849 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08004850 }
Bookatzb1f04f32017-05-19 13:57:32 -07004851 sb.append("\n");
4852 if (actualTimeMsBg > 0 || countBg > 0) {
4853 sb.append(prefix);
4854 sb.append(" Bluetooth Scan (background realtime): ");
4855 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
4856 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004857 sb.append(countBg);
4858 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07004859 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
4860 sb.append(" (currently running in background)");
4861 }
4862 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004863 }
Bookatzb1f04f32017-05-19 13:57:32 -07004864
4865 sb.append(prefix);
4866 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07004867 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07004868 sb.append(" (");
4869 sb.append(resultCountBg);
4870 sb.append(" in background)");
4871
4872 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
4873 sb.append("\n");
4874 sb.append(prefix);
4875 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
4876 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
4877 sb.append(" (max ");
4878 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
4879 sb.append(")");
4880 if (unoptimizedScanTimer != null
4881 && unoptimizedScanTimer.isRunningLocked()) {
4882 sb.append(" (currently running unoptimized)");
4883 }
4884 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
4885 sb.append("\n");
4886 sb.append(prefix);
4887 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
4888 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
4889 sb.append(" (max ");
4890 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
4891 sb.append(")");
4892 if (unoptimizedScanTimerBg.isRunningLocked()) {
4893 sb.append(" (currently running unoptimized in background)");
4894 }
4895 }
4896 }
Bookatz867c0d72017-03-07 18:23:42 -08004897 pw.println(sb.toString());
4898 uidActivity = true;
4899 }
4900 }
4901
4902
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004903
Dianne Hackborn617f8772009-03-31 15:04:46 -07004904 if (u.hasUserActivity()) {
4905 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004906 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004907 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004908 if (val != 0) {
4909 if (!hasData) {
4910 sb.setLength(0);
4911 sb.append(" User activity: ");
4912 hasData = true;
4913 } else {
4914 sb.append(", ");
4915 }
4916 sb.append(val);
4917 sb.append(" ");
4918 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4919 }
4920 }
4921 if (hasData) {
4922 pw.println(sb.toString());
4923 }
4924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004926 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4927 = u.getWakelockStats();
4928 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004929 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004930 int countWakelock = 0;
4931 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4932 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4933 String linePrefix = ": ";
4934 sb.setLength(0);
4935 sb.append(prefix);
4936 sb.append(" Wake lock ");
4937 sb.append(wakelocks.keyAt(iw));
4938 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4939 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004940 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4941 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004942 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004943 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
4944 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004945 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4946 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004947 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4948 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004949 sb.append(" realtime");
4950 pw.println(sb.toString());
4951 uidActivity = true;
4952 countWakelock++;
4953
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004954 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4955 rawRealtime, which);
4956 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4957 rawRealtime, which);
4958 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4959 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004960 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004961 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004962 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004963 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004964 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4965 // pooled and therefore just a lower bound)
4966 long actualTotalPartialWakelock = 0;
4967 long actualBgPartialWakelock = 0;
4968 if (u.getAggregatedPartialWakelockTimer() != null) {
4969 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4970 // Convert from microseconds to milliseconds with rounding
4971 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07004972 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07004973 final Timer bgAggTimer = aggTimer.getSubTimer();
4974 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004975 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07004976 }
4977
4978 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4979 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4980 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004981 sb.setLength(0);
4982 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004983 sb.append(" TOTAL wake: ");
4984 boolean needComma = false;
4985 if (totalFullWakelock != 0) {
4986 needComma = true;
4987 formatTimeMs(sb, totalFullWakelock);
4988 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004989 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004990 if (totalPartialWakelock != 0) {
4991 if (needComma) {
4992 sb.append(", ");
4993 }
4994 needComma = true;
4995 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004996 sb.append("blamed partial");
4997 }
4998 if (actualTotalPartialWakelock != 0) {
4999 if (needComma) {
5000 sb.append(", ");
5001 }
5002 needComma = true;
5003 formatTimeMs(sb, actualTotalPartialWakelock);
5004 sb.append("actual partial");
5005 }
5006 if (actualBgPartialWakelock != 0) {
5007 if (needComma) {
5008 sb.append(", ");
5009 }
5010 needComma = true;
5011 formatTimeMs(sb, actualBgPartialWakelock);
5012 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005013 }
5014 if (totalWindowWakelock != 0) {
5015 if (needComma) {
5016 sb.append(", ");
5017 }
5018 needComma = true;
5019 formatTimeMs(sb, totalWindowWakelock);
5020 sb.append("window");
5021 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005022 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005023 if (needComma) {
5024 sb.append(",");
5025 }
5026 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005027 formatTimeMs(sb, totalDrawWakelock);
5028 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005029 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005030 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005031 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005032 }
5033 }
5034
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005035 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5036 for (int isy=syncs.size()-1; isy>=0; isy--) {
5037 final Timer timer = syncs.valueAt(isy);
5038 // Convert from microseconds to milliseconds with rounding
5039 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5040 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005041 final Timer bgTimer = timer.getSubTimer();
5042 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005043 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005044 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005045 sb.setLength(0);
5046 sb.append(prefix);
5047 sb.append(" Sync ");
5048 sb.append(syncs.keyAt(isy));
5049 sb.append(": ");
5050 if (totalTime != 0) {
5051 formatTimeMs(sb, totalTime);
5052 sb.append("realtime (");
5053 sb.append(count);
5054 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005055 if (bgTime > 0) {
5056 sb.append(", ");
5057 formatTimeMs(sb, bgTime);
5058 sb.append("background (");
5059 sb.append(bgCount);
5060 sb.append(" times)");
5061 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005062 } else {
5063 sb.append("(not used)");
5064 }
5065 pw.println(sb.toString());
5066 uidActivity = true;
5067 }
5068
5069 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5070 for (int ij=jobs.size()-1; ij>=0; ij--) {
5071 final Timer timer = jobs.valueAt(ij);
5072 // Convert from microseconds to milliseconds with rounding
5073 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5074 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005075 final Timer bgTimer = timer.getSubTimer();
5076 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005077 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005078 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005079 sb.setLength(0);
5080 sb.append(prefix);
5081 sb.append(" Job ");
5082 sb.append(jobs.keyAt(ij));
5083 sb.append(": ");
5084 if (totalTime != 0) {
5085 formatTimeMs(sb, totalTime);
5086 sb.append("realtime (");
5087 sb.append(count);
5088 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005089 if (bgTime > 0) {
5090 sb.append(", ");
5091 formatTimeMs(sb, bgTime);
5092 sb.append("background (");
5093 sb.append(bgCount);
5094 sb.append(" times)");
5095 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005096 } else {
5097 sb.append("(not used)");
5098 }
5099 pw.println(sb.toString());
5100 uidActivity = true;
5101 }
5102
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005103 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5104 for (int ic=completions.size()-1; ic>=0; ic--) {
5105 SparseIntArray types = completions.valueAt(ic);
5106 if (types != null) {
5107 pw.print(prefix);
5108 pw.print(" Job Completions ");
5109 pw.print(completions.keyAt(ic));
5110 pw.print(":");
5111 for (int it=0; it<types.size(); it++) {
5112 pw.print(" ");
5113 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5114 pw.print("(");
5115 pw.print(types.valueAt(it));
5116 pw.print("x)");
5117 }
5118 pw.println();
5119 }
5120 }
5121
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005122 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5123 prefix, "Flashlight");
5124 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5125 prefix, "Camera");
5126 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5127 prefix, "Video");
5128 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5129 prefix, "Audio");
5130
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005131 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5132 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005133 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005134 final Uid.Sensor se = sensors.valueAt(ise);
5135 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005136 sb.setLength(0);
5137 sb.append(prefix);
5138 sb.append(" Sensor ");
5139 int handle = se.getHandle();
5140 if (handle == Uid.Sensor.GPS) {
5141 sb.append("GPS");
5142 } else {
5143 sb.append(handle);
5144 }
5145 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005146
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005147 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005148 if (timer != null) {
5149 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005150 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5151 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005152 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005153 final Timer bgTimer = se.getSensorBackgroundTime();
5154 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005155 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5156 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5157 final long bgActualTime = bgTimer != null ?
5158 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5159
Dianne Hackborn61659e52014-07-09 16:13:01 -07005160 //timer.logState();
5161 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005162 if (actualTime != totalTime) {
5163 formatTimeMs(sb, totalTime);
5164 sb.append("blamed realtime, ");
5165 }
5166
5167 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005168 sb.append("realtime (");
5169 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005170 sb.append(" times)");
5171
5172 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005173 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005174 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5175 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005176 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005177 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 } else {
5180 sb.append("(not used)");
5181 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005182 } else {
5183 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005185
5186 pw.println(sb.toString());
5187 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 }
5189
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005190 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5191 "Vibrator");
5192 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5193 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005194 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5195 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005196
Dianne Hackborn61659e52014-07-09 16:13:01 -07005197 long totalStateTime = 0;
5198 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5199 long time = u.getProcessStateTime(ips, rawRealtime, which);
5200 if (time > 0) {
5201 totalStateTime += time;
5202 sb.setLength(0);
5203 sb.append(prefix);
5204 sb.append(" ");
5205 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5206 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005207 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005208 pw.println(sb.toString());
5209 uidActivity = true;
5210 }
5211 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005212 if (totalStateTime > 0) {
5213 sb.setLength(0);
5214 sb.append(prefix);
5215 sb.append(" Total running: ");
5216 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5217 pw.println(sb.toString());
5218 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005219
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005220 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5221 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005222 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005223 sb.setLength(0);
5224 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005225 sb.append(" Total cpu time: u=");
5226 formatTimeMs(sb, userCpuTimeUs / 1000);
5227 sb.append("s=");
5228 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005229 pw.println(sb.toString());
5230 }
5231
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005232 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5233 if (cpuFreqTimes != null) {
5234 sb.setLength(0);
5235 sb.append(" Total cpu time per freq:");
5236 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5237 sb.append(" " + cpuFreqTimes[i]);
5238 }
5239 pw.println(sb.toString());
5240 }
5241 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5242 if (screenOffCpuFreqTimes != null) {
5243 sb.setLength(0);
5244 sb.append(" Total screen-off cpu time per freq:");
5245 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5246 sb.append(" " + screenOffCpuFreqTimes[i]);
5247 }
5248 pw.println(sb.toString());
5249 }
5250
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005251 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5252 = u.getProcessStats();
5253 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5254 final Uid.Proc ps = processStats.valueAt(ipr);
5255 long userTime;
5256 long systemTime;
5257 long foregroundTime;
5258 int starts;
5259 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005260
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005261 userTime = ps.getUserTime(which);
5262 systemTime = ps.getSystemTime(which);
5263 foregroundTime = ps.getForegroundTime(which);
5264 starts = ps.getStarts(which);
5265 final int numCrashes = ps.getNumCrashes(which);
5266 final int numAnrs = ps.getNumAnrs(which);
5267 numExcessive = which == STATS_SINCE_CHARGED
5268 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005270 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5271 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5272 sb.setLength(0);
5273 sb.append(prefix); sb.append(" Proc ");
5274 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5275 sb.append(prefix); sb.append(" CPU: ");
5276 formatTimeMs(sb, userTime); sb.append("usr + ");
5277 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5278 formatTimeMs(sb, foregroundTime); sb.append("fg");
5279 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5280 sb.append("\n"); sb.append(prefix); sb.append(" ");
5281 boolean hasOne = false;
5282 if (starts != 0) {
5283 hasOne = true;
5284 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005285 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005286 if (numCrashes != 0) {
5287 if (hasOne) {
5288 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005289 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005290 hasOne = true;
5291 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005292 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005293 if (numAnrs != 0) {
5294 if (hasOne) {
5295 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005297 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005298 }
5299 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005300 pw.println(sb.toString());
5301 for (int e=0; e<numExcessive; e++) {
5302 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5303 if (ew != null) {
5304 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005305 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005306 pw.print("cpu");
5307 } else {
5308 pw.print("unknown");
5309 }
5310 pw.print(" use: ");
5311 TimeUtils.formatDuration(ew.usedTime, pw);
5312 pw.print(" over ");
5313 TimeUtils.formatDuration(ew.overTime, pw);
5314 if (ew.overTime != 0) {
5315 pw.print(" (");
5316 pw.print((ew.usedTime*100)/ew.overTime);
5317 pw.println("%)");
5318 }
5319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 }
5321 uidActivity = true;
5322 }
5323 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005324
5325 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5326 = u.getPackageStats();
5327 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5328 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5329 pw.println(":");
5330 boolean apkActivity = false;
5331 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5332 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5333 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5334 pw.print(prefix); pw.print(" Wakeup alarm ");
5335 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5336 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5337 pw.println(" times");
5338 apkActivity = true;
5339 }
5340 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5341 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5342 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5343 final long startTime = ss.getStartTime(batteryUptime, which);
5344 final int starts = ss.getStarts(which);
5345 final int launches = ss.getLaunches(which);
5346 if (startTime != 0 || starts != 0 || launches != 0) {
5347 sb.setLength(0);
5348 sb.append(prefix); sb.append(" Service ");
5349 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5350 sb.append(prefix); sb.append(" Created for: ");
5351 formatTimeMs(sb, startTime / 1000);
5352 sb.append("uptime\n");
5353 sb.append(prefix); sb.append(" Starts: ");
5354 sb.append(starts);
5355 sb.append(", launches: "); sb.append(launches);
5356 pw.println(sb.toString());
5357 apkActivity = true;
5358 }
5359 }
5360 if (!apkActivity) {
5361 pw.print(prefix); pw.println(" (nothing executed)");
5362 }
5363 uidActivity = true;
5364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005366 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005367 }
5368 }
5369 }
5370
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005371 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005372 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005373 int diff = oldval ^ newval;
5374 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005375 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005376 for (int i=0; i<descriptions.length; i++) {
5377 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005378 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005379 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005380 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005381 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005382 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005383 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5384 didWake = true;
5385 pw.print("=");
5386 if (longNames) {
5387 UserHandle.formatUid(pw, wakelockTag.uid);
5388 pw.print(":\"");
5389 pw.print(wakelockTag.string);
5390 pw.print("\"");
5391 } else {
5392 pw.print(wakelockTag.poolIdx);
5393 }
5394 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005395 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005396 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005397 pw.print("=");
5398 int val = (newval&bd.mask)>>bd.shift;
5399 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005400 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005401 } else {
5402 pw.print(val);
5403 }
5404 }
5405 }
5406 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005407 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005408 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005409 if (longNames) {
5410 UserHandle.formatUid(pw, wakelockTag.uid);
5411 pw.print(":\"");
5412 pw.print(wakelockTag.string);
5413 pw.print("\"");
5414 } else {
5415 pw.print(wakelockTag.poolIdx);
5416 }
5417 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005418 }
5419
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005420 public void prepareForDumpLocked() {
5421 }
5422
5423 public static class HistoryPrinter {
5424 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005425 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005426 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005427 int oldStatus = -1;
5428 int oldHealth = -1;
5429 int oldPlug = -1;
5430 int oldTemp = -1;
5431 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005432 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005433 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005434
Dianne Hackborn3251b902014-06-20 14:40:53 -07005435 void reset() {
5436 oldState = oldState2 = 0;
5437 oldLevel = -1;
5438 oldStatus = -1;
5439 oldHealth = -1;
5440 oldPlug = -1;
5441 oldTemp = -1;
5442 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005443 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005444 }
5445
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005446 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005447 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005448 if (!checkin) {
5449 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005450 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005451 pw.print(" (");
5452 pw.print(rec.numReadInts);
5453 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005454 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005455 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5456 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005457 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005458 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005459 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005460 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005461 }
5462 lastTime = rec.time;
5463 }
5464 if (rec.cmd == HistoryItem.CMD_START) {
5465 if (checkin) {
5466 pw.print(":");
5467 }
5468 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005469 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005470 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5471 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005472 if (checkin) {
5473 pw.print(":");
5474 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005475 if (rec.cmd == HistoryItem.CMD_RESET) {
5476 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005477 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005478 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005479 pw.print("TIME:");
5480 if (checkin) {
5481 pw.println(rec.currentTime);
5482 } else {
5483 pw.print(" ");
5484 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5485 rec.currentTime).toString());
5486 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005487 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5488 if (checkin) {
5489 pw.print(":");
5490 }
5491 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005492 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5493 if (checkin) {
5494 pw.print(":");
5495 }
5496 pw.println("*OVERFLOW*");
5497 } else {
5498 if (!checkin) {
5499 if (rec.batteryLevel < 10) pw.print("00");
5500 else if (rec.batteryLevel < 100) pw.print("0");
5501 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005502 if (verbose) {
5503 pw.print(" ");
5504 if (rec.states < 0) ;
5505 else if (rec.states < 0x10) pw.print("0000000");
5506 else if (rec.states < 0x100) pw.print("000000");
5507 else if (rec.states < 0x1000) pw.print("00000");
5508 else if (rec.states < 0x10000) pw.print("0000");
5509 else if (rec.states < 0x100000) pw.print("000");
5510 else if (rec.states < 0x1000000) pw.print("00");
5511 else if (rec.states < 0x10000000) pw.print("0");
5512 pw.print(Integer.toHexString(rec.states));
5513 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005514 } else {
5515 if (oldLevel != rec.batteryLevel) {
5516 oldLevel = rec.batteryLevel;
5517 pw.print(",Bl="); pw.print(rec.batteryLevel);
5518 }
5519 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005520 if (oldStatus != rec.batteryStatus) {
5521 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005522 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005523 switch (oldStatus) {
5524 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005525 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005526 break;
5527 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005528 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005529 break;
5530 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005531 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005532 break;
5533 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005534 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005535 break;
5536 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005537 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005538 break;
5539 default:
5540 pw.print(oldStatus);
5541 break;
5542 }
5543 }
5544 if (oldHealth != rec.batteryHealth) {
5545 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005546 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005547 switch (oldHealth) {
5548 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005549 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005550 break;
5551 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005552 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005553 break;
5554 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005555 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005556 break;
5557 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005558 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005559 break;
5560 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005561 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005562 break;
5563 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005564 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005565 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005566 case BatteryManager.BATTERY_HEALTH_COLD:
5567 pw.print(checkin ? "c" : "cold");
5568 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005569 default:
5570 pw.print(oldHealth);
5571 break;
5572 }
5573 }
5574 if (oldPlug != rec.batteryPlugType) {
5575 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005576 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005577 switch (oldPlug) {
5578 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005579 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005580 break;
5581 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005582 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005583 break;
5584 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005585 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005586 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005587 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005588 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005589 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005590 default:
5591 pw.print(oldPlug);
5592 break;
5593 }
5594 }
5595 if (oldTemp != rec.batteryTemperature) {
5596 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005597 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005598 pw.print(oldTemp);
5599 }
5600 if (oldVolt != rec.batteryVoltage) {
5601 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005602 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005603 pw.print(oldVolt);
5604 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005605 final int chargeMAh = rec.batteryChargeUAh / 1000;
5606 if (oldChargeMAh != chargeMAh) {
5607 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005608 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005609 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005610 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005611 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005612 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005613 printBitDescriptions(pw, oldState2, rec.states2, null,
5614 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005615 if (rec.wakeReasonTag != null) {
5616 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005617 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005618 pw.print(rec.wakeReasonTag.poolIdx);
5619 } else {
5620 pw.print(" wake_reason=");
5621 pw.print(rec.wakeReasonTag.uid);
5622 pw.print(":\"");
5623 pw.print(rec.wakeReasonTag.string);
5624 pw.print("\"");
5625 }
5626 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005627 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005628 pw.print(checkin ? "," : " ");
5629 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5630 pw.print("+");
5631 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5632 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005633 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005634 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5635 : HISTORY_EVENT_NAMES;
5636 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5637 | HistoryItem.EVENT_FLAG_FINISH);
5638 if (idx >= 0 && idx < eventNames.length) {
5639 pw.print(eventNames[idx]);
5640 } else {
5641 pw.print(checkin ? "Ev" : "event");
5642 pw.print(idx);
5643 }
5644 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005645 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005646 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005647 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005648 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5649 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005650 pw.print(":\"");
5651 pw.print(rec.eventTag.string);
5652 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005653 }
5654 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005655 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005656 if (rec.stepDetails != null) {
5657 if (!checkin) {
5658 pw.print(" Details: cpu=");
5659 pw.print(rec.stepDetails.userTime);
5660 pw.print("u+");
5661 pw.print(rec.stepDetails.systemTime);
5662 pw.print("s");
5663 if (rec.stepDetails.appCpuUid1 >= 0) {
5664 pw.print(" (");
5665 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5666 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5667 if (rec.stepDetails.appCpuUid2 >= 0) {
5668 pw.print(", ");
5669 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5670 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5671 }
5672 if (rec.stepDetails.appCpuUid3 >= 0) {
5673 pw.print(", ");
5674 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5675 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5676 }
5677 pw.print(')');
5678 }
5679 pw.println();
5680 pw.print(" /proc/stat=");
5681 pw.print(rec.stepDetails.statUserTime);
5682 pw.print(" usr, ");
5683 pw.print(rec.stepDetails.statSystemTime);
5684 pw.print(" sys, ");
5685 pw.print(rec.stepDetails.statIOWaitTime);
5686 pw.print(" io, ");
5687 pw.print(rec.stepDetails.statIrqTime);
5688 pw.print(" irq, ");
5689 pw.print(rec.stepDetails.statSoftIrqTime);
5690 pw.print(" sirq, ");
5691 pw.print(rec.stepDetails.statIdlTime);
5692 pw.print(" idle");
5693 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5694 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5695 + rec.stepDetails.statSoftIrqTime;
5696 int total = totalRun + rec.stepDetails.statIdlTime;
5697 if (total > 0) {
5698 pw.print(" (");
5699 float perc = ((float)totalRun) / ((float)total) * 100;
5700 pw.print(String.format("%.1f%%", perc));
5701 pw.print(" of ");
5702 StringBuilder sb = new StringBuilder(64);
5703 formatTimeMsNoSpace(sb, total*10);
5704 pw.print(sb);
5705 pw.print(")");
5706 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005707 pw.print(", PlatformIdleStat ");
5708 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005709 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005710
5711 pw.print(", SubsystemPowerState ");
5712 pw.print(rec.stepDetails.statSubsystemPowerState);
5713 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005714 } else {
5715 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5716 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5717 pw.print(rec.stepDetails.userTime);
5718 pw.print(":");
5719 pw.print(rec.stepDetails.systemTime);
5720 if (rec.stepDetails.appCpuUid1 >= 0) {
5721 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5722 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5723 if (rec.stepDetails.appCpuUid2 >= 0) {
5724 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5725 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5726 }
5727 if (rec.stepDetails.appCpuUid3 >= 0) {
5728 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5729 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5730 }
5731 }
5732 pw.println();
5733 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5734 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5735 pw.print(rec.stepDetails.statUserTime);
5736 pw.print(',');
5737 pw.print(rec.stepDetails.statSystemTime);
5738 pw.print(',');
5739 pw.print(rec.stepDetails.statIOWaitTime);
5740 pw.print(',');
5741 pw.print(rec.stepDetails.statIrqTime);
5742 pw.print(',');
5743 pw.print(rec.stepDetails.statSoftIrqTime);
5744 pw.print(',');
5745 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005746 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005747 if (rec.stepDetails.statPlatformIdleState != null) {
5748 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07005749 if (rec.stepDetails.statSubsystemPowerState != null) {
5750 pw.print(',');
5751 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005752 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005753
5754 if (rec.stepDetails.statSubsystemPowerState != null) {
5755 pw.print(rec.stepDetails.statSubsystemPowerState);
5756 }
5757 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005758 }
5759 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005760 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005761 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005762 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005763 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005764
5765 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5766 UserHandle.formatUid(pw, uid);
5767 pw.print("=");
5768 pw.print(utime);
5769 pw.print("u+");
5770 pw.print(stime);
5771 pw.print("s");
5772 }
5773
5774 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5775 pw.print('/');
5776 pw.print(uid);
5777 pw.print(":");
5778 pw.print(utime);
5779 pw.print(":");
5780 pw.print(stime);
5781 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005782 }
5783
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005784 private void printSizeValue(PrintWriter pw, long size) {
5785 float result = size;
5786 String suffix = "";
5787 if (result >= 10*1024) {
5788 suffix = "KB";
5789 result = result / 1024;
5790 }
5791 if (result >= 10*1024) {
5792 suffix = "MB";
5793 result = result / 1024;
5794 }
5795 if (result >= 10*1024) {
5796 suffix = "GB";
5797 result = result / 1024;
5798 }
5799 if (result >= 10*1024) {
5800 suffix = "TB";
5801 result = result / 1024;
5802 }
5803 if (result >= 10*1024) {
5804 suffix = "PB";
5805 result = result / 1024;
5806 }
5807 pw.print((int)result);
5808 pw.print(suffix);
5809 }
5810
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005811 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5812 String label3, long estimatedTime) {
5813 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005814 return false;
5815 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005816 pw.print(label1);
5817 pw.print(label2);
5818 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005819 StringBuilder sb = new StringBuilder(64);
5820 formatTimeMs(sb, estimatedTime);
5821 pw.print(sb);
5822 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005823 return true;
5824 }
5825
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005826 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5827 LevelStepTracker steps, boolean checkin) {
5828 if (steps == null) {
5829 return false;
5830 }
5831 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005832 if (count <= 0) {
5833 return false;
5834 }
5835 if (!checkin) {
5836 pw.println(header);
5837 }
Kweku Adams030980a2015-04-01 16:07:48 -07005838 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005839 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005840 long duration = steps.getDurationAt(i);
5841 int level = steps.getLevelAt(i);
5842 long initMode = steps.getInitModeAt(i);
5843 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005844 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005845 lineArgs[0] = Long.toString(duration);
5846 lineArgs[1] = Integer.toString(level);
5847 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5848 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5849 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5850 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5851 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5852 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005853 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005854 }
5855 } else {
5856 lineArgs[2] = "";
5857 }
5858 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5859 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5860 } else {
5861 lineArgs[3] = "";
5862 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005863 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005864 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005865 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005866 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005867 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005868 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5869 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005870 pw.print(prefix);
5871 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005872 TimeUtils.formatDuration(duration, pw);
5873 pw.print(" to "); pw.print(level);
5874 boolean haveModes = false;
5875 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5876 pw.print(" (");
5877 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5878 case Display.STATE_OFF: pw.print("screen-off"); break;
5879 case Display.STATE_ON: pw.print("screen-on"); break;
5880 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5881 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005882 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005883 }
5884 haveModes = true;
5885 }
5886 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5887 pw.print(haveModes ? ", " : " (");
5888 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5889 ? "power-save-on" : "power-save-off");
5890 haveModes = true;
5891 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005892 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5893 pw.print(haveModes ? ", " : " (");
5894 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5895 ? "device-idle-on" : "device-idle-off");
5896 haveModes = true;
5897 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005898 if (haveModes) {
5899 pw.print(")");
5900 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005901 pw.println();
5902 }
5903 }
5904 return true;
5905 }
5906
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005907 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005908 public static final int DUMP_DAILY_ONLY = 1<<2;
5909 public static final int DUMP_HISTORY_ONLY = 1<<3;
5910 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5911 public static final int DUMP_VERBOSE = 1<<5;
5912 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005913
Dianne Hackborn37de0982014-05-09 09:32:18 -07005914 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5915 final HistoryPrinter hprinter = new HistoryPrinter();
5916 final HistoryItem rec = new HistoryItem();
5917 long lastTime = -1;
5918 long baseTime = -1;
5919 boolean printed = false;
5920 HistoryEventTracker tracker = null;
5921 while (getNextHistoryLocked(rec)) {
5922 lastTime = rec.time;
5923 if (baseTime < 0) {
5924 baseTime = lastTime;
5925 }
5926 if (rec.time >= histStart) {
5927 if (histStart >= 0 && !printed) {
5928 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005929 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005930 || rec.cmd == HistoryItem.CMD_START
5931 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005932 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005933 hprinter.printNextItem(pw, rec, baseTime, checkin,
5934 (flags&DUMP_VERBOSE) != 0);
5935 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005936 } else if (rec.currentTime != 0) {
5937 printed = true;
5938 byte cmd = rec.cmd;
5939 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005940 hprinter.printNextItem(pw, rec, baseTime, checkin,
5941 (flags&DUMP_VERBOSE) != 0);
5942 rec.cmd = cmd;
5943 }
5944 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005945 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5946 hprinter.printNextItem(pw, rec, baseTime, checkin,
5947 (flags&DUMP_VERBOSE) != 0);
5948 rec.cmd = HistoryItem.CMD_UPDATE;
5949 }
5950 int oldEventCode = rec.eventCode;
5951 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005952 rec.eventTag = new HistoryTag();
5953 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5954 HashMap<String, SparseIntArray> active
5955 = tracker.getStateForEvent(i);
5956 if (active == null) {
5957 continue;
5958 }
5959 for (HashMap.Entry<String, SparseIntArray> ent
5960 : active.entrySet()) {
5961 SparseIntArray uids = ent.getValue();
5962 for (int j=0; j<uids.size(); j++) {
5963 rec.eventCode = i;
5964 rec.eventTag.string = ent.getKey();
5965 rec.eventTag.uid = uids.keyAt(j);
5966 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005967 hprinter.printNextItem(pw, rec, baseTime, checkin,
5968 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005969 rec.wakeReasonTag = null;
5970 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005971 }
5972 }
5973 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005974 rec.eventCode = oldEventCode;
5975 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005976 tracker = null;
5977 }
5978 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005979 hprinter.printNextItem(pw, rec, baseTime, checkin,
5980 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005981 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5982 // This is an attempt to aggregate the previous state and generate
5983 // fake events to reflect that state at the point where we start
5984 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005985 if (tracker == null) {
5986 tracker = new HistoryEventTracker();
5987 }
5988 tracker.updateState(rec.eventCode, rec.eventTag.string,
5989 rec.eventTag.uid, rec.eventTag.poolIdx);
5990 }
5991 }
5992 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005993 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005994 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5995 }
5996 }
5997
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005998 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5999 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6000 if (steps == null) {
6001 return;
6002 }
6003 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6004 if (timeRemaining >= 0) {
6005 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6006 tmpSb.setLength(0);
6007 formatTimeMs(tmpSb, timeRemaining);
6008 pw.print(tmpSb);
6009 pw.print(" (from "); pw.print(tmpOutInt[0]);
6010 pw.println(" steps)");
6011 }
6012 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6013 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6014 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6015 if (estimatedTime > 0) {
6016 pw.print(prefix); pw.print(label); pw.print(" ");
6017 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6018 pw.print(" time: ");
6019 tmpSb.setLength(0);
6020 formatTimeMs(tmpSb, estimatedTime);
6021 pw.print(tmpSb);
6022 pw.print(" (from "); pw.print(tmpOutInt[0]);
6023 pw.println(" steps)");
6024 }
6025 }
6026 }
6027
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006028 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6029 ArrayList<PackageChange> changes) {
6030 if (changes == null) {
6031 return;
6032 }
6033 pw.print(prefix); pw.println("Package changes:");
6034 for (int i=0; i<changes.size(); i++) {
6035 PackageChange pc = changes.get(i);
6036 if (pc.mUpdate) {
6037 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6038 pw.print(" vers="); pw.println(pc.mVersionCode);
6039 } else {
6040 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6041 }
6042 }
6043 }
6044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 /**
6046 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6047 *
6048 * @param pw a Printer to receive the dump output.
6049 */
6050 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006051 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006052 prepareForDumpLocked();
6053
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006054 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006055 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006056
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006057 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006058 final long historyTotalSize = getHistoryTotalSize();
6059 final long historyUsedSize = getHistoryUsedSize();
6060 if (startIteratingHistoryLocked()) {
6061 try {
6062 pw.print("Battery History (");
6063 pw.print((100*historyUsedSize)/historyTotalSize);
6064 pw.print("% used, ");
6065 printSizeValue(pw, historyUsedSize);
6066 pw.print(" used of ");
6067 printSizeValue(pw, historyTotalSize);
6068 pw.print(", ");
6069 pw.print(getHistoryStringPoolSize());
6070 pw.print(" strings using ");
6071 printSizeValue(pw, getHistoryStringPoolBytes());
6072 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006073 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006074 pw.println();
6075 } finally {
6076 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006077 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006078 }
6079
6080 if (startIteratingOldHistoryLocked()) {
6081 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006082 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006083 pw.println("Old battery History:");
6084 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006085 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006086 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006087 if (baseTime < 0) {
6088 baseTime = rec.time;
6089 }
6090 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006091 }
6092 pw.println();
6093 } finally {
6094 finishIteratingOldHistoryLocked();
6095 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006096 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006097 }
6098
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006099 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006100 return;
6101 }
6102
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006103 if (!filtering) {
6104 SparseArray<? extends Uid> uidStats = getUidStats();
6105 final int NU = uidStats.size();
6106 boolean didPid = false;
6107 long nowRealtime = SystemClock.elapsedRealtime();
6108 for (int i=0; i<NU; i++) {
6109 Uid uid = uidStats.valueAt(i);
6110 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6111 if (pids != null) {
6112 for (int j=0; j<pids.size(); j++) {
6113 Uid.Pid pid = pids.valueAt(j);
6114 if (!didPid) {
6115 pw.println("Per-PID Stats:");
6116 didPid = true;
6117 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006118 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6119 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006120 pw.print(" PID "); pw.print(pids.keyAt(j));
6121 pw.print(" wake time: ");
6122 TimeUtils.formatDuration(time, pw);
6123 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006124 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006125 }
6126 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006127 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006128 pw.println();
6129 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006130 }
6131
6132 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006133 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6134 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006135 long timeRemaining = computeBatteryTimeRemaining(
6136 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006137 if (timeRemaining >= 0) {
6138 pw.print(" Estimated discharge time remaining: ");
6139 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6140 pw.println();
6141 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006142 final LevelStepTracker steps = getDischargeLevelStepTracker();
6143 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6144 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6145 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6146 STEP_LEVEL_MODE_VALUES[i], null));
6147 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006148 pw.println();
6149 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006150 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6151 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006152 long timeRemaining = computeChargeTimeRemaining(
6153 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006154 if (timeRemaining >= 0) {
6155 pw.print(" Estimated charge time remaining: ");
6156 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6157 pw.println();
6158 }
6159 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006160 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006161 }
6162 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6163 pw.println("Daily stats:");
6164 pw.print(" Current start time: ");
6165 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6166 getCurrentDailyStartTime()).toString());
6167 pw.print(" Next min deadline: ");
6168 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6169 getNextMinDailyDeadline()).toString());
6170 pw.print(" Next max deadline: ");
6171 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6172 getNextMaxDailyDeadline()).toString());
6173 StringBuilder sb = new StringBuilder(64);
6174 int[] outInt = new int[1];
6175 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6176 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006177 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6178 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006179 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006180 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6181 dsteps, false)) {
6182 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6183 sb, outInt);
6184 }
6185 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6186 csteps, false)) {
6187 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6188 sb, outInt);
6189 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006190 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006191 } else {
6192 pw.println(" Current daily steps:");
6193 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6194 sb, outInt);
6195 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6196 sb, outInt);
6197 }
6198 }
6199 DailyItem dit;
6200 int curIndex = 0;
6201 while ((dit=getDailyItemLocked(curIndex)) != null) {
6202 curIndex++;
6203 if ((flags&DUMP_DAILY_ONLY) != 0) {
6204 pw.println();
6205 }
6206 pw.print(" Daily from ");
6207 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6208 pw.print(" to ");
6209 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6210 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006211 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006212 if (dumpDurationSteps(pw, " ",
6213 " Discharge step durations:", dit.mDischargeSteps, false)) {
6214 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6215 sb, outInt);
6216 }
6217 if (dumpDurationSteps(pw, " ",
6218 " Charge step durations:", dit.mChargeSteps, false)) {
6219 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6220 sb, outInt);
6221 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006222 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006223 } else {
6224 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6225 sb, outInt);
6226 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6227 sb, outInt);
6228 }
6229 }
6230 pw.println();
6231 }
6232 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006233 pw.println("Statistics since last charge:");
6234 pw.println(" System starts: " + getStartCount()
6235 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006236 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6237 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006238 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 }
6241
6242 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006243 public void dumpCheckinLocked(Context context, PrintWriter pw,
6244 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006245 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006246
6247 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006248 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6249 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006250
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006251 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6252
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006253 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006254 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006255
6256 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006257 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006258 try {
6259 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6260 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6261 pw.print(HISTORY_STRING_POOL); pw.print(',');
6262 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006263 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006264 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006265 pw.print(",\"");
6266 String str = getHistoryTagPoolString(i);
6267 str = str.replace("\\", "\\\\");
6268 str = str.replace("\"", "\\\"");
6269 pw.print(str);
6270 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006271 pw.println();
6272 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006273 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006274 } finally {
6275 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006276 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006277 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006278 }
6279
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006280 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006281 return;
6282 }
6283
Dianne Hackborne4a59512010-12-07 11:08:07 -08006284 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006285 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006286 for (int i=0; i<apps.size(); i++) {
6287 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006288 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6289 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006290 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006291 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6292 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006293 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006294 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006295 }
6296 SparseArray<? extends Uid> uidStats = getUidStats();
6297 final int NU = uidStats.size();
6298 String[] lineArgs = new String[2];
6299 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006300 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6301 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6302 if (pkgs != null && !pkgs.second.value) {
6303 pkgs.second.value = true;
6304 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006305 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006306 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006307 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6308 (Object[])lineArgs);
6309 }
6310 }
6311 }
6312 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006313 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006314 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006315 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006316 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006317 if (timeRemaining >= 0) {
6318 lineArgs[0] = Long.toString(timeRemaining);
6319 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6320 (Object[])lineArgs);
6321 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006322 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006323 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006324 if (timeRemaining >= 0) {
6325 lineArgs[0] = Long.toString(timeRemaining);
6326 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6327 (Object[])lineArgs);
6328 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006329 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6330 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333}