blob: 450ced4b98971dec8f0ee0460537848bf27a04ba [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
Dianne Hackborn94326cb2017-06-28 16:17:20 -070019import android.app.job.JobParameters;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080020import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080021import android.content.pm.ApplicationInfo;
Kweku Adams2f73ecd2017-09-27 16:59:19 -070022import android.service.batterystats.BatteryStatsServiceDumpProto;
Wink Saville52840902011-02-18 12:40:47 -080023import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080024import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070025import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070026import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070027import android.util.MutableBoolean;
28import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.util.Printer;
30import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070031import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070032import android.util.TimeUtils;
Kweku Adams2f73ecd2017-09-27 16:59:19 -070033import android.util.proto.ProtoOutputStream;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070034import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080035
Dianne Hackborna7c837f2014-01-15 16:20:44 -080036import com.android.internal.os.BatterySipper;
37import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kweku Adams2f73ecd2017-09-27 16:59:19 -070039import java.io.FileDescriptor;
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -070040import java.io.PrintWriter;
41import java.util.ArrayList;
42import java.util.Collections;
43import java.util.Comparator;
44import java.util.Formatter;
45import java.util.HashMap;
46import java.util.List;
47import java.util.Map;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049/**
50 * A class providing access to battery usage statistics, including information on
51 * wakelocks, processes, packages, and services. All times are represented in microseconds
52 * except where indicated otherwise.
53 * @hide
54 */
55public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070056 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
58 private static final boolean LOCAL_LOGV = false;
Bookatz82b341172017-09-07 19:06:08 -070059 /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */
60 protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070061
62 /** @hide */
63 public static final String SERVICE_NAME = "batterystats";
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 /**
66 * A constant indicating a partial wake lock timer.
67 */
68 public static final int WAKE_TYPE_PARTIAL = 0;
69
70 /**
71 * A constant indicating a full wake lock timer.
72 */
73 public static final int WAKE_TYPE_FULL = 1;
74
75 /**
76 * A constant indicating a window wake lock timer.
77 */
78 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 /**
81 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
83 public static final int SENSOR = 3;
Mike Mac2f518a2017-09-19 16:06:03 -070084
The Android Open Source Project10592532009-03-18 17:39:46 -070085 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070086 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070087 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070088 public static final int WIFI_RUNNING = 4;
Mike Mac2f518a2017-09-19 16:06:03 -070089
Dianne Hackborn617f8772009-03-31 15:04:46 -070090 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070091 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070092 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070093 public static final int FULL_WIFI_LOCK = 5;
Mike Mac2f518a2017-09-19 16:06:03 -070094
The Android Open Source Project10592532009-03-18 17:39:46 -070095 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070096 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070097 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070098 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
Dianne Hackborn62793e42015-03-09 11:15:41 -0700100 /**
101 * A constant indicating a wifi multicast timer
102 */
103 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700106 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700107 */
108 public static final int VIDEO_TURNED_ON = 8;
109
110 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800111 * A constant indicating a vibrator on timer
112 */
113 public static final int VIBRATOR_ON = 9;
114
115 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700116 * A constant indicating a foreground activity timer
117 */
118 public static final int FOREGROUND_ACTIVITY = 10;
119
120 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700121 * A constant indicating a wifi batched scan is active
122 */
123 public static final int WIFI_BATCHED_SCAN = 11;
124
125 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700126 * A constant indicating a process state timer
127 */
128 public static final int PROCESS_STATE = 12;
129
130 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700131 * A constant indicating a sync timer
132 */
133 public static final int SYNC = 13;
134
135 /**
136 * A constant indicating a job timer
137 */
138 public static final int JOB = 14;
139
140 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800141 * A constant indicating an audio turn on timer
142 */
143 public static final int AUDIO_TURNED_ON = 15;
144
145 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700146 * A constant indicating a flashlight turn on timer
147 */
148 public static final int FLASHLIGHT_TURNED_ON = 16;
149
150 /**
151 * A constant indicating a camera turn on timer
152 */
153 public static final int CAMERA_TURNED_ON = 17;
154
155 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700156 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700157 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700158 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700159
160 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800161 * A constant indicating a bluetooth scan timer.
162 */
163 public static final int BLUETOOTH_SCAN_ON = 19;
164
165 /**
Bookatzc8c44962017-05-11 12:12:54 -0700166 * A constant indicating an aggregated partial wake lock timer.
167 */
168 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
169
170 /**
Bookatzb1f04f32017-05-19 13:57:32 -0700171 * A constant indicating a bluetooth scan timer for unoptimized scans.
172 */
173 public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21;
174
175 /**
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700176 * A constant indicating a foreground service timer
177 */
178 public static final int FOREGROUND_SERVICE = 22;
179
180 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 * Include all of the data in the stats, including previously saved data.
182 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700183 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184
185 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 * Include only the current run in the stats.
187 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700188 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
190 /**
191 * Include only the run since the last time the device was unplugged in the stats.
192 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700193 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700194
195 // NOTE: Update this list if you add/change any stats above.
Kweku Adams2f73ecd2017-09-27 16:59:19 -0700196 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700197 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700198 private static final String[] STAT_NAMES = { "l", "c", "u" };
199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700201 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700202 *
203 * New in version 19:
204 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800205 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700206 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700207 * New in version 21:
208 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700209 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700210 * - BLE scan result count
211 * - CPU frequency time per uid
212 * New in version 22:
213 * - BLE scan result background count, BLE unoptimized scan time
Bookatz98d4d5c2017-08-01 19:07:54 -0700214 * - Background partial wakelock time & count
215 * New in version 23:
216 * - Logging smeared power model values
217 * New in version 24:
218 * - Fixed bugs in background timers and BLE scan time
219 * New in version 25:
220 * - Package wakeup alarms are now on screen-off timebase
Bookatz50df7112017-08-04 14:53:26 -0700221 * New in version 26:
Bookatz82b341172017-09-07 19:06:08 -0700222 * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
Mike Mac2f518a2017-09-19 16:06:03 -0700223 * New in version 27:
224 * - Always On Display (screen doze mode) time and power
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700225 */
Kweku Adams2f73ecd2017-09-27 16:59:19 -0700226 static final int CHECKIN_VERSION = 27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700227
228 /**
229 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700231 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700232
Evan Millar22ac0432009-03-31 11:33:18 -0700233 private static final long BYTES_PER_KB = 1024;
234 private static final long BYTES_PER_MB = 1048576; // 1024^2
235 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700236
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700237 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800238 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700239 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700241 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700242 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700243 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
244 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700245 // rpm line is:
246 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
247 // screen-off time, screen-off count
248 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700249 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800250 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700251 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
252 // fgs line is:
253 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
254 // foreground service time, count
255 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700256 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700257 // wl line is:
258 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700259 // full totalTime, 'f', count, current duration, max duration, total duration,
260 // partial totalTime, 'p', count, current duration, max duration, total duration,
261 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
262 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700263 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700264 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700265 // awl line is:
266 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
267 // cumulative partial wakelock duration, cumulative background partial wakelock duration
268 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700269 private static final String SYNC_DATA = "sy";
270 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700271 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700272 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700273 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700274 private static final String NETWORK_DATA = "nt";
275 private static final String USER_ACTIVITY_DATA = "ua";
276 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800277 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700278 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700279 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700280 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800281 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
282 private static final String WIFI_CONTROLLER_DATA = "wfcd";
283 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
284 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700285 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700286 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800287 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800288 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
289 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800290 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700291 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700292 private static final String SCREEN_BRIGHTNESS_DATA = "br";
293 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700294 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700295 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
296 private static final String DATA_CONNECTION_TIME_DATA = "dct";
297 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800298 private static final String WIFI_STATE_TIME_DATA = "wst";
299 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700300 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
301 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
302 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
303 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800304 private static final String POWER_USE_SUMMARY_DATA = "pws";
305 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700306 private static final String DISCHARGE_STEP_DATA = "dsd";
307 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700308 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
309 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700310 private static final String FLASHLIGHT_DATA = "fla";
311 private static final String CAMERA_DATA = "cam";
312 private static final String VIDEO_DATA = "vid";
313 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314
Adam Lesinski010bf372016-04-11 12:18:18 -0700315 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
316
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700317 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 private final Formatter mFormatter = new Formatter(mFormatBuilder);
319
320 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700321 * Indicates times spent by the uid at each cpu frequency in all process states.
322 *
323 * Other types might include times spent in foreground, background etc.
324 */
325 private final String UID_TIMES_TYPE_ALL = "A";
326
327 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700328 * State for keeping track of counting information.
329 */
330 public static abstract class Counter {
331
332 /**
333 * Returns the count associated with this Counter for the
334 * selected type of statistics.
335 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700336 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700337 */
Evan Millarc64edde2009-04-18 12:26:32 -0700338 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700339
340 /**
341 * Temporary for debugging.
342 */
343 public abstract void logState(Printer pw, String prefix);
344 }
345
346 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700347 * State for keeping track of long counting information.
348 */
349 public static abstract class LongCounter {
350
351 /**
352 * Returns the count associated with this Counter for the
353 * selected type of statistics.
354 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700355 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700356 */
357 public abstract long getCountLocked(int which);
358
359 /**
360 * Temporary for debugging.
361 */
362 public abstract void logState(Printer pw, String prefix);
363 }
364
365 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700366 * State for keeping track of array of long counting information.
367 */
368 public static abstract class LongCounterArray {
369 /**
370 * Returns the counts associated with this Counter for the
371 * selected type of statistics.
372 *
373 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
374 */
375 public abstract long[] getCountsLocked(int which);
376
377 /**
378 * Temporary for debugging.
379 */
380 public abstract void logState(Printer pw, String prefix);
381 }
382
383 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800384 * Container class that aggregates counters for transmit, receive, and idle state of a
385 * radio controller.
386 */
387 public static abstract class ControllerActivityCounter {
388 /**
389 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
390 * idle state.
391 */
392 public abstract LongCounter getIdleTimeCounter();
393
394 /**
395 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
396 * receive state.
397 */
398 public abstract LongCounter getRxTimeCounter();
399
400 /**
401 * An array of {@link LongCounter}, representing various transmit levels, where each level
402 * may draw a different amount of power. The levels themselves are controller-specific.
403 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
404 * various transmit level states.
405 */
406 public abstract LongCounter[] getTxTimeCounters();
407
408 /**
409 * @return a non-null {@link LongCounter} representing the power consumed by the controller
410 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
411 * yield a value of 0 if the device doesn't support power calculations.
412 */
413 public abstract LongCounter getPowerCounter();
414 }
415
416 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 * State for keeping track of timing information.
418 */
419 public static abstract class Timer {
420
421 /**
422 * Returns the count associated with this Timer for the
423 * selected type of statistics.
424 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700425 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 */
Evan Millarc64edde2009-04-18 12:26:32 -0700427 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428
429 /**
430 * Returns the total time in microseconds associated with this Timer for the
431 * selected type of statistics.
432 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800433 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700434 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 * @return a time in microseconds
436 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800437 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700440 * Returns the total time in microseconds associated with this Timer since the
441 * 'mark' was last set.
442 *
443 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
444 * @return a time in microseconds
445 */
446 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
447
448 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700449 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800450 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700451
452 */
453 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
454 return -1;
455 }
456
457 /**
458 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800459 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700460 */
461 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
462 return -1;
463 }
464
465 /**
Bookatz867c0d72017-03-07 18:23:42 -0800466 * Returns the current time the timer has been active, if it is being tracked.
467 *
468 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
469 * been on since reset.
470 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
471 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
472 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
473 * the actual total time.
474 * Not all Timer subclasses track the max, total, current durations.
475 */
476 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
477 return -1;
478 }
479
480 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700481 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
482 * used, for example, for tracking background usage. Secondary timers are never pooled.
483 *
484 * Not all Timer subclasses have a secondary timer; those that don't return null.
485 */
486 public Timer getSubTimer() {
487 return null;
488 }
489
490 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700491 * Returns whether the timer is currently running. Some types of timers
492 * (e.g. BatchTimers) don't know whether the event is currently active,
493 * and report false.
494 */
495 public boolean isRunningLocked() {
496 return false;
497 }
498
499 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 * Temporary for debugging.
501 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700502 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504
505 /**
506 * The statistics associated with a particular uid.
507 */
508 public static abstract class Uid {
509
510 /**
511 * Returns a mapping containing wakelock statistics.
512 *
513 * @return a Map from Strings to Uid.Wakelock objects.
514 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700515 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516
517 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700518 * Returns a mapping containing sync statistics.
519 *
520 * @return a Map from Strings to Timer objects.
521 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700522 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700523
524 /**
525 * Returns a mapping containing scheduled job statistics.
526 *
527 * @return a Map from Strings to Timer objects.
528 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700529 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700530
531 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700532 * Returns statistics about how jobs have completed.
533 *
534 * @return A Map of String job names to completion type -> count mapping.
535 */
536 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
537
538 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 * The statistics associated with a particular wake lock.
540 */
541 public static abstract class Wakelock {
542 public abstract Timer getWakeTime(int type);
543 }
544
545 /**
Bookatzc8c44962017-05-11 12:12:54 -0700546 * The cumulative time the uid spent holding any partial wakelocks. This will generally
547 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
548 * wakelocks that overlap in time (and therefore over-counts).
549 */
550 public abstract Timer getAggregatedPartialWakelockTimer();
551
552 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 * Returns a mapping containing sensor statistics.
554 *
555 * @return a Map from Integer sensor ids to Uid.Sensor objects.
556 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700557 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558
559 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700560 * Returns a mapping containing active process data.
561 */
562 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700563
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700564 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 * Returns a mapping containing process statistics.
566 *
567 * @return a Map from Strings to Uid.Proc objects.
568 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700569 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570
571 /**
572 * Returns a mapping containing package statistics.
573 *
574 * @return a Map from Strings to Uid.Pkg objects.
575 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700576 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700577
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800578 public abstract ControllerActivityCounter getWifiControllerActivity();
579 public abstract ControllerActivityCounter getBluetoothControllerActivity();
580 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800581
582 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 * {@hide}
584 */
585 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700586
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800587 public abstract void noteWifiRunningLocked(long elapsedRealtime);
588 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
589 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
590 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
591 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
592 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
593 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
594 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
595 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
596 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800597 public abstract void noteActivityResumedLocked(long elapsedRealtime);
598 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800599 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
600 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
601 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700602 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800603 public abstract int getWifiScanBackgroundCount(int which);
604 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
605 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800606 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700607 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800608 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700609 public abstract Timer getAudioTurnedOnTimer();
610 public abstract Timer getVideoTurnedOnTimer();
611 public abstract Timer getFlashlightTurnedOnTimer();
612 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700613 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700614
615 /**
616 * Returns the timer keeping track of Foreground Service time
617 */
618 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800619 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800620 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700621 public abstract Timer getBluetoothUnoptimizedScanTimer();
622 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700623 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700624 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700625
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700626 public abstract long[] getCpuFreqTimes(int which);
627 public abstract long[] getScreenOffCpuFreqTimes(int which);
628
Dianne Hackborna0200e32016-03-30 18:01:41 -0700629 // Note: the following times are disjoint. They can be added together to find the
630 // total time a uid has had any processes running at all.
631
632 /**
633 * Time this uid has any processes in the top state (or above such as persistent).
634 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800635 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700636 /**
637 * Time this uid has any process with a started out bound foreground service, but
638 * none in the "top" state.
639 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800640 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700641 /**
642 * Time this uid has any process that is top while the device is sleeping, but none
643 * in the "foreground service" or better state.
644 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800645 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700646 /**
647 * Time this uid has any process in an active foreground state, but none in the
648 * "top sleeping" or better state.
649 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800650 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700651 /**
652 * Time this uid has any process in an active background state, but none in the
653 * "foreground" or better state.
654 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800655 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700656 /**
657 * Time this uid has any processes that are sitting around cached, not in one of the
658 * other active states.
659 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800660 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700661 /**
662 * Total number of process states we track.
663 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800664 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700665
666 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800667 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700668 };
669
670 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800671 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700672
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800673 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674
Robert Greenwalta029ea12013-09-25 16:38:12 -0700675 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
676
Dianne Hackborn617f8772009-03-31 15:04:46 -0700677 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700678 * Note that these must match the constants in android.os.PowerManager.
679 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
680 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700681 */
682 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700683 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700684 };
Bookatzc8c44962017-05-11 12:12:54 -0700685
Phil Weaverda80d672016-03-15 16:25:46 -0700686 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700687
Dianne Hackborn617f8772009-03-31 15:04:46 -0700688 public abstract void noteUserActivityLocked(int type);
689 public abstract boolean hasUserActivity();
690 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700691
692 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800693 public abstract long getNetworkActivityBytes(int type, int which);
694 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800695 public abstract long getMobileRadioActiveTime(int which);
696 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700697
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700698 /**
699 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
700 */
701 public abstract long getUserCpuTimeUs(int which);
702
703 /**
704 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
705 */
706 public abstract long getSystemCpuTimeUs(int which);
707
708 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700709 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700710 * given CPU cluster.
711 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700712 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700713 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700714 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
715 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700716 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700717 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700718
Adam Lesinski5f056f62016-07-14 16:56:08 -0700719 /**
720 * Returns the number of times this UID woke up the Application Processor to
721 * process a mobile radio packet.
722 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
723 */
724 public abstract long getMobileRadioApWakeupCount(int which);
725
726 /**
727 * Returns the number of times this UID woke up the Application Processor to
728 * process a WiFi packet.
729 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
730 */
731 public abstract long getWifiRadioApWakeupCount(int which);
732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800734 /*
735 * FIXME: it's not correct to use this magic value because it
736 * could clash with a sensor handle (which are defined by
737 * the sensor HAL, and therefore out of our control
738 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 // Magic sensor number for the GPS.
740 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800745
Bookatz867c0d72017-03-07 18:23:42 -0800746 /** Returns a Timer for sensor usage when app is in the background. */
747 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 }
749
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700750 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800751 public int mWakeNesting;
752 public long mWakeSumMs;
753 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700754 }
755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 /**
757 * The statistics associated with a particular process.
758 */
759 public static abstract class Proc {
760
Dianne Hackborn287952c2010-09-22 22:34:31 -0700761 public static class ExcessivePower {
762 public static final int TYPE_WAKE = 1;
763 public static final int TYPE_CPU = 2;
764
765 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700766 public long overTime;
767 public long usedTime;
768 }
769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800771 * Returns true if this process is still active in the battery stats.
772 */
773 public abstract boolean isActive();
774
775 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700776 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700778 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 */
780 public abstract long getUserTime(int which);
781
782 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700783 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700785 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 */
787 public abstract long getSystemTime(int which);
788
789 /**
790 * Returns the number of times the process has been started.
791 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700792 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 */
794 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700795
796 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800797 * Returns the number of times the process has crashed.
798 *
799 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
800 */
801 public abstract int getNumCrashes(int which);
802
803 /**
804 * Returns the number of times the process has ANRed.
805 *
806 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
807 */
808 public abstract int getNumAnrs(int which);
809
810 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700811 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700812 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700813 * @return foreground cpu time in microseconds
814 */
815 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700816
Dianne Hackborn287952c2010-09-22 22:34:31 -0700817 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700818
Dianne Hackborn287952c2010-09-22 22:34:31 -0700819 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 }
821
822 /**
823 * The statistics associated with a particular package.
824 */
825 public static abstract class Pkg {
826
827 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700828 * Returns information about all wakeup alarms that have been triggered for this
829 * package. The mapping keys are tag names for the alarms, the counter contains
830 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700832 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833
834 /**
835 * Returns a mapping containing service statistics.
836 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700837 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838
839 /**
840 * The statistics associated with a particular service.
841 */
Joe Onoratoabded112016-02-08 16:49:39 -0800842 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843
844 /**
845 * Returns the amount of time spent started.
846 *
847 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700848 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 * @return
850 */
851 public abstract long getStartTime(long batteryUptime, int which);
852
853 /**
854 * Returns the total number of times startService() has been called.
855 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700856 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 */
858 public abstract int getStarts(int which);
859
860 /**
861 * Returns the total number times the service has been launched.
862 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700863 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 */
865 public abstract int getLaunches(int which);
866 }
867 }
868 }
869
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800870 public static final class LevelStepTracker {
871 public long mLastStepTime = -1;
872 public int mNumStepDurations;
873 public final long[] mStepDurations;
874
875 public LevelStepTracker(int maxLevelSteps) {
876 mStepDurations = new long[maxLevelSteps];
877 }
878
879 public LevelStepTracker(int numSteps, long[] steps) {
880 mNumStepDurations = numSteps;
881 mStepDurations = new long[numSteps];
882 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
883 }
884
885 public long getDurationAt(int index) {
886 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
887 }
888
889 public int getLevelAt(int index) {
890 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
891 >> STEP_LEVEL_LEVEL_SHIFT);
892 }
893
894 public int getInitModeAt(int index) {
895 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
896 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
897 }
898
899 public int getModModeAt(int index) {
900 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
901 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
902 }
903
904 private void appendHex(long val, int topOffset, StringBuilder out) {
905 boolean hasData = false;
906 while (topOffset >= 0) {
907 int digit = (int)( (val>>topOffset) & 0xf );
908 topOffset -= 4;
909 if (!hasData && digit == 0) {
910 continue;
911 }
912 hasData = true;
913 if (digit >= 0 && digit <= 9) {
914 out.append((char)('0' + digit));
915 } else {
916 out.append((char)('a' + digit - 10));
917 }
918 }
919 }
920
921 public void encodeEntryAt(int index, StringBuilder out) {
922 long item = mStepDurations[index];
923 long duration = item & STEP_LEVEL_TIME_MASK;
924 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
925 >> STEP_LEVEL_LEVEL_SHIFT);
926 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
927 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
928 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
929 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
930 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
931 case Display.STATE_OFF: out.append('f'); break;
932 case Display.STATE_ON: out.append('o'); break;
933 case Display.STATE_DOZE: out.append('d'); break;
934 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
935 }
936 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
937 out.append('p');
938 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700939 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
940 out.append('i');
941 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800942 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
943 case Display.STATE_OFF: out.append('F'); break;
944 case Display.STATE_ON: out.append('O'); break;
945 case Display.STATE_DOZE: out.append('D'); break;
946 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
947 }
948 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
949 out.append('P');
950 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700951 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
952 out.append('I');
953 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800954 out.append('-');
955 appendHex(level, 4, out);
956 out.append('-');
957 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
958 }
959
960 public void decodeEntryAt(int index, String value) {
961 final int N = value.length();
962 int i = 0;
963 char c;
964 long out = 0;
965 while (i < N && (c=value.charAt(i)) != '-') {
966 i++;
967 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800968 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800969 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800970 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800971 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800972 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800973 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800974 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
975 << STEP_LEVEL_INITIAL_MODE_SHIFT);
976 break;
977 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
978 << STEP_LEVEL_INITIAL_MODE_SHIFT);
979 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700980 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
981 << STEP_LEVEL_INITIAL_MODE_SHIFT);
982 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800983 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
984 break;
985 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
986 break;
987 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
988 break;
989 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
990 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
991 break;
992 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
993 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800994 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700995 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
996 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
997 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800998 }
999 }
1000 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001001 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001002 while (i < N && (c=value.charAt(i)) != '-') {
1003 i++;
1004 level <<= 4;
1005 if (c >= '0' && c <= '9') {
1006 level += c - '0';
1007 } else if (c >= 'a' && c <= 'f') {
1008 level += c - 'a' + 10;
1009 } else if (c >= 'A' && c <= 'F') {
1010 level += c - 'A' + 10;
1011 }
1012 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001013 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001014 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1015 long duration = 0;
1016 while (i < N && (c=value.charAt(i)) != '-') {
1017 i++;
1018 duration <<= 4;
1019 if (c >= '0' && c <= '9') {
1020 duration += c - '0';
1021 } else if (c >= 'a' && c <= 'f') {
1022 duration += c - 'a' + 10;
1023 } else if (c >= 'A' && c <= 'F') {
1024 duration += c - 'A' + 10;
1025 }
1026 }
1027 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1028 }
1029
1030 public void init() {
1031 mLastStepTime = -1;
1032 mNumStepDurations = 0;
1033 }
1034
1035 public void clearTime() {
1036 mLastStepTime = -1;
1037 }
1038
1039 public long computeTimePerLevel() {
1040 final long[] steps = mStepDurations;
1041 final int numSteps = mNumStepDurations;
1042
1043 // For now we'll do a simple average across all steps.
1044 if (numSteps <= 0) {
1045 return -1;
1046 }
1047 long total = 0;
1048 for (int i=0; i<numSteps; i++) {
1049 total += steps[i] & STEP_LEVEL_TIME_MASK;
1050 }
1051 return total / numSteps;
1052 /*
1053 long[] buckets = new long[numSteps];
1054 int numBuckets = 0;
1055 int numToAverage = 4;
1056 int i = 0;
1057 while (i < numSteps) {
1058 long totalTime = 0;
1059 int num = 0;
1060 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1061 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1062 num++;
1063 }
1064 buckets[numBuckets] = totalTime / num;
1065 numBuckets++;
1066 numToAverage *= 2;
1067 i += num;
1068 }
1069 if (numBuckets < 1) {
1070 return -1;
1071 }
1072 long averageTime = buckets[numBuckets-1];
1073 for (i=numBuckets-2; i>=0; i--) {
1074 averageTime = (averageTime + buckets[i]) / 2;
1075 }
1076 return averageTime;
1077 */
1078 }
1079
1080 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1081 int[] outNumOfInterest) {
1082 final long[] steps = mStepDurations;
1083 final int count = mNumStepDurations;
1084 if (count <= 0) {
1085 return -1;
1086 }
1087 long total = 0;
1088 int numOfInterest = 0;
1089 for (int i=0; i<count; i++) {
1090 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1091 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1092 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1093 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1094 // If the modes of interest didn't change during this step period...
1095 if ((modMode&modesOfInterest) == 0) {
1096 // And the mode values during this period match those we are measuring...
1097 if ((initMode&modesOfInterest) == modeValues) {
1098 // Then this can be used to estimate the total time!
1099 numOfInterest++;
1100 total += steps[i] & STEP_LEVEL_TIME_MASK;
1101 }
1102 }
1103 }
1104 if (numOfInterest <= 0) {
1105 return -1;
1106 }
1107
1108 if (outNumOfInterest != null) {
1109 outNumOfInterest[0] = numOfInterest;
1110 }
1111
1112 // The estimated time is the average time we spend in each level, multipled
1113 // by 100 -- the total number of battery levels
1114 return (total / numOfInterest) * 100;
1115 }
1116
1117 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1118 int stepCount = mNumStepDurations;
1119 final long lastStepTime = mLastStepTime;
1120 if (lastStepTime >= 0 && numStepLevels > 0) {
1121 final long[] steps = mStepDurations;
1122 long duration = elapsedRealtime - lastStepTime;
1123 for (int i=0; i<numStepLevels; i++) {
1124 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1125 long thisDuration = duration / (numStepLevels-i);
1126 duration -= thisDuration;
1127 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1128 thisDuration = STEP_LEVEL_TIME_MASK;
1129 }
1130 steps[0] = thisDuration | modeBits;
1131 }
1132 stepCount += numStepLevels;
1133 if (stepCount > steps.length) {
1134 stepCount = steps.length;
1135 }
1136 }
1137 mNumStepDurations = stepCount;
1138 mLastStepTime = elapsedRealtime;
1139 }
1140
1141 public void readFromParcel(Parcel in) {
1142 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001143 if (N > mStepDurations.length) {
1144 throw new ParcelFormatException("more step durations than available: " + N);
1145 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001146 mNumStepDurations = N;
1147 for (int i=0; i<N; i++) {
1148 mStepDurations[i] = in.readLong();
1149 }
1150 }
1151
1152 public void writeToParcel(Parcel out) {
1153 final int N = mNumStepDurations;
1154 out.writeInt(N);
1155 for (int i=0; i<N; i++) {
1156 out.writeLong(mStepDurations[i]);
1157 }
1158 }
1159 }
1160
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001161 public static final class PackageChange {
1162 public String mPackageName;
1163 public boolean mUpdate;
1164 public int mVersionCode;
1165 }
1166
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001167 public static final class DailyItem {
1168 public long mStartTime;
1169 public long mEndTime;
1170 public LevelStepTracker mDischargeSteps;
1171 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001172 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001173 }
1174
1175 public abstract DailyItem getDailyItemLocked(int daysAgo);
1176
1177 public abstract long getCurrentDailyStartTime();
1178
1179 public abstract long getNextMinDailyDeadline();
1180
1181 public abstract long getNextMaxDailyDeadline();
1182
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001183 public abstract long[] getCpuFreqs();
1184
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001185 public final static class HistoryTag {
1186 public String string;
1187 public int uid;
1188
1189 public int poolIdx;
1190
1191 public void setTo(HistoryTag o) {
1192 string = o.string;
1193 uid = o.uid;
1194 poolIdx = o.poolIdx;
1195 }
1196
1197 public void setTo(String _string, int _uid) {
1198 string = _string;
1199 uid = _uid;
1200 poolIdx = -1;
1201 }
1202
1203 public void writeToParcel(Parcel dest, int flags) {
1204 dest.writeString(string);
1205 dest.writeInt(uid);
1206 }
1207
1208 public void readFromParcel(Parcel src) {
1209 string = src.readString();
1210 uid = src.readInt();
1211 poolIdx = -1;
1212 }
1213
1214 @Override
1215 public boolean equals(Object o) {
1216 if (this == o) return true;
1217 if (o == null || getClass() != o.getClass()) return false;
1218
1219 HistoryTag that = (HistoryTag) o;
1220
1221 if (uid != that.uid) return false;
1222 if (!string.equals(that.string)) return false;
1223
1224 return true;
1225 }
1226
1227 @Override
1228 public int hashCode() {
1229 int result = string.hashCode();
1230 result = 31 * result + uid;
1231 return result;
1232 }
1233 }
1234
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001235 /**
1236 * Optional detailed information that can go into a history step. This is typically
1237 * generated each time the battery level changes.
1238 */
1239 public final static class HistoryStepDetails {
1240 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1241 public int userTime;
1242 public int systemTime;
1243
1244 // Top three apps using CPU in the last step, with times in 1/100 second.
1245 public int appCpuUid1;
1246 public int appCpuUTime1;
1247 public int appCpuSTime1;
1248 public int appCpuUid2;
1249 public int appCpuUTime2;
1250 public int appCpuSTime2;
1251 public int appCpuUid3;
1252 public int appCpuUTime3;
1253 public int appCpuSTime3;
1254
1255 // Information from /proc/stat
1256 public int statUserTime;
1257 public int statSystemTime;
1258 public int statIOWaitTime;
1259 public int statIrqTime;
1260 public int statSoftIrqTime;
1261 public int statIdlTime;
1262
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001263 // Platform-level low power state stats
1264 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001265 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001266
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001267 public HistoryStepDetails() {
1268 clear();
1269 }
1270
1271 public void clear() {
1272 userTime = systemTime = 0;
1273 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1274 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1275 = appCpuUTime3 = appCpuSTime3 = 0;
1276 }
1277
1278 public void writeToParcel(Parcel out) {
1279 out.writeInt(userTime);
1280 out.writeInt(systemTime);
1281 out.writeInt(appCpuUid1);
1282 out.writeInt(appCpuUTime1);
1283 out.writeInt(appCpuSTime1);
1284 out.writeInt(appCpuUid2);
1285 out.writeInt(appCpuUTime2);
1286 out.writeInt(appCpuSTime2);
1287 out.writeInt(appCpuUid3);
1288 out.writeInt(appCpuUTime3);
1289 out.writeInt(appCpuSTime3);
1290 out.writeInt(statUserTime);
1291 out.writeInt(statSystemTime);
1292 out.writeInt(statIOWaitTime);
1293 out.writeInt(statIrqTime);
1294 out.writeInt(statSoftIrqTime);
1295 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001296 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001297 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001298 }
1299
1300 public void readFromParcel(Parcel in) {
1301 userTime = in.readInt();
1302 systemTime = in.readInt();
1303 appCpuUid1 = in.readInt();
1304 appCpuUTime1 = in.readInt();
1305 appCpuSTime1 = in.readInt();
1306 appCpuUid2 = in.readInt();
1307 appCpuUTime2 = in.readInt();
1308 appCpuSTime2 = in.readInt();
1309 appCpuUid3 = in.readInt();
1310 appCpuUTime3 = in.readInt();
1311 appCpuSTime3 = in.readInt();
1312 statUserTime = in.readInt();
1313 statSystemTime = in.readInt();
1314 statIOWaitTime = in.readInt();
1315 statIrqTime = in.readInt();
1316 statSoftIrqTime = in.readInt();
1317 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001318 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001319 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001320 }
1321 }
1322
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001323 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001324 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001325
1326 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001327 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001328
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001329 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001330 public static final byte CMD_NULL = -1;
1331 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001332 public static final byte CMD_CURRENT_TIME = 5;
1333 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001334 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001335 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001336
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001337 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001338
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001339 /**
1340 * Return whether the command code is a delta data update.
1341 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001342 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001343 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001344 }
1345
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001346 public byte batteryLevel;
1347 public byte batteryStatus;
1348 public byte batteryHealth;
1349 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001350
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001351 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001352 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001353
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001354 // The charge of the battery in micro-Ampere-hours.
1355 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001356
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001357 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001358 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001359 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001360 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001361 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1362 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001363 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001364 public static final int STATE_PHONE_STATE_SHIFT = 6;
1365 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001366 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001367 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001368 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001369
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001370 // These states always appear directly in the first int token
1371 // of a delta change; they should be ones that change relatively
1372 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001373 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1374 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001375 public static final int STATE_GPS_ON_FLAG = 1<<29;
1376 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001377 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001378 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001379 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001380 // Do not use, this is used for coulomb delta count.
1381 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001382 // These are on the lower bits used for the command; if they change
1383 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001384 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001385 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001386 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001387 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1388 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001389 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001390 // empty slot
1391 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001392
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001393 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001394 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001395
1396 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001397
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001398 public int states;
1399
Dianne Hackborn3251b902014-06-20 14:40:53 -07001400 // Constants from WIFI_SUPPL_STATE_*
1401 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1402 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1403 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1404 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1405 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1406 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1407
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001408 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001409 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1410 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1411 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001412 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001413 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1414 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1415 public static final int STATE2_CHARGING_FLAG = 1<<24;
1416 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1417 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1418 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001419 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001420
1421 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001422 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1423 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001424
1425 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001426
Dianne Hackborn40c87252014-03-19 16:55:40 -07001427 public int states2;
1428
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001429 // The wake lock that was acquired at this point.
1430 public HistoryTag wakelockTag;
1431
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001432 // Kernel wakeup reason at this point.
1433 public HistoryTag wakeReasonTag;
1434
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001435 // Non-null when there is more detailed information at this step.
1436 public HistoryStepDetails stepDetails;
1437
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001438 public static final int EVENT_FLAG_START = 0x8000;
1439 public static final int EVENT_FLAG_FINISH = 0x4000;
1440
1441 // No event in this item.
1442 public static final int EVENT_NONE = 0x0000;
1443 // Event is about a process that is running.
1444 public static final int EVENT_PROC = 0x0001;
1445 // Event is about an application package that is in the foreground.
1446 public static final int EVENT_FOREGROUND = 0x0002;
1447 // Event is about an application package that is at the top of the screen.
1448 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001449 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001450 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001451 // Events for all additional wake locks aquired/release within a wake block.
1452 // These are not generated by default.
1453 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001454 // Event is about an application executing a scheduled job.
1455 public static final int EVENT_JOB = 0x0006;
1456 // Events for users running.
1457 public static final int EVENT_USER_RUNNING = 0x0007;
1458 // Events for foreground user.
1459 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001460 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001461 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001462 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001463 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001464 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001465 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001466 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001467 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001468 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001469 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001470 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001471 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001472 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001473 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001474 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001475 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001476 // Event for a package being on the temporary whitelist.
1477 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001478 // Event for the screen waking up.
1479 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001480 // Event for the UID that woke up the application processor.
1481 // Used for wakeups coming from WiFi, modem, etc.
1482 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001483 // Event for reporting that a specific partial wake lock has been held for a long duration.
1484 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001485
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001486 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001487 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001488 // Mask to extract out only the type part of the event.
1489 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001490
1491 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1492 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1493 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1494 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1495 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1496 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001497 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1498 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001499 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1500 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001501 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1502 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1503 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1504 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1505 public static final int EVENT_USER_FOREGROUND_START =
1506 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1507 public static final int EVENT_USER_FOREGROUND_FINISH =
1508 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001509 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1510 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001511 public static final int EVENT_TEMP_WHITELIST_START =
1512 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1513 public static final int EVENT_TEMP_WHITELIST_FINISH =
1514 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001515 public static final int EVENT_LONG_WAKE_LOCK_START =
1516 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1517 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1518 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001519
1520 // For CMD_EVENT.
1521 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001522 public HistoryTag eventTag;
1523
Dianne Hackborn9a755432014-05-15 17:05:22 -07001524 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001525 public long currentTime;
1526
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001527 // Meta-data when reading.
1528 public int numReadInts;
1529
1530 // Pre-allocated objects.
1531 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001532 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001533 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001534
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001535 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001536 }
Bookatzc8c44962017-05-11 12:12:54 -07001537
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001538 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001539 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001540 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001541 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001542 }
Bookatzc8c44962017-05-11 12:12:54 -07001543
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001544 public int describeContents() {
1545 return 0;
1546 }
1547
1548 public void writeToParcel(Parcel dest, int flags) {
1549 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001550 int bat = (((int)cmd)&0xff)
1551 | ((((int)batteryLevel)<<8)&0xff00)
1552 | ((((int)batteryStatus)<<16)&0xf0000)
1553 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001554 | ((((int)batteryPlugType)<<24)&0xf000000)
1555 | (wakelockTag != null ? 0x10000000 : 0)
1556 | (wakeReasonTag != null ? 0x20000000 : 0)
1557 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001558 dest.writeInt(bat);
1559 bat = (((int)batteryTemperature)&0xffff)
1560 | ((((int)batteryVoltage)<<16)&0xffff0000);
1561 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001562 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001563 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001564 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001565 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001566 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001567 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001568 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001569 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001570 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001571 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001572 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001573 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001574 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001575 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001576 dest.writeLong(currentTime);
1577 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001578 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001579
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001580 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001581 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001582 int bat = src.readInt();
1583 cmd = (byte)(bat&0xff);
1584 batteryLevel = (byte)((bat>>8)&0xff);
1585 batteryStatus = (byte)((bat>>16)&0xf);
1586 batteryHealth = (byte)((bat>>20)&0xf);
1587 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001588 int bat2 = src.readInt();
1589 batteryTemperature = (short)(bat2&0xffff);
1590 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001591 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001592 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001593 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001594 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001595 wakelockTag = localWakelockTag;
1596 wakelockTag.readFromParcel(src);
1597 } else {
1598 wakelockTag = null;
1599 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001600 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001601 wakeReasonTag = localWakeReasonTag;
1602 wakeReasonTag.readFromParcel(src);
1603 } else {
1604 wakeReasonTag = null;
1605 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001606 if ((bat&0x40000000) != 0) {
1607 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001608 eventTag = localEventTag;
1609 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001610 } else {
1611 eventCode = EVENT_NONE;
1612 eventTag = null;
1613 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001614 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001615 currentTime = src.readLong();
1616 } else {
1617 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001618 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001619 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001620 }
1621
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001622 public void clear() {
1623 time = 0;
1624 cmd = CMD_NULL;
1625 batteryLevel = 0;
1626 batteryStatus = 0;
1627 batteryHealth = 0;
1628 batteryPlugType = 0;
1629 batteryTemperature = 0;
1630 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001631 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001632 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001633 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001634 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001635 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001636 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001637 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001638 }
Bookatzc8c44962017-05-11 12:12:54 -07001639
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001640 public void setTo(HistoryItem o) {
1641 time = o.time;
1642 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001643 setToCommon(o);
1644 }
1645
1646 public void setTo(long time, byte cmd, HistoryItem o) {
1647 this.time = time;
1648 this.cmd = cmd;
1649 setToCommon(o);
1650 }
1651
1652 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001653 batteryLevel = o.batteryLevel;
1654 batteryStatus = o.batteryStatus;
1655 batteryHealth = o.batteryHealth;
1656 batteryPlugType = o.batteryPlugType;
1657 batteryTemperature = o.batteryTemperature;
1658 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001659 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001660 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001661 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001662 if (o.wakelockTag != null) {
1663 wakelockTag = localWakelockTag;
1664 wakelockTag.setTo(o.wakelockTag);
1665 } else {
1666 wakelockTag = null;
1667 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001668 if (o.wakeReasonTag != null) {
1669 wakeReasonTag = localWakeReasonTag;
1670 wakeReasonTag.setTo(o.wakeReasonTag);
1671 } else {
1672 wakeReasonTag = null;
1673 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001674 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001675 if (o.eventTag != null) {
1676 eventTag = localEventTag;
1677 eventTag.setTo(o.eventTag);
1678 } else {
1679 eventTag = null;
1680 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001681 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001682 }
1683
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001684 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001685 return batteryLevel == o.batteryLevel
1686 && batteryStatus == o.batteryStatus
1687 && batteryHealth == o.batteryHealth
1688 && batteryPlugType == o.batteryPlugType
1689 && batteryTemperature == o.batteryTemperature
1690 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001691 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001692 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001693 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001694 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001695 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001696
1697 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001698 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001699 return false;
1700 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001701 if (wakelockTag != o.wakelockTag) {
1702 if (wakelockTag == null || o.wakelockTag == null) {
1703 return false;
1704 }
1705 if (!wakelockTag.equals(o.wakelockTag)) {
1706 return false;
1707 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001708 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001709 if (wakeReasonTag != o.wakeReasonTag) {
1710 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1711 return false;
1712 }
1713 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1714 return false;
1715 }
1716 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001717 if (eventTag != o.eventTag) {
1718 if (eventTag == null || o.eventTag == null) {
1719 return false;
1720 }
1721 if (!eventTag.equals(o.eventTag)) {
1722 return false;
1723 }
1724 }
1725 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001726 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001727 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001728
1729 public final static class HistoryEventTracker {
1730 private final HashMap<String, SparseIntArray>[] mActiveEvents
1731 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1732
1733 public boolean updateState(int code, String name, int uid, int poolIdx) {
1734 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1735 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1736 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1737 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001738 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001739 mActiveEvents[idx] = active;
1740 }
1741 SparseIntArray uids = active.get(name);
1742 if (uids == null) {
1743 uids = new SparseIntArray();
1744 active.put(name, uids);
1745 }
1746 if (uids.indexOfKey(uid) >= 0) {
1747 // Already set, nothing to do!
1748 return false;
1749 }
1750 uids.put(uid, poolIdx);
1751 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1752 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1753 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1754 if (active == null) {
1755 // not currently active, nothing to do.
1756 return false;
1757 }
1758 SparseIntArray uids = active.get(name);
1759 if (uids == null) {
1760 // not currently active, nothing to do.
1761 return false;
1762 }
1763 idx = uids.indexOfKey(uid);
1764 if (idx < 0) {
1765 // not currently active, nothing to do.
1766 return false;
1767 }
1768 uids.removeAt(idx);
1769 if (uids.size() <= 0) {
1770 active.remove(name);
1771 }
1772 }
1773 return true;
1774 }
1775
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001776 public void removeEvents(int code) {
1777 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1778 mActiveEvents[idx] = null;
1779 }
1780
Dianne Hackborn37de0982014-05-09 09:32:18 -07001781 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1782 return mActiveEvents[code];
1783 }
1784 }
1785
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001786 public static final class BitDescription {
1787 public final int mask;
1788 public final int shift;
1789 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001790 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001791 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001792 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001793
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001794 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001795 this.mask = mask;
1796 this.shift = -1;
1797 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001798 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001799 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001800 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001801 }
Bookatzc8c44962017-05-11 12:12:54 -07001802
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001803 public BitDescription(int mask, int shift, String name, String shortName,
1804 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001805 this.mask = mask;
1806 this.shift = shift;
1807 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001808 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001809 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001810 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001811 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001812 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001813
Dianne Hackbornfc064132014-06-02 12:42:12 -07001814 /**
1815 * Don't allow any more batching in to the current history event. This
1816 * is called when printing partial histories, so to ensure that the next
1817 * history event will go in to a new batch after what was printed in the
1818 * last partial history.
1819 */
1820 public abstract void commitCurrentHistoryBatchLocked();
1821
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001822 public abstract int getHistoryTotalSize();
1823
1824 public abstract int getHistoryUsedSize();
1825
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001826 public abstract boolean startIteratingHistoryLocked();
1827
Dianne Hackborn099bc622014-01-22 13:39:16 -08001828 public abstract int getHistoryStringPoolSize();
1829
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001830 public abstract int getHistoryStringPoolBytes();
1831
1832 public abstract String getHistoryTagPoolString(int index);
1833
1834 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001835
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001836 public abstract boolean getNextHistoryLocked(HistoryItem out);
1837
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001838 public abstract void finishIteratingHistoryLocked();
1839
1840 public abstract boolean startIteratingOldHistoryLocked();
1841
1842 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1843
1844 public abstract void finishIteratingOldHistoryLocked();
1845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001847 * Return the base time offset for the battery history.
1848 */
1849 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001850
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001851 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 * Returns the number of times the device has been started.
1853 */
1854 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001857 * 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 -08001858 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001859 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 * {@hide}
1861 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001862 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001863
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001864 /**
1865 * Returns the number of times the screen was turned on.
1866 *
1867 * {@hide}
1868 */
1869 public abstract int getScreenOnCount(int which);
1870
Mike Mac2f518a2017-09-19 16:06:03 -07001871 /**
1872 * Returns the time in microseconds that the screen has been dozing while the device was
1873 * running on battery.
1874 *
1875 * {@hide}
1876 */
1877 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
1878
1879 /**
1880 * Returns the number of times the screen was turned dozing.
1881 *
1882 * {@hide}
1883 */
1884 public abstract int getScreenDozeCount(int which);
1885
Jeff Browne95c3cd2014-05-02 16:59:26 -07001886 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1887
Dianne Hackborn617f8772009-03-31 15:04:46 -07001888 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1889 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1890 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1891 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1892 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001893
Dianne Hackborn617f8772009-03-31 15:04:46 -07001894 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1895 "dark", "dim", "medium", "light", "bright"
1896 };
Bookatzc8c44962017-05-11 12:12:54 -07001897
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001898 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1899 "0", "1", "2", "3", "4"
1900 };
1901
Dianne Hackborn617f8772009-03-31 15:04:46 -07001902 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001903
Dianne Hackborn617f8772009-03-31 15:04:46 -07001904 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001905 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001906 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001907 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001908 * {@hide}
1909 */
1910 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001911 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07001914 * Returns the {@link Timer} object that tracks the given screen brightness.
1915 *
1916 * {@hide}
1917 */
1918 public abstract Timer getScreenBrightnessTimer(int brightnessBin);
1919
1920 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001921 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001922 * running on battery.
1923 *
1924 * {@hide}
1925 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001926 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001927
1928 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001929 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001930 *
1931 * {@hide}
1932 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001933 public abstract int getPowerSaveModeEnabledCount(int which);
1934
1935 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001936 * Constant for device idle mode: not active.
1937 */
1938 public static final int DEVICE_IDLE_MODE_OFF = 0;
1939
1940 /**
1941 * Constant for device idle mode: active in lightweight mode.
1942 */
1943 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1944
1945 /**
1946 * Constant for device idle mode: active in full mode.
1947 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001948 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001949
1950 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001951 * Returns the time in microseconds that device has been in idle mode while
1952 * running on battery.
1953 *
1954 * {@hide}
1955 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001956 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001957
1958 /**
1959 * Returns the number of times that the devie has gone in to idle mode.
1960 *
1961 * {@hide}
1962 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001963 public abstract int getDeviceIdleModeCount(int mode, int which);
1964
1965 /**
1966 * Return the longest duration we spent in a particular device idle mode (fully in the
1967 * mode, not in idle maintenance etc).
1968 */
1969 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001970
1971 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001972 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001973 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001974 * counts all of the time that we consider the device to be idle, whether or not
1975 * it is currently in the actual device idle mode.
1976 *
1977 * {@hide}
1978 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001979 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001980
1981 /**
1982 * Returns the number of times that the devie has started idling.
1983 *
1984 * {@hide}
1985 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001986 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001987
1988 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001989 * Returns the number of times that connectivity state changed.
1990 *
1991 * {@hide}
1992 */
1993 public abstract int getNumConnectivityChange(int which);
1994
1995 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001996 * 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 -08001997 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001998 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 * {@hide}
2000 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002001 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002002
Dianne Hackborn627bba72009-03-24 22:32:56 -07002003 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002004 * Returns the number of times a phone call was activated.
2005 *
2006 * {@hide}
2007 */
2008 public abstract int getPhoneOnCount(int which);
2009
2010 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002011 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002012 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002013 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002014 * {@hide}
2015 */
2016 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002017 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002018
Dianne Hackborn617f8772009-03-31 15:04:46 -07002019 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002020 * Returns the time in microseconds that the phone has been trying to
2021 * acquire a signal.
2022 *
2023 * {@hide}
2024 */
2025 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002026 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002027
2028 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002029 * Returns the {@link Timer} object that tracks how much the phone has been trying to
2030 * acquire a signal.
2031 *
2032 * {@hide}
2033 */
2034 public abstract Timer getPhoneSignalScanningTimer();
2035
2036 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002037 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002038 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002039 * {@hide}
2040 */
2041 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2042
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002043 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002044 * Return the {@link Timer} object used to track the given signal strength's duration and
2045 * counts.
2046 */
2047 protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin);
2048
2049 /**
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002050 * Returns the time in microseconds that the mobile network has been active
2051 * (in a high power state).
2052 *
2053 * {@hide}
2054 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002055 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002056
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002057 /**
2058 * Returns the number of times that the mobile network has transitioned to the
2059 * active state.
2060 *
2061 * {@hide}
2062 */
2063 public abstract int getMobileRadioActiveCount(int which);
2064
2065 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002066 * Returns the time in microseconds that is the difference between the mobile radio
2067 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2068 * from the radio.
2069 *
2070 * {@hide}
2071 */
2072 public abstract long getMobileRadioActiveAdjustedTime(int which);
2073
2074 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002075 * Returns the time in microseconds that the mobile network has been active
2076 * (in a high power state) but not being able to blame on an app.
2077 *
2078 * {@hide}
2079 */
2080 public abstract long getMobileRadioActiveUnknownTime(int which);
2081
2082 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002083 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002084 *
2085 * {@hide}
2086 */
2087 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002088
Dianne Hackborn627bba72009-03-24 22:32:56 -07002089 public static final int DATA_CONNECTION_NONE = 0;
2090 public static final int DATA_CONNECTION_GPRS = 1;
2091 public static final int DATA_CONNECTION_EDGE = 2;
2092 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002093 public static final int DATA_CONNECTION_CDMA = 4;
2094 public static final int DATA_CONNECTION_EVDO_0 = 5;
2095 public static final int DATA_CONNECTION_EVDO_A = 6;
2096 public static final int DATA_CONNECTION_1xRTT = 7;
2097 public static final int DATA_CONNECTION_HSDPA = 8;
2098 public static final int DATA_CONNECTION_HSUPA = 9;
2099 public static final int DATA_CONNECTION_HSPA = 10;
2100 public static final int DATA_CONNECTION_IDEN = 11;
2101 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002102 public static final int DATA_CONNECTION_LTE = 13;
2103 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002104 public static final int DATA_CONNECTION_HSPAP = 15;
2105 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002106
Dianne Hackborn627bba72009-03-24 22:32:56 -07002107 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002108 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002109 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002110 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002111 };
Bookatzc8c44962017-05-11 12:12:54 -07002112
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002113 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002114
Dianne Hackborn627bba72009-03-24 22:32:56 -07002115 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002116 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002117 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002118 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002119 * {@hide}
2120 */
2121 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002122 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002125 * Returns the number of times the phone has entered the given data
2126 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002127 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002128 * {@hide}
2129 */
2130 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002131
Kweku Adams87b19ec2017-10-09 12:40:03 -07002132 /**
2133 * Returns the {@link Timer} object that tracks the phone's data connection type stats.
2134 */
2135 public abstract Timer getPhoneDataConnectionTimer(int dataType);
2136
Dianne Hackborn3251b902014-06-20 14:40:53 -07002137 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2138 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2139 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2140 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2141 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2142 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2143 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2144 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2145 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2146 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2147 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2148 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2149 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2150
2151 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2152
2153 static final String[] WIFI_SUPPL_STATE_NAMES = {
2154 "invalid", "disconn", "disabled", "inactive", "scanning",
2155 "authenticating", "associating", "associated", "4-way-handshake",
2156 "group-handshake", "completed", "dormant", "uninit"
2157 };
2158
2159 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2160 "inv", "dsc", "dis", "inact", "scan",
2161 "auth", "ascing", "asced", "4-way",
2162 "group", "compl", "dorm", "uninit"
2163 };
2164
Mike Mac2f518a2017-09-19 16:06:03 -07002165 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002166 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002167 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2168 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002169 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002170 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2171 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2172 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002173 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002174 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002175 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002176 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002177 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2178 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002179 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002180 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2181 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2182 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2183 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2184 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2185 new String[] {"in", "out", "emergency", "off"},
2186 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002187 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2188 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2189 SignalStrength.SIGNAL_STRENGTH_NAMES,
2190 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002191 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2192 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2193 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002194 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002195
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002196 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2197 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002198 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002199 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002200 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002201 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002202 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002203 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2204 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2205 new String[] { "off", "light", "full", "???" },
2206 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002207 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2208 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2209 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002210 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2211 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2212 new String[] { "0", "1", "2", "3", "4" },
2213 new String[] { "0", "1", "2", "3", "4" }),
2214 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2215 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2216 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002217 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002218 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002219 };
2220
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002221 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002222 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002223 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2224 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002225 };
2226
2227 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002228 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002229 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002230 "Esw", "Ewa", "Elw", "Eec"
2231 };
2232
2233 @FunctionalInterface
2234 public interface IntToString {
2235 String applyAsString(int val);
2236 }
2237
2238 private static final IntToString sUidToString = UserHandle::formatUid;
2239 private static final IntToString sIntToString = Integer::toString;
2240
2241 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2242 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2243 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2244 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2245 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002246 };
2247
Dianne Hackborn617f8772009-03-31 15:04:46 -07002248 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002249 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002250 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002251 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002252 * {@hide}
2253 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002254 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002255
2256 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002257 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002258 * been in the running state while the device was running on battery.
2259 *
2260 * {@hide}
2261 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002262 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002263
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002264 public static final int WIFI_STATE_OFF = 0;
2265 public static final int WIFI_STATE_OFF_SCANNING = 1;
2266 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2267 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2268 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2269 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2270 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2271 public static final int WIFI_STATE_SOFT_AP = 7;
2272
2273 static final String[] WIFI_STATE_NAMES = {
2274 "off", "scanning", "no_net", "disconn",
2275 "sta", "p2p", "sta_p2p", "soft_ap"
2276 };
2277
2278 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2279
2280 /**
2281 * Returns the time in microseconds that WiFi has been running in the given state.
2282 *
2283 * {@hide}
2284 */
2285 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002286 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002287
2288 /**
2289 * Returns the number of times that WiFi has entered the given state.
2290 *
2291 * {@hide}
2292 */
2293 public abstract int getWifiStateCount(int wifiState, int which);
2294
The Android Open Source Project10592532009-03-18 17:39:46 -07002295 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002296 * Returns the {@link Timer} object that tracks the given WiFi state.
2297 *
2298 * {@hide}
2299 */
2300 public abstract Timer getWifiStateTimer(int wifiState);
2301
2302 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002303 * Returns the time in microseconds that the wifi supplicant has been
2304 * in a given state.
2305 *
2306 * {@hide}
2307 */
2308 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2309
2310 /**
2311 * Returns the number of times that the wifi supplicant has transitioned
2312 * to a given state.
2313 *
2314 * {@hide}
2315 */
2316 public abstract int getWifiSupplStateCount(int state, int which);
2317
Kweku Adams87b19ec2017-10-09 12:40:03 -07002318 /**
2319 * Returns the {@link Timer} object that tracks the given wifi supplicant state.
2320 *
2321 * {@hide}
2322 */
2323 public abstract Timer getWifiSupplStateTimer(int state);
2324
Dianne Hackborn3251b902014-06-20 14:40:53 -07002325 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2326
2327 /**
2328 * Returns the time in microseconds that WIFI has been running with
2329 * the given signal strength.
2330 *
2331 * {@hide}
2332 */
2333 public abstract long getWifiSignalStrengthTime(int strengthBin,
2334 long elapsedRealtimeUs, int which);
2335
2336 /**
2337 * Returns the number of times WIFI has entered the given signal strength.
2338 *
2339 * {@hide}
2340 */
2341 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2342
2343 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002344 * Returns the {@link Timer} object that tracks the given WIFI signal strength.
2345 *
2346 * {@hide}
2347 */
2348 public abstract Timer getWifiSignalStrengthTimer(int strengthBin);
2349
2350 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002351 * Returns the time in microseconds that the flashlight has been on while the device was
2352 * running on battery.
2353 *
2354 * {@hide}
2355 */
2356 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2357
2358 /**
2359 * Returns the number of times that the flashlight has been turned on while the device was
2360 * running on battery.
2361 *
2362 * {@hide}
2363 */
2364 public abstract long getFlashlightOnCount(int which);
2365
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002366 /**
2367 * Returns the time in microseconds that the camera has been on while the device was
2368 * running on battery.
2369 *
2370 * {@hide}
2371 */
2372 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2373
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002374 /**
2375 * Returns the time in microseconds that bluetooth scans were running while the device was
2376 * on battery.
2377 *
2378 * {@hide}
2379 */
2380 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002381
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002382 public static final int NETWORK_MOBILE_RX_DATA = 0;
2383 public static final int NETWORK_MOBILE_TX_DATA = 1;
2384 public static final int NETWORK_WIFI_RX_DATA = 2;
2385 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002386 public static final int NETWORK_BT_RX_DATA = 4;
2387 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002388 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2389 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2390 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2391 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2392 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002393
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002394 public abstract long getNetworkActivityBytes(int type, int which);
2395 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002396
Adam Lesinskie08af192015-03-25 16:42:59 -07002397 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002398 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002399 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002400 * actual power data.
2401 */
2402 public abstract boolean hasWifiActivityReporting();
2403
2404 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002405 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2406 * in various radio controller states, such as transmit, receive, and idle.
2407 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002408 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002409 public abstract ControllerActivityCounter getWifiControllerActivity();
2410
2411 /**
2412 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2413 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2414 * actual power data.
2415 */
2416 public abstract boolean hasBluetoothActivityReporting();
2417
2418 /**
2419 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2420 * in various radio controller states, such as transmit, receive, and idle.
2421 * @return non-null {@link ControllerActivityCounter}
2422 */
2423 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2424
2425 /**
2426 * Returns true if the BatteryStats object has detailed modem power reports.
2427 * When true, calling {@link #getModemControllerActivity()} will yield the
2428 * actual power data.
2429 */
2430 public abstract boolean hasModemActivityReporting();
2431
2432 /**
2433 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2434 * in various radio controller states, such as transmit, receive, and idle.
2435 * @return non-null {@link ControllerActivityCounter}
2436 */
2437 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002438
The Android Open Source Project10592532009-03-18 17:39:46 -07002439 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002440 * Return the wall clock time when battery stats data collection started.
2441 */
2442 public abstract long getStartClockTime();
2443
2444 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002445 * Return platform version tag that we were running in when the battery stats started.
2446 */
2447 public abstract String getStartPlatformVersion();
2448
2449 /**
2450 * Return platform version tag that we were running in when the battery stats ended.
2451 */
2452 public abstract String getEndPlatformVersion();
2453
2454 /**
2455 * Return the internal version code of the parcelled format.
2456 */
2457 public abstract int getParcelVersion();
2458
2459 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 * Return whether we are currently running on battery.
2461 */
2462 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 /**
2465 * Returns a SparseArray containing the statistics for each uid.
2466 */
2467 public abstract SparseArray<? extends Uid> getUidStats();
2468
2469 /**
2470 * Returns the current battery uptime in microseconds.
2471 *
2472 * @param curTime the amount of elapsed realtime in microseconds.
2473 */
2474 public abstract long getBatteryUptime(long curTime);
2475
2476 /**
2477 * Returns the current battery realtime in microseconds.
2478 *
2479 * @param curTime the amount of elapsed realtime in microseconds.
2480 */
2481 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002482
The Android Open Source Project10592532009-03-18 17:39:46 -07002483 /**
Evan Millar633a1742009-04-02 16:36:33 -07002484 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002485 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002486 */
Evan Millar633a1742009-04-02 16:36:33 -07002487 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002488
The Android Open Source Project10592532009-03-18 17:39:46 -07002489 /**
Evan Millar633a1742009-04-02 16:36:33 -07002490 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2491 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002492 */
Evan Millar633a1742009-04-02 16:36:33 -07002493 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494
2495 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002496 * Get the amount the battery has discharged since the stats were
2497 * last reset after charging, as a lower-end approximation.
2498 */
2499 public abstract int getLowDischargeAmountSinceCharge();
2500
2501 /**
2502 * Get the amount the battery has discharged since the stats were
2503 * last reset after charging, as an upper-end approximation.
2504 */
2505 public abstract int getHighDischargeAmountSinceCharge();
2506
2507 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002508 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2509 */
2510 public abstract int getDischargeAmount(int which);
2511
2512 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002513 * Get the amount the battery has discharged while the screen was on,
2514 * since the last time power was unplugged.
2515 */
2516 public abstract int getDischargeAmountScreenOn();
2517
2518 /**
2519 * Get the amount the battery has discharged while the screen was on,
2520 * since the last time the device was charged.
2521 */
2522 public abstract int getDischargeAmountScreenOnSinceCharge();
2523
2524 /**
2525 * Get the amount the battery has discharged while the screen was off,
2526 * since the last time power was unplugged.
2527 */
2528 public abstract int getDischargeAmountScreenOff();
2529
2530 /**
2531 * Get the amount the battery has discharged while the screen was off,
2532 * since the last time the device was charged.
2533 */
2534 public abstract int getDischargeAmountScreenOffSinceCharge();
2535
2536 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002537 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002538 * since the last time power was unplugged.
2539 */
2540 public abstract int getDischargeAmountScreenDoze();
2541
2542 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002543 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002544 * since the last time the device was charged.
2545 */
2546 public abstract int getDischargeAmountScreenDozeSinceCharge();
2547
2548 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 * Returns the total, last, or current battery uptime in microseconds.
2550 *
2551 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002552 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 */
2554 public abstract long computeBatteryUptime(long curTime, int which);
2555
2556 /**
2557 * Returns the total, last, or current battery realtime in microseconds.
2558 *
2559 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002560 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 */
2562 public abstract long computeBatteryRealtime(long curTime, int which);
2563
2564 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002565 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002566 *
2567 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002568 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002569 */
2570 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2571
2572 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002573 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002574 *
2575 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002576 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002577 */
2578 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2579
2580 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 * Returns the total, last, or current uptime in microseconds.
2582 *
2583 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002584 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 */
2586 public abstract long computeUptime(long curTime, int which);
2587
2588 /**
2589 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002590 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002592 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 */
2594 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002595
2596 /**
2597 * Compute an approximation for how much run time (in microseconds) is remaining on
2598 * the battery. Returns -1 if no time can be computed: either there is not
2599 * enough current data to make a decision, or the battery is currently
2600 * charging.
2601 *
2602 * @param curTime The current elepsed realtime in microseconds.
2603 */
2604 public abstract long computeBatteryTimeRemaining(long curTime);
2605
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002606 // The part of a step duration that is the actual time.
2607 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2608
2609 // Bits in a step duration that are the new battery level we are at.
2610 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002611 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002612
2613 // Bits in a step duration that are the initial mode we were in at that step.
2614 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002615 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002616
2617 // Bits in a step duration that indicate which modes changed during that step.
2618 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002619 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002620
2621 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2622 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2623
Santos Cordone94f0502017-02-24 12:31:20 -08002624 // The largest value for screen state that is tracked in battery states. Any values above
2625 // this should be mapped back to one of the tracked values before being tracked here.
2626 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2627
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002628 // Step duration mode: power save is on.
2629 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2630
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002631 // Step duration mode: device is currently in idle mode.
2632 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2633
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002634 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2635 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002636 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2637 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002638 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2639 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2640 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2641 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2642 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002643 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2644 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002645 };
2646 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2647 (Display.STATE_OFF-1),
2648 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002649 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002650 (Display.STATE_ON-1),
2651 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2652 (Display.STATE_DOZE-1),
2653 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2654 (Display.STATE_DOZE_SUSPEND-1),
2655 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002656 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002657 };
2658 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2659 "screen off",
2660 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002661 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002662 "screen on",
2663 "screen on power save",
2664 "screen doze",
2665 "screen doze power save",
2666 "screen doze-suspend",
2667 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002668 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002669 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002670
2671 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002672 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002673 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2674 * a coulomb counter.
2675 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002676 public abstract long getUahDischargeScreenOff(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002677
2678 /**
2679 * Return the amount of battery discharge while the screen was in doze mode, measured in
2680 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2681 * a coulomb counter.
2682 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002683 public abstract long getUahDischargeScreenDoze(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002684
2685 /**
2686 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2687 * non-zero only if the device's battery has a coulomb counter.
2688 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002689 public abstract long getUahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002690
2691 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002692 * Returns the estimated real battery capacity, which may be less than the capacity
2693 * declared by the PowerProfile.
2694 * @return The estimated battery capacity in mAh.
2695 */
2696 public abstract int getEstimatedBatteryCapacity();
2697
2698 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002699 * @return The minimum learned battery capacity in uAh.
2700 */
2701 public abstract int getMinLearnedBatteryCapacity();
2702
2703 /**
2704 * @return The maximum learned battery capacity in uAh.
2705 */
2706 public abstract int getMaxLearnedBatteryCapacity() ;
2707
2708 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002709 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002710 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002711 public abstract LevelStepTracker getDischargeLevelStepTracker();
2712
2713 /**
2714 * Return the array of daily discharge step durations.
2715 */
2716 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002717
2718 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002719 * Compute an approximation for how much time (in microseconds) remains until the battery
2720 * is fully charged. Returns -1 if no time can be computed: either there is not
2721 * enough current data to make a decision, or the battery is currently
2722 * discharging.
2723 *
2724 * @param curTime The current elepsed realtime in microseconds.
2725 */
2726 public abstract long computeChargeTimeRemaining(long curTime);
2727
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002728 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002729 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002730 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002731 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002732
2733 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002734 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002735 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002736 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002737
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002738 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2739
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002740 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002741
Evan Millarc64edde2009-04-18 12:26:32 -07002742 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743
Bookatz50df7112017-08-04 14:53:26 -07002744 /**
2745 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2746 */
2747 public abstract Map<String, ? extends Timer> getRpmStats();
2748 /**
2749 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2750 */
2751 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2752
2753
James Carr2dd7e5e2016-07-20 18:48:39 -07002754 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2755
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002756 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2757
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002758 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 long days = seconds / (60 * 60 * 24);
2760 if (days != 0) {
2761 out.append(days);
2762 out.append("d ");
2763 }
2764 long used = days * 60 * 60 * 24;
2765
2766 long hours = (seconds - used) / (60 * 60);
2767 if (hours != 0 || used != 0) {
2768 out.append(hours);
2769 out.append("h ");
2770 }
2771 used += hours * 60 * 60;
2772
2773 long mins = (seconds-used) / 60;
2774 if (mins != 0 || used != 0) {
2775 out.append(mins);
2776 out.append("m ");
2777 }
2778 used += mins * 60;
2779
2780 if (seconds != 0 || used != 0) {
2781 out.append(seconds-used);
2782 out.append("s ");
2783 }
2784 }
2785
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002786 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002788 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 sb.append(time - (sec * 1000));
2790 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 }
2792
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002793 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002794 long sec = time / 1000;
2795 formatTimeRaw(sb, sec);
2796 sb.append(time - (sec * 1000));
2797 sb.append("ms");
2798 }
2799
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002800 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002802 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 }
2804 float perc = ((float)num) / ((float)den) * 100;
2805 mFormatBuilder.setLength(0);
2806 mFormatter.format("%.1f%%", perc);
2807 return mFormatBuilder.toString();
2808 }
2809
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002810 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002811 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002812
Evan Millar22ac0432009-03-31 11:33:18 -07002813 if (bytes < BYTES_PER_KB) {
2814 return bytes + "B";
2815 } else if (bytes < BYTES_PER_MB) {
2816 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2817 return mFormatBuilder.toString();
2818 } else if (bytes < BYTES_PER_GB){
2819 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2820 return mFormatBuilder.toString();
2821 } else {
2822 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2823 return mFormatBuilder.toString();
2824 }
2825 }
2826
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002827 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002828 if (timer != null) {
2829 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002830 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002831 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2832 return totalTimeMillis;
2833 }
2834 return 0;
2835 }
2836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 /**
2838 *
2839 * @param sb a StringBuilder object.
2840 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002841 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002843 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 * @param linePrefix a String to be prepended to each line of output.
2845 * @return the line prefix
2846 */
2847 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002848 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002851 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002852
Evan Millarc64edde2009-04-18 12:26:32 -07002853 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 if (totalTimeMillis != 0) {
2855 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002856 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002857 if (name != null) {
2858 sb.append(name);
2859 sb.append(' ');
2860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 sb.append('(');
2862 sb.append(count);
2863 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002864 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2865 if (maxDurationMs >= 0) {
2866 sb.append(" max=");
2867 sb.append(maxDurationMs);
2868 }
Bookatz506a8182017-05-01 14:18:42 -07002869 // Put actual time if it is available and different from totalTimeMillis.
2870 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2871 if (totalDurMs > totalTimeMillis) {
2872 sb.append(" actual=");
2873 sb.append(totalDurMs);
2874 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002875 if (timer.isRunningLocked()) {
2876 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2877 if (currentMs >= 0) {
2878 sb.append(" (running for ");
2879 sb.append(currentMs);
2880 sb.append("ms)");
2881 } else {
2882 sb.append(" (running)");
2883 }
2884 }
2885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 return ", ";
2887 }
2888 }
2889 return linePrefix;
2890 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002891
2892 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002893 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002894 *
2895 * @param pw a PrintWriter object to print to.
2896 * @param sb a StringBuilder object.
2897 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002898 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002899 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2900 * @param prefix a String to be prepended to each line of output.
2901 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002902 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002903 */
2904 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002905 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002906 if (timer != null) {
2907 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002908 final long totalTimeMs = (timer.getTotalTimeLocked(
2909 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002910 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002911 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002912 sb.setLength(0);
2913 sb.append(prefix);
2914 sb.append(" ");
2915 sb.append(type);
2916 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002917 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002918 sb.append("realtime (");
2919 sb.append(count);
2920 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002921 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2922 if (maxDurationMs >= 0) {
2923 sb.append(" max=");
2924 sb.append(maxDurationMs);
2925 }
2926 if (timer.isRunningLocked()) {
2927 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2928 if (currentMs >= 0) {
2929 sb.append(" (running for ");
2930 sb.append(currentMs);
2931 sb.append("ms)");
2932 } else {
2933 sb.append(" (running)");
2934 }
2935 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002936 pw.println(sb.toString());
2937 return true;
2938 }
2939 }
2940 return false;
2941 }
Bookatzc8c44962017-05-11 12:12:54 -07002942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 /**
2944 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002945 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 * @param sb a StringBuilder object.
2947 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002948 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002950 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 * @param linePrefix a String to be prepended to each line of output.
2952 * @return the line prefix
2953 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002954 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2955 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 long totalTimeMicros = 0;
2957 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002958 long max = 0;
2959 long current = 0;
2960 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002962 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002963 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002964 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2965 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002966 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
2968 sb.append(linePrefix);
2969 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2970 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002971 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002973 sb.append(',');
2974 sb.append(current);
2975 sb.append(',');
2976 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002977 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2978 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2979 // totalDuration independent of totalTimeMicros (since they are not pooled).
2980 if (name != null) {
2981 sb.append(',');
2982 sb.append(totalDuration);
2983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 return ",";
2985 }
Bookatz506a8182017-05-01 14:18:42 -07002986
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002987 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2988 String type) {
2989 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2990 pw.print(',');
2991 pw.print(uid);
2992 pw.print(',');
2993 pw.print(category);
2994 pw.print(',');
2995 pw.print(type);
2996 }
2997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 /**
2999 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07003000 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 * @param pw the PageWriter to dump log to
3002 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3003 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3004 * @param args type-dependent data arguments
3005 */
Bookatzc8c44962017-05-11 12:12:54 -07003006 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003008 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003009 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003010 pw.print(',');
3011 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003013 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07003015
3016 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003017 * Dump a given timer stat for terse checkin mode.
3018 *
3019 * @param pw the PageWriter to dump log to
3020 * @param uid the UID to log
3021 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3022 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3023 * @param timer a {@link Timer} to dump stats for
3024 * @param rawRealtime the current elapsed realtime of the system in microseconds
3025 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3026 */
3027 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
3028 Timer timer, long rawRealtime, int which) {
3029 if (timer != null) {
3030 // Convert from microseconds to milliseconds with rounding
3031 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3032 / 1000;
3033 final int count = timer.getCountLocked(which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003034 if (totalTime != 0 || count != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003035 dumpLine(pw, uid, category, type, totalTime, count);
3036 }
3037 }
3038 }
3039
3040 /**
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003041 * Dump a given timer stat to the proto stream.
3042 *
3043 * @param proto the ProtoOutputStream to log to
3044 * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK)
3045 * @param timer a {@link Timer} to dump stats for
3046 * @param rawRealtimeUs the current elapsed realtime of the system in microseconds
3047 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3048 */
3049 private static void dumpTimer(ProtoOutputStream proto, long fieldId,
Kweku Adams87b19ec2017-10-09 12:40:03 -07003050 Timer timer, long rawRealtimeUs, int which) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003051 if (timer == null) {
3052 return;
3053 }
3054 // Convert from microseconds to milliseconds with rounding
Kweku Adams87b19ec2017-10-09 12:40:03 -07003055 final long totalTimeMs = (timer.getTotalTimeLocked(rawRealtimeUs, which) + 500) / 1000;
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003056 final int count = timer.getCountLocked(which);
3057 if (totalTimeMs != 0 || count != 0) {
3058 final long token = proto.start(fieldId);
3059 proto.write(TimerProto.DURATION_MS, totalTimeMs);
3060 proto.write(TimerProto.COUNT, count);
3061 proto.end(token);
3062 }
3063 }
3064
3065 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003066 * Checks if the ControllerActivityCounter has any data worth dumping.
3067 */
3068 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
3069 if (counter == null) {
3070 return false;
3071 }
3072
3073 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
3074 || counter.getRxTimeCounter().getCountLocked(which) != 0
3075 || counter.getPowerCounter().getCountLocked(which) != 0) {
3076 return true;
3077 }
3078
3079 for (LongCounter c : counter.getTxTimeCounters()) {
3080 if (c.getCountLocked(which) != 0) {
3081 return true;
3082 }
3083 }
3084 return false;
3085 }
3086
3087 /**
3088 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3089 * The order of the arguments in the final check in line is:
3090 *
3091 * idle, rx, power, tx...
3092 *
3093 * where tx... is one or more transmit level times.
3094 */
3095 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3096 String type,
3097 ControllerActivityCounter counter,
3098 int which) {
3099 if (!controllerActivityHasData(counter, which)) {
3100 return;
3101 }
3102
3103 dumpLineHeader(pw, uid, category, type);
3104 pw.print(",");
3105 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3106 pw.print(",");
3107 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3108 pw.print(",");
3109 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3110 for (LongCounter c : counter.getTxTimeCounters()) {
3111 pw.print(",");
3112 pw.print(c.getCountLocked(which));
3113 }
3114 pw.println();
3115 }
3116
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003117 /**
3118 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3119 */
3120 private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId,
3121 ControllerActivityCounter counter,
3122 int which) {
3123 if (!controllerActivityHasData(counter, which)) {
3124 return;
3125 }
3126
3127 final long cToken = proto.start(fieldId);
3128
3129 proto.write(ControllerActivityProto.IDLE_DURATION_MS,
3130 counter.getIdleTimeCounter().getCountLocked(which));
3131 proto.write(ControllerActivityProto.RX_DURATION_MS,
3132 counter.getRxTimeCounter().getCountLocked(which));
3133 proto.write(ControllerActivityProto.POWER_MAH,
3134 counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3135
3136 long tToken;
3137 LongCounter[] txCounters = counter.getTxTimeCounters();
3138 for (int i = 0; i < txCounters.length; ++i) {
3139 LongCounter c = txCounters[i];
3140 tToken = proto.start(ControllerActivityProto.TX);
3141 proto.write(ControllerActivityProto.TxLevel.LEVEL, i);
3142 proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which));
3143 proto.end(tToken);
3144 }
3145
3146 proto.end(cToken);
3147 }
3148
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003149 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3150 String prefix, String controllerName,
3151 ControllerActivityCounter counter,
3152 int which) {
3153 if (controllerActivityHasData(counter, which)) {
3154 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3155 }
3156 }
3157
3158 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3159 String controllerName,
3160 ControllerActivityCounter counter, int which) {
3161 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3162 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3163 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
3164 long totalTxTimeMs = 0;
3165 for (LongCounter txState : counter.getTxTimeCounters()) {
3166 totalTxTimeMs += txState.getCountLocked(which);
3167 }
3168
3169 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
3170
3171 sb.setLength(0);
3172 sb.append(prefix);
3173 sb.append(" ");
3174 sb.append(controllerName);
3175 sb.append(" Idle time: ");
3176 formatTimeMs(sb, idleTimeMs);
3177 sb.append("(");
3178 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
3179 sb.append(")");
3180 pw.println(sb.toString());
3181
3182 sb.setLength(0);
3183 sb.append(prefix);
3184 sb.append(" ");
3185 sb.append(controllerName);
3186 sb.append(" Rx time: ");
3187 formatTimeMs(sb, rxTimeMs);
3188 sb.append("(");
3189 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
3190 sb.append(")");
3191 pw.println(sb.toString());
3192
3193 sb.setLength(0);
3194 sb.append(prefix);
3195 sb.append(" ");
3196 sb.append(controllerName);
3197 sb.append(" Tx time: ");
3198 formatTimeMs(sb, totalTxTimeMs);
3199 sb.append("(");
3200 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
3201 sb.append(")");
3202 pw.println(sb.toString());
3203
3204 final int numTxLvls = counter.getTxTimeCounters().length;
3205 if (numTxLvls > 1) {
3206 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3207 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3208 sb.setLength(0);
3209 sb.append(prefix);
3210 sb.append(" [");
3211 sb.append(lvl);
3212 sb.append("] ");
3213 formatTimeMs(sb, txLvlTimeMs);
3214 sb.append("(");
3215 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3216 sb.append(")");
3217 pw.println(sb.toString());
3218 }
3219 }
3220
3221 sb.setLength(0);
3222 sb.append(prefix);
3223 sb.append(" ");
3224 sb.append(controllerName);
3225 sb.append(" Power drain: ").append(
3226 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3227 sb.append("mAh");
3228 pw.println(sb.toString());
3229 }
3230
3231 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003232 * Temporary for settings.
3233 */
3234 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3235 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3236 }
3237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 /**
3239 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003240 *
Kweku Adams87b19ec2017-10-09 12:40:03 -07003241 * NOTE: all times are expressed in microseconds, unless specified otherwise.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003243 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3244 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 final long rawUptime = SystemClock.uptimeMillis() * 1000;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003246 final long rawRealtimeMs = SystemClock.elapsedRealtime();
3247 final long rawRealtime = rawRealtimeMs * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3250 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003251 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3252 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3253 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 final long totalRealtime = computeRealtime(rawRealtime, which);
3255 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003256 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003257 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003258 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003259 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003260 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3261 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003262 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003263 rawRealtime, which);
3264 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3265 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003266 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003267 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003268 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003269 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003270 final long dischargeCount = getUahDischarge(which);
3271 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
3272 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003273
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003274 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003275
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003276 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003277 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003278
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003279 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003282 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003283 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003284 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003285 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003286 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003287 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003288 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003289 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3290 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003291
Bookatzc8c44962017-05-11 12:12:54 -07003292
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003293 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003294 long fullWakeLockTimeTotal = 0;
3295 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003296
Evan Millar22ac0432009-03-31 11:33:18 -07003297 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003298 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003299
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003300 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3301 = u.getWakelockStats();
3302 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3303 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003304
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003305 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3306 if (fullWakeTimer != null) {
3307 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3308 which);
3309 }
3310
3311 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3312 if (partialWakeTimer != null) {
3313 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3314 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003315 }
3316 }
3317 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003318
3319 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003320 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3321 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3322 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3323 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3324 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3325 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3326 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3327 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003328 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3329 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003330 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3331 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003332 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3333 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003334
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003335 // Dump Modem controller stats
3336 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3337 getModemControllerActivity(), which);
3338
Adam Lesinskie283d332015-04-16 12:29:25 -07003339 // Dump Wifi controller stats
3340 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3341 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003342 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003343 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003344
3345 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3346 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003347
3348 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003349 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3350 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 // Dump misc stats
3353 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003354 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003355 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003356 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003357 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003358 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003359 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3360 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003361 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003362 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3363 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3364 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3365 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003366 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003367
Dianne Hackborn617f8772009-03-31 15:04:46 -07003368 // Dump screen brightness stats
3369 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3370 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003371 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003372 }
3373 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003374
Dianne Hackborn627bba72009-03-24 22:32:56 -07003375 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003376 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3377 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003378 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003379 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003380 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003381 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003382 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003383 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003384 args[i] = getPhoneSignalStrengthCount(i, which);
3385 }
3386 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003387
Dianne Hackborn627bba72009-03-24 22:32:56 -07003388 // Dump network type stats
3389 args = new Object[NUM_DATA_CONNECTION_TYPES];
3390 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003391 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003392 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003393 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3394 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3395 args[i] = getPhoneDataConnectionCount(i, which);
3396 }
3397 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003398
3399 // Dump wifi state stats
3400 args = new Object[NUM_WIFI_STATES];
3401 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003402 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003403 }
3404 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3405 for (int i=0; i<NUM_WIFI_STATES; i++) {
3406 args[i] = getWifiStateCount(i, which);
3407 }
3408 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3409
Dianne Hackborn3251b902014-06-20 14:40:53 -07003410 // Dump wifi suppl state stats
3411 args = new Object[NUM_WIFI_SUPPL_STATES];
3412 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3413 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3414 }
3415 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3416 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3417 args[i] = getWifiSupplStateCount(i, which);
3418 }
3419 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3420
3421 // Dump wifi signal strength stats
3422 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3423 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3424 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3425 }
3426 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3427 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3428 args[i] = getWifiSignalStrengthCount(i, which);
3429 }
3430 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3431
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003432 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003433 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003434 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003435 }
Bookatzc8c44962017-05-11 12:12:54 -07003436
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003437 if (which == STATS_SINCE_UNPLUGGED) {
3438 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3439 getDischargeStartLevel()-getDischargeCurrentLevel(),
3440 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003441 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003442 dischargeCount / 1000, dischargeScreenOffCount / 1000,
3443 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003444 } else {
3445 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3446 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003447 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003448 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003449 dischargeCount / 1000, dischargeScreenOffCount / 1000,
3450 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003451 }
Bookatzc8c44962017-05-11 12:12:54 -07003452
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003453 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003454 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003455 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003456 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003457 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003458 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003459 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3460 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003461 }
Evan Millarc64edde2009-04-18 12:26:32 -07003462 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003463 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003464 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003465 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3466 // Not doing the regular wake lock formatting to remain compatible
3467 // with the old checkin format.
3468 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3469 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003470 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003471 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003472 }
3473 }
Evan Millarc64edde2009-04-18 12:26:32 -07003474 }
Bookatzc8c44962017-05-11 12:12:54 -07003475
Bookatz50df7112017-08-04 14:53:26 -07003476 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3477 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3478 if (rpmStats.size() > 0) {
3479 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3480 sb.setLength(0);
3481 Timer totalTimer = ent.getValue();
3482 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3483 int count = totalTimer.getCountLocked(which);
3484 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3485 long screenOffTimeMs = screenOffTimer != null
3486 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3487 int screenOffCount = screenOffTimer != null
3488 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003489 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3490 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3491 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3492 screenOffCount);
3493 } else {
3494 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3495 "\"" + ent.getKey() + "\"", timeMs, count);
3496 }
Bookatz50df7112017-08-04 14:53:26 -07003497 }
3498 }
3499
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003500 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003501 helper.create(this);
3502 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003503 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003504 if (sippers != null && sippers.size() > 0) {
3505 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3506 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003507 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003508 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3509 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
Kweku Adams87b19ec2017-10-09 12:40:03 -07003510 int uid = 0;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003511 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003512 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003513 String label;
3514 switch (bs.drainType) {
3515 case IDLE:
3516 label="idle";
3517 break;
3518 case CELL:
3519 label="cell";
3520 break;
3521 case PHONE:
3522 label="phone";
3523 break;
3524 case WIFI:
3525 label="wifi";
3526 break;
3527 case BLUETOOTH:
3528 label="blue";
3529 break;
3530 case SCREEN:
3531 label="scrn";
3532 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003533 case FLASHLIGHT:
3534 label="flashlight";
3535 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003536 case APP:
3537 uid = bs.uidObj.getUid();
3538 label = "uid";
3539 break;
3540 case USER:
3541 uid = UserHandle.getUid(bs.userId, 0);
3542 label = "user";
3543 break;
3544 case UNACCOUNTED:
3545 label = "unacc";
3546 break;
3547 case OVERCOUNTED:
3548 label = "over";
3549 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003550 case CAMERA:
3551 label = "camera";
3552 break;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003553 case MEMORY:
3554 label = "memory";
3555 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003556 default:
3557 label = "???";
3558 }
3559 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003560 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3561 bs.shouldHide ? 1 : 0,
3562 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3563 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003564 }
3565 }
3566
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003567 final long[] cpuFreqs = getCpuFreqs();
3568 if (cpuFreqs != null) {
3569 sb.setLength(0);
3570 for (int i = 0; i < cpuFreqs.length; ++i) {
3571 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3572 }
3573 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3574 }
3575
Kweku Adams87b19ec2017-10-09 12:40:03 -07003576 // Dump stats per UID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 for (int iu = 0; iu < NU; iu++) {
3578 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003579 if (reqUid >= 0 && uid != reqUid) {
3580 continue;
3581 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003582 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003585 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3586 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3587 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3588 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3589 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3590 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3591 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3592 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003593 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003594 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3595 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003596 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003597 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3598 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003599 // Background data transfers
3600 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3601 which);
3602 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3603 which);
3604 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3605 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3606 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3607 which);
3608 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3609 which);
3610 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3611 which);
3612 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3613 which);
3614
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003615 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3616 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003617 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003618 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3619 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3620 || wifiBytesBgTx > 0
3621 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3622 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003623 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3624 wifiBytesRx, wifiBytesTx,
3625 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003626 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003627 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003628 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3629 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3630 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3631 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003632 }
3633
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003634 // Dump modem controller data, per UID.
3635 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3636 u.getModemControllerActivity(), which);
3637
3638 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003639 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3640 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3641 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003642 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3643 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003644 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3645 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3646 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003647 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003648 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003649 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3650 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003651 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3652 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003653 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003654 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003657 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3658 u.getWifiControllerActivity(), which);
3659
Bookatz867c0d72017-03-07 18:23:42 -08003660 final Timer bleTimer = u.getBluetoothScanTimer();
3661 if (bleTimer != null) {
3662 // Convert from microseconds to milliseconds with rounding
3663 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3664 / 1000;
3665 if (totalTime != 0) {
3666 final int count = bleTimer.getCountLocked(which);
3667 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3668 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003669 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3670 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3671 final long actualTimeBg = bleTimerBg != null ?
3672 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003673 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003674 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3675 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003676 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3677 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3678 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3679 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3680 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3681 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3682 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3683 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3684 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3685 final Timer unoptimizedScanTimerBg =
3686 u.getBluetoothUnoptimizedScanBackgroundTimer();
3687 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3688 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3689 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3690 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3691
Bookatz867c0d72017-03-07 18:23:42 -08003692 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003693 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3694 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3695 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003696 }
3697 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003698
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003699 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3700 u.getBluetoothControllerActivity(), which);
3701
Dianne Hackborn617f8772009-03-31 15:04:46 -07003702 if (u.hasUserActivity()) {
3703 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3704 boolean hasData = false;
3705 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3706 int val = u.getUserActivityCount(i, which);
3707 args[i] = val;
3708 if (val != 0) hasData = true;
3709 }
3710 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003711 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003712 }
3713 }
Bookatzc8c44962017-05-11 12:12:54 -07003714
3715 if (u.getAggregatedPartialWakelockTimer() != null) {
3716 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003717 // Times are since reset (regardless of 'which')
3718 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003719 final Timer bgTimer = timer.getSubTimer();
3720 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003721 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003722 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3723 }
3724
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003725 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3726 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3727 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3728 String linePrefix = "";
3729 sb.setLength(0);
3730 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3731 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003732 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3733 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003734 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003735 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3736 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003737 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3738 rawRealtime, "w", which, linePrefix);
3739
3740 // Only log if we had at lease one wakelock...
3741 if (sb.length() > 0) {
3742 String name = wakelocks.keyAt(iw);
3743 if (name.indexOf(',') >= 0) {
3744 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 }
Yi Jin02483362017-08-04 11:30:44 -07003746 if (name.indexOf('\n') >= 0) {
3747 name = name.replace('\n', '_');
3748 }
3749 if (name.indexOf('\r') >= 0) {
3750 name = name.replace('\r', '_');
3751 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003752 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 }
3754 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003755
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003756 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3757 for (int isy=syncs.size()-1; isy>=0; isy--) {
3758 final Timer timer = syncs.valueAt(isy);
3759 // Convert from microseconds to milliseconds with rounding
3760 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3761 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003762 final Timer bgTimer = timer.getSubTimer();
3763 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003764 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003765 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003766 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003767 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003768 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003769 }
3770 }
3771
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003772 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3773 for (int ij=jobs.size()-1; ij>=0; ij--) {
3774 final Timer timer = jobs.valueAt(ij);
3775 // Convert from microseconds to milliseconds with rounding
3776 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3777 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003778 final Timer bgTimer = timer.getSubTimer();
3779 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003780 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003781 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003782 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003783 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003784 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003785 }
3786 }
3787
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003788 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3789 for (int ic=completions.size()-1; ic>=0; ic--) {
3790 SparseIntArray types = completions.valueAt(ic);
3791 if (types != null) {
3792 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3793 "\"" + completions.keyAt(ic) + "\"",
3794 types.get(JobParameters.REASON_CANCELED, 0),
3795 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3796 types.get(JobParameters.REASON_PREEMPT, 0),
3797 types.get(JobParameters.REASON_TIMEOUT, 0),
3798 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3799 }
3800 }
3801
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003802 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3803 rawRealtime, which);
3804 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3805 rawRealtime, which);
3806 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3807 rawRealtime, which);
3808 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3809 rawRealtime, which);
3810
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003811 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3812 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003813 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003814 final Uid.Sensor se = sensors.valueAt(ise);
3815 final int sensorNumber = sensors.keyAt(ise);
3816 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003817 if (timer != null) {
3818 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003819 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3820 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003821 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003822 final int count = timer.getCountLocked(which);
3823 final Timer bgTimer = se.getSensorBackgroundTime();
3824 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003825 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3826 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3827 final long bgActualTime = bgTimer != null ?
3828 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3829 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3830 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 }
3833 }
3834
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003835 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3836 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003837
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003838 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3839 rawRealtime, which);
3840
3841 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003842 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003843
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003844 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003845 long totalStateTime = 0;
3846 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003847 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3848 totalStateTime += time;
3849 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003850 }
3851 if (totalStateTime > 0) {
3852 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3853 }
3854
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003855 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3856 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003857 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003858 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003859 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003860 }
3861
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003862 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3863 if (cpuFreqs != null) {
3864 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3865 // If total cpuFreqTimes is null, then we don't need to check for
3866 // screenOffCpuFreqTimes.
3867 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3868 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003869 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003870 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003871 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003872 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3873 if (screenOffCpuFreqTimeMs != null) {
3874 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3875 sb.append("," + screenOffCpuFreqTimeMs[i]);
3876 }
3877 } else {
3878 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3879 sb.append(",0");
3880 }
3881 }
3882 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3883 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003884 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003885 }
3886
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003887 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3888 = u.getProcessStats();
3889 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3890 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003891
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003892 final long userMillis = ps.getUserTime(which);
3893 final long systemMillis = ps.getSystemTime(which);
3894 final long foregroundMillis = ps.getForegroundTime(which);
3895 final int starts = ps.getStarts(which);
3896 final int numCrashes = ps.getNumCrashes(which);
3897 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003898
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003899 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3900 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003901 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3902 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 }
3904 }
3905
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003906 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3907 = u.getPackageStats();
3908 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3909 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3910 int wakeups = 0;
3911 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3912 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003913 int count = alarms.valueAt(iwa).getCountLocked(which);
3914 wakeups += count;
3915 String name = alarms.keyAt(iwa).replace(',', '_');
3916 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003917 }
3918 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3919 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3920 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3921 final long startTime = ss.getStartTime(batteryUptime, which);
3922 final int starts = ss.getStarts(which);
3923 final int launches = ss.getLaunches(which);
3924 if (startTime != 0 || starts != 0 || launches != 0) {
3925 dumpLine(pw, uid, category, APK_DATA,
3926 wakeups, // wakeup alarms
3927 packageStats.keyAt(ipkg), // Apk
3928 serviceStats.keyAt(isvc), // service
3929 startTime / 1000, // time spent started, in ms
3930 starts,
3931 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 }
3933 }
3934 }
3935 }
3936 }
3937
Dianne Hackborn81038902012-11-26 17:04:09 -08003938 static final class TimerEntry {
3939 final String mName;
3940 final int mId;
3941 final BatteryStats.Timer mTimer;
3942 final long mTime;
3943 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3944 mName = name;
3945 mId = id;
3946 mTimer = timer;
3947 mTime = time;
3948 }
3949 }
3950
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003951 private void printmAh(PrintWriter printer, double power) {
3952 printer.print(BatteryStatsHelper.makemAh(power));
3953 }
3954
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003955 private void printmAh(StringBuilder sb, double power) {
3956 sb.append(BatteryStatsHelper.makemAh(power));
3957 }
3958
Dianne Hackbornd953c532014-08-16 18:17:38 -07003959 /**
3960 * Temporary for settings.
3961 */
3962 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3963 int reqUid) {
3964 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3965 }
3966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003968 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003969 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3971 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003972 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974
3975 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3976 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3977 final long totalRealtime = computeRealtime(rawRealtime, which);
3978 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003979 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3980 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3981 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003982 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3983 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07003984 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003985
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003986 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003987
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003988 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003989 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003991 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3992 if (estimatedBatteryCapacity > 0) {
3993 sb.setLength(0);
3994 sb.append(prefix);
3995 sb.append(" Estimated battery capacity: ");
3996 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3997 sb.append(" mAh");
3998 pw.println(sb.toString());
3999 }
4000
Jocelyn Dangc627d102017-04-14 13:15:14 -07004001 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
4002 if (minLearnedBatteryCapacity > 0) {
4003 sb.setLength(0);
4004 sb.append(prefix);
4005 sb.append(" Min learned battery capacity: ");
4006 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
4007 sb.append(" mAh");
4008 pw.println(sb.toString());
4009 }
4010 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
4011 if (maxLearnedBatteryCapacity > 0) {
4012 sb.setLength(0);
4013 sb.append(prefix);
4014 sb.append(" Max learned battery capacity: ");
4015 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
4016 sb.append(" mAh");
4017 pw.println(sb.toString());
4018 }
4019
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004020 sb.setLength(0);
4021 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004022 sb.append(" Time on battery: ");
4023 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
4024 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
4025 sb.append(") realtime, ");
4026 formatTimeMs(sb, whichBatteryUptime / 1000);
4027 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
4028 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004029 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004030
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004031 sb.setLength(0);
4032 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004033 sb.append(" Time on battery screen off: ");
4034 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
4035 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
4036 sb.append(") realtime, ");
4037 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
4038 sb.append("(");
4039 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
4040 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004041 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004042
4043 sb.setLength(0);
4044 sb.append(prefix);
4045 sb.append(" Time on battery screen doze: ");
4046 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
4047 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
4048 sb.append(")");
4049 pw.println(sb.toString());
4050
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004051 sb.setLength(0);
4052 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004053 sb.append(" Total run time: ");
4054 formatTimeMs(sb, totalRealtime / 1000);
4055 sb.append("realtime, ");
4056 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004057 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07004058 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004059 if (batteryTimeRemaining >= 0) {
4060 sb.setLength(0);
4061 sb.append(prefix);
4062 sb.append(" Battery time remaining: ");
4063 formatTimeMs(sb, batteryTimeRemaining / 1000);
4064 pw.println(sb.toString());
4065 }
4066 if (chargeTimeRemaining >= 0) {
4067 sb.setLength(0);
4068 sb.append(prefix);
4069 sb.append(" Charge time remaining: ");
4070 formatTimeMs(sb, chargeTimeRemaining / 1000);
4071 pw.println(sb.toString());
4072 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004073
Kweku Adams87b19ec2017-10-09 12:40:03 -07004074 final long dischargeCount = getUahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004075 if (dischargeCount >= 0) {
4076 sb.setLength(0);
4077 sb.append(prefix);
4078 sb.append(" Discharge: ");
4079 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
4080 sb.append(" mAh");
4081 pw.println(sb.toString());
4082 }
4083
Kweku Adams87b19ec2017-10-09 12:40:03 -07004084 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004085 if (dischargeScreenOffCount >= 0) {
4086 sb.setLength(0);
4087 sb.append(prefix);
4088 sb.append(" Screen off discharge: ");
4089 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
4090 sb.append(" mAh");
4091 pw.println(sb.toString());
4092 }
4093
Kweku Adams87b19ec2017-10-09 12:40:03 -07004094 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Mac2f518a2017-09-19 16:06:03 -07004095 if (dischargeScreenDozeCount >= 0) {
4096 sb.setLength(0);
4097 sb.append(prefix);
4098 sb.append(" Screen doze discharge: ");
4099 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
4100 sb.append(" mAh");
4101 pw.println(sb.toString());
4102 }
4103
4104 final long dischargeScreenOnCount =
4105 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004106 if (dischargeScreenOnCount >= 0) {
4107 sb.setLength(0);
4108 sb.append(prefix);
4109 sb.append(" Screen on discharge: ");
4110 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4111 sb.append(" mAh");
4112 pw.println(sb.toString());
4113 }
4114
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004115 pw.print(" Start clock time: ");
4116 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4117
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004118 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004119 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004120 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004121 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4122 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004123 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004124 rawRealtime, which);
4125 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4126 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004127 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004128 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004129 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4130 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4131 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004132 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004133 sb.append(prefix);
4134 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4135 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004136 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004137 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4138 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004139 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004140 pw.println(sb.toString());
4141 sb.setLength(0);
4142 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004143 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004144 boolean didOne = false;
4145 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004146 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004147 if (time == 0) {
4148 continue;
4149 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004150 sb.append("\n ");
4151 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004152 didOne = true;
4153 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4154 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004155 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004156 sb.append("(");
4157 sb.append(formatRatioLocked(time, screenOnTime));
4158 sb.append(")");
4159 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004160 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004161 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004162 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004163 sb.setLength(0);
4164 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004165 sb.append(" Power save mode enabled: ");
4166 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004167 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004168 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004169 sb.append(")");
4170 pw.println(sb.toString());
4171 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004172 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004173 sb.setLength(0);
4174 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004175 sb.append(" Device light idling: ");
4176 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004177 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004178 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4179 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004180 sb.append("x");
4181 pw.println(sb.toString());
4182 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004183 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004184 sb.setLength(0);
4185 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004186 sb.append(" Idle mode light time: ");
4187 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004188 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004189 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4190 sb.append(") ");
4191 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004192 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004193 sb.append(" -- longest ");
4194 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4195 pw.println(sb.toString());
4196 }
4197 if (deviceIdlingTime != 0) {
4198 sb.setLength(0);
4199 sb.append(prefix);
4200 sb.append(" Device full idling: ");
4201 formatTimeMs(sb, deviceIdlingTime / 1000);
4202 sb.append("(");
4203 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004204 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004205 sb.append("x");
4206 pw.println(sb.toString());
4207 }
4208 if (deviceIdleModeFullTime != 0) {
4209 sb.setLength(0);
4210 sb.append(prefix);
4211 sb.append(" Idle mode full time: ");
4212 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4213 sb.append("(");
4214 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4215 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004216 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004217 sb.append("x");
4218 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004219 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004220 pw.println(sb.toString());
4221 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004222 if (phoneOnTime != 0) {
4223 sb.setLength(0);
4224 sb.append(prefix);
4225 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4226 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004227 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004228 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004229 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004230 if (connChanges != 0) {
4231 pw.print(prefix);
4232 pw.print(" Connectivity changes: "); pw.println(connChanges);
4233 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004234
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004235 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004236 long fullWakeLockTimeTotalMicros = 0;
4237 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004238
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004239 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004240
Evan Millar22ac0432009-03-31 11:33:18 -07004241 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004242 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004243
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004244 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4245 = u.getWakelockStats();
4246 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4247 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004248
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004249 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4250 if (fullWakeTimer != null) {
4251 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4252 rawRealtime, which);
4253 }
4254
4255 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4256 if (partialWakeTimer != null) {
4257 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4258 rawRealtime, which);
4259 if (totalTimeMicros > 0) {
4260 if (reqUid < 0) {
4261 // Only show the ordered list of all wake
4262 // locks if the caller is not asking for data
4263 // about a specific uid.
4264 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4265 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004266 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004267 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004268 }
4269 }
4270 }
4271 }
Bookatzc8c44962017-05-11 12:12:54 -07004272
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004273 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4274 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4275 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4276 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4277 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4278 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4279 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4280 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004281 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4282 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004283
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004284 if (fullWakeLockTimeTotalMicros != 0) {
4285 sb.setLength(0);
4286 sb.append(prefix);
4287 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4288 (fullWakeLockTimeTotalMicros + 500) / 1000);
4289 pw.println(sb.toString());
4290 }
4291
4292 if (partialWakeLockTimeTotalMicros != 0) {
4293 sb.setLength(0);
4294 sb.append(prefix);
4295 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4296 (partialWakeLockTimeTotalMicros + 500) / 1000);
4297 pw.println(sb.toString());
4298 }
4299
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004300 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004301 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4302 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4303 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4304 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004305 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004306 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004307 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004308 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004309 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004310 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004311 if (time == 0) {
4312 continue;
4313 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004314 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004315 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004316 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004317 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004318 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004319 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004320 sb.append("(");
4321 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004322 sb.append(") ");
4323 sb.append(getPhoneSignalStrengthCount(i, which));
4324 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004325 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004326 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004327 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004328
4329 sb.setLength(0);
4330 sb.append(prefix);
4331 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004332 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004333 pw.println(sb.toString());
4334
Dianne Hackborn627bba72009-03-24 22:32:56 -07004335 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004336 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004337 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004338 didOne = false;
4339 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004340 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004341 if (time == 0) {
4342 continue;
4343 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004344 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004345 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004346 didOne = true;
4347 sb.append(DATA_CONNECTION_NAMES[i]);
4348 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004349 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004350 sb.append("(");
4351 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004352 sb.append(") ");
4353 sb.append(getPhoneDataConnectionCount(i, which));
4354 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004355 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004356 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004357 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004358
4359 sb.setLength(0);
4360 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004361 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004362 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004363 formatTimeMs(sb, mobileActiveTime / 1000);
4364 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4365 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4366 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004367 pw.println(sb.toString());
4368
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004369 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4370 if (mobileActiveUnknownTime != 0) {
4371 sb.setLength(0);
4372 sb.append(prefix);
4373 sb.append(" Mobile radio active unknown time: ");
4374 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4375 sb.append("(");
4376 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4377 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4378 sb.append("x");
4379 pw.println(sb.toString());
4380 }
4381
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004382 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4383 if (mobileActiveAdjustedTime != 0) {
4384 sb.setLength(0);
4385 sb.append(prefix);
4386 sb.append(" Mobile radio active adjusted time: ");
4387 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4388 sb.append("(");
4389 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4390 sb.append(")");
4391 pw.println(sb.toString());
4392 }
4393
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004394 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4395
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004396 pw.print(prefix);
4397 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4398 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4399 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4400 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004401 sb.setLength(0);
4402 sb.append(prefix);
4403 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4404 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4405 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4406 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004407 sb.append(")");
4408 pw.println(sb.toString());
4409
4410 sb.setLength(0);
4411 sb.append(prefix);
4412 sb.append(" Wifi states:");
4413 didOne = false;
4414 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004415 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004416 if (time == 0) {
4417 continue;
4418 }
4419 sb.append("\n ");
4420 didOne = true;
4421 sb.append(WIFI_STATE_NAMES[i]);
4422 sb.append(" ");
4423 formatTimeMs(sb, time/1000);
4424 sb.append("(");
4425 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4426 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004427 sb.append(getWifiStateCount(i, which));
4428 sb.append("x");
4429 }
4430 if (!didOne) sb.append(" (no activity)");
4431 pw.println(sb.toString());
4432
4433 sb.setLength(0);
4434 sb.append(prefix);
4435 sb.append(" Wifi supplicant states:");
4436 didOne = false;
4437 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4438 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4439 if (time == 0) {
4440 continue;
4441 }
4442 sb.append("\n ");
4443 didOne = true;
4444 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4445 sb.append(" ");
4446 formatTimeMs(sb, time/1000);
4447 sb.append("(");
4448 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4449 sb.append(") ");
4450 sb.append(getWifiSupplStateCount(i, which));
4451 sb.append("x");
4452 }
4453 if (!didOne) sb.append(" (no activity)");
4454 pw.println(sb.toString());
4455
4456 sb.setLength(0);
4457 sb.append(prefix);
4458 sb.append(" Wifi signal levels:");
4459 didOne = false;
4460 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4461 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4462 if (time == 0) {
4463 continue;
4464 }
4465 sb.append("\n ");
4466 sb.append(prefix);
4467 didOne = true;
4468 sb.append("level(");
4469 sb.append(i);
4470 sb.append(") ");
4471 formatTimeMs(sb, time/1000);
4472 sb.append("(");
4473 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4474 sb.append(") ");
4475 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004476 sb.append("x");
4477 }
4478 if (!didOne) sb.append(" (no activity)");
4479 pw.println(sb.toString());
4480
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004481 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004482
Adam Lesinski50e47602015-12-04 17:04:54 -08004483 pw.print(prefix);
4484 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4485 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4486
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004487 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4488 sb.setLength(0);
4489 sb.append(prefix);
4490 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4491 pw.println(sb.toString());
4492
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004493 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4494 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004495
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004496 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004497
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004498 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004499 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004500 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004501 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004502 pw.println(getDischargeStartLevel());
4503 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4504 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004505 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004506 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004507 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004508 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004509 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004510 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004511 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004512 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004513 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004514 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004515 pw.println(getDischargeAmountScreenOff());
4516 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4517 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004518 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004519 } else {
4520 pw.print(prefix); pw.println(" Device battery use since last full charge");
4521 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004522 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004523 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004524 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004525 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004526 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004527 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004528 pw.println(getDischargeAmountScreenOffSinceCharge());
4529 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4530 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004531 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004532 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004533
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004534 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004535 helper.create(this);
4536 helper.refreshStats(which, UserHandle.USER_ALL);
4537 List<BatterySipper> sippers = helper.getUsageList();
4538 if (sippers != null && sippers.size() > 0) {
4539 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4540 pw.print(prefix); pw.print(" Capacity: ");
4541 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004542 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004543 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4544 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4545 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4546 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004547 pw.println();
4548 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004549 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004550 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004551 switch (bs.drainType) {
4552 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004553 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004554 break;
4555 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004556 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004557 break;
4558 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004559 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004560 break;
4561 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004562 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004563 break;
4564 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004565 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004566 break;
4567 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004568 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004569 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004570 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004571 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004572 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004573 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004574 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004575 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004576 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004577 break;
4578 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004579 pw.print(" User "); pw.print(bs.userId);
4580 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004581 break;
4582 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004583 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004584 break;
4585 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004586 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004587 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004588 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004589 pw.print(" Camera: ");
4590 break;
4591 default:
4592 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004593 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004594 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004595 printmAh(pw, bs.totalPowerMah);
4596
Adam Lesinski57123002015-06-12 16:12:07 -07004597 if (bs.usagePowerMah != bs.totalPowerMah) {
4598 // If the usage (generic power) isn't the whole amount, we list out
4599 // what components are involved in the calculation.
4600
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004601 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004602 if (bs.usagePowerMah != 0) {
4603 pw.print(" usage=");
4604 printmAh(pw, bs.usagePowerMah);
4605 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004606 if (bs.cpuPowerMah != 0) {
4607 pw.print(" cpu=");
4608 printmAh(pw, bs.cpuPowerMah);
4609 }
4610 if (bs.wakeLockPowerMah != 0) {
4611 pw.print(" wake=");
4612 printmAh(pw, bs.wakeLockPowerMah);
4613 }
4614 if (bs.mobileRadioPowerMah != 0) {
4615 pw.print(" radio=");
4616 printmAh(pw, bs.mobileRadioPowerMah);
4617 }
4618 if (bs.wifiPowerMah != 0) {
4619 pw.print(" wifi=");
4620 printmAh(pw, bs.wifiPowerMah);
4621 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004622 if (bs.bluetoothPowerMah != 0) {
4623 pw.print(" bt=");
4624 printmAh(pw, bs.bluetoothPowerMah);
4625 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004626 if (bs.gpsPowerMah != 0) {
4627 pw.print(" gps=");
4628 printmAh(pw, bs.gpsPowerMah);
4629 }
4630 if (bs.sensorPowerMah != 0) {
4631 pw.print(" sensor=");
4632 printmAh(pw, bs.sensorPowerMah);
4633 }
4634 if (bs.cameraPowerMah != 0) {
4635 pw.print(" camera=");
4636 printmAh(pw, bs.cameraPowerMah);
4637 }
4638 if (bs.flashlightPowerMah != 0) {
4639 pw.print(" flash=");
4640 printmAh(pw, bs.flashlightPowerMah);
4641 }
4642 pw.print(" )");
4643 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004644
4645 // If there is additional smearing information, include it.
4646 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4647 pw.print(" Including smearing: ");
4648 printmAh(pw, bs.totalSmearedPowerMah);
4649 pw.print(" (");
4650 if (bs.screenPowerMah != 0) {
4651 pw.print(" screen=");
4652 printmAh(pw, bs.screenPowerMah);
4653 }
4654 if (bs.proportionalSmearMah != 0) {
4655 pw.print(" proportional=");
4656 printmAh(pw, bs.proportionalSmearMah);
4657 }
4658 pw.print(" )");
4659 }
4660 if (bs.shouldHide) {
4661 pw.print(" Excluded from smearing");
4662 }
4663
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004664 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004665 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004666 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004667 }
4668
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004669 sippers = helper.getMobilemsppList();
4670 if (sippers != null && sippers.size() > 0) {
4671 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004672 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004673 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004674 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004675 sb.setLength(0);
4676 sb.append(prefix); sb.append(" Uid ");
4677 UserHandle.formatUid(sb, bs.uidObj.getUid());
4678 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4679 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4680 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004681 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004682 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004683 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004684 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004685 sb.setLength(0);
4686 sb.append(prefix);
4687 sb.append(" TOTAL TIME: ");
4688 formatTimeMs(sb, totalTime);
4689 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4690 sb.append(")");
4691 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004692 pw.println();
4693 }
4694
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004695 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4696 @Override
4697 public int compare(TimerEntry lhs, TimerEntry rhs) {
4698 long lhsTime = lhs.mTime;
4699 long rhsTime = rhs.mTime;
4700 if (lhsTime < rhsTime) {
4701 return 1;
4702 }
4703 if (lhsTime > rhsTime) {
4704 return -1;
4705 }
4706 return 0;
4707 }
4708 };
4709
4710 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004711 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4712 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004713 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004714 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4715 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4716 : kernelWakelocks.entrySet()) {
4717 final BatteryStats.Timer timer = ent.getValue();
4718 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004719 if (totalTimeMillis > 0) {
4720 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4721 }
4722 }
4723 if (ktimers.size() > 0) {
4724 Collections.sort(ktimers, timerComparator);
4725 pw.print(prefix); pw.println(" All kernel wake locks:");
4726 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004727 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004728 String linePrefix = ": ";
4729 sb.setLength(0);
4730 sb.append(prefix);
4731 sb.append(" Kernel Wake lock ");
4732 sb.append(timer.mName);
4733 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4734 which, linePrefix);
4735 if (!linePrefix.equals(": ")) {
4736 sb.append(" realtime");
4737 // Only print out wake locks that were held
4738 pw.println(sb.toString());
4739 }
4740 }
4741 pw.println();
4742 }
4743 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004744
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004745 if (timers.size() > 0) {
4746 Collections.sort(timers, timerComparator);
4747 pw.print(prefix); pw.println(" All partial wake locks:");
4748 for (int i=0; i<timers.size(); i++) {
4749 TimerEntry timer = timers.get(i);
4750 sb.setLength(0);
4751 sb.append(" Wake lock ");
4752 UserHandle.formatUid(sb, timer.mId);
4753 sb.append(" ");
4754 sb.append(timer.mName);
4755 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4756 sb.append(" realtime");
4757 pw.println(sb.toString());
4758 }
4759 timers.clear();
4760 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004761 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004762
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004763 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004764 if (wakeupReasons.size() > 0) {
4765 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004766 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004767 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004768 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004769 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4770 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004771 }
4772 Collections.sort(reasons, timerComparator);
4773 for (int i=0; i<reasons.size(); i++) {
4774 TimerEntry timer = reasons.get(i);
4775 String linePrefix = ": ";
4776 sb.setLength(0);
4777 sb.append(prefix);
4778 sb.append(" Wakeup reason ");
4779 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004780 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4781 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004782 pw.println(sb.toString());
4783 }
4784 pw.println();
4785 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004786 }
Evan Millar22ac0432009-03-31 11:33:18 -07004787
James Carr2dd7e5e2016-07-20 18:48:39 -07004788 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004789 if (mMemoryStats.size() > 0) {
4790 pw.println(" Memory Stats");
4791 for (int i = 0; i < mMemoryStats.size(); i++) {
4792 sb.setLength(0);
4793 sb.append(" Bandwidth ");
4794 sb.append(mMemoryStats.keyAt(i));
4795 sb.append(" Time ");
4796 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4797 pw.println(sb.toString());
4798 }
4799 pw.println();
4800 }
4801
4802 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4803 if (rpmStats.size() > 0) {
4804 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4805 if (rpmStats.size() > 0) {
4806 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4807 final String timerName = ent.getKey();
4808 final Timer timer = ent.getValue();
4809 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4810 }
4811 }
4812 pw.println();
4813 }
Bookatz82b341172017-09-07 19:06:08 -07004814 if (SCREEN_OFF_RPM_STATS_ENABLED) {
4815 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07004816 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07004817 pw.print(prefix);
4818 pw.println(" Resource Power Manager Stats for when screen was off");
4819 if (screenOffRpmStats.size() > 0) {
4820 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4821 final String timerName = ent.getKey();
4822 final Timer timer = ent.getValue();
4823 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4824 }
Bookatz50df7112017-08-04 14:53:26 -07004825 }
Bookatz82b341172017-09-07 19:06:08 -07004826 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07004827 }
James Carr2dd7e5e2016-07-20 18:48:39 -07004828 }
4829
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004830 final long[] cpuFreqs = getCpuFreqs();
4831 if (cpuFreqs != null) {
4832 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004833 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004834 for (int i = 0; i < cpuFreqs.length; ++i) {
4835 sb.append(" " + cpuFreqs[i]);
4836 }
4837 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07004838 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004839 }
4840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 for (int iu=0; iu<NU; iu++) {
4842 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004843 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004844 continue;
4845 }
Bookatzc8c44962017-05-11 12:12:54 -07004846
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004847 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004848
4849 pw.print(prefix);
4850 pw.print(" ");
4851 UserHandle.formatUid(pw, uid);
4852 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004854
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004855 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4856 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4857 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4858 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004859 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4860 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4861
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004862 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4863 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004864 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4865 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004866
4867 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4868 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4869
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004870 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4871 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4872 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004873 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4874 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4875 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4876 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004877 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004878
Adam Lesinski5f056f62016-07-14 16:56:08 -07004879 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4880 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4881
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004882 if (mobileRxBytes > 0 || mobileTxBytes > 0
4883 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004884 pw.print(prefix); pw.print(" Mobile network: ");
4885 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004886 pw.print(formatBytesLocked(mobileTxBytes));
4887 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4888 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004889 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004890 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4891 sb.setLength(0);
4892 sb.append(prefix); sb.append(" Mobile radio active: ");
4893 formatTimeMs(sb, uidMobileActiveTime / 1000);
4894 sb.append("(");
4895 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4896 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4897 long packets = mobileRxPackets + mobileTxPackets;
4898 if (packets == 0) {
4899 packets = 1;
4900 }
4901 sb.append(" @ ");
4902 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4903 sb.append(" mspp");
4904 pw.println(sb.toString());
4905 }
4906
Adam Lesinski5f056f62016-07-14 16:56:08 -07004907 if (mobileWakeup > 0) {
4908 sb.setLength(0);
4909 sb.append(prefix);
4910 sb.append(" Mobile radio AP wakeups: ");
4911 sb.append(mobileWakeup);
4912 pw.println(sb.toString());
4913 }
4914
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004915 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4916 u.getModemControllerActivity(), which);
4917
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004918 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004919 pw.print(prefix); pw.print(" Wi-Fi network: ");
4920 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004921 pw.print(formatBytesLocked(wifiTxBytes));
4922 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4923 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004924 }
4925
Dianne Hackborn62793e42015-03-09 11:15:41 -07004926 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004927 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004928 || uidWifiRunningTime != 0) {
4929 sb.setLength(0);
4930 sb.append(prefix); sb.append(" Wifi Running: ");
4931 formatTimeMs(sb, uidWifiRunningTime / 1000);
4932 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4933 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004934 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004935 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4936 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4937 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004938 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004939 formatTimeMs(sb, wifiScanTime / 1000);
4940 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004941 whichBatteryRealtime)); sb.append(") ");
4942 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004943 sb.append("x\n");
4944 // actual and background times are unpooled and since reset (regardless of 'which')
4945 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4946 formatTimeMs(sb, wifiScanActualTime / 1000);
4947 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4948 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4949 sb.append(") ");
4950 sb.append(wifiScanCount);
4951 sb.append("x\n");
4952 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4953 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4954 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4955 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4956 sb.append(") ");
4957 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004958 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004959 pw.println(sb.toString());
4960 }
4961
Adam Lesinski5f056f62016-07-14 16:56:08 -07004962 if (wifiWakeup > 0) {
4963 sb.setLength(0);
4964 sb.append(prefix);
4965 sb.append(" WiFi AP wakeups: ");
4966 sb.append(wifiWakeup);
4967 pw.println(sb.toString());
4968 }
4969
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004970 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4971 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004972
Adam Lesinski50e47602015-12-04 17:04:54 -08004973 if (btRxBytes > 0 || btTxBytes > 0) {
4974 pw.print(prefix); pw.print(" Bluetooth network: ");
4975 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4976 pw.print(formatBytesLocked(btTxBytes));
4977 pw.println(" sent");
4978 }
4979
Bookatz867c0d72017-03-07 18:23:42 -08004980 final Timer bleTimer = u.getBluetoothScanTimer();
4981 if (bleTimer != null) {
4982 // Convert from microseconds to milliseconds with rounding
4983 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4984 / 1000;
4985 if (totalTimeMs != 0) {
4986 final int count = bleTimer.getCountLocked(which);
4987 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4988 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004989 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4990 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4991 final long actualTimeMsBg = bleTimerBg != null ?
4992 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004993 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004994 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4995 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004996 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4997 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4998 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4999 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
5000 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
5001 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5002 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
5003 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
5004 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
5005 final Timer unoptimizedScanTimerBg =
5006 u.getBluetoothUnoptimizedScanBackgroundTimer();
5007 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
5008 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5009 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
5010 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005011
5012 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08005013 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07005014 sb.append(prefix);
5015 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08005016 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07005017 sb.append(" (");
5018 sb.append(count);
5019 sb.append(" times)");
5020 if (bleTimer.isRunningLocked()) {
5021 sb.append(" (currently running)");
5022 }
5023 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005024 }
Bookatzb1f04f32017-05-19 13:57:32 -07005025
5026 sb.append(prefix);
5027 sb.append(" Bluetooth Scan (total actual realtime): ");
5028 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
5029 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005030 sb.append(count);
5031 sb.append(" times)");
5032 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07005033 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08005034 }
Bookatzb1f04f32017-05-19 13:57:32 -07005035 sb.append("\n");
5036 if (actualTimeMsBg > 0 || countBg > 0) {
5037 sb.append(prefix);
5038 sb.append(" Bluetooth Scan (background realtime): ");
5039 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
5040 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005041 sb.append(countBg);
5042 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07005043 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
5044 sb.append(" (currently running in background)");
5045 }
5046 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005047 }
Bookatzb1f04f32017-05-19 13:57:32 -07005048
5049 sb.append(prefix);
5050 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07005051 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07005052 sb.append(" (");
5053 sb.append(resultCountBg);
5054 sb.append(" in background)");
5055
5056 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
5057 sb.append("\n");
5058 sb.append(prefix);
5059 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
5060 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
5061 sb.append(" (max ");
5062 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
5063 sb.append(")");
5064 if (unoptimizedScanTimer != null
5065 && unoptimizedScanTimer.isRunningLocked()) {
5066 sb.append(" (currently running unoptimized)");
5067 }
5068 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
5069 sb.append("\n");
5070 sb.append(prefix);
5071 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
5072 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
5073 sb.append(" (max ");
5074 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
5075 sb.append(")");
5076 if (unoptimizedScanTimerBg.isRunningLocked()) {
5077 sb.append(" (currently running unoptimized in background)");
5078 }
5079 }
5080 }
Bookatz867c0d72017-03-07 18:23:42 -08005081 pw.println(sb.toString());
5082 uidActivity = true;
5083 }
5084 }
5085
5086
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005087
Dianne Hackborn617f8772009-03-31 15:04:46 -07005088 if (u.hasUserActivity()) {
5089 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07005090 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005091 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07005092 if (val != 0) {
5093 if (!hasData) {
5094 sb.setLength(0);
5095 sb.append(" User activity: ");
5096 hasData = true;
5097 } else {
5098 sb.append(", ");
5099 }
5100 sb.append(val);
5101 sb.append(" ");
5102 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
5103 }
5104 }
5105 if (hasData) {
5106 pw.println(sb.toString());
5107 }
5108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005110 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5111 = u.getWakelockStats();
5112 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005113 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005114 int countWakelock = 0;
5115 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5116 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5117 String linePrefix = ": ";
5118 sb.setLength(0);
5119 sb.append(prefix);
5120 sb.append(" Wake lock ");
5121 sb.append(wakelocks.keyAt(iw));
5122 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5123 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005124 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5125 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005126 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005127 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5128 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005129 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5130 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005131 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5132 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005133 sb.append(" realtime");
5134 pw.println(sb.toString());
5135 uidActivity = true;
5136 countWakelock++;
5137
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005138 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5139 rawRealtime, which);
5140 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5141 rawRealtime, which);
5142 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5143 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005144 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005145 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005146 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005147 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005148 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5149 // pooled and therefore just a lower bound)
5150 long actualTotalPartialWakelock = 0;
5151 long actualBgPartialWakelock = 0;
5152 if (u.getAggregatedPartialWakelockTimer() != null) {
5153 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5154 // Convert from microseconds to milliseconds with rounding
5155 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005156 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005157 final Timer bgAggTimer = aggTimer.getSubTimer();
5158 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005159 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005160 }
5161
5162 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5163 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5164 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005165 sb.setLength(0);
5166 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005167 sb.append(" TOTAL wake: ");
5168 boolean needComma = false;
5169 if (totalFullWakelock != 0) {
5170 needComma = true;
5171 formatTimeMs(sb, totalFullWakelock);
5172 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005173 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005174 if (totalPartialWakelock != 0) {
5175 if (needComma) {
5176 sb.append(", ");
5177 }
5178 needComma = true;
5179 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005180 sb.append("blamed partial");
5181 }
5182 if (actualTotalPartialWakelock != 0) {
5183 if (needComma) {
5184 sb.append(", ");
5185 }
5186 needComma = true;
5187 formatTimeMs(sb, actualTotalPartialWakelock);
5188 sb.append("actual partial");
5189 }
5190 if (actualBgPartialWakelock != 0) {
5191 if (needComma) {
5192 sb.append(", ");
5193 }
5194 needComma = true;
5195 formatTimeMs(sb, actualBgPartialWakelock);
5196 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005197 }
5198 if (totalWindowWakelock != 0) {
5199 if (needComma) {
5200 sb.append(", ");
5201 }
5202 needComma = true;
5203 formatTimeMs(sb, totalWindowWakelock);
5204 sb.append("window");
5205 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005206 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005207 if (needComma) {
5208 sb.append(",");
5209 }
5210 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005211 formatTimeMs(sb, totalDrawWakelock);
5212 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005213 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005214 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005215 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005216 }
5217 }
5218
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005219 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5220 for (int isy=syncs.size()-1; isy>=0; isy--) {
5221 final Timer timer = syncs.valueAt(isy);
5222 // Convert from microseconds to milliseconds with rounding
5223 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5224 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005225 final Timer bgTimer = timer.getSubTimer();
5226 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005227 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005228 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005229 sb.setLength(0);
5230 sb.append(prefix);
5231 sb.append(" Sync ");
5232 sb.append(syncs.keyAt(isy));
5233 sb.append(": ");
5234 if (totalTime != 0) {
5235 formatTimeMs(sb, totalTime);
5236 sb.append("realtime (");
5237 sb.append(count);
5238 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005239 if (bgTime > 0) {
5240 sb.append(", ");
5241 formatTimeMs(sb, bgTime);
5242 sb.append("background (");
5243 sb.append(bgCount);
5244 sb.append(" times)");
5245 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005246 } else {
5247 sb.append("(not used)");
5248 }
5249 pw.println(sb.toString());
5250 uidActivity = true;
5251 }
5252
5253 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5254 for (int ij=jobs.size()-1; ij>=0; ij--) {
5255 final Timer timer = jobs.valueAt(ij);
5256 // Convert from microseconds to milliseconds with rounding
5257 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5258 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005259 final Timer bgTimer = timer.getSubTimer();
5260 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005261 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005262 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005263 sb.setLength(0);
5264 sb.append(prefix);
5265 sb.append(" Job ");
5266 sb.append(jobs.keyAt(ij));
5267 sb.append(": ");
5268 if (totalTime != 0) {
5269 formatTimeMs(sb, totalTime);
5270 sb.append("realtime (");
5271 sb.append(count);
5272 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005273 if (bgTime > 0) {
5274 sb.append(", ");
5275 formatTimeMs(sb, bgTime);
5276 sb.append("background (");
5277 sb.append(bgCount);
5278 sb.append(" times)");
5279 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005280 } else {
5281 sb.append("(not used)");
5282 }
5283 pw.println(sb.toString());
5284 uidActivity = true;
5285 }
5286
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005287 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5288 for (int ic=completions.size()-1; ic>=0; ic--) {
5289 SparseIntArray types = completions.valueAt(ic);
5290 if (types != null) {
5291 pw.print(prefix);
5292 pw.print(" Job Completions ");
5293 pw.print(completions.keyAt(ic));
5294 pw.print(":");
5295 for (int it=0; it<types.size(); it++) {
5296 pw.print(" ");
5297 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5298 pw.print("(");
5299 pw.print(types.valueAt(it));
5300 pw.print("x)");
5301 }
5302 pw.println();
5303 }
5304 }
5305
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005306 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5307 prefix, "Flashlight");
5308 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5309 prefix, "Camera");
5310 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5311 prefix, "Video");
5312 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5313 prefix, "Audio");
5314
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005315 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5316 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005317 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005318 final Uid.Sensor se = sensors.valueAt(ise);
5319 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005320 sb.setLength(0);
5321 sb.append(prefix);
5322 sb.append(" Sensor ");
5323 int handle = se.getHandle();
5324 if (handle == Uid.Sensor.GPS) {
5325 sb.append("GPS");
5326 } else {
5327 sb.append(handle);
5328 }
5329 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005331 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005332 if (timer != null) {
5333 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005334 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5335 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005336 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005337 final Timer bgTimer = se.getSensorBackgroundTime();
5338 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005339 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5340 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5341 final long bgActualTime = bgTimer != null ?
5342 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5343
Dianne Hackborn61659e52014-07-09 16:13:01 -07005344 //timer.logState();
5345 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005346 if (actualTime != totalTime) {
5347 formatTimeMs(sb, totalTime);
5348 sb.append("blamed realtime, ");
5349 }
5350
5351 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005352 sb.append("realtime (");
5353 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005354 sb.append(" times)");
5355
5356 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005357 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005358 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5359 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005360 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005361 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005363 } else {
5364 sb.append("(not used)");
5365 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005366 } else {
5367 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005369
5370 pw.println(sb.toString());
5371 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 }
5373
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005374 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5375 "Vibrator");
5376 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5377 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005378 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5379 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005380
Dianne Hackborn61659e52014-07-09 16:13:01 -07005381 long totalStateTime = 0;
5382 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5383 long time = u.getProcessStateTime(ips, rawRealtime, which);
5384 if (time > 0) {
5385 totalStateTime += time;
5386 sb.setLength(0);
5387 sb.append(prefix);
5388 sb.append(" ");
5389 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5390 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005391 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005392 pw.println(sb.toString());
5393 uidActivity = true;
5394 }
5395 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005396 if (totalStateTime > 0) {
5397 sb.setLength(0);
5398 sb.append(prefix);
5399 sb.append(" Total running: ");
5400 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5401 pw.println(sb.toString());
5402 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005403
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005404 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5405 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005406 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005407 sb.setLength(0);
5408 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005409 sb.append(" Total cpu time: u=");
5410 formatTimeMs(sb, userCpuTimeUs / 1000);
5411 sb.append("s=");
5412 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005413 pw.println(sb.toString());
5414 }
5415
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005416 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5417 if (cpuFreqTimes != null) {
5418 sb.setLength(0);
5419 sb.append(" Total cpu time per freq:");
5420 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5421 sb.append(" " + cpuFreqTimes[i]);
5422 }
5423 pw.println(sb.toString());
5424 }
5425 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5426 if (screenOffCpuFreqTimes != null) {
5427 sb.setLength(0);
5428 sb.append(" Total screen-off cpu time per freq:");
5429 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5430 sb.append(" " + screenOffCpuFreqTimes[i]);
5431 }
5432 pw.println(sb.toString());
5433 }
5434
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005435 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5436 = u.getProcessStats();
5437 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5438 final Uid.Proc ps = processStats.valueAt(ipr);
5439 long userTime;
5440 long systemTime;
5441 long foregroundTime;
5442 int starts;
5443 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005445 userTime = ps.getUserTime(which);
5446 systemTime = ps.getSystemTime(which);
5447 foregroundTime = ps.getForegroundTime(which);
5448 starts = ps.getStarts(which);
5449 final int numCrashes = ps.getNumCrashes(which);
5450 final int numAnrs = ps.getNumAnrs(which);
5451 numExcessive = which == STATS_SINCE_CHARGED
5452 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005454 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5455 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5456 sb.setLength(0);
5457 sb.append(prefix); sb.append(" Proc ");
5458 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5459 sb.append(prefix); sb.append(" CPU: ");
5460 formatTimeMs(sb, userTime); sb.append("usr + ");
5461 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5462 formatTimeMs(sb, foregroundTime); sb.append("fg");
5463 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5464 sb.append("\n"); sb.append(prefix); sb.append(" ");
5465 boolean hasOne = false;
5466 if (starts != 0) {
5467 hasOne = true;
5468 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005469 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005470 if (numCrashes != 0) {
5471 if (hasOne) {
5472 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005473 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005474 hasOne = true;
5475 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005476 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005477 if (numAnrs != 0) {
5478 if (hasOne) {
5479 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005480 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005481 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482 }
5483 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005484 pw.println(sb.toString());
5485 for (int e=0; e<numExcessive; e++) {
5486 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5487 if (ew != null) {
5488 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005489 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005490 pw.print("cpu");
5491 } else {
5492 pw.print("unknown");
5493 }
5494 pw.print(" use: ");
5495 TimeUtils.formatDuration(ew.usedTime, pw);
5496 pw.print(" over ");
5497 TimeUtils.formatDuration(ew.overTime, pw);
5498 if (ew.overTime != 0) {
5499 pw.print(" (");
5500 pw.print((ew.usedTime*100)/ew.overTime);
5501 pw.println("%)");
5502 }
5503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504 }
5505 uidActivity = true;
5506 }
5507 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005508
5509 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5510 = u.getPackageStats();
5511 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5512 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5513 pw.println(":");
5514 boolean apkActivity = false;
5515 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5516 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5517 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5518 pw.print(prefix); pw.print(" Wakeup alarm ");
5519 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5520 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5521 pw.println(" times");
5522 apkActivity = true;
5523 }
5524 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5525 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5526 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5527 final long startTime = ss.getStartTime(batteryUptime, which);
5528 final int starts = ss.getStarts(which);
5529 final int launches = ss.getLaunches(which);
5530 if (startTime != 0 || starts != 0 || launches != 0) {
5531 sb.setLength(0);
5532 sb.append(prefix); sb.append(" Service ");
5533 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5534 sb.append(prefix); sb.append(" Created for: ");
5535 formatTimeMs(sb, startTime / 1000);
5536 sb.append("uptime\n");
5537 sb.append(prefix); sb.append(" Starts: ");
5538 sb.append(starts);
5539 sb.append(", launches: "); sb.append(launches);
5540 pw.println(sb.toString());
5541 apkActivity = true;
5542 }
5543 }
5544 if (!apkActivity) {
5545 pw.print(prefix); pw.println(" (nothing executed)");
5546 }
5547 uidActivity = true;
5548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005549 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005550 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005551 }
5552 }
5553 }
5554
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005555 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005556 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005557 int diff = oldval ^ newval;
5558 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005559 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005560 for (int i=0; i<descriptions.length; i++) {
5561 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005562 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005563 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005564 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005565 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005566 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005567 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5568 didWake = true;
5569 pw.print("=");
5570 if (longNames) {
5571 UserHandle.formatUid(pw, wakelockTag.uid);
5572 pw.print(":\"");
5573 pw.print(wakelockTag.string);
5574 pw.print("\"");
5575 } else {
5576 pw.print(wakelockTag.poolIdx);
5577 }
5578 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005579 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005580 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005581 pw.print("=");
5582 int val = (newval&bd.mask)>>bd.shift;
5583 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005584 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005585 } else {
5586 pw.print(val);
5587 }
5588 }
5589 }
5590 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005591 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005592 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005593 if (longNames) {
5594 UserHandle.formatUid(pw, wakelockTag.uid);
5595 pw.print(":\"");
5596 pw.print(wakelockTag.string);
5597 pw.print("\"");
5598 } else {
5599 pw.print(wakelockTag.poolIdx);
5600 }
5601 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005602 }
Mike Mac2f518a2017-09-19 16:06:03 -07005603
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005604 public void prepareForDumpLocked() {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07005605 // We don't need to require subclasses implement this.
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005606 }
5607
5608 public static class HistoryPrinter {
5609 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005610 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005611 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005612 int oldStatus = -1;
5613 int oldHealth = -1;
5614 int oldPlug = -1;
5615 int oldTemp = -1;
5616 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005617 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005618 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005619
Dianne Hackborn3251b902014-06-20 14:40:53 -07005620 void reset() {
5621 oldState = oldState2 = 0;
5622 oldLevel = -1;
5623 oldStatus = -1;
5624 oldHealth = -1;
5625 oldPlug = -1;
5626 oldTemp = -1;
5627 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005628 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005629 }
5630
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005631 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005632 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005633 if (!checkin) {
5634 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005635 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005636 pw.print(" (");
5637 pw.print(rec.numReadInts);
5638 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005639 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005640 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5641 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005642 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005643 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005644 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005645 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005646 }
5647 lastTime = rec.time;
5648 }
5649 if (rec.cmd == HistoryItem.CMD_START) {
5650 if (checkin) {
5651 pw.print(":");
5652 }
5653 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005654 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005655 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5656 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005657 if (checkin) {
5658 pw.print(":");
5659 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005660 if (rec.cmd == HistoryItem.CMD_RESET) {
5661 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005662 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005663 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005664 pw.print("TIME:");
5665 if (checkin) {
5666 pw.println(rec.currentTime);
5667 } else {
5668 pw.print(" ");
5669 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5670 rec.currentTime).toString());
5671 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005672 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5673 if (checkin) {
5674 pw.print(":");
5675 }
5676 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005677 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5678 if (checkin) {
5679 pw.print(":");
5680 }
5681 pw.println("*OVERFLOW*");
5682 } else {
5683 if (!checkin) {
5684 if (rec.batteryLevel < 10) pw.print("00");
5685 else if (rec.batteryLevel < 100) pw.print("0");
5686 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005687 if (verbose) {
5688 pw.print(" ");
5689 if (rec.states < 0) ;
5690 else if (rec.states < 0x10) pw.print("0000000");
5691 else if (rec.states < 0x100) pw.print("000000");
5692 else if (rec.states < 0x1000) pw.print("00000");
5693 else if (rec.states < 0x10000) pw.print("0000");
5694 else if (rec.states < 0x100000) pw.print("000");
5695 else if (rec.states < 0x1000000) pw.print("00");
5696 else if (rec.states < 0x10000000) pw.print("0");
5697 pw.print(Integer.toHexString(rec.states));
5698 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005699 } else {
5700 if (oldLevel != rec.batteryLevel) {
5701 oldLevel = rec.batteryLevel;
5702 pw.print(",Bl="); pw.print(rec.batteryLevel);
5703 }
5704 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005705 if (oldStatus != rec.batteryStatus) {
5706 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005707 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005708 switch (oldStatus) {
5709 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005710 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005711 break;
5712 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005713 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005714 break;
5715 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005716 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005717 break;
5718 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005719 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005720 break;
5721 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005722 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005723 break;
5724 default:
5725 pw.print(oldStatus);
5726 break;
5727 }
5728 }
5729 if (oldHealth != rec.batteryHealth) {
5730 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005731 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005732 switch (oldHealth) {
5733 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005734 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005735 break;
5736 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005737 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005738 break;
5739 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005740 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005741 break;
5742 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005743 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005744 break;
5745 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005746 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005747 break;
5748 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005749 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005750 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005751 case BatteryManager.BATTERY_HEALTH_COLD:
5752 pw.print(checkin ? "c" : "cold");
5753 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005754 default:
5755 pw.print(oldHealth);
5756 break;
5757 }
5758 }
5759 if (oldPlug != rec.batteryPlugType) {
5760 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005761 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005762 switch (oldPlug) {
5763 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005764 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005765 break;
5766 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005767 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005768 break;
5769 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005770 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005771 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005772 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005773 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005774 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005775 default:
5776 pw.print(oldPlug);
5777 break;
5778 }
5779 }
5780 if (oldTemp != rec.batteryTemperature) {
5781 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005782 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005783 pw.print(oldTemp);
5784 }
5785 if (oldVolt != rec.batteryVoltage) {
5786 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005787 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005788 pw.print(oldVolt);
5789 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005790 final int chargeMAh = rec.batteryChargeUAh / 1000;
5791 if (oldChargeMAh != chargeMAh) {
5792 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005793 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005794 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005795 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005796 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005797 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005798 printBitDescriptions(pw, oldState2, rec.states2, null,
5799 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005800 if (rec.wakeReasonTag != null) {
5801 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005802 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005803 pw.print(rec.wakeReasonTag.poolIdx);
5804 } else {
5805 pw.print(" wake_reason=");
5806 pw.print(rec.wakeReasonTag.uid);
5807 pw.print(":\"");
5808 pw.print(rec.wakeReasonTag.string);
5809 pw.print("\"");
5810 }
5811 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005812 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005813 pw.print(checkin ? "," : " ");
5814 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5815 pw.print("+");
5816 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5817 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005818 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005819 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5820 : HISTORY_EVENT_NAMES;
5821 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5822 | HistoryItem.EVENT_FLAG_FINISH);
5823 if (idx >= 0 && idx < eventNames.length) {
5824 pw.print(eventNames[idx]);
5825 } else {
5826 pw.print(checkin ? "Ev" : "event");
5827 pw.print(idx);
5828 }
5829 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005830 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005831 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005832 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005833 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5834 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005835 pw.print(":\"");
5836 pw.print(rec.eventTag.string);
5837 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005838 }
5839 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005840 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005841 if (rec.stepDetails != null) {
5842 if (!checkin) {
5843 pw.print(" Details: cpu=");
5844 pw.print(rec.stepDetails.userTime);
5845 pw.print("u+");
5846 pw.print(rec.stepDetails.systemTime);
5847 pw.print("s");
5848 if (rec.stepDetails.appCpuUid1 >= 0) {
5849 pw.print(" (");
5850 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5851 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5852 if (rec.stepDetails.appCpuUid2 >= 0) {
5853 pw.print(", ");
5854 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5855 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5856 }
5857 if (rec.stepDetails.appCpuUid3 >= 0) {
5858 pw.print(", ");
5859 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5860 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5861 }
5862 pw.print(')');
5863 }
5864 pw.println();
5865 pw.print(" /proc/stat=");
5866 pw.print(rec.stepDetails.statUserTime);
5867 pw.print(" usr, ");
5868 pw.print(rec.stepDetails.statSystemTime);
5869 pw.print(" sys, ");
5870 pw.print(rec.stepDetails.statIOWaitTime);
5871 pw.print(" io, ");
5872 pw.print(rec.stepDetails.statIrqTime);
5873 pw.print(" irq, ");
5874 pw.print(rec.stepDetails.statSoftIrqTime);
5875 pw.print(" sirq, ");
5876 pw.print(rec.stepDetails.statIdlTime);
5877 pw.print(" idle");
5878 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5879 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5880 + rec.stepDetails.statSoftIrqTime;
5881 int total = totalRun + rec.stepDetails.statIdlTime;
5882 if (total > 0) {
5883 pw.print(" (");
5884 float perc = ((float)totalRun) / ((float)total) * 100;
5885 pw.print(String.format("%.1f%%", perc));
5886 pw.print(" of ");
5887 StringBuilder sb = new StringBuilder(64);
5888 formatTimeMsNoSpace(sb, total*10);
5889 pw.print(sb);
5890 pw.print(")");
5891 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005892 pw.print(", PlatformIdleStat ");
5893 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005894 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005895
5896 pw.print(", SubsystemPowerState ");
5897 pw.print(rec.stepDetails.statSubsystemPowerState);
5898 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005899 } else {
5900 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5901 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5902 pw.print(rec.stepDetails.userTime);
5903 pw.print(":");
5904 pw.print(rec.stepDetails.systemTime);
5905 if (rec.stepDetails.appCpuUid1 >= 0) {
5906 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5907 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5908 if (rec.stepDetails.appCpuUid2 >= 0) {
5909 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5910 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5911 }
5912 if (rec.stepDetails.appCpuUid3 >= 0) {
5913 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5914 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5915 }
5916 }
5917 pw.println();
5918 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5919 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5920 pw.print(rec.stepDetails.statUserTime);
5921 pw.print(',');
5922 pw.print(rec.stepDetails.statSystemTime);
5923 pw.print(',');
5924 pw.print(rec.stepDetails.statIOWaitTime);
5925 pw.print(',');
5926 pw.print(rec.stepDetails.statIrqTime);
5927 pw.print(',');
5928 pw.print(rec.stepDetails.statSoftIrqTime);
5929 pw.print(',');
5930 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005931 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005932 if (rec.stepDetails.statPlatformIdleState != null) {
5933 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07005934 if (rec.stepDetails.statSubsystemPowerState != null) {
5935 pw.print(',');
5936 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005937 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005938
5939 if (rec.stepDetails.statSubsystemPowerState != null) {
5940 pw.print(rec.stepDetails.statSubsystemPowerState);
5941 }
5942 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005943 }
5944 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005945 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005946 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005947 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005948 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005949
5950 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5951 UserHandle.formatUid(pw, uid);
5952 pw.print("=");
5953 pw.print(utime);
5954 pw.print("u+");
5955 pw.print(stime);
5956 pw.print("s");
5957 }
5958
5959 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5960 pw.print('/');
5961 pw.print(uid);
5962 pw.print(":");
5963 pw.print(utime);
5964 pw.print(":");
5965 pw.print(stime);
5966 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005967 }
5968
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005969 private void printSizeValue(PrintWriter pw, long size) {
5970 float result = size;
5971 String suffix = "";
5972 if (result >= 10*1024) {
5973 suffix = "KB";
5974 result = result / 1024;
5975 }
5976 if (result >= 10*1024) {
5977 suffix = "MB";
5978 result = result / 1024;
5979 }
5980 if (result >= 10*1024) {
5981 suffix = "GB";
5982 result = result / 1024;
5983 }
5984 if (result >= 10*1024) {
5985 suffix = "TB";
5986 result = result / 1024;
5987 }
5988 if (result >= 10*1024) {
5989 suffix = "PB";
5990 result = result / 1024;
5991 }
5992 pw.print((int)result);
5993 pw.print(suffix);
5994 }
5995
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005996 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5997 String label3, long estimatedTime) {
5998 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005999 return false;
6000 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006001 pw.print(label1);
6002 pw.print(label2);
6003 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006004 StringBuilder sb = new StringBuilder(64);
6005 formatTimeMs(sb, estimatedTime);
6006 pw.print(sb);
6007 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006008 return true;
6009 }
6010
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006011 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
6012 LevelStepTracker steps, boolean checkin) {
6013 if (steps == null) {
6014 return false;
6015 }
6016 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006017 if (count <= 0) {
6018 return false;
6019 }
6020 if (!checkin) {
6021 pw.println(header);
6022 }
Kweku Adams030980a2015-04-01 16:07:48 -07006023 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006024 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006025 long duration = steps.getDurationAt(i);
6026 int level = steps.getLevelAt(i);
6027 long initMode = steps.getInitModeAt(i);
6028 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006029 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006030 lineArgs[0] = Long.toString(duration);
6031 lineArgs[1] = Integer.toString(level);
6032 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6033 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6034 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
6035 case Display.STATE_ON: lineArgs[2] = "s+"; break;
6036 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
6037 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07006038 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006039 }
6040 } else {
6041 lineArgs[2] = "";
6042 }
6043 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6044 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
6045 } else {
6046 lineArgs[3] = "";
6047 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006048 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07006049 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006050 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07006051 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006052 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006053 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
6054 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006055 pw.print(prefix);
6056 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006057 TimeUtils.formatDuration(duration, pw);
6058 pw.print(" to "); pw.print(level);
6059 boolean haveModes = false;
6060 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6061 pw.print(" (");
6062 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6063 case Display.STATE_OFF: pw.print("screen-off"); break;
6064 case Display.STATE_ON: pw.print("screen-on"); break;
6065 case Display.STATE_DOZE: pw.print("screen-doze"); break;
6066 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07006067 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006068 }
6069 haveModes = true;
6070 }
6071 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6072 pw.print(haveModes ? ", " : " (");
6073 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
6074 ? "power-save-on" : "power-save-off");
6075 haveModes = true;
6076 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006077 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6078 pw.print(haveModes ? ", " : " (");
6079 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6080 ? "device-idle-on" : "device-idle-off");
6081 haveModes = true;
6082 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006083 if (haveModes) {
6084 pw.print(")");
6085 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006086 pw.println();
6087 }
6088 }
6089 return true;
6090 }
6091
Kweku Adams87b19ec2017-10-09 12:40:03 -07006092 private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId,
6093 LevelStepTracker steps) {
6094 if (steps == null) {
6095 return;
6096 }
6097 int count = steps.mNumStepDurations;
6098 long token;
6099 for (int i = 0; i < count; ++i) {
6100 token = proto.start(fieldId);
6101 proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i));
6102 proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i));
6103
6104 final long initMode = steps.getInitModeAt(i);
6105 final long modMode = steps.getModModeAt(i);
6106
6107 int ds = SystemProto.BatteryLevelStep.DS_MIXED;
6108 if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6109 switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6110 case Display.STATE_OFF:
6111 ds = SystemProto.BatteryLevelStep.DS_OFF;
6112 break;
6113 case Display.STATE_ON:
6114 ds = SystemProto.BatteryLevelStep.DS_ON;
6115 break;
6116 case Display.STATE_DOZE:
6117 ds = SystemProto.BatteryLevelStep.DS_DOZE;
6118 break;
6119 case Display.STATE_DOZE_SUSPEND:
6120 ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND;
6121 break;
6122 default:
6123 ds = SystemProto.BatteryLevelStep.DS_ERROR;
6124 break;
6125 }
6126 }
6127 proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds);
6128
6129 int psm = SystemProto.BatteryLevelStep.PSM_MIXED;
6130 if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6131 psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0
6132 ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF;
6133 }
6134 proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm);
6135
6136 int im = SystemProto.BatteryLevelStep.IM_MIXED;
6137 if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6138 im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6139 ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF;
6140 }
6141 proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im);
6142
6143 proto.end(token);
6144 }
6145 }
6146
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006147 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006148 public static final int DUMP_DAILY_ONLY = 1<<2;
6149 public static final int DUMP_HISTORY_ONLY = 1<<3;
6150 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
6151 public static final int DUMP_VERBOSE = 1<<5;
6152 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006153
Dianne Hackborn37de0982014-05-09 09:32:18 -07006154 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
6155 final HistoryPrinter hprinter = new HistoryPrinter();
6156 final HistoryItem rec = new HistoryItem();
6157 long lastTime = -1;
6158 long baseTime = -1;
6159 boolean printed = false;
6160 HistoryEventTracker tracker = null;
6161 while (getNextHistoryLocked(rec)) {
6162 lastTime = rec.time;
6163 if (baseTime < 0) {
6164 baseTime = lastTime;
6165 }
6166 if (rec.time >= histStart) {
6167 if (histStart >= 0 && !printed) {
6168 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006169 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006170 || rec.cmd == HistoryItem.CMD_START
6171 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006172 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006173 hprinter.printNextItem(pw, rec, baseTime, checkin,
6174 (flags&DUMP_VERBOSE) != 0);
6175 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006176 } else if (rec.currentTime != 0) {
6177 printed = true;
6178 byte cmd = rec.cmd;
6179 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006180 hprinter.printNextItem(pw, rec, baseTime, checkin,
6181 (flags&DUMP_VERBOSE) != 0);
6182 rec.cmd = cmd;
6183 }
6184 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006185 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6186 hprinter.printNextItem(pw, rec, baseTime, checkin,
6187 (flags&DUMP_VERBOSE) != 0);
6188 rec.cmd = HistoryItem.CMD_UPDATE;
6189 }
6190 int oldEventCode = rec.eventCode;
6191 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006192 rec.eventTag = new HistoryTag();
6193 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6194 HashMap<String, SparseIntArray> active
6195 = tracker.getStateForEvent(i);
6196 if (active == null) {
6197 continue;
6198 }
6199 for (HashMap.Entry<String, SparseIntArray> ent
6200 : active.entrySet()) {
6201 SparseIntArray uids = ent.getValue();
6202 for (int j=0; j<uids.size(); j++) {
6203 rec.eventCode = i;
6204 rec.eventTag.string = ent.getKey();
6205 rec.eventTag.uid = uids.keyAt(j);
6206 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006207 hprinter.printNextItem(pw, rec, baseTime, checkin,
6208 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006209 rec.wakeReasonTag = null;
6210 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006211 }
6212 }
6213 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006214 rec.eventCode = oldEventCode;
6215 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006216 tracker = null;
6217 }
6218 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006219 hprinter.printNextItem(pw, rec, baseTime, checkin,
6220 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006221 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6222 // This is an attempt to aggregate the previous state and generate
6223 // fake events to reflect that state at the point where we start
6224 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006225 if (tracker == null) {
6226 tracker = new HistoryEventTracker();
6227 }
6228 tracker.updateState(rec.eventCode, rec.eventTag.string,
6229 rec.eventTag.uid, rec.eventTag.poolIdx);
6230 }
6231 }
6232 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006233 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006234 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6235 }
6236 }
6237
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006238 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6239 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6240 if (steps == null) {
6241 return;
6242 }
6243 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6244 if (timeRemaining >= 0) {
6245 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6246 tmpSb.setLength(0);
6247 formatTimeMs(tmpSb, timeRemaining);
6248 pw.print(tmpSb);
6249 pw.print(" (from "); pw.print(tmpOutInt[0]);
6250 pw.println(" steps)");
6251 }
6252 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6253 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6254 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6255 if (estimatedTime > 0) {
6256 pw.print(prefix); pw.print(label); pw.print(" ");
6257 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6258 pw.print(" time: ");
6259 tmpSb.setLength(0);
6260 formatTimeMs(tmpSb, estimatedTime);
6261 pw.print(tmpSb);
6262 pw.print(" (from "); pw.print(tmpOutInt[0]);
6263 pw.println(" steps)");
6264 }
6265 }
6266 }
6267
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006268 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6269 ArrayList<PackageChange> changes) {
6270 if (changes == null) {
6271 return;
6272 }
6273 pw.print(prefix); pw.println("Package changes:");
6274 for (int i=0; i<changes.size(); i++) {
6275 PackageChange pc = changes.get(i);
6276 if (pc.mUpdate) {
6277 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6278 pw.print(" vers="); pw.println(pc.mVersionCode);
6279 } else {
6280 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6281 }
6282 }
6283 }
6284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 /**
6286 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6287 *
6288 * @param pw a Printer to receive the dump output.
6289 */
6290 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006291 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006292 prepareForDumpLocked();
6293
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006294 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006295 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006296
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006297 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006298 final long historyTotalSize = getHistoryTotalSize();
6299 final long historyUsedSize = getHistoryUsedSize();
6300 if (startIteratingHistoryLocked()) {
6301 try {
6302 pw.print("Battery History (");
6303 pw.print((100*historyUsedSize)/historyTotalSize);
6304 pw.print("% used, ");
6305 printSizeValue(pw, historyUsedSize);
6306 pw.print(" used of ");
6307 printSizeValue(pw, historyTotalSize);
6308 pw.print(", ");
6309 pw.print(getHistoryStringPoolSize());
6310 pw.print(" strings using ");
6311 printSizeValue(pw, getHistoryStringPoolBytes());
6312 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006313 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006314 pw.println();
6315 } finally {
6316 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006317 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006318 }
6319
6320 if (startIteratingOldHistoryLocked()) {
6321 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006322 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006323 pw.println("Old battery History:");
6324 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006325 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006326 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006327 if (baseTime < 0) {
6328 baseTime = rec.time;
6329 }
6330 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006331 }
6332 pw.println();
6333 } finally {
6334 finishIteratingOldHistoryLocked();
6335 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006336 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006337 }
6338
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006339 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006340 return;
6341 }
6342
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006343 if (!filtering) {
6344 SparseArray<? extends Uid> uidStats = getUidStats();
6345 final int NU = uidStats.size();
6346 boolean didPid = false;
6347 long nowRealtime = SystemClock.elapsedRealtime();
6348 for (int i=0; i<NU; i++) {
6349 Uid uid = uidStats.valueAt(i);
6350 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6351 if (pids != null) {
6352 for (int j=0; j<pids.size(); j++) {
6353 Uid.Pid pid = pids.valueAt(j);
6354 if (!didPid) {
6355 pw.println("Per-PID Stats:");
6356 didPid = true;
6357 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006358 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6359 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006360 pw.print(" PID "); pw.print(pids.keyAt(j));
6361 pw.print(" wake time: ");
6362 TimeUtils.formatDuration(time, pw);
6363 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006364 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006365 }
6366 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006367 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006368 pw.println();
6369 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006370 }
6371
6372 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006373 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6374 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006375 long timeRemaining = computeBatteryTimeRemaining(
6376 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006377 if (timeRemaining >= 0) {
6378 pw.print(" Estimated discharge time remaining: ");
6379 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6380 pw.println();
6381 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006382 final LevelStepTracker steps = getDischargeLevelStepTracker();
6383 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6384 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6385 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6386 STEP_LEVEL_MODE_VALUES[i], null));
6387 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006388 pw.println();
6389 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006390 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6391 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006392 long timeRemaining = computeChargeTimeRemaining(
6393 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006394 if (timeRemaining >= 0) {
6395 pw.print(" Estimated charge time remaining: ");
6396 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6397 pw.println();
6398 }
6399 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006400 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006401 }
6402 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6403 pw.println("Daily stats:");
6404 pw.print(" Current start time: ");
6405 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6406 getCurrentDailyStartTime()).toString());
6407 pw.print(" Next min deadline: ");
6408 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6409 getNextMinDailyDeadline()).toString());
6410 pw.print(" Next max deadline: ");
6411 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6412 getNextMaxDailyDeadline()).toString());
6413 StringBuilder sb = new StringBuilder(64);
6414 int[] outInt = new int[1];
6415 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6416 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006417 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6418 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006419 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006420 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6421 dsteps, false)) {
6422 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6423 sb, outInt);
6424 }
6425 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6426 csteps, false)) {
6427 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6428 sb, outInt);
6429 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006430 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006431 } else {
6432 pw.println(" Current daily steps:");
6433 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6434 sb, outInt);
6435 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6436 sb, outInt);
6437 }
6438 }
6439 DailyItem dit;
6440 int curIndex = 0;
6441 while ((dit=getDailyItemLocked(curIndex)) != null) {
6442 curIndex++;
6443 if ((flags&DUMP_DAILY_ONLY) != 0) {
6444 pw.println();
6445 }
6446 pw.print(" Daily from ");
6447 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6448 pw.print(" to ");
6449 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6450 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006451 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006452 if (dumpDurationSteps(pw, " ",
6453 " Discharge step durations:", dit.mDischargeSteps, false)) {
6454 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6455 sb, outInt);
6456 }
6457 if (dumpDurationSteps(pw, " ",
6458 " Charge step durations:", dit.mChargeSteps, false)) {
6459 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6460 sb, outInt);
6461 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006462 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006463 } else {
6464 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6465 sb, outInt);
6466 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6467 sb, outInt);
6468 }
6469 }
6470 pw.println();
6471 }
6472 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006473 pw.println("Statistics since last charge:");
6474 pw.println(" System starts: " + getStartCount()
6475 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006476 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6477 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006478 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006480 }
Mike Mac2f518a2017-09-19 16:06:03 -07006481
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006482 // This is called from BatteryStatsService.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006484 public void dumpCheckinLocked(Context context, PrintWriter pw,
6485 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006486 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006487
6488 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006489 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6490 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006491
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006492 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6493
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006494 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006495 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006496 try {
6497 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6498 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6499 pw.print(HISTORY_STRING_POOL); pw.print(',');
6500 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006501 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006502 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006503 pw.print(",\"");
6504 String str = getHistoryTagPoolString(i);
6505 str = str.replace("\\", "\\\\");
6506 str = str.replace("\"", "\\\"");
6507 pw.print(str);
6508 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006509 pw.println();
6510 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006511 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006512 } finally {
6513 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006514 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006515 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006516 }
6517
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006518 if ((flags & DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006519 return;
6520 }
6521
Dianne Hackborne4a59512010-12-07 11:08:07 -08006522 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006523 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006524 for (int i=0; i<apps.size(); i++) {
6525 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006526 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6527 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006528 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006529 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6530 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006531 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006532 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006533 }
6534 SparseArray<? extends Uid> uidStats = getUidStats();
6535 final int NU = uidStats.size();
6536 String[] lineArgs = new String[2];
6537 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006538 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6539 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6540 if (pkgs != null && !pkgs.second.value) {
6541 pkgs.second.value = true;
6542 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006543 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006544 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006545 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6546 (Object[])lineArgs);
6547 }
6548 }
6549 }
6550 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006551 if ((flags & DUMP_DAILY_ONLY) == 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006552 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006553 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006554 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006555 if (timeRemaining >= 0) {
6556 lineArgs[0] = Long.toString(timeRemaining);
6557 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6558 (Object[])lineArgs);
6559 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006560 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006561 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006562 if (timeRemaining >= 0) {
6563 lineArgs[0] = Long.toString(timeRemaining);
6564 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6565 (Object[])lineArgs);
6566 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006567 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6568 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006571
Kweku Adams87b19ec2017-10-09 12:40:03 -07006572 /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006573 public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps,
6574 int flags, long historyStart) {
6575 final ProtoOutputStream proto = new ProtoOutputStream(fd);
6576 final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS);
6577 prepareForDumpLocked();
6578
6579 proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION);
6580 proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion());
6581 proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion());
6582 proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion());
6583
6584 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6585
6586 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
6587 if (startIteratingHistoryLocked()) {
6588 // TODO: implement dumpProtoHistoryLocked(proto);
6589 }
6590 }
6591
6592 if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) {
6593 // TODO: implement dumpProtoAppsLocked(proto, apps);
Kweku Adams87b19ec2017-10-09 12:40:03 -07006594 dumpProtoSystemLocked(context, proto, (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006595 }
6596
6597 proto.end(bToken);
6598 proto.flush();
6599 }
Kweku Adams87b19ec2017-10-09 12:40:03 -07006600
6601 private void dumpProtoSystemLocked(Context context, ProtoOutputStream proto, boolean wifiOnly) {
6602 final long sToken = proto.start(BatteryStatsProto.SYSTEM);
6603 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
6604 final long rawRealtimeMs = SystemClock.elapsedRealtime();
6605 final long rawRealtimeUs = rawRealtimeMs * 1000;
6606 final int which = STATS_SINCE_CHARGED;
6607
6608 // Battery data (BATTERY_DATA)
6609 long token = proto.start(SystemProto.BATTERY);
6610 proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime());
6611 proto.write(SystemProto.Battery.START_COUNT, getStartCount());
6612 proto.write(SystemProto.Battery.TOTAL_REALTIME_MS,
6613 computeRealtime(rawRealtimeUs, which) / 1000);
6614 proto.write(SystemProto.Battery.TOTAL_UPTIME_MS,
6615 computeUptime(rawUptimeUs, which) / 1000);
6616 proto.write(SystemProto.Battery.BATTERY_REALTIME_MS,
6617 computeBatteryRealtime(rawRealtimeUs, which) / 1000);
6618 proto.write(SystemProto.Battery.BATTERY_UPTIME_MS,
6619 computeBatteryUptime(rawUptimeUs, which) / 1000);
6620 proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS,
6621 computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000);
6622 proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS,
6623 computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000);
6624 proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS,
6625 getScreenDozeTime(rawRealtimeUs, which) / 1000);
6626 proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH,
6627 getEstimatedBatteryCapacity());
6628 proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH,
6629 getMinLearnedBatteryCapacity());
6630 proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH,
6631 getMaxLearnedBatteryCapacity());
6632 proto.end(token);
6633
6634 // Battery discharge (BATTERY_DISCHARGE_DATA)
6635 token = proto.start(SystemProto.BATTERY_DISCHARGE);
6636 proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE,
6637 getLowDischargeAmountSinceCharge());
6638 proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE,
6639 getHighDischargeAmountSinceCharge());
6640 proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE,
6641 getDischargeAmountScreenOnSinceCharge());
6642 proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE,
6643 getDischargeAmountScreenOffSinceCharge());
6644 proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE,
6645 getDischargeAmountScreenDozeSinceCharge());
6646 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH,
6647 getUahDischarge(which) / 1000);
6648 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF,
6649 getUahDischargeScreenOff(which) / 1000);
6650 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE,
6651 getUahDischargeScreenDoze(which) / 1000);
6652 proto.end(token);
6653
6654 // Time remaining
6655 long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs);
6656 if (timeRemainingUs >= 0) {
6657 // Charge time remaining (CHARGE_TIME_REMAIN_DATA)
6658 proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
6659 } else {
6660 timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs);
6661 // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA)
6662 if (timeRemainingUs >= 0) {
6663 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
6664 } else {
6665 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1);
6666 }
6667 }
6668
6669 // Charge step (CHARGE_STEP_DATA)
6670 dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker());
6671
6672 // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA)
6673 for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) {
6674 token = proto.start(SystemProto.DATA_CONNECTION);
6675 proto.write(SystemProto.DataConnection.NAME, i);
6676 dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i),
6677 rawRealtimeUs, which);
6678 proto.end(token);
6679 }
6680
6681 // Discharge step (DISCHARGE_STEP_DATA)
6682 dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker());
6683
6684 // CPU frequencies (GLOBAL_CPU_FREQ_DATA)
6685 final long[] cpuFreqs = getCpuFreqs();
6686 if (cpuFreqs != null) {
6687 for (long i : cpuFreqs) {
6688 proto.write(SystemProto.CPU_FREQUENCY, i);
6689 }
6690 }
6691
6692 // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA)
6693 dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER,
6694 getBluetoothControllerActivity(), which);
6695
6696 // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA)
6697 dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER,
6698 getModemControllerActivity(), which);
6699
6700 // Global network data (GLOBAL_NETWORK_DATA)
6701 token = proto.start(SystemProto.GLOBAL_NETWORK);
6702 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX,
6703 getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
6704 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX,
6705 getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
6706 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX,
6707 getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
6708 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX,
6709 getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
6710 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX,
6711 getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
6712 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX,
6713 getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
6714 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX,
6715 getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
6716 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX,
6717 getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
6718 proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX,
6719 getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
6720 proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX,
6721 getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
6722 proto.end(token);
6723
6724 // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA)
6725 dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER,
6726 getWifiControllerActivity(), which);
6727
6728
6729 // Global wifi (GLOBAL_WIFI_DATA)
6730 token = proto.start(SystemProto.GLOBAL_WIFI);
6731 proto.write(SystemProto.GlobalWifi.ON_DURATION_MS,
6732 getWifiOnTime(rawRealtimeUs, which) / 1000);
6733 proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS,
6734 getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000);
6735 proto.end(token);
6736
6737 // Kernel wakelock (KERNEL_WAKELOCK_DATA)
6738 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
6739 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
6740 token = proto.start(SystemProto.KERNEL_WAKELOCK);
6741 proto.write(SystemProto.KernelWakelock.NAME, ent.getKey());
6742 dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(),
6743 rawRealtimeUs, which);
6744 proto.end(token);
6745 }
6746
6747 // Misc (MISC_DATA)
6748 // Calculate wakelock times across all uids.
6749 long fullWakeLockTimeTotalUs = 0;
6750 long partialWakeLockTimeTotalUs = 0;
6751
6752 final SparseArray<? extends Uid> uidStats = getUidStats();
6753 for (int iu = 0; iu < uidStats.size(); iu++) {
6754 final Uid u = uidStats.valueAt(iu);
6755
6756 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks =
6757 u.getWakelockStats();
6758 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
6759 final Uid.Wakelock wl = wakelocks.valueAt(iw);
6760
6761 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
6762 if (fullWakeTimer != null) {
6763 fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs,
6764 which);
6765 }
6766
6767 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
6768 if (partialWakeTimer != null) {
6769 partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked(
6770 rawRealtimeUs, which);
6771 }
6772 }
6773 }
6774 token = proto.start(SystemProto.MISC);
6775 proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS,
6776 getScreenOnTime(rawRealtimeUs, which) / 1000);
6777 proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS,
6778 getPhoneOnTime(rawRealtimeUs, which) / 1000);
6779 proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS,
6780 fullWakeLockTimeTotalUs / 1000);
6781 proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS,
6782 partialWakeLockTimeTotalUs / 1000);
6783 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS,
6784 getMobileRadioActiveTime(rawRealtimeUs, which) / 1000);
6785 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS,
6786 getMobileRadioActiveAdjustedTime(which) / 1000);
6787 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT,
6788 getMobileRadioActiveCount(which));
6789 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS,
6790 getMobileRadioActiveUnknownTime(which) / 1000);
6791 proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS,
6792 getInteractiveTime(rawRealtimeUs, which) / 1000);
6793 proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS,
6794 getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000);
6795 proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES,
6796 getNumConnectivityChange(which));
6797 proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS,
6798 getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
6799 proto.write(SystemProto.Misc.DEEP_DOZE_COUNT,
6800 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
6801 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS,
6802 getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
6803 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT,
6804 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
6805 proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS,
6806 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
6807 proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS,
6808 getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
6809 proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT,
6810 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
6811 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS,
6812 getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
6813 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT,
6814 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
6815 proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS,
6816 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
6817 proto.end(token);
6818
6819 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
6820 helper.create(this);
6821 helper.refreshStats(which, UserHandle.USER_ALL);
6822
6823 // Power use item (POWER_USE_ITEM_DATA)
6824 final List<BatterySipper> sippers = helper.getUsageList();
6825 if (sippers != null) {
6826 for (int i = 0; i < sippers.size(); ++i) {
6827 final BatterySipper bs = sippers.get(i);
6828 int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER;
6829 int uid = 0;
6830 switch (bs.drainType) {
6831 case IDLE:
6832 n = SystemProto.PowerUseItem.IDLE;
6833 break;
6834 case CELL:
6835 n = SystemProto.PowerUseItem.CELL;
6836 break;
6837 case PHONE:
6838 n = SystemProto.PowerUseItem.PHONE;
6839 break;
6840 case WIFI:
6841 n = SystemProto.PowerUseItem.WIFI;
6842 break;
6843 case BLUETOOTH:
6844 n = SystemProto.PowerUseItem.BLUETOOTH;
6845 break;
6846 case SCREEN:
6847 n = SystemProto.PowerUseItem.SCREEN;
6848 break;
6849 case FLASHLIGHT:
6850 n = SystemProto.PowerUseItem.FLASHLIGHT;
6851 break;
6852 case APP:
6853 // dumpProtoAppLocked will handle this.
6854 continue;
6855 case USER:
6856 n = SystemProto.PowerUseItem.USER;
6857 uid = UserHandle.getUid(bs.userId, 0);
6858 break;
6859 case UNACCOUNTED:
6860 n = SystemProto.PowerUseItem.UNACCOUNTED;
6861 break;
6862 case OVERCOUNTED:
6863 n = SystemProto.PowerUseItem.OVERCOUNTED;
6864 break;
6865 case CAMERA:
6866 n = SystemProto.PowerUseItem.CAMERA;
6867 break;
6868 case MEMORY:
6869 n = SystemProto.PowerUseItem.MEMORY;
6870 break;
6871 }
6872 token = proto.start(SystemProto.POWER_USE_ITEM);
6873 proto.write(SystemProto.PowerUseItem.NAME, n);
6874 proto.write(SystemProto.PowerUseItem.UID, uid);
6875 proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
6876 proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
6877 proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
6878 proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
6879 bs.proportionalSmearMah);
6880 proto.end(token);
6881 }
6882 }
6883
6884 // Power use summary (POWER_USE_SUMMARY_DATA)
6885 token = proto.start(SystemProto.POWER_USE_SUMMARY);
6886 proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH,
6887 helper.getPowerProfile().getBatteryCapacity());
6888 proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower());
6889 proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower());
6890 proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower());
6891 proto.end(token);
6892
6893 // RPM stats (RESOURCE_POWER_MANAGER_DATA)
6894 final Map<String, ? extends Timer> rpmStats = getRpmStats();
6895 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
6896 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
6897 token = proto.start(SystemProto.RESOURCE_POWER_MANAGER);
6898 proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey());
6899 dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL,
6900 ent.getValue(), rawRealtimeUs, which);
6901 dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF,
6902 screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which);
6903 proto.end(token);
6904 }
6905
6906 // Screen brightness (SCREEN_BRIGHTNESS_DATA)
6907 for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) {
6908 token = proto.start(SystemProto.SCREEN_BRIGHTNESS);
6909 proto.write(SystemProto.ScreenBrightness.NAME, i);
6910 dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i),
6911 rawRealtimeUs, which);
6912 proto.end(token);
6913 }
6914
6915 // Signal scanning time (SIGNAL_SCANNING_TIME_DATA)
6916 dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs,
6917 which);
6918
6919 // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA)
6920 for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) {
6921 token = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH);
6922 proto.write(SystemProto.PhoneSignalStrength.NAME, i);
6923 dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i),
6924 rawRealtimeUs, which);
6925 proto.end(token);
6926 }
6927
6928 // Wakeup reasons (WAKEUP_REASON_DATA)
6929 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
6930 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
6931 token = proto.start(SystemProto.WAKEUP_REASON);
6932 proto.write(SystemProto.WakeupReason.NAME, ent.getKey());
6933 dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which);
6934 proto.end(token);
6935 }
6936
6937 // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA)
6938 for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) {
6939 token = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH);
6940 proto.write(SystemProto.WifiSignalStrength.NAME, i);
6941 dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i),
6942 rawRealtimeUs, which);
6943 proto.end(token);
6944 }
6945
6946 // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA)
6947 for (int i = 0; i < NUM_WIFI_STATES; ++i) {
6948 token = proto.start(SystemProto.WIFI_STATE);
6949 proto.write(SystemProto.WifiState.NAME, i);
6950 dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i),
6951 rawRealtimeUs, which);
6952 proto.end(token);
6953 }
6954
6955 // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA)
6956 for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) {
6957 token = proto.start(SystemProto.WIFI_SUPPLICANT_STATE);
6958 proto.write(SystemProto.WifiSupplicantState.NAME, i);
6959 dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i),
6960 rawRealtimeUs, which);
6961 proto.end(token);
6962 }
6963
6964 proto.end(sToken);
6965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966}