blob: 5faebff5803a8822e92762f07afcd5717d4f4905 [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
Mike Ma15313c92017-11-15 17:58:21 -0800225 * New in version 28:
226 * - Light/Deep Doze power
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700227 * - WiFi Multicast Wakelock statistics (count & duration)
Kweku Adamsa8943cb2017-12-22 13:21:06 -0800228 * New in version 29:
229 * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced.
230 * - CPU times per UID process state
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700231 */
Kweku Adamsa8943cb2017-12-22 13:21:06 -0800232 static final int CHECKIN_VERSION = 29;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700233
234 /**
235 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700237 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700238
Evan Millar22ac0432009-03-31 11:33:18 -0700239 private static final long BYTES_PER_KB = 1024;
240 private static final long BYTES_PER_MB = 1048576; // 1024^2
241 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700242
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700243 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800244 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700245 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700247 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700248 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700249 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
250 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700251 // rpm line is:
252 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
253 // screen-off time, screen-off count
254 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700255 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800256 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700257 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
258 // fgs line is:
259 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
260 // foreground service time, count
261 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700262 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700263 // wl line is:
264 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700265 // full totalTime, 'f', count, current duration, max duration, total duration,
266 // partial totalTime, 'p', count, current duration, max duration, total duration,
267 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
268 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700269 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700270 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700271 // awl line is:
272 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
273 // cumulative partial wakelock duration, cumulative background partial wakelock duration
274 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700275 private static final String SYNC_DATA = "sy";
276 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700277 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700278 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700279 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700280 private static final String NETWORK_DATA = "nt";
281 private static final String USER_ACTIVITY_DATA = "ua";
282 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800283 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700284 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700285 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700286 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800287 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
288 private static final String WIFI_CONTROLLER_DATA = "wfcd";
289 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
290 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700291 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700292 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800293 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800294 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
295 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800296 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700297 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700298 private static final String SCREEN_BRIGHTNESS_DATA = "br";
299 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700300 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700301 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
302 private static final String DATA_CONNECTION_TIME_DATA = "dct";
303 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800304 private static final String WIFI_STATE_TIME_DATA = "wst";
305 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700306 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
307 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
308 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
309 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800310 private static final String POWER_USE_SUMMARY_DATA = "pws";
311 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700312 private static final String DISCHARGE_STEP_DATA = "dsd";
313 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700314 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
315 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700316 private static final String FLASHLIGHT_DATA = "fla";
317 private static final String CAMERA_DATA = "cam";
318 private static final String VIDEO_DATA = "vid";
319 private static final String AUDIO_DATA = "aud";
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700320 private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct";
321 private static final String WIFI_MULTICAST_DATA = "wmc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322
Adam Lesinski010bf372016-04-11 12:18:18 -0700323 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
324
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700325 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 private final Formatter mFormatter = new Formatter(mFormatBuilder);
327
328 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700329 * Indicates times spent by the uid at each cpu frequency in all process states.
330 *
331 * Other types might include times spent in foreground, background etc.
332 */
333 private final String UID_TIMES_TYPE_ALL = "A";
334
335 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700336 * State for keeping track of counting information.
337 */
338 public static abstract class Counter {
339
340 /**
341 * Returns the count associated with this Counter for the
342 * selected type of statistics.
343 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700344 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700345 */
Evan Millarc64edde2009-04-18 12:26:32 -0700346 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700347
348 /**
349 * Temporary for debugging.
350 */
351 public abstract void logState(Printer pw, String prefix);
352 }
353
354 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700355 * State for keeping track of long counting information.
356 */
357 public static abstract class LongCounter {
358
359 /**
360 * Returns the count associated with this Counter for the
361 * selected type of statistics.
362 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700363 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700364 */
365 public abstract long getCountLocked(int which);
366
367 /**
368 * Temporary for debugging.
369 */
370 public abstract void logState(Printer pw, String prefix);
371 }
372
373 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700374 * State for keeping track of array of long counting information.
375 */
376 public static abstract class LongCounterArray {
377 /**
378 * Returns the counts associated with this Counter for the
379 * selected type of statistics.
380 *
381 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
382 */
383 public abstract long[] getCountsLocked(int which);
384
385 /**
386 * Temporary for debugging.
387 */
388 public abstract void logState(Printer pw, String prefix);
389 }
390
391 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800392 * Container class that aggregates counters for transmit, receive, and idle state of a
393 * radio controller.
394 */
395 public static abstract class ControllerActivityCounter {
396 /**
397 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
398 * idle state.
399 */
400 public abstract LongCounter getIdleTimeCounter();
401
402 /**
403 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
404 * receive state.
405 */
406 public abstract LongCounter getRxTimeCounter();
407
408 /**
409 * An array of {@link LongCounter}, representing various transmit levels, where each level
410 * may draw a different amount of power. The levels themselves are controller-specific.
411 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
412 * various transmit level states.
413 */
414 public abstract LongCounter[] getTxTimeCounters();
415
416 /**
417 * @return a non-null {@link LongCounter} representing the power consumed by the controller
418 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
419 * yield a value of 0 if the device doesn't support power calculations.
420 */
421 public abstract LongCounter getPowerCounter();
422 }
423
424 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 * State for keeping track of timing information.
426 */
427 public static abstract class Timer {
428
429 /**
430 * Returns the count associated with this Timer for the
431 * selected type of statistics.
432 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700433 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 */
Evan Millarc64edde2009-04-18 12:26:32 -0700435 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436
437 /**
438 * Returns the total time in microseconds associated with this Timer for the
439 * selected type of statistics.
440 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800441 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700442 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 * @return a time in microseconds
444 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800445 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700448 * Returns the total time in microseconds associated with this Timer since the
449 * 'mark' was last set.
450 *
451 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
452 * @return a time in microseconds
453 */
454 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
455
456 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700457 * Returns the max duration if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700458 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700459 */
460 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
461 return -1;
462 }
463
464 /**
465 * Returns the current time the timer has been active, if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700466 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700467 */
468 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
469 return -1;
470 }
471
472 /**
Kweku Adams103351f2017-10-16 14:39:34 -0700473 * Returns the total time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800474 *
475 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
476 * been on since reset.
477 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
478 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
479 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
480 * the actual total time.
Kweku Adams103351f2017-10-16 14:39:34 -0700481 * Not all Timer subclasses track the max, total, and current durations.
Bookatz867c0d72017-03-07 18:23:42 -0800482 */
483 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
484 return -1;
485 }
486
487 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700488 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
489 * used, for example, for tracking background usage. Secondary timers are never pooled.
490 *
491 * Not all Timer subclasses have a secondary timer; those that don't return null.
492 */
493 public Timer getSubTimer() {
494 return null;
495 }
496
497 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700498 * Returns whether the timer is currently running. Some types of timers
499 * (e.g. BatchTimers) don't know whether the event is currently active,
500 * and report false.
501 */
502 public boolean isRunningLocked() {
503 return false;
504 }
505
506 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 * Temporary for debugging.
508 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700509 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511
512 /**
513 * The statistics associated with a particular uid.
514 */
515 public static abstract class Uid {
516
517 /**
518 * Returns a mapping containing wakelock statistics.
519 *
520 * @return a Map from Strings to Uid.Wakelock objects.
521 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700522 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523
524 /**
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700525 * Returns the WiFi Multicast Wakelock statistics.
526 *
527 * @return a Timer Object for the per uid Multicast statistics.
528 */
529 public abstract Timer getMulticastWakelockStats();
530
531 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700532 * Returns a mapping containing sync statistics.
533 *
534 * @return a Map from Strings to Timer objects.
535 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700536 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700537
538 /**
539 * Returns a mapping containing scheduled job statistics.
540 *
541 * @return a Map from Strings to Timer objects.
542 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700543 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700544
545 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700546 * Returns statistics about how jobs have completed.
547 *
548 * @return A Map of String job names to completion type -> count mapping.
549 */
550 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
551
552 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 * The statistics associated with a particular wake lock.
554 */
555 public static abstract class Wakelock {
556 public abstract Timer getWakeTime(int type);
557 }
558
559 /**
Bookatzc8c44962017-05-11 12:12:54 -0700560 * The cumulative time the uid spent holding any partial wakelocks. This will generally
561 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
562 * wakelocks that overlap in time (and therefore over-counts).
563 */
564 public abstract Timer getAggregatedPartialWakelockTimer();
565
566 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 * Returns a mapping containing sensor statistics.
568 *
569 * @return a Map from Integer sensor ids to Uid.Sensor objects.
570 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700571 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572
573 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700574 * Returns a mapping containing active process data.
575 */
576 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700577
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700578 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 * Returns a mapping containing process statistics.
580 *
581 * @return a Map from Strings to Uid.Proc objects.
582 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700583 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584
585 /**
586 * Returns a mapping containing package statistics.
587 *
588 * @return a Map from Strings to Uid.Pkg objects.
589 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700590 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700591
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800592 public abstract ControllerActivityCounter getWifiControllerActivity();
593 public abstract ControllerActivityCounter getBluetoothControllerActivity();
594 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800595
596 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 * {@hide}
598 */
599 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700600
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800601 public abstract void noteWifiRunningLocked(long elapsedRealtime);
602 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
603 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
604 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
605 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
606 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
607 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
608 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
609 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
610 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800611 public abstract void noteActivityResumedLocked(long elapsedRealtime);
612 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800613 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
614 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
615 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700616 public abstract int getWifiScanCount(int which);
Kweku Adams103351f2017-10-16 14:39:34 -0700617 /**
618 * Returns the timer keeping track of wifi scans.
619 */
620 public abstract Timer getWifiScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800621 public abstract int getWifiScanBackgroundCount(int which);
622 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
623 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -0700624 /**
625 * Returns the timer keeping track of background wifi scans.
626 */
627 public abstract Timer getWifiScanBackgroundTimer();
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800628 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700629 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800630 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700631 public abstract Timer getAudioTurnedOnTimer();
632 public abstract Timer getVideoTurnedOnTimer();
633 public abstract Timer getFlashlightTurnedOnTimer();
634 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700635 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700636
637 /**
638 * Returns the timer keeping track of Foreground Service time
639 */
640 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800641 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800642 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700643 public abstract Timer getBluetoothUnoptimizedScanTimer();
644 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700645 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700646 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700647
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700648 public abstract long[] getCpuFreqTimes(int which);
649 public abstract long[] getScreenOffCpuFreqTimes(int which);
650
Dianne Hackborna0200e32016-03-30 18:01:41 -0700651 // Note: the following times are disjoint. They can be added together to find the
652 // total time a uid has had any processes running at all.
653
654 /**
655 * Time this uid has any processes in the top state (or above such as persistent).
656 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800657 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700658 /**
659 * Time this uid has any process with a started out bound foreground service, but
660 * none in the "top" state.
661 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800662 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700663 /**
Dianne Hackborna0200e32016-03-30 18:01:41 -0700664 * Time this uid has any process in an active foreground state, but none in the
665 * "top sleeping" or better state.
666 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800667 public static final int PROCESS_STATE_FOREGROUND = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700668 /**
669 * Time this uid has any process in an active background state, but none in the
670 * "foreground" or better state.
671 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800672 public static final int PROCESS_STATE_BACKGROUND = 3;
673 /**
674 * Time this uid has any process that is top while the device is sleeping, but not
675 * active for any other reason. We kind-of consider it a kind of cached process
676 * for execution restrictions.
677 */
678 public static final int PROCESS_STATE_TOP_SLEEPING = 4;
679 /**
680 * Time this uid has any process that is in the background but it has an activity
681 * marked as "can't save state". This is essentially a cached process, though the
682 * system will try much harder than normal to avoid killing it.
683 */
684 public static final int PROCESS_STATE_HEAVY_WEIGHT = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700685 /**
686 * Time this uid has any processes that are sitting around cached, not in one of the
687 * other active states.
688 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800689 public static final int PROCESS_STATE_CACHED = 6;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700690 /**
691 * Total number of process states we track.
692 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800693 public static final int NUM_PROCESS_STATE = 7;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700694
695 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800696 "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight",
697 "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700698 };
699
700 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800701 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700702
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800703 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704
Robert Greenwalta029ea12013-09-25 16:38:12 -0700705 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
706
Dianne Hackborn617f8772009-03-31 15:04:46 -0700707 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700708 * Note that these must match the constants in android.os.PowerManager.
709 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
710 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700711 */
712 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700713 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700714 };
Bookatzc8c44962017-05-11 12:12:54 -0700715
Phil Weaverda80d672016-03-15 16:25:46 -0700716 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700717
Dianne Hackborn617f8772009-03-31 15:04:46 -0700718 public abstract void noteUserActivityLocked(int type);
719 public abstract boolean hasUserActivity();
720 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700721
722 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800723 public abstract long getNetworkActivityBytes(int type, int which);
724 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800725 public abstract long getMobileRadioActiveTime(int which);
726 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700727
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700728 /**
729 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
730 */
731 public abstract long getUserCpuTimeUs(int which);
732
733 /**
734 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
735 */
736 public abstract long getSystemCpuTimeUs(int which);
737
738 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700739 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700740 * given CPU cluster.
741 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700742 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700743 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700744 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
745 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700746 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700747 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700748
Adam Lesinski5f056f62016-07-14 16:56:08 -0700749 /**
750 * Returns the number of times this UID woke up the Application Processor to
751 * process a mobile radio packet.
752 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
753 */
754 public abstract long getMobileRadioApWakeupCount(int which);
755
756 /**
757 * Returns the number of times this UID woke up the Application Processor to
758 * process a WiFi packet.
759 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
760 */
761 public abstract long getWifiRadioApWakeupCount(int which);
762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800764 /*
765 * FIXME: it's not correct to use this magic value because it
766 * could clash with a sensor handle (which are defined by
767 * the sensor HAL, and therefore out of our control
768 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 // Magic sensor number for the GPS.
770 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800775
Bookatz867c0d72017-03-07 18:23:42 -0800776 /** Returns a Timer for sensor usage when app is in the background. */
777 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 }
779
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700780 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800781 public int mWakeNesting;
782 public long mWakeSumMs;
783 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700784 }
785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 /**
787 * The statistics associated with a particular process.
788 */
789 public static abstract class Proc {
790
Dianne Hackborn287952c2010-09-22 22:34:31 -0700791 public static class ExcessivePower {
792 public static final int TYPE_WAKE = 1;
793 public static final int TYPE_CPU = 2;
794
795 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700796 public long overTime;
797 public long usedTime;
798 }
799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800801 * Returns true if this process is still active in the battery stats.
802 */
803 public abstract boolean isActive();
804
805 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700806 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700808 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 */
810 public abstract long getUserTime(int which);
811
812 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700813 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700815 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 */
817 public abstract long getSystemTime(int which);
818
819 /**
820 * Returns the number of times the process has been started.
821 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700822 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 */
824 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700825
826 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800827 * Returns the number of times the process has crashed.
828 *
829 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
830 */
831 public abstract int getNumCrashes(int which);
832
833 /**
834 * Returns the number of times the process has ANRed.
835 *
836 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
837 */
838 public abstract int getNumAnrs(int which);
839
840 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700841 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700842 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700843 * @return foreground cpu time in microseconds
844 */
845 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700846
Dianne Hackborn287952c2010-09-22 22:34:31 -0700847 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700848
Dianne Hackborn287952c2010-09-22 22:34:31 -0700849 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
851
852 /**
853 * The statistics associated with a particular package.
854 */
855 public static abstract class Pkg {
856
857 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700858 * Returns information about all wakeup alarms that have been triggered for this
859 * package. The mapping keys are tag names for the alarms, the counter contains
860 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700862 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863
864 /**
865 * Returns a mapping containing service statistics.
866 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700867 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868
869 /**
870 * The statistics associated with a particular service.
871 */
Joe Onoratoabded112016-02-08 16:49:39 -0800872 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873
874 /**
875 * Returns the amount of time spent started.
876 *
877 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700878 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 * @return
880 */
881 public abstract long getStartTime(long batteryUptime, int which);
882
883 /**
884 * Returns the total number of times startService() has been called.
885 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700886 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 */
888 public abstract int getStarts(int which);
889
890 /**
891 * Returns the total number times the service has been launched.
892 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700893 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 */
895 public abstract int getLaunches(int which);
896 }
897 }
898 }
899
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800900 public static final class LevelStepTracker {
901 public long mLastStepTime = -1;
902 public int mNumStepDurations;
903 public final long[] mStepDurations;
904
905 public LevelStepTracker(int maxLevelSteps) {
906 mStepDurations = new long[maxLevelSteps];
907 }
908
909 public LevelStepTracker(int numSteps, long[] steps) {
910 mNumStepDurations = numSteps;
911 mStepDurations = new long[numSteps];
912 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
913 }
914
915 public long getDurationAt(int index) {
916 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
917 }
918
919 public int getLevelAt(int index) {
920 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
921 >> STEP_LEVEL_LEVEL_SHIFT);
922 }
923
924 public int getInitModeAt(int index) {
925 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
926 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
927 }
928
929 public int getModModeAt(int index) {
930 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
931 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
932 }
933
934 private void appendHex(long val, int topOffset, StringBuilder out) {
935 boolean hasData = false;
936 while (topOffset >= 0) {
937 int digit = (int)( (val>>topOffset) & 0xf );
938 topOffset -= 4;
939 if (!hasData && digit == 0) {
940 continue;
941 }
942 hasData = true;
943 if (digit >= 0 && digit <= 9) {
944 out.append((char)('0' + digit));
945 } else {
946 out.append((char)('a' + digit - 10));
947 }
948 }
949 }
950
951 public void encodeEntryAt(int index, StringBuilder out) {
952 long item = mStepDurations[index];
953 long duration = item & STEP_LEVEL_TIME_MASK;
954 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
955 >> STEP_LEVEL_LEVEL_SHIFT);
956 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
957 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
958 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
959 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
960 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
961 case Display.STATE_OFF: out.append('f'); break;
962 case Display.STATE_ON: out.append('o'); break;
963 case Display.STATE_DOZE: out.append('d'); break;
964 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
965 }
966 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
967 out.append('p');
968 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700969 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
970 out.append('i');
971 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800972 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
973 case Display.STATE_OFF: out.append('F'); break;
974 case Display.STATE_ON: out.append('O'); break;
975 case Display.STATE_DOZE: out.append('D'); break;
976 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
977 }
978 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
979 out.append('P');
980 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700981 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
982 out.append('I');
983 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800984 out.append('-');
985 appendHex(level, 4, out);
986 out.append('-');
987 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
988 }
989
990 public void decodeEntryAt(int index, String value) {
991 final int N = value.length();
992 int i = 0;
993 char c;
994 long out = 0;
995 while (i < N && (c=value.charAt(i)) != '-') {
996 i++;
997 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800998 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800999 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001000 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001001 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001002 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001003 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001004 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1005 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1006 break;
1007 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1008 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1009 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001010 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1011 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1012 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001013 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1014 break;
1015 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1016 break;
1017 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1018 break;
1019 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1020 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1021 break;
1022 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1023 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001024 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001025 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1026 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1027 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001028 }
1029 }
1030 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001031 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001032 while (i < N && (c=value.charAt(i)) != '-') {
1033 i++;
1034 level <<= 4;
1035 if (c >= '0' && c <= '9') {
1036 level += c - '0';
1037 } else if (c >= 'a' && c <= 'f') {
1038 level += c - 'a' + 10;
1039 } else if (c >= 'A' && c <= 'F') {
1040 level += c - 'A' + 10;
1041 }
1042 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001043 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001044 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1045 long duration = 0;
1046 while (i < N && (c=value.charAt(i)) != '-') {
1047 i++;
1048 duration <<= 4;
1049 if (c >= '0' && c <= '9') {
1050 duration += c - '0';
1051 } else if (c >= 'a' && c <= 'f') {
1052 duration += c - 'a' + 10;
1053 } else if (c >= 'A' && c <= 'F') {
1054 duration += c - 'A' + 10;
1055 }
1056 }
1057 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1058 }
1059
1060 public void init() {
1061 mLastStepTime = -1;
1062 mNumStepDurations = 0;
1063 }
1064
1065 public void clearTime() {
1066 mLastStepTime = -1;
1067 }
1068
1069 public long computeTimePerLevel() {
1070 final long[] steps = mStepDurations;
1071 final int numSteps = mNumStepDurations;
1072
1073 // For now we'll do a simple average across all steps.
1074 if (numSteps <= 0) {
1075 return -1;
1076 }
1077 long total = 0;
1078 for (int i=0; i<numSteps; i++) {
1079 total += steps[i] & STEP_LEVEL_TIME_MASK;
1080 }
1081 return total / numSteps;
1082 /*
1083 long[] buckets = new long[numSteps];
1084 int numBuckets = 0;
1085 int numToAverage = 4;
1086 int i = 0;
1087 while (i < numSteps) {
1088 long totalTime = 0;
1089 int num = 0;
1090 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1091 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1092 num++;
1093 }
1094 buckets[numBuckets] = totalTime / num;
1095 numBuckets++;
1096 numToAverage *= 2;
1097 i += num;
1098 }
1099 if (numBuckets < 1) {
1100 return -1;
1101 }
1102 long averageTime = buckets[numBuckets-1];
1103 for (i=numBuckets-2; i>=0; i--) {
1104 averageTime = (averageTime + buckets[i]) / 2;
1105 }
1106 return averageTime;
1107 */
1108 }
1109
1110 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1111 int[] outNumOfInterest) {
1112 final long[] steps = mStepDurations;
1113 final int count = mNumStepDurations;
1114 if (count <= 0) {
1115 return -1;
1116 }
1117 long total = 0;
1118 int numOfInterest = 0;
1119 for (int i=0; i<count; i++) {
1120 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1121 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1122 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1123 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1124 // If the modes of interest didn't change during this step period...
1125 if ((modMode&modesOfInterest) == 0) {
1126 // And the mode values during this period match those we are measuring...
1127 if ((initMode&modesOfInterest) == modeValues) {
1128 // Then this can be used to estimate the total time!
1129 numOfInterest++;
1130 total += steps[i] & STEP_LEVEL_TIME_MASK;
1131 }
1132 }
1133 }
1134 if (numOfInterest <= 0) {
1135 return -1;
1136 }
1137
1138 if (outNumOfInterest != null) {
1139 outNumOfInterest[0] = numOfInterest;
1140 }
1141
1142 // The estimated time is the average time we spend in each level, multipled
1143 // by 100 -- the total number of battery levels
1144 return (total / numOfInterest) * 100;
1145 }
1146
1147 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1148 int stepCount = mNumStepDurations;
1149 final long lastStepTime = mLastStepTime;
1150 if (lastStepTime >= 0 && numStepLevels > 0) {
1151 final long[] steps = mStepDurations;
1152 long duration = elapsedRealtime - lastStepTime;
1153 for (int i=0; i<numStepLevels; i++) {
1154 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1155 long thisDuration = duration / (numStepLevels-i);
1156 duration -= thisDuration;
1157 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1158 thisDuration = STEP_LEVEL_TIME_MASK;
1159 }
1160 steps[0] = thisDuration | modeBits;
1161 }
1162 stepCount += numStepLevels;
1163 if (stepCount > steps.length) {
1164 stepCount = steps.length;
1165 }
1166 }
1167 mNumStepDurations = stepCount;
1168 mLastStepTime = elapsedRealtime;
1169 }
1170
1171 public void readFromParcel(Parcel in) {
1172 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001173 if (N > mStepDurations.length) {
1174 throw new ParcelFormatException("more step durations than available: " + N);
1175 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001176 mNumStepDurations = N;
1177 for (int i=0; i<N; i++) {
1178 mStepDurations[i] = in.readLong();
1179 }
1180 }
1181
1182 public void writeToParcel(Parcel out) {
1183 final int N = mNumStepDurations;
1184 out.writeInt(N);
1185 for (int i=0; i<N; i++) {
1186 out.writeLong(mStepDurations[i]);
1187 }
1188 }
1189 }
1190
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001191 public static final class PackageChange {
1192 public String mPackageName;
1193 public boolean mUpdate;
Dianne Hackborn3accca02013-09-20 09:32:11 -07001194 public long mVersionCode;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001195 }
1196
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001197 public static final class DailyItem {
1198 public long mStartTime;
1199 public long mEndTime;
1200 public LevelStepTracker mDischargeSteps;
1201 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001202 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001203 }
1204
1205 public abstract DailyItem getDailyItemLocked(int daysAgo);
1206
1207 public abstract long getCurrentDailyStartTime();
1208
1209 public abstract long getNextMinDailyDeadline();
1210
1211 public abstract long getNextMaxDailyDeadline();
1212
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001213 public abstract long[] getCpuFreqs();
1214
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001215 public final static class HistoryTag {
1216 public String string;
1217 public int uid;
1218
1219 public int poolIdx;
1220
1221 public void setTo(HistoryTag o) {
1222 string = o.string;
1223 uid = o.uid;
1224 poolIdx = o.poolIdx;
1225 }
1226
1227 public void setTo(String _string, int _uid) {
1228 string = _string;
1229 uid = _uid;
1230 poolIdx = -1;
1231 }
1232
1233 public void writeToParcel(Parcel dest, int flags) {
1234 dest.writeString(string);
1235 dest.writeInt(uid);
1236 }
1237
1238 public void readFromParcel(Parcel src) {
1239 string = src.readString();
1240 uid = src.readInt();
1241 poolIdx = -1;
1242 }
1243
1244 @Override
1245 public boolean equals(Object o) {
1246 if (this == o) return true;
1247 if (o == null || getClass() != o.getClass()) return false;
1248
1249 HistoryTag that = (HistoryTag) o;
1250
1251 if (uid != that.uid) return false;
1252 if (!string.equals(that.string)) return false;
1253
1254 return true;
1255 }
1256
1257 @Override
1258 public int hashCode() {
1259 int result = string.hashCode();
1260 result = 31 * result + uid;
1261 return result;
1262 }
1263 }
1264
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001265 /**
1266 * Optional detailed information that can go into a history step. This is typically
1267 * generated each time the battery level changes.
1268 */
1269 public final static class HistoryStepDetails {
1270 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1271 public int userTime;
1272 public int systemTime;
1273
1274 // Top three apps using CPU in the last step, with times in 1/100 second.
1275 public int appCpuUid1;
1276 public int appCpuUTime1;
1277 public int appCpuSTime1;
1278 public int appCpuUid2;
1279 public int appCpuUTime2;
1280 public int appCpuSTime2;
1281 public int appCpuUid3;
1282 public int appCpuUTime3;
1283 public int appCpuSTime3;
1284
1285 // Information from /proc/stat
1286 public int statUserTime;
1287 public int statSystemTime;
1288 public int statIOWaitTime;
1289 public int statIrqTime;
1290 public int statSoftIrqTime;
1291 public int statIdlTime;
1292
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001293 // Platform-level low power state stats
1294 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001295 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001296
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001297 public HistoryStepDetails() {
1298 clear();
1299 }
1300
1301 public void clear() {
1302 userTime = systemTime = 0;
1303 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1304 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1305 = appCpuUTime3 = appCpuSTime3 = 0;
1306 }
1307
1308 public void writeToParcel(Parcel out) {
1309 out.writeInt(userTime);
1310 out.writeInt(systemTime);
1311 out.writeInt(appCpuUid1);
1312 out.writeInt(appCpuUTime1);
1313 out.writeInt(appCpuSTime1);
1314 out.writeInt(appCpuUid2);
1315 out.writeInt(appCpuUTime2);
1316 out.writeInt(appCpuSTime2);
1317 out.writeInt(appCpuUid3);
1318 out.writeInt(appCpuUTime3);
1319 out.writeInt(appCpuSTime3);
1320 out.writeInt(statUserTime);
1321 out.writeInt(statSystemTime);
1322 out.writeInt(statIOWaitTime);
1323 out.writeInt(statIrqTime);
1324 out.writeInt(statSoftIrqTime);
1325 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001326 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001327 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001328 }
1329
1330 public void readFromParcel(Parcel in) {
1331 userTime = in.readInt();
1332 systemTime = in.readInt();
1333 appCpuUid1 = in.readInt();
1334 appCpuUTime1 = in.readInt();
1335 appCpuSTime1 = in.readInt();
1336 appCpuUid2 = in.readInt();
1337 appCpuUTime2 = in.readInt();
1338 appCpuSTime2 = in.readInt();
1339 appCpuUid3 = in.readInt();
1340 appCpuUTime3 = in.readInt();
1341 appCpuSTime3 = in.readInt();
1342 statUserTime = in.readInt();
1343 statSystemTime = in.readInt();
1344 statIOWaitTime = in.readInt();
1345 statIrqTime = in.readInt();
1346 statSoftIrqTime = in.readInt();
1347 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001348 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001349 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001350 }
1351 }
1352
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001353 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001354 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001355
1356 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001357 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001358
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001359 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001360 public static final byte CMD_NULL = -1;
1361 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001362 public static final byte CMD_CURRENT_TIME = 5;
1363 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001364 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001365 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001366
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001367 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001368
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001369 /**
1370 * Return whether the command code is a delta data update.
1371 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001372 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001373 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001374 }
1375
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001376 public byte batteryLevel;
1377 public byte batteryStatus;
1378 public byte batteryHealth;
1379 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001380
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001381 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001382 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001383
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001384 // The charge of the battery in micro-Ampere-hours.
1385 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001386
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001387 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001388 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001389 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001390 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001391 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1392 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001393 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001394 public static final int STATE_PHONE_STATE_SHIFT = 6;
1395 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001396 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001397 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001398 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001399
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001400 // These states always appear directly in the first int token
1401 // of a delta change; they should be ones that change relatively
1402 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001403 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1404 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001405 public static final int STATE_GPS_ON_FLAG = 1<<29;
1406 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001407 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001408 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001409 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001410 // Do not use, this is used for coulomb delta count.
1411 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001412 // These are on the lower bits used for the command; if they change
1413 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001414 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001415 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001416 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001417 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1418 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001419 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001420 // empty slot
1421 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001422
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001423 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001424 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001425
1426 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001427
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001428 public int states;
1429
Dianne Hackborn3251b902014-06-20 14:40:53 -07001430 // Constants from WIFI_SUPPL_STATE_*
1431 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1432 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1433 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1434 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1435 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1436 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1437
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001438 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001439 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1440 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1441 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001442 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001443 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1444 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1445 public static final int STATE2_CHARGING_FLAG = 1<<24;
1446 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1447 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1448 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001449 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001450
1451 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001452 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1453 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001454
1455 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001456
Dianne Hackborn40c87252014-03-19 16:55:40 -07001457 public int states2;
1458
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001459 // The wake lock that was acquired at this point.
1460 public HistoryTag wakelockTag;
1461
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001462 // Kernel wakeup reason at this point.
1463 public HistoryTag wakeReasonTag;
1464
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001465 // Non-null when there is more detailed information at this step.
1466 public HistoryStepDetails stepDetails;
1467
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001468 public static final int EVENT_FLAG_START = 0x8000;
1469 public static final int EVENT_FLAG_FINISH = 0x4000;
1470
1471 // No event in this item.
1472 public static final int EVENT_NONE = 0x0000;
1473 // Event is about a process that is running.
1474 public static final int EVENT_PROC = 0x0001;
1475 // Event is about an application package that is in the foreground.
1476 public static final int EVENT_FOREGROUND = 0x0002;
1477 // Event is about an application package that is at the top of the screen.
1478 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001479 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001480 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001481 // Events for all additional wake locks aquired/release within a wake block.
1482 // These are not generated by default.
1483 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001484 // Event is about an application executing a scheduled job.
1485 public static final int EVENT_JOB = 0x0006;
1486 // Events for users running.
1487 public static final int EVENT_USER_RUNNING = 0x0007;
1488 // Events for foreground user.
1489 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001490 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001491 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001492 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001493 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001494 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001495 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001496 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001497 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001498 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001499 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001500 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001501 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001502 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001503 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001504 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001505 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001506 // Event for a package being on the temporary whitelist.
1507 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001508 // Event for the screen waking up.
1509 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001510 // Event for the UID that woke up the application processor.
1511 // Used for wakeups coming from WiFi, modem, etc.
1512 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001513 // Event for reporting that a specific partial wake lock has been held for a long duration.
1514 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001515
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001516 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001517 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001518 // Mask to extract out only the type part of the event.
1519 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001520
1521 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1522 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1523 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1524 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1525 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1526 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001527 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1528 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001529 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1530 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001531 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1532 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1533 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1534 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1535 public static final int EVENT_USER_FOREGROUND_START =
1536 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1537 public static final int EVENT_USER_FOREGROUND_FINISH =
1538 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001539 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1540 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001541 public static final int EVENT_TEMP_WHITELIST_START =
1542 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1543 public static final int EVENT_TEMP_WHITELIST_FINISH =
1544 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001545 public static final int EVENT_LONG_WAKE_LOCK_START =
1546 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1547 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1548 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001549
1550 // For CMD_EVENT.
1551 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001552 public HistoryTag eventTag;
1553
Dianne Hackborn9a755432014-05-15 17:05:22 -07001554 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001555 public long currentTime;
1556
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001557 // Meta-data when reading.
1558 public int numReadInts;
1559
1560 // Pre-allocated objects.
1561 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001562 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001563 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001564
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001565 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001566 }
Bookatzc8c44962017-05-11 12:12:54 -07001567
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001568 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001569 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001570 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001571 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001572 }
Bookatzc8c44962017-05-11 12:12:54 -07001573
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001574 public int describeContents() {
1575 return 0;
1576 }
1577
1578 public void writeToParcel(Parcel dest, int flags) {
1579 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001580 int bat = (((int)cmd)&0xff)
1581 | ((((int)batteryLevel)<<8)&0xff00)
1582 | ((((int)batteryStatus)<<16)&0xf0000)
1583 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001584 | ((((int)batteryPlugType)<<24)&0xf000000)
1585 | (wakelockTag != null ? 0x10000000 : 0)
1586 | (wakeReasonTag != null ? 0x20000000 : 0)
1587 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001588 dest.writeInt(bat);
1589 bat = (((int)batteryTemperature)&0xffff)
1590 | ((((int)batteryVoltage)<<16)&0xffff0000);
1591 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001592 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001593 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001594 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001595 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001596 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001597 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001598 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001599 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001600 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001601 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001602 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001603 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001604 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001605 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001606 dest.writeLong(currentTime);
1607 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001608 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001609
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001610 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001611 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001612 int bat = src.readInt();
1613 cmd = (byte)(bat&0xff);
1614 batteryLevel = (byte)((bat>>8)&0xff);
1615 batteryStatus = (byte)((bat>>16)&0xf);
1616 batteryHealth = (byte)((bat>>20)&0xf);
1617 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001618 int bat2 = src.readInt();
1619 batteryTemperature = (short)(bat2&0xffff);
1620 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001621 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001622 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001623 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001624 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001625 wakelockTag = localWakelockTag;
1626 wakelockTag.readFromParcel(src);
1627 } else {
1628 wakelockTag = null;
1629 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001630 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001631 wakeReasonTag = localWakeReasonTag;
1632 wakeReasonTag.readFromParcel(src);
1633 } else {
1634 wakeReasonTag = null;
1635 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001636 if ((bat&0x40000000) != 0) {
1637 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001638 eventTag = localEventTag;
1639 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001640 } else {
1641 eventCode = EVENT_NONE;
1642 eventTag = null;
1643 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001644 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001645 currentTime = src.readLong();
1646 } else {
1647 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001648 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001649 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001650 }
1651
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001652 public void clear() {
1653 time = 0;
1654 cmd = CMD_NULL;
1655 batteryLevel = 0;
1656 batteryStatus = 0;
1657 batteryHealth = 0;
1658 batteryPlugType = 0;
1659 batteryTemperature = 0;
1660 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001661 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001662 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001663 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001664 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001665 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001666 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001667 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001668 }
Bookatzc8c44962017-05-11 12:12:54 -07001669
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001670 public void setTo(HistoryItem o) {
1671 time = o.time;
1672 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001673 setToCommon(o);
1674 }
1675
1676 public void setTo(long time, byte cmd, HistoryItem o) {
1677 this.time = time;
1678 this.cmd = cmd;
1679 setToCommon(o);
1680 }
1681
1682 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001683 batteryLevel = o.batteryLevel;
1684 batteryStatus = o.batteryStatus;
1685 batteryHealth = o.batteryHealth;
1686 batteryPlugType = o.batteryPlugType;
1687 batteryTemperature = o.batteryTemperature;
1688 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001689 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001690 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001691 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001692 if (o.wakelockTag != null) {
1693 wakelockTag = localWakelockTag;
1694 wakelockTag.setTo(o.wakelockTag);
1695 } else {
1696 wakelockTag = null;
1697 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001698 if (o.wakeReasonTag != null) {
1699 wakeReasonTag = localWakeReasonTag;
1700 wakeReasonTag.setTo(o.wakeReasonTag);
1701 } else {
1702 wakeReasonTag = null;
1703 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001704 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001705 if (o.eventTag != null) {
1706 eventTag = localEventTag;
1707 eventTag.setTo(o.eventTag);
1708 } else {
1709 eventTag = null;
1710 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001711 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001712 }
1713
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001714 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001715 return batteryLevel == o.batteryLevel
1716 && batteryStatus == o.batteryStatus
1717 && batteryHealth == o.batteryHealth
1718 && batteryPlugType == o.batteryPlugType
1719 && batteryTemperature == o.batteryTemperature
1720 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001721 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001722 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001723 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001724 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001725 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001726
1727 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001728 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001729 return false;
1730 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001731 if (wakelockTag != o.wakelockTag) {
1732 if (wakelockTag == null || o.wakelockTag == null) {
1733 return false;
1734 }
1735 if (!wakelockTag.equals(o.wakelockTag)) {
1736 return false;
1737 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001738 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001739 if (wakeReasonTag != o.wakeReasonTag) {
1740 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1741 return false;
1742 }
1743 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1744 return false;
1745 }
1746 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001747 if (eventTag != o.eventTag) {
1748 if (eventTag == null || o.eventTag == null) {
1749 return false;
1750 }
1751 if (!eventTag.equals(o.eventTag)) {
1752 return false;
1753 }
1754 }
1755 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001756 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001757 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001758
1759 public final static class HistoryEventTracker {
1760 private final HashMap<String, SparseIntArray>[] mActiveEvents
1761 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1762
1763 public boolean updateState(int code, String name, int uid, int poolIdx) {
1764 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1765 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1766 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1767 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001768 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001769 mActiveEvents[idx] = active;
1770 }
1771 SparseIntArray uids = active.get(name);
1772 if (uids == null) {
1773 uids = new SparseIntArray();
1774 active.put(name, uids);
1775 }
1776 if (uids.indexOfKey(uid) >= 0) {
1777 // Already set, nothing to do!
1778 return false;
1779 }
1780 uids.put(uid, poolIdx);
1781 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1782 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1783 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1784 if (active == null) {
1785 // not currently active, nothing to do.
1786 return false;
1787 }
1788 SparseIntArray uids = active.get(name);
1789 if (uids == null) {
1790 // not currently active, nothing to do.
1791 return false;
1792 }
1793 idx = uids.indexOfKey(uid);
1794 if (idx < 0) {
1795 // not currently active, nothing to do.
1796 return false;
1797 }
1798 uids.removeAt(idx);
1799 if (uids.size() <= 0) {
1800 active.remove(name);
1801 }
1802 }
1803 return true;
1804 }
1805
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001806 public void removeEvents(int code) {
1807 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1808 mActiveEvents[idx] = null;
1809 }
1810
Dianne Hackborn37de0982014-05-09 09:32:18 -07001811 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1812 return mActiveEvents[code];
1813 }
1814 }
1815
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001816 public static final class BitDescription {
1817 public final int mask;
1818 public final int shift;
1819 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001820 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001821 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001822 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001823
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001824 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001825 this.mask = mask;
1826 this.shift = -1;
1827 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001828 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001829 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001830 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001831 }
Bookatzc8c44962017-05-11 12:12:54 -07001832
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001833 public BitDescription(int mask, int shift, String name, String shortName,
1834 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001835 this.mask = mask;
1836 this.shift = shift;
1837 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001838 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001839 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001840 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001841 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001842 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001843
Dianne Hackbornfc064132014-06-02 12:42:12 -07001844 /**
1845 * Don't allow any more batching in to the current history event. This
1846 * is called when printing partial histories, so to ensure that the next
1847 * history event will go in to a new batch after what was printed in the
1848 * last partial history.
1849 */
1850 public abstract void commitCurrentHistoryBatchLocked();
1851
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001852 public abstract int getHistoryTotalSize();
1853
1854 public abstract int getHistoryUsedSize();
1855
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001856 public abstract boolean startIteratingHistoryLocked();
1857
Dianne Hackborn099bc622014-01-22 13:39:16 -08001858 public abstract int getHistoryStringPoolSize();
1859
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001860 public abstract int getHistoryStringPoolBytes();
1861
1862 public abstract String getHistoryTagPoolString(int index);
1863
1864 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001865
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001866 public abstract boolean getNextHistoryLocked(HistoryItem out);
1867
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001868 public abstract void finishIteratingHistoryLocked();
1869
1870 public abstract boolean startIteratingOldHistoryLocked();
1871
1872 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1873
1874 public abstract void finishIteratingOldHistoryLocked();
1875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001877 * Return the base time offset for the battery history.
1878 */
1879 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001880
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 * Returns the number of times the device has been started.
1883 */
1884 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001887 * 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 -08001888 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001889 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 * {@hide}
1891 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001892 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001893
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001894 /**
1895 * Returns the number of times the screen was turned on.
1896 *
1897 * {@hide}
1898 */
1899 public abstract int getScreenOnCount(int which);
1900
Mike Mac2f518a2017-09-19 16:06:03 -07001901 /**
1902 * Returns the time in microseconds that the screen has been dozing while the device was
1903 * running on battery.
1904 *
1905 * {@hide}
1906 */
1907 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
1908
1909 /**
1910 * Returns the number of times the screen was turned dozing.
1911 *
1912 * {@hide}
1913 */
1914 public abstract int getScreenDozeCount(int which);
1915
Jeff Browne95c3cd2014-05-02 16:59:26 -07001916 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1917
Dianne Hackborn617f8772009-03-31 15:04:46 -07001918 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1919 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1920 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1921 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1922 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001923
Dianne Hackborn617f8772009-03-31 15:04:46 -07001924 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1925 "dark", "dim", "medium", "light", "bright"
1926 };
Bookatzc8c44962017-05-11 12:12:54 -07001927
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001928 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1929 "0", "1", "2", "3", "4"
1930 };
1931
Dianne Hackborn617f8772009-03-31 15:04:46 -07001932 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001933
Dianne Hackborn617f8772009-03-31 15:04:46 -07001934 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001935 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001936 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001937 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001938 * {@hide}
1939 */
1940 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001941 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07001944 * Returns the {@link Timer} object that tracks the given screen brightness.
1945 *
1946 * {@hide}
1947 */
1948 public abstract Timer getScreenBrightnessTimer(int brightnessBin);
1949
1950 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001951 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001952 * running on battery.
1953 *
1954 * {@hide}
1955 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001956 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001957
1958 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001959 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001960 *
1961 * {@hide}
1962 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001963 public abstract int getPowerSaveModeEnabledCount(int which);
1964
1965 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001966 * Constant for device idle mode: not active.
1967 */
1968 public static final int DEVICE_IDLE_MODE_OFF = 0;
1969
1970 /**
1971 * Constant for device idle mode: active in lightweight mode.
1972 */
1973 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1974
1975 /**
1976 * Constant for device idle mode: active in full mode.
1977 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001978 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001979
1980 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001981 * Returns the time in microseconds that device has been in idle mode while
1982 * running on battery.
1983 *
1984 * {@hide}
1985 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001986 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001987
1988 /**
1989 * Returns the number of times that the devie has gone in to idle mode.
1990 *
1991 * {@hide}
1992 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001993 public abstract int getDeviceIdleModeCount(int mode, int which);
1994
1995 /**
1996 * Return the longest duration we spent in a particular device idle mode (fully in the
1997 * mode, not in idle maintenance etc).
1998 */
1999 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002000
2001 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002002 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002003 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002004 * counts all of the time that we consider the device to be idle, whether or not
2005 * it is currently in the actual device idle mode.
2006 *
2007 * {@hide}
2008 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002009 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002010
2011 /**
Bookatz8c6571b2017-10-24 15:04:41 -07002012 * Returns the number of times that the device has started idling.
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002013 *
2014 * {@hide}
2015 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002016 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002017
2018 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002019 * Returns the number of times that connectivity state changed.
2020 *
2021 * {@hide}
2022 */
2023 public abstract int getNumConnectivityChange(int which);
2024
2025 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002026 * 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 -08002027 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002028 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 * {@hide}
2030 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002031 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002032
Dianne Hackborn627bba72009-03-24 22:32:56 -07002033 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002034 * Returns the number of times a phone call was activated.
2035 *
2036 * {@hide}
2037 */
2038 public abstract int getPhoneOnCount(int which);
2039
2040 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002041 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002042 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002043 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002044 * {@hide}
2045 */
2046 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002047 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002048
Dianne Hackborn617f8772009-03-31 15:04:46 -07002049 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002050 * Returns the time in microseconds that the phone has been trying to
2051 * acquire a signal.
2052 *
2053 * {@hide}
2054 */
2055 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002056 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002057
2058 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002059 * Returns the {@link Timer} object that tracks how much the phone has been trying to
2060 * acquire a signal.
2061 *
2062 * {@hide}
2063 */
2064 public abstract Timer getPhoneSignalScanningTimer();
2065
2066 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002067 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002068 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002069 * {@hide}
2070 */
2071 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2072
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002073 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002074 * Return the {@link Timer} object used to track the given signal strength's duration and
2075 * counts.
2076 */
2077 protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin);
2078
2079 /**
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002080 * Returns the time in microseconds that the mobile network has been active
2081 * (in a high power state).
2082 *
2083 * {@hide}
2084 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002085 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002086
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002087 /**
2088 * Returns the number of times that the mobile network has transitioned to the
2089 * active state.
2090 *
2091 * {@hide}
2092 */
2093 public abstract int getMobileRadioActiveCount(int which);
2094
2095 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002096 * Returns the time in microseconds that is the difference between the mobile radio
2097 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2098 * from the radio.
2099 *
2100 * {@hide}
2101 */
2102 public abstract long getMobileRadioActiveAdjustedTime(int which);
2103
2104 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002105 * Returns the time in microseconds that the mobile network has been active
2106 * (in a high power state) but not being able to blame on an app.
2107 *
2108 * {@hide}
2109 */
2110 public abstract long getMobileRadioActiveUnknownTime(int which);
2111
2112 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002113 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002114 *
2115 * {@hide}
2116 */
2117 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002118
Dianne Hackborn627bba72009-03-24 22:32:56 -07002119 public static final int DATA_CONNECTION_NONE = 0;
2120 public static final int DATA_CONNECTION_GPRS = 1;
2121 public static final int DATA_CONNECTION_EDGE = 2;
2122 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002123 public static final int DATA_CONNECTION_CDMA = 4;
2124 public static final int DATA_CONNECTION_EVDO_0 = 5;
2125 public static final int DATA_CONNECTION_EVDO_A = 6;
2126 public static final int DATA_CONNECTION_1xRTT = 7;
2127 public static final int DATA_CONNECTION_HSDPA = 8;
2128 public static final int DATA_CONNECTION_HSUPA = 9;
2129 public static final int DATA_CONNECTION_HSPA = 10;
2130 public static final int DATA_CONNECTION_IDEN = 11;
2131 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002132 public static final int DATA_CONNECTION_LTE = 13;
2133 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002134 public static final int DATA_CONNECTION_HSPAP = 15;
2135 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002136
Dianne Hackborn627bba72009-03-24 22:32:56 -07002137 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002138 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002139 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002140 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002141 };
Bookatzc8c44962017-05-11 12:12:54 -07002142
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002143 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002144
Dianne Hackborn627bba72009-03-24 22:32:56 -07002145 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002146 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002147 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002148 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002149 * {@hide}
2150 */
2151 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002152 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002155 * Returns the number of times the phone has entered the given data
2156 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002157 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002158 * {@hide}
2159 */
2160 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002161
Kweku Adams87b19ec2017-10-09 12:40:03 -07002162 /**
2163 * Returns the {@link Timer} object that tracks the phone's data connection type stats.
2164 */
2165 public abstract Timer getPhoneDataConnectionTimer(int dataType);
2166
Dianne Hackborn3251b902014-06-20 14:40:53 -07002167 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2168 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2169 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2170 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2171 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2172 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2173 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2174 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2175 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2176 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2177 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2178 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2179 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2180
2181 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2182
2183 static final String[] WIFI_SUPPL_STATE_NAMES = {
2184 "invalid", "disconn", "disabled", "inactive", "scanning",
2185 "authenticating", "associating", "associated", "4-way-handshake",
2186 "group-handshake", "completed", "dormant", "uninit"
2187 };
2188
2189 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2190 "inv", "dsc", "dis", "inact", "scan",
2191 "auth", "ascing", "asced", "4-way",
2192 "group", "compl", "dorm", "uninit"
2193 };
2194
Mike Mac2f518a2017-09-19 16:06:03 -07002195 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002196 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002197 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2198 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002199 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002200 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2201 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2202 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002203 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002204 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002205 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002206 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002207 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2208 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002209 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002210 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2211 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2212 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2213 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2214 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2215 new String[] {"in", "out", "emergency", "off"},
2216 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002217 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2218 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2219 SignalStrength.SIGNAL_STRENGTH_NAMES,
2220 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002221 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2222 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2223 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002224 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002225
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002226 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2227 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002228 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002229 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002230 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002231 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002232 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002233 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2234 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2235 new String[] { "off", "light", "full", "???" },
2236 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002237 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2238 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2239 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002240 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2241 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2242 new String[] { "0", "1", "2", "3", "4" },
2243 new String[] { "0", "1", "2", "3", "4" }),
2244 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2245 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2246 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002247 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002248 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002249 };
2250
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002251 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002252 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002253 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2254 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002255 };
2256
2257 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002258 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002259 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002260 "Esw", "Ewa", "Elw", "Eec"
2261 };
2262
2263 @FunctionalInterface
2264 public interface IntToString {
2265 String applyAsString(int val);
2266 }
2267
2268 private static final IntToString sUidToString = UserHandle::formatUid;
2269 private static final IntToString sIntToString = Integer::toString;
2270
2271 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2272 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2273 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2274 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2275 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002276 };
2277
Dianne Hackborn617f8772009-03-31 15:04:46 -07002278 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002279 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002280 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002281 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002282 * {@hide}
2283 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002284 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002285
2286 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002287 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002288 * been in the running state while the device was running on battery.
2289 *
2290 * {@hide}
2291 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002292 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002293
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002294 public static final int WIFI_STATE_OFF = 0;
2295 public static final int WIFI_STATE_OFF_SCANNING = 1;
2296 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2297 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2298 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2299 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2300 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2301 public static final int WIFI_STATE_SOFT_AP = 7;
2302
2303 static final String[] WIFI_STATE_NAMES = {
2304 "off", "scanning", "no_net", "disconn",
2305 "sta", "p2p", "sta_p2p", "soft_ap"
2306 };
2307
2308 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2309
2310 /**
2311 * Returns the time in microseconds that WiFi has been running in the given state.
2312 *
2313 * {@hide}
2314 */
2315 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002316 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002317
2318 /**
2319 * Returns the number of times that WiFi has entered the given state.
2320 *
2321 * {@hide}
2322 */
2323 public abstract int getWifiStateCount(int wifiState, int which);
2324
The Android Open Source Project10592532009-03-18 17:39:46 -07002325 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002326 * Returns the {@link Timer} object that tracks the given WiFi state.
2327 *
2328 * {@hide}
2329 */
2330 public abstract Timer getWifiStateTimer(int wifiState);
2331
2332 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002333 * Returns the time in microseconds that the wifi supplicant has been
2334 * in a given state.
2335 *
2336 * {@hide}
2337 */
2338 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2339
2340 /**
2341 * Returns the number of times that the wifi supplicant has transitioned
2342 * to a given state.
2343 *
2344 * {@hide}
2345 */
2346 public abstract int getWifiSupplStateCount(int state, int which);
2347
Kweku Adams87b19ec2017-10-09 12:40:03 -07002348 /**
2349 * Returns the {@link Timer} object that tracks the given wifi supplicant state.
2350 *
2351 * {@hide}
2352 */
2353 public abstract Timer getWifiSupplStateTimer(int state);
2354
Dianne Hackborn3251b902014-06-20 14:40:53 -07002355 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2356
2357 /**
2358 * Returns the time in microseconds that WIFI has been running with
2359 * the given signal strength.
2360 *
2361 * {@hide}
2362 */
2363 public abstract long getWifiSignalStrengthTime(int strengthBin,
2364 long elapsedRealtimeUs, int which);
2365
2366 /**
2367 * Returns the number of times WIFI has entered the given signal strength.
2368 *
2369 * {@hide}
2370 */
2371 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2372
2373 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002374 * Returns the {@link Timer} object that tracks the given WIFI signal strength.
2375 *
2376 * {@hide}
2377 */
2378 public abstract Timer getWifiSignalStrengthTimer(int strengthBin);
2379
2380 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002381 * Returns the time in microseconds that the flashlight has been on while the device was
2382 * running on battery.
2383 *
2384 * {@hide}
2385 */
2386 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2387
2388 /**
2389 * Returns the number of times that the flashlight has been turned on while the device was
2390 * running on battery.
2391 *
2392 * {@hide}
2393 */
2394 public abstract long getFlashlightOnCount(int which);
2395
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002396 /**
2397 * Returns the time in microseconds that the camera has been on while the device was
2398 * running on battery.
2399 *
2400 * {@hide}
2401 */
2402 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2403
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002404 /**
2405 * Returns the time in microseconds that bluetooth scans were running while the device was
2406 * on battery.
2407 *
2408 * {@hide}
2409 */
2410 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002411
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002412 public static final int NETWORK_MOBILE_RX_DATA = 0;
2413 public static final int NETWORK_MOBILE_TX_DATA = 1;
2414 public static final int NETWORK_WIFI_RX_DATA = 2;
2415 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002416 public static final int NETWORK_BT_RX_DATA = 4;
2417 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002418 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2419 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2420 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2421 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2422 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002423
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002424 public abstract long getNetworkActivityBytes(int type, int which);
2425 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002426
Adam Lesinskie08af192015-03-25 16:42:59 -07002427 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002428 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002429 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002430 * actual power data.
2431 */
2432 public abstract boolean hasWifiActivityReporting();
2433
2434 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002435 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2436 * in various radio controller states, such as transmit, receive, and idle.
2437 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002438 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002439 public abstract ControllerActivityCounter getWifiControllerActivity();
2440
2441 /**
2442 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2443 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2444 * actual power data.
2445 */
2446 public abstract boolean hasBluetoothActivityReporting();
2447
2448 /**
2449 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2450 * in various radio controller states, such as transmit, receive, and idle.
2451 * @return non-null {@link ControllerActivityCounter}
2452 */
2453 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2454
2455 /**
2456 * Returns true if the BatteryStats object has detailed modem power reports.
2457 * When true, calling {@link #getModemControllerActivity()} will yield the
2458 * actual power data.
2459 */
2460 public abstract boolean hasModemActivityReporting();
2461
2462 /**
2463 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2464 * in various radio controller states, such as transmit, receive, and idle.
2465 * @return non-null {@link ControllerActivityCounter}
2466 */
2467 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002468
The Android Open Source Project10592532009-03-18 17:39:46 -07002469 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002470 * Return the wall clock time when battery stats data collection started.
2471 */
2472 public abstract long getStartClockTime();
2473
2474 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002475 * Return platform version tag that we were running in when the battery stats started.
2476 */
2477 public abstract String getStartPlatformVersion();
2478
2479 /**
2480 * Return platform version tag that we were running in when the battery stats ended.
2481 */
2482 public abstract String getEndPlatformVersion();
2483
2484 /**
2485 * Return the internal version code of the parcelled format.
2486 */
2487 public abstract int getParcelVersion();
2488
2489 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 * Return whether we are currently running on battery.
2491 */
2492 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 /**
2495 * Returns a SparseArray containing the statistics for each uid.
2496 */
2497 public abstract SparseArray<? extends Uid> getUidStats();
2498
2499 /**
2500 * Returns the current battery uptime in microseconds.
2501 *
2502 * @param curTime the amount of elapsed realtime in microseconds.
2503 */
2504 public abstract long getBatteryUptime(long curTime);
2505
2506 /**
2507 * Returns the current battery realtime in microseconds.
2508 *
2509 * @param curTime the amount of elapsed realtime in microseconds.
2510 */
2511 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002512
The Android Open Source Project10592532009-03-18 17:39:46 -07002513 /**
Evan Millar633a1742009-04-02 16:36:33 -07002514 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002515 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002516 */
Evan Millar633a1742009-04-02 16:36:33 -07002517 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002518
The Android Open Source Project10592532009-03-18 17:39:46 -07002519 /**
Evan Millar633a1742009-04-02 16:36:33 -07002520 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2521 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002522 */
Evan Millar633a1742009-04-02 16:36:33 -07002523 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524
2525 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002526 * Get the amount the battery has discharged since the stats were
2527 * last reset after charging, as a lower-end approximation.
2528 */
2529 public abstract int getLowDischargeAmountSinceCharge();
2530
2531 /**
2532 * Get the amount the battery has discharged since the stats were
2533 * last reset after charging, as an upper-end approximation.
2534 */
2535 public abstract int getHighDischargeAmountSinceCharge();
2536
2537 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002538 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2539 */
2540 public abstract int getDischargeAmount(int which);
2541
2542 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002543 * Get the amount the battery has discharged while the screen was on,
2544 * since the last time power was unplugged.
2545 */
2546 public abstract int getDischargeAmountScreenOn();
2547
2548 /**
2549 * Get the amount the battery has discharged while the screen was on,
2550 * since the last time the device was charged.
2551 */
2552 public abstract int getDischargeAmountScreenOnSinceCharge();
2553
2554 /**
2555 * Get the amount the battery has discharged while the screen was off,
2556 * since the last time power was unplugged.
2557 */
2558 public abstract int getDischargeAmountScreenOff();
2559
2560 /**
2561 * Get the amount the battery has discharged while the screen was off,
2562 * since the last time the device was charged.
2563 */
2564 public abstract int getDischargeAmountScreenOffSinceCharge();
2565
2566 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002567 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002568 * since the last time power was unplugged.
2569 */
2570 public abstract int getDischargeAmountScreenDoze();
2571
2572 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002573 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002574 * since the last time the device was charged.
2575 */
2576 public abstract int getDischargeAmountScreenDozeSinceCharge();
2577
2578 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 * Returns the total, last, or current battery uptime in microseconds.
2580 *
2581 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002582 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 */
2584 public abstract long computeBatteryUptime(long curTime, int which);
2585
2586 /**
2587 * Returns the total, last, or current battery realtime in microseconds.
2588 *
2589 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002590 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 */
2592 public abstract long computeBatteryRealtime(long curTime, int which);
2593
2594 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002595 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002596 *
2597 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002598 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002599 */
2600 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2601
2602 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002603 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002604 *
2605 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002606 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002607 */
2608 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2609
2610 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 * Returns the total, last, or current uptime in microseconds.
2612 *
2613 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002614 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 */
2616 public abstract long computeUptime(long curTime, int which);
2617
2618 /**
2619 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002620 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002622 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 */
2624 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002625
2626 /**
2627 * Compute an approximation for how much run time (in microseconds) is remaining on
2628 * the battery. Returns -1 if no time can be computed: either there is not
2629 * enough current data to make a decision, or the battery is currently
2630 * charging.
2631 *
2632 * @param curTime The current elepsed realtime in microseconds.
2633 */
2634 public abstract long computeBatteryTimeRemaining(long curTime);
2635
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002636 // The part of a step duration that is the actual time.
2637 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2638
2639 // Bits in a step duration that are the new battery level we are at.
2640 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002641 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002642
2643 // Bits in a step duration that are the initial mode we were in at that step.
2644 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002645 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002646
2647 // Bits in a step duration that indicate which modes changed during that step.
2648 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002649 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002650
2651 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2652 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2653
Santos Cordone94f0502017-02-24 12:31:20 -08002654 // The largest value for screen state that is tracked in battery states. Any values above
2655 // this should be mapped back to one of the tracked values before being tracked here.
2656 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2657
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002658 // Step duration mode: power save is on.
2659 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2660
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002661 // Step duration mode: device is currently in idle mode.
2662 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2663
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002664 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2665 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002666 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2667 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002668 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2669 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2670 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2671 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2672 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002673 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2674 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002675 };
2676 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2677 (Display.STATE_OFF-1),
2678 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002679 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002680 (Display.STATE_ON-1),
2681 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2682 (Display.STATE_DOZE-1),
2683 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2684 (Display.STATE_DOZE_SUSPEND-1),
2685 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002686 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002687 };
2688 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2689 "screen off",
2690 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002691 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002692 "screen on",
2693 "screen on power save",
2694 "screen doze",
2695 "screen doze power save",
2696 "screen doze-suspend",
2697 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002698 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002699 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002700
2701 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002702 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002703 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2704 * a coulomb counter.
2705 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002706 public abstract long getUahDischargeScreenOff(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002707
2708 /**
2709 * Return the amount of battery discharge while the screen was in doze mode, measured in
2710 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2711 * a coulomb counter.
2712 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002713 public abstract long getUahDischargeScreenDoze(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002714
2715 /**
2716 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2717 * non-zero only if the device's battery has a coulomb counter.
2718 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002719 public abstract long getUahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002720
2721 /**
Mike Ma15313c92017-11-15 17:58:21 -08002722 * @return the amount of battery discharge while the device is in light idle mode, measured in
2723 * micro-Ampere-hours.
2724 */
2725 public abstract long getUahDischargeLightDoze(int which);
2726
2727 /**
2728 * @return the amount of battery discharge while the device is in deep idle mode, measured in
2729 * micro-Ampere-hours.
2730 */
2731 public abstract long getUahDischargeDeepDoze(int which);
2732
2733 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002734 * Returns the estimated real battery capacity, which may be less than the capacity
2735 * declared by the PowerProfile.
2736 * @return The estimated battery capacity in mAh.
2737 */
2738 public abstract int getEstimatedBatteryCapacity();
2739
2740 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002741 * @return The minimum learned battery capacity in uAh.
2742 */
2743 public abstract int getMinLearnedBatteryCapacity();
2744
2745 /**
2746 * @return The maximum learned battery capacity in uAh.
2747 */
2748 public abstract int getMaxLearnedBatteryCapacity() ;
2749
2750 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002751 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002752 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002753 public abstract LevelStepTracker getDischargeLevelStepTracker();
2754
2755 /**
2756 * Return the array of daily discharge step durations.
2757 */
2758 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002759
2760 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002761 * Compute an approximation for how much time (in microseconds) remains until the battery
2762 * is fully charged. Returns -1 if no time can be computed: either there is not
2763 * enough current data to make a decision, or the battery is currently
2764 * discharging.
2765 *
2766 * @param curTime The current elepsed realtime in microseconds.
2767 */
2768 public abstract long computeChargeTimeRemaining(long curTime);
2769
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002770 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002771 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002772 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002773 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002774
2775 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002776 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002777 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002778 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002779
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002780 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2781
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002782 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002783
Evan Millarc64edde2009-04-18 12:26:32 -07002784 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785
Bookatz50df7112017-08-04 14:53:26 -07002786 /**
2787 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2788 */
2789 public abstract Map<String, ? extends Timer> getRpmStats();
2790 /**
2791 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2792 */
2793 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2794
2795
James Carr2dd7e5e2016-07-20 18:48:39 -07002796 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2797
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002798 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2799
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002800 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 long days = seconds / (60 * 60 * 24);
2802 if (days != 0) {
2803 out.append(days);
2804 out.append("d ");
2805 }
2806 long used = days * 60 * 60 * 24;
2807
2808 long hours = (seconds - used) / (60 * 60);
2809 if (hours != 0 || used != 0) {
2810 out.append(hours);
2811 out.append("h ");
2812 }
2813 used += hours * 60 * 60;
2814
2815 long mins = (seconds-used) / 60;
2816 if (mins != 0 || used != 0) {
2817 out.append(mins);
2818 out.append("m ");
2819 }
2820 used += mins * 60;
2821
2822 if (seconds != 0 || used != 0) {
2823 out.append(seconds-used);
2824 out.append("s ");
2825 }
2826 }
2827
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002828 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002830 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 sb.append(time - (sec * 1000));
2832 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002835 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002836 long sec = time / 1000;
2837 formatTimeRaw(sb, sec);
2838 sb.append(time - (sec * 1000));
2839 sb.append("ms");
2840 }
2841
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002842 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002844 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 }
2846 float perc = ((float)num) / ((float)den) * 100;
2847 mFormatBuilder.setLength(0);
2848 mFormatter.format("%.1f%%", perc);
2849 return mFormatBuilder.toString();
2850 }
2851
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002852 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002853 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002854
Evan Millar22ac0432009-03-31 11:33:18 -07002855 if (bytes < BYTES_PER_KB) {
2856 return bytes + "B";
2857 } else if (bytes < BYTES_PER_MB) {
2858 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2859 return mFormatBuilder.toString();
2860 } else if (bytes < BYTES_PER_GB){
2861 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2862 return mFormatBuilder.toString();
2863 } else {
2864 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2865 return mFormatBuilder.toString();
2866 }
2867 }
2868
Kweku Adams103351f2017-10-16 14:39:34 -07002869 private static long roundUsToMs(long timeUs) {
2870 return (timeUs + 500) / 1000;
2871 }
2872
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002873 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002874 if (timer != null) {
2875 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002876 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002877 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2878 return totalTimeMillis;
2879 }
2880 return 0;
2881 }
2882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 /**
2884 *
2885 * @param sb a StringBuilder object.
2886 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002887 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002889 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 * @param linePrefix a String to be prepended to each line of output.
2891 * @return the line prefix
2892 */
2893 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002894 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002897 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002898
Evan Millarc64edde2009-04-18 12:26:32 -07002899 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 if (totalTimeMillis != 0) {
2901 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002902 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002903 if (name != null) {
2904 sb.append(name);
2905 sb.append(' ');
2906 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 sb.append('(');
2908 sb.append(count);
2909 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002910 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2911 if (maxDurationMs >= 0) {
2912 sb.append(" max=");
2913 sb.append(maxDurationMs);
2914 }
Bookatz506a8182017-05-01 14:18:42 -07002915 // Put actual time if it is available and different from totalTimeMillis.
2916 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2917 if (totalDurMs > totalTimeMillis) {
2918 sb.append(" actual=");
2919 sb.append(totalDurMs);
2920 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002921 if (timer.isRunningLocked()) {
2922 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2923 if (currentMs >= 0) {
2924 sb.append(" (running for ");
2925 sb.append(currentMs);
2926 sb.append("ms)");
2927 } else {
2928 sb.append(" (running)");
2929 }
2930 }
2931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 return ", ";
2933 }
2934 }
2935 return linePrefix;
2936 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002937
2938 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002939 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002940 *
2941 * @param pw a PrintWriter object to print to.
2942 * @param sb a StringBuilder object.
2943 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002944 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002945 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2946 * @param prefix a String to be prepended to each line of output.
2947 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002948 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002949 */
2950 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002951 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002952 if (timer != null) {
2953 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002954 final long totalTimeMs = (timer.getTotalTimeLocked(
2955 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002956 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002957 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002958 sb.setLength(0);
2959 sb.append(prefix);
2960 sb.append(" ");
2961 sb.append(type);
2962 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002963 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002964 sb.append("realtime (");
2965 sb.append(count);
2966 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002967 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2968 if (maxDurationMs >= 0) {
2969 sb.append(" max=");
2970 sb.append(maxDurationMs);
2971 }
2972 if (timer.isRunningLocked()) {
2973 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2974 if (currentMs >= 0) {
2975 sb.append(" (running for ");
2976 sb.append(currentMs);
2977 sb.append("ms)");
2978 } else {
2979 sb.append(" (running)");
2980 }
2981 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002982 pw.println(sb.toString());
2983 return true;
2984 }
2985 }
2986 return false;
2987 }
Bookatzc8c44962017-05-11 12:12:54 -07002988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 /**
2990 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002991 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 * @param sb a StringBuilder object.
2993 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002994 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002996 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 * @param linePrefix a String to be prepended to each line of output.
2998 * @return the line prefix
2999 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003000 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
3001 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 long totalTimeMicros = 0;
3003 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07003004 long max = 0;
3005 long current = 0;
3006 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003008 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07003009 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003010 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
3011 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07003012 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 }
3014 sb.append(linePrefix);
3015 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
3016 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07003017 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003019 sb.append(',');
3020 sb.append(current);
3021 sb.append(',');
3022 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07003023 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
3024 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
3025 // totalDuration independent of totalTimeMicros (since they are not pooled).
3026 if (name != null) {
3027 sb.append(',');
3028 sb.append(totalDuration);
3029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 return ",";
3031 }
Bookatz506a8182017-05-01 14:18:42 -07003032
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003033 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
3034 String type) {
3035 pw.print(BATTERY_STATS_CHECKIN_VERSION);
3036 pw.print(',');
3037 pw.print(uid);
3038 pw.print(',');
3039 pw.print(category);
3040 pw.print(',');
3041 pw.print(type);
3042 }
3043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 /**
3045 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07003046 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 * @param pw the PageWriter to dump log to
3048 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3049 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3050 * @param args type-dependent data arguments
3051 */
Bookatzc8c44962017-05-11 12:12:54 -07003052 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003054 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003055 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003056 pw.print(',');
3057 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003059 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07003061
3062 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003063 * Dump a given timer stat for terse checkin mode.
3064 *
3065 * @param pw the PageWriter to dump log to
3066 * @param uid the UID to log
3067 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3068 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3069 * @param timer a {@link Timer} to dump stats for
3070 * @param rawRealtime the current elapsed realtime of the system in microseconds
3071 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3072 */
3073 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
3074 Timer timer, long rawRealtime, int which) {
3075 if (timer != null) {
3076 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003077 final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which));
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003078 final int count = timer.getCountLocked(which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003079 if (totalTime != 0 || count != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003080 dumpLine(pw, uid, category, type, totalTime, count);
3081 }
3082 }
3083 }
3084
3085 /**
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003086 * Dump a given timer stat to the proto stream.
3087 *
3088 * @param proto the ProtoOutputStream to log to
3089 * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK)
3090 * @param timer a {@link Timer} to dump stats for
3091 * @param rawRealtimeUs the current elapsed realtime of the system in microseconds
3092 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3093 */
3094 private static void dumpTimer(ProtoOutputStream proto, long fieldId,
Kweku Adams87b19ec2017-10-09 12:40:03 -07003095 Timer timer, long rawRealtimeUs, int which) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003096 if (timer == null) {
3097 return;
3098 }
3099 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003100 final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which));
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003101 final int count = timer.getCountLocked(which);
Kweku Adams103351f2017-10-16 14:39:34 -07003102 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000);
3103 final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000);
3104 final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000);
3105 if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1
3106 || totalDurationMs != -1) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003107 final long token = proto.start(fieldId);
Kweku Adams103351f2017-10-16 14:39:34 -07003108 proto.write(TimerProto.DURATION_MS, timeMs);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003109 proto.write(TimerProto.COUNT, count);
Kweku Adams103351f2017-10-16 14:39:34 -07003110 // These values will be -1 for timers that don't implement the functionality.
3111 if (maxDurationMs != -1) {
3112 proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs);
3113 }
3114 if (curDurationMs != -1) {
3115 proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs);
3116 }
3117 if (totalDurationMs != -1) {
3118 proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs);
3119 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003120 proto.end(token);
3121 }
3122 }
3123
3124 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003125 * Checks if the ControllerActivityCounter has any data worth dumping.
3126 */
3127 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
3128 if (counter == null) {
3129 return false;
3130 }
3131
3132 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
3133 || counter.getRxTimeCounter().getCountLocked(which) != 0
3134 || counter.getPowerCounter().getCountLocked(which) != 0) {
3135 return true;
3136 }
3137
3138 for (LongCounter c : counter.getTxTimeCounters()) {
3139 if (c.getCountLocked(which) != 0) {
3140 return true;
3141 }
3142 }
3143 return false;
3144 }
3145
3146 /**
3147 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3148 * The order of the arguments in the final check in line is:
3149 *
3150 * idle, rx, power, tx...
3151 *
3152 * where tx... is one or more transmit level times.
3153 */
3154 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3155 String type,
3156 ControllerActivityCounter counter,
3157 int which) {
3158 if (!controllerActivityHasData(counter, which)) {
3159 return;
3160 }
3161
3162 dumpLineHeader(pw, uid, category, type);
3163 pw.print(",");
3164 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3165 pw.print(",");
3166 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3167 pw.print(",");
3168 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3169 for (LongCounter c : counter.getTxTimeCounters()) {
3170 pw.print(",");
3171 pw.print(c.getCountLocked(which));
3172 }
3173 pw.println();
3174 }
3175
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003176 /**
3177 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3178 */
3179 private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId,
3180 ControllerActivityCounter counter,
3181 int which) {
3182 if (!controllerActivityHasData(counter, which)) {
3183 return;
3184 }
3185
3186 final long cToken = proto.start(fieldId);
3187
3188 proto.write(ControllerActivityProto.IDLE_DURATION_MS,
3189 counter.getIdleTimeCounter().getCountLocked(which));
3190 proto.write(ControllerActivityProto.RX_DURATION_MS,
3191 counter.getRxTimeCounter().getCountLocked(which));
3192 proto.write(ControllerActivityProto.POWER_MAH,
3193 counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3194
3195 long tToken;
3196 LongCounter[] txCounters = counter.getTxTimeCounters();
3197 for (int i = 0; i < txCounters.length; ++i) {
3198 LongCounter c = txCounters[i];
3199 tToken = proto.start(ControllerActivityProto.TX);
3200 proto.write(ControllerActivityProto.TxLevel.LEVEL, i);
3201 proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which));
3202 proto.end(tToken);
3203 }
3204
3205 proto.end(cToken);
3206 }
3207
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003208 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3209 String prefix, String controllerName,
3210 ControllerActivityCounter counter,
3211 int which) {
3212 if (controllerActivityHasData(counter, which)) {
3213 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3214 }
3215 }
3216
3217 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3218 String controllerName,
3219 ControllerActivityCounter counter, int which) {
3220 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3221 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3222 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003223 // Battery real time
3224 final long totalControllerActivityTimeMs
3225 = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000;
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003226 long totalTxTimeMs = 0;
3227 for (LongCounter txState : counter.getTxTimeCounters()) {
3228 totalTxTimeMs += txState.getCountLocked(which);
3229 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003230 final long sleepTimeMs
3231 = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003232
3233 sb.setLength(0);
3234 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003235 sb.append(" ");
3236 sb.append(controllerName);
3237 sb.append(" Sleep time: ");
3238 formatTimeMs(sb, sleepTimeMs);
3239 sb.append("(");
3240 sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs));
3241 sb.append(")");
3242 pw.println(sb.toString());
3243
3244 sb.setLength(0);
3245 sb.append(prefix);
3246 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003247 sb.append(controllerName);
3248 sb.append(" Idle time: ");
3249 formatTimeMs(sb, idleTimeMs);
3250 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003251 sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003252 sb.append(")");
3253 pw.println(sb.toString());
3254
3255 sb.setLength(0);
3256 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003257 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003258 sb.append(controllerName);
3259 sb.append(" Rx time: ");
3260 formatTimeMs(sb, rxTimeMs);
3261 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003262 sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003263 sb.append(")");
3264 pw.println(sb.toString());
3265
3266 sb.setLength(0);
3267 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003268 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003269 sb.append(controllerName);
3270 sb.append(" Tx time: ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003271
Siddharth Ray3c648c42017-10-02 17:30:58 -07003272 String [] powerLevel;
3273 switch(controllerName) {
3274 case "Cellular":
3275 powerLevel = new String[] {
3276 " less than 0dBm: ",
3277 " 0dBm to 8dBm: ",
3278 " 8dBm to 15dBm: ",
3279 " 15dBm to 20dBm: ",
3280 " above 20dBm: "};
3281 break;
3282 default:
3283 powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"};
3284 break;
3285 }
3286 final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003287 if (numTxLvls > 1) {
Siddharth Ray3c648c42017-10-02 17:30:58 -07003288 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003289 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3290 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3291 sb.setLength(0);
3292 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003293 sb.append(" ");
3294 sb.append(powerLevel[lvl]);
3295 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003296 formatTimeMs(sb, txLvlTimeMs);
3297 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003298 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003299 sb.append(")");
3300 pw.println(sb.toString());
3301 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003302 } else {
3303 final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which);
3304 formatTimeMs(sb, txLvlTimeMs);
3305 sb.append("(");
3306 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
3307 sb.append(")");
3308 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003309 }
3310
Siddharth Ray3c648c42017-10-02 17:30:58 -07003311 if (powerDrainMaMs > 0) {
3312 sb.setLength(0);
3313 sb.append(prefix);
3314 sb.append(" ");
3315 sb.append(controllerName);
3316 sb.append(" Battery drain: ").append(
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003317 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
Siddharth Ray3c648c42017-10-02 17:30:58 -07003318 sb.append("mAh");
3319 pw.println(sb.toString());
3320 }
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003321 }
3322
3323 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003324 * Temporary for settings.
3325 */
3326 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3327 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3328 }
3329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 /**
3331 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003332 *
Kweku Adams87b19ec2017-10-09 12:40:03 -07003333 * NOTE: all times are expressed in microseconds, unless specified otherwise.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003335 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3336 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 final long rawUptime = SystemClock.uptimeMillis() * 1000;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003338 final long rawRealtimeMs = SystemClock.elapsedRealtime();
3339 final long rawRealtime = rawRealtimeMs * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3342 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003343 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3344 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3345 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 final long totalRealtime = computeRealtime(rawRealtime, which);
3347 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003348 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003349 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003350 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003351 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003352 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3353 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003354 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003355 rawRealtime, which);
3356 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3357 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003358 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003359 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003360 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003361 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003362 final long dischargeCount = getUahDischarge(which);
3363 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
3364 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Ma15313c92017-11-15 17:58:21 -08003365 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
3366 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003367
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003368 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003369
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003370 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003371 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003372
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003373 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003376 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003377 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003378 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003379 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003380 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003381 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003382 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003383 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3384 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003385
Bookatzc8c44962017-05-11 12:12:54 -07003386
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003387 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003388 long fullWakeLockTimeTotal = 0;
3389 long partialWakeLockTimeTotal = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003390 long multicastWakeLockTimeTotalMicros = 0;
3391 int multicastWakeLockCountTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003392
Evan Millar22ac0432009-03-31 11:33:18 -07003393 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003394 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003395
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003396 // First calculating the wakelock stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003397 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3398 = u.getWakelockStats();
3399 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3400 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003401
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003402 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3403 if (fullWakeTimer != null) {
3404 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3405 which);
3406 }
3407
3408 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3409 if (partialWakeTimer != null) {
3410 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3411 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003412 }
3413 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003414
3415 // Now calculating the wifi multicast wakelock stats
3416 final Timer mcTimer = u.getMulticastWakelockStats();
3417 if (mcTimer != null) {
3418 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
3419 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
3420 }
Evan Millar22ac0432009-03-31 11:33:18 -07003421 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003422
3423 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003424 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3425 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3426 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3427 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3428 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3429 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3430 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3431 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003432 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3433 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003434 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3435 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003436 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3437 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003438
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003439 // Dump Modem controller stats
3440 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3441 getModemControllerActivity(), which);
3442
Adam Lesinskie283d332015-04-16 12:29:25 -07003443 // Dump Wifi controller stats
3444 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3445 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003446 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003447 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003448
3449 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3450 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003451
3452 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003453 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3454 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 // Dump misc stats
3457 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003458 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003459 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003460 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003461 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003462 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003463 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3464 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003465 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003466 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3467 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3468 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3469 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003470 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003471
Dianne Hackborn617f8772009-03-31 15:04:46 -07003472 // Dump screen brightness stats
3473 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3474 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003475 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003476 }
3477 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003478
Dianne Hackborn627bba72009-03-24 22:32:56 -07003479 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003480 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3481 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003482 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003483 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003484 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003485 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003486 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003487 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003488 args[i] = getPhoneSignalStrengthCount(i, which);
3489 }
3490 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003491
Dianne Hackborn627bba72009-03-24 22:32:56 -07003492 // Dump network type stats
3493 args = new Object[NUM_DATA_CONNECTION_TYPES];
3494 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003495 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003496 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003497 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3498 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3499 args[i] = getPhoneDataConnectionCount(i, which);
3500 }
3501 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003502
3503 // Dump wifi state stats
3504 args = new Object[NUM_WIFI_STATES];
3505 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003506 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003507 }
3508 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3509 for (int i=0; i<NUM_WIFI_STATES; i++) {
3510 args[i] = getWifiStateCount(i, which);
3511 }
3512 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3513
Dianne Hackborn3251b902014-06-20 14:40:53 -07003514 // Dump wifi suppl state stats
3515 args = new Object[NUM_WIFI_SUPPL_STATES];
3516 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3517 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3518 }
3519 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3520 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3521 args[i] = getWifiSupplStateCount(i, which);
3522 }
3523 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3524
3525 // Dump wifi signal strength stats
3526 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3527 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3528 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3529 }
3530 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3531 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3532 args[i] = getWifiSignalStrengthCount(i, which);
3533 }
3534 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3535
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003536 // Dump Multicast total stats
3537 dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA,
3538 multicastWakeLockTimeTotalMicros / 1000,
3539 multicastWakeLockCountTotal);
3540
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003541 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003542 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003543 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003544 }
Bookatzc8c44962017-05-11 12:12:54 -07003545
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003546 if (which == STATS_SINCE_UNPLUGGED) {
3547 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3548 getDischargeStartLevel()-getDischargeCurrentLevel(),
3549 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003550 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003551 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003552 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000,
3553 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003554 } else {
3555 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3556 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003557 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003558 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003559 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003560 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000,
3561 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003562 }
Bookatzc8c44962017-05-11 12:12:54 -07003563
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003564 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003565 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003566 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003567 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003568 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003569 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003570 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3571 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003572 }
Evan Millarc64edde2009-04-18 12:26:32 -07003573 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003574 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003575 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003576 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3577 // Not doing the regular wake lock formatting to remain compatible
3578 // with the old checkin format.
3579 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3580 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003581 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003582 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003583 }
3584 }
Evan Millarc64edde2009-04-18 12:26:32 -07003585 }
Bookatzc8c44962017-05-11 12:12:54 -07003586
Bookatz50df7112017-08-04 14:53:26 -07003587 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3588 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3589 if (rpmStats.size() > 0) {
3590 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3591 sb.setLength(0);
3592 Timer totalTimer = ent.getValue();
3593 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3594 int count = totalTimer.getCountLocked(which);
3595 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3596 long screenOffTimeMs = screenOffTimer != null
3597 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3598 int screenOffCount = screenOffTimer != null
3599 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003600 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3601 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3602 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3603 screenOffCount);
3604 } else {
3605 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3606 "\"" + ent.getKey() + "\"", timeMs, count);
3607 }
Bookatz50df7112017-08-04 14:53:26 -07003608 }
3609 }
3610
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003611 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003612 helper.create(this);
3613 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003614 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003615 if (sippers != null && sippers.size() > 0) {
3616 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3617 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003618 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003619 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3620 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
Kweku Adams87b19ec2017-10-09 12:40:03 -07003621 int uid = 0;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003622 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003623 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003624 String label;
3625 switch (bs.drainType) {
3626 case IDLE:
3627 label="idle";
3628 break;
3629 case CELL:
3630 label="cell";
3631 break;
3632 case PHONE:
3633 label="phone";
3634 break;
3635 case WIFI:
3636 label="wifi";
3637 break;
3638 case BLUETOOTH:
3639 label="blue";
3640 break;
3641 case SCREEN:
3642 label="scrn";
3643 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003644 case FLASHLIGHT:
3645 label="flashlight";
3646 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003647 case APP:
3648 uid = bs.uidObj.getUid();
3649 label = "uid";
3650 break;
3651 case USER:
3652 uid = UserHandle.getUid(bs.userId, 0);
3653 label = "user";
3654 break;
3655 case UNACCOUNTED:
3656 label = "unacc";
3657 break;
3658 case OVERCOUNTED:
3659 label = "over";
3660 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003661 case CAMERA:
3662 label = "camera";
3663 break;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003664 case MEMORY:
3665 label = "memory";
3666 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003667 default:
3668 label = "???";
3669 }
3670 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003671 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3672 bs.shouldHide ? 1 : 0,
3673 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3674 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003675 }
3676 }
3677
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003678 final long[] cpuFreqs = getCpuFreqs();
3679 if (cpuFreqs != null) {
3680 sb.setLength(0);
3681 for (int i = 0; i < cpuFreqs.length; ++i) {
3682 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3683 }
3684 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3685 }
3686
Kweku Adams87b19ec2017-10-09 12:40:03 -07003687 // Dump stats per UID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 for (int iu = 0; iu < NU; iu++) {
3689 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003690 if (reqUid >= 0 && uid != reqUid) {
3691 continue;
3692 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003693 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003696 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3697 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3698 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3699 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3700 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3701 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3702 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3703 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003704 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003705 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3706 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003707 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003708 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3709 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003710 // Background data transfers
3711 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3712 which);
3713 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3714 which);
3715 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3716 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3717 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3718 which);
3719 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3720 which);
3721 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3722 which);
3723 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3724 which);
3725
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003726 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3727 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003728 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003729 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3730 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3731 || wifiBytesBgTx > 0
3732 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3733 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003734 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3735 wifiBytesRx, wifiBytesTx,
3736 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003737 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003738 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003739 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3740 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3741 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3742 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003743 }
3744
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003745 // Dump modem controller data, per UID.
3746 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3747 u.getModemControllerActivity(), which);
3748
3749 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003750 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3751 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3752 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003753 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3754 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003755 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3756 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3757 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003758 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003759 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003760 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3761 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003762 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3763 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003764 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003765 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003766 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003768 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3769 u.getWifiControllerActivity(), which);
3770
Bookatz867c0d72017-03-07 18:23:42 -08003771 final Timer bleTimer = u.getBluetoothScanTimer();
3772 if (bleTimer != null) {
3773 // Convert from microseconds to milliseconds with rounding
3774 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3775 / 1000;
3776 if (totalTime != 0) {
3777 final int count = bleTimer.getCountLocked(which);
3778 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3779 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003780 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3781 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3782 final long actualTimeBg = bleTimerBg != null ?
3783 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003784 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003785 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3786 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003787 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3788 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3789 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3790 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3791 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3792 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3793 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3794 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3795 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3796 final Timer unoptimizedScanTimerBg =
3797 u.getBluetoothUnoptimizedScanBackgroundTimer();
3798 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3799 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3800 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3801 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3802
Bookatz867c0d72017-03-07 18:23:42 -08003803 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003804 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3805 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3806 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003807 }
3808 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003809
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003810 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3811 u.getBluetoothControllerActivity(), which);
3812
Dianne Hackborn617f8772009-03-31 15:04:46 -07003813 if (u.hasUserActivity()) {
3814 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3815 boolean hasData = false;
3816 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3817 int val = u.getUserActivityCount(i, which);
3818 args[i] = val;
3819 if (val != 0) hasData = true;
3820 }
3821 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003822 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003823 }
3824 }
Bookatzc8c44962017-05-11 12:12:54 -07003825
3826 if (u.getAggregatedPartialWakelockTimer() != null) {
3827 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003828 // Times are since reset (regardless of 'which')
3829 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003830 final Timer bgTimer = timer.getSubTimer();
3831 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003832 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003833 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3834 }
3835
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003836 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3837 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3838 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3839 String linePrefix = "";
3840 sb.setLength(0);
3841 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3842 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003843 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3844 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003845 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003846 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3847 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003848 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3849 rawRealtime, "w", which, linePrefix);
3850
Kweku Adams103351f2017-10-16 14:39:34 -07003851 // Only log if we had at least one wakelock...
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003852 if (sb.length() > 0) {
3853 String name = wakelocks.keyAt(iw);
3854 if (name.indexOf(',') >= 0) {
3855 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 }
Yi Jin02483362017-08-04 11:30:44 -07003857 if (name.indexOf('\n') >= 0) {
3858 name = name.replace('\n', '_');
3859 }
3860 if (name.indexOf('\r') >= 0) {
3861 name = name.replace('\r', '_');
3862 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003863 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 }
3865 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003866
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003867 // WiFi Multicast Wakelock Statistics
3868 final Timer mcTimer = u.getMulticastWakelockStats();
3869 if (mcTimer != null) {
3870 final long totalMcWakelockTimeMs =
3871 mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ;
3872 final int countMcWakelock = mcTimer.getCountLocked(which);
3873 if(totalMcWakelockTimeMs > 0) {
3874 dumpLine(pw, uid, category, WIFI_MULTICAST_DATA,
3875 totalMcWakelockTimeMs, countMcWakelock);
3876 }
3877 }
3878
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003879 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3880 for (int isy=syncs.size()-1; isy>=0; isy--) {
3881 final Timer timer = syncs.valueAt(isy);
3882 // Convert from microseconds to milliseconds with rounding
3883 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3884 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003885 final Timer bgTimer = timer.getSubTimer();
3886 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003887 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003888 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003889 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003890 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003891 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003892 }
3893 }
3894
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003895 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3896 for (int ij=jobs.size()-1; ij>=0; ij--) {
3897 final Timer timer = jobs.valueAt(ij);
3898 // Convert from microseconds to milliseconds with rounding
3899 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3900 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003901 final Timer bgTimer = timer.getSubTimer();
3902 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003903 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003904 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003905 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003906 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003907 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003908 }
3909 }
3910
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003911 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3912 for (int ic=completions.size()-1; ic>=0; ic--) {
3913 SparseIntArray types = completions.valueAt(ic);
3914 if (types != null) {
3915 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3916 "\"" + completions.keyAt(ic) + "\"",
3917 types.get(JobParameters.REASON_CANCELED, 0),
3918 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3919 types.get(JobParameters.REASON_PREEMPT, 0),
3920 types.get(JobParameters.REASON_TIMEOUT, 0),
3921 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3922 }
3923 }
3924
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003925 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3926 rawRealtime, which);
3927 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3928 rawRealtime, which);
3929 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3930 rawRealtime, which);
3931 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3932 rawRealtime, which);
3933
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003934 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3935 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003936 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003937 final Uid.Sensor se = sensors.valueAt(ise);
3938 final int sensorNumber = sensors.keyAt(ise);
3939 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003940 if (timer != null) {
3941 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003942 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3943 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003944 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003945 final int count = timer.getCountLocked(which);
3946 final Timer bgTimer = se.getSensorBackgroundTime();
3947 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003948 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3949 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3950 final long bgActualTime = bgTimer != null ?
3951 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3952 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3953 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 }
3956 }
3957
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003958 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3959 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003960
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003961 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3962 rawRealtime, which);
3963
3964 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003965 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003966
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003967 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003968 long totalStateTime = 0;
3969 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003970 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3971 totalStateTime += time;
3972 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003973 }
3974 if (totalStateTime > 0) {
3975 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3976 }
3977
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003978 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3979 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003980 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003981 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003982 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003983 }
3984
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003985 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3986 if (cpuFreqs != null) {
3987 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3988 // If total cpuFreqTimes is null, then we don't need to check for
3989 // screenOffCpuFreqTimes.
3990 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3991 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003992 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003993 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003994 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003995 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3996 if (screenOffCpuFreqTimeMs != null) {
3997 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3998 sb.append("," + screenOffCpuFreqTimeMs[i]);
3999 }
4000 } else {
4001 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
4002 sb.append(",0");
4003 }
4004 }
4005 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
4006 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004007 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004008 }
4009
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004010 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4011 = u.getProcessStats();
4012 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4013 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004014
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004015 final long userMillis = ps.getUserTime(which);
4016 final long systemMillis = ps.getSystemTime(which);
4017 final long foregroundMillis = ps.getForegroundTime(which);
4018 final int starts = ps.getStarts(which);
4019 final int numCrashes = ps.getNumCrashes(which);
4020 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004021
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004022 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
4023 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004024 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
4025 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 }
4027 }
4028
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004029 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4030 = u.getPackageStats();
4031 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4032 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4033 int wakeups = 0;
4034 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4035 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07004036 int count = alarms.valueAt(iwa).getCountLocked(which);
4037 wakeups += count;
4038 String name = alarms.keyAt(iwa).replace(',', '_');
4039 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004040 }
4041 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4042 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4043 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4044 final long startTime = ss.getStartTime(batteryUptime, which);
4045 final int starts = ss.getStarts(which);
4046 final int launches = ss.getLaunches(which);
4047 if (startTime != 0 || starts != 0 || launches != 0) {
4048 dumpLine(pw, uid, category, APK_DATA,
4049 wakeups, // wakeup alarms
4050 packageStats.keyAt(ipkg), // Apk
4051 serviceStats.keyAt(isvc), // service
4052 startTime / 1000, // time spent started, in ms
4053 starts,
4054 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 }
4056 }
4057 }
4058 }
4059 }
4060
Dianne Hackborn81038902012-11-26 17:04:09 -08004061 static final class TimerEntry {
4062 final String mName;
4063 final int mId;
4064 final BatteryStats.Timer mTimer;
4065 final long mTime;
4066 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
4067 mName = name;
4068 mId = id;
4069 mTimer = timer;
4070 mTime = time;
4071 }
4072 }
4073
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004074 private void printmAh(PrintWriter printer, double power) {
4075 printer.print(BatteryStatsHelper.makemAh(power));
4076 }
4077
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004078 private void printmAh(StringBuilder sb, double power) {
4079 sb.append(BatteryStatsHelper.makemAh(power));
4080 }
4081
Dianne Hackbornd953c532014-08-16 18:17:38 -07004082 /**
4083 * Temporary for settings.
4084 */
4085 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
4086 int reqUid) {
4087 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
4088 }
4089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004091 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07004092 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 final long rawUptime = SystemClock.uptimeMillis() * 1000;
4094 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07004095 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097
4098 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
4099 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
4100 final long totalRealtime = computeRealtime(rawRealtime, which);
4101 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004102 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
4103 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
4104 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004105 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
4106 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07004107 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004108
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004109 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07004110
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004111 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07004112 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113
Adam Lesinskif9b20a92016-06-17 17:30:01 -07004114 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
4115 if (estimatedBatteryCapacity > 0) {
4116 sb.setLength(0);
4117 sb.append(prefix);
4118 sb.append(" Estimated battery capacity: ");
4119 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
4120 sb.append(" mAh");
4121 pw.println(sb.toString());
4122 }
4123
Jocelyn Dangc627d102017-04-14 13:15:14 -07004124 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
4125 if (minLearnedBatteryCapacity > 0) {
4126 sb.setLength(0);
4127 sb.append(prefix);
4128 sb.append(" Min learned battery capacity: ");
4129 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
4130 sb.append(" mAh");
4131 pw.println(sb.toString());
4132 }
4133 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
4134 if (maxLearnedBatteryCapacity > 0) {
4135 sb.setLength(0);
4136 sb.append(prefix);
4137 sb.append(" Max learned battery capacity: ");
4138 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
4139 sb.append(" mAh");
4140 pw.println(sb.toString());
4141 }
4142
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004143 sb.setLength(0);
4144 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004145 sb.append(" Time on battery: ");
4146 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
4147 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
4148 sb.append(") realtime, ");
4149 formatTimeMs(sb, whichBatteryUptime / 1000);
4150 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
4151 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004152 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004153
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004154 sb.setLength(0);
4155 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004156 sb.append(" Time on battery screen off: ");
4157 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
4158 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
4159 sb.append(") realtime, ");
4160 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
4161 sb.append("(");
4162 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
4163 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004164 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004165
4166 sb.setLength(0);
4167 sb.append(prefix);
4168 sb.append(" Time on battery screen doze: ");
4169 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
4170 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
4171 sb.append(")");
4172 pw.println(sb.toString());
4173
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004174 sb.setLength(0);
4175 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004176 sb.append(" Total run time: ");
4177 formatTimeMs(sb, totalRealtime / 1000);
4178 sb.append("realtime, ");
4179 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004180 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07004181 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004182 if (batteryTimeRemaining >= 0) {
4183 sb.setLength(0);
4184 sb.append(prefix);
4185 sb.append(" Battery time remaining: ");
4186 formatTimeMs(sb, batteryTimeRemaining / 1000);
4187 pw.println(sb.toString());
4188 }
4189 if (chargeTimeRemaining >= 0) {
4190 sb.setLength(0);
4191 sb.append(prefix);
4192 sb.append(" Charge time remaining: ");
4193 formatTimeMs(sb, chargeTimeRemaining / 1000);
4194 pw.println(sb.toString());
4195 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004196
Kweku Adams87b19ec2017-10-09 12:40:03 -07004197 final long dischargeCount = getUahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004198 if (dischargeCount >= 0) {
4199 sb.setLength(0);
4200 sb.append(prefix);
4201 sb.append(" Discharge: ");
4202 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
4203 sb.append(" mAh");
4204 pw.println(sb.toString());
4205 }
4206
Kweku Adams87b19ec2017-10-09 12:40:03 -07004207 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004208 if (dischargeScreenOffCount >= 0) {
4209 sb.setLength(0);
4210 sb.append(prefix);
4211 sb.append(" Screen off discharge: ");
4212 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
4213 sb.append(" mAh");
4214 pw.println(sb.toString());
4215 }
4216
Kweku Adams87b19ec2017-10-09 12:40:03 -07004217 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Mac2f518a2017-09-19 16:06:03 -07004218 if (dischargeScreenDozeCount >= 0) {
4219 sb.setLength(0);
4220 sb.append(prefix);
4221 sb.append(" Screen doze discharge: ");
4222 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
4223 sb.append(" mAh");
4224 pw.println(sb.toString());
4225 }
4226
4227 final long dischargeScreenOnCount =
4228 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004229 if (dischargeScreenOnCount >= 0) {
4230 sb.setLength(0);
4231 sb.append(prefix);
4232 sb.append(" Screen on discharge: ");
4233 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4234 sb.append(" mAh");
4235 pw.println(sb.toString());
4236 }
4237
Mike Ma15313c92017-11-15 17:58:21 -08004238 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
4239 if (dischargeLightDozeCount >= 0) {
4240 sb.setLength(0);
4241 sb.append(prefix);
4242 sb.append(" Device light doze discharge: ");
4243 sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0));
4244 sb.append(" mAh");
4245 pw.println(sb.toString());
4246 }
4247
4248 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
4249 if (dischargeDeepDozeCount >= 0) {
4250 sb.setLength(0);
4251 sb.append(prefix);
4252 sb.append(" Device deep doze discharge: ");
4253 sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0));
4254 sb.append(" mAh");
4255 pw.println(sb.toString());
4256 }
4257
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004258 pw.print(" Start clock time: ");
4259 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4260
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004261 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004262 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004263 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004264 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4265 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004266 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004267 rawRealtime, which);
4268 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4269 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004270 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004271 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004272 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4273 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4274 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004275 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004276 sb.append(prefix);
4277 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4278 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004279 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004280 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4281 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004282 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004283 pw.println(sb.toString());
4284 sb.setLength(0);
4285 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004286 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004287 boolean didOne = false;
4288 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004289 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004290 if (time == 0) {
4291 continue;
4292 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004293 sb.append("\n ");
4294 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004295 didOne = true;
4296 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4297 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004298 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004299 sb.append("(");
4300 sb.append(formatRatioLocked(time, screenOnTime));
4301 sb.append(")");
4302 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004303 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004304 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004305 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004306 sb.setLength(0);
4307 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004308 sb.append(" Power save mode enabled: ");
4309 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004310 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004311 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004312 sb.append(")");
4313 pw.println(sb.toString());
4314 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004315 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004316 sb.setLength(0);
4317 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004318 sb.append(" Device light idling: ");
4319 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004320 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004321 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4322 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004323 sb.append("x");
4324 pw.println(sb.toString());
4325 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004326 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004327 sb.setLength(0);
4328 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004329 sb.append(" Idle mode light time: ");
4330 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004331 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004332 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4333 sb.append(") ");
4334 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004335 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004336 sb.append(" -- longest ");
4337 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4338 pw.println(sb.toString());
4339 }
4340 if (deviceIdlingTime != 0) {
4341 sb.setLength(0);
4342 sb.append(prefix);
4343 sb.append(" Device full idling: ");
4344 formatTimeMs(sb, deviceIdlingTime / 1000);
4345 sb.append("(");
4346 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004347 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004348 sb.append("x");
4349 pw.println(sb.toString());
4350 }
4351 if (deviceIdleModeFullTime != 0) {
4352 sb.setLength(0);
4353 sb.append(prefix);
4354 sb.append(" Idle mode full time: ");
4355 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4356 sb.append("(");
4357 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4358 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004359 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004360 sb.append("x");
4361 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004362 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004363 pw.println(sb.toString());
4364 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004365 if (phoneOnTime != 0) {
4366 sb.setLength(0);
4367 sb.append(prefix);
4368 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4369 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004370 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004371 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004372 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004373 if (connChanges != 0) {
4374 pw.print(prefix);
4375 pw.print(" Connectivity changes: "); pw.println(connChanges);
4376 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004377
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004378 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004379 long fullWakeLockTimeTotalMicros = 0;
4380 long partialWakeLockTimeTotalMicros = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004381 long multicastWakeLockTimeTotalMicros = 0;
4382 int multicastWakeLockCountTotal = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004383
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004384 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004385
Evan Millar22ac0432009-03-31 11:33:18 -07004386 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004387 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004388
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004389 // First calculate wakelock statistics
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004390 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4391 = u.getWakelockStats();
4392 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4393 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004394
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004395 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4396 if (fullWakeTimer != null) {
4397 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4398 rawRealtime, which);
4399 }
4400
4401 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4402 if (partialWakeTimer != null) {
4403 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4404 rawRealtime, which);
4405 if (totalTimeMicros > 0) {
4406 if (reqUid < 0) {
4407 // Only show the ordered list of all wake
4408 // locks if the caller is not asking for data
4409 // about a specific uid.
4410 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4411 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004412 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004413 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004414 }
4415 }
4416 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004417
4418 // Next calculate wifi multicast wakelock statistics
4419 final Timer mcTimer = u.getMulticastWakelockStats();
4420 if (mcTimer != null) {
4421 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
4422 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
4423 }
Evan Millar22ac0432009-03-31 11:33:18 -07004424 }
Bookatzc8c44962017-05-11 12:12:54 -07004425
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004426 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4427 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4428 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4429 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4430 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4431 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4432 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4433 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004434 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4435 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004436
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004437 if (fullWakeLockTimeTotalMicros != 0) {
4438 sb.setLength(0);
4439 sb.append(prefix);
4440 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4441 (fullWakeLockTimeTotalMicros + 500) / 1000);
4442 pw.println(sb.toString());
4443 }
4444
4445 if (partialWakeLockTimeTotalMicros != 0) {
4446 sb.setLength(0);
4447 sb.append(prefix);
4448 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4449 (partialWakeLockTimeTotalMicros + 500) / 1000);
4450 pw.println(sb.toString());
4451 }
4452
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004453 if (multicastWakeLockTimeTotalMicros != 0) {
4454 sb.setLength(0);
4455 sb.append(prefix);
4456 sb.append(" Total WiFi Multicast wakelock Count: ");
4457 sb.append(multicastWakeLockCountTotal);
4458 pw.println(sb.toString());
4459
4460 sb.setLength(0);
4461 sb.append(prefix);
4462 sb.append(" Total WiFi Multicast wakelock time: ");
4463 formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000);
4464 pw.println(sb.toString());
4465 }
4466
Siddharth Ray3c648c42017-10-02 17:30:58 -07004467 pw.println("");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004468 pw.print(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004469 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004470 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004471 sb.append(" CONNECTIVITY POWER SUMMARY START");
4472 pw.println(sb.toString());
4473
4474 pw.print(prefix);
4475 sb.setLength(0);
4476 sb.append(prefix);
4477 sb.append(" Logging duration for connectivity statistics: ");
4478 formatTimeMs(sb, whichBatteryRealtime / 1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004479 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004480
4481 sb.setLength(0);
4482 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004483 sb.append(" Cellular Statistics:");
Amith Yamasanif37447b2009-10-08 18:28:01 -07004484 pw.println(sb.toString());
4485
Siddharth Ray3c648c42017-10-02 17:30:58 -07004486 pw.print(prefix);
4487 sb.setLength(0);
4488 sb.append(prefix);
4489 sb.append(" Cellular kernel active time: ");
4490 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
4491 formatTimeMs(sb, mobileActiveTime / 1000);
4492 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4493 sb.append(")");
4494 pw.println(sb.toString());
4495
4496 pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes));
4497 pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes));
4498 pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets);
4499 pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets);
4500
Dianne Hackborn627bba72009-03-24 22:32:56 -07004501 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004502 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004503 sb.append(" Cellular Radio Access Technology:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004504 didOne = false;
4505 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004506 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004507 if (time == 0) {
4508 continue;
4509 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004510 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004511 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004512 didOne = true;
4513 sb.append(DATA_CONNECTION_NAMES[i]);
4514 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004515 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004516 sb.append("(");
4517 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004518 sb.append(") ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004519 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004520 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004521 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004522
4523 sb.setLength(0);
4524 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004525 sb.append(" Cellular Rx signal strength (RSRP):");
4526 final String[] cellularRxSignalStrengthDescription = new String[]{
4527 "very poor (less than -128dBm): ",
4528 "poor (-128dBm to -118dBm): ",
4529 "moderate (-118dBm to -108dBm): ",
4530 "good (-108dBm to -98dBm): ",
4531 "great (greater than -98dBm): "};
4532 didOne = false;
4533 final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS,
4534 cellularRxSignalStrengthDescription.length);
4535 for (int i=0; i<numCellularRxBins; i++) {
4536 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
4537 if (time == 0) {
4538 continue;
4539 }
4540 sb.append("\n ");
4541 sb.append(prefix);
4542 didOne = true;
4543 sb.append(cellularRxSignalStrengthDescription[i]);
4544 sb.append(" ");
4545 formatTimeMs(sb, time/1000);
4546 sb.append("(");
4547 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4548 sb.append(") ");
4549 }
4550 if (!didOne) sb.append(" (no activity)");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004551 pw.println(sb.toString());
4552
Siddharth Ray3c648c42017-10-02 17:30:58 -07004553 printControllerActivity(pw, sb, prefix, "Cellular",
4554 getModemControllerActivity(), which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004555
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004556 pw.print(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004557 sb.setLength(0);
4558 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004559 sb.append(" Wifi Statistics:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004560 pw.println(sb.toString());
4561
Siddharth Ray3c648c42017-10-02 17:30:58 -07004562 pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes));
4563 pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes));
4564 pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets);
4565 pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets);
4566
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004567 sb.setLength(0);
4568 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004569 sb.append(" Wifi states:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004570 didOne = false;
4571 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004572 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004573 if (time == 0) {
4574 continue;
4575 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004576 sb.append("\n ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004577 didOne = true;
4578 sb.append(WIFI_STATE_NAMES[i]);
4579 sb.append(" ");
4580 formatTimeMs(sb, time/1000);
4581 sb.append("(");
4582 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4583 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004584 }
4585 if (!didOne) sb.append(" (no activity)");
4586 pw.println(sb.toString());
4587
4588 sb.setLength(0);
4589 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004590 sb.append(" Wifi supplicant states:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004591 didOne = false;
4592 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4593 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4594 if (time == 0) {
4595 continue;
4596 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004597 sb.append("\n ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004598 didOne = true;
4599 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4600 sb.append(" ");
4601 formatTimeMs(sb, time/1000);
4602 sb.append("(");
4603 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4604 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004605 }
4606 if (!didOne) sb.append(" (no activity)");
4607 pw.println(sb.toString());
4608
4609 sb.setLength(0);
4610 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004611 sb.append(" Wifi Rx signal strength (RSSI):");
4612 final String[] wifiRxSignalStrengthDescription = new String[]{
4613 "very poor (less than -88.75dBm): ",
4614 "poor (-88.75 to -77.5dBm): ",
4615 "moderate (-77.5dBm to -66.25dBm): ",
4616 "good (-66.25dBm to -55dBm): ",
4617 "great (greater than -55dBm): "};
Dianne Hackborn3251b902014-06-20 14:40:53 -07004618 didOne = false;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004619 final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS,
4620 wifiRxSignalStrengthDescription.length);
4621 for (int i=0; i<numWifiRxBins; i++) {
Dianne Hackborn3251b902014-06-20 14:40:53 -07004622 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4623 if (time == 0) {
4624 continue;
4625 }
4626 sb.append("\n ");
4627 sb.append(prefix);
4628 didOne = true;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004629 sb.append(" ");
4630 sb.append(wifiRxSignalStrengthDescription[i]);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004631 formatTimeMs(sb, time/1000);
4632 sb.append("(");
4633 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4634 sb.append(") ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004635 }
4636 if (!didOne) sb.append(" (no activity)");
4637 pw.println(sb.toString());
4638
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004639 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004640
Adam Lesinski50e47602015-12-04 17:04:54 -08004641 pw.print(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004642 sb.setLength(0);
4643 sb.append(prefix);
4644 sb.append(" CONNECTIVITY POWER SUMMARY END");
4645 pw.println(sb.toString());
4646 pw.println("");
4647
4648 pw.print(prefix);
Adam Lesinski50e47602015-12-04 17:04:54 -08004649 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4650 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4651
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004652 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4653 sb.setLength(0);
4654 sb.append(prefix);
4655 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4656 pw.println(sb.toString());
4657
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004658 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4659 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004660
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004661 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004662
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004663 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004664 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004665 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004666 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004667 pw.println(getDischargeStartLevel());
4668 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4669 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004670 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004671 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004672 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004673 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004674 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004675 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004676 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004677 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004678 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004679 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004680 pw.println(getDischargeAmountScreenOff());
4681 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4682 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004683 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004684 } else {
4685 pw.print(prefix); pw.println(" Device battery use since last full charge");
4686 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004687 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004688 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004689 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004690 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004691 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004692 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004693 pw.println(getDischargeAmountScreenOffSinceCharge());
4694 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4695 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004696 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004697 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004698
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004699 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004700 helper.create(this);
4701 helper.refreshStats(which, UserHandle.USER_ALL);
4702 List<BatterySipper> sippers = helper.getUsageList();
4703 if (sippers != null && sippers.size() > 0) {
4704 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4705 pw.print(prefix); pw.print(" Capacity: ");
4706 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004707 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004708 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4709 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4710 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4711 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004712 pw.println();
4713 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004714 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004715 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004716 switch (bs.drainType) {
4717 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004718 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004719 break;
4720 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004721 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004722 break;
4723 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004724 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004725 break;
4726 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004727 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004728 break;
4729 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004730 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004731 break;
4732 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004733 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004734 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004735 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004736 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004737 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004738 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004739 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004740 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004741 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004742 break;
4743 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004744 pw.print(" User "); pw.print(bs.userId);
4745 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004746 break;
4747 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004748 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004749 break;
4750 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004751 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004752 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004753 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004754 pw.print(" Camera: ");
4755 break;
4756 default:
4757 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004758 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004759 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004760 printmAh(pw, bs.totalPowerMah);
4761
Adam Lesinski57123002015-06-12 16:12:07 -07004762 if (bs.usagePowerMah != bs.totalPowerMah) {
4763 // If the usage (generic power) isn't the whole amount, we list out
4764 // what components are involved in the calculation.
4765
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004766 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004767 if (bs.usagePowerMah != 0) {
4768 pw.print(" usage=");
4769 printmAh(pw, bs.usagePowerMah);
4770 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004771 if (bs.cpuPowerMah != 0) {
4772 pw.print(" cpu=");
4773 printmAh(pw, bs.cpuPowerMah);
4774 }
4775 if (bs.wakeLockPowerMah != 0) {
4776 pw.print(" wake=");
4777 printmAh(pw, bs.wakeLockPowerMah);
4778 }
4779 if (bs.mobileRadioPowerMah != 0) {
4780 pw.print(" radio=");
4781 printmAh(pw, bs.mobileRadioPowerMah);
4782 }
4783 if (bs.wifiPowerMah != 0) {
4784 pw.print(" wifi=");
4785 printmAh(pw, bs.wifiPowerMah);
4786 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004787 if (bs.bluetoothPowerMah != 0) {
4788 pw.print(" bt=");
4789 printmAh(pw, bs.bluetoothPowerMah);
4790 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004791 if (bs.gpsPowerMah != 0) {
4792 pw.print(" gps=");
4793 printmAh(pw, bs.gpsPowerMah);
4794 }
4795 if (bs.sensorPowerMah != 0) {
4796 pw.print(" sensor=");
4797 printmAh(pw, bs.sensorPowerMah);
4798 }
4799 if (bs.cameraPowerMah != 0) {
4800 pw.print(" camera=");
4801 printmAh(pw, bs.cameraPowerMah);
4802 }
4803 if (bs.flashlightPowerMah != 0) {
4804 pw.print(" flash=");
4805 printmAh(pw, bs.flashlightPowerMah);
4806 }
4807 pw.print(" )");
4808 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004809
4810 // If there is additional smearing information, include it.
4811 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4812 pw.print(" Including smearing: ");
4813 printmAh(pw, bs.totalSmearedPowerMah);
4814 pw.print(" (");
4815 if (bs.screenPowerMah != 0) {
4816 pw.print(" screen=");
4817 printmAh(pw, bs.screenPowerMah);
4818 }
4819 if (bs.proportionalSmearMah != 0) {
4820 pw.print(" proportional=");
4821 printmAh(pw, bs.proportionalSmearMah);
4822 }
4823 pw.print(" )");
4824 }
4825 if (bs.shouldHide) {
4826 pw.print(" Excluded from smearing");
4827 }
4828
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004829 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004830 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004831 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004832 }
4833
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004834 sippers = helper.getMobilemsppList();
4835 if (sippers != null && sippers.size() > 0) {
4836 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004837 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004838 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004839 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004840 sb.setLength(0);
4841 sb.append(prefix); sb.append(" Uid ");
4842 UserHandle.formatUid(sb, bs.uidObj.getUid());
4843 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4844 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4845 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004846 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004847 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004848 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004849 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004850 sb.setLength(0);
4851 sb.append(prefix);
4852 sb.append(" TOTAL TIME: ");
4853 formatTimeMs(sb, totalTime);
4854 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4855 sb.append(")");
4856 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004857 pw.println();
4858 }
4859
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004860 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4861 @Override
4862 public int compare(TimerEntry lhs, TimerEntry rhs) {
4863 long lhsTime = lhs.mTime;
4864 long rhsTime = rhs.mTime;
4865 if (lhsTime < rhsTime) {
4866 return 1;
4867 }
4868 if (lhsTime > rhsTime) {
4869 return -1;
4870 }
4871 return 0;
4872 }
4873 };
4874
4875 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004876 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4877 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004878 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004879 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4880 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4881 : kernelWakelocks.entrySet()) {
4882 final BatteryStats.Timer timer = ent.getValue();
4883 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004884 if (totalTimeMillis > 0) {
4885 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4886 }
4887 }
4888 if (ktimers.size() > 0) {
4889 Collections.sort(ktimers, timerComparator);
4890 pw.print(prefix); pw.println(" All kernel wake locks:");
4891 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004892 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004893 String linePrefix = ": ";
4894 sb.setLength(0);
4895 sb.append(prefix);
4896 sb.append(" Kernel Wake lock ");
4897 sb.append(timer.mName);
4898 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4899 which, linePrefix);
4900 if (!linePrefix.equals(": ")) {
4901 sb.append(" realtime");
4902 // Only print out wake locks that were held
4903 pw.println(sb.toString());
4904 }
4905 }
4906 pw.println();
4907 }
4908 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004909
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004910 if (timers.size() > 0) {
4911 Collections.sort(timers, timerComparator);
4912 pw.print(prefix); pw.println(" All partial wake locks:");
4913 for (int i=0; i<timers.size(); i++) {
4914 TimerEntry timer = timers.get(i);
4915 sb.setLength(0);
4916 sb.append(" Wake lock ");
4917 UserHandle.formatUid(sb, timer.mId);
4918 sb.append(" ");
4919 sb.append(timer.mName);
4920 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4921 sb.append(" realtime");
4922 pw.println(sb.toString());
4923 }
4924 timers.clear();
4925 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004926 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004927
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004928 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004929 if (wakeupReasons.size() > 0) {
4930 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004931 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004932 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004933 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004934 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4935 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004936 }
4937 Collections.sort(reasons, timerComparator);
4938 for (int i=0; i<reasons.size(); i++) {
4939 TimerEntry timer = reasons.get(i);
4940 String linePrefix = ": ";
4941 sb.setLength(0);
4942 sb.append(prefix);
4943 sb.append(" Wakeup reason ");
4944 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004945 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4946 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004947 pw.println(sb.toString());
4948 }
4949 pw.println();
4950 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004951 }
Evan Millar22ac0432009-03-31 11:33:18 -07004952
James Carr2dd7e5e2016-07-20 18:48:39 -07004953 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004954 if (mMemoryStats.size() > 0) {
4955 pw.println(" Memory Stats");
4956 for (int i = 0; i < mMemoryStats.size(); i++) {
4957 sb.setLength(0);
4958 sb.append(" Bandwidth ");
4959 sb.append(mMemoryStats.keyAt(i));
4960 sb.append(" Time ");
4961 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4962 pw.println(sb.toString());
4963 }
4964 pw.println();
4965 }
4966
4967 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4968 if (rpmStats.size() > 0) {
4969 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4970 if (rpmStats.size() > 0) {
4971 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4972 final String timerName = ent.getKey();
4973 final Timer timer = ent.getValue();
4974 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4975 }
4976 }
4977 pw.println();
4978 }
Bookatz82b341172017-09-07 19:06:08 -07004979 if (SCREEN_OFF_RPM_STATS_ENABLED) {
4980 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07004981 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07004982 pw.print(prefix);
4983 pw.println(" Resource Power Manager Stats for when screen was off");
4984 if (screenOffRpmStats.size() > 0) {
4985 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4986 final String timerName = ent.getKey();
4987 final Timer timer = ent.getValue();
4988 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4989 }
Bookatz50df7112017-08-04 14:53:26 -07004990 }
Bookatz82b341172017-09-07 19:06:08 -07004991 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07004992 }
James Carr2dd7e5e2016-07-20 18:48:39 -07004993 }
4994
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004995 final long[] cpuFreqs = getCpuFreqs();
4996 if (cpuFreqs != null) {
4997 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004998 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004999 for (int i = 0; i < cpuFreqs.length; ++i) {
5000 sb.append(" " + cpuFreqs[i]);
5001 }
5002 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07005003 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005004 }
5005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005006 for (int iu=0; iu<NU; iu++) {
5007 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005008 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08005009 continue;
5010 }
Bookatzc8c44962017-05-11 12:12:54 -07005011
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005012 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07005013
5014 pw.print(prefix);
5015 pw.print(" ");
5016 UserHandle.formatUid(pw, uid);
5017 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005019
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005020 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
5021 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
5022 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
5023 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005024 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
5025 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
5026
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005027 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
5028 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005029 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
5030 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005031
5032 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
5033 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
5034
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005035 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
5036 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
5037 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08005038 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
5039 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5040 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
5041 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005042 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005043
Adam Lesinski5f056f62016-07-14 16:56:08 -07005044 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
5045 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
5046
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005047 if (mobileRxBytes > 0 || mobileTxBytes > 0
5048 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005049 pw.print(prefix); pw.print(" Mobile network: ");
5050 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005051 pw.print(formatBytesLocked(mobileTxBytes));
5052 pw.print(" sent (packets "); pw.print(mobileRxPackets);
5053 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005055 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
5056 sb.setLength(0);
5057 sb.append(prefix); sb.append(" Mobile radio active: ");
5058 formatTimeMs(sb, uidMobileActiveTime / 1000);
5059 sb.append("(");
5060 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
5061 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
5062 long packets = mobileRxPackets + mobileTxPackets;
5063 if (packets == 0) {
5064 packets = 1;
5065 }
5066 sb.append(" @ ");
5067 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
5068 sb.append(" mspp");
5069 pw.println(sb.toString());
5070 }
5071
Adam Lesinski5f056f62016-07-14 16:56:08 -07005072 if (mobileWakeup > 0) {
5073 sb.setLength(0);
5074 sb.append(prefix);
5075 sb.append(" Mobile radio AP wakeups: ");
5076 sb.append(mobileWakeup);
5077 pw.println(sb.toString());
5078 }
5079
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005080 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
5081 u.getModemControllerActivity(), which);
5082
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005083 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005084 pw.print(prefix); pw.print(" Wi-Fi network: ");
5085 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005086 pw.print(formatBytesLocked(wifiTxBytes));
5087 pw.print(" sent (packets "); pw.print(wifiRxPackets);
5088 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005089 }
5090
Dianne Hackborn62793e42015-03-09 11:15:41 -07005091 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08005092 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005093 || uidWifiRunningTime != 0) {
5094 sb.setLength(0);
5095 sb.append(prefix); sb.append(" Wifi Running: ");
5096 formatTimeMs(sb, uidWifiRunningTime / 1000);
5097 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
5098 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07005099 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005100 formatTimeMs(sb, fullWifiLockOnTime / 1000);
5101 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
5102 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08005103 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005104 formatTimeMs(sb, wifiScanTime / 1000);
5105 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07005106 whichBatteryRealtime)); sb.append(") ");
5107 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08005108 sb.append("x\n");
5109 // actual and background times are unpooled and since reset (regardless of 'which')
5110 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
5111 formatTimeMs(sb, wifiScanActualTime / 1000);
5112 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
5113 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5114 sb.append(") ");
5115 sb.append(wifiScanCount);
5116 sb.append("x\n");
5117 sb.append(prefix); sb.append(" Background Wifi Scan: ");
5118 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
5119 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
5120 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5121 sb.append(") ");
5122 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07005123 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005124 pw.println(sb.toString());
5125 }
5126
Adam Lesinski5f056f62016-07-14 16:56:08 -07005127 if (wifiWakeup > 0) {
5128 sb.setLength(0);
5129 sb.append(prefix);
5130 sb.append(" WiFi AP wakeups: ");
5131 sb.append(wifiWakeup);
5132 pw.println(sb.toString());
5133 }
5134
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005135 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
5136 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07005137
Adam Lesinski50e47602015-12-04 17:04:54 -08005138 if (btRxBytes > 0 || btTxBytes > 0) {
5139 pw.print(prefix); pw.print(" Bluetooth network: ");
5140 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
5141 pw.print(formatBytesLocked(btTxBytes));
5142 pw.println(" sent");
5143 }
5144
Bookatz867c0d72017-03-07 18:23:42 -08005145 final Timer bleTimer = u.getBluetoothScanTimer();
5146 if (bleTimer != null) {
5147 // Convert from microseconds to milliseconds with rounding
5148 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
5149 / 1000;
5150 if (totalTimeMs != 0) {
5151 final int count = bleTimer.getCountLocked(which);
5152 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
5153 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005154 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5155 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
5156 final long actualTimeMsBg = bleTimerBg != null ?
5157 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005158 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07005159 final int resultCount = u.getBluetoothScanResultCounter() != null ?
5160 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005161 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
5162 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
5163 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
5164 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
5165 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
5166 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5167 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
5168 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
5169 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
5170 final Timer unoptimizedScanTimerBg =
5171 u.getBluetoothUnoptimizedScanBackgroundTimer();
5172 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
5173 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5174 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
5175 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005176
5177 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08005178 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07005179 sb.append(prefix);
5180 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08005181 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07005182 sb.append(" (");
5183 sb.append(count);
5184 sb.append(" times)");
5185 if (bleTimer.isRunningLocked()) {
5186 sb.append(" (currently running)");
5187 }
5188 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005189 }
Bookatzb1f04f32017-05-19 13:57:32 -07005190
5191 sb.append(prefix);
5192 sb.append(" Bluetooth Scan (total actual realtime): ");
5193 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
5194 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005195 sb.append(count);
5196 sb.append(" times)");
5197 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07005198 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08005199 }
Bookatzb1f04f32017-05-19 13:57:32 -07005200 sb.append("\n");
5201 if (actualTimeMsBg > 0 || countBg > 0) {
5202 sb.append(prefix);
5203 sb.append(" Bluetooth Scan (background realtime): ");
5204 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
5205 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005206 sb.append(countBg);
5207 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07005208 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
5209 sb.append(" (currently running in background)");
5210 }
5211 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005212 }
Bookatzb1f04f32017-05-19 13:57:32 -07005213
5214 sb.append(prefix);
5215 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07005216 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07005217 sb.append(" (");
5218 sb.append(resultCountBg);
5219 sb.append(" in background)");
5220
5221 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
5222 sb.append("\n");
5223 sb.append(prefix);
5224 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
5225 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
5226 sb.append(" (max ");
5227 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
5228 sb.append(")");
5229 if (unoptimizedScanTimer != null
5230 && unoptimizedScanTimer.isRunningLocked()) {
5231 sb.append(" (currently running unoptimized)");
5232 }
5233 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
5234 sb.append("\n");
5235 sb.append(prefix);
5236 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
5237 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
5238 sb.append(" (max ");
5239 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
5240 sb.append(")");
5241 if (unoptimizedScanTimerBg.isRunningLocked()) {
5242 sb.append(" (currently running unoptimized in background)");
5243 }
5244 }
5245 }
Bookatz867c0d72017-03-07 18:23:42 -08005246 pw.println(sb.toString());
5247 uidActivity = true;
5248 }
5249 }
5250
5251
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005252
Dianne Hackborn617f8772009-03-31 15:04:46 -07005253 if (u.hasUserActivity()) {
5254 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07005255 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005256 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07005257 if (val != 0) {
5258 if (!hasData) {
5259 sb.setLength(0);
5260 sb.append(" User activity: ");
5261 hasData = true;
5262 } else {
5263 sb.append(", ");
5264 }
5265 sb.append(val);
5266 sb.append(" ");
5267 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
5268 }
5269 }
5270 if (hasData) {
5271 pw.println(sb.toString());
5272 }
5273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005274
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005275 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5276 = u.getWakelockStats();
5277 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005278 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005279 int countWakelock = 0;
5280 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5281 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5282 String linePrefix = ": ";
5283 sb.setLength(0);
5284 sb.append(prefix);
5285 sb.append(" Wake lock ");
5286 sb.append(wakelocks.keyAt(iw));
5287 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5288 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005289 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5290 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005291 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005292 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5293 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005294 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5295 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005296 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5297 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005298 sb.append(" realtime");
5299 pw.println(sb.toString());
5300 uidActivity = true;
5301 countWakelock++;
5302
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005303 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5304 rawRealtime, which);
5305 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5306 rawRealtime, which);
5307 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5308 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005309 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005310 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005311 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005312 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005313 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5314 // pooled and therefore just a lower bound)
5315 long actualTotalPartialWakelock = 0;
5316 long actualBgPartialWakelock = 0;
5317 if (u.getAggregatedPartialWakelockTimer() != null) {
5318 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5319 // Convert from microseconds to milliseconds with rounding
5320 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005321 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005322 final Timer bgAggTimer = aggTimer.getSubTimer();
5323 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005324 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005325 }
5326
5327 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5328 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5329 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005330 sb.setLength(0);
5331 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005332 sb.append(" TOTAL wake: ");
5333 boolean needComma = false;
5334 if (totalFullWakelock != 0) {
5335 needComma = true;
5336 formatTimeMs(sb, totalFullWakelock);
5337 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005338 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005339 if (totalPartialWakelock != 0) {
5340 if (needComma) {
5341 sb.append(", ");
5342 }
5343 needComma = true;
5344 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005345 sb.append("blamed partial");
5346 }
5347 if (actualTotalPartialWakelock != 0) {
5348 if (needComma) {
5349 sb.append(", ");
5350 }
5351 needComma = true;
5352 formatTimeMs(sb, actualTotalPartialWakelock);
5353 sb.append("actual partial");
5354 }
5355 if (actualBgPartialWakelock != 0) {
5356 if (needComma) {
5357 sb.append(", ");
5358 }
5359 needComma = true;
5360 formatTimeMs(sb, actualBgPartialWakelock);
5361 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005362 }
5363 if (totalWindowWakelock != 0) {
5364 if (needComma) {
5365 sb.append(", ");
5366 }
5367 needComma = true;
5368 formatTimeMs(sb, totalWindowWakelock);
5369 sb.append("window");
5370 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005371 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005372 if (needComma) {
5373 sb.append(",");
5374 }
5375 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005376 formatTimeMs(sb, totalDrawWakelock);
5377 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005378 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005379 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005380 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005381 }
5382 }
5383
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07005384 // Calculate multicast wakelock stats
5385 final Timer mcTimer = u.getMulticastWakelockStats();
5386 if (mcTimer != null) {
5387 final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which);
5388 final int multicastWakeLockCount = mcTimer.getCountLocked(which);
5389
5390 if (multicastWakeLockTimeMicros > 0) {
5391 sb.setLength(0);
5392 sb.append(prefix);
5393 sb.append(" WiFi Multicast Wakelock");
5394 sb.append(" count = ");
5395 sb.append(multicastWakeLockCount);
5396 sb.append(" time = ");
5397 formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000);
5398 pw.println(sb.toString());
5399 }
5400 }
5401
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005402 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5403 for (int isy=syncs.size()-1; isy>=0; isy--) {
5404 final Timer timer = syncs.valueAt(isy);
5405 // Convert from microseconds to milliseconds with rounding
5406 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5407 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005408 final Timer bgTimer = timer.getSubTimer();
5409 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005410 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005411 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005412 sb.setLength(0);
5413 sb.append(prefix);
5414 sb.append(" Sync ");
5415 sb.append(syncs.keyAt(isy));
5416 sb.append(": ");
5417 if (totalTime != 0) {
5418 formatTimeMs(sb, totalTime);
5419 sb.append("realtime (");
5420 sb.append(count);
5421 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005422 if (bgTime > 0) {
5423 sb.append(", ");
5424 formatTimeMs(sb, bgTime);
5425 sb.append("background (");
5426 sb.append(bgCount);
5427 sb.append(" times)");
5428 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005429 } else {
5430 sb.append("(not used)");
5431 }
5432 pw.println(sb.toString());
5433 uidActivity = true;
5434 }
5435
5436 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5437 for (int ij=jobs.size()-1; ij>=0; ij--) {
5438 final Timer timer = jobs.valueAt(ij);
5439 // Convert from microseconds to milliseconds with rounding
5440 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5441 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005442 final Timer bgTimer = timer.getSubTimer();
5443 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005444 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005445 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005446 sb.setLength(0);
5447 sb.append(prefix);
5448 sb.append(" Job ");
5449 sb.append(jobs.keyAt(ij));
5450 sb.append(": ");
5451 if (totalTime != 0) {
5452 formatTimeMs(sb, totalTime);
5453 sb.append("realtime (");
5454 sb.append(count);
5455 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005456 if (bgTime > 0) {
5457 sb.append(", ");
5458 formatTimeMs(sb, bgTime);
5459 sb.append("background (");
5460 sb.append(bgCount);
5461 sb.append(" times)");
5462 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005463 } else {
5464 sb.append("(not used)");
5465 }
5466 pw.println(sb.toString());
5467 uidActivity = true;
5468 }
5469
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005470 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5471 for (int ic=completions.size()-1; ic>=0; ic--) {
5472 SparseIntArray types = completions.valueAt(ic);
5473 if (types != null) {
5474 pw.print(prefix);
5475 pw.print(" Job Completions ");
5476 pw.print(completions.keyAt(ic));
5477 pw.print(":");
5478 for (int it=0; it<types.size(); it++) {
5479 pw.print(" ");
5480 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5481 pw.print("(");
5482 pw.print(types.valueAt(it));
5483 pw.print("x)");
5484 }
5485 pw.println();
5486 }
5487 }
5488
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005489 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5490 prefix, "Flashlight");
5491 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5492 prefix, "Camera");
5493 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5494 prefix, "Video");
5495 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5496 prefix, "Audio");
5497
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005498 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5499 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005500 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005501 final Uid.Sensor se = sensors.valueAt(ise);
5502 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005503 sb.setLength(0);
5504 sb.append(prefix);
5505 sb.append(" Sensor ");
5506 int handle = se.getHandle();
5507 if (handle == Uid.Sensor.GPS) {
5508 sb.append("GPS");
5509 } else {
5510 sb.append(handle);
5511 }
5512 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005513
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005514 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005515 if (timer != null) {
5516 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005517 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5518 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005519 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005520 final Timer bgTimer = se.getSensorBackgroundTime();
5521 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005522 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5523 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5524 final long bgActualTime = bgTimer != null ?
5525 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5526
Dianne Hackborn61659e52014-07-09 16:13:01 -07005527 //timer.logState();
5528 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005529 if (actualTime != totalTime) {
5530 formatTimeMs(sb, totalTime);
5531 sb.append("blamed realtime, ");
5532 }
5533
5534 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005535 sb.append("realtime (");
5536 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005537 sb.append(" times)");
5538
5539 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005540 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005541 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5542 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005543 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005544 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005546 } else {
5547 sb.append("(not used)");
5548 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005549 } else {
5550 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005551 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005552
5553 pw.println(sb.toString());
5554 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005555 }
5556
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005557 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5558 "Vibrator");
5559 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5560 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005561 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5562 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005563
Dianne Hackborn61659e52014-07-09 16:13:01 -07005564 long totalStateTime = 0;
5565 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5566 long time = u.getProcessStateTime(ips, rawRealtime, which);
5567 if (time > 0) {
5568 totalStateTime += time;
5569 sb.setLength(0);
5570 sb.append(prefix);
5571 sb.append(" ");
5572 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5573 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005574 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005575 pw.println(sb.toString());
5576 uidActivity = true;
5577 }
5578 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005579 if (totalStateTime > 0) {
5580 sb.setLength(0);
5581 sb.append(prefix);
5582 sb.append(" Total running: ");
5583 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5584 pw.println(sb.toString());
5585 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005586
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005587 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5588 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005589 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005590 sb.setLength(0);
5591 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005592 sb.append(" Total cpu time: u=");
5593 formatTimeMs(sb, userCpuTimeUs / 1000);
5594 sb.append("s=");
5595 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005596 pw.println(sb.toString());
5597 }
5598
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005599 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5600 if (cpuFreqTimes != null) {
5601 sb.setLength(0);
5602 sb.append(" Total cpu time per freq:");
5603 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5604 sb.append(" " + cpuFreqTimes[i]);
5605 }
5606 pw.println(sb.toString());
5607 }
5608 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5609 if (screenOffCpuFreqTimes != null) {
5610 sb.setLength(0);
5611 sb.append(" Total screen-off cpu time per freq:");
5612 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5613 sb.append(" " + screenOffCpuFreqTimes[i]);
5614 }
5615 pw.println(sb.toString());
5616 }
5617
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005618 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5619 = u.getProcessStats();
5620 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5621 final Uid.Proc ps = processStats.valueAt(ipr);
5622 long userTime;
5623 long systemTime;
5624 long foregroundTime;
5625 int starts;
5626 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005627
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005628 userTime = ps.getUserTime(which);
5629 systemTime = ps.getSystemTime(which);
5630 foregroundTime = ps.getForegroundTime(which);
5631 starts = ps.getStarts(which);
5632 final int numCrashes = ps.getNumCrashes(which);
5633 final int numAnrs = ps.getNumAnrs(which);
5634 numExcessive = which == STATS_SINCE_CHARGED
5635 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005637 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5638 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5639 sb.setLength(0);
5640 sb.append(prefix); sb.append(" Proc ");
5641 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5642 sb.append(prefix); sb.append(" CPU: ");
5643 formatTimeMs(sb, userTime); sb.append("usr + ");
5644 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5645 formatTimeMs(sb, foregroundTime); sb.append("fg");
5646 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5647 sb.append("\n"); sb.append(prefix); sb.append(" ");
5648 boolean hasOne = false;
5649 if (starts != 0) {
5650 hasOne = true;
5651 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005652 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005653 if (numCrashes != 0) {
5654 if (hasOne) {
5655 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005656 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005657 hasOne = true;
5658 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005659 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005660 if (numAnrs != 0) {
5661 if (hasOne) {
5662 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005664 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 }
5666 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005667 pw.println(sb.toString());
5668 for (int e=0; e<numExcessive; e++) {
5669 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5670 if (ew != null) {
5671 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005672 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005673 pw.print("cpu");
5674 } else {
5675 pw.print("unknown");
5676 }
5677 pw.print(" use: ");
5678 TimeUtils.formatDuration(ew.usedTime, pw);
5679 pw.print(" over ");
5680 TimeUtils.formatDuration(ew.overTime, pw);
5681 if (ew.overTime != 0) {
5682 pw.print(" (");
5683 pw.print((ew.usedTime*100)/ew.overTime);
5684 pw.println("%)");
5685 }
5686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005687 }
5688 uidActivity = true;
5689 }
5690 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005691
5692 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5693 = u.getPackageStats();
5694 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5695 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5696 pw.println(":");
5697 boolean apkActivity = false;
5698 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5699 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5700 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5701 pw.print(prefix); pw.print(" Wakeup alarm ");
5702 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5703 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5704 pw.println(" times");
5705 apkActivity = true;
5706 }
5707 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5708 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5709 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5710 final long startTime = ss.getStartTime(batteryUptime, which);
5711 final int starts = ss.getStarts(which);
5712 final int launches = ss.getLaunches(which);
5713 if (startTime != 0 || starts != 0 || launches != 0) {
5714 sb.setLength(0);
5715 sb.append(prefix); sb.append(" Service ");
5716 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5717 sb.append(prefix); sb.append(" Created for: ");
5718 formatTimeMs(sb, startTime / 1000);
5719 sb.append("uptime\n");
5720 sb.append(prefix); sb.append(" Starts: ");
5721 sb.append(starts);
5722 sb.append(", launches: "); sb.append(launches);
5723 pw.println(sb.toString());
5724 apkActivity = true;
5725 }
5726 }
5727 if (!apkActivity) {
5728 pw.print(prefix); pw.println(" (nothing executed)");
5729 }
5730 uidActivity = true;
5731 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005733 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 }
5735 }
5736 }
5737
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005738 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005739 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005740 int diff = oldval ^ newval;
5741 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005742 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005743 for (int i=0; i<descriptions.length; i++) {
5744 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005745 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005746 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005747 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005748 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005749 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005750 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5751 didWake = true;
5752 pw.print("=");
5753 if (longNames) {
5754 UserHandle.formatUid(pw, wakelockTag.uid);
5755 pw.print(":\"");
5756 pw.print(wakelockTag.string);
5757 pw.print("\"");
5758 } else {
5759 pw.print(wakelockTag.poolIdx);
5760 }
5761 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005762 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005763 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005764 pw.print("=");
5765 int val = (newval&bd.mask)>>bd.shift;
5766 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005767 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005768 } else {
5769 pw.print(val);
5770 }
5771 }
5772 }
5773 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005774 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005775 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005776 if (longNames) {
5777 UserHandle.formatUid(pw, wakelockTag.uid);
5778 pw.print(":\"");
5779 pw.print(wakelockTag.string);
5780 pw.print("\"");
5781 } else {
5782 pw.print(wakelockTag.poolIdx);
5783 }
5784 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005785 }
Mike Mac2f518a2017-09-19 16:06:03 -07005786
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005787 public void prepareForDumpLocked() {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07005788 // We don't need to require subclasses implement this.
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005789 }
5790
5791 public static class HistoryPrinter {
5792 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005793 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005794 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005795 int oldStatus = -1;
5796 int oldHealth = -1;
5797 int oldPlug = -1;
5798 int oldTemp = -1;
5799 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005800 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005801 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005802
Dianne Hackborn3251b902014-06-20 14:40:53 -07005803 void reset() {
5804 oldState = oldState2 = 0;
5805 oldLevel = -1;
5806 oldStatus = -1;
5807 oldHealth = -1;
5808 oldPlug = -1;
5809 oldTemp = -1;
5810 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005811 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005812 }
5813
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005814 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005815 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005816 if (!checkin) {
5817 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005818 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005819 pw.print(" (");
5820 pw.print(rec.numReadInts);
5821 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005822 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005823 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5824 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005825 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005826 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005827 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005828 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005829 }
5830 lastTime = rec.time;
5831 }
5832 if (rec.cmd == HistoryItem.CMD_START) {
5833 if (checkin) {
5834 pw.print(":");
5835 }
5836 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005837 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005838 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5839 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005840 if (checkin) {
5841 pw.print(":");
5842 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005843 if (rec.cmd == HistoryItem.CMD_RESET) {
5844 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005845 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005846 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005847 pw.print("TIME:");
5848 if (checkin) {
5849 pw.println(rec.currentTime);
5850 } else {
5851 pw.print(" ");
5852 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5853 rec.currentTime).toString());
5854 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005855 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5856 if (checkin) {
5857 pw.print(":");
5858 }
5859 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005860 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5861 if (checkin) {
5862 pw.print(":");
5863 }
5864 pw.println("*OVERFLOW*");
5865 } else {
5866 if (!checkin) {
5867 if (rec.batteryLevel < 10) pw.print("00");
5868 else if (rec.batteryLevel < 100) pw.print("0");
5869 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005870 if (verbose) {
5871 pw.print(" ");
5872 if (rec.states < 0) ;
5873 else if (rec.states < 0x10) pw.print("0000000");
5874 else if (rec.states < 0x100) pw.print("000000");
5875 else if (rec.states < 0x1000) pw.print("00000");
5876 else if (rec.states < 0x10000) pw.print("0000");
5877 else if (rec.states < 0x100000) pw.print("000");
5878 else if (rec.states < 0x1000000) pw.print("00");
5879 else if (rec.states < 0x10000000) pw.print("0");
5880 pw.print(Integer.toHexString(rec.states));
5881 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005882 } else {
5883 if (oldLevel != rec.batteryLevel) {
5884 oldLevel = rec.batteryLevel;
5885 pw.print(",Bl="); pw.print(rec.batteryLevel);
5886 }
5887 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005888 if (oldStatus != rec.batteryStatus) {
5889 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005890 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005891 switch (oldStatus) {
5892 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005893 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005894 break;
5895 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005896 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005897 break;
5898 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005899 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005900 break;
5901 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005902 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005903 break;
5904 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005905 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005906 break;
5907 default:
5908 pw.print(oldStatus);
5909 break;
5910 }
5911 }
5912 if (oldHealth != rec.batteryHealth) {
5913 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005914 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005915 switch (oldHealth) {
5916 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005917 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005918 break;
5919 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005920 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005921 break;
5922 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005923 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005924 break;
5925 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005926 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005927 break;
5928 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005929 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005930 break;
5931 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005932 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005933 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005934 case BatteryManager.BATTERY_HEALTH_COLD:
5935 pw.print(checkin ? "c" : "cold");
5936 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005937 default:
5938 pw.print(oldHealth);
5939 break;
5940 }
5941 }
5942 if (oldPlug != rec.batteryPlugType) {
5943 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005944 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005945 switch (oldPlug) {
5946 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005947 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005948 break;
5949 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005950 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005951 break;
5952 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005953 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005954 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005955 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005956 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005957 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005958 default:
5959 pw.print(oldPlug);
5960 break;
5961 }
5962 }
5963 if (oldTemp != rec.batteryTemperature) {
5964 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005965 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005966 pw.print(oldTemp);
5967 }
5968 if (oldVolt != rec.batteryVoltage) {
5969 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005970 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005971 pw.print(oldVolt);
5972 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005973 final int chargeMAh = rec.batteryChargeUAh / 1000;
5974 if (oldChargeMAh != chargeMAh) {
5975 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005976 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005977 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005978 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005979 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005980 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005981 printBitDescriptions(pw, oldState2, rec.states2, null,
5982 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005983 if (rec.wakeReasonTag != null) {
5984 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005985 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005986 pw.print(rec.wakeReasonTag.poolIdx);
5987 } else {
5988 pw.print(" wake_reason=");
5989 pw.print(rec.wakeReasonTag.uid);
5990 pw.print(":\"");
5991 pw.print(rec.wakeReasonTag.string);
5992 pw.print("\"");
5993 }
5994 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005995 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005996 pw.print(checkin ? "," : " ");
5997 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5998 pw.print("+");
5999 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
6000 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006001 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08006002 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
6003 : HISTORY_EVENT_NAMES;
6004 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
6005 | HistoryItem.EVENT_FLAG_FINISH);
6006 if (idx >= 0 && idx < eventNames.length) {
6007 pw.print(eventNames[idx]);
6008 } else {
6009 pw.print(checkin ? "Ev" : "event");
6010 pw.print(idx);
6011 }
6012 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006013 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006014 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08006015 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08006016 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
6017 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006018 pw.print(":\"");
6019 pw.print(rec.eventTag.string);
6020 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006021 }
6022 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006023 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006024 if (rec.stepDetails != null) {
6025 if (!checkin) {
6026 pw.print(" Details: cpu=");
6027 pw.print(rec.stepDetails.userTime);
6028 pw.print("u+");
6029 pw.print(rec.stepDetails.systemTime);
6030 pw.print("s");
6031 if (rec.stepDetails.appCpuUid1 >= 0) {
6032 pw.print(" (");
6033 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
6034 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6035 if (rec.stepDetails.appCpuUid2 >= 0) {
6036 pw.print(", ");
6037 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
6038 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6039 }
6040 if (rec.stepDetails.appCpuUid3 >= 0) {
6041 pw.print(", ");
6042 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
6043 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6044 }
6045 pw.print(')');
6046 }
6047 pw.println();
6048 pw.print(" /proc/stat=");
6049 pw.print(rec.stepDetails.statUserTime);
6050 pw.print(" usr, ");
6051 pw.print(rec.stepDetails.statSystemTime);
6052 pw.print(" sys, ");
6053 pw.print(rec.stepDetails.statIOWaitTime);
6054 pw.print(" io, ");
6055 pw.print(rec.stepDetails.statIrqTime);
6056 pw.print(" irq, ");
6057 pw.print(rec.stepDetails.statSoftIrqTime);
6058 pw.print(" sirq, ");
6059 pw.print(rec.stepDetails.statIdlTime);
6060 pw.print(" idle");
6061 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
6062 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
6063 + rec.stepDetails.statSoftIrqTime;
6064 int total = totalRun + rec.stepDetails.statIdlTime;
6065 if (total > 0) {
6066 pw.print(" (");
6067 float perc = ((float)totalRun) / ((float)total) * 100;
6068 pw.print(String.format("%.1f%%", perc));
6069 pw.print(" of ");
6070 StringBuilder sb = new StringBuilder(64);
6071 formatTimeMsNoSpace(sb, total*10);
6072 pw.print(sb);
6073 pw.print(")");
6074 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006075 pw.print(", PlatformIdleStat ");
6076 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006077 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006078
6079 pw.print(", SubsystemPowerState ");
6080 pw.print(rec.stepDetails.statSubsystemPowerState);
6081 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006082 } else {
6083 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6084 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
6085 pw.print(rec.stepDetails.userTime);
6086 pw.print(":");
6087 pw.print(rec.stepDetails.systemTime);
6088 if (rec.stepDetails.appCpuUid1 >= 0) {
6089 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
6090 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6091 if (rec.stepDetails.appCpuUid2 >= 0) {
6092 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
6093 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6094 }
6095 if (rec.stepDetails.appCpuUid3 >= 0) {
6096 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
6097 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6098 }
6099 }
6100 pw.println();
6101 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6102 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
6103 pw.print(rec.stepDetails.statUserTime);
6104 pw.print(',');
6105 pw.print(rec.stepDetails.statSystemTime);
6106 pw.print(',');
6107 pw.print(rec.stepDetails.statIOWaitTime);
6108 pw.print(',');
6109 pw.print(rec.stepDetails.statIrqTime);
6110 pw.print(',');
6111 pw.print(rec.stepDetails.statSoftIrqTime);
6112 pw.print(',');
6113 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006114 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006115 if (rec.stepDetails.statPlatformIdleState != null) {
6116 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07006117 if (rec.stepDetails.statSubsystemPowerState != null) {
6118 pw.print(',');
6119 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006120 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006121
6122 if (rec.stepDetails.statSubsystemPowerState != null) {
6123 pw.print(rec.stepDetails.statSubsystemPowerState);
6124 }
6125 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006126 }
6127 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006128 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006129 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006130 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006131 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006132
6133 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
6134 UserHandle.formatUid(pw, uid);
6135 pw.print("=");
6136 pw.print(utime);
6137 pw.print("u+");
6138 pw.print(stime);
6139 pw.print("s");
6140 }
6141
6142 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
6143 pw.print('/');
6144 pw.print(uid);
6145 pw.print(":");
6146 pw.print(utime);
6147 pw.print(":");
6148 pw.print(stime);
6149 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006150 }
6151
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006152 private void printSizeValue(PrintWriter pw, long size) {
6153 float result = size;
6154 String suffix = "";
6155 if (result >= 10*1024) {
6156 suffix = "KB";
6157 result = result / 1024;
6158 }
6159 if (result >= 10*1024) {
6160 suffix = "MB";
6161 result = result / 1024;
6162 }
6163 if (result >= 10*1024) {
6164 suffix = "GB";
6165 result = result / 1024;
6166 }
6167 if (result >= 10*1024) {
6168 suffix = "TB";
6169 result = result / 1024;
6170 }
6171 if (result >= 10*1024) {
6172 suffix = "PB";
6173 result = result / 1024;
6174 }
6175 pw.print((int)result);
6176 pw.print(suffix);
6177 }
6178
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006179 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
6180 String label3, long estimatedTime) {
6181 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006182 return false;
6183 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006184 pw.print(label1);
6185 pw.print(label2);
6186 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006187 StringBuilder sb = new StringBuilder(64);
6188 formatTimeMs(sb, estimatedTime);
6189 pw.print(sb);
6190 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006191 return true;
6192 }
6193
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006194 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
6195 LevelStepTracker steps, boolean checkin) {
6196 if (steps == null) {
6197 return false;
6198 }
6199 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006200 if (count <= 0) {
6201 return false;
6202 }
6203 if (!checkin) {
6204 pw.println(header);
6205 }
Kweku Adams030980a2015-04-01 16:07:48 -07006206 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006207 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006208 long duration = steps.getDurationAt(i);
6209 int level = steps.getLevelAt(i);
6210 long initMode = steps.getInitModeAt(i);
6211 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006212 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006213 lineArgs[0] = Long.toString(duration);
6214 lineArgs[1] = Integer.toString(level);
6215 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6216 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6217 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
6218 case Display.STATE_ON: lineArgs[2] = "s+"; break;
6219 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
6220 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07006221 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006222 }
6223 } else {
6224 lineArgs[2] = "";
6225 }
6226 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6227 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
6228 } else {
6229 lineArgs[3] = "";
6230 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006231 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07006232 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006233 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07006234 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006235 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006236 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
6237 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006238 pw.print(prefix);
6239 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006240 TimeUtils.formatDuration(duration, pw);
6241 pw.print(" to "); pw.print(level);
6242 boolean haveModes = false;
6243 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6244 pw.print(" (");
6245 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6246 case Display.STATE_OFF: pw.print("screen-off"); break;
6247 case Display.STATE_ON: pw.print("screen-on"); break;
6248 case Display.STATE_DOZE: pw.print("screen-doze"); break;
6249 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07006250 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006251 }
6252 haveModes = true;
6253 }
6254 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6255 pw.print(haveModes ? ", " : " (");
6256 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
6257 ? "power-save-on" : "power-save-off");
6258 haveModes = true;
6259 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006260 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6261 pw.print(haveModes ? ", " : " (");
6262 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6263 ? "device-idle-on" : "device-idle-off");
6264 haveModes = true;
6265 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006266 if (haveModes) {
6267 pw.print(")");
6268 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006269 pw.println();
6270 }
6271 }
6272 return true;
6273 }
6274
Kweku Adams87b19ec2017-10-09 12:40:03 -07006275 private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId,
6276 LevelStepTracker steps) {
6277 if (steps == null) {
6278 return;
6279 }
6280 int count = steps.mNumStepDurations;
Kweku Adams87b19ec2017-10-09 12:40:03 -07006281 for (int i = 0; i < count; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07006282 long token = proto.start(fieldId);
Kweku Adams87b19ec2017-10-09 12:40:03 -07006283 proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i));
6284 proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i));
6285
6286 final long initMode = steps.getInitModeAt(i);
6287 final long modMode = steps.getModModeAt(i);
6288
6289 int ds = SystemProto.BatteryLevelStep.DS_MIXED;
6290 if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6291 switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6292 case Display.STATE_OFF:
6293 ds = SystemProto.BatteryLevelStep.DS_OFF;
6294 break;
6295 case Display.STATE_ON:
6296 ds = SystemProto.BatteryLevelStep.DS_ON;
6297 break;
6298 case Display.STATE_DOZE:
6299 ds = SystemProto.BatteryLevelStep.DS_DOZE;
6300 break;
6301 case Display.STATE_DOZE_SUSPEND:
6302 ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND;
6303 break;
6304 default:
6305 ds = SystemProto.BatteryLevelStep.DS_ERROR;
6306 break;
6307 }
6308 }
6309 proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds);
6310
6311 int psm = SystemProto.BatteryLevelStep.PSM_MIXED;
6312 if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6313 psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0
6314 ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF;
6315 }
6316 proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm);
6317
6318 int im = SystemProto.BatteryLevelStep.IM_MIXED;
6319 if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6320 im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6321 ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF;
6322 }
6323 proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im);
6324
6325 proto.end(token);
6326 }
6327 }
6328
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006329 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006330 public static final int DUMP_DAILY_ONLY = 1<<2;
6331 public static final int DUMP_HISTORY_ONLY = 1<<3;
6332 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
6333 public static final int DUMP_VERBOSE = 1<<5;
6334 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006335
Dianne Hackborn37de0982014-05-09 09:32:18 -07006336 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
6337 final HistoryPrinter hprinter = new HistoryPrinter();
6338 final HistoryItem rec = new HistoryItem();
6339 long lastTime = -1;
6340 long baseTime = -1;
6341 boolean printed = false;
6342 HistoryEventTracker tracker = null;
6343 while (getNextHistoryLocked(rec)) {
6344 lastTime = rec.time;
6345 if (baseTime < 0) {
6346 baseTime = lastTime;
6347 }
6348 if (rec.time >= histStart) {
6349 if (histStart >= 0 && !printed) {
6350 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006351 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006352 || rec.cmd == HistoryItem.CMD_START
6353 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006354 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006355 hprinter.printNextItem(pw, rec, baseTime, checkin,
6356 (flags&DUMP_VERBOSE) != 0);
6357 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006358 } else if (rec.currentTime != 0) {
6359 printed = true;
6360 byte cmd = rec.cmd;
6361 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006362 hprinter.printNextItem(pw, rec, baseTime, checkin,
6363 (flags&DUMP_VERBOSE) != 0);
6364 rec.cmd = cmd;
6365 }
6366 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006367 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6368 hprinter.printNextItem(pw, rec, baseTime, checkin,
6369 (flags&DUMP_VERBOSE) != 0);
6370 rec.cmd = HistoryItem.CMD_UPDATE;
6371 }
6372 int oldEventCode = rec.eventCode;
6373 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006374 rec.eventTag = new HistoryTag();
6375 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6376 HashMap<String, SparseIntArray> active
6377 = tracker.getStateForEvent(i);
6378 if (active == null) {
6379 continue;
6380 }
6381 for (HashMap.Entry<String, SparseIntArray> ent
6382 : active.entrySet()) {
6383 SparseIntArray uids = ent.getValue();
6384 for (int j=0; j<uids.size(); j++) {
6385 rec.eventCode = i;
6386 rec.eventTag.string = ent.getKey();
6387 rec.eventTag.uid = uids.keyAt(j);
6388 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006389 hprinter.printNextItem(pw, rec, baseTime, checkin,
6390 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006391 rec.wakeReasonTag = null;
6392 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006393 }
6394 }
6395 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006396 rec.eventCode = oldEventCode;
6397 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006398 tracker = null;
6399 }
6400 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006401 hprinter.printNextItem(pw, rec, baseTime, checkin,
6402 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006403 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6404 // This is an attempt to aggregate the previous state and generate
6405 // fake events to reflect that state at the point where we start
6406 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006407 if (tracker == null) {
6408 tracker = new HistoryEventTracker();
6409 }
6410 tracker.updateState(rec.eventCode, rec.eventTag.string,
6411 rec.eventTag.uid, rec.eventTag.poolIdx);
6412 }
6413 }
6414 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006415 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006416 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6417 }
6418 }
6419
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006420 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6421 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6422 if (steps == null) {
6423 return;
6424 }
6425 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6426 if (timeRemaining >= 0) {
6427 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6428 tmpSb.setLength(0);
6429 formatTimeMs(tmpSb, timeRemaining);
6430 pw.print(tmpSb);
6431 pw.print(" (from "); pw.print(tmpOutInt[0]);
6432 pw.println(" steps)");
6433 }
6434 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6435 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6436 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6437 if (estimatedTime > 0) {
6438 pw.print(prefix); pw.print(label); pw.print(" ");
6439 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6440 pw.print(" time: ");
6441 tmpSb.setLength(0);
6442 formatTimeMs(tmpSb, estimatedTime);
6443 pw.print(tmpSb);
6444 pw.print(" (from "); pw.print(tmpOutInt[0]);
6445 pw.println(" steps)");
6446 }
6447 }
6448 }
6449
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006450 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6451 ArrayList<PackageChange> changes) {
6452 if (changes == null) {
6453 return;
6454 }
6455 pw.print(prefix); pw.println("Package changes:");
6456 for (int i=0; i<changes.size(); i++) {
6457 PackageChange pc = changes.get(i);
6458 if (pc.mUpdate) {
6459 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6460 pw.print(" vers="); pw.println(pc.mVersionCode);
6461 } else {
6462 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6463 }
6464 }
6465 }
6466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 /**
6468 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6469 *
6470 * @param pw a Printer to receive the dump output.
6471 */
6472 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006473 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006474 prepareForDumpLocked();
6475
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006476 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006477 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006478
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006479 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006480 final long historyTotalSize = getHistoryTotalSize();
6481 final long historyUsedSize = getHistoryUsedSize();
6482 if (startIteratingHistoryLocked()) {
6483 try {
6484 pw.print("Battery History (");
6485 pw.print((100*historyUsedSize)/historyTotalSize);
6486 pw.print("% used, ");
6487 printSizeValue(pw, historyUsedSize);
6488 pw.print(" used of ");
6489 printSizeValue(pw, historyTotalSize);
6490 pw.print(", ");
6491 pw.print(getHistoryStringPoolSize());
6492 pw.print(" strings using ");
6493 printSizeValue(pw, getHistoryStringPoolBytes());
6494 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006495 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006496 pw.println();
6497 } finally {
6498 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006499 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006500 }
6501
6502 if (startIteratingOldHistoryLocked()) {
6503 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006504 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006505 pw.println("Old battery History:");
6506 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006507 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006508 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006509 if (baseTime < 0) {
6510 baseTime = rec.time;
6511 }
6512 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006513 }
6514 pw.println();
6515 } finally {
6516 finishIteratingOldHistoryLocked();
6517 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006518 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006519 }
6520
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006521 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006522 return;
6523 }
6524
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006525 if (!filtering) {
6526 SparseArray<? extends Uid> uidStats = getUidStats();
6527 final int NU = uidStats.size();
6528 boolean didPid = false;
6529 long nowRealtime = SystemClock.elapsedRealtime();
6530 for (int i=0; i<NU; i++) {
6531 Uid uid = uidStats.valueAt(i);
6532 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6533 if (pids != null) {
6534 for (int j=0; j<pids.size(); j++) {
6535 Uid.Pid pid = pids.valueAt(j);
6536 if (!didPid) {
6537 pw.println("Per-PID Stats:");
6538 didPid = true;
6539 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006540 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6541 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006542 pw.print(" PID "); pw.print(pids.keyAt(j));
6543 pw.print(" wake time: ");
6544 TimeUtils.formatDuration(time, pw);
6545 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006546 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006547 }
6548 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006549 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006550 pw.println();
6551 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006552 }
6553
6554 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006555 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6556 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006557 long timeRemaining = computeBatteryTimeRemaining(
6558 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006559 if (timeRemaining >= 0) {
6560 pw.print(" Estimated discharge time remaining: ");
6561 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6562 pw.println();
6563 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006564 final LevelStepTracker steps = getDischargeLevelStepTracker();
6565 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6566 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6567 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6568 STEP_LEVEL_MODE_VALUES[i], null));
6569 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006570 pw.println();
6571 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006572 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6573 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006574 long timeRemaining = computeChargeTimeRemaining(
6575 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006576 if (timeRemaining >= 0) {
6577 pw.print(" Estimated charge time remaining: ");
6578 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6579 pw.println();
6580 }
6581 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006582 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006583 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07006584 if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006585 pw.println("Daily stats:");
6586 pw.print(" Current start time: ");
6587 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6588 getCurrentDailyStartTime()).toString());
6589 pw.print(" Next min deadline: ");
6590 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6591 getNextMinDailyDeadline()).toString());
6592 pw.print(" Next max deadline: ");
6593 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6594 getNextMaxDailyDeadline()).toString());
6595 StringBuilder sb = new StringBuilder(64);
6596 int[] outInt = new int[1];
6597 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6598 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006599 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6600 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006601 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006602 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6603 dsteps, false)) {
6604 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6605 sb, outInt);
6606 }
6607 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6608 csteps, false)) {
6609 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6610 sb, outInt);
6611 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006612 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006613 } else {
6614 pw.println(" Current daily steps:");
6615 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6616 sb, outInt);
6617 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6618 sb, outInt);
6619 }
6620 }
6621 DailyItem dit;
6622 int curIndex = 0;
6623 while ((dit=getDailyItemLocked(curIndex)) != null) {
6624 curIndex++;
6625 if ((flags&DUMP_DAILY_ONLY) != 0) {
6626 pw.println();
6627 }
6628 pw.print(" Daily from ");
6629 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6630 pw.print(" to ");
6631 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6632 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006633 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006634 if (dumpDurationSteps(pw, " ",
6635 " Discharge step durations:", dit.mDischargeSteps, false)) {
6636 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6637 sb, outInt);
6638 }
6639 if (dumpDurationSteps(pw, " ",
6640 " Charge step durations:", dit.mChargeSteps, false)) {
6641 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6642 sb, outInt);
6643 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006644 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006645 } else {
6646 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6647 sb, outInt);
6648 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6649 sb, outInt);
6650 }
6651 }
6652 pw.println();
6653 }
6654 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006655 pw.println("Statistics since last charge:");
6656 pw.println(" System starts: " + getStartCount()
6657 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006658 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6659 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006660 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 }
Mike Mac2f518a2017-09-19 16:06:03 -07006663
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006664 // This is called from BatteryStatsService.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006666 public void dumpCheckinLocked(Context context, PrintWriter pw,
6667 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006668 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006669
6670 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006671 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6672 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006673
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006674 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6675
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006676 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006677 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006678 try {
6679 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6680 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6681 pw.print(HISTORY_STRING_POOL); pw.print(',');
6682 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006683 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006684 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006685 pw.print(",\"");
6686 String str = getHistoryTagPoolString(i);
6687 str = str.replace("\\", "\\\\");
6688 str = str.replace("\"", "\\\"");
6689 pw.print(str);
6690 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006691 pw.println();
6692 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006693 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006694 } finally {
6695 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006696 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006697 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006698 }
6699
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006700 if ((flags & DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006701 return;
6702 }
6703
Dianne Hackborne4a59512010-12-07 11:08:07 -08006704 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006705 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006706 for (int i=0; i<apps.size(); i++) {
6707 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006708 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6709 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006710 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006711 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6712 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006713 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006714 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006715 }
6716 SparseArray<? extends Uid> uidStats = getUidStats();
6717 final int NU = uidStats.size();
6718 String[] lineArgs = new String[2];
6719 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006720 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6721 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6722 if (pkgs != null && !pkgs.second.value) {
6723 pkgs.second.value = true;
6724 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006725 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006726 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006727 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6728 (Object[])lineArgs);
6729 }
6730 }
6731 }
6732 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006733 if ((flags & DUMP_DAILY_ONLY) == 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006734 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006735 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006736 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006737 if (timeRemaining >= 0) {
6738 lineArgs[0] = Long.toString(timeRemaining);
6739 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6740 (Object[])lineArgs);
6741 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006742 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006743 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006744 if (timeRemaining >= 0) {
6745 lineArgs[0] = Long.toString(timeRemaining);
6746 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6747 (Object[])lineArgs);
6748 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006749 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6750 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006753
Kweku Adams87b19ec2017-10-09 12:40:03 -07006754 /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006755 public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps,
Kweku Adams6ccebf22017-12-11 12:30:35 -08006756 int flags) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006757 final ProtoOutputStream proto = new ProtoOutputStream(fd);
6758 final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS);
6759 prepareForDumpLocked();
6760
6761 proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION);
6762 proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion());
6763 proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion());
6764 proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion());
6765
Kweku Adams6ccebf22017-12-11 12:30:35 -08006766 // History intentionally not included in proto dump.
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006767
6768 if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) {
Kweku Adams103351f2017-10-16 14:39:34 -07006769 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false,
6770 (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
6771 helper.create(this);
6772 helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL);
6773
6774 dumpProtoAppsLocked(proto, helper, apps);
6775 dumpProtoSystemLocked(proto, helper);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006776 }
6777
6778 proto.end(bToken);
6779 proto.flush();
6780 }
Kweku Adams87b19ec2017-10-09 12:40:03 -07006781
Kweku Adams103351f2017-10-16 14:39:34 -07006782 private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper,
6783 List<ApplicationInfo> apps) {
6784 final int which = STATS_SINCE_CHARGED;
6785 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
6786 final long rawRealtimeMs = SystemClock.elapsedRealtime();
6787 final long rawRealtimeUs = rawRealtimeMs * 1000;
6788 final long batteryUptimeUs = getBatteryUptime(rawUptimeUs);
6789
6790 SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>();
6791 if (apps != null) {
6792 for (int i = 0; i < apps.size(); ++i) {
6793 ApplicationInfo ai = apps.get(i);
6794 int aid = UserHandle.getAppId(ai.uid);
6795 ArrayList<String> pkgs = aidToPackages.get(aid);
6796 if (pkgs == null) {
6797 pkgs = new ArrayList<String>();
6798 aidToPackages.put(aid, pkgs);
6799 }
6800 pkgs.add(ai.packageName);
6801 }
6802 }
6803
6804 SparseArray<BatterySipper> uidToSipper = new SparseArray<>();
6805 final List<BatterySipper> sippers = helper.getUsageList();
6806 if (sippers != null) {
6807 for (int i = 0; i < sippers.size(); ++i) {
6808 final BatterySipper bs = sippers.get(i);
6809 if (bs.drainType != BatterySipper.DrainType.APP) {
6810 // Others are handled by dumpProtoSystemLocked()
6811 continue;
6812 }
6813 uidToSipper.put(bs.uidObj.getUid(), bs);
6814 }
6815 }
6816
6817 SparseArray<? extends Uid> uidStats = getUidStats();
6818 final int n = uidStats.size();
6819 for (int iu = 0; iu < n; ++iu) {
6820 final long uTkn = proto.start(BatteryStatsProto.UIDS);
6821 final Uid u = uidStats.valueAt(iu);
6822
6823 final int uid = uidStats.keyAt(iu);
6824 proto.write(UidProto.UID, uid);
6825
6826 // Print packages and apk stats (UID_DATA & APK_DATA)
6827 ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid));
6828 if (pkgs == null) {
6829 pkgs = new ArrayList<String>();
6830 }
6831 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats =
6832 u.getPackageStats();
6833 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
6834 String pkg = packageStats.keyAt(ipkg);
6835 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats =
6836 packageStats.valueAt(ipkg).getServiceStats();
6837 if (serviceStats.size() == 0) {
6838 // Due to the way ActivityManagerService logs wakeup alarms, some packages (for
6839 // example, "android") may be included in the packageStats that aren't part of
6840 // the UID. If they don't have any services, then they shouldn't be listed here.
6841 // These packages won't be a part in the pkgs List.
6842 continue;
6843 }
6844
6845 final long pToken = proto.start(UidProto.PACKAGES);
6846 proto.write(UidProto.Package.NAME, pkg);
6847 // Remove from the packages list since we're logging it here.
6848 pkgs.remove(pkg);
6849
6850 for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) {
6851 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
6852 long sToken = proto.start(UidProto.Package.SERVICES);
6853
6854 proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc));
6855 proto.write(UidProto.Package.Service.START_DURATION_MS,
6856 roundUsToMs(ss.getStartTime(batteryUptimeUs, which)));
6857 proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which));
6858 proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which));
6859
6860 proto.end(sToken);
6861 }
6862 proto.end(pToken);
6863 }
6864 // Print any remaining packages that weren't in the packageStats map. pkgs is pulled
6865 // from PackageManager data. Packages are only included in packageStats if there was
6866 // specific data tracked for them (services and wakeup alarms, etc.).
6867 for (String p : pkgs) {
6868 final long pToken = proto.start(UidProto.PACKAGES);
6869 proto.write(UidProto.Package.NAME, p);
6870 proto.end(pToken);
6871 }
6872
6873 // Total wakelock data (AGGREGATED_WAKELOCK_DATA)
6874 if (u.getAggregatedPartialWakelockTimer() != null) {
6875 final Timer timer = u.getAggregatedPartialWakelockTimer();
6876 // Times are since reset (regardless of 'which')
6877 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
6878 final Timer bgTimer = timer.getSubTimer();
6879 final long bgTimeMs = bgTimer != null
6880 ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
6881 final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK);
6882 proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs);
6883 proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs);
6884 proto.end(awToken);
6885 }
6886
6887 // Audio (AUDIO_DATA)
6888 dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which);
6889
6890 // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA)
6891 dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER,
6892 u.getBluetoothControllerActivity(), which);
6893
6894 // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked)
6895 final Timer bleTimer = u.getBluetoothScanTimer();
6896 if (bleTimer != null) {
6897 final long bmToken = proto.start(UidProto.BLUETOOTH_MISC);
6898
6899 dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer,
6900 rawRealtimeUs, which);
6901 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN,
6902 u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which);
6903 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
6904 dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN,
6905 u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which);
6906 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
6907 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN,
6908 u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which);
6909 // Result counters
6910 proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT,
6911 u.getBluetoothScanResultCounter() != null
6912 ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0);
6913 proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT,
6914 u.getBluetoothScanResultBgCounter() != null
6915 ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0);
6916
6917 proto.end(bmToken);
6918 }
6919
6920 // Camera (CAMERA_DATA)
6921 dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which);
6922
6923 // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA)
6924 final long cpuToken = proto.start(UidProto.CPU);
6925 proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which)));
6926 proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which)));
6927
6928 final long[] cpuFreqs = getCpuFreqs();
6929 if (cpuFreqs != null) {
6930 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
6931 // If total cpuFreqTimes is null, then we don't need to check for
6932 // screenOffCpuFreqTimes.
6933 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
6934 long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
6935 if (screenOffCpuFreqTimeMs == null) {
6936 screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
6937 }
6938 for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) {
6939 long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY);
6940 proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1);
6941 proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS,
6942 cpuFreqTimeMs[ic]);
6943 proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS,
6944 screenOffCpuFreqTimeMs[ic]);
6945 proto.end(cToken);
6946 }
6947 }
6948 }
6949 proto.end(cpuToken);
6950
6951 // Flashlight (FLASHLIGHT_DATA)
6952 dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(),
6953 rawRealtimeUs, which);
6954
6955 // Foreground activity (FOREGROUND_ACTIVITY_DATA)
6956 dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(),
6957 rawRealtimeUs, which);
6958
6959 // Foreground service (FOREGROUND_SERVICE_DATA)
6960 dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(),
6961 rawRealtimeUs, which);
6962
6963 // Job completion (JOB_COMPLETION_DATA)
6964 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
6965 final int[] reasons = new int[]{
6966 JobParameters.REASON_CANCELED,
6967 JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
6968 JobParameters.REASON_PREEMPT,
6969 JobParameters.REASON_TIMEOUT,
6970 JobParameters.REASON_DEVICE_IDLE,
6971 };
6972 for (int ic = 0; ic < completions.size(); ++ic) {
6973 SparseIntArray types = completions.valueAt(ic);
6974 if (types != null) {
6975 final long jcToken = proto.start(UidProto.JOB_COMPLETION);
6976
6977 proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic));
6978
6979 for (int r : reasons) {
6980 long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT);
6981 proto.write(UidProto.JobCompletion.ReasonCount.NAME, r);
6982 proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0));
6983 proto.end(rToken);
6984 }
6985
6986 proto.end(jcToken);
6987 }
6988 }
6989
6990 // Scheduled jobs (JOB_DATA)
6991 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
6992 for (int ij = jobs.size() - 1; ij >= 0; --ij) {
6993 final Timer timer = jobs.valueAt(ij);
6994 final Timer bgTimer = timer.getSubTimer();
6995 final long jToken = proto.start(UidProto.JOBS);
6996
6997 proto.write(UidProto.Job.NAME, jobs.keyAt(ij));
6998 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
6999 dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which);
7000 dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which);
7001
7002 proto.end(jToken);
7003 }
7004
7005 // Modem Controller (MODEM_CONTROLLER_DATA)
7006 dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER,
7007 u.getModemControllerActivity(), which);
7008
7009 // Network stats (NETWORK_DATA)
7010 final long nToken = proto.start(UidProto.NETWORK);
7011 proto.write(UidProto.Network.MOBILE_BYTES_RX,
7012 u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7013 proto.write(UidProto.Network.MOBILE_BYTES_TX,
7014 u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7015 proto.write(UidProto.Network.WIFI_BYTES_RX,
7016 u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7017 proto.write(UidProto.Network.WIFI_BYTES_TX,
7018 u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7019 proto.write(UidProto.Network.BT_BYTES_RX,
7020 u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7021 proto.write(UidProto.Network.BT_BYTES_TX,
7022 u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
7023 proto.write(UidProto.Network.MOBILE_PACKETS_RX,
7024 u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7025 proto.write(UidProto.Network.MOBILE_PACKETS_TX,
7026 u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7027 proto.write(UidProto.Network.WIFI_PACKETS_RX,
7028 u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7029 proto.write(UidProto.Network.WIFI_PACKETS_TX,
7030 u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7031 proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS,
7032 roundUsToMs(u.getMobileRadioActiveTime(which)));
7033 proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT,
7034 u.getMobileRadioActiveCount(which));
7035 proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT,
7036 u.getMobileRadioApWakeupCount(which));
7037 proto.write(UidProto.Network.WIFI_WAKEUP_COUNT,
7038 u.getWifiRadioApWakeupCount(which));
7039 proto.write(UidProto.Network.MOBILE_BYTES_BG_RX,
7040 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which));
7041 proto.write(UidProto.Network.MOBILE_BYTES_BG_TX,
7042 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which));
7043 proto.write(UidProto.Network.WIFI_BYTES_BG_RX,
7044 u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which));
7045 proto.write(UidProto.Network.WIFI_BYTES_BG_TX,
7046 u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which));
7047 proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX,
7048 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which));
7049 proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX,
7050 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which));
7051 proto.write(UidProto.Network.WIFI_PACKETS_BG_RX,
7052 u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which));
7053 proto.write(UidProto.Network.WIFI_PACKETS_BG_TX,
7054 u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which));
7055 proto.end(nToken);
7056
7057 // Power use item (POWER_USE_ITEM_DATA)
7058 BatterySipper bs = uidToSipper.get(uid);
7059 if (bs != null) {
7060 final long bsToken = proto.start(UidProto.POWER_USE_ITEM);
7061 proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7062 proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7063 proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7064 proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7065 bs.proportionalSmearMah);
7066 proto.end(bsToken);
7067 }
7068
7069 // Processes (PROCESS_DATA)
7070 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats =
7071 u.getProcessStats();
7072 for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) {
7073 final Uid.Proc ps = processStats.valueAt(ipr);
7074 final long prToken = proto.start(UidProto.PROCESS);
7075
7076 proto.write(UidProto.Process.NAME, processStats.keyAt(ipr));
7077 proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which));
7078 proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which));
7079 proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which));
7080 proto.write(UidProto.Process.START_COUNT, ps.getStarts(which));
7081 proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which));
7082 proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which));
7083
7084 proto.end(prToken);
7085 }
7086
7087 // Sensors (SENSOR_DATA)
7088 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
7089 for (int ise = 0; ise < sensors.size(); ++ise) {
7090 final Uid.Sensor se = sensors.valueAt(ise);
7091 final Timer timer = se.getSensorTime();
7092 if (timer == null) {
7093 continue;
7094 }
7095 final Timer bgTimer = se.getSensorBackgroundTime();
7096 final int sensorNumber = sensors.keyAt(ise);
7097 final long seToken = proto.start(UidProto.SENSORS);
7098
7099 proto.write(UidProto.Sensor.ID, sensorNumber);
7100 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7101 dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which);
7102 dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which);
7103
7104 proto.end(seToken);
7105 }
7106
7107 // State times (STATE_TIME_DATA)
7108 for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) {
7109 long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which));
7110 if (durMs == 0) {
7111 continue;
7112 }
7113 final long stToken = proto.start(UidProto.STATES);
7114 proto.write(UidProto.StateTime.STATE, ips);
7115 proto.write(UidProto.StateTime.DURATION_MS, durMs);
7116 proto.end(stToken);
7117 }
7118
7119 // Syncs (SYNC_DATA)
7120 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
7121 for (int isy = syncs.size() - 1; isy >= 0; --isy) {
7122 final Timer timer = syncs.valueAt(isy);
7123 final Timer bgTimer = timer.getSubTimer();
7124 final long syToken = proto.start(UidProto.SYNCS);
7125
7126 proto.write(UidProto.Sync.NAME, syncs.keyAt(isy));
7127 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7128 dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which);
7129 dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which);
7130
7131 proto.end(syToken);
7132 }
7133
7134 // User activity (USER_ACTIVITY_DATA)
7135 if (u.hasUserActivity()) {
7136 for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) {
7137 int val = u.getUserActivityCount(i, which);
7138 if (val != 0) {
7139 final long uaToken = proto.start(UidProto.USER_ACTIVITY);
7140 proto.write(UidProto.UserActivity.NAME, i);
7141 proto.write(UidProto.UserActivity.COUNT, val);
7142 proto.end(uaToken);
7143 }
7144 }
7145 }
7146
7147 // Vibrator (VIBRATOR_DATA)
7148 dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which);
7149
7150 // Video (VIDEO_DATA)
7151 dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which);
7152
7153 // Wakelocks (WAKELOCK_DATA)
7154 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
7155 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7156 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7157 final long wToken = proto.start(UidProto.WAKELOCKS);
7158 proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw));
7159 dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL),
7160 rawRealtimeUs, which);
7161 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7162 if (pTimer != null) {
7163 dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which);
7164 dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(),
7165 rawRealtimeUs, which);
7166 }
7167 dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW),
7168 rawRealtimeUs, which);
7169 proto.end(wToken);
7170 }
7171
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007172 // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA)
7173 dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(),
7174 rawRealtimeUs, which);
7175
Kweku Adams103351f2017-10-16 14:39:34 -07007176 // Wakeup alarms (WAKEUP_ALARM_DATA)
7177 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
7178 final Uid.Pkg ps = packageStats.valueAt(ipkg);
7179 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
7180 for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) {
7181 final long waToken = proto.start(UidProto.WAKEUP_ALARM);
7182 proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa));
7183 proto.write(UidProto.WakeupAlarm.COUNT,
7184 alarms.valueAt(iwa).getCountLocked(which));
7185 proto.end(waToken);
7186 }
7187 }
7188
7189 // Wifi Controller (WIFI_CONTROLLER_DATA)
7190 dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER,
7191 u.getWifiControllerActivity(), which);
7192
7193 // Wifi data (WIFI_DATA)
7194 final long wToken = proto.start(UidProto.WIFI);
7195 proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS,
7196 roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which)));
7197 dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(),
7198 rawRealtimeUs, which);
7199 proto.write(UidProto.Wifi.RUNNING_DURATION_MS,
7200 roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which)));
7201 dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(),
7202 rawRealtimeUs, which);
7203 proto.end(wToken);
7204
7205 proto.end(uTkn);
7206 }
7207 }
7208
7209 private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) {
Kweku Adams87b19ec2017-10-09 12:40:03 -07007210 final long sToken = proto.start(BatteryStatsProto.SYSTEM);
7211 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
7212 final long rawRealtimeMs = SystemClock.elapsedRealtime();
7213 final long rawRealtimeUs = rawRealtimeMs * 1000;
7214 final int which = STATS_SINCE_CHARGED;
7215
7216 // Battery data (BATTERY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007217 final long bToken = proto.start(SystemProto.BATTERY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007218 proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime());
7219 proto.write(SystemProto.Battery.START_COUNT, getStartCount());
7220 proto.write(SystemProto.Battery.TOTAL_REALTIME_MS,
7221 computeRealtime(rawRealtimeUs, which) / 1000);
7222 proto.write(SystemProto.Battery.TOTAL_UPTIME_MS,
7223 computeUptime(rawUptimeUs, which) / 1000);
7224 proto.write(SystemProto.Battery.BATTERY_REALTIME_MS,
7225 computeBatteryRealtime(rawRealtimeUs, which) / 1000);
7226 proto.write(SystemProto.Battery.BATTERY_UPTIME_MS,
7227 computeBatteryUptime(rawUptimeUs, which) / 1000);
7228 proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS,
7229 computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000);
7230 proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS,
7231 computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000);
7232 proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS,
7233 getScreenDozeTime(rawRealtimeUs, which) / 1000);
7234 proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH,
7235 getEstimatedBatteryCapacity());
7236 proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH,
7237 getMinLearnedBatteryCapacity());
7238 proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH,
7239 getMaxLearnedBatteryCapacity());
Kweku Adams103351f2017-10-16 14:39:34 -07007240 proto.end(bToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007241
7242 // Battery discharge (BATTERY_DISCHARGE_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007243 final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007244 proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE,
7245 getLowDischargeAmountSinceCharge());
7246 proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE,
7247 getHighDischargeAmountSinceCharge());
7248 proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE,
7249 getDischargeAmountScreenOnSinceCharge());
7250 proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE,
7251 getDischargeAmountScreenOffSinceCharge());
7252 proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE,
7253 getDischargeAmountScreenDozeSinceCharge());
7254 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH,
7255 getUahDischarge(which) / 1000);
7256 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF,
7257 getUahDischargeScreenOff(which) / 1000);
7258 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE,
7259 getUahDischargeScreenDoze(which) / 1000);
Mike Ma15313c92017-11-15 17:58:21 -08007260 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE,
7261 getUahDischargeLightDoze(which) / 1000);
7262 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE,
7263 getUahDischargeDeepDoze(which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007264 proto.end(bdToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007265
7266 // Time remaining
7267 long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -07007268 // These are part of a oneof, so we should only set one of them.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007269 if (timeRemainingUs >= 0) {
7270 // Charge time remaining (CHARGE_TIME_REMAIN_DATA)
7271 proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7272 } else {
7273 timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs);
7274 // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA)
7275 if (timeRemainingUs >= 0) {
7276 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7277 } else {
7278 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1);
7279 }
7280 }
7281
7282 // Charge step (CHARGE_STEP_DATA)
7283 dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker());
7284
7285 // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA)
7286 for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007287 final long pdcToken = proto.start(SystemProto.DATA_CONNECTION);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007288 proto.write(SystemProto.DataConnection.NAME, i);
7289 dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i),
7290 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007291 proto.end(pdcToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007292 }
7293
7294 // Discharge step (DISCHARGE_STEP_DATA)
7295 dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker());
7296
7297 // CPU frequencies (GLOBAL_CPU_FREQ_DATA)
7298 final long[] cpuFreqs = getCpuFreqs();
7299 if (cpuFreqs != null) {
7300 for (long i : cpuFreqs) {
7301 proto.write(SystemProto.CPU_FREQUENCY, i);
7302 }
7303 }
7304
7305 // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA)
7306 dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER,
7307 getBluetoothControllerActivity(), which);
7308
7309 // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA)
7310 dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER,
7311 getModemControllerActivity(), which);
7312
7313 // Global network data (GLOBAL_NETWORK_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007314 final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007315 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX,
7316 getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7317 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX,
7318 getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7319 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX,
7320 getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7321 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX,
7322 getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7323 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX,
7324 getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7325 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX,
7326 getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7327 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX,
7328 getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7329 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX,
7330 getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7331 proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX,
7332 getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7333 proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX,
7334 getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
Kweku Adams103351f2017-10-16 14:39:34 -07007335 proto.end(gnToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007336
7337 // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA)
7338 dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER,
7339 getWifiControllerActivity(), which);
7340
7341
7342 // Global wifi (GLOBAL_WIFI_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007343 final long gwToken = proto.start(SystemProto.GLOBAL_WIFI);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007344 proto.write(SystemProto.GlobalWifi.ON_DURATION_MS,
7345 getWifiOnTime(rawRealtimeUs, which) / 1000);
7346 proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS,
7347 getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007348 proto.end(gwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007349
7350 // Kernel wakelock (KERNEL_WAKELOCK_DATA)
7351 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
7352 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007353 final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007354 proto.write(SystemProto.KernelWakelock.NAME, ent.getKey());
7355 dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(),
7356 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007357 proto.end(kwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007358 }
7359
7360 // Misc (MISC_DATA)
7361 // Calculate wakelock times across all uids.
7362 long fullWakeLockTimeTotalUs = 0;
7363 long partialWakeLockTimeTotalUs = 0;
7364
7365 final SparseArray<? extends Uid> uidStats = getUidStats();
7366 for (int iu = 0; iu < uidStats.size(); iu++) {
7367 final Uid u = uidStats.valueAt(iu);
7368
7369 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks =
7370 u.getWakelockStats();
7371 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7372 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7373
7374 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
7375 if (fullWakeTimer != null) {
7376 fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs,
7377 which);
7378 }
7379
7380 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7381 if (partialWakeTimer != null) {
7382 partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked(
7383 rawRealtimeUs, which);
7384 }
7385 }
7386 }
Kweku Adams103351f2017-10-16 14:39:34 -07007387 final long mToken = proto.start(SystemProto.MISC);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007388 proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS,
7389 getScreenOnTime(rawRealtimeUs, which) / 1000);
7390 proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS,
7391 getPhoneOnTime(rawRealtimeUs, which) / 1000);
7392 proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS,
7393 fullWakeLockTimeTotalUs / 1000);
7394 proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS,
7395 partialWakeLockTimeTotalUs / 1000);
7396 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS,
7397 getMobileRadioActiveTime(rawRealtimeUs, which) / 1000);
7398 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS,
7399 getMobileRadioActiveAdjustedTime(which) / 1000);
7400 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT,
7401 getMobileRadioActiveCount(which));
7402 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS,
7403 getMobileRadioActiveUnknownTime(which) / 1000);
7404 proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS,
7405 getInteractiveTime(rawRealtimeUs, which) / 1000);
7406 proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS,
7407 getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000);
7408 proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES,
7409 getNumConnectivityChange(which));
7410 proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS,
7411 getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7412 proto.write(SystemProto.Misc.DEEP_DOZE_COUNT,
7413 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
7414 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS,
7415 getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7416 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT,
7417 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
7418 proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS,
7419 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
7420 proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS,
7421 getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7422 proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT,
7423 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
7424 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS,
7425 getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7426 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT,
7427 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
7428 proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS,
7429 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
Kweku Adams103351f2017-10-16 14:39:34 -07007430 proto.end(mToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007431
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007432 // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA)
7433 // Calculate multicast wakelock stats across all uids.
7434 long multicastWakeLockTimeTotalUs = 0;
7435 int multicastWakeLockCountTotal = 0;
7436
7437 for (int iu = 0; iu < uidStats.size(); iu++) {
7438 final Uid u = uidStats.valueAt(iu);
7439
7440 final Timer mcTimer = u.getMulticastWakelockStats();
7441
7442 if (mcTimer != null) {
7443 multicastWakeLockTimeTotalUs +=
7444 mcTimer.getTotalTimeLocked(rawRealtimeUs, which);
7445 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
7446 }
7447 }
7448
7449 final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL);
7450 proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS,
7451 multicastWakeLockTimeTotalUs / 1000);
7452 proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT,
7453 multicastWakeLockCountTotal);
7454 proto.end(wmctToken);
7455
Kweku Adams87b19ec2017-10-09 12:40:03 -07007456 // Power use item (POWER_USE_ITEM_DATA)
7457 final List<BatterySipper> sippers = helper.getUsageList();
7458 if (sippers != null) {
7459 for (int i = 0; i < sippers.size(); ++i) {
7460 final BatterySipper bs = sippers.get(i);
7461 int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER;
7462 int uid = 0;
7463 switch (bs.drainType) {
7464 case IDLE:
7465 n = SystemProto.PowerUseItem.IDLE;
7466 break;
7467 case CELL:
7468 n = SystemProto.PowerUseItem.CELL;
7469 break;
7470 case PHONE:
7471 n = SystemProto.PowerUseItem.PHONE;
7472 break;
7473 case WIFI:
7474 n = SystemProto.PowerUseItem.WIFI;
7475 break;
7476 case BLUETOOTH:
7477 n = SystemProto.PowerUseItem.BLUETOOTH;
7478 break;
7479 case SCREEN:
7480 n = SystemProto.PowerUseItem.SCREEN;
7481 break;
7482 case FLASHLIGHT:
7483 n = SystemProto.PowerUseItem.FLASHLIGHT;
7484 break;
7485 case APP:
Kweku Adams103351f2017-10-16 14:39:34 -07007486 // dumpProtoAppsLocked will handle this.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007487 continue;
7488 case USER:
7489 n = SystemProto.PowerUseItem.USER;
7490 uid = UserHandle.getUid(bs.userId, 0);
7491 break;
7492 case UNACCOUNTED:
7493 n = SystemProto.PowerUseItem.UNACCOUNTED;
7494 break;
7495 case OVERCOUNTED:
7496 n = SystemProto.PowerUseItem.OVERCOUNTED;
7497 break;
7498 case CAMERA:
7499 n = SystemProto.PowerUseItem.CAMERA;
7500 break;
7501 case MEMORY:
7502 n = SystemProto.PowerUseItem.MEMORY;
7503 break;
7504 }
Kweku Adams103351f2017-10-16 14:39:34 -07007505 final long puiToken = proto.start(SystemProto.POWER_USE_ITEM);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007506 proto.write(SystemProto.PowerUseItem.NAME, n);
7507 proto.write(SystemProto.PowerUseItem.UID, uid);
7508 proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7509 proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7510 proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7511 proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7512 bs.proportionalSmearMah);
Kweku Adams103351f2017-10-16 14:39:34 -07007513 proto.end(puiToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007514 }
7515 }
7516
7517 // Power use summary (POWER_USE_SUMMARY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007518 final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007519 proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH,
7520 helper.getPowerProfile().getBatteryCapacity());
7521 proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower());
7522 proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower());
7523 proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower());
Kweku Adams103351f2017-10-16 14:39:34 -07007524 proto.end(pusToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007525
7526 // RPM stats (RESOURCE_POWER_MANAGER_DATA)
7527 final Map<String, ? extends Timer> rpmStats = getRpmStats();
7528 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
7529 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007530 final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007531 proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey());
7532 dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL,
7533 ent.getValue(), rawRealtimeUs, which);
7534 dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF,
7535 screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007536 proto.end(rpmToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007537 }
7538
7539 // Screen brightness (SCREEN_BRIGHTNESS_DATA)
7540 for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007541 final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007542 proto.write(SystemProto.ScreenBrightness.NAME, i);
7543 dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i),
7544 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007545 proto.end(sbToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007546 }
7547
7548 // Signal scanning time (SIGNAL_SCANNING_TIME_DATA)
7549 dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs,
7550 which);
7551
7552 // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA)
7553 for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007554 final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007555 proto.write(SystemProto.PhoneSignalStrength.NAME, i);
7556 dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i),
7557 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007558 proto.end(pssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007559 }
7560
7561 // Wakeup reasons (WAKEUP_REASON_DATA)
7562 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
7563 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007564 final long wrToken = proto.start(SystemProto.WAKEUP_REASON);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007565 proto.write(SystemProto.WakeupReason.NAME, ent.getKey());
7566 dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007567 proto.end(wrToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007568 }
7569
7570 // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA)
7571 for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007572 final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007573 proto.write(SystemProto.WifiSignalStrength.NAME, i);
7574 dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i),
7575 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007576 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007577 }
7578
7579 // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA)
7580 for (int i = 0; i < NUM_WIFI_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007581 final long wsToken = proto.start(SystemProto.WIFI_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007582 proto.write(SystemProto.WifiState.NAME, i);
7583 dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i),
7584 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007585 proto.end(wsToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007586 }
7587
7588 // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA)
7589 for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007590 final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007591 proto.write(SystemProto.WifiSupplicantState.NAME, i);
7592 dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i),
7593 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007594 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007595 }
7596
7597 proto.end(sToken);
7598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599}