blob: a34668c33fcabc895a0abf822208c79e1cbc7140 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborn94326cb2017-06-28 16:17:20 -070028import android.app.job.JobParameters;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080029import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080030import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080031import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080032import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070033import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070034import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070035import android.util.MutableBoolean;
36import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.Printer;
38import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070039import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070040import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070041import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080042
Dianne Hackborna7c837f2014-01-15 16:20:44 -080043import com.android.internal.os.BatterySipper;
44import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46/**
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 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 * Include all of the data in the stats, including previously saved data.
172 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700173 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174
175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 * Include only the current run in the stats.
177 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700178 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179
180 /**
181 * Include only the run since the last time the device was unplugged in the stats.
182 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700183 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700184
185 // NOTE: Update this list if you add/change any stats above.
186 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700187 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700188 private static final String[] STAT_NAMES = { "l", "c", "u" };
189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700191 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700192 *
193 * New in version 19:
194 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800195 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700196 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700197 * New in version 21:
198 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700199 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700200 * - BLE scan result count
201 * - CPU frequency time per uid
202 * New in version 22:
203 * - BLE scan result background count, BLE unoptimized scan time
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700204 */
Bookatz6d799932017-06-07 12:30:07 -0700205 static final String CHECKIN_VERSION = "23";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700206
207 /**
208 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700210 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700211
Evan Millar22ac0432009-03-31 11:33:18 -0700212 private static final long BYTES_PER_KB = 1024;
213 private static final long BYTES_PER_MB = 1048576; // 1024^2
214 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700215
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700216 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800217 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700218 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700220 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700221 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700222 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
223 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Evan Millare84de8d2009-04-02 22:16:12 -0700224 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800225 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700226 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700227 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700228 // wl line is:
229 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700230 // full totalTime, 'f', count, current duration, max duration, total duration,
231 // partial totalTime, 'p', count, current duration, max duration, total duration,
232 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
233 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700234 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700235 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700236 // awl line is:
237 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
238 // cumulative partial wakelock duration, cumulative background partial wakelock duration
239 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700240 private static final String SYNC_DATA = "sy";
241 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700242 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700243 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700244 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700245 private static final String NETWORK_DATA = "nt";
246 private static final String USER_ACTIVITY_DATA = "ua";
247 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800248 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700249 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700250 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700251 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800252 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
253 private static final String WIFI_CONTROLLER_DATA = "wfcd";
254 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
255 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700256 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700257 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800258 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800259 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
260 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800261 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700262 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700263 private static final String SCREEN_BRIGHTNESS_DATA = "br";
264 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700265 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700266 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
267 private static final String DATA_CONNECTION_TIME_DATA = "dct";
268 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800269 private static final String WIFI_STATE_TIME_DATA = "wst";
270 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700271 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
272 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
273 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
274 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800275 private static final String POWER_USE_SUMMARY_DATA = "pws";
276 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700277 private static final String DISCHARGE_STEP_DATA = "dsd";
278 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700279 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
280 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700281 private static final String FLASHLIGHT_DATA = "fla";
282 private static final String CAMERA_DATA = "cam";
283 private static final String VIDEO_DATA = "vid";
284 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285
Adam Lesinski010bf372016-04-11 12:18:18 -0700286 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
287
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700288 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 private final Formatter mFormatter = new Formatter(mFormatBuilder);
290
291 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700292 * Indicates times spent by the uid at each cpu frequency in all process states.
293 *
294 * Other types might include times spent in foreground, background etc.
295 */
296 private final String UID_TIMES_TYPE_ALL = "A";
297
298 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700299 * State for keeping track of counting information.
300 */
301 public static abstract class Counter {
302
303 /**
304 * Returns the count associated with this Counter for the
305 * selected type of statistics.
306 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700307 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700308 */
Evan Millarc64edde2009-04-18 12:26:32 -0700309 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700310
311 /**
312 * Temporary for debugging.
313 */
314 public abstract void logState(Printer pw, String prefix);
315 }
316
317 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700318 * State for keeping track of long counting information.
319 */
320 public static abstract class LongCounter {
321
322 /**
323 * Returns the count associated with this Counter for the
324 * selected type of statistics.
325 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700326 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700327 */
328 public abstract long getCountLocked(int which);
329
330 /**
331 * Temporary for debugging.
332 */
333 public abstract void logState(Printer pw, String prefix);
334 }
335
336 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700337 * State for keeping track of array of long counting information.
338 */
339 public static abstract class LongCounterArray {
340 /**
341 * Returns the counts associated with this Counter for the
342 * selected type of statistics.
343 *
344 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
345 */
346 public abstract long[] getCountsLocked(int which);
347
348 /**
349 * Temporary for debugging.
350 */
351 public abstract void logState(Printer pw, String prefix);
352 }
353
354 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800355 * Container class that aggregates counters for transmit, receive, and idle state of a
356 * radio controller.
357 */
358 public static abstract class ControllerActivityCounter {
359 /**
360 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
361 * idle state.
362 */
363 public abstract LongCounter getIdleTimeCounter();
364
365 /**
366 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
367 * receive state.
368 */
369 public abstract LongCounter getRxTimeCounter();
370
371 /**
372 * An array of {@link LongCounter}, representing various transmit levels, where each level
373 * may draw a different amount of power. The levels themselves are controller-specific.
374 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
375 * various transmit level states.
376 */
377 public abstract LongCounter[] getTxTimeCounters();
378
379 /**
380 * @return a non-null {@link LongCounter} representing the power consumed by the controller
381 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
382 * yield a value of 0 if the device doesn't support power calculations.
383 */
384 public abstract LongCounter getPowerCounter();
385 }
386
387 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 * State for keeping track of timing information.
389 */
390 public static abstract class Timer {
391
392 /**
393 * Returns the count associated with this Timer for the
394 * selected type of statistics.
395 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700396 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 */
Evan Millarc64edde2009-04-18 12:26:32 -0700398 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
400 /**
401 * Returns the total time in microseconds associated with this Timer for the
402 * selected type of statistics.
403 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800404 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700405 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 * @return a time in microseconds
407 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800408 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700411 * Returns the total time in microseconds associated with this Timer since the
412 * 'mark' was last set.
413 *
414 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
415 * @return a time in microseconds
416 */
417 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
418
419 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700420 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800421 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700422
423 */
424 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
425 return -1;
426 }
427
428 /**
429 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800430 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700431 */
432 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
433 return -1;
434 }
435
436 /**
Bookatz867c0d72017-03-07 18:23:42 -0800437 * Returns the current time the timer has been active, if it is being tracked.
438 *
439 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
440 * been on since reset.
441 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
442 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
443 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
444 * the actual total time.
445 * Not all Timer subclasses track the max, total, current durations.
446 */
447 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
448 return -1;
449 }
450
451 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700452 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
453 * used, for example, for tracking background usage. Secondary timers are never pooled.
454 *
455 * Not all Timer subclasses have a secondary timer; those that don't return null.
456 */
457 public Timer getSubTimer() {
458 return null;
459 }
460
461 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700462 * Returns whether the timer is currently running. Some types of timers
463 * (e.g. BatchTimers) don't know whether the event is currently active,
464 * and report false.
465 */
466 public boolean isRunningLocked() {
467 return false;
468 }
469
470 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 * Temporary for debugging.
472 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700473 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 }
475
476 /**
477 * The statistics associated with a particular uid.
478 */
479 public static abstract class Uid {
480
481 /**
482 * Returns a mapping containing wakelock statistics.
483 *
484 * @return a Map from Strings to Uid.Wakelock objects.
485 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700486 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487
488 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700489 * Returns a mapping containing sync statistics.
490 *
491 * @return a Map from Strings to Timer objects.
492 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700493 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700494
495 /**
496 * Returns a mapping containing scheduled job statistics.
497 *
498 * @return a Map from Strings to Timer objects.
499 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700500 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700501
502 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700503 * Returns statistics about how jobs have completed.
504 *
505 * @return A Map of String job names to completion type -> count mapping.
506 */
507 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
508
509 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 * The statistics associated with a particular wake lock.
511 */
512 public static abstract class Wakelock {
513 public abstract Timer getWakeTime(int type);
514 }
515
516 /**
Bookatzc8c44962017-05-11 12:12:54 -0700517 * The cumulative time the uid spent holding any partial wakelocks. This will generally
518 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
519 * wakelocks that overlap in time (and therefore over-counts).
520 */
521 public abstract Timer getAggregatedPartialWakelockTimer();
522
523 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 * Returns a mapping containing sensor statistics.
525 *
526 * @return a Map from Integer sensor ids to Uid.Sensor objects.
527 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700528 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529
530 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700531 * Returns a mapping containing active process data.
532 */
533 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700534
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700535 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 * Returns a mapping containing process statistics.
537 *
538 * @return a Map from Strings to Uid.Proc objects.
539 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700540 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541
542 /**
543 * Returns a mapping containing package statistics.
544 *
545 * @return a Map from Strings to Uid.Pkg objects.
546 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700547 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700548
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800549 public abstract ControllerActivityCounter getWifiControllerActivity();
550 public abstract ControllerActivityCounter getBluetoothControllerActivity();
551 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800552
553 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 * {@hide}
555 */
556 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700557
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800558 public abstract void noteWifiRunningLocked(long elapsedRealtime);
559 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
560 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
561 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
562 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
563 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
564 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
565 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
566 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
567 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800568 public abstract void noteActivityResumedLocked(long elapsedRealtime);
569 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800570 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
571 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
572 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700573 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800574 public abstract int getWifiScanBackgroundCount(int which);
575 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
576 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800577 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700578 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800579 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700580 public abstract Timer getAudioTurnedOnTimer();
581 public abstract Timer getVideoTurnedOnTimer();
582 public abstract Timer getFlashlightTurnedOnTimer();
583 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700584 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800585 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800586 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700587 public abstract Timer getBluetoothUnoptimizedScanTimer();
588 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700589 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700590 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700591
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700592 public abstract long[] getCpuFreqTimes(int which);
593 public abstract long[] getScreenOffCpuFreqTimes(int which);
594
Dianne Hackborna0200e32016-03-30 18:01:41 -0700595 // Note: the following times are disjoint. They can be added together to find the
596 // total time a uid has had any processes running at all.
597
598 /**
599 * Time this uid has any processes in the top state (or above such as persistent).
600 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800601 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700602 /**
603 * Time this uid has any process with a started out bound foreground service, but
604 * none in the "top" state.
605 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800606 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700607 /**
608 * Time this uid has any process that is top while the device is sleeping, but none
609 * in the "foreground service" or better state.
610 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800611 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700612 /**
613 * Time this uid has any process in an active foreground state, but none in the
614 * "top sleeping" or better state.
615 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800616 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700617 /**
618 * Time this uid has any process in an active background state, but none in the
619 * "foreground" or better state.
620 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800621 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700622 /**
623 * Time this uid has any processes that are sitting around cached, not in one of the
624 * other active states.
625 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800626 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700627 /**
628 * Total number of process states we track.
629 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800630 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700631
632 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800633 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700634 };
635
636 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800637 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700638
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800639 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640
Robert Greenwalta029ea12013-09-25 16:38:12 -0700641 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
642
Dianne Hackborn617f8772009-03-31 15:04:46 -0700643 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700644 * Note that these must match the constants in android.os.PowerManager.
645 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
646 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700647 */
648 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700649 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700650 };
Bookatzc8c44962017-05-11 12:12:54 -0700651
Phil Weaverda80d672016-03-15 16:25:46 -0700652 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700653
Dianne Hackborn617f8772009-03-31 15:04:46 -0700654 public abstract void noteUserActivityLocked(int type);
655 public abstract boolean hasUserActivity();
656 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700657
658 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800659 public abstract long getNetworkActivityBytes(int type, int which);
660 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800661 public abstract long getMobileRadioActiveTime(int which);
662 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700663
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700664 /**
665 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
666 */
667 public abstract long getUserCpuTimeUs(int which);
668
669 /**
670 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
671 */
672 public abstract long getSystemCpuTimeUs(int which);
673
674 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700675 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
676 * given CPU cluster.
677 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700678 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700679 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700680 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
681 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700682 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700683 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700684
Adam Lesinski5f056f62016-07-14 16:56:08 -0700685 /**
686 * Returns the number of times this UID woke up the Application Processor to
687 * process a mobile radio packet.
688 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
689 */
690 public abstract long getMobileRadioApWakeupCount(int which);
691
692 /**
693 * Returns the number of times this UID woke up the Application Processor to
694 * process a WiFi packet.
695 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
696 */
697 public abstract long getWifiRadioApWakeupCount(int which);
698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800700 /*
701 * FIXME: it's not correct to use this magic value because it
702 * could clash with a sensor handle (which are defined by
703 * the sensor HAL, and therefore out of our control
704 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 // Magic sensor number for the GPS.
706 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800711
Bookatz867c0d72017-03-07 18:23:42 -0800712 /** Returns a Timer for sensor usage when app is in the background. */
713 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 }
715
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700716 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800717 public int mWakeNesting;
718 public long mWakeSumMs;
719 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700720 }
721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 /**
723 * The statistics associated with a particular process.
724 */
725 public static abstract class Proc {
726
Dianne Hackborn287952c2010-09-22 22:34:31 -0700727 public static class ExcessivePower {
728 public static final int TYPE_WAKE = 1;
729 public static final int TYPE_CPU = 2;
730
731 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700732 public long overTime;
733 public long usedTime;
734 }
735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800737 * Returns true if this process is still active in the battery stats.
738 */
739 public abstract boolean isActive();
740
741 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700742 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700744 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 */
746 public abstract long getUserTime(int which);
747
748 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700749 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700751 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 */
753 public abstract long getSystemTime(int which);
754
755 /**
756 * Returns the number of times the process has been started.
757 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700758 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 */
760 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700761
762 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800763 * Returns the number of times the process has crashed.
764 *
765 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
766 */
767 public abstract int getNumCrashes(int which);
768
769 /**
770 * Returns the number of times the process has ANRed.
771 *
772 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
773 */
774 public abstract int getNumAnrs(int which);
775
776 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700777 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700778 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700779 * @return foreground cpu time in microseconds
780 */
781 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700782
Dianne Hackborn287952c2010-09-22 22:34:31 -0700783 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700784
Dianne Hackborn287952c2010-09-22 22:34:31 -0700785 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 }
787
788 /**
789 * The statistics associated with a particular package.
790 */
791 public static abstract class Pkg {
792
793 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700794 * Returns information about all wakeup alarms that have been triggered for this
795 * package. The mapping keys are tag names for the alarms, the counter contains
796 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700798 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799
800 /**
801 * Returns a mapping containing service statistics.
802 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700803 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804
805 /**
806 * The statistics associated with a particular service.
807 */
Joe Onoratoabded112016-02-08 16:49:39 -0800808 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809
810 /**
811 * Returns the amount of time spent started.
812 *
813 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700814 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 * @return
816 */
817 public abstract long getStartTime(long batteryUptime, int which);
818
819 /**
820 * Returns the total number of times startService() has been called.
821 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700822 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 */
824 public abstract int getStarts(int which);
825
826 /**
827 * Returns the total number times the service has been launched.
828 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700829 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 */
831 public abstract int getLaunches(int which);
832 }
833 }
834 }
835
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800836 public static final class LevelStepTracker {
837 public long mLastStepTime = -1;
838 public int mNumStepDurations;
839 public final long[] mStepDurations;
840
841 public LevelStepTracker(int maxLevelSteps) {
842 mStepDurations = new long[maxLevelSteps];
843 }
844
845 public LevelStepTracker(int numSteps, long[] steps) {
846 mNumStepDurations = numSteps;
847 mStepDurations = new long[numSteps];
848 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
849 }
850
851 public long getDurationAt(int index) {
852 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
853 }
854
855 public int getLevelAt(int index) {
856 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
857 >> STEP_LEVEL_LEVEL_SHIFT);
858 }
859
860 public int getInitModeAt(int index) {
861 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
862 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
863 }
864
865 public int getModModeAt(int index) {
866 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
867 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
868 }
869
870 private void appendHex(long val, int topOffset, StringBuilder out) {
871 boolean hasData = false;
872 while (topOffset >= 0) {
873 int digit = (int)( (val>>topOffset) & 0xf );
874 topOffset -= 4;
875 if (!hasData && digit == 0) {
876 continue;
877 }
878 hasData = true;
879 if (digit >= 0 && digit <= 9) {
880 out.append((char)('0' + digit));
881 } else {
882 out.append((char)('a' + digit - 10));
883 }
884 }
885 }
886
887 public void encodeEntryAt(int index, StringBuilder out) {
888 long item = mStepDurations[index];
889 long duration = item & STEP_LEVEL_TIME_MASK;
890 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
891 >> STEP_LEVEL_LEVEL_SHIFT);
892 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
893 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
894 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
895 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
896 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
897 case Display.STATE_OFF: out.append('f'); break;
898 case Display.STATE_ON: out.append('o'); break;
899 case Display.STATE_DOZE: out.append('d'); break;
900 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
901 }
902 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
903 out.append('p');
904 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700905 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
906 out.append('i');
907 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800908 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
909 case Display.STATE_OFF: out.append('F'); break;
910 case Display.STATE_ON: out.append('O'); break;
911 case Display.STATE_DOZE: out.append('D'); break;
912 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
913 }
914 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
915 out.append('P');
916 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700917 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
918 out.append('I');
919 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800920 out.append('-');
921 appendHex(level, 4, out);
922 out.append('-');
923 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
924 }
925
926 public void decodeEntryAt(int index, String value) {
927 final int N = value.length();
928 int i = 0;
929 char c;
930 long out = 0;
931 while (i < N && (c=value.charAt(i)) != '-') {
932 i++;
933 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800934 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800935 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800936 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800937 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800938 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800939 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800940 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
941 << STEP_LEVEL_INITIAL_MODE_SHIFT);
942 break;
943 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
944 << STEP_LEVEL_INITIAL_MODE_SHIFT);
945 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700946 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
947 << STEP_LEVEL_INITIAL_MODE_SHIFT);
948 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800949 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
950 break;
951 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
952 break;
953 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
954 break;
955 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
956 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
957 break;
958 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
959 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800960 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700961 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
962 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
963 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800964 }
965 }
966 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800967 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800968 while (i < N && (c=value.charAt(i)) != '-') {
969 i++;
970 level <<= 4;
971 if (c >= '0' && c <= '9') {
972 level += c - '0';
973 } else if (c >= 'a' && c <= 'f') {
974 level += c - 'a' + 10;
975 } else if (c >= 'A' && c <= 'F') {
976 level += c - 'A' + 10;
977 }
978 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800979 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800980 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
981 long duration = 0;
982 while (i < N && (c=value.charAt(i)) != '-') {
983 i++;
984 duration <<= 4;
985 if (c >= '0' && c <= '9') {
986 duration += c - '0';
987 } else if (c >= 'a' && c <= 'f') {
988 duration += c - 'a' + 10;
989 } else if (c >= 'A' && c <= 'F') {
990 duration += c - 'A' + 10;
991 }
992 }
993 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
994 }
995
996 public void init() {
997 mLastStepTime = -1;
998 mNumStepDurations = 0;
999 }
1000
1001 public void clearTime() {
1002 mLastStepTime = -1;
1003 }
1004
1005 public long computeTimePerLevel() {
1006 final long[] steps = mStepDurations;
1007 final int numSteps = mNumStepDurations;
1008
1009 // For now we'll do a simple average across all steps.
1010 if (numSteps <= 0) {
1011 return -1;
1012 }
1013 long total = 0;
1014 for (int i=0; i<numSteps; i++) {
1015 total += steps[i] & STEP_LEVEL_TIME_MASK;
1016 }
1017 return total / numSteps;
1018 /*
1019 long[] buckets = new long[numSteps];
1020 int numBuckets = 0;
1021 int numToAverage = 4;
1022 int i = 0;
1023 while (i < numSteps) {
1024 long totalTime = 0;
1025 int num = 0;
1026 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1027 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1028 num++;
1029 }
1030 buckets[numBuckets] = totalTime / num;
1031 numBuckets++;
1032 numToAverage *= 2;
1033 i += num;
1034 }
1035 if (numBuckets < 1) {
1036 return -1;
1037 }
1038 long averageTime = buckets[numBuckets-1];
1039 for (i=numBuckets-2; i>=0; i--) {
1040 averageTime = (averageTime + buckets[i]) / 2;
1041 }
1042 return averageTime;
1043 */
1044 }
1045
1046 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1047 int[] outNumOfInterest) {
1048 final long[] steps = mStepDurations;
1049 final int count = mNumStepDurations;
1050 if (count <= 0) {
1051 return -1;
1052 }
1053 long total = 0;
1054 int numOfInterest = 0;
1055 for (int i=0; i<count; i++) {
1056 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1057 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1058 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1059 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1060 // If the modes of interest didn't change during this step period...
1061 if ((modMode&modesOfInterest) == 0) {
1062 // And the mode values during this period match those we are measuring...
1063 if ((initMode&modesOfInterest) == modeValues) {
1064 // Then this can be used to estimate the total time!
1065 numOfInterest++;
1066 total += steps[i] & STEP_LEVEL_TIME_MASK;
1067 }
1068 }
1069 }
1070 if (numOfInterest <= 0) {
1071 return -1;
1072 }
1073
1074 if (outNumOfInterest != null) {
1075 outNumOfInterest[0] = numOfInterest;
1076 }
1077
1078 // The estimated time is the average time we spend in each level, multipled
1079 // by 100 -- the total number of battery levels
1080 return (total / numOfInterest) * 100;
1081 }
1082
1083 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1084 int stepCount = mNumStepDurations;
1085 final long lastStepTime = mLastStepTime;
1086 if (lastStepTime >= 0 && numStepLevels > 0) {
1087 final long[] steps = mStepDurations;
1088 long duration = elapsedRealtime - lastStepTime;
1089 for (int i=0; i<numStepLevels; i++) {
1090 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1091 long thisDuration = duration / (numStepLevels-i);
1092 duration -= thisDuration;
1093 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1094 thisDuration = STEP_LEVEL_TIME_MASK;
1095 }
1096 steps[0] = thisDuration | modeBits;
1097 }
1098 stepCount += numStepLevels;
1099 if (stepCount > steps.length) {
1100 stepCount = steps.length;
1101 }
1102 }
1103 mNumStepDurations = stepCount;
1104 mLastStepTime = elapsedRealtime;
1105 }
1106
1107 public void readFromParcel(Parcel in) {
1108 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001109 if (N > mStepDurations.length) {
1110 throw new ParcelFormatException("more step durations than available: " + N);
1111 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001112 mNumStepDurations = N;
1113 for (int i=0; i<N; i++) {
1114 mStepDurations[i] = in.readLong();
1115 }
1116 }
1117
1118 public void writeToParcel(Parcel out) {
1119 final int N = mNumStepDurations;
1120 out.writeInt(N);
1121 for (int i=0; i<N; i++) {
1122 out.writeLong(mStepDurations[i]);
1123 }
1124 }
1125 }
1126
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001127 public static final class PackageChange {
1128 public String mPackageName;
1129 public boolean mUpdate;
1130 public int mVersionCode;
1131 }
1132
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001133 public static final class DailyItem {
1134 public long mStartTime;
1135 public long mEndTime;
1136 public LevelStepTracker mDischargeSteps;
1137 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001138 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001139 }
1140
1141 public abstract DailyItem getDailyItemLocked(int daysAgo);
1142
1143 public abstract long getCurrentDailyStartTime();
1144
1145 public abstract long getNextMinDailyDeadline();
1146
1147 public abstract long getNextMaxDailyDeadline();
1148
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001149 public abstract long[] getCpuFreqs();
1150
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001151 public final static class HistoryTag {
1152 public String string;
1153 public int uid;
1154
1155 public int poolIdx;
1156
1157 public void setTo(HistoryTag o) {
1158 string = o.string;
1159 uid = o.uid;
1160 poolIdx = o.poolIdx;
1161 }
1162
1163 public void setTo(String _string, int _uid) {
1164 string = _string;
1165 uid = _uid;
1166 poolIdx = -1;
1167 }
1168
1169 public void writeToParcel(Parcel dest, int flags) {
1170 dest.writeString(string);
1171 dest.writeInt(uid);
1172 }
1173
1174 public void readFromParcel(Parcel src) {
1175 string = src.readString();
1176 uid = src.readInt();
1177 poolIdx = -1;
1178 }
1179
1180 @Override
1181 public boolean equals(Object o) {
1182 if (this == o) return true;
1183 if (o == null || getClass() != o.getClass()) return false;
1184
1185 HistoryTag that = (HistoryTag) o;
1186
1187 if (uid != that.uid) return false;
1188 if (!string.equals(that.string)) return false;
1189
1190 return true;
1191 }
1192
1193 @Override
1194 public int hashCode() {
1195 int result = string.hashCode();
1196 result = 31 * result + uid;
1197 return result;
1198 }
1199 }
1200
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001201 /**
1202 * Optional detailed information that can go into a history step. This is typically
1203 * generated each time the battery level changes.
1204 */
1205 public final static class HistoryStepDetails {
1206 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1207 public int userTime;
1208 public int systemTime;
1209
1210 // Top three apps using CPU in the last step, with times in 1/100 second.
1211 public int appCpuUid1;
1212 public int appCpuUTime1;
1213 public int appCpuSTime1;
1214 public int appCpuUid2;
1215 public int appCpuUTime2;
1216 public int appCpuSTime2;
1217 public int appCpuUid3;
1218 public int appCpuUTime3;
1219 public int appCpuSTime3;
1220
1221 // Information from /proc/stat
1222 public int statUserTime;
1223 public int statSystemTime;
1224 public int statIOWaitTime;
1225 public int statIrqTime;
1226 public int statSoftIrqTime;
1227 public int statIdlTime;
1228
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001229 // Platform-level low power state stats
1230 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001231 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001232
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001233 public HistoryStepDetails() {
1234 clear();
1235 }
1236
1237 public void clear() {
1238 userTime = systemTime = 0;
1239 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1240 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1241 = appCpuUTime3 = appCpuSTime3 = 0;
1242 }
1243
1244 public void writeToParcel(Parcel out) {
1245 out.writeInt(userTime);
1246 out.writeInt(systemTime);
1247 out.writeInt(appCpuUid1);
1248 out.writeInt(appCpuUTime1);
1249 out.writeInt(appCpuSTime1);
1250 out.writeInt(appCpuUid2);
1251 out.writeInt(appCpuUTime2);
1252 out.writeInt(appCpuSTime2);
1253 out.writeInt(appCpuUid3);
1254 out.writeInt(appCpuUTime3);
1255 out.writeInt(appCpuSTime3);
1256 out.writeInt(statUserTime);
1257 out.writeInt(statSystemTime);
1258 out.writeInt(statIOWaitTime);
1259 out.writeInt(statIrqTime);
1260 out.writeInt(statSoftIrqTime);
1261 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001262 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001263 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001264 }
1265
1266 public void readFromParcel(Parcel in) {
1267 userTime = in.readInt();
1268 systemTime = in.readInt();
1269 appCpuUid1 = in.readInt();
1270 appCpuUTime1 = in.readInt();
1271 appCpuSTime1 = in.readInt();
1272 appCpuUid2 = in.readInt();
1273 appCpuUTime2 = in.readInt();
1274 appCpuSTime2 = in.readInt();
1275 appCpuUid3 = in.readInt();
1276 appCpuUTime3 = in.readInt();
1277 appCpuSTime3 = in.readInt();
1278 statUserTime = in.readInt();
1279 statSystemTime = in.readInt();
1280 statIOWaitTime = in.readInt();
1281 statIrqTime = in.readInt();
1282 statSoftIrqTime = in.readInt();
1283 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001284 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001285 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001286 }
1287 }
1288
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001289 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001290 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001291
1292 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001293 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001294
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001295 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001296 public static final byte CMD_NULL = -1;
1297 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001298 public static final byte CMD_CURRENT_TIME = 5;
1299 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001300 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001301 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001302
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001303 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001304
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001305 /**
1306 * Return whether the command code is a delta data update.
1307 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001308 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001309 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001310 }
1311
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001312 public byte batteryLevel;
1313 public byte batteryStatus;
1314 public byte batteryHealth;
1315 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001316
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001317 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001318 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001319
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001320 // The charge of the battery in micro-Ampere-hours.
1321 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001322
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001323 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001324 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001325 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001326 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001327 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1328 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001329 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001330 public static final int STATE_PHONE_STATE_SHIFT = 6;
1331 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001332 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001333 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001334 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001335
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001336 // These states always appear directly in the first int token
1337 // of a delta change; they should be ones that change relatively
1338 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001339 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1340 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001341 public static final int STATE_GPS_ON_FLAG = 1<<29;
1342 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001343 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001344 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001345 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001346 // Do not use, this is used for coulomb delta count.
1347 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001348 // These are on the lower bits used for the command; if they change
1349 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001350 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001351 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001352 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001353 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1354 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1355 // empty slot
1356 // empty slot
1357 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001358
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001359 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001360 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1361
1362 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001363
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001364 public int states;
1365
Dianne Hackborn3251b902014-06-20 14:40:53 -07001366 // Constants from WIFI_SUPPL_STATE_*
1367 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1368 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1369 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1370 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1371 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1372 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1373
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001374 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001375 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1376 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1377 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001378 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001379 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1380 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1381 public static final int STATE2_CHARGING_FLAG = 1<<24;
1382 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1383 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1384 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001385 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001386
1387 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001388 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001389 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1390
1391 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001392
Dianne Hackborn40c87252014-03-19 16:55:40 -07001393 public int states2;
1394
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001395 // The wake lock that was acquired at this point.
1396 public HistoryTag wakelockTag;
1397
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001398 // Kernel wakeup reason at this point.
1399 public HistoryTag wakeReasonTag;
1400
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001401 // Non-null when there is more detailed information at this step.
1402 public HistoryStepDetails stepDetails;
1403
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001404 public static final int EVENT_FLAG_START = 0x8000;
1405 public static final int EVENT_FLAG_FINISH = 0x4000;
1406
1407 // No event in this item.
1408 public static final int EVENT_NONE = 0x0000;
1409 // Event is about a process that is running.
1410 public static final int EVENT_PROC = 0x0001;
1411 // Event is about an application package that is in the foreground.
1412 public static final int EVENT_FOREGROUND = 0x0002;
1413 // Event is about an application package that is at the top of the screen.
1414 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001415 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001416 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001417 // Events for all additional wake locks aquired/release within a wake block.
1418 // These are not generated by default.
1419 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001420 // Event is about an application executing a scheduled job.
1421 public static final int EVENT_JOB = 0x0006;
1422 // Events for users running.
1423 public static final int EVENT_USER_RUNNING = 0x0007;
1424 // Events for foreground user.
1425 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001426 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001427 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001428 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001429 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001430 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001431 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001432 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001433 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001434 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001435 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001436 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001437 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001438 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001439 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001440 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001441 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001442 // Event for a package being on the temporary whitelist.
1443 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001444 // Event for the screen waking up.
1445 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001446 // Event for the UID that woke up the application processor.
1447 // Used for wakeups coming from WiFi, modem, etc.
1448 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001449 // Event for reporting that a specific partial wake lock has been held for a long duration.
1450 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001451
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001452 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001453 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001454 // Mask to extract out only the type part of the event.
1455 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001456
1457 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1458 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1459 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1460 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1461 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1462 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001463 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1464 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001465 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1466 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001467 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1468 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1469 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1470 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1471 public static final int EVENT_USER_FOREGROUND_START =
1472 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1473 public static final int EVENT_USER_FOREGROUND_FINISH =
1474 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001475 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1476 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001477 public static final int EVENT_TEMP_WHITELIST_START =
1478 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1479 public static final int EVENT_TEMP_WHITELIST_FINISH =
1480 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001481 public static final int EVENT_LONG_WAKE_LOCK_START =
1482 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1483 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1484 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001485
1486 // For CMD_EVENT.
1487 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001488 public HistoryTag eventTag;
1489
Dianne Hackborn9a755432014-05-15 17:05:22 -07001490 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001491 public long currentTime;
1492
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001493 // Meta-data when reading.
1494 public int numReadInts;
1495
1496 // Pre-allocated objects.
1497 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001498 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001499 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001500
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001501 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001502 }
Bookatzc8c44962017-05-11 12:12:54 -07001503
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001504 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001505 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001506 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001507 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001508 }
Bookatzc8c44962017-05-11 12:12:54 -07001509
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001510 public int describeContents() {
1511 return 0;
1512 }
1513
1514 public void writeToParcel(Parcel dest, int flags) {
1515 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001516 int bat = (((int)cmd)&0xff)
1517 | ((((int)batteryLevel)<<8)&0xff00)
1518 | ((((int)batteryStatus)<<16)&0xf0000)
1519 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001520 | ((((int)batteryPlugType)<<24)&0xf000000)
1521 | (wakelockTag != null ? 0x10000000 : 0)
1522 | (wakeReasonTag != null ? 0x20000000 : 0)
1523 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001524 dest.writeInt(bat);
1525 bat = (((int)batteryTemperature)&0xffff)
1526 | ((((int)batteryVoltage)<<16)&0xffff0000);
1527 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001528 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001529 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001530 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001531 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001532 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001533 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001534 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001535 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001536 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001537 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001538 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001539 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001540 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001541 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001542 dest.writeLong(currentTime);
1543 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001544 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001545
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001546 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001547 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001548 int bat = src.readInt();
1549 cmd = (byte)(bat&0xff);
1550 batteryLevel = (byte)((bat>>8)&0xff);
1551 batteryStatus = (byte)((bat>>16)&0xf);
1552 batteryHealth = (byte)((bat>>20)&0xf);
1553 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001554 int bat2 = src.readInt();
1555 batteryTemperature = (short)(bat2&0xffff);
1556 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001557 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001558 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001559 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001560 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001561 wakelockTag = localWakelockTag;
1562 wakelockTag.readFromParcel(src);
1563 } else {
1564 wakelockTag = null;
1565 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001566 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001567 wakeReasonTag = localWakeReasonTag;
1568 wakeReasonTag.readFromParcel(src);
1569 } else {
1570 wakeReasonTag = null;
1571 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001572 if ((bat&0x40000000) != 0) {
1573 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001574 eventTag = localEventTag;
1575 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001576 } else {
1577 eventCode = EVENT_NONE;
1578 eventTag = null;
1579 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001580 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001581 currentTime = src.readLong();
1582 } else {
1583 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001584 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001585 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001586 }
1587
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001588 public void clear() {
1589 time = 0;
1590 cmd = CMD_NULL;
1591 batteryLevel = 0;
1592 batteryStatus = 0;
1593 batteryHealth = 0;
1594 batteryPlugType = 0;
1595 batteryTemperature = 0;
1596 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001597 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001598 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001599 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001600 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001601 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001602 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001603 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001604 }
Bookatzc8c44962017-05-11 12:12:54 -07001605
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001606 public void setTo(HistoryItem o) {
1607 time = o.time;
1608 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001609 setToCommon(o);
1610 }
1611
1612 public void setTo(long time, byte cmd, HistoryItem o) {
1613 this.time = time;
1614 this.cmd = cmd;
1615 setToCommon(o);
1616 }
1617
1618 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001619 batteryLevel = o.batteryLevel;
1620 batteryStatus = o.batteryStatus;
1621 batteryHealth = o.batteryHealth;
1622 batteryPlugType = o.batteryPlugType;
1623 batteryTemperature = o.batteryTemperature;
1624 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001625 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001626 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001627 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001628 if (o.wakelockTag != null) {
1629 wakelockTag = localWakelockTag;
1630 wakelockTag.setTo(o.wakelockTag);
1631 } else {
1632 wakelockTag = null;
1633 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001634 if (o.wakeReasonTag != null) {
1635 wakeReasonTag = localWakeReasonTag;
1636 wakeReasonTag.setTo(o.wakeReasonTag);
1637 } else {
1638 wakeReasonTag = null;
1639 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001640 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001641 if (o.eventTag != null) {
1642 eventTag = localEventTag;
1643 eventTag.setTo(o.eventTag);
1644 } else {
1645 eventTag = null;
1646 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001647 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001648 }
1649
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001650 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001651 return batteryLevel == o.batteryLevel
1652 && batteryStatus == o.batteryStatus
1653 && batteryHealth == o.batteryHealth
1654 && batteryPlugType == o.batteryPlugType
1655 && batteryTemperature == o.batteryTemperature
1656 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001657 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001658 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001659 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001660 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001661 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001662
1663 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001664 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001665 return false;
1666 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001667 if (wakelockTag != o.wakelockTag) {
1668 if (wakelockTag == null || o.wakelockTag == null) {
1669 return false;
1670 }
1671 if (!wakelockTag.equals(o.wakelockTag)) {
1672 return false;
1673 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001674 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001675 if (wakeReasonTag != o.wakeReasonTag) {
1676 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1677 return false;
1678 }
1679 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1680 return false;
1681 }
1682 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001683 if (eventTag != o.eventTag) {
1684 if (eventTag == null || o.eventTag == null) {
1685 return false;
1686 }
1687 if (!eventTag.equals(o.eventTag)) {
1688 return false;
1689 }
1690 }
1691 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001692 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001693 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001694
1695 public final static class HistoryEventTracker {
1696 private final HashMap<String, SparseIntArray>[] mActiveEvents
1697 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1698
1699 public boolean updateState(int code, String name, int uid, int poolIdx) {
1700 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1701 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1702 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1703 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001704 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001705 mActiveEvents[idx] = active;
1706 }
1707 SparseIntArray uids = active.get(name);
1708 if (uids == null) {
1709 uids = new SparseIntArray();
1710 active.put(name, uids);
1711 }
1712 if (uids.indexOfKey(uid) >= 0) {
1713 // Already set, nothing to do!
1714 return false;
1715 }
1716 uids.put(uid, poolIdx);
1717 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1718 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1719 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1720 if (active == null) {
1721 // not currently active, nothing to do.
1722 return false;
1723 }
1724 SparseIntArray uids = active.get(name);
1725 if (uids == null) {
1726 // not currently active, nothing to do.
1727 return false;
1728 }
1729 idx = uids.indexOfKey(uid);
1730 if (idx < 0) {
1731 // not currently active, nothing to do.
1732 return false;
1733 }
1734 uids.removeAt(idx);
1735 if (uids.size() <= 0) {
1736 active.remove(name);
1737 }
1738 }
1739 return true;
1740 }
1741
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001742 public void removeEvents(int code) {
1743 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1744 mActiveEvents[idx] = null;
1745 }
1746
Dianne Hackborn37de0982014-05-09 09:32:18 -07001747 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1748 return mActiveEvents[code];
1749 }
1750 }
1751
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001752 public static final class BitDescription {
1753 public final int mask;
1754 public final int shift;
1755 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001756 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001757 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001758 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001759
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001760 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001761 this.mask = mask;
1762 this.shift = -1;
1763 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001764 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001765 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001766 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001767 }
Bookatzc8c44962017-05-11 12:12:54 -07001768
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001769 public BitDescription(int mask, int shift, String name, String shortName,
1770 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001771 this.mask = mask;
1772 this.shift = shift;
1773 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001774 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001775 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001776 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001777 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001778 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001779
Dianne Hackbornfc064132014-06-02 12:42:12 -07001780 /**
1781 * Don't allow any more batching in to the current history event. This
1782 * is called when printing partial histories, so to ensure that the next
1783 * history event will go in to a new batch after what was printed in the
1784 * last partial history.
1785 */
1786 public abstract void commitCurrentHistoryBatchLocked();
1787
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001788 public abstract int getHistoryTotalSize();
1789
1790 public abstract int getHistoryUsedSize();
1791
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001792 public abstract boolean startIteratingHistoryLocked();
1793
Dianne Hackborn099bc622014-01-22 13:39:16 -08001794 public abstract int getHistoryStringPoolSize();
1795
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001796 public abstract int getHistoryStringPoolBytes();
1797
1798 public abstract String getHistoryTagPoolString(int index);
1799
1800 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001801
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001802 public abstract boolean getNextHistoryLocked(HistoryItem out);
1803
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001804 public abstract void finishIteratingHistoryLocked();
1805
1806 public abstract boolean startIteratingOldHistoryLocked();
1807
1808 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1809
1810 public abstract void finishIteratingOldHistoryLocked();
1811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001813 * Return the base time offset for the battery history.
1814 */
1815 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001816
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001817 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 * Returns the number of times the device has been started.
1819 */
1820 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001823 * 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 -08001824 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001825 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 * {@hide}
1827 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001828 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001829
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001830 /**
1831 * Returns the number of times the screen was turned on.
1832 *
1833 * {@hide}
1834 */
1835 public abstract int getScreenOnCount(int which);
1836
Jeff Browne95c3cd2014-05-02 16:59:26 -07001837 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1838
Dianne Hackborn617f8772009-03-31 15:04:46 -07001839 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1840 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1841 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1842 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1843 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001844
Dianne Hackborn617f8772009-03-31 15:04:46 -07001845 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1846 "dark", "dim", "medium", "light", "bright"
1847 };
Bookatzc8c44962017-05-11 12:12:54 -07001848
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001849 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1850 "0", "1", "2", "3", "4"
1851 };
1852
Dianne Hackborn617f8772009-03-31 15:04:46 -07001853 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001854
Dianne Hackborn617f8772009-03-31 15:04:46 -07001855 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001856 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001857 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001858 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001859 * {@hide}
1860 */
1861 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001862 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001865 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001866 * running on battery.
1867 *
1868 * {@hide}
1869 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001870 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001871
1872 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001873 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001874 *
1875 * {@hide}
1876 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001877 public abstract int getPowerSaveModeEnabledCount(int which);
1878
1879 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001880 * Constant for device idle mode: not active.
1881 */
1882 public static final int DEVICE_IDLE_MODE_OFF = 0;
1883
1884 /**
1885 * Constant for device idle mode: active in lightweight mode.
1886 */
1887 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1888
1889 /**
1890 * Constant for device idle mode: active in full mode.
1891 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001892 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001893
1894 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001895 * Returns the time in microseconds that device has been in idle mode while
1896 * running on battery.
1897 *
1898 * {@hide}
1899 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001900 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001901
1902 /**
1903 * Returns the number of times that the devie has gone in to idle mode.
1904 *
1905 * {@hide}
1906 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001907 public abstract int getDeviceIdleModeCount(int mode, int which);
1908
1909 /**
1910 * Return the longest duration we spent in a particular device idle mode (fully in the
1911 * mode, not in idle maintenance etc).
1912 */
1913 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001914
1915 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001916 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001917 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001918 * counts all of the time that we consider the device to be idle, whether or not
1919 * it is currently in the actual device idle mode.
1920 *
1921 * {@hide}
1922 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001923 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001924
1925 /**
1926 * Returns the number of times that the devie has started idling.
1927 *
1928 * {@hide}
1929 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001930 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001931
1932 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001933 * Returns the number of times that connectivity state changed.
1934 *
1935 * {@hide}
1936 */
1937 public abstract int getNumConnectivityChange(int which);
1938
1939 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001940 * 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 -08001941 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001942 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 * {@hide}
1944 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001945 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001946
Dianne Hackborn627bba72009-03-24 22:32:56 -07001947 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001948 * Returns the number of times a phone call was activated.
1949 *
1950 * {@hide}
1951 */
1952 public abstract int getPhoneOnCount(int which);
1953
1954 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001955 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001956 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001957 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001958 * {@hide}
1959 */
1960 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001961 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001962
Dianne Hackborn617f8772009-03-31 15:04:46 -07001963 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001964 * Returns the time in microseconds that the phone has been trying to
1965 * acquire a signal.
1966 *
1967 * {@hide}
1968 */
1969 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001970 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001971
1972 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001973 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001974 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001975 * {@hide}
1976 */
1977 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1978
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001979 /**
1980 * Returns the time in microseconds that the mobile network has been active
1981 * (in a high power state).
1982 *
1983 * {@hide}
1984 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001985 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001986
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001987 /**
1988 * Returns the number of times that the mobile network has transitioned to the
1989 * active state.
1990 *
1991 * {@hide}
1992 */
1993 public abstract int getMobileRadioActiveCount(int which);
1994
1995 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001996 * Returns the time in microseconds that is the difference between the mobile radio
1997 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1998 * from the radio.
1999 *
2000 * {@hide}
2001 */
2002 public abstract long getMobileRadioActiveAdjustedTime(int which);
2003
2004 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002005 * Returns the time in microseconds that the mobile network has been active
2006 * (in a high power state) but not being able to blame on an app.
2007 *
2008 * {@hide}
2009 */
2010 public abstract long getMobileRadioActiveUnknownTime(int which);
2011
2012 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002013 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002014 *
2015 * {@hide}
2016 */
2017 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002018
Dianne Hackborn627bba72009-03-24 22:32:56 -07002019 public static final int DATA_CONNECTION_NONE = 0;
2020 public static final int DATA_CONNECTION_GPRS = 1;
2021 public static final int DATA_CONNECTION_EDGE = 2;
2022 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002023 public static final int DATA_CONNECTION_CDMA = 4;
2024 public static final int DATA_CONNECTION_EVDO_0 = 5;
2025 public static final int DATA_CONNECTION_EVDO_A = 6;
2026 public static final int DATA_CONNECTION_1xRTT = 7;
2027 public static final int DATA_CONNECTION_HSDPA = 8;
2028 public static final int DATA_CONNECTION_HSUPA = 9;
2029 public static final int DATA_CONNECTION_HSPA = 10;
2030 public static final int DATA_CONNECTION_IDEN = 11;
2031 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002032 public static final int DATA_CONNECTION_LTE = 13;
2033 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002034 public static final int DATA_CONNECTION_HSPAP = 15;
2035 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002036
Dianne Hackborn627bba72009-03-24 22:32:56 -07002037 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002038 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002039 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002040 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002041 };
Bookatzc8c44962017-05-11 12:12:54 -07002042
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002043 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002044
Dianne Hackborn627bba72009-03-24 22:32:56 -07002045 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002046 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002047 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002048 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002049 * {@hide}
2050 */
2051 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002052 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002055 * Returns the number of times the phone has entered the given data
2056 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002057 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002058 * {@hide}
2059 */
2060 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002061
Dianne Hackborn3251b902014-06-20 14:40:53 -07002062 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2063 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2064 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2065 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2066 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2067 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2068 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2069 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2070 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2071 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2072 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2073 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2074 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2075
2076 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2077
2078 static final String[] WIFI_SUPPL_STATE_NAMES = {
2079 "invalid", "disconn", "disabled", "inactive", "scanning",
2080 "authenticating", "associating", "associated", "4-way-handshake",
2081 "group-handshake", "completed", "dormant", "uninit"
2082 };
2083
2084 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2085 "inv", "dsc", "dis", "inact", "scan",
2086 "auth", "ascing", "asced", "4-way",
2087 "group", "compl", "dorm", "uninit"
2088 };
2089
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002090 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2091 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002092 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002093 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2094 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002095 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002096 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2097 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2098 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002099 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002100 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002101 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002102 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002103 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2104 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002105 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2106 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2107 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2108 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2109 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2110 new String[] {"in", "out", "emergency", "off"},
2111 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002112 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2113 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2114 SignalStrength.SIGNAL_STRENGTH_NAMES,
2115 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002116 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2117 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2118 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002119 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002120
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002121 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2122 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002123 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002124 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002125 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002126 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002127 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002128 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2129 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2130 new String[] { "off", "light", "full", "???" },
2131 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002132 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2133 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2134 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002135 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2136 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2137 new String[] { "0", "1", "2", "3", "4" },
2138 new String[] { "0", "1", "2", "3", "4" }),
2139 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2140 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2141 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002142 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002143 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002144 };
2145
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002146 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002147 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002148 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2149 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002150 };
2151
2152 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002153 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002154 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002155 "Esw", "Ewa", "Elw", "Eec"
2156 };
2157
2158 @FunctionalInterface
2159 public interface IntToString {
2160 String applyAsString(int val);
2161 }
2162
2163 private static final IntToString sUidToString = UserHandle::formatUid;
2164 private static final IntToString sIntToString = Integer::toString;
2165
2166 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2167 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2168 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2169 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2170 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002171 };
2172
Dianne Hackborn617f8772009-03-31 15:04:46 -07002173 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002174 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002175 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002176 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002177 * {@hide}
2178 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002179 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002180
2181 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002182 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002183 * been in the running state while the device was running on battery.
2184 *
2185 * {@hide}
2186 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002187 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002188
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002189 public static final int WIFI_STATE_OFF = 0;
2190 public static final int WIFI_STATE_OFF_SCANNING = 1;
2191 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2192 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2193 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2194 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2195 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2196 public static final int WIFI_STATE_SOFT_AP = 7;
2197
2198 static final String[] WIFI_STATE_NAMES = {
2199 "off", "scanning", "no_net", "disconn",
2200 "sta", "p2p", "sta_p2p", "soft_ap"
2201 };
2202
2203 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2204
2205 /**
2206 * Returns the time in microseconds that WiFi has been running in the given state.
2207 *
2208 * {@hide}
2209 */
2210 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002211 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002212
2213 /**
2214 * Returns the number of times that WiFi has entered the given state.
2215 *
2216 * {@hide}
2217 */
2218 public abstract int getWifiStateCount(int wifiState, int which);
2219
The Android Open Source Project10592532009-03-18 17:39:46 -07002220 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002221 * Returns the time in microseconds that the wifi supplicant has been
2222 * in a given state.
2223 *
2224 * {@hide}
2225 */
2226 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2227
2228 /**
2229 * Returns the number of times that the wifi supplicant has transitioned
2230 * to a given state.
2231 *
2232 * {@hide}
2233 */
2234 public abstract int getWifiSupplStateCount(int state, int which);
2235
2236 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2237
2238 /**
2239 * Returns the time in microseconds that WIFI has been running with
2240 * the given signal strength.
2241 *
2242 * {@hide}
2243 */
2244 public abstract long getWifiSignalStrengthTime(int strengthBin,
2245 long elapsedRealtimeUs, int which);
2246
2247 /**
2248 * Returns the number of times WIFI has entered the given signal strength.
2249 *
2250 * {@hide}
2251 */
2252 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2253
2254 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002255 * Returns the time in microseconds that the flashlight has been on while the device was
2256 * running on battery.
2257 *
2258 * {@hide}
2259 */
2260 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2261
2262 /**
2263 * Returns the number of times that the flashlight has been turned on while the device was
2264 * running on battery.
2265 *
2266 * {@hide}
2267 */
2268 public abstract long getFlashlightOnCount(int which);
2269
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002270 /**
2271 * Returns the time in microseconds that the camera has been on while the device was
2272 * running on battery.
2273 *
2274 * {@hide}
2275 */
2276 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2277
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002278 /**
2279 * Returns the time in microseconds that bluetooth scans were running while the device was
2280 * on battery.
2281 *
2282 * {@hide}
2283 */
2284 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002285
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002286 public static final int NETWORK_MOBILE_RX_DATA = 0;
2287 public static final int NETWORK_MOBILE_TX_DATA = 1;
2288 public static final int NETWORK_WIFI_RX_DATA = 2;
2289 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002290 public static final int NETWORK_BT_RX_DATA = 4;
2291 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002292 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2293 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2294 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2295 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2296 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002297
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002298 public abstract long getNetworkActivityBytes(int type, int which);
2299 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002300
Adam Lesinskie08af192015-03-25 16:42:59 -07002301 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002302 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002303 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002304 * actual power data.
2305 */
2306 public abstract boolean hasWifiActivityReporting();
2307
2308 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002309 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2310 * in various radio controller states, such as transmit, receive, and idle.
2311 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002312 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002313 public abstract ControllerActivityCounter getWifiControllerActivity();
2314
2315 /**
2316 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2317 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2318 * actual power data.
2319 */
2320 public abstract boolean hasBluetoothActivityReporting();
2321
2322 /**
2323 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2324 * in various radio controller states, such as transmit, receive, and idle.
2325 * @return non-null {@link ControllerActivityCounter}
2326 */
2327 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2328
2329 /**
2330 * Returns true if the BatteryStats object has detailed modem power reports.
2331 * When true, calling {@link #getModemControllerActivity()} will yield the
2332 * actual power data.
2333 */
2334 public abstract boolean hasModemActivityReporting();
2335
2336 /**
2337 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2338 * in various radio controller states, such as transmit, receive, and idle.
2339 * @return non-null {@link ControllerActivityCounter}
2340 */
2341 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002342
The Android Open Source Project10592532009-03-18 17:39:46 -07002343 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002344 * Return the wall clock time when battery stats data collection started.
2345 */
2346 public abstract long getStartClockTime();
2347
2348 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002349 * Return platform version tag that we were running in when the battery stats started.
2350 */
2351 public abstract String getStartPlatformVersion();
2352
2353 /**
2354 * Return platform version tag that we were running in when the battery stats ended.
2355 */
2356 public abstract String getEndPlatformVersion();
2357
2358 /**
2359 * Return the internal version code of the parcelled format.
2360 */
2361 public abstract int getParcelVersion();
2362
2363 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 * Return whether we are currently running on battery.
2365 */
2366 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 /**
2369 * Returns a SparseArray containing the statistics for each uid.
2370 */
2371 public abstract SparseArray<? extends Uid> getUidStats();
2372
2373 /**
2374 * Returns the current battery uptime in microseconds.
2375 *
2376 * @param curTime the amount of elapsed realtime in microseconds.
2377 */
2378 public abstract long getBatteryUptime(long curTime);
2379
2380 /**
2381 * Returns the current battery realtime in microseconds.
2382 *
2383 * @param curTime the amount of elapsed realtime in microseconds.
2384 */
2385 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002386
The Android Open Source Project10592532009-03-18 17:39:46 -07002387 /**
Evan Millar633a1742009-04-02 16:36:33 -07002388 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002389 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002390 */
Evan Millar633a1742009-04-02 16:36:33 -07002391 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002392
The Android Open Source Project10592532009-03-18 17:39:46 -07002393 /**
Evan Millar633a1742009-04-02 16:36:33 -07002394 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2395 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002396 */
Evan Millar633a1742009-04-02 16:36:33 -07002397 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398
2399 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002400 * Get the amount the battery has discharged since the stats were
2401 * last reset after charging, as a lower-end approximation.
2402 */
2403 public abstract int getLowDischargeAmountSinceCharge();
2404
2405 /**
2406 * Get the amount the battery has discharged since the stats were
2407 * last reset after charging, as an upper-end approximation.
2408 */
2409 public abstract int getHighDischargeAmountSinceCharge();
2410
2411 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002412 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2413 */
2414 public abstract int getDischargeAmount(int which);
2415
2416 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002417 * Get the amount the battery has discharged while the screen was on,
2418 * since the last time power was unplugged.
2419 */
2420 public abstract int getDischargeAmountScreenOn();
2421
2422 /**
2423 * Get the amount the battery has discharged while the screen was on,
2424 * since the last time the device was charged.
2425 */
2426 public abstract int getDischargeAmountScreenOnSinceCharge();
2427
2428 /**
2429 * Get the amount the battery has discharged while the screen was off,
2430 * since the last time power was unplugged.
2431 */
2432 public abstract int getDischargeAmountScreenOff();
2433
2434 /**
2435 * Get the amount the battery has discharged while the screen was off,
2436 * since the last time the device was charged.
2437 */
2438 public abstract int getDischargeAmountScreenOffSinceCharge();
2439
2440 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 * Returns the total, last, or current battery uptime in microseconds.
2442 *
2443 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002444 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 */
2446 public abstract long computeBatteryUptime(long curTime, int which);
2447
2448 /**
2449 * Returns the total, last, or current battery realtime in microseconds.
2450 *
2451 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002452 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 */
2454 public abstract long computeBatteryRealtime(long curTime, int which);
2455
2456 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002457 * Returns the total, last, or current battery screen off uptime in microseconds.
2458 *
2459 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002460 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002461 */
2462 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2463
2464 /**
2465 * Returns the total, last, or current battery screen off realtime in microseconds.
2466 *
2467 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002468 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002469 */
2470 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2471
2472 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 * Returns the total, last, or current uptime in microseconds.
2474 *
2475 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002476 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 */
2478 public abstract long computeUptime(long curTime, int which);
2479
2480 /**
2481 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002482 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002484 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 */
2486 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002487
2488 /**
2489 * Compute an approximation for how much run time (in microseconds) is remaining on
2490 * the battery. Returns -1 if no time can be computed: either there is not
2491 * enough current data to make a decision, or the battery is currently
2492 * charging.
2493 *
2494 * @param curTime The current elepsed realtime in microseconds.
2495 */
2496 public abstract long computeBatteryTimeRemaining(long curTime);
2497
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002498 // The part of a step duration that is the actual time.
2499 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2500
2501 // Bits in a step duration that are the new battery level we are at.
2502 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002503 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002504
2505 // Bits in a step duration that are the initial mode we were in at that step.
2506 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002507 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002508
2509 // Bits in a step duration that indicate which modes changed during that step.
2510 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002511 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002512
2513 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2514 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2515
Santos Cordone94f0502017-02-24 12:31:20 -08002516 // The largest value for screen state that is tracked in battery states. Any values above
2517 // this should be mapped back to one of the tracked values before being tracked here.
2518 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2519
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002520 // Step duration mode: power save is on.
2521 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2522
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002523 // Step duration mode: device is currently in idle mode.
2524 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2525
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002526 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2527 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002528 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2529 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002530 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2531 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2532 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2533 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2534 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002535 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2536 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002537 };
2538 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2539 (Display.STATE_OFF-1),
2540 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002541 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002542 (Display.STATE_ON-1),
2543 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2544 (Display.STATE_DOZE-1),
2545 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2546 (Display.STATE_DOZE_SUSPEND-1),
2547 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002548 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002549 };
2550 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2551 "screen off",
2552 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002553 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002554 "screen on",
2555 "screen on power save",
2556 "screen doze",
2557 "screen doze power save",
2558 "screen doze-suspend",
2559 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002560 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002561 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002562
2563 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002564 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2565 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2566 * a coulomb counter.
2567 */
2568 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2569
2570 /**
2571 * Return the counter keeping track of the amount of battery discharge measured in
2572 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2573 * a coulomb counter.
2574 */
2575 public abstract LongCounter getDischargeCoulombCounter();
2576
2577 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002578 * Returns the estimated real battery capacity, which may be less than the capacity
2579 * declared by the PowerProfile.
2580 * @return The estimated battery capacity in mAh.
2581 */
2582 public abstract int getEstimatedBatteryCapacity();
2583
2584 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002585 * @return The minimum learned battery capacity in uAh.
2586 */
2587 public abstract int getMinLearnedBatteryCapacity();
2588
2589 /**
2590 * @return The maximum learned battery capacity in uAh.
2591 */
2592 public abstract int getMaxLearnedBatteryCapacity() ;
2593
2594 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002595 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002596 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002597 public abstract LevelStepTracker getDischargeLevelStepTracker();
2598
2599 /**
2600 * Return the array of daily discharge step durations.
2601 */
2602 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002603
2604 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002605 * Compute an approximation for how much time (in microseconds) remains until the battery
2606 * is fully charged. Returns -1 if no time can be computed: either there is not
2607 * enough current data to make a decision, or the battery is currently
2608 * discharging.
2609 *
2610 * @param curTime The current elepsed realtime in microseconds.
2611 */
2612 public abstract long computeChargeTimeRemaining(long curTime);
2613
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002614 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002615 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002616 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002617 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002618
2619 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002620 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002621 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002622 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002623
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002624 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2625
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002626 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002627
Evan Millarc64edde2009-04-18 12:26:32 -07002628 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629
James Carr2dd7e5e2016-07-20 18:48:39 -07002630 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2631
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002632 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2633
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002634 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 long days = seconds / (60 * 60 * 24);
2636 if (days != 0) {
2637 out.append(days);
2638 out.append("d ");
2639 }
2640 long used = days * 60 * 60 * 24;
2641
2642 long hours = (seconds - used) / (60 * 60);
2643 if (hours != 0 || used != 0) {
2644 out.append(hours);
2645 out.append("h ");
2646 }
2647 used += hours * 60 * 60;
2648
2649 long mins = (seconds-used) / 60;
2650 if (mins != 0 || used != 0) {
2651 out.append(mins);
2652 out.append("m ");
2653 }
2654 used += mins * 60;
2655
2656 if (seconds != 0 || used != 0) {
2657 out.append(seconds-used);
2658 out.append("s ");
2659 }
2660 }
2661
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002662 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002664 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 sb.append(time - (sec * 1000));
2666 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 }
2668
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002669 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002670 long sec = time / 1000;
2671 formatTimeRaw(sb, sec);
2672 sb.append(time - (sec * 1000));
2673 sb.append("ms");
2674 }
2675
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002676 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002678 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 }
2680 float perc = ((float)num) / ((float)den) * 100;
2681 mFormatBuilder.setLength(0);
2682 mFormatter.format("%.1f%%", perc);
2683 return mFormatBuilder.toString();
2684 }
2685
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002686 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002687 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002688
Evan Millar22ac0432009-03-31 11:33:18 -07002689 if (bytes < BYTES_PER_KB) {
2690 return bytes + "B";
2691 } else if (bytes < BYTES_PER_MB) {
2692 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2693 return mFormatBuilder.toString();
2694 } else if (bytes < BYTES_PER_GB){
2695 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2696 return mFormatBuilder.toString();
2697 } else {
2698 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2699 return mFormatBuilder.toString();
2700 }
2701 }
2702
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002703 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002704 if (timer != null) {
2705 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002706 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002707 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2708 return totalTimeMillis;
2709 }
2710 return 0;
2711 }
2712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 /**
2714 *
2715 * @param sb a StringBuilder object.
2716 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002717 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002719 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720 * @param linePrefix a String to be prepended to each line of output.
2721 * @return the line prefix
2722 */
2723 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002724 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002727 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002728
Evan Millarc64edde2009-04-18 12:26:32 -07002729 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 if (totalTimeMillis != 0) {
2731 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002732 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002733 if (name != null) {
2734 sb.append(name);
2735 sb.append(' ');
2736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 sb.append('(');
2738 sb.append(count);
2739 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002740 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2741 if (maxDurationMs >= 0) {
2742 sb.append(" max=");
2743 sb.append(maxDurationMs);
2744 }
Bookatz506a8182017-05-01 14:18:42 -07002745 // Put actual time if it is available and different from totalTimeMillis.
2746 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2747 if (totalDurMs > totalTimeMillis) {
2748 sb.append(" actual=");
2749 sb.append(totalDurMs);
2750 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002751 if (timer.isRunningLocked()) {
2752 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2753 if (currentMs >= 0) {
2754 sb.append(" (running for ");
2755 sb.append(currentMs);
2756 sb.append("ms)");
2757 } else {
2758 sb.append(" (running)");
2759 }
2760 }
2761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 return ", ";
2763 }
2764 }
2765 return linePrefix;
2766 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002767
2768 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002769 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002770 *
2771 * @param pw a PrintWriter object to print to.
2772 * @param sb a StringBuilder object.
2773 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002774 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002775 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2776 * @param prefix a String to be prepended to each line of output.
2777 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002778 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002779 */
2780 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002781 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002782 if (timer != null) {
2783 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002784 final long totalTimeMs = (timer.getTotalTimeLocked(
2785 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002786 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002787 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002788 sb.setLength(0);
2789 sb.append(prefix);
2790 sb.append(" ");
2791 sb.append(type);
2792 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002793 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002794 sb.append("realtime (");
2795 sb.append(count);
2796 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002797 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2798 if (maxDurationMs >= 0) {
2799 sb.append(" max=");
2800 sb.append(maxDurationMs);
2801 }
2802 if (timer.isRunningLocked()) {
2803 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2804 if (currentMs >= 0) {
2805 sb.append(" (running for ");
2806 sb.append(currentMs);
2807 sb.append("ms)");
2808 } else {
2809 sb.append(" (running)");
2810 }
2811 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002812 pw.println(sb.toString());
2813 return true;
2814 }
2815 }
2816 return false;
2817 }
Bookatzc8c44962017-05-11 12:12:54 -07002818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 /**
2820 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002821 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 * @param sb a StringBuilder object.
2823 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002824 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002826 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 * @param linePrefix a String to be prepended to each line of output.
2828 * @return the line prefix
2829 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002830 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2831 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 long totalTimeMicros = 0;
2833 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002834 long max = 0;
2835 long current = 0;
2836 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002838 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002839 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002840 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2841 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002842 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 }
2844 sb.append(linePrefix);
2845 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2846 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002847 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002849 sb.append(',');
2850 sb.append(current);
2851 sb.append(',');
2852 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002853 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2854 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2855 // totalDuration independent of totalTimeMicros (since they are not pooled).
2856 if (name != null) {
2857 sb.append(',');
2858 sb.append(totalDuration);
2859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 return ",";
2861 }
Bookatz506a8182017-05-01 14:18:42 -07002862
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002863 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2864 String type) {
2865 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2866 pw.print(',');
2867 pw.print(uid);
2868 pw.print(',');
2869 pw.print(category);
2870 pw.print(',');
2871 pw.print(type);
2872 }
2873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 /**
2875 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002876 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 * @param pw the PageWriter to dump log to
2878 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2879 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2880 * @param args type-dependent data arguments
2881 */
Bookatzc8c44962017-05-11 12:12:54 -07002882 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002884 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002885 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002886 pw.print(',');
2887 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002889 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002891
2892 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002893 * Dump a given timer stat for terse checkin mode.
2894 *
2895 * @param pw the PageWriter to dump log to
2896 * @param uid the UID to log
2897 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2898 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2899 * @param timer a {@link Timer} to dump stats for
2900 * @param rawRealtime the current elapsed realtime of the system in microseconds
2901 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2902 */
2903 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2904 Timer timer, long rawRealtime, int which) {
2905 if (timer != null) {
2906 // Convert from microseconds to milliseconds with rounding
2907 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2908 / 1000;
2909 final int count = timer.getCountLocked(which);
2910 if (totalTime != 0) {
2911 dumpLine(pw, uid, category, type, totalTime, count);
2912 }
2913 }
2914 }
2915
2916 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002917 * Checks if the ControllerActivityCounter has any data worth dumping.
2918 */
2919 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2920 if (counter == null) {
2921 return false;
2922 }
2923
2924 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2925 || counter.getRxTimeCounter().getCountLocked(which) != 0
2926 || counter.getPowerCounter().getCountLocked(which) != 0) {
2927 return true;
2928 }
2929
2930 for (LongCounter c : counter.getTxTimeCounters()) {
2931 if (c.getCountLocked(which) != 0) {
2932 return true;
2933 }
2934 }
2935 return false;
2936 }
2937
2938 /**
2939 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2940 * The order of the arguments in the final check in line is:
2941 *
2942 * idle, rx, power, tx...
2943 *
2944 * where tx... is one or more transmit level times.
2945 */
2946 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2947 String type,
2948 ControllerActivityCounter counter,
2949 int which) {
2950 if (!controllerActivityHasData(counter, which)) {
2951 return;
2952 }
2953
2954 dumpLineHeader(pw, uid, category, type);
2955 pw.print(",");
2956 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2957 pw.print(",");
2958 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2959 pw.print(",");
2960 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2961 for (LongCounter c : counter.getTxTimeCounters()) {
2962 pw.print(",");
2963 pw.print(c.getCountLocked(which));
2964 }
2965 pw.println();
2966 }
2967
2968 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2969 String prefix, String controllerName,
2970 ControllerActivityCounter counter,
2971 int which) {
2972 if (controllerActivityHasData(counter, which)) {
2973 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2974 }
2975 }
2976
2977 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2978 String controllerName,
2979 ControllerActivityCounter counter, int which) {
2980 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2981 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2982 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2983 long totalTxTimeMs = 0;
2984 for (LongCounter txState : counter.getTxTimeCounters()) {
2985 totalTxTimeMs += txState.getCountLocked(which);
2986 }
2987
2988 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2989
2990 sb.setLength(0);
2991 sb.append(prefix);
2992 sb.append(" ");
2993 sb.append(controllerName);
2994 sb.append(" Idle time: ");
2995 formatTimeMs(sb, idleTimeMs);
2996 sb.append("(");
2997 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2998 sb.append(")");
2999 pw.println(sb.toString());
3000
3001 sb.setLength(0);
3002 sb.append(prefix);
3003 sb.append(" ");
3004 sb.append(controllerName);
3005 sb.append(" Rx time: ");
3006 formatTimeMs(sb, rxTimeMs);
3007 sb.append("(");
3008 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
3009 sb.append(")");
3010 pw.println(sb.toString());
3011
3012 sb.setLength(0);
3013 sb.append(prefix);
3014 sb.append(" ");
3015 sb.append(controllerName);
3016 sb.append(" Tx time: ");
3017 formatTimeMs(sb, totalTxTimeMs);
3018 sb.append("(");
3019 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
3020 sb.append(")");
3021 pw.println(sb.toString());
3022
3023 final int numTxLvls = counter.getTxTimeCounters().length;
3024 if (numTxLvls > 1) {
3025 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3026 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3027 sb.setLength(0);
3028 sb.append(prefix);
3029 sb.append(" [");
3030 sb.append(lvl);
3031 sb.append("] ");
3032 formatTimeMs(sb, txLvlTimeMs);
3033 sb.append("(");
3034 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3035 sb.append(")");
3036 pw.println(sb.toString());
3037 }
3038 }
3039
3040 sb.setLength(0);
3041 sb.append(prefix);
3042 sb.append(" ");
3043 sb.append(controllerName);
3044 sb.append(" Power drain: ").append(
3045 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3046 sb.append("mAh");
3047 pw.println(sb.toString());
3048 }
3049
3050 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003051 * Temporary for settings.
3052 */
3053 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3054 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3055 }
3056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 /**
3058 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003059 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003062 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3063 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3065 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003066 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3069 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003070 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3071 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3072 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 final long totalRealtime = computeRealtime(rawRealtime, which);
3074 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003075 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003076 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003077 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003078 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3079 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003080 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003081 rawRealtime, which);
3082 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3083 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003084 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003085 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003086 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003087 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003088 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3089 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3090 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003091
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003092 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003093
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003094 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003095 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003096
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003097 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003100 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003101 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003102 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003103 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003104 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003105 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003106 getEstimatedBatteryCapacity(),
3107 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003108
Bookatzc8c44962017-05-11 12:12:54 -07003109
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003110 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003111 long fullWakeLockTimeTotal = 0;
3112 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003113
Evan Millar22ac0432009-03-31 11:33:18 -07003114 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003115 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003116
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003117 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3118 = u.getWakelockStats();
3119 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3120 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003121
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003122 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3123 if (fullWakeTimer != null) {
3124 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3125 which);
3126 }
3127
3128 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3129 if (partialWakeTimer != null) {
3130 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3131 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003132 }
3133 }
3134 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003135
3136 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003137 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3138 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3139 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3140 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3141 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3142 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3143 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3144 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003145 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3146 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003147 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3148 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003149 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3150 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003151
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003152 // Dump Modem controller stats
3153 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3154 getModemControllerActivity(), which);
3155
Adam Lesinskie283d332015-04-16 12:29:25 -07003156 // Dump Wifi controller stats
3157 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3158 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003159 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003160 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003161
3162 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3163 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003164
3165 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003166 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3167 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 // Dump misc stats
3170 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003171 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003172 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003173 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003174 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003175 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003176 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3177 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003178 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003179 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3180 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3181 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3182 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003183 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003184
Dianne Hackborn617f8772009-03-31 15:04:46 -07003185 // Dump screen brightness stats
3186 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3187 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003188 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003189 }
3190 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003191
Dianne Hackborn627bba72009-03-24 22:32:56 -07003192 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003193 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3194 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003195 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003196 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003197 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003198 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003199 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003200 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003201 args[i] = getPhoneSignalStrengthCount(i, which);
3202 }
3203 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003204
Dianne Hackborn627bba72009-03-24 22:32:56 -07003205 // Dump network type stats
3206 args = new Object[NUM_DATA_CONNECTION_TYPES];
3207 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003208 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003209 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003210 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3211 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3212 args[i] = getPhoneDataConnectionCount(i, which);
3213 }
3214 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003215
3216 // Dump wifi state stats
3217 args = new Object[NUM_WIFI_STATES];
3218 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003219 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003220 }
3221 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3222 for (int i=0; i<NUM_WIFI_STATES; i++) {
3223 args[i] = getWifiStateCount(i, which);
3224 }
3225 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3226
Dianne Hackborn3251b902014-06-20 14:40:53 -07003227 // Dump wifi suppl state stats
3228 args = new Object[NUM_WIFI_SUPPL_STATES];
3229 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3230 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3231 }
3232 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3233 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3234 args[i] = getWifiSupplStateCount(i, which);
3235 }
3236 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3237
3238 // Dump wifi signal strength stats
3239 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3240 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3241 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3242 }
3243 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3244 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3245 args[i] = getWifiSignalStrengthCount(i, which);
3246 }
3247 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3248
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003249 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003250 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003251 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003252 }
Bookatzc8c44962017-05-11 12:12:54 -07003253
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003254 if (which == STATS_SINCE_UNPLUGGED) {
3255 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3256 getDischargeStartLevel()-getDischargeCurrentLevel(),
3257 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003258 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3259 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003260 } else {
3261 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3262 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003263 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003264 getDischargeAmountScreenOffSinceCharge(),
3265 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003266 }
Bookatzc8c44962017-05-11 12:12:54 -07003267
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003268 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003269 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003270 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003271 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003272 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003273 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003274 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3275 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003276 }
Evan Millarc64edde2009-04-18 12:26:32 -07003277 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003278 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003279 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003280 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3281 // Not doing the regular wake lock formatting to remain compatible
3282 // with the old checkin format.
3283 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3284 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003285 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003286 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003287 }
3288 }
Evan Millarc64edde2009-04-18 12:26:32 -07003289 }
Bookatzc8c44962017-05-11 12:12:54 -07003290
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003291 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003292 helper.create(this);
3293 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003294 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003295 if (sippers != null && sippers.size() > 0) {
3296 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3297 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003298 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003299 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3300 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3301 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003302 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003303 int uid = 0;
3304 String label;
3305 switch (bs.drainType) {
3306 case IDLE:
3307 label="idle";
3308 break;
3309 case CELL:
3310 label="cell";
3311 break;
3312 case PHONE:
3313 label="phone";
3314 break;
3315 case WIFI:
3316 label="wifi";
3317 break;
3318 case BLUETOOTH:
3319 label="blue";
3320 break;
3321 case SCREEN:
3322 label="scrn";
3323 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003324 case FLASHLIGHT:
3325 label="flashlight";
3326 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003327 case APP:
3328 uid = bs.uidObj.getUid();
3329 label = "uid";
3330 break;
3331 case USER:
3332 uid = UserHandle.getUid(bs.userId, 0);
3333 label = "user";
3334 break;
3335 case UNACCOUNTED:
3336 label = "unacc";
3337 break;
3338 case OVERCOUNTED:
3339 label = "over";
3340 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003341 case CAMERA:
3342 label = "camera";
3343 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003344 default:
3345 label = "???";
3346 }
3347 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003348 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3349 bs.shouldHide ? 1 : 0,
3350 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3351 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003352 }
3353 }
3354
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003355 final long[] cpuFreqs = getCpuFreqs();
3356 if (cpuFreqs != null) {
3357 sb.setLength(0);
3358 for (int i = 0; i < cpuFreqs.length; ++i) {
3359 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3360 }
3361 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3362 }
3363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 for (int iu = 0; iu < NU; iu++) {
3365 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003366 if (reqUid >= 0 && uid != reqUid) {
3367 continue;
3368 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003369 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003372 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3373 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3374 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3375 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3376 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3377 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3378 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3379 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003380 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003381 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3382 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003383 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003384 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3385 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003386 // Background data transfers
3387 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3388 which);
3389 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3390 which);
3391 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3392 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3393 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3394 which);
3395 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3396 which);
3397 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3398 which);
3399 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3400 which);
3401
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003402 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3403 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003404 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003405 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3406 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3407 || wifiBytesBgTx > 0
3408 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3409 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003410 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3411 wifiBytesRx, wifiBytesTx,
3412 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003413 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003414 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003415 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3416 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3417 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3418 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003419 }
3420
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003421 // Dump modem controller data, per UID.
3422 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3423 u.getModemControllerActivity(), which);
3424
3425 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003426 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3427 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3428 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003429 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3430 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003431 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3432 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3433 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003434 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003435 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003436 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3437 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003438 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3439 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003440 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003441 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003444 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3445 u.getWifiControllerActivity(), which);
3446
Bookatz867c0d72017-03-07 18:23:42 -08003447 final Timer bleTimer = u.getBluetoothScanTimer();
3448 if (bleTimer != null) {
3449 // Convert from microseconds to milliseconds with rounding
3450 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3451 / 1000;
3452 if (totalTime != 0) {
3453 final int count = bleTimer.getCountLocked(which);
3454 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3455 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003456 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3457 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3458 final long actualTimeBg = bleTimerBg != null ?
3459 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003460 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003461 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3462 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003463 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3464 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3465 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3466 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3467 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3468 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3469 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3470 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3471 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3472 final Timer unoptimizedScanTimerBg =
3473 u.getBluetoothUnoptimizedScanBackgroundTimer();
3474 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3475 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3476 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3477 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3478
Bookatz867c0d72017-03-07 18:23:42 -08003479 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003480 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3481 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3482 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003483 }
3484 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003485
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003486 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3487 u.getBluetoothControllerActivity(), which);
3488
Dianne Hackborn617f8772009-03-31 15:04:46 -07003489 if (u.hasUserActivity()) {
3490 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3491 boolean hasData = false;
3492 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3493 int val = u.getUserActivityCount(i, which);
3494 args[i] = val;
3495 if (val != 0) hasData = true;
3496 }
3497 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003498 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003499 }
3500 }
Bookatzc8c44962017-05-11 12:12:54 -07003501
3502 if (u.getAggregatedPartialWakelockTimer() != null) {
3503 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003504 // Times are since reset (regardless of 'which')
3505 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003506 final Timer bgTimer = timer.getSubTimer();
3507 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003508 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003509 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3510 }
3511
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003512 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3513 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3514 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3515 String linePrefix = "";
3516 sb.setLength(0);
3517 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3518 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003519 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3520 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003521 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003522 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3523 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003524 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3525 rawRealtime, "w", which, linePrefix);
3526
3527 // Only log if we had at lease one wakelock...
3528 if (sb.length() > 0) {
3529 String name = wakelocks.keyAt(iw);
3530 if (name.indexOf(',') >= 0) {
3531 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003533 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 }
3535 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003536
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003537 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3538 for (int isy=syncs.size()-1; isy>=0; isy--) {
3539 final Timer timer = syncs.valueAt(isy);
3540 // Convert from microseconds to milliseconds with rounding
3541 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3542 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003543 final Timer bgTimer = timer.getSubTimer();
3544 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003545 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003546 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003547 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003548 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003549 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003550 }
3551 }
3552
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003553 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3554 for (int ij=jobs.size()-1; ij>=0; ij--) {
3555 final Timer timer = jobs.valueAt(ij);
3556 // Convert from microseconds to milliseconds with rounding
3557 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3558 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003559 final Timer bgTimer = timer.getSubTimer();
3560 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003561 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003562 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003563 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003564 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003565 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003566 }
3567 }
3568
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003569 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3570 for (int ic=completions.size()-1; ic>=0; ic--) {
3571 SparseIntArray types = completions.valueAt(ic);
3572 if (types != null) {
3573 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3574 "\"" + completions.keyAt(ic) + "\"",
3575 types.get(JobParameters.REASON_CANCELED, 0),
3576 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3577 types.get(JobParameters.REASON_PREEMPT, 0),
3578 types.get(JobParameters.REASON_TIMEOUT, 0),
3579 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3580 }
3581 }
3582
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003583 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3584 rawRealtime, which);
3585 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3586 rawRealtime, which);
3587 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3588 rawRealtime, which);
3589 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3590 rawRealtime, which);
3591
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003592 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3593 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003594 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003595 final Uid.Sensor se = sensors.valueAt(ise);
3596 final int sensorNumber = sensors.keyAt(ise);
3597 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003598 if (timer != null) {
3599 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003600 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3601 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003602 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003603 final int count = timer.getCountLocked(which);
3604 final Timer bgTimer = se.getSensorBackgroundTime();
3605 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003606 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3607 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3608 final long bgActualTime = bgTimer != null ?
3609 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3610 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3611 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 }
3614 }
3615
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003616 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3617 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003618
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003619 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3620 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003621
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003622 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003623 long totalStateTime = 0;
3624 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003625 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3626 totalStateTime += time;
3627 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003628 }
3629 if (totalStateTime > 0) {
3630 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3631 }
3632
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003633 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3634 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003635 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003636 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003637 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003638 }
3639
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003640 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3641 // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
3642 if (cpuFreqTimeMs != null) {
3643 sb.setLength(0);
3644 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3645 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
3646 }
3647 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3648 if (screenOffCpuFreqTimeMs != null) {
3649 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3650 sb.append("," + screenOffCpuFreqTimeMs[i]);
3651 }
3652 } else {
3653 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3654 sb.append(",0");
3655 }
3656 }
3657 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3658 cpuFreqTimeMs.length, sb.toString());
3659 }
3660
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003661 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3662 = u.getProcessStats();
3663 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3664 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003665
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003666 final long userMillis = ps.getUserTime(which);
3667 final long systemMillis = ps.getSystemTime(which);
3668 final long foregroundMillis = ps.getForegroundTime(which);
3669 final int starts = ps.getStarts(which);
3670 final int numCrashes = ps.getNumCrashes(which);
3671 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003672
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003673 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3674 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003675 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3676 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 }
3678 }
3679
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003680 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3681 = u.getPackageStats();
3682 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3683 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3684 int wakeups = 0;
3685 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3686 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003687 int count = alarms.valueAt(iwa).getCountLocked(which);
3688 wakeups += count;
3689 String name = alarms.keyAt(iwa).replace(',', '_');
3690 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003691 }
3692 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3693 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3694 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3695 final long startTime = ss.getStartTime(batteryUptime, which);
3696 final int starts = ss.getStarts(which);
3697 final int launches = ss.getLaunches(which);
3698 if (startTime != 0 || starts != 0 || launches != 0) {
3699 dumpLine(pw, uid, category, APK_DATA,
3700 wakeups, // wakeup alarms
3701 packageStats.keyAt(ipkg), // Apk
3702 serviceStats.keyAt(isvc), // service
3703 startTime / 1000, // time spent started, in ms
3704 starts,
3705 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 }
3707 }
3708 }
3709 }
3710 }
3711
Dianne Hackborn81038902012-11-26 17:04:09 -08003712 static final class TimerEntry {
3713 final String mName;
3714 final int mId;
3715 final BatteryStats.Timer mTimer;
3716 final long mTime;
3717 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3718 mName = name;
3719 mId = id;
3720 mTimer = timer;
3721 mTime = time;
3722 }
3723 }
3724
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003725 private void printmAh(PrintWriter printer, double power) {
3726 printer.print(BatteryStatsHelper.makemAh(power));
3727 }
3728
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003729 private void printmAh(StringBuilder sb, double power) {
3730 sb.append(BatteryStatsHelper.makemAh(power));
3731 }
3732
Dianne Hackbornd953c532014-08-16 18:17:38 -07003733 /**
3734 * Temporary for settings.
3735 */
3736 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3737 int reqUid) {
3738 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3739 }
3740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003742 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003743 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3745 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003746 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748
3749 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3750 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3751 final long totalRealtime = computeRealtime(rawRealtime, which);
3752 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003753 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3754 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3755 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003756 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3757 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003758
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003759 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003760
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003761 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003762 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003764 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3765 if (estimatedBatteryCapacity > 0) {
3766 sb.setLength(0);
3767 sb.append(prefix);
3768 sb.append(" Estimated battery capacity: ");
3769 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3770 sb.append(" mAh");
3771 pw.println(sb.toString());
3772 }
3773
Jocelyn Dangc627d102017-04-14 13:15:14 -07003774 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3775 if (minLearnedBatteryCapacity > 0) {
3776 sb.setLength(0);
3777 sb.append(prefix);
3778 sb.append(" Min learned battery capacity: ");
3779 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3780 sb.append(" mAh");
3781 pw.println(sb.toString());
3782 }
3783 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3784 if (maxLearnedBatteryCapacity > 0) {
3785 sb.setLength(0);
3786 sb.append(prefix);
3787 sb.append(" Max learned battery capacity: ");
3788 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3789 sb.append(" mAh");
3790 pw.println(sb.toString());
3791 }
3792
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003793 sb.setLength(0);
3794 sb.append(prefix);
3795 sb.append(" Time on battery: ");
3796 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3797 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3798 sb.append(") realtime, ");
3799 formatTimeMs(sb, whichBatteryUptime / 1000);
3800 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3801 sb.append(") uptime");
3802 pw.println(sb.toString());
3803 sb.setLength(0);
3804 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003805 sb.append(" Time on battery screen off: ");
3806 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3807 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3808 sb.append(") realtime, ");
3809 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3810 sb.append("(");
3811 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3812 sb.append(") uptime");
3813 pw.println(sb.toString());
3814 sb.setLength(0);
3815 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003816 sb.append(" Total run time: ");
3817 formatTimeMs(sb, totalRealtime / 1000);
3818 sb.append("realtime, ");
3819 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003820 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003821 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003822 if (batteryTimeRemaining >= 0) {
3823 sb.setLength(0);
3824 sb.append(prefix);
3825 sb.append(" Battery time remaining: ");
3826 formatTimeMs(sb, batteryTimeRemaining / 1000);
3827 pw.println(sb.toString());
3828 }
3829 if (chargeTimeRemaining >= 0) {
3830 sb.setLength(0);
3831 sb.append(prefix);
3832 sb.append(" Charge time remaining: ");
3833 formatTimeMs(sb, chargeTimeRemaining / 1000);
3834 pw.println(sb.toString());
3835 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003836
3837 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3838 final long dischargeCount = dischargeCounter.getCountLocked(which);
3839 if (dischargeCount >= 0) {
3840 sb.setLength(0);
3841 sb.append(prefix);
3842 sb.append(" Discharge: ");
3843 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3844 sb.append(" mAh");
3845 pw.println(sb.toString());
3846 }
3847
3848 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3849 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3850 if (dischargeScreenOffCount >= 0) {
3851 sb.setLength(0);
3852 sb.append(prefix);
3853 sb.append(" Screen off discharge: ");
3854 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3855 sb.append(" mAh");
3856 pw.println(sb.toString());
3857 }
3858
3859 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3860 if (dischargeScreenOnCount >= 0) {
3861 sb.setLength(0);
3862 sb.append(prefix);
3863 sb.append(" Screen on discharge: ");
3864 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3865 sb.append(" mAh");
3866 pw.println(sb.toString());
3867 }
3868
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003869 pw.print(" Start clock time: ");
3870 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3871
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003872 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003873 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003874 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003875 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3876 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003877 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003878 rawRealtime, which);
3879 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3880 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003881 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003882 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003883 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3884 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3885 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003886 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003887 sb.append(prefix);
3888 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3889 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003890 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003891 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3892 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003893 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003894 pw.println(sb.toString());
3895 sb.setLength(0);
3896 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003897 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003898 boolean didOne = false;
3899 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003900 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003901 if (time == 0) {
3902 continue;
3903 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003904 sb.append("\n ");
3905 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003906 didOne = true;
3907 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3908 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003909 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003910 sb.append("(");
3911 sb.append(formatRatioLocked(time, screenOnTime));
3912 sb.append(")");
3913 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003914 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003915 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003916 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003917 sb.setLength(0);
3918 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003919 sb.append(" Power save mode enabled: ");
3920 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003921 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003922 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003923 sb.append(")");
3924 pw.println(sb.toString());
3925 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003926 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003927 sb.setLength(0);
3928 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003929 sb.append(" Device light idling: ");
3930 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003931 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003932 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3933 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003934 sb.append("x");
3935 pw.println(sb.toString());
3936 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003937 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003938 sb.setLength(0);
3939 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003940 sb.append(" Idle mode light time: ");
3941 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003942 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003943 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3944 sb.append(") ");
3945 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003946 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003947 sb.append(" -- longest ");
3948 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3949 pw.println(sb.toString());
3950 }
3951 if (deviceIdlingTime != 0) {
3952 sb.setLength(0);
3953 sb.append(prefix);
3954 sb.append(" Device full idling: ");
3955 formatTimeMs(sb, deviceIdlingTime / 1000);
3956 sb.append("(");
3957 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003958 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003959 sb.append("x");
3960 pw.println(sb.toString());
3961 }
3962 if (deviceIdleModeFullTime != 0) {
3963 sb.setLength(0);
3964 sb.append(prefix);
3965 sb.append(" Idle mode full time: ");
3966 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3967 sb.append("(");
3968 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3969 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003970 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003971 sb.append("x");
3972 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003973 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003974 pw.println(sb.toString());
3975 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003976 if (phoneOnTime != 0) {
3977 sb.setLength(0);
3978 sb.append(prefix);
3979 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3980 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003981 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003982 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003983 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003984 if (connChanges != 0) {
3985 pw.print(prefix);
3986 pw.print(" Connectivity changes: "); pw.println(connChanges);
3987 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003988
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003989 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003990 long fullWakeLockTimeTotalMicros = 0;
3991 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003992
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003993 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003994
Evan Millar22ac0432009-03-31 11:33:18 -07003995 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003996 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003997
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003998 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3999 = u.getWakelockStats();
4000 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4001 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004002
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004003 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4004 if (fullWakeTimer != null) {
4005 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4006 rawRealtime, which);
4007 }
4008
4009 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4010 if (partialWakeTimer != null) {
4011 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4012 rawRealtime, which);
4013 if (totalTimeMicros > 0) {
4014 if (reqUid < 0) {
4015 // Only show the ordered list of all wake
4016 // locks if the caller is not asking for data
4017 // about a specific uid.
4018 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4019 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004020 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004021 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004022 }
4023 }
4024 }
4025 }
Bookatzc8c44962017-05-11 12:12:54 -07004026
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004027 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4028 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4029 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4030 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4031 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4032 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4033 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4034 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004035 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4036 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004037
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004038 if (fullWakeLockTimeTotalMicros != 0) {
4039 sb.setLength(0);
4040 sb.append(prefix);
4041 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4042 (fullWakeLockTimeTotalMicros + 500) / 1000);
4043 pw.println(sb.toString());
4044 }
4045
4046 if (partialWakeLockTimeTotalMicros != 0) {
4047 sb.setLength(0);
4048 sb.append(prefix);
4049 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4050 (partialWakeLockTimeTotalMicros + 500) / 1000);
4051 pw.println(sb.toString());
4052 }
4053
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004054 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004055 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4056 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4057 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4058 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004059 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004060 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004061 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004062 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004063 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004064 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004065 if (time == 0) {
4066 continue;
4067 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004068 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004069 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004070 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004071 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004072 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004073 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004074 sb.append("(");
4075 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004076 sb.append(") ");
4077 sb.append(getPhoneSignalStrengthCount(i, which));
4078 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004079 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004080 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004081 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004082
4083 sb.setLength(0);
4084 sb.append(prefix);
4085 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004086 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004087 pw.println(sb.toString());
4088
Dianne Hackborn627bba72009-03-24 22:32:56 -07004089 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004090 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004091 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004092 didOne = false;
4093 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004094 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004095 if (time == 0) {
4096 continue;
4097 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004098 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004099 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004100 didOne = true;
4101 sb.append(DATA_CONNECTION_NAMES[i]);
4102 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004103 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004104 sb.append("(");
4105 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004106 sb.append(") ");
4107 sb.append(getPhoneDataConnectionCount(i, which));
4108 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004109 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004110 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004111 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004112
4113 sb.setLength(0);
4114 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004115 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004116 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004117 formatTimeMs(sb, mobileActiveTime / 1000);
4118 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4119 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4120 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004121 pw.println(sb.toString());
4122
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004123 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4124 if (mobileActiveUnknownTime != 0) {
4125 sb.setLength(0);
4126 sb.append(prefix);
4127 sb.append(" Mobile radio active unknown time: ");
4128 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4129 sb.append("(");
4130 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4131 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4132 sb.append("x");
4133 pw.println(sb.toString());
4134 }
4135
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004136 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4137 if (mobileActiveAdjustedTime != 0) {
4138 sb.setLength(0);
4139 sb.append(prefix);
4140 sb.append(" Mobile radio active adjusted time: ");
4141 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4142 sb.append("(");
4143 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4144 sb.append(")");
4145 pw.println(sb.toString());
4146 }
4147
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004148 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4149
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004150 pw.print(prefix);
4151 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4152 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4153 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4154 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004155 sb.setLength(0);
4156 sb.append(prefix);
4157 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4158 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4159 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4160 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004161 sb.append(")");
4162 pw.println(sb.toString());
4163
4164 sb.setLength(0);
4165 sb.append(prefix);
4166 sb.append(" Wifi states:");
4167 didOne = false;
4168 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004169 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004170 if (time == 0) {
4171 continue;
4172 }
4173 sb.append("\n ");
4174 didOne = true;
4175 sb.append(WIFI_STATE_NAMES[i]);
4176 sb.append(" ");
4177 formatTimeMs(sb, time/1000);
4178 sb.append("(");
4179 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4180 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004181 sb.append(getWifiStateCount(i, which));
4182 sb.append("x");
4183 }
4184 if (!didOne) sb.append(" (no activity)");
4185 pw.println(sb.toString());
4186
4187 sb.setLength(0);
4188 sb.append(prefix);
4189 sb.append(" Wifi supplicant states:");
4190 didOne = false;
4191 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4192 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4193 if (time == 0) {
4194 continue;
4195 }
4196 sb.append("\n ");
4197 didOne = true;
4198 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4199 sb.append(" ");
4200 formatTimeMs(sb, time/1000);
4201 sb.append("(");
4202 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4203 sb.append(") ");
4204 sb.append(getWifiSupplStateCount(i, which));
4205 sb.append("x");
4206 }
4207 if (!didOne) sb.append(" (no activity)");
4208 pw.println(sb.toString());
4209
4210 sb.setLength(0);
4211 sb.append(prefix);
4212 sb.append(" Wifi signal levels:");
4213 didOne = false;
4214 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4215 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4216 if (time == 0) {
4217 continue;
4218 }
4219 sb.append("\n ");
4220 sb.append(prefix);
4221 didOne = true;
4222 sb.append("level(");
4223 sb.append(i);
4224 sb.append(") ");
4225 formatTimeMs(sb, time/1000);
4226 sb.append("(");
4227 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4228 sb.append(") ");
4229 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004230 sb.append("x");
4231 }
4232 if (!didOne) sb.append(" (no activity)");
4233 pw.println(sb.toString());
4234
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004235 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004236
Adam Lesinski50e47602015-12-04 17:04:54 -08004237 pw.print(prefix);
4238 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4239 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4240
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004241 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4242 sb.setLength(0);
4243 sb.append(prefix);
4244 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4245 pw.println(sb.toString());
4246
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004247 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4248 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004249
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004250 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004251
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004252 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004253 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004254 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004255 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004256 pw.println(getDischargeStartLevel());
4257 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4258 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004259 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004260 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004261 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004262 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004263 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004264 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004265 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004266 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4267 pw.println(getDischargeAmountScreenOn());
4268 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4269 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004270 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004271 } else {
4272 pw.print(prefix); pw.println(" Device battery use since last full charge");
4273 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4274 pw.println(getLowDischargeAmountSinceCharge());
4275 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4276 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004277 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4278 pw.println(getDischargeAmountScreenOnSinceCharge());
4279 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4280 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004281 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004282 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004283
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004284 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004285 helper.create(this);
4286 helper.refreshStats(which, UserHandle.USER_ALL);
4287 List<BatterySipper> sippers = helper.getUsageList();
4288 if (sippers != null && sippers.size() > 0) {
4289 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4290 pw.print(prefix); pw.print(" Capacity: ");
4291 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004292 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004293 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4294 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4295 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4296 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004297 pw.println();
4298 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004299 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004300 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004301 switch (bs.drainType) {
4302 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004303 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004304 break;
4305 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004306 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004307 break;
4308 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004309 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004310 break;
4311 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004312 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004313 break;
4314 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004315 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004316 break;
4317 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004318 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004319 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004320 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004321 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004322 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004323 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004324 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004325 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004326 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004327 break;
4328 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004329 pw.print(" User "); pw.print(bs.userId);
4330 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004331 break;
4332 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004333 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004334 break;
4335 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004336 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004337 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004338 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004339 pw.print(" Camera: ");
4340 break;
4341 default:
4342 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004343 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004344 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004345 printmAh(pw, bs.totalPowerMah);
4346
Adam Lesinski57123002015-06-12 16:12:07 -07004347 if (bs.usagePowerMah != bs.totalPowerMah) {
4348 // If the usage (generic power) isn't the whole amount, we list out
4349 // what components are involved in the calculation.
4350
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004351 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004352 if (bs.usagePowerMah != 0) {
4353 pw.print(" usage=");
4354 printmAh(pw, bs.usagePowerMah);
4355 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004356 if (bs.cpuPowerMah != 0) {
4357 pw.print(" cpu=");
4358 printmAh(pw, bs.cpuPowerMah);
4359 }
4360 if (bs.wakeLockPowerMah != 0) {
4361 pw.print(" wake=");
4362 printmAh(pw, bs.wakeLockPowerMah);
4363 }
4364 if (bs.mobileRadioPowerMah != 0) {
4365 pw.print(" radio=");
4366 printmAh(pw, bs.mobileRadioPowerMah);
4367 }
4368 if (bs.wifiPowerMah != 0) {
4369 pw.print(" wifi=");
4370 printmAh(pw, bs.wifiPowerMah);
4371 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004372 if (bs.bluetoothPowerMah != 0) {
4373 pw.print(" bt=");
4374 printmAh(pw, bs.bluetoothPowerMah);
4375 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004376 if (bs.gpsPowerMah != 0) {
4377 pw.print(" gps=");
4378 printmAh(pw, bs.gpsPowerMah);
4379 }
4380 if (bs.sensorPowerMah != 0) {
4381 pw.print(" sensor=");
4382 printmAh(pw, bs.sensorPowerMah);
4383 }
4384 if (bs.cameraPowerMah != 0) {
4385 pw.print(" camera=");
4386 printmAh(pw, bs.cameraPowerMah);
4387 }
4388 if (bs.flashlightPowerMah != 0) {
4389 pw.print(" flash=");
4390 printmAh(pw, bs.flashlightPowerMah);
4391 }
4392 pw.print(" )");
4393 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004394
4395 // If there is additional smearing information, include it.
4396 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4397 pw.print(" Including smearing: ");
4398 printmAh(pw, bs.totalSmearedPowerMah);
4399 pw.print(" (");
4400 if (bs.screenPowerMah != 0) {
4401 pw.print(" screen=");
4402 printmAh(pw, bs.screenPowerMah);
4403 }
4404 if (bs.proportionalSmearMah != 0) {
4405 pw.print(" proportional=");
4406 printmAh(pw, bs.proportionalSmearMah);
4407 }
4408 pw.print(" )");
4409 }
4410 if (bs.shouldHide) {
4411 pw.print(" Excluded from smearing");
4412 }
4413
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004414 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004415 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004416 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004417 }
4418
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004419 sippers = helper.getMobilemsppList();
4420 if (sippers != null && sippers.size() > 0) {
4421 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004422 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004423 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004424 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004425 sb.setLength(0);
4426 sb.append(prefix); sb.append(" Uid ");
4427 UserHandle.formatUid(sb, bs.uidObj.getUid());
4428 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4429 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4430 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004431 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004432 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004433 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004434 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004435 sb.setLength(0);
4436 sb.append(prefix);
4437 sb.append(" TOTAL TIME: ");
4438 formatTimeMs(sb, totalTime);
4439 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4440 sb.append(")");
4441 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004442 pw.println();
4443 }
4444
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004445 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4446 @Override
4447 public int compare(TimerEntry lhs, TimerEntry rhs) {
4448 long lhsTime = lhs.mTime;
4449 long rhsTime = rhs.mTime;
4450 if (lhsTime < rhsTime) {
4451 return 1;
4452 }
4453 if (lhsTime > rhsTime) {
4454 return -1;
4455 }
4456 return 0;
4457 }
4458 };
4459
4460 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004461 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4462 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004463 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004464 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4465 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4466 : kernelWakelocks.entrySet()) {
4467 final BatteryStats.Timer timer = ent.getValue();
4468 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004469 if (totalTimeMillis > 0) {
4470 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4471 }
4472 }
4473 if (ktimers.size() > 0) {
4474 Collections.sort(ktimers, timerComparator);
4475 pw.print(prefix); pw.println(" All kernel wake locks:");
4476 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004477 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004478 String linePrefix = ": ";
4479 sb.setLength(0);
4480 sb.append(prefix);
4481 sb.append(" Kernel Wake lock ");
4482 sb.append(timer.mName);
4483 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4484 which, linePrefix);
4485 if (!linePrefix.equals(": ")) {
4486 sb.append(" realtime");
4487 // Only print out wake locks that were held
4488 pw.println(sb.toString());
4489 }
4490 }
4491 pw.println();
4492 }
4493 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004494
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004495 if (timers.size() > 0) {
4496 Collections.sort(timers, timerComparator);
4497 pw.print(prefix); pw.println(" All partial wake locks:");
4498 for (int i=0; i<timers.size(); i++) {
4499 TimerEntry timer = timers.get(i);
4500 sb.setLength(0);
4501 sb.append(" Wake lock ");
4502 UserHandle.formatUid(sb, timer.mId);
4503 sb.append(" ");
4504 sb.append(timer.mName);
4505 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4506 sb.append(" realtime");
4507 pw.println(sb.toString());
4508 }
4509 timers.clear();
4510 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004511 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004512
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004513 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004514 if (wakeupReasons.size() > 0) {
4515 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004516 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004517 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004518 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004519 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4520 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004521 }
4522 Collections.sort(reasons, timerComparator);
4523 for (int i=0; i<reasons.size(); i++) {
4524 TimerEntry timer = reasons.get(i);
4525 String linePrefix = ": ";
4526 sb.setLength(0);
4527 sb.append(prefix);
4528 sb.append(" Wakeup reason ");
4529 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004530 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4531 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004532 pw.println(sb.toString());
4533 }
4534 pw.println();
4535 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004536 }
Evan Millar22ac0432009-03-31 11:33:18 -07004537
James Carr2dd7e5e2016-07-20 18:48:39 -07004538 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4539 pw.println("Memory Stats");
4540 for (int i = 0; i < mMemoryStats.size(); i++) {
4541 sb.setLength(0);
4542 sb.append("Bandwidth ");
4543 sb.append(mMemoryStats.keyAt(i));
4544 sb.append(" Time ");
4545 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4546 pw.println(sb.toString());
4547 }
4548
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004549 final long[] cpuFreqs = getCpuFreqs();
4550 if (cpuFreqs != null) {
4551 sb.setLength(0);
4552 sb.append("CPU freqs:");
4553 for (int i = 0; i < cpuFreqs.length; ++i) {
4554 sb.append(" " + cpuFreqs[i]);
4555 }
4556 pw.println(sb.toString());
4557 }
4558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004559 for (int iu=0; iu<NU; iu++) {
4560 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004561 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004562 continue;
4563 }
Bookatzc8c44962017-05-11 12:12:54 -07004564
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004565 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004566
4567 pw.print(prefix);
4568 pw.print(" ");
4569 UserHandle.formatUid(pw, uid);
4570 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004572
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004573 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4574 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4575 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4576 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004577 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4578 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4579
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004580 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4581 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004582 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4583 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004584
4585 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4586 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4587
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004588 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4589 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4590 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004591 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4592 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4593 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4594 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004595 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004596
Adam Lesinski5f056f62016-07-14 16:56:08 -07004597 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4598 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4599
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004600 if (mobileRxBytes > 0 || mobileTxBytes > 0
4601 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004602 pw.print(prefix); pw.print(" Mobile network: ");
4603 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004604 pw.print(formatBytesLocked(mobileTxBytes));
4605 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4606 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004608 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4609 sb.setLength(0);
4610 sb.append(prefix); sb.append(" Mobile radio active: ");
4611 formatTimeMs(sb, uidMobileActiveTime / 1000);
4612 sb.append("(");
4613 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4614 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4615 long packets = mobileRxPackets + mobileTxPackets;
4616 if (packets == 0) {
4617 packets = 1;
4618 }
4619 sb.append(" @ ");
4620 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4621 sb.append(" mspp");
4622 pw.println(sb.toString());
4623 }
4624
Adam Lesinski5f056f62016-07-14 16:56:08 -07004625 if (mobileWakeup > 0) {
4626 sb.setLength(0);
4627 sb.append(prefix);
4628 sb.append(" Mobile radio AP wakeups: ");
4629 sb.append(mobileWakeup);
4630 pw.println(sb.toString());
4631 }
4632
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004633 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4634 u.getModemControllerActivity(), which);
4635
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004636 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004637 pw.print(prefix); pw.print(" Wi-Fi network: ");
4638 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004639 pw.print(formatBytesLocked(wifiTxBytes));
4640 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4641 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004642 }
4643
Dianne Hackborn62793e42015-03-09 11:15:41 -07004644 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004645 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004646 || uidWifiRunningTime != 0) {
4647 sb.setLength(0);
4648 sb.append(prefix); sb.append(" Wifi Running: ");
4649 formatTimeMs(sb, uidWifiRunningTime / 1000);
4650 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4651 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004652 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004653 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4654 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4655 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004656 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004657 formatTimeMs(sb, wifiScanTime / 1000);
4658 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004659 whichBatteryRealtime)); sb.append(") ");
4660 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004661 sb.append("x\n");
4662 // actual and background times are unpooled and since reset (regardless of 'which')
4663 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4664 formatTimeMs(sb, wifiScanActualTime / 1000);
4665 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4666 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4667 sb.append(") ");
4668 sb.append(wifiScanCount);
4669 sb.append("x\n");
4670 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4671 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4672 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4673 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4674 sb.append(") ");
4675 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004676 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004677 pw.println(sb.toString());
4678 }
4679
Adam Lesinski5f056f62016-07-14 16:56:08 -07004680 if (wifiWakeup > 0) {
4681 sb.setLength(0);
4682 sb.append(prefix);
4683 sb.append(" WiFi AP wakeups: ");
4684 sb.append(wifiWakeup);
4685 pw.println(sb.toString());
4686 }
4687
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004688 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4689 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004690
Adam Lesinski50e47602015-12-04 17:04:54 -08004691 if (btRxBytes > 0 || btTxBytes > 0) {
4692 pw.print(prefix); pw.print(" Bluetooth network: ");
4693 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4694 pw.print(formatBytesLocked(btTxBytes));
4695 pw.println(" sent");
4696 }
4697
Bookatz867c0d72017-03-07 18:23:42 -08004698 final Timer bleTimer = u.getBluetoothScanTimer();
4699 if (bleTimer != null) {
4700 // Convert from microseconds to milliseconds with rounding
4701 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4702 / 1000;
4703 if (totalTimeMs != 0) {
4704 final int count = bleTimer.getCountLocked(which);
4705 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4706 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004707 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4708 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4709 final long actualTimeMsBg = bleTimerBg != null ?
4710 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004711 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004712 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4713 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004714 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4715 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4716 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4717 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
4718 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
4719 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4720 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
4721 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
4722 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
4723 final Timer unoptimizedScanTimerBg =
4724 u.getBluetoothUnoptimizedScanBackgroundTimer();
4725 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
4726 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4727 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
4728 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004729
4730 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08004731 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07004732 sb.append(prefix);
4733 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08004734 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07004735 sb.append(" (");
4736 sb.append(count);
4737 sb.append(" times)");
4738 if (bleTimer.isRunningLocked()) {
4739 sb.append(" (currently running)");
4740 }
4741 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004742 }
Bookatzb1f04f32017-05-19 13:57:32 -07004743
4744 sb.append(prefix);
4745 sb.append(" Bluetooth Scan (total actual realtime): ");
4746 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
4747 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004748 sb.append(count);
4749 sb.append(" times)");
4750 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07004751 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08004752 }
Bookatzb1f04f32017-05-19 13:57:32 -07004753 sb.append("\n");
4754 if (actualTimeMsBg > 0 || countBg > 0) {
4755 sb.append(prefix);
4756 sb.append(" Bluetooth Scan (background realtime): ");
4757 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
4758 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004759 sb.append(countBg);
4760 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07004761 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
4762 sb.append(" (currently running in background)");
4763 }
4764 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004765 }
Bookatzb1f04f32017-05-19 13:57:32 -07004766
4767 sb.append(prefix);
4768 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07004769 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07004770 sb.append(" (");
4771 sb.append(resultCountBg);
4772 sb.append(" in background)");
4773
4774 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
4775 sb.append("\n");
4776 sb.append(prefix);
4777 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
4778 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
4779 sb.append(" (max ");
4780 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
4781 sb.append(")");
4782 if (unoptimizedScanTimer != null
4783 && unoptimizedScanTimer.isRunningLocked()) {
4784 sb.append(" (currently running unoptimized)");
4785 }
4786 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
4787 sb.append("\n");
4788 sb.append(prefix);
4789 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
4790 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
4791 sb.append(" (max ");
4792 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
4793 sb.append(")");
4794 if (unoptimizedScanTimerBg.isRunningLocked()) {
4795 sb.append(" (currently running unoptimized in background)");
4796 }
4797 }
4798 }
Bookatz867c0d72017-03-07 18:23:42 -08004799 pw.println(sb.toString());
4800 uidActivity = true;
4801 }
4802 }
4803
4804
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004805
Dianne Hackborn617f8772009-03-31 15:04:46 -07004806 if (u.hasUserActivity()) {
4807 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004808 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004809 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004810 if (val != 0) {
4811 if (!hasData) {
4812 sb.setLength(0);
4813 sb.append(" User activity: ");
4814 hasData = true;
4815 } else {
4816 sb.append(", ");
4817 }
4818 sb.append(val);
4819 sb.append(" ");
4820 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4821 }
4822 }
4823 if (hasData) {
4824 pw.println(sb.toString());
4825 }
4826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004828 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4829 = u.getWakelockStats();
4830 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004831 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004832 int countWakelock = 0;
4833 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4834 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4835 String linePrefix = ": ";
4836 sb.setLength(0);
4837 sb.append(prefix);
4838 sb.append(" Wake lock ");
4839 sb.append(wakelocks.keyAt(iw));
4840 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4841 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004842 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4843 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004844 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004845 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
4846 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004847 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4848 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004849 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4850 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004851 sb.append(" realtime");
4852 pw.println(sb.toString());
4853 uidActivity = true;
4854 countWakelock++;
4855
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004856 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4857 rawRealtime, which);
4858 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4859 rawRealtime, which);
4860 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4861 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004862 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004863 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004864 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004865 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004866 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4867 // pooled and therefore just a lower bound)
4868 long actualTotalPartialWakelock = 0;
4869 long actualBgPartialWakelock = 0;
4870 if (u.getAggregatedPartialWakelockTimer() != null) {
4871 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4872 // Convert from microseconds to milliseconds with rounding
4873 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07004874 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07004875 final Timer bgAggTimer = aggTimer.getSubTimer();
4876 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004877 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07004878 }
4879
4880 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4881 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4882 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004883 sb.setLength(0);
4884 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004885 sb.append(" TOTAL wake: ");
4886 boolean needComma = false;
4887 if (totalFullWakelock != 0) {
4888 needComma = true;
4889 formatTimeMs(sb, totalFullWakelock);
4890 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004891 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004892 if (totalPartialWakelock != 0) {
4893 if (needComma) {
4894 sb.append(", ");
4895 }
4896 needComma = true;
4897 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004898 sb.append("blamed partial");
4899 }
4900 if (actualTotalPartialWakelock != 0) {
4901 if (needComma) {
4902 sb.append(", ");
4903 }
4904 needComma = true;
4905 formatTimeMs(sb, actualTotalPartialWakelock);
4906 sb.append("actual partial");
4907 }
4908 if (actualBgPartialWakelock != 0) {
4909 if (needComma) {
4910 sb.append(", ");
4911 }
4912 needComma = true;
4913 formatTimeMs(sb, actualBgPartialWakelock);
4914 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004915 }
4916 if (totalWindowWakelock != 0) {
4917 if (needComma) {
4918 sb.append(", ");
4919 }
4920 needComma = true;
4921 formatTimeMs(sb, totalWindowWakelock);
4922 sb.append("window");
4923 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004924 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004925 if (needComma) {
4926 sb.append(",");
4927 }
4928 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004929 formatTimeMs(sb, totalDrawWakelock);
4930 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004931 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004932 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004933 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004934 }
4935 }
4936
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004937 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4938 for (int isy=syncs.size()-1; isy>=0; isy--) {
4939 final Timer timer = syncs.valueAt(isy);
4940 // Convert from microseconds to milliseconds with rounding
4941 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4942 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004943 final Timer bgTimer = timer.getSubTimer();
4944 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004945 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07004946 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004947 sb.setLength(0);
4948 sb.append(prefix);
4949 sb.append(" Sync ");
4950 sb.append(syncs.keyAt(isy));
4951 sb.append(": ");
4952 if (totalTime != 0) {
4953 formatTimeMs(sb, totalTime);
4954 sb.append("realtime (");
4955 sb.append(count);
4956 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004957 if (bgTime > 0) {
4958 sb.append(", ");
4959 formatTimeMs(sb, bgTime);
4960 sb.append("background (");
4961 sb.append(bgCount);
4962 sb.append(" times)");
4963 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004964 } else {
4965 sb.append("(not used)");
4966 }
4967 pw.println(sb.toString());
4968 uidActivity = true;
4969 }
4970
4971 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4972 for (int ij=jobs.size()-1; ij>=0; ij--) {
4973 final Timer timer = jobs.valueAt(ij);
4974 // Convert from microseconds to milliseconds with rounding
4975 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4976 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07004977 final Timer bgTimer = timer.getSubTimer();
4978 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004979 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07004980 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004981 sb.setLength(0);
4982 sb.append(prefix);
4983 sb.append(" Job ");
4984 sb.append(jobs.keyAt(ij));
4985 sb.append(": ");
4986 if (totalTime != 0) {
4987 formatTimeMs(sb, totalTime);
4988 sb.append("realtime (");
4989 sb.append(count);
4990 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07004991 if (bgTime > 0) {
4992 sb.append(", ");
4993 formatTimeMs(sb, bgTime);
4994 sb.append("background (");
4995 sb.append(bgCount);
4996 sb.append(" times)");
4997 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004998 } else {
4999 sb.append("(not used)");
5000 }
5001 pw.println(sb.toString());
5002 uidActivity = true;
5003 }
5004
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005005 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5006 for (int ic=completions.size()-1; ic>=0; ic--) {
5007 SparseIntArray types = completions.valueAt(ic);
5008 if (types != null) {
5009 pw.print(prefix);
5010 pw.print(" Job Completions ");
5011 pw.print(completions.keyAt(ic));
5012 pw.print(":");
5013 for (int it=0; it<types.size(); it++) {
5014 pw.print(" ");
5015 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5016 pw.print("(");
5017 pw.print(types.valueAt(it));
5018 pw.print("x)");
5019 }
5020 pw.println();
5021 }
5022 }
5023
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005024 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5025 prefix, "Flashlight");
5026 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5027 prefix, "Camera");
5028 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5029 prefix, "Video");
5030 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5031 prefix, "Audio");
5032
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005033 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5034 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005035 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005036 final Uid.Sensor se = sensors.valueAt(ise);
5037 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005038 sb.setLength(0);
5039 sb.append(prefix);
5040 sb.append(" Sensor ");
5041 int handle = se.getHandle();
5042 if (handle == Uid.Sensor.GPS) {
5043 sb.append("GPS");
5044 } else {
5045 sb.append(handle);
5046 }
5047 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005049 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005050 if (timer != null) {
5051 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005052 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5053 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005054 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005055 final Timer bgTimer = se.getSensorBackgroundTime();
5056 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005057 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5058 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5059 final long bgActualTime = bgTimer != null ?
5060 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5061
Dianne Hackborn61659e52014-07-09 16:13:01 -07005062 //timer.logState();
5063 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005064 if (actualTime != totalTime) {
5065 formatTimeMs(sb, totalTime);
5066 sb.append("blamed realtime, ");
5067 }
5068
5069 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005070 sb.append("realtime (");
5071 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005072 sb.append(" times)");
5073
5074 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005075 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005076 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5077 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005078 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005079 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005081 } else {
5082 sb.append("(not used)");
5083 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005084 } else {
5085 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005086 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005087
5088 pw.println(sb.toString());
5089 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005090 }
5091
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005092 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5093 "Vibrator");
5094 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5095 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005096
Dianne Hackborn61659e52014-07-09 16:13:01 -07005097 long totalStateTime = 0;
5098 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5099 long time = u.getProcessStateTime(ips, rawRealtime, which);
5100 if (time > 0) {
5101 totalStateTime += time;
5102 sb.setLength(0);
5103 sb.append(prefix);
5104 sb.append(" ");
5105 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5106 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005107 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005108 pw.println(sb.toString());
5109 uidActivity = true;
5110 }
5111 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005112 if (totalStateTime > 0) {
5113 sb.setLength(0);
5114 sb.append(prefix);
5115 sb.append(" Total running: ");
5116 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5117 pw.println(sb.toString());
5118 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005119
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005120 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5121 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005122 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005123 sb.setLength(0);
5124 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005125 sb.append(" Total cpu time: u=");
5126 formatTimeMs(sb, userCpuTimeUs / 1000);
5127 sb.append("s=");
5128 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005129 pw.println(sb.toString());
5130 }
5131
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005132 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5133 if (cpuFreqTimes != null) {
5134 sb.setLength(0);
5135 sb.append(" Total cpu time per freq:");
5136 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5137 sb.append(" " + cpuFreqTimes[i]);
5138 }
5139 pw.println(sb.toString());
5140 }
5141 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5142 if (screenOffCpuFreqTimes != null) {
5143 sb.setLength(0);
5144 sb.append(" Total screen-off cpu time per freq:");
5145 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5146 sb.append(" " + screenOffCpuFreqTimes[i]);
5147 }
5148 pw.println(sb.toString());
5149 }
5150
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005151 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5152 = u.getProcessStats();
5153 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5154 final Uid.Proc ps = processStats.valueAt(ipr);
5155 long userTime;
5156 long systemTime;
5157 long foregroundTime;
5158 int starts;
5159 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005160
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005161 userTime = ps.getUserTime(which);
5162 systemTime = ps.getSystemTime(which);
5163 foregroundTime = ps.getForegroundTime(which);
5164 starts = ps.getStarts(which);
5165 final int numCrashes = ps.getNumCrashes(which);
5166 final int numAnrs = ps.getNumAnrs(which);
5167 numExcessive = which == STATS_SINCE_CHARGED
5168 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005170 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5171 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5172 sb.setLength(0);
5173 sb.append(prefix); sb.append(" Proc ");
5174 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5175 sb.append(prefix); sb.append(" CPU: ");
5176 formatTimeMs(sb, userTime); sb.append("usr + ");
5177 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5178 formatTimeMs(sb, foregroundTime); sb.append("fg");
5179 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5180 sb.append("\n"); sb.append(prefix); sb.append(" ");
5181 boolean hasOne = false;
5182 if (starts != 0) {
5183 hasOne = true;
5184 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005185 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005186 if (numCrashes != 0) {
5187 if (hasOne) {
5188 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005189 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005190 hasOne = true;
5191 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005192 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005193 if (numAnrs != 0) {
5194 if (hasOne) {
5195 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005197 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 }
5199 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005200 pw.println(sb.toString());
5201 for (int e=0; e<numExcessive; e++) {
5202 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5203 if (ew != null) {
5204 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005205 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005206 pw.print("cpu");
5207 } else {
5208 pw.print("unknown");
5209 }
5210 pw.print(" use: ");
5211 TimeUtils.formatDuration(ew.usedTime, pw);
5212 pw.print(" over ");
5213 TimeUtils.formatDuration(ew.overTime, pw);
5214 if (ew.overTime != 0) {
5215 pw.print(" (");
5216 pw.print((ew.usedTime*100)/ew.overTime);
5217 pw.println("%)");
5218 }
5219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 }
5221 uidActivity = true;
5222 }
5223 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005224
5225 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5226 = u.getPackageStats();
5227 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5228 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5229 pw.println(":");
5230 boolean apkActivity = false;
5231 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5232 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5233 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5234 pw.print(prefix); pw.print(" Wakeup alarm ");
5235 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5236 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5237 pw.println(" times");
5238 apkActivity = true;
5239 }
5240 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5241 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5242 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5243 final long startTime = ss.getStartTime(batteryUptime, which);
5244 final int starts = ss.getStarts(which);
5245 final int launches = ss.getLaunches(which);
5246 if (startTime != 0 || starts != 0 || launches != 0) {
5247 sb.setLength(0);
5248 sb.append(prefix); sb.append(" Service ");
5249 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5250 sb.append(prefix); sb.append(" Created for: ");
5251 formatTimeMs(sb, startTime / 1000);
5252 sb.append("uptime\n");
5253 sb.append(prefix); sb.append(" Starts: ");
5254 sb.append(starts);
5255 sb.append(", launches: "); sb.append(launches);
5256 pw.println(sb.toString());
5257 apkActivity = true;
5258 }
5259 }
5260 if (!apkActivity) {
5261 pw.print(prefix); pw.println(" (nothing executed)");
5262 }
5263 uidActivity = true;
5264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005265 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005266 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 }
5268 }
5269 }
5270
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005271 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005272 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005273 int diff = oldval ^ newval;
5274 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005275 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005276 for (int i=0; i<descriptions.length; i++) {
5277 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005278 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005279 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005280 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005281 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005282 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005283 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5284 didWake = true;
5285 pw.print("=");
5286 if (longNames) {
5287 UserHandle.formatUid(pw, wakelockTag.uid);
5288 pw.print(":\"");
5289 pw.print(wakelockTag.string);
5290 pw.print("\"");
5291 } else {
5292 pw.print(wakelockTag.poolIdx);
5293 }
5294 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005295 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005296 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005297 pw.print("=");
5298 int val = (newval&bd.mask)>>bd.shift;
5299 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005300 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005301 } else {
5302 pw.print(val);
5303 }
5304 }
5305 }
5306 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005307 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005308 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005309 if (longNames) {
5310 UserHandle.formatUid(pw, wakelockTag.uid);
5311 pw.print(":\"");
5312 pw.print(wakelockTag.string);
5313 pw.print("\"");
5314 } else {
5315 pw.print(wakelockTag.poolIdx);
5316 }
5317 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005318 }
5319
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005320 public void prepareForDumpLocked() {
5321 }
5322
5323 public static class HistoryPrinter {
5324 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005325 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005326 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005327 int oldStatus = -1;
5328 int oldHealth = -1;
5329 int oldPlug = -1;
5330 int oldTemp = -1;
5331 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005332 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005333 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005334
Dianne Hackborn3251b902014-06-20 14:40:53 -07005335 void reset() {
5336 oldState = oldState2 = 0;
5337 oldLevel = -1;
5338 oldStatus = -1;
5339 oldHealth = -1;
5340 oldPlug = -1;
5341 oldTemp = -1;
5342 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005343 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005344 }
5345
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005346 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005347 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005348 if (!checkin) {
5349 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005350 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005351 pw.print(" (");
5352 pw.print(rec.numReadInts);
5353 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005354 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005355 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5356 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005357 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005358 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005359 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005360 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005361 }
5362 lastTime = rec.time;
5363 }
5364 if (rec.cmd == HistoryItem.CMD_START) {
5365 if (checkin) {
5366 pw.print(":");
5367 }
5368 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005369 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005370 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5371 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005372 if (checkin) {
5373 pw.print(":");
5374 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005375 if (rec.cmd == HistoryItem.CMD_RESET) {
5376 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005377 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005378 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005379 pw.print("TIME:");
5380 if (checkin) {
5381 pw.println(rec.currentTime);
5382 } else {
5383 pw.print(" ");
5384 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5385 rec.currentTime).toString());
5386 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005387 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5388 if (checkin) {
5389 pw.print(":");
5390 }
5391 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005392 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5393 if (checkin) {
5394 pw.print(":");
5395 }
5396 pw.println("*OVERFLOW*");
5397 } else {
5398 if (!checkin) {
5399 if (rec.batteryLevel < 10) pw.print("00");
5400 else if (rec.batteryLevel < 100) pw.print("0");
5401 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005402 if (verbose) {
5403 pw.print(" ");
5404 if (rec.states < 0) ;
5405 else if (rec.states < 0x10) pw.print("0000000");
5406 else if (rec.states < 0x100) pw.print("000000");
5407 else if (rec.states < 0x1000) pw.print("00000");
5408 else if (rec.states < 0x10000) pw.print("0000");
5409 else if (rec.states < 0x100000) pw.print("000");
5410 else if (rec.states < 0x1000000) pw.print("00");
5411 else if (rec.states < 0x10000000) pw.print("0");
5412 pw.print(Integer.toHexString(rec.states));
5413 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005414 } else {
5415 if (oldLevel != rec.batteryLevel) {
5416 oldLevel = rec.batteryLevel;
5417 pw.print(",Bl="); pw.print(rec.batteryLevel);
5418 }
5419 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005420 if (oldStatus != rec.batteryStatus) {
5421 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005422 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005423 switch (oldStatus) {
5424 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005425 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005426 break;
5427 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005428 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005429 break;
5430 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005431 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005432 break;
5433 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005434 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005435 break;
5436 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005437 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005438 break;
5439 default:
5440 pw.print(oldStatus);
5441 break;
5442 }
5443 }
5444 if (oldHealth != rec.batteryHealth) {
5445 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005446 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005447 switch (oldHealth) {
5448 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005449 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005450 break;
5451 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005452 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005453 break;
5454 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005455 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005456 break;
5457 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005458 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005459 break;
5460 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005461 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005462 break;
5463 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005464 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005465 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005466 case BatteryManager.BATTERY_HEALTH_COLD:
5467 pw.print(checkin ? "c" : "cold");
5468 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005469 default:
5470 pw.print(oldHealth);
5471 break;
5472 }
5473 }
5474 if (oldPlug != rec.batteryPlugType) {
5475 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005476 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005477 switch (oldPlug) {
5478 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005479 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005480 break;
5481 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005482 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005483 break;
5484 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005485 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005486 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005487 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005488 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005489 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005490 default:
5491 pw.print(oldPlug);
5492 break;
5493 }
5494 }
5495 if (oldTemp != rec.batteryTemperature) {
5496 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005497 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005498 pw.print(oldTemp);
5499 }
5500 if (oldVolt != rec.batteryVoltage) {
5501 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005502 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005503 pw.print(oldVolt);
5504 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005505 final int chargeMAh = rec.batteryChargeUAh / 1000;
5506 if (oldChargeMAh != chargeMAh) {
5507 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005508 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005509 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005510 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005511 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005512 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005513 printBitDescriptions(pw, oldState2, rec.states2, null,
5514 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005515 if (rec.wakeReasonTag != null) {
5516 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005517 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005518 pw.print(rec.wakeReasonTag.poolIdx);
5519 } else {
5520 pw.print(" wake_reason=");
5521 pw.print(rec.wakeReasonTag.uid);
5522 pw.print(":\"");
5523 pw.print(rec.wakeReasonTag.string);
5524 pw.print("\"");
5525 }
5526 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005527 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005528 pw.print(checkin ? "," : " ");
5529 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5530 pw.print("+");
5531 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5532 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005533 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005534 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5535 : HISTORY_EVENT_NAMES;
5536 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5537 | HistoryItem.EVENT_FLAG_FINISH);
5538 if (idx >= 0 && idx < eventNames.length) {
5539 pw.print(eventNames[idx]);
5540 } else {
5541 pw.print(checkin ? "Ev" : "event");
5542 pw.print(idx);
5543 }
5544 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005545 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005546 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005547 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005548 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5549 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005550 pw.print(":\"");
5551 pw.print(rec.eventTag.string);
5552 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005553 }
5554 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005555 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005556 if (rec.stepDetails != null) {
5557 if (!checkin) {
5558 pw.print(" Details: cpu=");
5559 pw.print(rec.stepDetails.userTime);
5560 pw.print("u+");
5561 pw.print(rec.stepDetails.systemTime);
5562 pw.print("s");
5563 if (rec.stepDetails.appCpuUid1 >= 0) {
5564 pw.print(" (");
5565 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5566 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5567 if (rec.stepDetails.appCpuUid2 >= 0) {
5568 pw.print(", ");
5569 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5570 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5571 }
5572 if (rec.stepDetails.appCpuUid3 >= 0) {
5573 pw.print(", ");
5574 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5575 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5576 }
5577 pw.print(')');
5578 }
5579 pw.println();
5580 pw.print(" /proc/stat=");
5581 pw.print(rec.stepDetails.statUserTime);
5582 pw.print(" usr, ");
5583 pw.print(rec.stepDetails.statSystemTime);
5584 pw.print(" sys, ");
5585 pw.print(rec.stepDetails.statIOWaitTime);
5586 pw.print(" io, ");
5587 pw.print(rec.stepDetails.statIrqTime);
5588 pw.print(" irq, ");
5589 pw.print(rec.stepDetails.statSoftIrqTime);
5590 pw.print(" sirq, ");
5591 pw.print(rec.stepDetails.statIdlTime);
5592 pw.print(" idle");
5593 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5594 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5595 + rec.stepDetails.statSoftIrqTime;
5596 int total = totalRun + rec.stepDetails.statIdlTime;
5597 if (total > 0) {
5598 pw.print(" (");
5599 float perc = ((float)totalRun) / ((float)total) * 100;
5600 pw.print(String.format("%.1f%%", perc));
5601 pw.print(" of ");
5602 StringBuilder sb = new StringBuilder(64);
5603 formatTimeMsNoSpace(sb, total*10);
5604 pw.print(sb);
5605 pw.print(")");
5606 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005607 pw.print(", PlatformIdleStat ");
5608 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005609 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005610
5611 pw.print(", SubsystemPowerState ");
5612 pw.print(rec.stepDetails.statSubsystemPowerState);
5613 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005614 } else {
5615 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5616 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5617 pw.print(rec.stepDetails.userTime);
5618 pw.print(":");
5619 pw.print(rec.stepDetails.systemTime);
5620 if (rec.stepDetails.appCpuUid1 >= 0) {
5621 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5622 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5623 if (rec.stepDetails.appCpuUid2 >= 0) {
5624 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5625 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5626 }
5627 if (rec.stepDetails.appCpuUid3 >= 0) {
5628 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5629 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5630 }
5631 }
5632 pw.println();
5633 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5634 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5635 pw.print(rec.stepDetails.statUserTime);
5636 pw.print(',');
5637 pw.print(rec.stepDetails.statSystemTime);
5638 pw.print(',');
5639 pw.print(rec.stepDetails.statIOWaitTime);
5640 pw.print(',');
5641 pw.print(rec.stepDetails.statIrqTime);
5642 pw.print(',');
5643 pw.print(rec.stepDetails.statSoftIrqTime);
5644 pw.print(',');
5645 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005646 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005647 if (rec.stepDetails.statPlatformIdleState != null) {
5648 pw.print(rec.stepDetails.statPlatformIdleState);
5649 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005650 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005651
5652 if (rec.stepDetails.statSubsystemPowerState != null) {
5653 pw.print(rec.stepDetails.statSubsystemPowerState);
5654 }
5655 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005656 }
5657 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005658 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005659 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005660 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005661 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005662
5663 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5664 UserHandle.formatUid(pw, uid);
5665 pw.print("=");
5666 pw.print(utime);
5667 pw.print("u+");
5668 pw.print(stime);
5669 pw.print("s");
5670 }
5671
5672 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5673 pw.print('/');
5674 pw.print(uid);
5675 pw.print(":");
5676 pw.print(utime);
5677 pw.print(":");
5678 pw.print(stime);
5679 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005680 }
5681
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005682 private void printSizeValue(PrintWriter pw, long size) {
5683 float result = size;
5684 String suffix = "";
5685 if (result >= 10*1024) {
5686 suffix = "KB";
5687 result = result / 1024;
5688 }
5689 if (result >= 10*1024) {
5690 suffix = "MB";
5691 result = result / 1024;
5692 }
5693 if (result >= 10*1024) {
5694 suffix = "GB";
5695 result = result / 1024;
5696 }
5697 if (result >= 10*1024) {
5698 suffix = "TB";
5699 result = result / 1024;
5700 }
5701 if (result >= 10*1024) {
5702 suffix = "PB";
5703 result = result / 1024;
5704 }
5705 pw.print((int)result);
5706 pw.print(suffix);
5707 }
5708
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005709 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5710 String label3, long estimatedTime) {
5711 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005712 return false;
5713 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005714 pw.print(label1);
5715 pw.print(label2);
5716 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005717 StringBuilder sb = new StringBuilder(64);
5718 formatTimeMs(sb, estimatedTime);
5719 pw.print(sb);
5720 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005721 return true;
5722 }
5723
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005724 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5725 LevelStepTracker steps, boolean checkin) {
5726 if (steps == null) {
5727 return false;
5728 }
5729 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005730 if (count <= 0) {
5731 return false;
5732 }
5733 if (!checkin) {
5734 pw.println(header);
5735 }
Kweku Adams030980a2015-04-01 16:07:48 -07005736 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005737 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005738 long duration = steps.getDurationAt(i);
5739 int level = steps.getLevelAt(i);
5740 long initMode = steps.getInitModeAt(i);
5741 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005742 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005743 lineArgs[0] = Long.toString(duration);
5744 lineArgs[1] = Integer.toString(level);
5745 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5746 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5747 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5748 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5749 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5750 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005751 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005752 }
5753 } else {
5754 lineArgs[2] = "";
5755 }
5756 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5757 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5758 } else {
5759 lineArgs[3] = "";
5760 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005761 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005762 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005763 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005764 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005765 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005766 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5767 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005768 pw.print(prefix);
5769 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005770 TimeUtils.formatDuration(duration, pw);
5771 pw.print(" to "); pw.print(level);
5772 boolean haveModes = false;
5773 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5774 pw.print(" (");
5775 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5776 case Display.STATE_OFF: pw.print("screen-off"); break;
5777 case Display.STATE_ON: pw.print("screen-on"); break;
5778 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5779 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005780 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005781 }
5782 haveModes = true;
5783 }
5784 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5785 pw.print(haveModes ? ", " : " (");
5786 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5787 ? "power-save-on" : "power-save-off");
5788 haveModes = true;
5789 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005790 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5791 pw.print(haveModes ? ", " : " (");
5792 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5793 ? "device-idle-on" : "device-idle-off");
5794 haveModes = true;
5795 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005796 if (haveModes) {
5797 pw.print(")");
5798 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005799 pw.println();
5800 }
5801 }
5802 return true;
5803 }
5804
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005805 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005806 public static final int DUMP_DAILY_ONLY = 1<<2;
5807 public static final int DUMP_HISTORY_ONLY = 1<<3;
5808 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5809 public static final int DUMP_VERBOSE = 1<<5;
5810 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005811
Dianne Hackborn37de0982014-05-09 09:32:18 -07005812 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5813 final HistoryPrinter hprinter = new HistoryPrinter();
5814 final HistoryItem rec = new HistoryItem();
5815 long lastTime = -1;
5816 long baseTime = -1;
5817 boolean printed = false;
5818 HistoryEventTracker tracker = null;
5819 while (getNextHistoryLocked(rec)) {
5820 lastTime = rec.time;
5821 if (baseTime < 0) {
5822 baseTime = lastTime;
5823 }
5824 if (rec.time >= histStart) {
5825 if (histStart >= 0 && !printed) {
5826 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005827 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005828 || rec.cmd == HistoryItem.CMD_START
5829 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005830 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005831 hprinter.printNextItem(pw, rec, baseTime, checkin,
5832 (flags&DUMP_VERBOSE) != 0);
5833 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005834 } else if (rec.currentTime != 0) {
5835 printed = true;
5836 byte cmd = rec.cmd;
5837 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005838 hprinter.printNextItem(pw, rec, baseTime, checkin,
5839 (flags&DUMP_VERBOSE) != 0);
5840 rec.cmd = cmd;
5841 }
5842 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005843 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5844 hprinter.printNextItem(pw, rec, baseTime, checkin,
5845 (flags&DUMP_VERBOSE) != 0);
5846 rec.cmd = HistoryItem.CMD_UPDATE;
5847 }
5848 int oldEventCode = rec.eventCode;
5849 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005850 rec.eventTag = new HistoryTag();
5851 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5852 HashMap<String, SparseIntArray> active
5853 = tracker.getStateForEvent(i);
5854 if (active == null) {
5855 continue;
5856 }
5857 for (HashMap.Entry<String, SparseIntArray> ent
5858 : active.entrySet()) {
5859 SparseIntArray uids = ent.getValue();
5860 for (int j=0; j<uids.size(); j++) {
5861 rec.eventCode = i;
5862 rec.eventTag.string = ent.getKey();
5863 rec.eventTag.uid = uids.keyAt(j);
5864 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005865 hprinter.printNextItem(pw, rec, baseTime, checkin,
5866 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005867 rec.wakeReasonTag = null;
5868 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005869 }
5870 }
5871 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005872 rec.eventCode = oldEventCode;
5873 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005874 tracker = null;
5875 }
5876 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005877 hprinter.printNextItem(pw, rec, baseTime, checkin,
5878 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005879 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5880 // This is an attempt to aggregate the previous state and generate
5881 // fake events to reflect that state at the point where we start
5882 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005883 if (tracker == null) {
5884 tracker = new HistoryEventTracker();
5885 }
5886 tracker.updateState(rec.eventCode, rec.eventTag.string,
5887 rec.eventTag.uid, rec.eventTag.poolIdx);
5888 }
5889 }
5890 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005891 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005892 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5893 }
5894 }
5895
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005896 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5897 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5898 if (steps == null) {
5899 return;
5900 }
5901 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5902 if (timeRemaining >= 0) {
5903 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5904 tmpSb.setLength(0);
5905 formatTimeMs(tmpSb, timeRemaining);
5906 pw.print(tmpSb);
5907 pw.print(" (from "); pw.print(tmpOutInt[0]);
5908 pw.println(" steps)");
5909 }
5910 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5911 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5912 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5913 if (estimatedTime > 0) {
5914 pw.print(prefix); pw.print(label); pw.print(" ");
5915 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5916 pw.print(" time: ");
5917 tmpSb.setLength(0);
5918 formatTimeMs(tmpSb, estimatedTime);
5919 pw.print(tmpSb);
5920 pw.print(" (from "); pw.print(tmpOutInt[0]);
5921 pw.println(" steps)");
5922 }
5923 }
5924 }
5925
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005926 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5927 ArrayList<PackageChange> changes) {
5928 if (changes == null) {
5929 return;
5930 }
5931 pw.print(prefix); pw.println("Package changes:");
5932 for (int i=0; i<changes.size(); i++) {
5933 PackageChange pc = changes.get(i);
5934 if (pc.mUpdate) {
5935 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5936 pw.print(" vers="); pw.println(pc.mVersionCode);
5937 } else {
5938 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5939 }
5940 }
5941 }
5942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005943 /**
5944 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5945 *
5946 * @param pw a Printer to receive the dump output.
5947 */
5948 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005949 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005950 prepareForDumpLocked();
5951
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005952 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005953 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005954
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005955 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005956 final long historyTotalSize = getHistoryTotalSize();
5957 final long historyUsedSize = getHistoryUsedSize();
5958 if (startIteratingHistoryLocked()) {
5959 try {
5960 pw.print("Battery History (");
5961 pw.print((100*historyUsedSize)/historyTotalSize);
5962 pw.print("% used, ");
5963 printSizeValue(pw, historyUsedSize);
5964 pw.print(" used of ");
5965 printSizeValue(pw, historyTotalSize);
5966 pw.print(", ");
5967 pw.print(getHistoryStringPoolSize());
5968 pw.print(" strings using ");
5969 printSizeValue(pw, getHistoryStringPoolBytes());
5970 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005971 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005972 pw.println();
5973 } finally {
5974 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005975 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005976 }
5977
5978 if (startIteratingOldHistoryLocked()) {
5979 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005980 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005981 pw.println("Old battery History:");
5982 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005983 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005984 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005985 if (baseTime < 0) {
5986 baseTime = rec.time;
5987 }
5988 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005989 }
5990 pw.println();
5991 } finally {
5992 finishIteratingOldHistoryLocked();
5993 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005994 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005995 }
5996
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005997 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005998 return;
5999 }
6000
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006001 if (!filtering) {
6002 SparseArray<? extends Uid> uidStats = getUidStats();
6003 final int NU = uidStats.size();
6004 boolean didPid = false;
6005 long nowRealtime = SystemClock.elapsedRealtime();
6006 for (int i=0; i<NU; i++) {
6007 Uid uid = uidStats.valueAt(i);
6008 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6009 if (pids != null) {
6010 for (int j=0; j<pids.size(); j++) {
6011 Uid.Pid pid = pids.valueAt(j);
6012 if (!didPid) {
6013 pw.println("Per-PID Stats:");
6014 didPid = true;
6015 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006016 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6017 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006018 pw.print(" PID "); pw.print(pids.keyAt(j));
6019 pw.print(" wake time: ");
6020 TimeUtils.formatDuration(time, pw);
6021 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006022 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006023 }
6024 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006025 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006026 pw.println();
6027 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006028 }
6029
6030 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006031 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6032 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006033 long timeRemaining = computeBatteryTimeRemaining(
6034 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006035 if (timeRemaining >= 0) {
6036 pw.print(" Estimated discharge time remaining: ");
6037 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6038 pw.println();
6039 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006040 final LevelStepTracker steps = getDischargeLevelStepTracker();
6041 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6042 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6043 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6044 STEP_LEVEL_MODE_VALUES[i], null));
6045 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006046 pw.println();
6047 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006048 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6049 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006050 long timeRemaining = computeChargeTimeRemaining(
6051 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006052 if (timeRemaining >= 0) {
6053 pw.print(" Estimated charge time remaining: ");
6054 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6055 pw.println();
6056 }
6057 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006058 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006059 }
6060 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6061 pw.println("Daily stats:");
6062 pw.print(" Current start time: ");
6063 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6064 getCurrentDailyStartTime()).toString());
6065 pw.print(" Next min deadline: ");
6066 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6067 getNextMinDailyDeadline()).toString());
6068 pw.print(" Next max deadline: ");
6069 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6070 getNextMaxDailyDeadline()).toString());
6071 StringBuilder sb = new StringBuilder(64);
6072 int[] outInt = new int[1];
6073 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6074 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006075 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6076 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006077 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006078 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6079 dsteps, false)) {
6080 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6081 sb, outInt);
6082 }
6083 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6084 csteps, false)) {
6085 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6086 sb, outInt);
6087 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006088 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006089 } else {
6090 pw.println(" Current daily steps:");
6091 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6092 sb, outInt);
6093 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6094 sb, outInt);
6095 }
6096 }
6097 DailyItem dit;
6098 int curIndex = 0;
6099 while ((dit=getDailyItemLocked(curIndex)) != null) {
6100 curIndex++;
6101 if ((flags&DUMP_DAILY_ONLY) != 0) {
6102 pw.println();
6103 }
6104 pw.print(" Daily from ");
6105 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6106 pw.print(" to ");
6107 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6108 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006109 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006110 if (dumpDurationSteps(pw, " ",
6111 " Discharge step durations:", dit.mDischargeSteps, false)) {
6112 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6113 sb, outInt);
6114 }
6115 if (dumpDurationSteps(pw, " ",
6116 " Charge step durations:", dit.mChargeSteps, false)) {
6117 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6118 sb, outInt);
6119 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006120 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006121 } else {
6122 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6123 sb, outInt);
6124 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6125 sb, outInt);
6126 }
6127 }
6128 pw.println();
6129 }
6130 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006131 pw.println("Statistics since last charge:");
6132 pw.println(" System starts: " + getStartCount()
6133 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006134 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6135 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006136 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 }
6139
6140 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006141 public void dumpCheckinLocked(Context context, PrintWriter pw,
6142 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006143 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006144
6145 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006146 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6147 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006148
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006149 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6150
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006151 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006152 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006153
6154 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006155 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006156 try {
6157 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6158 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6159 pw.print(HISTORY_STRING_POOL); pw.print(',');
6160 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006161 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006162 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006163 pw.print(",\"");
6164 String str = getHistoryTagPoolString(i);
6165 str = str.replace("\\", "\\\\");
6166 str = str.replace("\"", "\\\"");
6167 pw.print(str);
6168 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006169 pw.println();
6170 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006171 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006172 } finally {
6173 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006174 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006175 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006176 }
6177
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006178 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006179 return;
6180 }
6181
Dianne Hackborne4a59512010-12-07 11:08:07 -08006182 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006183 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006184 for (int i=0; i<apps.size(); i++) {
6185 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006186 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6187 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006188 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006189 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6190 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006191 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006192 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006193 }
6194 SparseArray<? extends Uid> uidStats = getUidStats();
6195 final int NU = uidStats.size();
6196 String[] lineArgs = new String[2];
6197 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006198 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6199 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6200 if (pkgs != null && !pkgs.second.value) {
6201 pkgs.second.value = true;
6202 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006203 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006204 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006205 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6206 (Object[])lineArgs);
6207 }
6208 }
6209 }
6210 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006211 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006212 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006213 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006214 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006215 if (timeRemaining >= 0) {
6216 lineArgs[0] = Long.toString(timeRemaining);
6217 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6218 (Object[])lineArgs);
6219 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006220 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006221 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006222 if (timeRemaining >= 0) {
6223 lineArgs[0] = Long.toString(timeRemaining);
6224 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6225 (Object[])lineArgs);
6226 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006227 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6228 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006231}