blob: 9513b9bfea039a3be98daec035293a2e0ff331bb [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)
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700228 */
Mike Ma15313c92017-11-15 17:58:21 -0800229 static final int CHECKIN_VERSION = 28;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700230
231 /**
232 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700234 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700235
Evan Millar22ac0432009-03-31 11:33:18 -0700236 private static final long BYTES_PER_KB = 1024;
237 private static final long BYTES_PER_MB = 1048576; // 1024^2
238 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700239
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700240 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800241 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700242 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700244 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700245 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700246 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
247 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700248 // rpm line is:
249 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
250 // screen-off time, screen-off count
251 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700252 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800253 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700254 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
255 // fgs line is:
256 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
257 // foreground service time, count
258 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700259 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700260 // wl line is:
261 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700262 // full totalTime, 'f', count, current duration, max duration, total duration,
263 // partial totalTime, 'p', count, current duration, max duration, total duration,
264 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
265 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700266 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700267 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700268 // awl line is:
269 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
270 // cumulative partial wakelock duration, cumulative background partial wakelock duration
271 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700272 private static final String SYNC_DATA = "sy";
273 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700274 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700275 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700276 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700277 private static final String NETWORK_DATA = "nt";
278 private static final String USER_ACTIVITY_DATA = "ua";
279 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800280 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700281 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700282 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700283 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800284 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
285 private static final String WIFI_CONTROLLER_DATA = "wfcd";
286 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
287 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700288 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700289 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800290 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800291 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
292 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800293 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700294 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700295 private static final String SCREEN_BRIGHTNESS_DATA = "br";
296 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700297 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700298 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
299 private static final String DATA_CONNECTION_TIME_DATA = "dct";
300 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800301 private static final String WIFI_STATE_TIME_DATA = "wst";
302 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700303 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
304 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
305 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
306 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800307 private static final String POWER_USE_SUMMARY_DATA = "pws";
308 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700309 private static final String DISCHARGE_STEP_DATA = "dsd";
310 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700311 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
312 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700313 private static final String FLASHLIGHT_DATA = "fla";
314 private static final String CAMERA_DATA = "cam";
315 private static final String VIDEO_DATA = "vid";
316 private static final String AUDIO_DATA = "aud";
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700317 private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct";
318 private static final String WIFI_MULTICAST_DATA = "wmc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319
Adam Lesinski010bf372016-04-11 12:18:18 -0700320 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
321
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700322 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 private final Formatter mFormatter = new Formatter(mFormatBuilder);
324
325 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700326 * Indicates times spent by the uid at each cpu frequency in all process states.
327 *
328 * Other types might include times spent in foreground, background etc.
329 */
330 private final String UID_TIMES_TYPE_ALL = "A";
331
332 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700333 * State for keeping track of counting information.
334 */
335 public static abstract class Counter {
336
337 /**
338 * Returns the count associated with this Counter for the
339 * selected type of statistics.
340 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700341 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700342 */
Evan Millarc64edde2009-04-18 12:26:32 -0700343 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700344
345 /**
346 * Temporary for debugging.
347 */
348 public abstract void logState(Printer pw, String prefix);
349 }
350
351 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700352 * State for keeping track of long counting information.
353 */
354 public static abstract class LongCounter {
355
356 /**
357 * Returns the count associated with this Counter for the
358 * selected type of statistics.
359 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700360 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700361 */
362 public abstract long getCountLocked(int which);
363
364 /**
365 * Temporary for debugging.
366 */
367 public abstract void logState(Printer pw, String prefix);
368 }
369
370 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700371 * State for keeping track of array of long counting information.
372 */
373 public static abstract class LongCounterArray {
374 /**
375 * Returns the counts associated with this Counter for the
376 * selected type of statistics.
377 *
378 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
379 */
380 public abstract long[] getCountsLocked(int which);
381
382 /**
383 * Temporary for debugging.
384 */
385 public abstract void logState(Printer pw, String prefix);
386 }
387
388 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800389 * Container class that aggregates counters for transmit, receive, and idle state of a
390 * radio controller.
391 */
392 public static abstract class ControllerActivityCounter {
393 /**
394 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
395 * idle state.
396 */
397 public abstract LongCounter getIdleTimeCounter();
398
399 /**
400 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
401 * receive state.
402 */
403 public abstract LongCounter getRxTimeCounter();
404
405 /**
406 * An array of {@link LongCounter}, representing various transmit levels, where each level
407 * may draw a different amount of power. The levels themselves are controller-specific.
408 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
409 * various transmit level states.
410 */
411 public abstract LongCounter[] getTxTimeCounters();
412
413 /**
414 * @return a non-null {@link LongCounter} representing the power consumed by the controller
415 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
416 * yield a value of 0 if the device doesn't support power calculations.
417 */
418 public abstract LongCounter getPowerCounter();
419 }
420
421 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 * State for keeping track of timing information.
423 */
424 public static abstract class Timer {
425
426 /**
427 * Returns the count associated with this Timer for the
428 * selected type of statistics.
429 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700430 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 */
Evan Millarc64edde2009-04-18 12:26:32 -0700432 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433
434 /**
435 * Returns the total time in microseconds associated with this Timer for the
436 * selected type of statistics.
437 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800438 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700439 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 * @return a time in microseconds
441 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800442 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700445 * Returns the total time in microseconds associated with this Timer since the
446 * 'mark' was last set.
447 *
448 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
449 * @return a time in microseconds
450 */
451 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
452
453 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700454 * Returns the max duration if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700455 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700456 */
457 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
458 return -1;
459 }
460
461 /**
462 * Returns the current time the timer has been active, if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700463 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700464 */
465 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
466 return -1;
467 }
468
469 /**
Kweku Adams103351f2017-10-16 14:39:34 -0700470 * Returns the total time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800471 *
472 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
473 * been on since reset.
474 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
475 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
476 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
477 * the actual total time.
Kweku Adams103351f2017-10-16 14:39:34 -0700478 * Not all Timer subclasses track the max, total, and current durations.
Bookatz867c0d72017-03-07 18:23:42 -0800479 */
480 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
481 return -1;
482 }
483
484 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700485 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
486 * used, for example, for tracking background usage. Secondary timers are never pooled.
487 *
488 * Not all Timer subclasses have a secondary timer; those that don't return null.
489 */
490 public Timer getSubTimer() {
491 return null;
492 }
493
494 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700495 * Returns whether the timer is currently running. Some types of timers
496 * (e.g. BatchTimers) don't know whether the event is currently active,
497 * and report false.
498 */
499 public boolean isRunningLocked() {
500 return false;
501 }
502
503 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 * Temporary for debugging.
505 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700506 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508
509 /**
510 * The statistics associated with a particular uid.
511 */
512 public static abstract class Uid {
513
514 /**
515 * Returns a mapping containing wakelock statistics.
516 *
517 * @return a Map from Strings to Uid.Wakelock objects.
518 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700519 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520
521 /**
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700522 * Returns the WiFi Multicast Wakelock statistics.
523 *
524 * @return a Timer Object for the per uid Multicast statistics.
525 */
526 public abstract Timer getMulticastWakelockStats();
527
528 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700529 * Returns a mapping containing sync statistics.
530 *
531 * @return a Map from Strings to Timer objects.
532 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700533 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700534
535 /**
536 * Returns a mapping containing scheduled job statistics.
537 *
538 * @return a Map from Strings to Timer objects.
539 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700540 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700541
542 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700543 * Returns statistics about how jobs have completed.
544 *
545 * @return A Map of String job names to completion type -> count mapping.
546 */
547 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
548
549 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 * The statistics associated with a particular wake lock.
551 */
552 public static abstract class Wakelock {
553 public abstract Timer getWakeTime(int type);
554 }
555
556 /**
Bookatzc8c44962017-05-11 12:12:54 -0700557 * The cumulative time the uid spent holding any partial wakelocks. This will generally
558 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
559 * wakelocks that overlap in time (and therefore over-counts).
560 */
561 public abstract Timer getAggregatedPartialWakelockTimer();
562
563 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 * Returns a mapping containing sensor statistics.
565 *
566 * @return a Map from Integer sensor ids to Uid.Sensor objects.
567 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700568 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569
570 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700571 * Returns a mapping containing active process data.
572 */
573 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700574
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700575 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 * Returns a mapping containing process statistics.
577 *
578 * @return a Map from Strings to Uid.Proc objects.
579 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700580 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581
582 /**
583 * Returns a mapping containing package statistics.
584 *
585 * @return a Map from Strings to Uid.Pkg objects.
586 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700587 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700588
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800589 public abstract ControllerActivityCounter getWifiControllerActivity();
590 public abstract ControllerActivityCounter getBluetoothControllerActivity();
591 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800592
593 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 * {@hide}
595 */
596 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700597
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800598 public abstract void noteWifiRunningLocked(long elapsedRealtime);
599 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
600 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
601 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
602 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
603 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
604 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
605 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
606 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
607 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800608 public abstract void noteActivityResumedLocked(long elapsedRealtime);
609 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800610 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
611 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
612 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700613 public abstract int getWifiScanCount(int which);
Kweku Adams103351f2017-10-16 14:39:34 -0700614 /**
615 * Returns the timer keeping track of wifi scans.
616 */
617 public abstract Timer getWifiScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800618 public abstract int getWifiScanBackgroundCount(int which);
619 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
620 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -0700621 /**
622 * Returns the timer keeping track of background wifi scans.
623 */
624 public abstract Timer getWifiScanBackgroundTimer();
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800625 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700626 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800627 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700628 public abstract Timer getAudioTurnedOnTimer();
629 public abstract Timer getVideoTurnedOnTimer();
630 public abstract Timer getFlashlightTurnedOnTimer();
631 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700632 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700633
634 /**
635 * Returns the timer keeping track of Foreground Service time
636 */
637 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800638 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800639 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700640 public abstract Timer getBluetoothUnoptimizedScanTimer();
641 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700642 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700643 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700644
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700645 public abstract long[] getCpuFreqTimes(int which);
646 public abstract long[] getScreenOffCpuFreqTimes(int which);
647
Dianne Hackborna0200e32016-03-30 18:01:41 -0700648 // Note: the following times are disjoint. They can be added together to find the
649 // total time a uid has had any processes running at all.
650
651 /**
652 * Time this uid has any processes in the top state (or above such as persistent).
653 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800654 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700655 /**
656 * Time this uid has any process with a started out bound foreground service, but
657 * none in the "top" state.
658 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800659 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700660 /**
Dianne Hackborna0200e32016-03-30 18:01:41 -0700661 * Time this uid has any process in an active foreground state, but none in the
662 * "top sleeping" or better state.
663 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800664 public static final int PROCESS_STATE_FOREGROUND = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700665 /**
666 * Time this uid has any process in an active background state, but none in the
667 * "foreground" or better state.
668 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800669 public static final int PROCESS_STATE_BACKGROUND = 3;
670 /**
671 * Time this uid has any process that is top while the device is sleeping, but not
672 * active for any other reason. We kind-of consider it a kind of cached process
673 * for execution restrictions.
674 */
675 public static final int PROCESS_STATE_TOP_SLEEPING = 4;
676 /**
677 * Time this uid has any process that is in the background but it has an activity
678 * marked as "can't save state". This is essentially a cached process, though the
679 * system will try much harder than normal to avoid killing it.
680 */
681 public static final int PROCESS_STATE_HEAVY_WEIGHT = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700682 /**
683 * Time this uid has any processes that are sitting around cached, not in one of the
684 * other active states.
685 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800686 public static final int PROCESS_STATE_CACHED = 6;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700687 /**
688 * Total number of process states we track.
689 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800690 public static final int NUM_PROCESS_STATE = 7;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700691
692 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800693 "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight",
694 "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700695 };
696
697 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800698 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700699
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800700 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701
Robert Greenwalta029ea12013-09-25 16:38:12 -0700702 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
703
Dianne Hackborn617f8772009-03-31 15:04:46 -0700704 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700705 * Note that these must match the constants in android.os.PowerManager.
706 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
707 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700708 */
709 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700710 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700711 };
Bookatzc8c44962017-05-11 12:12:54 -0700712
Phil Weaverda80d672016-03-15 16:25:46 -0700713 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700714
Dianne Hackborn617f8772009-03-31 15:04:46 -0700715 public abstract void noteUserActivityLocked(int type);
716 public abstract boolean hasUserActivity();
717 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700718
719 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800720 public abstract long getNetworkActivityBytes(int type, int which);
721 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800722 public abstract long getMobileRadioActiveTime(int which);
723 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700724
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700725 /**
726 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
727 */
728 public abstract long getUserCpuTimeUs(int which);
729
730 /**
731 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
732 */
733 public abstract long getSystemCpuTimeUs(int which);
734
735 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700736 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700737 * given CPU cluster.
738 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700739 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700740 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700741 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
742 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700743 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700744 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700745
Adam Lesinski5f056f62016-07-14 16:56:08 -0700746 /**
747 * Returns the number of times this UID woke up the Application Processor to
748 * process a mobile radio packet.
749 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
750 */
751 public abstract long getMobileRadioApWakeupCount(int which);
752
753 /**
754 * Returns the number of times this UID woke up the Application Processor to
755 * process a WiFi packet.
756 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
757 */
758 public abstract long getWifiRadioApWakeupCount(int which);
759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800761 /*
762 * FIXME: it's not correct to use this magic value because it
763 * could clash with a sensor handle (which are defined by
764 * the sensor HAL, and therefore out of our control
765 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 // Magic sensor number for the GPS.
767 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800772
Bookatz867c0d72017-03-07 18:23:42 -0800773 /** Returns a Timer for sensor usage when app is in the background. */
774 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
776
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700777 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800778 public int mWakeNesting;
779 public long mWakeSumMs;
780 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700781 }
782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 /**
784 * The statistics associated with a particular process.
785 */
786 public static abstract class Proc {
787
Dianne Hackborn287952c2010-09-22 22:34:31 -0700788 public static class ExcessivePower {
789 public static final int TYPE_WAKE = 1;
790 public static final int TYPE_CPU = 2;
791
792 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700793 public long overTime;
794 public long usedTime;
795 }
796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800798 * Returns true if this process is still active in the battery stats.
799 */
800 public abstract boolean isActive();
801
802 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700803 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700805 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 */
807 public abstract long getUserTime(int which);
808
809 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700810 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700812 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 */
814 public abstract long getSystemTime(int which);
815
816 /**
817 * Returns the number of times the process has been started.
818 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700819 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 */
821 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700822
823 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800824 * Returns the number of times the process has crashed.
825 *
826 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
827 */
828 public abstract int getNumCrashes(int which);
829
830 /**
831 * Returns the number of times the process has ANRed.
832 *
833 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
834 */
835 public abstract int getNumAnrs(int which);
836
837 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700838 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700839 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700840 * @return foreground cpu time in microseconds
841 */
842 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700843
Dianne Hackborn287952c2010-09-22 22:34:31 -0700844 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700845
Dianne Hackborn287952c2010-09-22 22:34:31 -0700846 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
848
849 /**
850 * The statistics associated with a particular package.
851 */
852 public static abstract class Pkg {
853
854 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700855 * Returns information about all wakeup alarms that have been triggered for this
856 * package. The mapping keys are tag names for the alarms, the counter contains
857 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700859 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860
861 /**
862 * Returns a mapping containing service statistics.
863 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700864 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865
866 /**
867 * The statistics associated with a particular service.
868 */
Joe Onoratoabded112016-02-08 16:49:39 -0800869 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870
871 /**
872 * Returns the amount of time spent started.
873 *
874 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700875 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 * @return
877 */
878 public abstract long getStartTime(long batteryUptime, int which);
879
880 /**
881 * Returns the total number of times startService() has been called.
882 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700883 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 */
885 public abstract int getStarts(int which);
886
887 /**
888 * Returns the total number times the service has been launched.
889 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700890 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 */
892 public abstract int getLaunches(int which);
893 }
894 }
895 }
896
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800897 public static final class LevelStepTracker {
898 public long mLastStepTime = -1;
899 public int mNumStepDurations;
900 public final long[] mStepDurations;
901
902 public LevelStepTracker(int maxLevelSteps) {
903 mStepDurations = new long[maxLevelSteps];
904 }
905
906 public LevelStepTracker(int numSteps, long[] steps) {
907 mNumStepDurations = numSteps;
908 mStepDurations = new long[numSteps];
909 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
910 }
911
912 public long getDurationAt(int index) {
913 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
914 }
915
916 public int getLevelAt(int index) {
917 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
918 >> STEP_LEVEL_LEVEL_SHIFT);
919 }
920
921 public int getInitModeAt(int index) {
922 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
923 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
924 }
925
926 public int getModModeAt(int index) {
927 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
928 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
929 }
930
931 private void appendHex(long val, int topOffset, StringBuilder out) {
932 boolean hasData = false;
933 while (topOffset >= 0) {
934 int digit = (int)( (val>>topOffset) & 0xf );
935 topOffset -= 4;
936 if (!hasData && digit == 0) {
937 continue;
938 }
939 hasData = true;
940 if (digit >= 0 && digit <= 9) {
941 out.append((char)('0' + digit));
942 } else {
943 out.append((char)('a' + digit - 10));
944 }
945 }
946 }
947
948 public void encodeEntryAt(int index, StringBuilder out) {
949 long item = mStepDurations[index];
950 long duration = item & STEP_LEVEL_TIME_MASK;
951 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
952 >> STEP_LEVEL_LEVEL_SHIFT);
953 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
954 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
955 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
956 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
957 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
958 case Display.STATE_OFF: out.append('f'); break;
959 case Display.STATE_ON: out.append('o'); break;
960 case Display.STATE_DOZE: out.append('d'); break;
961 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
962 }
963 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
964 out.append('p');
965 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700966 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
967 out.append('i');
968 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800969 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
970 case Display.STATE_OFF: out.append('F'); break;
971 case Display.STATE_ON: out.append('O'); break;
972 case Display.STATE_DOZE: out.append('D'); break;
973 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
974 }
975 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
976 out.append('P');
977 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700978 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
979 out.append('I');
980 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800981 out.append('-');
982 appendHex(level, 4, out);
983 out.append('-');
984 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
985 }
986
987 public void decodeEntryAt(int index, String value) {
988 final int N = value.length();
989 int i = 0;
990 char c;
991 long out = 0;
992 while (i < N && (c=value.charAt(i)) != '-') {
993 i++;
994 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800995 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800996 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800997 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800998 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800999 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001000 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001001 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1002 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1003 break;
1004 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1005 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1006 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001007 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1008 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1009 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001010 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1011 break;
1012 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1013 break;
1014 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1015 break;
1016 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1017 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1018 break;
1019 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1020 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001021 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001022 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1023 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1024 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001025 }
1026 }
1027 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001028 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001029 while (i < N && (c=value.charAt(i)) != '-') {
1030 i++;
1031 level <<= 4;
1032 if (c >= '0' && c <= '9') {
1033 level += c - '0';
1034 } else if (c >= 'a' && c <= 'f') {
1035 level += c - 'a' + 10;
1036 } else if (c >= 'A' && c <= 'F') {
1037 level += c - 'A' + 10;
1038 }
1039 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001040 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001041 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1042 long duration = 0;
1043 while (i < N && (c=value.charAt(i)) != '-') {
1044 i++;
1045 duration <<= 4;
1046 if (c >= '0' && c <= '9') {
1047 duration += c - '0';
1048 } else if (c >= 'a' && c <= 'f') {
1049 duration += c - 'a' + 10;
1050 } else if (c >= 'A' && c <= 'F') {
1051 duration += c - 'A' + 10;
1052 }
1053 }
1054 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1055 }
1056
1057 public void init() {
1058 mLastStepTime = -1;
1059 mNumStepDurations = 0;
1060 }
1061
1062 public void clearTime() {
1063 mLastStepTime = -1;
1064 }
1065
1066 public long computeTimePerLevel() {
1067 final long[] steps = mStepDurations;
1068 final int numSteps = mNumStepDurations;
1069
1070 // For now we'll do a simple average across all steps.
1071 if (numSteps <= 0) {
1072 return -1;
1073 }
1074 long total = 0;
1075 for (int i=0; i<numSteps; i++) {
1076 total += steps[i] & STEP_LEVEL_TIME_MASK;
1077 }
1078 return total / numSteps;
1079 /*
1080 long[] buckets = new long[numSteps];
1081 int numBuckets = 0;
1082 int numToAverage = 4;
1083 int i = 0;
1084 while (i < numSteps) {
1085 long totalTime = 0;
1086 int num = 0;
1087 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1088 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1089 num++;
1090 }
1091 buckets[numBuckets] = totalTime / num;
1092 numBuckets++;
1093 numToAverage *= 2;
1094 i += num;
1095 }
1096 if (numBuckets < 1) {
1097 return -1;
1098 }
1099 long averageTime = buckets[numBuckets-1];
1100 for (i=numBuckets-2; i>=0; i--) {
1101 averageTime = (averageTime + buckets[i]) / 2;
1102 }
1103 return averageTime;
1104 */
1105 }
1106
1107 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1108 int[] outNumOfInterest) {
1109 final long[] steps = mStepDurations;
1110 final int count = mNumStepDurations;
1111 if (count <= 0) {
1112 return -1;
1113 }
1114 long total = 0;
1115 int numOfInterest = 0;
1116 for (int i=0; i<count; i++) {
1117 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1118 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1119 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1120 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1121 // If the modes of interest didn't change during this step period...
1122 if ((modMode&modesOfInterest) == 0) {
1123 // And the mode values during this period match those we are measuring...
1124 if ((initMode&modesOfInterest) == modeValues) {
1125 // Then this can be used to estimate the total time!
1126 numOfInterest++;
1127 total += steps[i] & STEP_LEVEL_TIME_MASK;
1128 }
1129 }
1130 }
1131 if (numOfInterest <= 0) {
1132 return -1;
1133 }
1134
1135 if (outNumOfInterest != null) {
1136 outNumOfInterest[0] = numOfInterest;
1137 }
1138
1139 // The estimated time is the average time we spend in each level, multipled
1140 // by 100 -- the total number of battery levels
1141 return (total / numOfInterest) * 100;
1142 }
1143
1144 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1145 int stepCount = mNumStepDurations;
1146 final long lastStepTime = mLastStepTime;
1147 if (lastStepTime >= 0 && numStepLevels > 0) {
1148 final long[] steps = mStepDurations;
1149 long duration = elapsedRealtime - lastStepTime;
1150 for (int i=0; i<numStepLevels; i++) {
1151 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1152 long thisDuration = duration / (numStepLevels-i);
1153 duration -= thisDuration;
1154 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1155 thisDuration = STEP_LEVEL_TIME_MASK;
1156 }
1157 steps[0] = thisDuration | modeBits;
1158 }
1159 stepCount += numStepLevels;
1160 if (stepCount > steps.length) {
1161 stepCount = steps.length;
1162 }
1163 }
1164 mNumStepDurations = stepCount;
1165 mLastStepTime = elapsedRealtime;
1166 }
1167
1168 public void readFromParcel(Parcel in) {
1169 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001170 if (N > mStepDurations.length) {
1171 throw new ParcelFormatException("more step durations than available: " + N);
1172 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001173 mNumStepDurations = N;
1174 for (int i=0; i<N; i++) {
1175 mStepDurations[i] = in.readLong();
1176 }
1177 }
1178
1179 public void writeToParcel(Parcel out) {
1180 final int N = mNumStepDurations;
1181 out.writeInt(N);
1182 for (int i=0; i<N; i++) {
1183 out.writeLong(mStepDurations[i]);
1184 }
1185 }
1186 }
1187
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001188 public static final class PackageChange {
1189 public String mPackageName;
1190 public boolean mUpdate;
Dianne Hackborn3accca02013-09-20 09:32:11 -07001191 public long mVersionCode;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001192 }
1193
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001194 public static final class DailyItem {
1195 public long mStartTime;
1196 public long mEndTime;
1197 public LevelStepTracker mDischargeSteps;
1198 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001199 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001200 }
1201
1202 public abstract DailyItem getDailyItemLocked(int daysAgo);
1203
1204 public abstract long getCurrentDailyStartTime();
1205
1206 public abstract long getNextMinDailyDeadline();
1207
1208 public abstract long getNextMaxDailyDeadline();
1209
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001210 public abstract long[] getCpuFreqs();
1211
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001212 public final static class HistoryTag {
1213 public String string;
1214 public int uid;
1215
1216 public int poolIdx;
1217
1218 public void setTo(HistoryTag o) {
1219 string = o.string;
1220 uid = o.uid;
1221 poolIdx = o.poolIdx;
1222 }
1223
1224 public void setTo(String _string, int _uid) {
1225 string = _string;
1226 uid = _uid;
1227 poolIdx = -1;
1228 }
1229
1230 public void writeToParcel(Parcel dest, int flags) {
1231 dest.writeString(string);
1232 dest.writeInt(uid);
1233 }
1234
1235 public void readFromParcel(Parcel src) {
1236 string = src.readString();
1237 uid = src.readInt();
1238 poolIdx = -1;
1239 }
1240
1241 @Override
1242 public boolean equals(Object o) {
1243 if (this == o) return true;
1244 if (o == null || getClass() != o.getClass()) return false;
1245
1246 HistoryTag that = (HistoryTag) o;
1247
1248 if (uid != that.uid) return false;
1249 if (!string.equals(that.string)) return false;
1250
1251 return true;
1252 }
1253
1254 @Override
1255 public int hashCode() {
1256 int result = string.hashCode();
1257 result = 31 * result + uid;
1258 return result;
1259 }
1260 }
1261
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001262 /**
1263 * Optional detailed information that can go into a history step. This is typically
1264 * generated each time the battery level changes.
1265 */
1266 public final static class HistoryStepDetails {
1267 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1268 public int userTime;
1269 public int systemTime;
1270
1271 // Top three apps using CPU in the last step, with times in 1/100 second.
1272 public int appCpuUid1;
1273 public int appCpuUTime1;
1274 public int appCpuSTime1;
1275 public int appCpuUid2;
1276 public int appCpuUTime2;
1277 public int appCpuSTime2;
1278 public int appCpuUid3;
1279 public int appCpuUTime3;
1280 public int appCpuSTime3;
1281
1282 // Information from /proc/stat
1283 public int statUserTime;
1284 public int statSystemTime;
1285 public int statIOWaitTime;
1286 public int statIrqTime;
1287 public int statSoftIrqTime;
1288 public int statIdlTime;
1289
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001290 // Platform-level low power state stats
1291 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001292 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001293
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001294 public HistoryStepDetails() {
1295 clear();
1296 }
1297
1298 public void clear() {
1299 userTime = systemTime = 0;
1300 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1301 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1302 = appCpuUTime3 = appCpuSTime3 = 0;
1303 }
1304
1305 public void writeToParcel(Parcel out) {
1306 out.writeInt(userTime);
1307 out.writeInt(systemTime);
1308 out.writeInt(appCpuUid1);
1309 out.writeInt(appCpuUTime1);
1310 out.writeInt(appCpuSTime1);
1311 out.writeInt(appCpuUid2);
1312 out.writeInt(appCpuUTime2);
1313 out.writeInt(appCpuSTime2);
1314 out.writeInt(appCpuUid3);
1315 out.writeInt(appCpuUTime3);
1316 out.writeInt(appCpuSTime3);
1317 out.writeInt(statUserTime);
1318 out.writeInt(statSystemTime);
1319 out.writeInt(statIOWaitTime);
1320 out.writeInt(statIrqTime);
1321 out.writeInt(statSoftIrqTime);
1322 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001323 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001324 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001325 }
1326
1327 public void readFromParcel(Parcel in) {
1328 userTime = in.readInt();
1329 systemTime = in.readInt();
1330 appCpuUid1 = in.readInt();
1331 appCpuUTime1 = in.readInt();
1332 appCpuSTime1 = in.readInt();
1333 appCpuUid2 = in.readInt();
1334 appCpuUTime2 = in.readInt();
1335 appCpuSTime2 = in.readInt();
1336 appCpuUid3 = in.readInt();
1337 appCpuUTime3 = in.readInt();
1338 appCpuSTime3 = in.readInt();
1339 statUserTime = in.readInt();
1340 statSystemTime = in.readInt();
1341 statIOWaitTime = in.readInt();
1342 statIrqTime = in.readInt();
1343 statSoftIrqTime = in.readInt();
1344 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001345 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001346 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001347 }
1348 }
1349
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001350 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001351 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001352
1353 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001354 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001355
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001356 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001357 public static final byte CMD_NULL = -1;
1358 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001359 public static final byte CMD_CURRENT_TIME = 5;
1360 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001361 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001362 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001363
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001364 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001365
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001366 /**
1367 * Return whether the command code is a delta data update.
1368 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001369 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001370 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001371 }
1372
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001373 public byte batteryLevel;
1374 public byte batteryStatus;
1375 public byte batteryHealth;
1376 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001377
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001378 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001379 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001380
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001381 // The charge of the battery in micro-Ampere-hours.
1382 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001383
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001384 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001385 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001386 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001387 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001388 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1389 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001390 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001391 public static final int STATE_PHONE_STATE_SHIFT = 6;
1392 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001393 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001394 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001395 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001396
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001397 // These states always appear directly in the first int token
1398 // of a delta change; they should be ones that change relatively
1399 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001400 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1401 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001402 public static final int STATE_GPS_ON_FLAG = 1<<29;
1403 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001404 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001405 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001406 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001407 // Do not use, this is used for coulomb delta count.
1408 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001409 // These are on the lower bits used for the command; if they change
1410 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001411 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001412 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001413 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001414 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1415 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001416 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001417 // empty slot
1418 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001419
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001420 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001421 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001422
1423 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001424
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001425 public int states;
1426
Dianne Hackborn3251b902014-06-20 14:40:53 -07001427 // Constants from WIFI_SUPPL_STATE_*
1428 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1429 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1430 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1431 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1432 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1433 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1434
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001435 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001436 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1437 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1438 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001439 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001440 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1441 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1442 public static final int STATE2_CHARGING_FLAG = 1<<24;
1443 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1444 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1445 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001446 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001447
1448 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001449 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1450 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001451
1452 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001453
Dianne Hackborn40c87252014-03-19 16:55:40 -07001454 public int states2;
1455
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001456 // The wake lock that was acquired at this point.
1457 public HistoryTag wakelockTag;
1458
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001459 // Kernel wakeup reason at this point.
1460 public HistoryTag wakeReasonTag;
1461
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001462 // Non-null when there is more detailed information at this step.
1463 public HistoryStepDetails stepDetails;
1464
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001465 public static final int EVENT_FLAG_START = 0x8000;
1466 public static final int EVENT_FLAG_FINISH = 0x4000;
1467
1468 // No event in this item.
1469 public static final int EVENT_NONE = 0x0000;
1470 // Event is about a process that is running.
1471 public static final int EVENT_PROC = 0x0001;
1472 // Event is about an application package that is in the foreground.
1473 public static final int EVENT_FOREGROUND = 0x0002;
1474 // Event is about an application package that is at the top of the screen.
1475 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001476 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001477 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001478 // Events for all additional wake locks aquired/release within a wake block.
1479 // These are not generated by default.
1480 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001481 // Event is about an application executing a scheduled job.
1482 public static final int EVENT_JOB = 0x0006;
1483 // Events for users running.
1484 public static final int EVENT_USER_RUNNING = 0x0007;
1485 // Events for foreground user.
1486 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001487 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001488 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001489 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001490 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001491 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001492 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001493 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001494 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001495 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001496 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001497 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001498 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001499 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001500 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001501 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001502 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001503 // Event for a package being on the temporary whitelist.
1504 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001505 // Event for the screen waking up.
1506 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001507 // Event for the UID that woke up the application processor.
1508 // Used for wakeups coming from WiFi, modem, etc.
1509 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001510 // Event for reporting that a specific partial wake lock has been held for a long duration.
1511 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001512
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001513 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001514 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001515 // Mask to extract out only the type part of the event.
1516 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001517
1518 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1519 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1520 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1521 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1522 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1523 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001524 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1525 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001526 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1527 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001528 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1529 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1530 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1531 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1532 public static final int EVENT_USER_FOREGROUND_START =
1533 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1534 public static final int EVENT_USER_FOREGROUND_FINISH =
1535 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001536 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1537 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001538 public static final int EVENT_TEMP_WHITELIST_START =
1539 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1540 public static final int EVENT_TEMP_WHITELIST_FINISH =
1541 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001542 public static final int EVENT_LONG_WAKE_LOCK_START =
1543 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1544 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1545 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001546
1547 // For CMD_EVENT.
1548 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001549 public HistoryTag eventTag;
1550
Dianne Hackborn9a755432014-05-15 17:05:22 -07001551 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001552 public long currentTime;
1553
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001554 // Meta-data when reading.
1555 public int numReadInts;
1556
1557 // Pre-allocated objects.
1558 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001559 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001560 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001561
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001562 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001563 }
Bookatzc8c44962017-05-11 12:12:54 -07001564
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001565 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001566 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001567 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001568 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001569 }
Bookatzc8c44962017-05-11 12:12:54 -07001570
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001571 public int describeContents() {
1572 return 0;
1573 }
1574
1575 public void writeToParcel(Parcel dest, int flags) {
1576 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001577 int bat = (((int)cmd)&0xff)
1578 | ((((int)batteryLevel)<<8)&0xff00)
1579 | ((((int)batteryStatus)<<16)&0xf0000)
1580 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001581 | ((((int)batteryPlugType)<<24)&0xf000000)
1582 | (wakelockTag != null ? 0x10000000 : 0)
1583 | (wakeReasonTag != null ? 0x20000000 : 0)
1584 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001585 dest.writeInt(bat);
1586 bat = (((int)batteryTemperature)&0xffff)
1587 | ((((int)batteryVoltage)<<16)&0xffff0000);
1588 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001589 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001590 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001591 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001592 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001593 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001594 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001595 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001596 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001597 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001598 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001599 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001600 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001601 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001602 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001603 dest.writeLong(currentTime);
1604 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001605 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001606
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001607 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001608 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001609 int bat = src.readInt();
1610 cmd = (byte)(bat&0xff);
1611 batteryLevel = (byte)((bat>>8)&0xff);
1612 batteryStatus = (byte)((bat>>16)&0xf);
1613 batteryHealth = (byte)((bat>>20)&0xf);
1614 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001615 int bat2 = src.readInt();
1616 batteryTemperature = (short)(bat2&0xffff);
1617 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001618 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001619 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001620 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001621 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001622 wakelockTag = localWakelockTag;
1623 wakelockTag.readFromParcel(src);
1624 } else {
1625 wakelockTag = null;
1626 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001627 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001628 wakeReasonTag = localWakeReasonTag;
1629 wakeReasonTag.readFromParcel(src);
1630 } else {
1631 wakeReasonTag = null;
1632 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001633 if ((bat&0x40000000) != 0) {
1634 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001635 eventTag = localEventTag;
1636 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001637 } else {
1638 eventCode = EVENT_NONE;
1639 eventTag = null;
1640 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001641 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001642 currentTime = src.readLong();
1643 } else {
1644 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001645 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001646 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001647 }
1648
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001649 public void clear() {
1650 time = 0;
1651 cmd = CMD_NULL;
1652 batteryLevel = 0;
1653 batteryStatus = 0;
1654 batteryHealth = 0;
1655 batteryPlugType = 0;
1656 batteryTemperature = 0;
1657 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001658 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001659 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001660 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001661 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001662 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001663 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001664 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001665 }
Bookatzc8c44962017-05-11 12:12:54 -07001666
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001667 public void setTo(HistoryItem o) {
1668 time = o.time;
1669 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001670 setToCommon(o);
1671 }
1672
1673 public void setTo(long time, byte cmd, HistoryItem o) {
1674 this.time = time;
1675 this.cmd = cmd;
1676 setToCommon(o);
1677 }
1678
1679 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001680 batteryLevel = o.batteryLevel;
1681 batteryStatus = o.batteryStatus;
1682 batteryHealth = o.batteryHealth;
1683 batteryPlugType = o.batteryPlugType;
1684 batteryTemperature = o.batteryTemperature;
1685 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001686 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001687 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001688 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001689 if (o.wakelockTag != null) {
1690 wakelockTag = localWakelockTag;
1691 wakelockTag.setTo(o.wakelockTag);
1692 } else {
1693 wakelockTag = null;
1694 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001695 if (o.wakeReasonTag != null) {
1696 wakeReasonTag = localWakeReasonTag;
1697 wakeReasonTag.setTo(o.wakeReasonTag);
1698 } else {
1699 wakeReasonTag = null;
1700 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001701 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001702 if (o.eventTag != null) {
1703 eventTag = localEventTag;
1704 eventTag.setTo(o.eventTag);
1705 } else {
1706 eventTag = null;
1707 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001708 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001709 }
1710
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001711 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001712 return batteryLevel == o.batteryLevel
1713 && batteryStatus == o.batteryStatus
1714 && batteryHealth == o.batteryHealth
1715 && batteryPlugType == o.batteryPlugType
1716 && batteryTemperature == o.batteryTemperature
1717 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001718 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001719 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001720 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001721 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001722 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001723
1724 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001725 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001726 return false;
1727 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001728 if (wakelockTag != o.wakelockTag) {
1729 if (wakelockTag == null || o.wakelockTag == null) {
1730 return false;
1731 }
1732 if (!wakelockTag.equals(o.wakelockTag)) {
1733 return false;
1734 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001735 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001736 if (wakeReasonTag != o.wakeReasonTag) {
1737 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1738 return false;
1739 }
1740 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1741 return false;
1742 }
1743 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001744 if (eventTag != o.eventTag) {
1745 if (eventTag == null || o.eventTag == null) {
1746 return false;
1747 }
1748 if (!eventTag.equals(o.eventTag)) {
1749 return false;
1750 }
1751 }
1752 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001753 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001754 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001755
1756 public final static class HistoryEventTracker {
1757 private final HashMap<String, SparseIntArray>[] mActiveEvents
1758 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1759
1760 public boolean updateState(int code, String name, int uid, int poolIdx) {
1761 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1762 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1763 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1764 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001765 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001766 mActiveEvents[idx] = active;
1767 }
1768 SparseIntArray uids = active.get(name);
1769 if (uids == null) {
1770 uids = new SparseIntArray();
1771 active.put(name, uids);
1772 }
1773 if (uids.indexOfKey(uid) >= 0) {
1774 // Already set, nothing to do!
1775 return false;
1776 }
1777 uids.put(uid, poolIdx);
1778 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1779 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1780 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1781 if (active == null) {
1782 // not currently active, nothing to do.
1783 return false;
1784 }
1785 SparseIntArray uids = active.get(name);
1786 if (uids == null) {
1787 // not currently active, nothing to do.
1788 return false;
1789 }
1790 idx = uids.indexOfKey(uid);
1791 if (idx < 0) {
1792 // not currently active, nothing to do.
1793 return false;
1794 }
1795 uids.removeAt(idx);
1796 if (uids.size() <= 0) {
1797 active.remove(name);
1798 }
1799 }
1800 return true;
1801 }
1802
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001803 public void removeEvents(int code) {
1804 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1805 mActiveEvents[idx] = null;
1806 }
1807
Dianne Hackborn37de0982014-05-09 09:32:18 -07001808 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1809 return mActiveEvents[code];
1810 }
1811 }
1812
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001813 public static final class BitDescription {
1814 public final int mask;
1815 public final int shift;
1816 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001817 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001818 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001819 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001820
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001821 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001822 this.mask = mask;
1823 this.shift = -1;
1824 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001825 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001826 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001827 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001828 }
Bookatzc8c44962017-05-11 12:12:54 -07001829
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001830 public BitDescription(int mask, int shift, String name, String shortName,
1831 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001832 this.mask = mask;
1833 this.shift = shift;
1834 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001835 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001836 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001837 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001838 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001839 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001840
Dianne Hackbornfc064132014-06-02 12:42:12 -07001841 /**
1842 * Don't allow any more batching in to the current history event. This
1843 * is called when printing partial histories, so to ensure that the next
1844 * history event will go in to a new batch after what was printed in the
1845 * last partial history.
1846 */
1847 public abstract void commitCurrentHistoryBatchLocked();
1848
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001849 public abstract int getHistoryTotalSize();
1850
1851 public abstract int getHistoryUsedSize();
1852
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001853 public abstract boolean startIteratingHistoryLocked();
1854
Dianne Hackborn099bc622014-01-22 13:39:16 -08001855 public abstract int getHistoryStringPoolSize();
1856
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001857 public abstract int getHistoryStringPoolBytes();
1858
1859 public abstract String getHistoryTagPoolString(int index);
1860
1861 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001862
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001863 public abstract boolean getNextHistoryLocked(HistoryItem out);
1864
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001865 public abstract void finishIteratingHistoryLocked();
1866
1867 public abstract boolean startIteratingOldHistoryLocked();
1868
1869 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1870
1871 public abstract void finishIteratingOldHistoryLocked();
1872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001873 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001874 * Return the base time offset for the battery history.
1875 */
1876 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001877
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001878 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 * Returns the number of times the device has been started.
1880 */
1881 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001884 * 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 -08001885 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001886 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 * {@hide}
1888 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001889 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001890
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001891 /**
1892 * Returns the number of times the screen was turned on.
1893 *
1894 * {@hide}
1895 */
1896 public abstract int getScreenOnCount(int which);
1897
Mike Mac2f518a2017-09-19 16:06:03 -07001898 /**
1899 * Returns the time in microseconds that the screen has been dozing while the device was
1900 * running on battery.
1901 *
1902 * {@hide}
1903 */
1904 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
1905
1906 /**
1907 * Returns the number of times the screen was turned dozing.
1908 *
1909 * {@hide}
1910 */
1911 public abstract int getScreenDozeCount(int which);
1912
Jeff Browne95c3cd2014-05-02 16:59:26 -07001913 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1914
Dianne Hackborn617f8772009-03-31 15:04:46 -07001915 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1916 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1917 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1918 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1919 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001920
Dianne Hackborn617f8772009-03-31 15:04:46 -07001921 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1922 "dark", "dim", "medium", "light", "bright"
1923 };
Bookatzc8c44962017-05-11 12:12:54 -07001924
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001925 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1926 "0", "1", "2", "3", "4"
1927 };
1928
Dianne Hackborn617f8772009-03-31 15:04:46 -07001929 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001930
Dianne Hackborn617f8772009-03-31 15:04:46 -07001931 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001932 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001933 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001934 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001935 * {@hide}
1936 */
1937 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001938 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07001941 * Returns the {@link Timer} object that tracks the given screen brightness.
1942 *
1943 * {@hide}
1944 */
1945 public abstract Timer getScreenBrightnessTimer(int brightnessBin);
1946
1947 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001948 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001949 * running on battery.
1950 *
1951 * {@hide}
1952 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001953 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001954
1955 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001956 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001957 *
1958 * {@hide}
1959 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001960 public abstract int getPowerSaveModeEnabledCount(int which);
1961
1962 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001963 * Constant for device idle mode: not active.
1964 */
1965 public static final int DEVICE_IDLE_MODE_OFF = 0;
1966
1967 /**
1968 * Constant for device idle mode: active in lightweight mode.
1969 */
1970 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1971
1972 /**
1973 * Constant for device idle mode: active in full mode.
1974 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001975 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001976
1977 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001978 * Returns the time in microseconds that device has been in idle mode while
1979 * running on battery.
1980 *
1981 * {@hide}
1982 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001983 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001984
1985 /**
1986 * Returns the number of times that the devie has gone in to idle mode.
1987 *
1988 * {@hide}
1989 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001990 public abstract int getDeviceIdleModeCount(int mode, int which);
1991
1992 /**
1993 * Return the longest duration we spent in a particular device idle mode (fully in the
1994 * mode, not in idle maintenance etc).
1995 */
1996 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001997
1998 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001999 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002000 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002001 * counts all of the time that we consider the device to be idle, whether or not
2002 * it is currently in the actual device idle mode.
2003 *
2004 * {@hide}
2005 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002006 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002007
2008 /**
Bookatz8c6571b2017-10-24 15:04:41 -07002009 * Returns the number of times that the device has started idling.
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002010 *
2011 * {@hide}
2012 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002013 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002014
2015 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002016 * Returns the number of times that connectivity state changed.
2017 *
2018 * {@hide}
2019 */
2020 public abstract int getNumConnectivityChange(int which);
2021
2022 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002023 * 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 -08002024 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002025 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 * {@hide}
2027 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002028 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002029
Dianne Hackborn627bba72009-03-24 22:32:56 -07002030 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002031 * Returns the number of times a phone call was activated.
2032 *
2033 * {@hide}
2034 */
2035 public abstract int getPhoneOnCount(int which);
2036
2037 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002038 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002039 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002040 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002041 * {@hide}
2042 */
2043 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002044 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002045
Dianne Hackborn617f8772009-03-31 15:04:46 -07002046 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002047 * Returns the time in microseconds that the phone has been trying to
2048 * acquire a signal.
2049 *
2050 * {@hide}
2051 */
2052 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002053 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002054
2055 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002056 * Returns the {@link Timer} object that tracks how much the phone has been trying to
2057 * acquire a signal.
2058 *
2059 * {@hide}
2060 */
2061 public abstract Timer getPhoneSignalScanningTimer();
2062
2063 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002064 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002065 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002066 * {@hide}
2067 */
2068 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2069
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002070 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002071 * Return the {@link Timer} object used to track the given signal strength's duration and
2072 * counts.
2073 */
2074 protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin);
2075
2076 /**
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002077 * Returns the time in microseconds that the mobile network has been active
2078 * (in a high power state).
2079 *
2080 * {@hide}
2081 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002082 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002083
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002084 /**
2085 * Returns the number of times that the mobile network has transitioned to the
2086 * active state.
2087 *
2088 * {@hide}
2089 */
2090 public abstract int getMobileRadioActiveCount(int which);
2091
2092 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002093 * Returns the time in microseconds that is the difference between the mobile radio
2094 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2095 * from the radio.
2096 *
2097 * {@hide}
2098 */
2099 public abstract long getMobileRadioActiveAdjustedTime(int which);
2100
2101 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002102 * Returns the time in microseconds that the mobile network has been active
2103 * (in a high power state) but not being able to blame on an app.
2104 *
2105 * {@hide}
2106 */
2107 public abstract long getMobileRadioActiveUnknownTime(int which);
2108
2109 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002110 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002111 *
2112 * {@hide}
2113 */
2114 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002115
Dianne Hackborn627bba72009-03-24 22:32:56 -07002116 public static final int DATA_CONNECTION_NONE = 0;
2117 public static final int DATA_CONNECTION_GPRS = 1;
2118 public static final int DATA_CONNECTION_EDGE = 2;
2119 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002120 public static final int DATA_CONNECTION_CDMA = 4;
2121 public static final int DATA_CONNECTION_EVDO_0 = 5;
2122 public static final int DATA_CONNECTION_EVDO_A = 6;
2123 public static final int DATA_CONNECTION_1xRTT = 7;
2124 public static final int DATA_CONNECTION_HSDPA = 8;
2125 public static final int DATA_CONNECTION_HSUPA = 9;
2126 public static final int DATA_CONNECTION_HSPA = 10;
2127 public static final int DATA_CONNECTION_IDEN = 11;
2128 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002129 public static final int DATA_CONNECTION_LTE = 13;
2130 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002131 public static final int DATA_CONNECTION_HSPAP = 15;
2132 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002133
Dianne Hackborn627bba72009-03-24 22:32:56 -07002134 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002135 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002136 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002137 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002138 };
Bookatzc8c44962017-05-11 12:12:54 -07002139
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002140 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002141
Dianne Hackborn627bba72009-03-24 22:32:56 -07002142 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002143 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002144 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002145 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002146 * {@hide}
2147 */
2148 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002149 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002152 * Returns the number of times the phone has entered the given data
2153 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002154 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002155 * {@hide}
2156 */
2157 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002158
Kweku Adams87b19ec2017-10-09 12:40:03 -07002159 /**
2160 * Returns the {@link Timer} object that tracks the phone's data connection type stats.
2161 */
2162 public abstract Timer getPhoneDataConnectionTimer(int dataType);
2163
Dianne Hackborn3251b902014-06-20 14:40:53 -07002164 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2165 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2166 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2167 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2168 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2169 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2170 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2171 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2172 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2173 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2174 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2175 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2176 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2177
2178 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2179
2180 static final String[] WIFI_SUPPL_STATE_NAMES = {
2181 "invalid", "disconn", "disabled", "inactive", "scanning",
2182 "authenticating", "associating", "associated", "4-way-handshake",
2183 "group-handshake", "completed", "dormant", "uninit"
2184 };
2185
2186 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2187 "inv", "dsc", "dis", "inact", "scan",
2188 "auth", "ascing", "asced", "4-way",
2189 "group", "compl", "dorm", "uninit"
2190 };
2191
Mike Mac2f518a2017-09-19 16:06:03 -07002192 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002193 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002194 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2195 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002196 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002197 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2198 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2199 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002200 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002201 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002202 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002203 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002204 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2205 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002206 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002207 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2208 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2209 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2210 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2211 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2212 new String[] {"in", "out", "emergency", "off"},
2213 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002214 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2215 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2216 SignalStrength.SIGNAL_STRENGTH_NAMES,
2217 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002218 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2219 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2220 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002221 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002222
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002223 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2224 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002225 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002226 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002227 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002228 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002229 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002230 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2231 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2232 new String[] { "off", "light", "full", "???" },
2233 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002234 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2235 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2236 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002237 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2238 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2239 new String[] { "0", "1", "2", "3", "4" },
2240 new String[] { "0", "1", "2", "3", "4" }),
2241 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2242 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2243 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002244 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002245 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002246 };
2247
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002248 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002249 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002250 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2251 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002252 };
2253
2254 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002255 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002256 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002257 "Esw", "Ewa", "Elw", "Eec"
2258 };
2259
2260 @FunctionalInterface
2261 public interface IntToString {
2262 String applyAsString(int val);
2263 }
2264
2265 private static final IntToString sUidToString = UserHandle::formatUid;
2266 private static final IntToString sIntToString = Integer::toString;
2267
2268 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2269 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2270 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2271 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2272 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002273 };
2274
Dianne Hackborn617f8772009-03-31 15:04:46 -07002275 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002276 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002277 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002278 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002279 * {@hide}
2280 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002281 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002282
2283 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002284 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002285 * been in the running state while the device was running on battery.
2286 *
2287 * {@hide}
2288 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002289 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002290
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002291 public static final int WIFI_STATE_OFF = 0;
2292 public static final int WIFI_STATE_OFF_SCANNING = 1;
2293 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2294 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2295 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2296 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2297 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2298 public static final int WIFI_STATE_SOFT_AP = 7;
2299
2300 static final String[] WIFI_STATE_NAMES = {
2301 "off", "scanning", "no_net", "disconn",
2302 "sta", "p2p", "sta_p2p", "soft_ap"
2303 };
2304
2305 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2306
2307 /**
2308 * Returns the time in microseconds that WiFi has been running in the given state.
2309 *
2310 * {@hide}
2311 */
2312 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002313 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002314
2315 /**
2316 * Returns the number of times that WiFi has entered the given state.
2317 *
2318 * {@hide}
2319 */
2320 public abstract int getWifiStateCount(int wifiState, int which);
2321
The Android Open Source Project10592532009-03-18 17:39:46 -07002322 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002323 * Returns the {@link Timer} object that tracks the given WiFi state.
2324 *
2325 * {@hide}
2326 */
2327 public abstract Timer getWifiStateTimer(int wifiState);
2328
2329 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002330 * Returns the time in microseconds that the wifi supplicant has been
2331 * in a given state.
2332 *
2333 * {@hide}
2334 */
2335 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2336
2337 /**
2338 * Returns the number of times that the wifi supplicant has transitioned
2339 * to a given state.
2340 *
2341 * {@hide}
2342 */
2343 public abstract int getWifiSupplStateCount(int state, int which);
2344
Kweku Adams87b19ec2017-10-09 12:40:03 -07002345 /**
2346 * Returns the {@link Timer} object that tracks the given wifi supplicant state.
2347 *
2348 * {@hide}
2349 */
2350 public abstract Timer getWifiSupplStateTimer(int state);
2351
Dianne Hackborn3251b902014-06-20 14:40:53 -07002352 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2353
2354 /**
2355 * Returns the time in microseconds that WIFI has been running with
2356 * the given signal strength.
2357 *
2358 * {@hide}
2359 */
2360 public abstract long getWifiSignalStrengthTime(int strengthBin,
2361 long elapsedRealtimeUs, int which);
2362
2363 /**
2364 * Returns the number of times WIFI has entered the given signal strength.
2365 *
2366 * {@hide}
2367 */
2368 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2369
2370 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002371 * Returns the {@link Timer} object that tracks the given WIFI signal strength.
2372 *
2373 * {@hide}
2374 */
2375 public abstract Timer getWifiSignalStrengthTimer(int strengthBin);
2376
2377 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002378 * Returns the time in microseconds that the flashlight has been on while the device was
2379 * running on battery.
2380 *
2381 * {@hide}
2382 */
2383 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2384
2385 /**
2386 * Returns the number of times that the flashlight has been turned on while the device was
2387 * running on battery.
2388 *
2389 * {@hide}
2390 */
2391 public abstract long getFlashlightOnCount(int which);
2392
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002393 /**
2394 * Returns the time in microseconds that the camera has been on while the device was
2395 * running on battery.
2396 *
2397 * {@hide}
2398 */
2399 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2400
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002401 /**
2402 * Returns the time in microseconds that bluetooth scans were running while the device was
2403 * on battery.
2404 *
2405 * {@hide}
2406 */
2407 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002408
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002409 public static final int NETWORK_MOBILE_RX_DATA = 0;
2410 public static final int NETWORK_MOBILE_TX_DATA = 1;
2411 public static final int NETWORK_WIFI_RX_DATA = 2;
2412 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002413 public static final int NETWORK_BT_RX_DATA = 4;
2414 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002415 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2416 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2417 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2418 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2419 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002420
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002421 public abstract long getNetworkActivityBytes(int type, int which);
2422 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002423
Adam Lesinskie08af192015-03-25 16:42:59 -07002424 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002425 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002426 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002427 * actual power data.
2428 */
2429 public abstract boolean hasWifiActivityReporting();
2430
2431 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002432 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2433 * in various radio controller states, such as transmit, receive, and idle.
2434 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002435 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002436 public abstract ControllerActivityCounter getWifiControllerActivity();
2437
2438 /**
2439 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2440 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2441 * actual power data.
2442 */
2443 public abstract boolean hasBluetoothActivityReporting();
2444
2445 /**
2446 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2447 * in various radio controller states, such as transmit, receive, and idle.
2448 * @return non-null {@link ControllerActivityCounter}
2449 */
2450 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2451
2452 /**
2453 * Returns true if the BatteryStats object has detailed modem power reports.
2454 * When true, calling {@link #getModemControllerActivity()} will yield the
2455 * actual power data.
2456 */
2457 public abstract boolean hasModemActivityReporting();
2458
2459 /**
2460 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2461 * in various radio controller states, such as transmit, receive, and idle.
2462 * @return non-null {@link ControllerActivityCounter}
2463 */
2464 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002465
The Android Open Source Project10592532009-03-18 17:39:46 -07002466 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002467 * Return the wall clock time when battery stats data collection started.
2468 */
2469 public abstract long getStartClockTime();
2470
2471 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002472 * Return platform version tag that we were running in when the battery stats started.
2473 */
2474 public abstract String getStartPlatformVersion();
2475
2476 /**
2477 * Return platform version tag that we were running in when the battery stats ended.
2478 */
2479 public abstract String getEndPlatformVersion();
2480
2481 /**
2482 * Return the internal version code of the parcelled format.
2483 */
2484 public abstract int getParcelVersion();
2485
2486 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 * Return whether we are currently running on battery.
2488 */
2489 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 /**
2492 * Returns a SparseArray containing the statistics for each uid.
2493 */
2494 public abstract SparseArray<? extends Uid> getUidStats();
2495
2496 /**
2497 * Returns the current battery uptime in microseconds.
2498 *
2499 * @param curTime the amount of elapsed realtime in microseconds.
2500 */
2501 public abstract long getBatteryUptime(long curTime);
2502
2503 /**
2504 * Returns the current battery realtime in microseconds.
2505 *
2506 * @param curTime the amount of elapsed realtime in microseconds.
2507 */
2508 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002509
The Android Open Source Project10592532009-03-18 17:39:46 -07002510 /**
Evan Millar633a1742009-04-02 16:36:33 -07002511 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002512 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002513 */
Evan Millar633a1742009-04-02 16:36:33 -07002514 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002515
The Android Open Source Project10592532009-03-18 17:39:46 -07002516 /**
Evan Millar633a1742009-04-02 16:36:33 -07002517 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2518 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002519 */
Evan Millar633a1742009-04-02 16:36:33 -07002520 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521
2522 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002523 * Get the amount the battery has discharged since the stats were
2524 * last reset after charging, as a lower-end approximation.
2525 */
2526 public abstract int getLowDischargeAmountSinceCharge();
2527
2528 /**
2529 * Get the amount the battery has discharged since the stats were
2530 * last reset after charging, as an upper-end approximation.
2531 */
2532 public abstract int getHighDischargeAmountSinceCharge();
2533
2534 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002535 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2536 */
2537 public abstract int getDischargeAmount(int which);
2538
2539 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002540 * Get the amount the battery has discharged while the screen was on,
2541 * since the last time power was unplugged.
2542 */
2543 public abstract int getDischargeAmountScreenOn();
2544
2545 /**
2546 * Get the amount the battery has discharged while the screen was on,
2547 * since the last time the device was charged.
2548 */
2549 public abstract int getDischargeAmountScreenOnSinceCharge();
2550
2551 /**
2552 * Get the amount the battery has discharged while the screen was off,
2553 * since the last time power was unplugged.
2554 */
2555 public abstract int getDischargeAmountScreenOff();
2556
2557 /**
2558 * Get the amount the battery has discharged while the screen was off,
2559 * since the last time the device was charged.
2560 */
2561 public abstract int getDischargeAmountScreenOffSinceCharge();
2562
2563 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002564 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002565 * since the last time power was unplugged.
2566 */
2567 public abstract int getDischargeAmountScreenDoze();
2568
2569 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002570 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002571 * since the last time the device was charged.
2572 */
2573 public abstract int getDischargeAmountScreenDozeSinceCharge();
2574
2575 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 * Returns the total, last, or current battery uptime in microseconds.
2577 *
2578 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002579 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 */
2581 public abstract long computeBatteryUptime(long curTime, int which);
2582
2583 /**
2584 * Returns the total, last, or current battery realtime in microseconds.
2585 *
2586 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002587 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 */
2589 public abstract long computeBatteryRealtime(long curTime, int which);
2590
2591 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002592 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002593 *
2594 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002595 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002596 */
2597 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2598
2599 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002600 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002601 *
2602 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002603 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002604 */
2605 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2606
2607 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 * Returns the total, last, or current uptime in microseconds.
2609 *
2610 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002611 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 */
2613 public abstract long computeUptime(long curTime, int which);
2614
2615 /**
2616 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002617 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002619 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002620 */
2621 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002622
2623 /**
2624 * Compute an approximation for how much run time (in microseconds) is remaining on
2625 * the battery. Returns -1 if no time can be computed: either there is not
2626 * enough current data to make a decision, or the battery is currently
2627 * charging.
2628 *
2629 * @param curTime The current elepsed realtime in microseconds.
2630 */
2631 public abstract long computeBatteryTimeRemaining(long curTime);
2632
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002633 // The part of a step duration that is the actual time.
2634 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2635
2636 // Bits in a step duration that are the new battery level we are at.
2637 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002638 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002639
2640 // Bits in a step duration that are the initial mode we were in at that step.
2641 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002642 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002643
2644 // Bits in a step duration that indicate which modes changed during that step.
2645 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002646 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002647
2648 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2649 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2650
Santos Cordone94f0502017-02-24 12:31:20 -08002651 // The largest value for screen state that is tracked in battery states. Any values above
2652 // this should be mapped back to one of the tracked values before being tracked here.
2653 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2654
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002655 // Step duration mode: power save is on.
2656 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2657
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002658 // Step duration mode: device is currently in idle mode.
2659 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2660
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002661 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2662 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002663 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2664 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002665 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2666 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2667 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2668 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2669 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002670 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2671 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002672 };
2673 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2674 (Display.STATE_OFF-1),
2675 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002676 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002677 (Display.STATE_ON-1),
2678 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2679 (Display.STATE_DOZE-1),
2680 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2681 (Display.STATE_DOZE_SUSPEND-1),
2682 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002683 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002684 };
2685 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2686 "screen off",
2687 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002688 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002689 "screen on",
2690 "screen on power save",
2691 "screen doze",
2692 "screen doze power save",
2693 "screen doze-suspend",
2694 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002695 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002696 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002697
2698 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002699 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002700 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2701 * a coulomb counter.
2702 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002703 public abstract long getUahDischargeScreenOff(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002704
2705 /**
2706 * Return the amount of battery discharge while the screen was in doze mode, measured in
2707 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2708 * a coulomb counter.
2709 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002710 public abstract long getUahDischargeScreenDoze(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002711
2712 /**
2713 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2714 * non-zero only if the device's battery has a coulomb counter.
2715 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002716 public abstract long getUahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002717
2718 /**
Mike Ma15313c92017-11-15 17:58:21 -08002719 * @return the amount of battery discharge while the device is in light idle mode, measured in
2720 * micro-Ampere-hours.
2721 */
2722 public abstract long getUahDischargeLightDoze(int which);
2723
2724 /**
2725 * @return the amount of battery discharge while the device is in deep idle mode, measured in
2726 * micro-Ampere-hours.
2727 */
2728 public abstract long getUahDischargeDeepDoze(int which);
2729
2730 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002731 * Returns the estimated real battery capacity, which may be less than the capacity
2732 * declared by the PowerProfile.
2733 * @return The estimated battery capacity in mAh.
2734 */
2735 public abstract int getEstimatedBatteryCapacity();
2736
2737 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002738 * @return The minimum learned battery capacity in uAh.
2739 */
2740 public abstract int getMinLearnedBatteryCapacity();
2741
2742 /**
2743 * @return The maximum learned battery capacity in uAh.
2744 */
2745 public abstract int getMaxLearnedBatteryCapacity() ;
2746
2747 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002748 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002749 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002750 public abstract LevelStepTracker getDischargeLevelStepTracker();
2751
2752 /**
2753 * Return the array of daily discharge step durations.
2754 */
2755 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002756
2757 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002758 * Compute an approximation for how much time (in microseconds) remains until the battery
2759 * is fully charged. Returns -1 if no time can be computed: either there is not
2760 * enough current data to make a decision, or the battery is currently
2761 * discharging.
2762 *
2763 * @param curTime The current elepsed realtime in microseconds.
2764 */
2765 public abstract long computeChargeTimeRemaining(long curTime);
2766
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002767 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002768 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002769 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002770 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002771
2772 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002773 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002774 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002775 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002776
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002777 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2778
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002779 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002780
Evan Millarc64edde2009-04-18 12:26:32 -07002781 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782
Bookatz50df7112017-08-04 14:53:26 -07002783 /**
2784 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2785 */
2786 public abstract Map<String, ? extends Timer> getRpmStats();
2787 /**
2788 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2789 */
2790 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2791
2792
James Carr2dd7e5e2016-07-20 18:48:39 -07002793 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2794
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002795 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2796
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002797 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 long days = seconds / (60 * 60 * 24);
2799 if (days != 0) {
2800 out.append(days);
2801 out.append("d ");
2802 }
2803 long used = days * 60 * 60 * 24;
2804
2805 long hours = (seconds - used) / (60 * 60);
2806 if (hours != 0 || used != 0) {
2807 out.append(hours);
2808 out.append("h ");
2809 }
2810 used += hours * 60 * 60;
2811
2812 long mins = (seconds-used) / 60;
2813 if (mins != 0 || used != 0) {
2814 out.append(mins);
2815 out.append("m ");
2816 }
2817 used += mins * 60;
2818
2819 if (seconds != 0 || used != 0) {
2820 out.append(seconds-used);
2821 out.append("s ");
2822 }
2823 }
2824
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002825 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002827 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 sb.append(time - (sec * 1000));
2829 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 }
2831
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002832 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002833 long sec = time / 1000;
2834 formatTimeRaw(sb, sec);
2835 sb.append(time - (sec * 1000));
2836 sb.append("ms");
2837 }
2838
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002839 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002841 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 }
2843 float perc = ((float)num) / ((float)den) * 100;
2844 mFormatBuilder.setLength(0);
2845 mFormatter.format("%.1f%%", perc);
2846 return mFormatBuilder.toString();
2847 }
2848
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002849 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002850 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002851
Evan Millar22ac0432009-03-31 11:33:18 -07002852 if (bytes < BYTES_PER_KB) {
2853 return bytes + "B";
2854 } else if (bytes < BYTES_PER_MB) {
2855 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2856 return mFormatBuilder.toString();
2857 } else if (bytes < BYTES_PER_GB){
2858 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2859 return mFormatBuilder.toString();
2860 } else {
2861 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2862 return mFormatBuilder.toString();
2863 }
2864 }
2865
Kweku Adams103351f2017-10-16 14:39:34 -07002866 private static long roundUsToMs(long timeUs) {
2867 return (timeUs + 500) / 1000;
2868 }
2869
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002870 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002871 if (timer != null) {
2872 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002873 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002874 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2875 return totalTimeMillis;
2876 }
2877 return 0;
2878 }
2879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 /**
2881 *
2882 * @param sb a StringBuilder object.
2883 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002884 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002886 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 * @param linePrefix a String to be prepended to each line of output.
2888 * @return the line prefix
2889 */
2890 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002891 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002894 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002895
Evan Millarc64edde2009-04-18 12:26:32 -07002896 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 if (totalTimeMillis != 0) {
2898 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002899 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002900 if (name != null) {
2901 sb.append(name);
2902 sb.append(' ');
2903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 sb.append('(');
2905 sb.append(count);
2906 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002907 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2908 if (maxDurationMs >= 0) {
2909 sb.append(" max=");
2910 sb.append(maxDurationMs);
2911 }
Bookatz506a8182017-05-01 14:18:42 -07002912 // Put actual time if it is available and different from totalTimeMillis.
2913 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2914 if (totalDurMs > totalTimeMillis) {
2915 sb.append(" actual=");
2916 sb.append(totalDurMs);
2917 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002918 if (timer.isRunningLocked()) {
2919 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2920 if (currentMs >= 0) {
2921 sb.append(" (running for ");
2922 sb.append(currentMs);
2923 sb.append("ms)");
2924 } else {
2925 sb.append(" (running)");
2926 }
2927 }
2928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 return ", ";
2930 }
2931 }
2932 return linePrefix;
2933 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002934
2935 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002936 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002937 *
2938 * @param pw a PrintWriter object to print to.
2939 * @param sb a StringBuilder object.
2940 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002941 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002942 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2943 * @param prefix a String to be prepended to each line of output.
2944 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002945 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002946 */
2947 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002948 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002949 if (timer != null) {
2950 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002951 final long totalTimeMs = (timer.getTotalTimeLocked(
2952 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002953 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002954 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002955 sb.setLength(0);
2956 sb.append(prefix);
2957 sb.append(" ");
2958 sb.append(type);
2959 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002960 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002961 sb.append("realtime (");
2962 sb.append(count);
2963 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002964 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2965 if (maxDurationMs >= 0) {
2966 sb.append(" max=");
2967 sb.append(maxDurationMs);
2968 }
2969 if (timer.isRunningLocked()) {
2970 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2971 if (currentMs >= 0) {
2972 sb.append(" (running for ");
2973 sb.append(currentMs);
2974 sb.append("ms)");
2975 } else {
2976 sb.append(" (running)");
2977 }
2978 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002979 pw.println(sb.toString());
2980 return true;
2981 }
2982 }
2983 return false;
2984 }
Bookatzc8c44962017-05-11 12:12:54 -07002985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 /**
2987 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002988 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 * @param sb a StringBuilder object.
2990 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002991 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002993 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 * @param linePrefix a String to be prepended to each line of output.
2995 * @return the line prefix
2996 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002997 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2998 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 long totalTimeMicros = 0;
3000 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07003001 long max = 0;
3002 long current = 0;
3003 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003005 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07003006 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003007 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
3008 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07003009 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011 sb.append(linePrefix);
3012 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
3013 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07003014 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003016 sb.append(',');
3017 sb.append(current);
3018 sb.append(',');
3019 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07003020 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
3021 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
3022 // totalDuration independent of totalTimeMicros (since they are not pooled).
3023 if (name != null) {
3024 sb.append(',');
3025 sb.append(totalDuration);
3026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 return ",";
3028 }
Bookatz506a8182017-05-01 14:18:42 -07003029
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003030 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
3031 String type) {
3032 pw.print(BATTERY_STATS_CHECKIN_VERSION);
3033 pw.print(',');
3034 pw.print(uid);
3035 pw.print(',');
3036 pw.print(category);
3037 pw.print(',');
3038 pw.print(type);
3039 }
3040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 /**
3042 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07003043 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 * @param pw the PageWriter to dump log to
3045 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3046 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3047 * @param args type-dependent data arguments
3048 */
Bookatzc8c44962017-05-11 12:12:54 -07003049 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003051 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003052 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003053 pw.print(',');
3054 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003056 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07003058
3059 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003060 * Dump a given timer stat for terse checkin mode.
3061 *
3062 * @param pw the PageWriter to dump log to
3063 * @param uid the UID to log
3064 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3065 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3066 * @param timer a {@link Timer} to dump stats for
3067 * @param rawRealtime the current elapsed realtime of the system in microseconds
3068 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3069 */
3070 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
3071 Timer timer, long rawRealtime, int which) {
3072 if (timer != null) {
3073 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003074 final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which));
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003075 final int count = timer.getCountLocked(which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003076 if (totalTime != 0 || count != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003077 dumpLine(pw, uid, category, type, totalTime, count);
3078 }
3079 }
3080 }
3081
3082 /**
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003083 * Dump a given timer stat to the proto stream.
3084 *
3085 * @param proto the ProtoOutputStream to log to
3086 * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK)
3087 * @param timer a {@link Timer} to dump stats for
3088 * @param rawRealtimeUs the current elapsed realtime of the system in microseconds
3089 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3090 */
3091 private static void dumpTimer(ProtoOutputStream proto, long fieldId,
Kweku Adams87b19ec2017-10-09 12:40:03 -07003092 Timer timer, long rawRealtimeUs, int which) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003093 if (timer == null) {
3094 return;
3095 }
3096 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003097 final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which));
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003098 final int count = timer.getCountLocked(which);
Kweku Adams103351f2017-10-16 14:39:34 -07003099 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000);
3100 final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000);
3101 final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000);
3102 if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1
3103 || totalDurationMs != -1) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003104 final long token = proto.start(fieldId);
Kweku Adams103351f2017-10-16 14:39:34 -07003105 proto.write(TimerProto.DURATION_MS, timeMs);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003106 proto.write(TimerProto.COUNT, count);
Kweku Adams103351f2017-10-16 14:39:34 -07003107 // These values will be -1 for timers that don't implement the functionality.
3108 if (maxDurationMs != -1) {
3109 proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs);
3110 }
3111 if (curDurationMs != -1) {
3112 proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs);
3113 }
3114 if (totalDurationMs != -1) {
3115 proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs);
3116 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003117 proto.end(token);
3118 }
3119 }
3120
3121 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003122 * Checks if the ControllerActivityCounter has any data worth dumping.
3123 */
3124 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
3125 if (counter == null) {
3126 return false;
3127 }
3128
3129 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
3130 || counter.getRxTimeCounter().getCountLocked(which) != 0
3131 || counter.getPowerCounter().getCountLocked(which) != 0) {
3132 return true;
3133 }
3134
3135 for (LongCounter c : counter.getTxTimeCounters()) {
3136 if (c.getCountLocked(which) != 0) {
3137 return true;
3138 }
3139 }
3140 return false;
3141 }
3142
3143 /**
3144 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3145 * The order of the arguments in the final check in line is:
3146 *
3147 * idle, rx, power, tx...
3148 *
3149 * where tx... is one or more transmit level times.
3150 */
3151 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3152 String type,
3153 ControllerActivityCounter counter,
3154 int which) {
3155 if (!controllerActivityHasData(counter, which)) {
3156 return;
3157 }
3158
3159 dumpLineHeader(pw, uid, category, type);
3160 pw.print(",");
3161 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3162 pw.print(",");
3163 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3164 pw.print(",");
3165 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3166 for (LongCounter c : counter.getTxTimeCounters()) {
3167 pw.print(",");
3168 pw.print(c.getCountLocked(which));
3169 }
3170 pw.println();
3171 }
3172
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003173 /**
3174 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3175 */
3176 private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId,
3177 ControllerActivityCounter counter,
3178 int which) {
3179 if (!controllerActivityHasData(counter, which)) {
3180 return;
3181 }
3182
3183 final long cToken = proto.start(fieldId);
3184
3185 proto.write(ControllerActivityProto.IDLE_DURATION_MS,
3186 counter.getIdleTimeCounter().getCountLocked(which));
3187 proto.write(ControllerActivityProto.RX_DURATION_MS,
3188 counter.getRxTimeCounter().getCountLocked(which));
3189 proto.write(ControllerActivityProto.POWER_MAH,
3190 counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3191
3192 long tToken;
3193 LongCounter[] txCounters = counter.getTxTimeCounters();
3194 for (int i = 0; i < txCounters.length; ++i) {
3195 LongCounter c = txCounters[i];
3196 tToken = proto.start(ControllerActivityProto.TX);
3197 proto.write(ControllerActivityProto.TxLevel.LEVEL, i);
3198 proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which));
3199 proto.end(tToken);
3200 }
3201
3202 proto.end(cToken);
3203 }
3204
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003205 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3206 String prefix, String controllerName,
3207 ControllerActivityCounter counter,
3208 int which) {
3209 if (controllerActivityHasData(counter, which)) {
3210 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3211 }
3212 }
3213
3214 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3215 String controllerName,
3216 ControllerActivityCounter counter, int which) {
3217 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3218 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3219 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003220 // Battery real time
3221 final long totalControllerActivityTimeMs
3222 = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000;
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003223 long totalTxTimeMs = 0;
3224 for (LongCounter txState : counter.getTxTimeCounters()) {
3225 totalTxTimeMs += txState.getCountLocked(which);
3226 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003227 final long sleepTimeMs
3228 = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003229
3230 sb.setLength(0);
3231 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003232 sb.append(" ");
3233 sb.append(controllerName);
3234 sb.append(" Sleep time: ");
3235 formatTimeMs(sb, sleepTimeMs);
3236 sb.append("(");
3237 sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs));
3238 sb.append(")");
3239 pw.println(sb.toString());
3240
3241 sb.setLength(0);
3242 sb.append(prefix);
3243 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003244 sb.append(controllerName);
3245 sb.append(" Idle time: ");
3246 formatTimeMs(sb, idleTimeMs);
3247 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003248 sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003249 sb.append(")");
3250 pw.println(sb.toString());
3251
3252 sb.setLength(0);
3253 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003254 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003255 sb.append(controllerName);
3256 sb.append(" Rx time: ");
3257 formatTimeMs(sb, rxTimeMs);
3258 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003259 sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003260 sb.append(")");
3261 pw.println(sb.toString());
3262
3263 sb.setLength(0);
3264 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003265 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003266 sb.append(controllerName);
3267 sb.append(" Tx time: ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003268
Siddharth Ray3c648c42017-10-02 17:30:58 -07003269 String [] powerLevel;
3270 switch(controllerName) {
3271 case "Cellular":
3272 powerLevel = new String[] {
3273 " less than 0dBm: ",
3274 " 0dBm to 8dBm: ",
3275 " 8dBm to 15dBm: ",
3276 " 15dBm to 20dBm: ",
3277 " above 20dBm: "};
3278 break;
3279 default:
3280 powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"};
3281 break;
3282 }
3283 final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003284 if (numTxLvls > 1) {
Siddharth Ray3c648c42017-10-02 17:30:58 -07003285 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003286 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3287 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3288 sb.setLength(0);
3289 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003290 sb.append(" ");
3291 sb.append(powerLevel[lvl]);
3292 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003293 formatTimeMs(sb, txLvlTimeMs);
3294 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003295 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003296 sb.append(")");
3297 pw.println(sb.toString());
3298 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003299 } else {
3300 final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which);
3301 formatTimeMs(sb, txLvlTimeMs);
3302 sb.append("(");
3303 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
3304 sb.append(")");
3305 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003306 }
3307
Siddharth Ray3c648c42017-10-02 17:30:58 -07003308 if (powerDrainMaMs > 0) {
3309 sb.setLength(0);
3310 sb.append(prefix);
3311 sb.append(" ");
3312 sb.append(controllerName);
3313 sb.append(" Battery drain: ").append(
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003314 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
Siddharth Ray3c648c42017-10-02 17:30:58 -07003315 sb.append("mAh");
3316 pw.println(sb.toString());
3317 }
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003318 }
3319
3320 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003321 * Temporary for settings.
3322 */
3323 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3324 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3325 }
3326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 /**
3328 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003329 *
Kweku Adams87b19ec2017-10-09 12:40:03 -07003330 * NOTE: all times are expressed in microseconds, unless specified otherwise.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003332 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3333 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 final long rawUptime = SystemClock.uptimeMillis() * 1000;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003335 final long rawRealtimeMs = SystemClock.elapsedRealtime();
3336 final long rawRealtime = rawRealtimeMs * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3339 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003340 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3341 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3342 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 final long totalRealtime = computeRealtime(rawRealtime, which);
3344 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003345 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003346 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003347 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003348 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003349 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3350 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003351 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003352 rawRealtime, which);
3353 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3354 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003355 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003356 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003357 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003358 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003359 final long dischargeCount = getUahDischarge(which);
3360 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
3361 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Ma15313c92017-11-15 17:58:21 -08003362 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
3363 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003364
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003365 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003366
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003367 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003368 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003369
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003370 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003373 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003374 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003375 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003376 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003377 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003378 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003379 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003380 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3381 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003382
Bookatzc8c44962017-05-11 12:12:54 -07003383
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003384 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003385 long fullWakeLockTimeTotal = 0;
3386 long partialWakeLockTimeTotal = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003387 long multicastWakeLockTimeTotalMicros = 0;
3388 int multicastWakeLockCountTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003389
Evan Millar22ac0432009-03-31 11:33:18 -07003390 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003391 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003392
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003393 // First calculating the wakelock stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003394 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3395 = u.getWakelockStats();
3396 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3397 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003398
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003399 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3400 if (fullWakeTimer != null) {
3401 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3402 which);
3403 }
3404
3405 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3406 if (partialWakeTimer != null) {
3407 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3408 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003409 }
3410 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003411
3412 // Now calculating the wifi multicast wakelock stats
3413 final Timer mcTimer = u.getMulticastWakelockStats();
3414 if (mcTimer != null) {
3415 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
3416 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
3417 }
Evan Millar22ac0432009-03-31 11:33:18 -07003418 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003419
3420 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003421 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3422 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3423 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3424 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3425 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3426 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3427 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3428 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003429 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3430 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003431 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3432 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003433 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3434 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003435
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003436 // Dump Modem controller stats
3437 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3438 getModemControllerActivity(), which);
3439
Adam Lesinskie283d332015-04-16 12:29:25 -07003440 // Dump Wifi controller stats
3441 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3442 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003443 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003444 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003445
3446 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3447 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003448
3449 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003450 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3451 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003453 // Dump misc stats
3454 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003455 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003456 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003457 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003458 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003459 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003460 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3461 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003462 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003463 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3464 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3465 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3466 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003467 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003468
Dianne Hackborn617f8772009-03-31 15:04:46 -07003469 // Dump screen brightness stats
3470 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3471 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003472 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003473 }
3474 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003475
Dianne Hackborn627bba72009-03-24 22:32:56 -07003476 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003477 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3478 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003479 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003480 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003481 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003482 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003483 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003484 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003485 args[i] = getPhoneSignalStrengthCount(i, which);
3486 }
3487 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003488
Dianne Hackborn627bba72009-03-24 22:32:56 -07003489 // Dump network type stats
3490 args = new Object[NUM_DATA_CONNECTION_TYPES];
3491 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003492 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003493 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003494 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3495 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3496 args[i] = getPhoneDataConnectionCount(i, which);
3497 }
3498 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003499
3500 // Dump wifi state stats
3501 args = new Object[NUM_WIFI_STATES];
3502 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003503 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003504 }
3505 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3506 for (int i=0; i<NUM_WIFI_STATES; i++) {
3507 args[i] = getWifiStateCount(i, which);
3508 }
3509 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3510
Dianne Hackborn3251b902014-06-20 14:40:53 -07003511 // Dump wifi suppl state stats
3512 args = new Object[NUM_WIFI_SUPPL_STATES];
3513 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3514 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3515 }
3516 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3517 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3518 args[i] = getWifiSupplStateCount(i, which);
3519 }
3520 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3521
3522 // Dump wifi signal strength stats
3523 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3524 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3525 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3526 }
3527 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3528 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3529 args[i] = getWifiSignalStrengthCount(i, which);
3530 }
3531 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3532
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003533 // Dump Multicast total stats
3534 dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA,
3535 multicastWakeLockTimeTotalMicros / 1000,
3536 multicastWakeLockCountTotal);
3537
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003538 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003539 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003540 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003541 }
Bookatzc8c44962017-05-11 12:12:54 -07003542
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003543 if (which == STATS_SINCE_UNPLUGGED) {
3544 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3545 getDischargeStartLevel()-getDischargeCurrentLevel(),
3546 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003547 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003548 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003549 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000,
3550 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003551 } else {
3552 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3553 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003554 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003555 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003556 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003557 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000,
3558 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003559 }
Bookatzc8c44962017-05-11 12:12:54 -07003560
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003561 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003562 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003563 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003564 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003565 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003566 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003567 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3568 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003569 }
Evan Millarc64edde2009-04-18 12:26:32 -07003570 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003571 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003572 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003573 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3574 // Not doing the regular wake lock formatting to remain compatible
3575 // with the old checkin format.
3576 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3577 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003578 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003579 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003580 }
3581 }
Evan Millarc64edde2009-04-18 12:26:32 -07003582 }
Bookatzc8c44962017-05-11 12:12:54 -07003583
Bookatz50df7112017-08-04 14:53:26 -07003584 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3585 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3586 if (rpmStats.size() > 0) {
3587 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3588 sb.setLength(0);
3589 Timer totalTimer = ent.getValue();
3590 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3591 int count = totalTimer.getCountLocked(which);
3592 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3593 long screenOffTimeMs = screenOffTimer != null
3594 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3595 int screenOffCount = screenOffTimer != null
3596 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003597 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3598 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3599 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3600 screenOffCount);
3601 } else {
3602 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3603 "\"" + ent.getKey() + "\"", timeMs, count);
3604 }
Bookatz50df7112017-08-04 14:53:26 -07003605 }
3606 }
3607
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003608 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003609 helper.create(this);
3610 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003611 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003612 if (sippers != null && sippers.size() > 0) {
3613 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3614 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003615 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003616 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3617 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
Kweku Adams87b19ec2017-10-09 12:40:03 -07003618 int uid = 0;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003619 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003620 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003621 String label;
3622 switch (bs.drainType) {
3623 case IDLE:
3624 label="idle";
3625 break;
3626 case CELL:
3627 label="cell";
3628 break;
3629 case PHONE:
3630 label="phone";
3631 break;
3632 case WIFI:
3633 label="wifi";
3634 break;
3635 case BLUETOOTH:
3636 label="blue";
3637 break;
3638 case SCREEN:
3639 label="scrn";
3640 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003641 case FLASHLIGHT:
3642 label="flashlight";
3643 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003644 case APP:
3645 uid = bs.uidObj.getUid();
3646 label = "uid";
3647 break;
3648 case USER:
3649 uid = UserHandle.getUid(bs.userId, 0);
3650 label = "user";
3651 break;
3652 case UNACCOUNTED:
3653 label = "unacc";
3654 break;
3655 case OVERCOUNTED:
3656 label = "over";
3657 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003658 case CAMERA:
3659 label = "camera";
3660 break;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003661 case MEMORY:
3662 label = "memory";
3663 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003664 default:
3665 label = "???";
3666 }
3667 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003668 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3669 bs.shouldHide ? 1 : 0,
3670 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3671 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003672 }
3673 }
3674
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003675 final long[] cpuFreqs = getCpuFreqs();
3676 if (cpuFreqs != null) {
3677 sb.setLength(0);
3678 for (int i = 0; i < cpuFreqs.length; ++i) {
3679 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3680 }
3681 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3682 }
3683
Kweku Adams87b19ec2017-10-09 12:40:03 -07003684 // Dump stats per UID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 for (int iu = 0; iu < NU; iu++) {
3686 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003687 if (reqUid >= 0 && uid != reqUid) {
3688 continue;
3689 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003690 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003693 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3694 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3695 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3696 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3697 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3698 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3699 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3700 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003701 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003702 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3703 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003704 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003705 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3706 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003707 // Background data transfers
3708 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3709 which);
3710 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3711 which);
3712 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3713 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3714 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3715 which);
3716 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3717 which);
3718 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3719 which);
3720 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3721 which);
3722
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003723 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3724 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003725 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003726 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3727 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3728 || wifiBytesBgTx > 0
3729 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3730 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003731 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3732 wifiBytesRx, wifiBytesTx,
3733 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003734 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003735 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003736 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3737 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3738 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3739 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003740 }
3741
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003742 // Dump modem controller data, per UID.
3743 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3744 u.getModemControllerActivity(), which);
3745
3746 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003747 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3748 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3749 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003750 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3751 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003752 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3753 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3754 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003755 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003756 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003757 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3758 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003759 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3760 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003761 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003762 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003765 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3766 u.getWifiControllerActivity(), which);
3767
Bookatz867c0d72017-03-07 18:23:42 -08003768 final Timer bleTimer = u.getBluetoothScanTimer();
3769 if (bleTimer != null) {
3770 // Convert from microseconds to milliseconds with rounding
3771 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3772 / 1000;
3773 if (totalTime != 0) {
3774 final int count = bleTimer.getCountLocked(which);
3775 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3776 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003777 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3778 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3779 final long actualTimeBg = bleTimerBg != null ?
3780 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003781 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003782 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3783 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003784 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3785 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3786 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3787 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3788 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3789 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3790 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3791 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3792 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3793 final Timer unoptimizedScanTimerBg =
3794 u.getBluetoothUnoptimizedScanBackgroundTimer();
3795 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3796 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3797 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3798 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3799
Bookatz867c0d72017-03-07 18:23:42 -08003800 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003801 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3802 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3803 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003804 }
3805 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003806
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003807 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3808 u.getBluetoothControllerActivity(), which);
3809
Dianne Hackborn617f8772009-03-31 15:04:46 -07003810 if (u.hasUserActivity()) {
3811 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3812 boolean hasData = false;
3813 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3814 int val = u.getUserActivityCount(i, which);
3815 args[i] = val;
3816 if (val != 0) hasData = true;
3817 }
3818 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003819 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003820 }
3821 }
Bookatzc8c44962017-05-11 12:12:54 -07003822
3823 if (u.getAggregatedPartialWakelockTimer() != null) {
3824 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003825 // Times are since reset (regardless of 'which')
3826 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003827 final Timer bgTimer = timer.getSubTimer();
3828 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003829 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003830 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3831 }
3832
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003833 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3834 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3835 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3836 String linePrefix = "";
3837 sb.setLength(0);
3838 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3839 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003840 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3841 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003842 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003843 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3844 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003845 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3846 rawRealtime, "w", which, linePrefix);
3847
Kweku Adams103351f2017-10-16 14:39:34 -07003848 // Only log if we had at least one wakelock...
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003849 if (sb.length() > 0) {
3850 String name = wakelocks.keyAt(iw);
3851 if (name.indexOf(',') >= 0) {
3852 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 }
Yi Jin02483362017-08-04 11:30:44 -07003854 if (name.indexOf('\n') >= 0) {
3855 name = name.replace('\n', '_');
3856 }
3857 if (name.indexOf('\r') >= 0) {
3858 name = name.replace('\r', '_');
3859 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003860 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 }
3862 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003863
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003864 // WiFi Multicast Wakelock Statistics
3865 final Timer mcTimer = u.getMulticastWakelockStats();
3866 if (mcTimer != null) {
3867 final long totalMcWakelockTimeMs =
3868 mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ;
3869 final int countMcWakelock = mcTimer.getCountLocked(which);
3870 if(totalMcWakelockTimeMs > 0) {
3871 dumpLine(pw, uid, category, WIFI_MULTICAST_DATA,
3872 totalMcWakelockTimeMs, countMcWakelock);
3873 }
3874 }
3875
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003876 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3877 for (int isy=syncs.size()-1; isy>=0; isy--) {
3878 final Timer timer = syncs.valueAt(isy);
3879 // Convert from microseconds to milliseconds with rounding
3880 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3881 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003882 final Timer bgTimer = timer.getSubTimer();
3883 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003884 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003885 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003886 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003887 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003888 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003889 }
3890 }
3891
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003892 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3893 for (int ij=jobs.size()-1; ij>=0; ij--) {
3894 final Timer timer = jobs.valueAt(ij);
3895 // Convert from microseconds to milliseconds with rounding
3896 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3897 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003898 final Timer bgTimer = timer.getSubTimer();
3899 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003900 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003901 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003902 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003903 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003904 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003905 }
3906 }
3907
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003908 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3909 for (int ic=completions.size()-1; ic>=0; ic--) {
3910 SparseIntArray types = completions.valueAt(ic);
3911 if (types != null) {
3912 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3913 "\"" + completions.keyAt(ic) + "\"",
3914 types.get(JobParameters.REASON_CANCELED, 0),
3915 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3916 types.get(JobParameters.REASON_PREEMPT, 0),
3917 types.get(JobParameters.REASON_TIMEOUT, 0),
3918 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3919 }
3920 }
3921
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003922 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3923 rawRealtime, which);
3924 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3925 rawRealtime, which);
3926 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3927 rawRealtime, which);
3928 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3929 rawRealtime, which);
3930
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003931 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3932 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003933 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003934 final Uid.Sensor se = sensors.valueAt(ise);
3935 final int sensorNumber = sensors.keyAt(ise);
3936 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003937 if (timer != null) {
3938 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003939 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3940 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003941 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003942 final int count = timer.getCountLocked(which);
3943 final Timer bgTimer = se.getSensorBackgroundTime();
3944 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003945 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3946 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3947 final long bgActualTime = bgTimer != null ?
3948 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3949 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3950 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 }
3953 }
3954
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003955 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3956 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003957
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003958 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3959 rawRealtime, which);
3960
3961 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003962 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003963
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003964 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003965 long totalStateTime = 0;
3966 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003967 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3968 totalStateTime += time;
3969 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003970 }
3971 if (totalStateTime > 0) {
3972 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3973 }
3974
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003975 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3976 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003977 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003978 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003979 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003980 }
3981
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003982 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3983 if (cpuFreqs != null) {
3984 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3985 // If total cpuFreqTimes is null, then we don't need to check for
3986 // screenOffCpuFreqTimes.
3987 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3988 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003989 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003990 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003991 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003992 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3993 if (screenOffCpuFreqTimeMs != null) {
3994 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3995 sb.append("," + screenOffCpuFreqTimeMs[i]);
3996 }
3997 } else {
3998 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3999 sb.append(",0");
4000 }
4001 }
4002 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
4003 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004004 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004005 }
4006
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004007 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4008 = u.getProcessStats();
4009 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4010 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004011
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004012 final long userMillis = ps.getUserTime(which);
4013 final long systemMillis = ps.getSystemTime(which);
4014 final long foregroundMillis = ps.getForegroundTime(which);
4015 final int starts = ps.getStarts(which);
4016 final int numCrashes = ps.getNumCrashes(which);
4017 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004018
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004019 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
4020 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004021 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
4022 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 }
4024 }
4025
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004026 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4027 = u.getPackageStats();
4028 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4029 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4030 int wakeups = 0;
4031 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4032 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07004033 int count = alarms.valueAt(iwa).getCountLocked(which);
4034 wakeups += count;
4035 String name = alarms.keyAt(iwa).replace(',', '_');
4036 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004037 }
4038 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4039 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4040 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4041 final long startTime = ss.getStartTime(batteryUptime, which);
4042 final int starts = ss.getStarts(which);
4043 final int launches = ss.getLaunches(which);
4044 if (startTime != 0 || starts != 0 || launches != 0) {
4045 dumpLine(pw, uid, category, APK_DATA,
4046 wakeups, // wakeup alarms
4047 packageStats.keyAt(ipkg), // Apk
4048 serviceStats.keyAt(isvc), // service
4049 startTime / 1000, // time spent started, in ms
4050 starts,
4051 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 }
4053 }
4054 }
4055 }
4056 }
4057
Dianne Hackborn81038902012-11-26 17:04:09 -08004058 static final class TimerEntry {
4059 final String mName;
4060 final int mId;
4061 final BatteryStats.Timer mTimer;
4062 final long mTime;
4063 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
4064 mName = name;
4065 mId = id;
4066 mTimer = timer;
4067 mTime = time;
4068 }
4069 }
4070
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004071 private void printmAh(PrintWriter printer, double power) {
4072 printer.print(BatteryStatsHelper.makemAh(power));
4073 }
4074
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004075 private void printmAh(StringBuilder sb, double power) {
4076 sb.append(BatteryStatsHelper.makemAh(power));
4077 }
4078
Dianne Hackbornd953c532014-08-16 18:17:38 -07004079 /**
4080 * Temporary for settings.
4081 */
4082 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
4083 int reqUid) {
4084 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
4085 }
4086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004088 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07004089 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 final long rawUptime = SystemClock.uptimeMillis() * 1000;
4091 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07004092 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094
4095 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
4096 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
4097 final long totalRealtime = computeRealtime(rawRealtime, which);
4098 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004099 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
4100 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
4101 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004102 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
4103 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07004104 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004105
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004106 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07004107
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004108 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07004109 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110
Adam Lesinskif9b20a92016-06-17 17:30:01 -07004111 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
4112 if (estimatedBatteryCapacity > 0) {
4113 sb.setLength(0);
4114 sb.append(prefix);
4115 sb.append(" Estimated battery capacity: ");
4116 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
4117 sb.append(" mAh");
4118 pw.println(sb.toString());
4119 }
4120
Jocelyn Dangc627d102017-04-14 13:15:14 -07004121 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
4122 if (minLearnedBatteryCapacity > 0) {
4123 sb.setLength(0);
4124 sb.append(prefix);
4125 sb.append(" Min learned battery capacity: ");
4126 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
4127 sb.append(" mAh");
4128 pw.println(sb.toString());
4129 }
4130 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
4131 if (maxLearnedBatteryCapacity > 0) {
4132 sb.setLength(0);
4133 sb.append(prefix);
4134 sb.append(" Max learned battery capacity: ");
4135 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
4136 sb.append(" mAh");
4137 pw.println(sb.toString());
4138 }
4139
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004140 sb.setLength(0);
4141 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004142 sb.append(" Time on battery: ");
4143 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
4144 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
4145 sb.append(") realtime, ");
4146 formatTimeMs(sb, whichBatteryUptime / 1000);
4147 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
4148 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004149 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004150
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004151 sb.setLength(0);
4152 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004153 sb.append(" Time on battery screen off: ");
4154 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
4155 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
4156 sb.append(") realtime, ");
4157 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
4158 sb.append("(");
4159 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
4160 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004161 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004162
4163 sb.setLength(0);
4164 sb.append(prefix);
4165 sb.append(" Time on battery screen doze: ");
4166 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
4167 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
4168 sb.append(")");
4169 pw.println(sb.toString());
4170
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004171 sb.setLength(0);
4172 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004173 sb.append(" Total run time: ");
4174 formatTimeMs(sb, totalRealtime / 1000);
4175 sb.append("realtime, ");
4176 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004177 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07004178 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004179 if (batteryTimeRemaining >= 0) {
4180 sb.setLength(0);
4181 sb.append(prefix);
4182 sb.append(" Battery time remaining: ");
4183 formatTimeMs(sb, batteryTimeRemaining / 1000);
4184 pw.println(sb.toString());
4185 }
4186 if (chargeTimeRemaining >= 0) {
4187 sb.setLength(0);
4188 sb.append(prefix);
4189 sb.append(" Charge time remaining: ");
4190 formatTimeMs(sb, chargeTimeRemaining / 1000);
4191 pw.println(sb.toString());
4192 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004193
Kweku Adams87b19ec2017-10-09 12:40:03 -07004194 final long dischargeCount = getUahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004195 if (dischargeCount >= 0) {
4196 sb.setLength(0);
4197 sb.append(prefix);
4198 sb.append(" Discharge: ");
4199 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
4200 sb.append(" mAh");
4201 pw.println(sb.toString());
4202 }
4203
Kweku Adams87b19ec2017-10-09 12:40:03 -07004204 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004205 if (dischargeScreenOffCount >= 0) {
4206 sb.setLength(0);
4207 sb.append(prefix);
4208 sb.append(" Screen off discharge: ");
4209 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
4210 sb.append(" mAh");
4211 pw.println(sb.toString());
4212 }
4213
Kweku Adams87b19ec2017-10-09 12:40:03 -07004214 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Mac2f518a2017-09-19 16:06:03 -07004215 if (dischargeScreenDozeCount >= 0) {
4216 sb.setLength(0);
4217 sb.append(prefix);
4218 sb.append(" Screen doze discharge: ");
4219 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
4220 sb.append(" mAh");
4221 pw.println(sb.toString());
4222 }
4223
4224 final long dischargeScreenOnCount =
4225 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004226 if (dischargeScreenOnCount >= 0) {
4227 sb.setLength(0);
4228 sb.append(prefix);
4229 sb.append(" Screen on discharge: ");
4230 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4231 sb.append(" mAh");
4232 pw.println(sb.toString());
4233 }
4234
Mike Ma15313c92017-11-15 17:58:21 -08004235 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
4236 if (dischargeLightDozeCount >= 0) {
4237 sb.setLength(0);
4238 sb.append(prefix);
4239 sb.append(" Device light doze discharge: ");
4240 sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0));
4241 sb.append(" mAh");
4242 pw.println(sb.toString());
4243 }
4244
4245 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
4246 if (dischargeDeepDozeCount >= 0) {
4247 sb.setLength(0);
4248 sb.append(prefix);
4249 sb.append(" Device deep doze discharge: ");
4250 sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0));
4251 sb.append(" mAh");
4252 pw.println(sb.toString());
4253 }
4254
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004255 pw.print(" Start clock time: ");
4256 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4257
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004258 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004259 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004260 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004261 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4262 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004263 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004264 rawRealtime, which);
4265 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4266 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004267 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004268 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004269 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4270 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4271 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004272 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004273 sb.append(prefix);
4274 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4275 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004276 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004277 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4278 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004279 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004280 pw.println(sb.toString());
4281 sb.setLength(0);
4282 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004283 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004284 boolean didOne = false;
4285 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004286 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004287 if (time == 0) {
4288 continue;
4289 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004290 sb.append("\n ");
4291 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004292 didOne = true;
4293 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4294 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004295 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004296 sb.append("(");
4297 sb.append(formatRatioLocked(time, screenOnTime));
4298 sb.append(")");
4299 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004300 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004301 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004302 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004303 sb.setLength(0);
4304 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004305 sb.append(" Power save mode enabled: ");
4306 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004307 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004308 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004309 sb.append(")");
4310 pw.println(sb.toString());
4311 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004312 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004313 sb.setLength(0);
4314 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004315 sb.append(" Device light idling: ");
4316 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004317 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004318 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4319 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004320 sb.append("x");
4321 pw.println(sb.toString());
4322 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004323 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004324 sb.setLength(0);
4325 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004326 sb.append(" Idle mode light time: ");
4327 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004328 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004329 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4330 sb.append(") ");
4331 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004332 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004333 sb.append(" -- longest ");
4334 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4335 pw.println(sb.toString());
4336 }
4337 if (deviceIdlingTime != 0) {
4338 sb.setLength(0);
4339 sb.append(prefix);
4340 sb.append(" Device full idling: ");
4341 formatTimeMs(sb, deviceIdlingTime / 1000);
4342 sb.append("(");
4343 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004344 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004345 sb.append("x");
4346 pw.println(sb.toString());
4347 }
4348 if (deviceIdleModeFullTime != 0) {
4349 sb.setLength(0);
4350 sb.append(prefix);
4351 sb.append(" Idle mode full time: ");
4352 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4353 sb.append("(");
4354 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4355 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004356 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004357 sb.append("x");
4358 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004359 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004360 pw.println(sb.toString());
4361 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004362 if (phoneOnTime != 0) {
4363 sb.setLength(0);
4364 sb.append(prefix);
4365 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4366 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004367 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004368 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004369 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004370 if (connChanges != 0) {
4371 pw.print(prefix);
4372 pw.print(" Connectivity changes: "); pw.println(connChanges);
4373 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004374
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004375 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004376 long fullWakeLockTimeTotalMicros = 0;
4377 long partialWakeLockTimeTotalMicros = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004378 long multicastWakeLockTimeTotalMicros = 0;
4379 int multicastWakeLockCountTotal = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004380
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004381 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004382
Evan Millar22ac0432009-03-31 11:33:18 -07004383 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004384 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004385
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004386 // First calculate wakelock statistics
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004387 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4388 = u.getWakelockStats();
4389 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4390 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004391
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004392 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4393 if (fullWakeTimer != null) {
4394 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4395 rawRealtime, which);
4396 }
4397
4398 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4399 if (partialWakeTimer != null) {
4400 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4401 rawRealtime, which);
4402 if (totalTimeMicros > 0) {
4403 if (reqUid < 0) {
4404 // Only show the ordered list of all wake
4405 // locks if the caller is not asking for data
4406 // about a specific uid.
4407 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4408 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004409 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004410 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004411 }
4412 }
4413 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004414
4415 // Next calculate wifi multicast wakelock statistics
4416 final Timer mcTimer = u.getMulticastWakelockStats();
4417 if (mcTimer != null) {
4418 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
4419 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
4420 }
Evan Millar22ac0432009-03-31 11:33:18 -07004421 }
Bookatzc8c44962017-05-11 12:12:54 -07004422
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004423 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4424 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4425 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4426 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4427 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4428 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4429 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4430 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004431 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4432 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004433
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004434 if (fullWakeLockTimeTotalMicros != 0) {
4435 sb.setLength(0);
4436 sb.append(prefix);
4437 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4438 (fullWakeLockTimeTotalMicros + 500) / 1000);
4439 pw.println(sb.toString());
4440 }
4441
4442 if (partialWakeLockTimeTotalMicros != 0) {
4443 sb.setLength(0);
4444 sb.append(prefix);
4445 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4446 (partialWakeLockTimeTotalMicros + 500) / 1000);
4447 pw.println(sb.toString());
4448 }
4449
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004450 if (multicastWakeLockTimeTotalMicros != 0) {
4451 sb.setLength(0);
4452 sb.append(prefix);
4453 sb.append(" Total WiFi Multicast wakelock Count: ");
4454 sb.append(multicastWakeLockCountTotal);
4455 pw.println(sb.toString());
4456
4457 sb.setLength(0);
4458 sb.append(prefix);
4459 sb.append(" Total WiFi Multicast wakelock time: ");
4460 formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000);
4461 pw.println(sb.toString());
4462 }
4463
Siddharth Ray3c648c42017-10-02 17:30:58 -07004464 pw.println("");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004465 pw.print(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004466 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004467 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004468 sb.append(" CONNECTIVITY POWER SUMMARY START");
4469 pw.println(sb.toString());
4470
4471 pw.print(prefix);
4472 sb.setLength(0);
4473 sb.append(prefix);
4474 sb.append(" Logging duration for connectivity statistics: ");
4475 formatTimeMs(sb, whichBatteryRealtime / 1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004476 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004477
4478 sb.setLength(0);
4479 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004480 sb.append(" Cellular Statistics:");
Amith Yamasanif37447b2009-10-08 18:28:01 -07004481 pw.println(sb.toString());
4482
Siddharth Ray3c648c42017-10-02 17:30:58 -07004483 pw.print(prefix);
4484 sb.setLength(0);
4485 sb.append(prefix);
4486 sb.append(" Cellular kernel active time: ");
4487 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
4488 formatTimeMs(sb, mobileActiveTime / 1000);
4489 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4490 sb.append(")");
4491 pw.println(sb.toString());
4492
4493 pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes));
4494 pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes));
4495 pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets);
4496 pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets);
4497
Dianne Hackborn627bba72009-03-24 22:32:56 -07004498 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004499 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004500 sb.append(" Cellular Radio Access Technology:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004501 didOne = false;
4502 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004503 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004504 if (time == 0) {
4505 continue;
4506 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004507 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004508 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004509 didOne = true;
4510 sb.append(DATA_CONNECTION_NAMES[i]);
4511 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004512 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004513 sb.append("(");
4514 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004515 sb.append(") ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004516 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004517 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004518 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004519
4520 sb.setLength(0);
4521 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004522 sb.append(" Cellular Rx signal strength (RSRP):");
4523 final String[] cellularRxSignalStrengthDescription = new String[]{
4524 "very poor (less than -128dBm): ",
4525 "poor (-128dBm to -118dBm): ",
4526 "moderate (-118dBm to -108dBm): ",
4527 "good (-108dBm to -98dBm): ",
4528 "great (greater than -98dBm): "};
4529 didOne = false;
4530 final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS,
4531 cellularRxSignalStrengthDescription.length);
4532 for (int i=0; i<numCellularRxBins; i++) {
4533 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
4534 if (time == 0) {
4535 continue;
4536 }
4537 sb.append("\n ");
4538 sb.append(prefix);
4539 didOne = true;
4540 sb.append(cellularRxSignalStrengthDescription[i]);
4541 sb.append(" ");
4542 formatTimeMs(sb, time/1000);
4543 sb.append("(");
4544 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4545 sb.append(") ");
4546 }
4547 if (!didOne) sb.append(" (no activity)");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004548 pw.println(sb.toString());
4549
Siddharth Ray3c648c42017-10-02 17:30:58 -07004550 printControllerActivity(pw, sb, prefix, "Cellular",
4551 getModemControllerActivity(), which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004552
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004553 pw.print(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004554 sb.setLength(0);
4555 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004556 sb.append(" Wifi Statistics:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004557 pw.println(sb.toString());
4558
Siddharth Ray3c648c42017-10-02 17:30:58 -07004559 pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes));
4560 pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes));
4561 pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets);
4562 pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets);
4563
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004564 sb.setLength(0);
4565 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004566 sb.append(" Wifi states:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004567 didOne = false;
4568 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004569 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004570 if (time == 0) {
4571 continue;
4572 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004573 sb.append("\n ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004574 didOne = true;
4575 sb.append(WIFI_STATE_NAMES[i]);
4576 sb.append(" ");
4577 formatTimeMs(sb, time/1000);
4578 sb.append("(");
4579 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4580 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004581 }
4582 if (!didOne) sb.append(" (no activity)");
4583 pw.println(sb.toString());
4584
4585 sb.setLength(0);
4586 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004587 sb.append(" Wifi supplicant states:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004588 didOne = false;
4589 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4590 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4591 if (time == 0) {
4592 continue;
4593 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004594 sb.append("\n ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004595 didOne = true;
4596 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4597 sb.append(" ");
4598 formatTimeMs(sb, time/1000);
4599 sb.append("(");
4600 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4601 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004602 }
4603 if (!didOne) sb.append(" (no activity)");
4604 pw.println(sb.toString());
4605
4606 sb.setLength(0);
4607 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004608 sb.append(" Wifi Rx signal strength (RSSI):");
4609 final String[] wifiRxSignalStrengthDescription = new String[]{
4610 "very poor (less than -88.75dBm): ",
4611 "poor (-88.75 to -77.5dBm): ",
4612 "moderate (-77.5dBm to -66.25dBm): ",
4613 "good (-66.25dBm to -55dBm): ",
4614 "great (greater than -55dBm): "};
Dianne Hackborn3251b902014-06-20 14:40:53 -07004615 didOne = false;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004616 final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS,
4617 wifiRxSignalStrengthDescription.length);
4618 for (int i=0; i<numWifiRxBins; i++) {
Dianne Hackborn3251b902014-06-20 14:40:53 -07004619 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4620 if (time == 0) {
4621 continue;
4622 }
4623 sb.append("\n ");
4624 sb.append(prefix);
4625 didOne = true;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004626 sb.append(" ");
4627 sb.append(wifiRxSignalStrengthDescription[i]);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004628 formatTimeMs(sb, time/1000);
4629 sb.append("(");
4630 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4631 sb.append(") ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004632 }
4633 if (!didOne) sb.append(" (no activity)");
4634 pw.println(sb.toString());
4635
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004636 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004637
Adam Lesinski50e47602015-12-04 17:04:54 -08004638 pw.print(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004639 sb.setLength(0);
4640 sb.append(prefix);
4641 sb.append(" CONNECTIVITY POWER SUMMARY END");
4642 pw.println(sb.toString());
4643 pw.println("");
4644
4645 pw.print(prefix);
Adam Lesinski50e47602015-12-04 17:04:54 -08004646 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4647 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4648
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004649 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4650 sb.setLength(0);
4651 sb.append(prefix);
4652 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4653 pw.println(sb.toString());
4654
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004655 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4656 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004657
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004658 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004659
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004660 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004661 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004662 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004663 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004664 pw.println(getDischargeStartLevel());
4665 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4666 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004667 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004668 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004669 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004670 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004671 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004672 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004673 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004674 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004675 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004676 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004677 pw.println(getDischargeAmountScreenOff());
4678 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4679 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004680 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004681 } else {
4682 pw.print(prefix); pw.println(" Device battery use since last full charge");
4683 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004684 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004685 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004686 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004687 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004688 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004689 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004690 pw.println(getDischargeAmountScreenOffSinceCharge());
4691 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4692 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004693 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004694 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004695
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004696 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004697 helper.create(this);
4698 helper.refreshStats(which, UserHandle.USER_ALL);
4699 List<BatterySipper> sippers = helper.getUsageList();
4700 if (sippers != null && sippers.size() > 0) {
4701 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4702 pw.print(prefix); pw.print(" Capacity: ");
4703 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004704 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004705 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4706 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4707 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4708 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004709 pw.println();
4710 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004711 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004712 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004713 switch (bs.drainType) {
4714 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004715 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004716 break;
4717 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004718 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004719 break;
4720 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004721 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004722 break;
4723 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004724 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004725 break;
4726 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004727 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004728 break;
4729 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004730 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004731 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004732 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004733 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004734 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004735 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004736 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004737 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004738 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004739 break;
4740 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004741 pw.print(" User "); pw.print(bs.userId);
4742 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004743 break;
4744 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004745 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004746 break;
4747 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004748 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004749 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004750 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004751 pw.print(" Camera: ");
4752 break;
4753 default:
4754 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004755 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004756 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004757 printmAh(pw, bs.totalPowerMah);
4758
Adam Lesinski57123002015-06-12 16:12:07 -07004759 if (bs.usagePowerMah != bs.totalPowerMah) {
4760 // If the usage (generic power) isn't the whole amount, we list out
4761 // what components are involved in the calculation.
4762
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004763 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004764 if (bs.usagePowerMah != 0) {
4765 pw.print(" usage=");
4766 printmAh(pw, bs.usagePowerMah);
4767 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004768 if (bs.cpuPowerMah != 0) {
4769 pw.print(" cpu=");
4770 printmAh(pw, bs.cpuPowerMah);
4771 }
4772 if (bs.wakeLockPowerMah != 0) {
4773 pw.print(" wake=");
4774 printmAh(pw, bs.wakeLockPowerMah);
4775 }
4776 if (bs.mobileRadioPowerMah != 0) {
4777 pw.print(" radio=");
4778 printmAh(pw, bs.mobileRadioPowerMah);
4779 }
4780 if (bs.wifiPowerMah != 0) {
4781 pw.print(" wifi=");
4782 printmAh(pw, bs.wifiPowerMah);
4783 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004784 if (bs.bluetoothPowerMah != 0) {
4785 pw.print(" bt=");
4786 printmAh(pw, bs.bluetoothPowerMah);
4787 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004788 if (bs.gpsPowerMah != 0) {
4789 pw.print(" gps=");
4790 printmAh(pw, bs.gpsPowerMah);
4791 }
4792 if (bs.sensorPowerMah != 0) {
4793 pw.print(" sensor=");
4794 printmAh(pw, bs.sensorPowerMah);
4795 }
4796 if (bs.cameraPowerMah != 0) {
4797 pw.print(" camera=");
4798 printmAh(pw, bs.cameraPowerMah);
4799 }
4800 if (bs.flashlightPowerMah != 0) {
4801 pw.print(" flash=");
4802 printmAh(pw, bs.flashlightPowerMah);
4803 }
4804 pw.print(" )");
4805 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004806
4807 // If there is additional smearing information, include it.
4808 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4809 pw.print(" Including smearing: ");
4810 printmAh(pw, bs.totalSmearedPowerMah);
4811 pw.print(" (");
4812 if (bs.screenPowerMah != 0) {
4813 pw.print(" screen=");
4814 printmAh(pw, bs.screenPowerMah);
4815 }
4816 if (bs.proportionalSmearMah != 0) {
4817 pw.print(" proportional=");
4818 printmAh(pw, bs.proportionalSmearMah);
4819 }
4820 pw.print(" )");
4821 }
4822 if (bs.shouldHide) {
4823 pw.print(" Excluded from smearing");
4824 }
4825
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004826 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004827 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004828 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004829 }
4830
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004831 sippers = helper.getMobilemsppList();
4832 if (sippers != null && sippers.size() > 0) {
4833 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004834 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004835 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004836 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004837 sb.setLength(0);
4838 sb.append(prefix); sb.append(" Uid ");
4839 UserHandle.formatUid(sb, bs.uidObj.getUid());
4840 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4841 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4842 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004843 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004844 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004845 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004846 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004847 sb.setLength(0);
4848 sb.append(prefix);
4849 sb.append(" TOTAL TIME: ");
4850 formatTimeMs(sb, totalTime);
4851 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4852 sb.append(")");
4853 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004854 pw.println();
4855 }
4856
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004857 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4858 @Override
4859 public int compare(TimerEntry lhs, TimerEntry rhs) {
4860 long lhsTime = lhs.mTime;
4861 long rhsTime = rhs.mTime;
4862 if (lhsTime < rhsTime) {
4863 return 1;
4864 }
4865 if (lhsTime > rhsTime) {
4866 return -1;
4867 }
4868 return 0;
4869 }
4870 };
4871
4872 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004873 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4874 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004875 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004876 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4877 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4878 : kernelWakelocks.entrySet()) {
4879 final BatteryStats.Timer timer = ent.getValue();
4880 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004881 if (totalTimeMillis > 0) {
4882 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4883 }
4884 }
4885 if (ktimers.size() > 0) {
4886 Collections.sort(ktimers, timerComparator);
4887 pw.print(prefix); pw.println(" All kernel wake locks:");
4888 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004889 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004890 String linePrefix = ": ";
4891 sb.setLength(0);
4892 sb.append(prefix);
4893 sb.append(" Kernel Wake lock ");
4894 sb.append(timer.mName);
4895 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4896 which, linePrefix);
4897 if (!linePrefix.equals(": ")) {
4898 sb.append(" realtime");
4899 // Only print out wake locks that were held
4900 pw.println(sb.toString());
4901 }
4902 }
4903 pw.println();
4904 }
4905 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004906
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004907 if (timers.size() > 0) {
4908 Collections.sort(timers, timerComparator);
4909 pw.print(prefix); pw.println(" All partial wake locks:");
4910 for (int i=0; i<timers.size(); i++) {
4911 TimerEntry timer = timers.get(i);
4912 sb.setLength(0);
4913 sb.append(" Wake lock ");
4914 UserHandle.formatUid(sb, timer.mId);
4915 sb.append(" ");
4916 sb.append(timer.mName);
4917 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4918 sb.append(" realtime");
4919 pw.println(sb.toString());
4920 }
4921 timers.clear();
4922 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004923 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004924
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004925 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004926 if (wakeupReasons.size() > 0) {
4927 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004928 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004929 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004930 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004931 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4932 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004933 }
4934 Collections.sort(reasons, timerComparator);
4935 for (int i=0; i<reasons.size(); i++) {
4936 TimerEntry timer = reasons.get(i);
4937 String linePrefix = ": ";
4938 sb.setLength(0);
4939 sb.append(prefix);
4940 sb.append(" Wakeup reason ");
4941 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004942 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4943 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004944 pw.println(sb.toString());
4945 }
4946 pw.println();
4947 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004948 }
Evan Millar22ac0432009-03-31 11:33:18 -07004949
James Carr2dd7e5e2016-07-20 18:48:39 -07004950 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004951 if (mMemoryStats.size() > 0) {
4952 pw.println(" Memory Stats");
4953 for (int i = 0; i < mMemoryStats.size(); i++) {
4954 sb.setLength(0);
4955 sb.append(" Bandwidth ");
4956 sb.append(mMemoryStats.keyAt(i));
4957 sb.append(" Time ");
4958 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4959 pw.println(sb.toString());
4960 }
4961 pw.println();
4962 }
4963
4964 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4965 if (rpmStats.size() > 0) {
4966 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4967 if (rpmStats.size() > 0) {
4968 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4969 final String timerName = ent.getKey();
4970 final Timer timer = ent.getValue();
4971 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4972 }
4973 }
4974 pw.println();
4975 }
Bookatz82b341172017-09-07 19:06:08 -07004976 if (SCREEN_OFF_RPM_STATS_ENABLED) {
4977 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07004978 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07004979 pw.print(prefix);
4980 pw.println(" Resource Power Manager Stats for when screen was off");
4981 if (screenOffRpmStats.size() > 0) {
4982 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4983 final String timerName = ent.getKey();
4984 final Timer timer = ent.getValue();
4985 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4986 }
Bookatz50df7112017-08-04 14:53:26 -07004987 }
Bookatz82b341172017-09-07 19:06:08 -07004988 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07004989 }
James Carr2dd7e5e2016-07-20 18:48:39 -07004990 }
4991
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004992 final long[] cpuFreqs = getCpuFreqs();
4993 if (cpuFreqs != null) {
4994 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004995 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004996 for (int i = 0; i < cpuFreqs.length; ++i) {
4997 sb.append(" " + cpuFreqs[i]);
4998 }
4999 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07005000 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005001 }
5002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003 for (int iu=0; iu<NU; iu++) {
5004 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005005 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08005006 continue;
5007 }
Bookatzc8c44962017-05-11 12:12:54 -07005008
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005009 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07005010
5011 pw.print(prefix);
5012 pw.print(" ");
5013 UserHandle.formatUid(pw, uid);
5014 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005015 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005016
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005017 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
5018 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
5019 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
5020 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005021 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
5022 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
5023
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005024 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
5025 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005026 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
5027 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005028
5029 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
5030 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
5031
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005032 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
5033 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
5034 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08005035 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
5036 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5037 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
5038 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005039 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005040
Adam Lesinski5f056f62016-07-14 16:56:08 -07005041 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
5042 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
5043
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005044 if (mobileRxBytes > 0 || mobileTxBytes > 0
5045 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005046 pw.print(prefix); pw.print(" Mobile network: ");
5047 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005048 pw.print(formatBytesLocked(mobileTxBytes));
5049 pw.print(" sent (packets "); pw.print(mobileRxPackets);
5050 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005051 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005052 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
5053 sb.setLength(0);
5054 sb.append(prefix); sb.append(" Mobile radio active: ");
5055 formatTimeMs(sb, uidMobileActiveTime / 1000);
5056 sb.append("(");
5057 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
5058 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
5059 long packets = mobileRxPackets + mobileTxPackets;
5060 if (packets == 0) {
5061 packets = 1;
5062 }
5063 sb.append(" @ ");
5064 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
5065 sb.append(" mspp");
5066 pw.println(sb.toString());
5067 }
5068
Adam Lesinski5f056f62016-07-14 16:56:08 -07005069 if (mobileWakeup > 0) {
5070 sb.setLength(0);
5071 sb.append(prefix);
5072 sb.append(" Mobile radio AP wakeups: ");
5073 sb.append(mobileWakeup);
5074 pw.println(sb.toString());
5075 }
5076
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005077 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
5078 u.getModemControllerActivity(), which);
5079
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005080 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005081 pw.print(prefix); pw.print(" Wi-Fi network: ");
5082 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005083 pw.print(formatBytesLocked(wifiTxBytes));
5084 pw.print(" sent (packets "); pw.print(wifiRxPackets);
5085 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005086 }
5087
Dianne Hackborn62793e42015-03-09 11:15:41 -07005088 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08005089 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005090 || uidWifiRunningTime != 0) {
5091 sb.setLength(0);
5092 sb.append(prefix); sb.append(" Wifi Running: ");
5093 formatTimeMs(sb, uidWifiRunningTime / 1000);
5094 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
5095 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07005096 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005097 formatTimeMs(sb, fullWifiLockOnTime / 1000);
5098 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
5099 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08005100 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005101 formatTimeMs(sb, wifiScanTime / 1000);
5102 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07005103 whichBatteryRealtime)); sb.append(") ");
5104 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08005105 sb.append("x\n");
5106 // actual and background times are unpooled and since reset (regardless of 'which')
5107 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
5108 formatTimeMs(sb, wifiScanActualTime / 1000);
5109 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
5110 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5111 sb.append(") ");
5112 sb.append(wifiScanCount);
5113 sb.append("x\n");
5114 sb.append(prefix); sb.append(" Background Wifi Scan: ");
5115 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
5116 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
5117 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5118 sb.append(") ");
5119 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07005120 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005121 pw.println(sb.toString());
5122 }
5123
Adam Lesinski5f056f62016-07-14 16:56:08 -07005124 if (wifiWakeup > 0) {
5125 sb.setLength(0);
5126 sb.append(prefix);
5127 sb.append(" WiFi AP wakeups: ");
5128 sb.append(wifiWakeup);
5129 pw.println(sb.toString());
5130 }
5131
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005132 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
5133 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07005134
Adam Lesinski50e47602015-12-04 17:04:54 -08005135 if (btRxBytes > 0 || btTxBytes > 0) {
5136 pw.print(prefix); pw.print(" Bluetooth network: ");
5137 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
5138 pw.print(formatBytesLocked(btTxBytes));
5139 pw.println(" sent");
5140 }
5141
Bookatz867c0d72017-03-07 18:23:42 -08005142 final Timer bleTimer = u.getBluetoothScanTimer();
5143 if (bleTimer != null) {
5144 // Convert from microseconds to milliseconds with rounding
5145 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
5146 / 1000;
5147 if (totalTimeMs != 0) {
5148 final int count = bleTimer.getCountLocked(which);
5149 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
5150 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005151 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5152 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
5153 final long actualTimeMsBg = bleTimerBg != null ?
5154 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005155 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07005156 final int resultCount = u.getBluetoothScanResultCounter() != null ?
5157 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005158 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
5159 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
5160 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
5161 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
5162 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
5163 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5164 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
5165 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
5166 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
5167 final Timer unoptimizedScanTimerBg =
5168 u.getBluetoothUnoptimizedScanBackgroundTimer();
5169 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
5170 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5171 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
5172 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005173
5174 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08005175 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07005176 sb.append(prefix);
5177 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08005178 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07005179 sb.append(" (");
5180 sb.append(count);
5181 sb.append(" times)");
5182 if (bleTimer.isRunningLocked()) {
5183 sb.append(" (currently running)");
5184 }
5185 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005186 }
Bookatzb1f04f32017-05-19 13:57:32 -07005187
5188 sb.append(prefix);
5189 sb.append(" Bluetooth Scan (total actual realtime): ");
5190 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
5191 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005192 sb.append(count);
5193 sb.append(" times)");
5194 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07005195 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08005196 }
Bookatzb1f04f32017-05-19 13:57:32 -07005197 sb.append("\n");
5198 if (actualTimeMsBg > 0 || countBg > 0) {
5199 sb.append(prefix);
5200 sb.append(" Bluetooth Scan (background realtime): ");
5201 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
5202 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005203 sb.append(countBg);
5204 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07005205 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
5206 sb.append(" (currently running in background)");
5207 }
5208 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005209 }
Bookatzb1f04f32017-05-19 13:57:32 -07005210
5211 sb.append(prefix);
5212 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07005213 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07005214 sb.append(" (");
5215 sb.append(resultCountBg);
5216 sb.append(" in background)");
5217
5218 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
5219 sb.append("\n");
5220 sb.append(prefix);
5221 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
5222 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
5223 sb.append(" (max ");
5224 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
5225 sb.append(")");
5226 if (unoptimizedScanTimer != null
5227 && unoptimizedScanTimer.isRunningLocked()) {
5228 sb.append(" (currently running unoptimized)");
5229 }
5230 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
5231 sb.append("\n");
5232 sb.append(prefix);
5233 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
5234 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
5235 sb.append(" (max ");
5236 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
5237 sb.append(")");
5238 if (unoptimizedScanTimerBg.isRunningLocked()) {
5239 sb.append(" (currently running unoptimized in background)");
5240 }
5241 }
5242 }
Bookatz867c0d72017-03-07 18:23:42 -08005243 pw.println(sb.toString());
5244 uidActivity = true;
5245 }
5246 }
5247
5248
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005249
Dianne Hackborn617f8772009-03-31 15:04:46 -07005250 if (u.hasUserActivity()) {
5251 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07005252 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005253 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07005254 if (val != 0) {
5255 if (!hasData) {
5256 sb.setLength(0);
5257 sb.append(" User activity: ");
5258 hasData = true;
5259 } else {
5260 sb.append(", ");
5261 }
5262 sb.append(val);
5263 sb.append(" ");
5264 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
5265 }
5266 }
5267 if (hasData) {
5268 pw.println(sb.toString());
5269 }
5270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005272 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5273 = u.getWakelockStats();
5274 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005275 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005276 int countWakelock = 0;
5277 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5278 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5279 String linePrefix = ": ";
5280 sb.setLength(0);
5281 sb.append(prefix);
5282 sb.append(" Wake lock ");
5283 sb.append(wakelocks.keyAt(iw));
5284 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5285 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005286 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5287 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005288 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005289 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5290 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005291 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5292 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005293 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5294 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005295 sb.append(" realtime");
5296 pw.println(sb.toString());
5297 uidActivity = true;
5298 countWakelock++;
5299
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005300 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5301 rawRealtime, which);
5302 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5303 rawRealtime, which);
5304 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5305 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005306 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005307 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005308 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005309 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005310 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5311 // pooled and therefore just a lower bound)
5312 long actualTotalPartialWakelock = 0;
5313 long actualBgPartialWakelock = 0;
5314 if (u.getAggregatedPartialWakelockTimer() != null) {
5315 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5316 // Convert from microseconds to milliseconds with rounding
5317 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005318 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005319 final Timer bgAggTimer = aggTimer.getSubTimer();
5320 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005321 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005322 }
5323
5324 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5325 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5326 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005327 sb.setLength(0);
5328 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005329 sb.append(" TOTAL wake: ");
5330 boolean needComma = false;
5331 if (totalFullWakelock != 0) {
5332 needComma = true;
5333 formatTimeMs(sb, totalFullWakelock);
5334 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005335 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005336 if (totalPartialWakelock != 0) {
5337 if (needComma) {
5338 sb.append(", ");
5339 }
5340 needComma = true;
5341 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005342 sb.append("blamed partial");
5343 }
5344 if (actualTotalPartialWakelock != 0) {
5345 if (needComma) {
5346 sb.append(", ");
5347 }
5348 needComma = true;
5349 formatTimeMs(sb, actualTotalPartialWakelock);
5350 sb.append("actual partial");
5351 }
5352 if (actualBgPartialWakelock != 0) {
5353 if (needComma) {
5354 sb.append(", ");
5355 }
5356 needComma = true;
5357 formatTimeMs(sb, actualBgPartialWakelock);
5358 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005359 }
5360 if (totalWindowWakelock != 0) {
5361 if (needComma) {
5362 sb.append(", ");
5363 }
5364 needComma = true;
5365 formatTimeMs(sb, totalWindowWakelock);
5366 sb.append("window");
5367 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005368 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005369 if (needComma) {
5370 sb.append(",");
5371 }
5372 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005373 formatTimeMs(sb, totalDrawWakelock);
5374 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005375 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005376 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005377 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005378 }
5379 }
5380
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07005381 // Calculate multicast wakelock stats
5382 final Timer mcTimer = u.getMulticastWakelockStats();
5383 if (mcTimer != null) {
5384 final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which);
5385 final int multicastWakeLockCount = mcTimer.getCountLocked(which);
5386
5387 if (multicastWakeLockTimeMicros > 0) {
5388 sb.setLength(0);
5389 sb.append(prefix);
5390 sb.append(" WiFi Multicast Wakelock");
5391 sb.append(" count = ");
5392 sb.append(multicastWakeLockCount);
5393 sb.append(" time = ");
5394 formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000);
5395 pw.println(sb.toString());
5396 }
5397 }
5398
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005399 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5400 for (int isy=syncs.size()-1; isy>=0; isy--) {
5401 final Timer timer = syncs.valueAt(isy);
5402 // Convert from microseconds to milliseconds with rounding
5403 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5404 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005405 final Timer bgTimer = timer.getSubTimer();
5406 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005407 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005408 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005409 sb.setLength(0);
5410 sb.append(prefix);
5411 sb.append(" Sync ");
5412 sb.append(syncs.keyAt(isy));
5413 sb.append(": ");
5414 if (totalTime != 0) {
5415 formatTimeMs(sb, totalTime);
5416 sb.append("realtime (");
5417 sb.append(count);
5418 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005419 if (bgTime > 0) {
5420 sb.append(", ");
5421 formatTimeMs(sb, bgTime);
5422 sb.append("background (");
5423 sb.append(bgCount);
5424 sb.append(" times)");
5425 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005426 } else {
5427 sb.append("(not used)");
5428 }
5429 pw.println(sb.toString());
5430 uidActivity = true;
5431 }
5432
5433 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5434 for (int ij=jobs.size()-1; ij>=0; ij--) {
5435 final Timer timer = jobs.valueAt(ij);
5436 // Convert from microseconds to milliseconds with rounding
5437 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5438 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005439 final Timer bgTimer = timer.getSubTimer();
5440 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005441 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005442 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005443 sb.setLength(0);
5444 sb.append(prefix);
5445 sb.append(" Job ");
5446 sb.append(jobs.keyAt(ij));
5447 sb.append(": ");
5448 if (totalTime != 0) {
5449 formatTimeMs(sb, totalTime);
5450 sb.append("realtime (");
5451 sb.append(count);
5452 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005453 if (bgTime > 0) {
5454 sb.append(", ");
5455 formatTimeMs(sb, bgTime);
5456 sb.append("background (");
5457 sb.append(bgCount);
5458 sb.append(" times)");
5459 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005460 } else {
5461 sb.append("(not used)");
5462 }
5463 pw.println(sb.toString());
5464 uidActivity = true;
5465 }
5466
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005467 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5468 for (int ic=completions.size()-1; ic>=0; ic--) {
5469 SparseIntArray types = completions.valueAt(ic);
5470 if (types != null) {
5471 pw.print(prefix);
5472 pw.print(" Job Completions ");
5473 pw.print(completions.keyAt(ic));
5474 pw.print(":");
5475 for (int it=0; it<types.size(); it++) {
5476 pw.print(" ");
5477 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5478 pw.print("(");
5479 pw.print(types.valueAt(it));
5480 pw.print("x)");
5481 }
5482 pw.println();
5483 }
5484 }
5485
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005486 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5487 prefix, "Flashlight");
5488 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5489 prefix, "Camera");
5490 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5491 prefix, "Video");
5492 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5493 prefix, "Audio");
5494
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005495 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5496 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005497 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005498 final Uid.Sensor se = sensors.valueAt(ise);
5499 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005500 sb.setLength(0);
5501 sb.append(prefix);
5502 sb.append(" Sensor ");
5503 int handle = se.getHandle();
5504 if (handle == Uid.Sensor.GPS) {
5505 sb.append("GPS");
5506 } else {
5507 sb.append(handle);
5508 }
5509 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005511 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005512 if (timer != null) {
5513 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005514 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5515 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005516 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005517 final Timer bgTimer = se.getSensorBackgroundTime();
5518 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005519 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5520 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5521 final long bgActualTime = bgTimer != null ?
5522 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5523
Dianne Hackborn61659e52014-07-09 16:13:01 -07005524 //timer.logState();
5525 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005526 if (actualTime != totalTime) {
5527 formatTimeMs(sb, totalTime);
5528 sb.append("blamed realtime, ");
5529 }
5530
5531 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005532 sb.append("realtime (");
5533 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005534 sb.append(" times)");
5535
5536 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005537 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005538 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5539 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005540 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005541 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005543 } else {
5544 sb.append("(not used)");
5545 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005546 } else {
5547 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005548 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005549
5550 pw.println(sb.toString());
5551 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552 }
5553
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005554 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5555 "Vibrator");
5556 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5557 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005558 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5559 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005560
Dianne Hackborn61659e52014-07-09 16:13:01 -07005561 long totalStateTime = 0;
5562 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5563 long time = u.getProcessStateTime(ips, rawRealtime, which);
5564 if (time > 0) {
5565 totalStateTime += time;
5566 sb.setLength(0);
5567 sb.append(prefix);
5568 sb.append(" ");
5569 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5570 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005571 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005572 pw.println(sb.toString());
5573 uidActivity = true;
5574 }
5575 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005576 if (totalStateTime > 0) {
5577 sb.setLength(0);
5578 sb.append(prefix);
5579 sb.append(" Total running: ");
5580 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5581 pw.println(sb.toString());
5582 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005583
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005584 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5585 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005586 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005587 sb.setLength(0);
5588 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005589 sb.append(" Total cpu time: u=");
5590 formatTimeMs(sb, userCpuTimeUs / 1000);
5591 sb.append("s=");
5592 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005593 pw.println(sb.toString());
5594 }
5595
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005596 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5597 if (cpuFreqTimes != null) {
5598 sb.setLength(0);
5599 sb.append(" Total cpu time per freq:");
5600 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5601 sb.append(" " + cpuFreqTimes[i]);
5602 }
5603 pw.println(sb.toString());
5604 }
5605 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5606 if (screenOffCpuFreqTimes != null) {
5607 sb.setLength(0);
5608 sb.append(" Total screen-off cpu time per freq:");
5609 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5610 sb.append(" " + screenOffCpuFreqTimes[i]);
5611 }
5612 pw.println(sb.toString());
5613 }
5614
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005615 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5616 = u.getProcessStats();
5617 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5618 final Uid.Proc ps = processStats.valueAt(ipr);
5619 long userTime;
5620 long systemTime;
5621 long foregroundTime;
5622 int starts;
5623 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005624
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005625 userTime = ps.getUserTime(which);
5626 systemTime = ps.getSystemTime(which);
5627 foregroundTime = ps.getForegroundTime(which);
5628 starts = ps.getStarts(which);
5629 final int numCrashes = ps.getNumCrashes(which);
5630 final int numAnrs = ps.getNumAnrs(which);
5631 numExcessive = which == STATS_SINCE_CHARGED
5632 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005633
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005634 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5635 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5636 sb.setLength(0);
5637 sb.append(prefix); sb.append(" Proc ");
5638 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5639 sb.append(prefix); sb.append(" CPU: ");
5640 formatTimeMs(sb, userTime); sb.append("usr + ");
5641 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5642 formatTimeMs(sb, foregroundTime); sb.append("fg");
5643 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5644 sb.append("\n"); sb.append(prefix); sb.append(" ");
5645 boolean hasOne = false;
5646 if (starts != 0) {
5647 hasOne = true;
5648 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005649 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005650 if (numCrashes != 0) {
5651 if (hasOne) {
5652 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005653 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005654 hasOne = true;
5655 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005656 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005657 if (numAnrs != 0) {
5658 if (hasOne) {
5659 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005660 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005661 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 }
5663 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005664 pw.println(sb.toString());
5665 for (int e=0; e<numExcessive; e++) {
5666 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5667 if (ew != null) {
5668 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005669 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005670 pw.print("cpu");
5671 } else {
5672 pw.print("unknown");
5673 }
5674 pw.print(" use: ");
5675 TimeUtils.formatDuration(ew.usedTime, pw);
5676 pw.print(" over ");
5677 TimeUtils.formatDuration(ew.overTime, pw);
5678 if (ew.overTime != 0) {
5679 pw.print(" (");
5680 pw.print((ew.usedTime*100)/ew.overTime);
5681 pw.println("%)");
5682 }
5683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005684 }
5685 uidActivity = true;
5686 }
5687 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005688
5689 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5690 = u.getPackageStats();
5691 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5692 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5693 pw.println(":");
5694 boolean apkActivity = false;
5695 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5696 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5697 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5698 pw.print(prefix); pw.print(" Wakeup alarm ");
5699 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5700 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5701 pw.println(" times");
5702 apkActivity = true;
5703 }
5704 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5705 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5706 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5707 final long startTime = ss.getStartTime(batteryUptime, which);
5708 final int starts = ss.getStarts(which);
5709 final int launches = ss.getLaunches(which);
5710 if (startTime != 0 || starts != 0 || launches != 0) {
5711 sb.setLength(0);
5712 sb.append(prefix); sb.append(" Service ");
5713 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5714 sb.append(prefix); sb.append(" Created for: ");
5715 formatTimeMs(sb, startTime / 1000);
5716 sb.append("uptime\n");
5717 sb.append(prefix); sb.append(" Starts: ");
5718 sb.append(starts);
5719 sb.append(", launches: "); sb.append(launches);
5720 pw.println(sb.toString());
5721 apkActivity = true;
5722 }
5723 }
5724 if (!apkActivity) {
5725 pw.print(prefix); pw.println(" (nothing executed)");
5726 }
5727 uidActivity = true;
5728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005729 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005730 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 }
5732 }
5733 }
5734
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005735 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005736 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005737 int diff = oldval ^ newval;
5738 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005739 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005740 for (int i=0; i<descriptions.length; i++) {
5741 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005742 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005743 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005744 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005745 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005746 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005747 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5748 didWake = true;
5749 pw.print("=");
5750 if (longNames) {
5751 UserHandle.formatUid(pw, wakelockTag.uid);
5752 pw.print(":\"");
5753 pw.print(wakelockTag.string);
5754 pw.print("\"");
5755 } else {
5756 pw.print(wakelockTag.poolIdx);
5757 }
5758 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005759 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005760 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005761 pw.print("=");
5762 int val = (newval&bd.mask)>>bd.shift;
5763 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005764 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005765 } else {
5766 pw.print(val);
5767 }
5768 }
5769 }
5770 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005771 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005772 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005773 if (longNames) {
5774 UserHandle.formatUid(pw, wakelockTag.uid);
5775 pw.print(":\"");
5776 pw.print(wakelockTag.string);
5777 pw.print("\"");
5778 } else {
5779 pw.print(wakelockTag.poolIdx);
5780 }
5781 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005782 }
Mike Mac2f518a2017-09-19 16:06:03 -07005783
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005784 public void prepareForDumpLocked() {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07005785 // We don't need to require subclasses implement this.
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005786 }
5787
5788 public static class HistoryPrinter {
5789 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005790 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005791 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005792 int oldStatus = -1;
5793 int oldHealth = -1;
5794 int oldPlug = -1;
5795 int oldTemp = -1;
5796 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005797 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005798 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005799
Dianne Hackborn3251b902014-06-20 14:40:53 -07005800 void reset() {
5801 oldState = oldState2 = 0;
5802 oldLevel = -1;
5803 oldStatus = -1;
5804 oldHealth = -1;
5805 oldPlug = -1;
5806 oldTemp = -1;
5807 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005808 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005809 }
5810
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005811 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005812 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005813 if (!checkin) {
5814 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005815 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005816 pw.print(" (");
5817 pw.print(rec.numReadInts);
5818 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005819 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005820 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5821 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005822 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005823 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005824 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005825 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005826 }
5827 lastTime = rec.time;
5828 }
5829 if (rec.cmd == HistoryItem.CMD_START) {
5830 if (checkin) {
5831 pw.print(":");
5832 }
5833 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005834 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005835 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5836 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005837 if (checkin) {
5838 pw.print(":");
5839 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005840 if (rec.cmd == HistoryItem.CMD_RESET) {
5841 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005842 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005843 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005844 pw.print("TIME:");
5845 if (checkin) {
5846 pw.println(rec.currentTime);
5847 } else {
5848 pw.print(" ");
5849 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5850 rec.currentTime).toString());
5851 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005852 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5853 if (checkin) {
5854 pw.print(":");
5855 }
5856 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005857 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5858 if (checkin) {
5859 pw.print(":");
5860 }
5861 pw.println("*OVERFLOW*");
5862 } else {
5863 if (!checkin) {
5864 if (rec.batteryLevel < 10) pw.print("00");
5865 else if (rec.batteryLevel < 100) pw.print("0");
5866 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005867 if (verbose) {
5868 pw.print(" ");
5869 if (rec.states < 0) ;
5870 else if (rec.states < 0x10) pw.print("0000000");
5871 else if (rec.states < 0x100) pw.print("000000");
5872 else if (rec.states < 0x1000) pw.print("00000");
5873 else if (rec.states < 0x10000) pw.print("0000");
5874 else if (rec.states < 0x100000) pw.print("000");
5875 else if (rec.states < 0x1000000) pw.print("00");
5876 else if (rec.states < 0x10000000) pw.print("0");
5877 pw.print(Integer.toHexString(rec.states));
5878 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005879 } else {
5880 if (oldLevel != rec.batteryLevel) {
5881 oldLevel = rec.batteryLevel;
5882 pw.print(",Bl="); pw.print(rec.batteryLevel);
5883 }
5884 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005885 if (oldStatus != rec.batteryStatus) {
5886 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005887 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005888 switch (oldStatus) {
5889 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005890 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005891 break;
5892 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005893 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005894 break;
5895 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005896 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005897 break;
5898 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005899 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005900 break;
5901 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005902 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005903 break;
5904 default:
5905 pw.print(oldStatus);
5906 break;
5907 }
5908 }
5909 if (oldHealth != rec.batteryHealth) {
5910 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005911 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005912 switch (oldHealth) {
5913 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005914 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005915 break;
5916 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005917 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005918 break;
5919 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005920 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005921 break;
5922 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005923 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005924 break;
5925 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005926 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005927 break;
5928 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005929 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005930 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005931 case BatteryManager.BATTERY_HEALTH_COLD:
5932 pw.print(checkin ? "c" : "cold");
5933 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005934 default:
5935 pw.print(oldHealth);
5936 break;
5937 }
5938 }
5939 if (oldPlug != rec.batteryPlugType) {
5940 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005941 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005942 switch (oldPlug) {
5943 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005944 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005945 break;
5946 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005947 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005948 break;
5949 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005950 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005951 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005952 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005953 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005954 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005955 default:
5956 pw.print(oldPlug);
5957 break;
5958 }
5959 }
5960 if (oldTemp != rec.batteryTemperature) {
5961 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005962 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005963 pw.print(oldTemp);
5964 }
5965 if (oldVolt != rec.batteryVoltage) {
5966 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005967 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005968 pw.print(oldVolt);
5969 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005970 final int chargeMAh = rec.batteryChargeUAh / 1000;
5971 if (oldChargeMAh != chargeMAh) {
5972 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005973 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005974 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005975 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005976 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005977 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005978 printBitDescriptions(pw, oldState2, rec.states2, null,
5979 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005980 if (rec.wakeReasonTag != null) {
5981 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005982 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005983 pw.print(rec.wakeReasonTag.poolIdx);
5984 } else {
5985 pw.print(" wake_reason=");
5986 pw.print(rec.wakeReasonTag.uid);
5987 pw.print(":\"");
5988 pw.print(rec.wakeReasonTag.string);
5989 pw.print("\"");
5990 }
5991 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005992 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005993 pw.print(checkin ? "," : " ");
5994 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5995 pw.print("+");
5996 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5997 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005998 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005999 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
6000 : HISTORY_EVENT_NAMES;
6001 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
6002 | HistoryItem.EVENT_FLAG_FINISH);
6003 if (idx >= 0 && idx < eventNames.length) {
6004 pw.print(eventNames[idx]);
6005 } else {
6006 pw.print(checkin ? "Ev" : "event");
6007 pw.print(idx);
6008 }
6009 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006010 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006011 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08006012 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08006013 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
6014 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006015 pw.print(":\"");
6016 pw.print(rec.eventTag.string);
6017 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006018 }
6019 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006020 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006021 if (rec.stepDetails != null) {
6022 if (!checkin) {
6023 pw.print(" Details: cpu=");
6024 pw.print(rec.stepDetails.userTime);
6025 pw.print("u+");
6026 pw.print(rec.stepDetails.systemTime);
6027 pw.print("s");
6028 if (rec.stepDetails.appCpuUid1 >= 0) {
6029 pw.print(" (");
6030 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
6031 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6032 if (rec.stepDetails.appCpuUid2 >= 0) {
6033 pw.print(", ");
6034 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
6035 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6036 }
6037 if (rec.stepDetails.appCpuUid3 >= 0) {
6038 pw.print(", ");
6039 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
6040 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6041 }
6042 pw.print(')');
6043 }
6044 pw.println();
6045 pw.print(" /proc/stat=");
6046 pw.print(rec.stepDetails.statUserTime);
6047 pw.print(" usr, ");
6048 pw.print(rec.stepDetails.statSystemTime);
6049 pw.print(" sys, ");
6050 pw.print(rec.stepDetails.statIOWaitTime);
6051 pw.print(" io, ");
6052 pw.print(rec.stepDetails.statIrqTime);
6053 pw.print(" irq, ");
6054 pw.print(rec.stepDetails.statSoftIrqTime);
6055 pw.print(" sirq, ");
6056 pw.print(rec.stepDetails.statIdlTime);
6057 pw.print(" idle");
6058 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
6059 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
6060 + rec.stepDetails.statSoftIrqTime;
6061 int total = totalRun + rec.stepDetails.statIdlTime;
6062 if (total > 0) {
6063 pw.print(" (");
6064 float perc = ((float)totalRun) / ((float)total) * 100;
6065 pw.print(String.format("%.1f%%", perc));
6066 pw.print(" of ");
6067 StringBuilder sb = new StringBuilder(64);
6068 formatTimeMsNoSpace(sb, total*10);
6069 pw.print(sb);
6070 pw.print(")");
6071 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006072 pw.print(", PlatformIdleStat ");
6073 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006074 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006075
6076 pw.print(", SubsystemPowerState ");
6077 pw.print(rec.stepDetails.statSubsystemPowerState);
6078 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006079 } else {
6080 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6081 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
6082 pw.print(rec.stepDetails.userTime);
6083 pw.print(":");
6084 pw.print(rec.stepDetails.systemTime);
6085 if (rec.stepDetails.appCpuUid1 >= 0) {
6086 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
6087 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6088 if (rec.stepDetails.appCpuUid2 >= 0) {
6089 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
6090 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6091 }
6092 if (rec.stepDetails.appCpuUid3 >= 0) {
6093 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
6094 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6095 }
6096 }
6097 pw.println();
6098 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6099 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
6100 pw.print(rec.stepDetails.statUserTime);
6101 pw.print(',');
6102 pw.print(rec.stepDetails.statSystemTime);
6103 pw.print(',');
6104 pw.print(rec.stepDetails.statIOWaitTime);
6105 pw.print(',');
6106 pw.print(rec.stepDetails.statIrqTime);
6107 pw.print(',');
6108 pw.print(rec.stepDetails.statSoftIrqTime);
6109 pw.print(',');
6110 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006111 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006112 if (rec.stepDetails.statPlatformIdleState != null) {
6113 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07006114 if (rec.stepDetails.statSubsystemPowerState != null) {
6115 pw.print(',');
6116 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006117 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006118
6119 if (rec.stepDetails.statSubsystemPowerState != null) {
6120 pw.print(rec.stepDetails.statSubsystemPowerState);
6121 }
6122 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006123 }
6124 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006125 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006126 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006127 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006128 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006129
6130 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
6131 UserHandle.formatUid(pw, uid);
6132 pw.print("=");
6133 pw.print(utime);
6134 pw.print("u+");
6135 pw.print(stime);
6136 pw.print("s");
6137 }
6138
6139 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
6140 pw.print('/');
6141 pw.print(uid);
6142 pw.print(":");
6143 pw.print(utime);
6144 pw.print(":");
6145 pw.print(stime);
6146 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006147 }
6148
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006149 private void printSizeValue(PrintWriter pw, long size) {
6150 float result = size;
6151 String suffix = "";
6152 if (result >= 10*1024) {
6153 suffix = "KB";
6154 result = result / 1024;
6155 }
6156 if (result >= 10*1024) {
6157 suffix = "MB";
6158 result = result / 1024;
6159 }
6160 if (result >= 10*1024) {
6161 suffix = "GB";
6162 result = result / 1024;
6163 }
6164 if (result >= 10*1024) {
6165 suffix = "TB";
6166 result = result / 1024;
6167 }
6168 if (result >= 10*1024) {
6169 suffix = "PB";
6170 result = result / 1024;
6171 }
6172 pw.print((int)result);
6173 pw.print(suffix);
6174 }
6175
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006176 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
6177 String label3, long estimatedTime) {
6178 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006179 return false;
6180 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006181 pw.print(label1);
6182 pw.print(label2);
6183 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006184 StringBuilder sb = new StringBuilder(64);
6185 formatTimeMs(sb, estimatedTime);
6186 pw.print(sb);
6187 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006188 return true;
6189 }
6190
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006191 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
6192 LevelStepTracker steps, boolean checkin) {
6193 if (steps == null) {
6194 return false;
6195 }
6196 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006197 if (count <= 0) {
6198 return false;
6199 }
6200 if (!checkin) {
6201 pw.println(header);
6202 }
Kweku Adams030980a2015-04-01 16:07:48 -07006203 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006204 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006205 long duration = steps.getDurationAt(i);
6206 int level = steps.getLevelAt(i);
6207 long initMode = steps.getInitModeAt(i);
6208 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006209 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006210 lineArgs[0] = Long.toString(duration);
6211 lineArgs[1] = Integer.toString(level);
6212 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6213 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6214 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
6215 case Display.STATE_ON: lineArgs[2] = "s+"; break;
6216 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
6217 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07006218 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006219 }
6220 } else {
6221 lineArgs[2] = "";
6222 }
6223 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6224 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
6225 } else {
6226 lineArgs[3] = "";
6227 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006228 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07006229 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006230 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07006231 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006232 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006233 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
6234 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006235 pw.print(prefix);
6236 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006237 TimeUtils.formatDuration(duration, pw);
6238 pw.print(" to "); pw.print(level);
6239 boolean haveModes = false;
6240 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6241 pw.print(" (");
6242 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6243 case Display.STATE_OFF: pw.print("screen-off"); break;
6244 case Display.STATE_ON: pw.print("screen-on"); break;
6245 case Display.STATE_DOZE: pw.print("screen-doze"); break;
6246 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07006247 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006248 }
6249 haveModes = true;
6250 }
6251 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6252 pw.print(haveModes ? ", " : " (");
6253 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
6254 ? "power-save-on" : "power-save-off");
6255 haveModes = true;
6256 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006257 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6258 pw.print(haveModes ? ", " : " (");
6259 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6260 ? "device-idle-on" : "device-idle-off");
6261 haveModes = true;
6262 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006263 if (haveModes) {
6264 pw.print(")");
6265 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006266 pw.println();
6267 }
6268 }
6269 return true;
6270 }
6271
Kweku Adams87b19ec2017-10-09 12:40:03 -07006272 private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId,
6273 LevelStepTracker steps) {
6274 if (steps == null) {
6275 return;
6276 }
6277 int count = steps.mNumStepDurations;
Kweku Adams87b19ec2017-10-09 12:40:03 -07006278 for (int i = 0; i < count; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07006279 long token = proto.start(fieldId);
Kweku Adams87b19ec2017-10-09 12:40:03 -07006280 proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i));
6281 proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i));
6282
6283 final long initMode = steps.getInitModeAt(i);
6284 final long modMode = steps.getModModeAt(i);
6285
6286 int ds = SystemProto.BatteryLevelStep.DS_MIXED;
6287 if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6288 switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6289 case Display.STATE_OFF:
6290 ds = SystemProto.BatteryLevelStep.DS_OFF;
6291 break;
6292 case Display.STATE_ON:
6293 ds = SystemProto.BatteryLevelStep.DS_ON;
6294 break;
6295 case Display.STATE_DOZE:
6296 ds = SystemProto.BatteryLevelStep.DS_DOZE;
6297 break;
6298 case Display.STATE_DOZE_SUSPEND:
6299 ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND;
6300 break;
6301 default:
6302 ds = SystemProto.BatteryLevelStep.DS_ERROR;
6303 break;
6304 }
6305 }
6306 proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds);
6307
6308 int psm = SystemProto.BatteryLevelStep.PSM_MIXED;
6309 if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6310 psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0
6311 ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF;
6312 }
6313 proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm);
6314
6315 int im = SystemProto.BatteryLevelStep.IM_MIXED;
6316 if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6317 im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6318 ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF;
6319 }
6320 proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im);
6321
6322 proto.end(token);
6323 }
6324 }
6325
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006326 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006327 public static final int DUMP_DAILY_ONLY = 1<<2;
6328 public static final int DUMP_HISTORY_ONLY = 1<<3;
6329 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
6330 public static final int DUMP_VERBOSE = 1<<5;
6331 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006332
Dianne Hackborn37de0982014-05-09 09:32:18 -07006333 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
6334 final HistoryPrinter hprinter = new HistoryPrinter();
6335 final HistoryItem rec = new HistoryItem();
6336 long lastTime = -1;
6337 long baseTime = -1;
6338 boolean printed = false;
6339 HistoryEventTracker tracker = null;
6340 while (getNextHistoryLocked(rec)) {
6341 lastTime = rec.time;
6342 if (baseTime < 0) {
6343 baseTime = lastTime;
6344 }
6345 if (rec.time >= histStart) {
6346 if (histStart >= 0 && !printed) {
6347 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006348 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006349 || rec.cmd == HistoryItem.CMD_START
6350 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006351 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006352 hprinter.printNextItem(pw, rec, baseTime, checkin,
6353 (flags&DUMP_VERBOSE) != 0);
6354 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006355 } else if (rec.currentTime != 0) {
6356 printed = true;
6357 byte cmd = rec.cmd;
6358 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006359 hprinter.printNextItem(pw, rec, baseTime, checkin,
6360 (flags&DUMP_VERBOSE) != 0);
6361 rec.cmd = cmd;
6362 }
6363 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006364 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6365 hprinter.printNextItem(pw, rec, baseTime, checkin,
6366 (flags&DUMP_VERBOSE) != 0);
6367 rec.cmd = HistoryItem.CMD_UPDATE;
6368 }
6369 int oldEventCode = rec.eventCode;
6370 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006371 rec.eventTag = new HistoryTag();
6372 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6373 HashMap<String, SparseIntArray> active
6374 = tracker.getStateForEvent(i);
6375 if (active == null) {
6376 continue;
6377 }
6378 for (HashMap.Entry<String, SparseIntArray> ent
6379 : active.entrySet()) {
6380 SparseIntArray uids = ent.getValue();
6381 for (int j=0; j<uids.size(); j++) {
6382 rec.eventCode = i;
6383 rec.eventTag.string = ent.getKey();
6384 rec.eventTag.uid = uids.keyAt(j);
6385 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006386 hprinter.printNextItem(pw, rec, baseTime, checkin,
6387 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006388 rec.wakeReasonTag = null;
6389 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006390 }
6391 }
6392 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006393 rec.eventCode = oldEventCode;
6394 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006395 tracker = null;
6396 }
6397 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006398 hprinter.printNextItem(pw, rec, baseTime, checkin,
6399 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006400 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6401 // This is an attempt to aggregate the previous state and generate
6402 // fake events to reflect that state at the point where we start
6403 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006404 if (tracker == null) {
6405 tracker = new HistoryEventTracker();
6406 }
6407 tracker.updateState(rec.eventCode, rec.eventTag.string,
6408 rec.eventTag.uid, rec.eventTag.poolIdx);
6409 }
6410 }
6411 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006412 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006413 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6414 }
6415 }
6416
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006417 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6418 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6419 if (steps == null) {
6420 return;
6421 }
6422 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6423 if (timeRemaining >= 0) {
6424 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6425 tmpSb.setLength(0);
6426 formatTimeMs(tmpSb, timeRemaining);
6427 pw.print(tmpSb);
6428 pw.print(" (from "); pw.print(tmpOutInt[0]);
6429 pw.println(" steps)");
6430 }
6431 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6432 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6433 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6434 if (estimatedTime > 0) {
6435 pw.print(prefix); pw.print(label); pw.print(" ");
6436 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6437 pw.print(" time: ");
6438 tmpSb.setLength(0);
6439 formatTimeMs(tmpSb, estimatedTime);
6440 pw.print(tmpSb);
6441 pw.print(" (from "); pw.print(tmpOutInt[0]);
6442 pw.println(" steps)");
6443 }
6444 }
6445 }
6446
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006447 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6448 ArrayList<PackageChange> changes) {
6449 if (changes == null) {
6450 return;
6451 }
6452 pw.print(prefix); pw.println("Package changes:");
6453 for (int i=0; i<changes.size(); i++) {
6454 PackageChange pc = changes.get(i);
6455 if (pc.mUpdate) {
6456 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6457 pw.print(" vers="); pw.println(pc.mVersionCode);
6458 } else {
6459 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6460 }
6461 }
6462 }
6463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 /**
6465 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6466 *
6467 * @param pw a Printer to receive the dump output.
6468 */
6469 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006470 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006471 prepareForDumpLocked();
6472
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006473 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006474 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006475
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006476 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006477 final long historyTotalSize = getHistoryTotalSize();
6478 final long historyUsedSize = getHistoryUsedSize();
6479 if (startIteratingHistoryLocked()) {
6480 try {
6481 pw.print("Battery History (");
6482 pw.print((100*historyUsedSize)/historyTotalSize);
6483 pw.print("% used, ");
6484 printSizeValue(pw, historyUsedSize);
6485 pw.print(" used of ");
6486 printSizeValue(pw, historyTotalSize);
6487 pw.print(", ");
6488 pw.print(getHistoryStringPoolSize());
6489 pw.print(" strings using ");
6490 printSizeValue(pw, getHistoryStringPoolBytes());
6491 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006492 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006493 pw.println();
6494 } finally {
6495 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006496 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006497 }
6498
6499 if (startIteratingOldHistoryLocked()) {
6500 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006501 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006502 pw.println("Old battery History:");
6503 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006504 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006505 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006506 if (baseTime < 0) {
6507 baseTime = rec.time;
6508 }
6509 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006510 }
6511 pw.println();
6512 } finally {
6513 finishIteratingOldHistoryLocked();
6514 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006515 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006516 }
6517
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006518 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006519 return;
6520 }
6521
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006522 if (!filtering) {
6523 SparseArray<? extends Uid> uidStats = getUidStats();
6524 final int NU = uidStats.size();
6525 boolean didPid = false;
6526 long nowRealtime = SystemClock.elapsedRealtime();
6527 for (int i=0; i<NU; i++) {
6528 Uid uid = uidStats.valueAt(i);
6529 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6530 if (pids != null) {
6531 for (int j=0; j<pids.size(); j++) {
6532 Uid.Pid pid = pids.valueAt(j);
6533 if (!didPid) {
6534 pw.println("Per-PID Stats:");
6535 didPid = true;
6536 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006537 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6538 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006539 pw.print(" PID "); pw.print(pids.keyAt(j));
6540 pw.print(" wake time: ");
6541 TimeUtils.formatDuration(time, pw);
6542 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006543 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006544 }
6545 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006546 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006547 pw.println();
6548 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006549 }
6550
6551 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006552 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6553 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006554 long timeRemaining = computeBatteryTimeRemaining(
6555 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006556 if (timeRemaining >= 0) {
6557 pw.print(" Estimated discharge time remaining: ");
6558 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6559 pw.println();
6560 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006561 final LevelStepTracker steps = getDischargeLevelStepTracker();
6562 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6563 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6564 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6565 STEP_LEVEL_MODE_VALUES[i], null));
6566 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006567 pw.println();
6568 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006569 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6570 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006571 long timeRemaining = computeChargeTimeRemaining(
6572 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006573 if (timeRemaining >= 0) {
6574 pw.print(" Estimated charge time remaining: ");
6575 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6576 pw.println();
6577 }
6578 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006579 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006580 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07006581 if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006582 pw.println("Daily stats:");
6583 pw.print(" Current start time: ");
6584 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6585 getCurrentDailyStartTime()).toString());
6586 pw.print(" Next min deadline: ");
6587 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6588 getNextMinDailyDeadline()).toString());
6589 pw.print(" Next max deadline: ");
6590 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6591 getNextMaxDailyDeadline()).toString());
6592 StringBuilder sb = new StringBuilder(64);
6593 int[] outInt = new int[1];
6594 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6595 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006596 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6597 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006598 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006599 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6600 dsteps, false)) {
6601 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6602 sb, outInt);
6603 }
6604 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6605 csteps, false)) {
6606 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6607 sb, outInt);
6608 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006609 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006610 } else {
6611 pw.println(" Current daily steps:");
6612 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6613 sb, outInt);
6614 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6615 sb, outInt);
6616 }
6617 }
6618 DailyItem dit;
6619 int curIndex = 0;
6620 while ((dit=getDailyItemLocked(curIndex)) != null) {
6621 curIndex++;
6622 if ((flags&DUMP_DAILY_ONLY) != 0) {
6623 pw.println();
6624 }
6625 pw.print(" Daily from ");
6626 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6627 pw.print(" to ");
6628 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6629 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006630 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006631 if (dumpDurationSteps(pw, " ",
6632 " Discharge step durations:", dit.mDischargeSteps, false)) {
6633 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6634 sb, outInt);
6635 }
6636 if (dumpDurationSteps(pw, " ",
6637 " Charge step durations:", dit.mChargeSteps, false)) {
6638 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6639 sb, outInt);
6640 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006641 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006642 } else {
6643 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6644 sb, outInt);
6645 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6646 sb, outInt);
6647 }
6648 }
6649 pw.println();
6650 }
6651 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006652 pw.println("Statistics since last charge:");
6653 pw.println(" System starts: " + getStartCount()
6654 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006655 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6656 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006657 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006659 }
Mike Mac2f518a2017-09-19 16:06:03 -07006660
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006661 // This is called from BatteryStatsService.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006663 public void dumpCheckinLocked(Context context, PrintWriter pw,
6664 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006665 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006666
6667 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006668 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6669 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006670
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006671 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6672
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006673 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006674 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006675 try {
6676 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6677 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6678 pw.print(HISTORY_STRING_POOL); pw.print(',');
6679 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006680 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006681 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006682 pw.print(",\"");
6683 String str = getHistoryTagPoolString(i);
6684 str = str.replace("\\", "\\\\");
6685 str = str.replace("\"", "\\\"");
6686 pw.print(str);
6687 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006688 pw.println();
6689 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006690 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006691 } finally {
6692 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006693 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006694 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006695 }
6696
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006697 if ((flags & DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006698 return;
6699 }
6700
Dianne Hackborne4a59512010-12-07 11:08:07 -08006701 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006702 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006703 for (int i=0; i<apps.size(); i++) {
6704 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006705 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6706 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006707 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006708 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6709 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006710 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006711 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006712 }
6713 SparseArray<? extends Uid> uidStats = getUidStats();
6714 final int NU = uidStats.size();
6715 String[] lineArgs = new String[2];
6716 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006717 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6718 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6719 if (pkgs != null && !pkgs.second.value) {
6720 pkgs.second.value = true;
6721 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006722 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006723 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006724 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6725 (Object[])lineArgs);
6726 }
6727 }
6728 }
6729 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006730 if ((flags & DUMP_DAILY_ONLY) == 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006731 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006732 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006733 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006734 if (timeRemaining >= 0) {
6735 lineArgs[0] = Long.toString(timeRemaining);
6736 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6737 (Object[])lineArgs);
6738 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006739 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006740 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006741 if (timeRemaining >= 0) {
6742 lineArgs[0] = Long.toString(timeRemaining);
6743 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6744 (Object[])lineArgs);
6745 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006746 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6747 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006750
Kweku Adams87b19ec2017-10-09 12:40:03 -07006751 /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006752 public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps,
Kweku Adams6ccebf22017-12-11 12:30:35 -08006753 int flags) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006754 final ProtoOutputStream proto = new ProtoOutputStream(fd);
6755 final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS);
6756 prepareForDumpLocked();
6757
6758 proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION);
6759 proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion());
6760 proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion());
6761 proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion());
6762
Kweku Adams6ccebf22017-12-11 12:30:35 -08006763 // History intentionally not included in proto dump.
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006764
6765 if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) {
Kweku Adams103351f2017-10-16 14:39:34 -07006766 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false,
6767 (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
6768 helper.create(this);
6769 helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL);
6770
6771 dumpProtoAppsLocked(proto, helper, apps);
6772 dumpProtoSystemLocked(proto, helper);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006773 }
6774
6775 proto.end(bToken);
6776 proto.flush();
6777 }
Kweku Adams87b19ec2017-10-09 12:40:03 -07006778
Kweku Adams103351f2017-10-16 14:39:34 -07006779 private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper,
6780 List<ApplicationInfo> apps) {
6781 final int which = STATS_SINCE_CHARGED;
6782 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
6783 final long rawRealtimeMs = SystemClock.elapsedRealtime();
6784 final long rawRealtimeUs = rawRealtimeMs * 1000;
6785 final long batteryUptimeUs = getBatteryUptime(rawUptimeUs);
6786
6787 SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>();
6788 if (apps != null) {
6789 for (int i = 0; i < apps.size(); ++i) {
6790 ApplicationInfo ai = apps.get(i);
6791 int aid = UserHandle.getAppId(ai.uid);
6792 ArrayList<String> pkgs = aidToPackages.get(aid);
6793 if (pkgs == null) {
6794 pkgs = new ArrayList<String>();
6795 aidToPackages.put(aid, pkgs);
6796 }
6797 pkgs.add(ai.packageName);
6798 }
6799 }
6800
6801 SparseArray<BatterySipper> uidToSipper = new SparseArray<>();
6802 final List<BatterySipper> sippers = helper.getUsageList();
6803 if (sippers != null) {
6804 for (int i = 0; i < sippers.size(); ++i) {
6805 final BatterySipper bs = sippers.get(i);
6806 if (bs.drainType != BatterySipper.DrainType.APP) {
6807 // Others are handled by dumpProtoSystemLocked()
6808 continue;
6809 }
6810 uidToSipper.put(bs.uidObj.getUid(), bs);
6811 }
6812 }
6813
6814 SparseArray<? extends Uid> uidStats = getUidStats();
6815 final int n = uidStats.size();
6816 for (int iu = 0; iu < n; ++iu) {
6817 final long uTkn = proto.start(BatteryStatsProto.UIDS);
6818 final Uid u = uidStats.valueAt(iu);
6819
6820 final int uid = uidStats.keyAt(iu);
6821 proto.write(UidProto.UID, uid);
6822
6823 // Print packages and apk stats (UID_DATA & APK_DATA)
6824 ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid));
6825 if (pkgs == null) {
6826 pkgs = new ArrayList<String>();
6827 }
6828 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats =
6829 u.getPackageStats();
6830 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
6831 String pkg = packageStats.keyAt(ipkg);
6832 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats =
6833 packageStats.valueAt(ipkg).getServiceStats();
6834 if (serviceStats.size() == 0) {
6835 // Due to the way ActivityManagerService logs wakeup alarms, some packages (for
6836 // example, "android") may be included in the packageStats that aren't part of
6837 // the UID. If they don't have any services, then they shouldn't be listed here.
6838 // These packages won't be a part in the pkgs List.
6839 continue;
6840 }
6841
6842 final long pToken = proto.start(UidProto.PACKAGES);
6843 proto.write(UidProto.Package.NAME, pkg);
6844 // Remove from the packages list since we're logging it here.
6845 pkgs.remove(pkg);
6846
6847 for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) {
6848 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
6849 long sToken = proto.start(UidProto.Package.SERVICES);
6850
6851 proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc));
6852 proto.write(UidProto.Package.Service.START_DURATION_MS,
6853 roundUsToMs(ss.getStartTime(batteryUptimeUs, which)));
6854 proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which));
6855 proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which));
6856
6857 proto.end(sToken);
6858 }
6859 proto.end(pToken);
6860 }
6861 // Print any remaining packages that weren't in the packageStats map. pkgs is pulled
6862 // from PackageManager data. Packages are only included in packageStats if there was
6863 // specific data tracked for them (services and wakeup alarms, etc.).
6864 for (String p : pkgs) {
6865 final long pToken = proto.start(UidProto.PACKAGES);
6866 proto.write(UidProto.Package.NAME, p);
6867 proto.end(pToken);
6868 }
6869
6870 // Total wakelock data (AGGREGATED_WAKELOCK_DATA)
6871 if (u.getAggregatedPartialWakelockTimer() != null) {
6872 final Timer timer = u.getAggregatedPartialWakelockTimer();
6873 // Times are since reset (regardless of 'which')
6874 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
6875 final Timer bgTimer = timer.getSubTimer();
6876 final long bgTimeMs = bgTimer != null
6877 ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
6878 final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK);
6879 proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs);
6880 proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs);
6881 proto.end(awToken);
6882 }
6883
6884 // Audio (AUDIO_DATA)
6885 dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which);
6886
6887 // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA)
6888 dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER,
6889 u.getBluetoothControllerActivity(), which);
6890
6891 // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked)
6892 final Timer bleTimer = u.getBluetoothScanTimer();
6893 if (bleTimer != null) {
6894 final long bmToken = proto.start(UidProto.BLUETOOTH_MISC);
6895
6896 dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer,
6897 rawRealtimeUs, which);
6898 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN,
6899 u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which);
6900 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
6901 dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN,
6902 u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which);
6903 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
6904 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN,
6905 u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which);
6906 // Result counters
6907 proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT,
6908 u.getBluetoothScanResultCounter() != null
6909 ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0);
6910 proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT,
6911 u.getBluetoothScanResultBgCounter() != null
6912 ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0);
6913
6914 proto.end(bmToken);
6915 }
6916
6917 // Camera (CAMERA_DATA)
6918 dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which);
6919
6920 // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA)
6921 final long cpuToken = proto.start(UidProto.CPU);
6922 proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which)));
6923 proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which)));
6924
6925 final long[] cpuFreqs = getCpuFreqs();
6926 if (cpuFreqs != null) {
6927 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
6928 // If total cpuFreqTimes is null, then we don't need to check for
6929 // screenOffCpuFreqTimes.
6930 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
6931 long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
6932 if (screenOffCpuFreqTimeMs == null) {
6933 screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
6934 }
6935 for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) {
6936 long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY);
6937 proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1);
6938 proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS,
6939 cpuFreqTimeMs[ic]);
6940 proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS,
6941 screenOffCpuFreqTimeMs[ic]);
6942 proto.end(cToken);
6943 }
6944 }
6945 }
6946 proto.end(cpuToken);
6947
6948 // Flashlight (FLASHLIGHT_DATA)
6949 dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(),
6950 rawRealtimeUs, which);
6951
6952 // Foreground activity (FOREGROUND_ACTIVITY_DATA)
6953 dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(),
6954 rawRealtimeUs, which);
6955
6956 // Foreground service (FOREGROUND_SERVICE_DATA)
6957 dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(),
6958 rawRealtimeUs, which);
6959
6960 // Job completion (JOB_COMPLETION_DATA)
6961 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
6962 final int[] reasons = new int[]{
6963 JobParameters.REASON_CANCELED,
6964 JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
6965 JobParameters.REASON_PREEMPT,
6966 JobParameters.REASON_TIMEOUT,
6967 JobParameters.REASON_DEVICE_IDLE,
6968 };
6969 for (int ic = 0; ic < completions.size(); ++ic) {
6970 SparseIntArray types = completions.valueAt(ic);
6971 if (types != null) {
6972 final long jcToken = proto.start(UidProto.JOB_COMPLETION);
6973
6974 proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic));
6975
6976 for (int r : reasons) {
6977 long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT);
6978 proto.write(UidProto.JobCompletion.ReasonCount.NAME, r);
6979 proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0));
6980 proto.end(rToken);
6981 }
6982
6983 proto.end(jcToken);
6984 }
6985 }
6986
6987 // Scheduled jobs (JOB_DATA)
6988 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
6989 for (int ij = jobs.size() - 1; ij >= 0; --ij) {
6990 final Timer timer = jobs.valueAt(ij);
6991 final Timer bgTimer = timer.getSubTimer();
6992 final long jToken = proto.start(UidProto.JOBS);
6993
6994 proto.write(UidProto.Job.NAME, jobs.keyAt(ij));
6995 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
6996 dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which);
6997 dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which);
6998
6999 proto.end(jToken);
7000 }
7001
7002 // Modem Controller (MODEM_CONTROLLER_DATA)
7003 dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER,
7004 u.getModemControllerActivity(), which);
7005
7006 // Network stats (NETWORK_DATA)
7007 final long nToken = proto.start(UidProto.NETWORK);
7008 proto.write(UidProto.Network.MOBILE_BYTES_RX,
7009 u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7010 proto.write(UidProto.Network.MOBILE_BYTES_TX,
7011 u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7012 proto.write(UidProto.Network.WIFI_BYTES_RX,
7013 u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7014 proto.write(UidProto.Network.WIFI_BYTES_TX,
7015 u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7016 proto.write(UidProto.Network.BT_BYTES_RX,
7017 u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7018 proto.write(UidProto.Network.BT_BYTES_TX,
7019 u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
7020 proto.write(UidProto.Network.MOBILE_PACKETS_RX,
7021 u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7022 proto.write(UidProto.Network.MOBILE_PACKETS_TX,
7023 u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7024 proto.write(UidProto.Network.WIFI_PACKETS_RX,
7025 u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7026 proto.write(UidProto.Network.WIFI_PACKETS_TX,
7027 u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7028 proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS,
7029 roundUsToMs(u.getMobileRadioActiveTime(which)));
7030 proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT,
7031 u.getMobileRadioActiveCount(which));
7032 proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT,
7033 u.getMobileRadioApWakeupCount(which));
7034 proto.write(UidProto.Network.WIFI_WAKEUP_COUNT,
7035 u.getWifiRadioApWakeupCount(which));
7036 proto.write(UidProto.Network.MOBILE_BYTES_BG_RX,
7037 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which));
7038 proto.write(UidProto.Network.MOBILE_BYTES_BG_TX,
7039 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which));
7040 proto.write(UidProto.Network.WIFI_BYTES_BG_RX,
7041 u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which));
7042 proto.write(UidProto.Network.WIFI_BYTES_BG_TX,
7043 u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which));
7044 proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX,
7045 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which));
7046 proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX,
7047 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which));
7048 proto.write(UidProto.Network.WIFI_PACKETS_BG_RX,
7049 u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which));
7050 proto.write(UidProto.Network.WIFI_PACKETS_BG_TX,
7051 u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which));
7052 proto.end(nToken);
7053
7054 // Power use item (POWER_USE_ITEM_DATA)
7055 BatterySipper bs = uidToSipper.get(uid);
7056 if (bs != null) {
7057 final long bsToken = proto.start(UidProto.POWER_USE_ITEM);
7058 proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7059 proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7060 proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7061 proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7062 bs.proportionalSmearMah);
7063 proto.end(bsToken);
7064 }
7065
7066 // Processes (PROCESS_DATA)
7067 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats =
7068 u.getProcessStats();
7069 for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) {
7070 final Uid.Proc ps = processStats.valueAt(ipr);
7071 final long prToken = proto.start(UidProto.PROCESS);
7072
7073 proto.write(UidProto.Process.NAME, processStats.keyAt(ipr));
7074 proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which));
7075 proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which));
7076 proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which));
7077 proto.write(UidProto.Process.START_COUNT, ps.getStarts(which));
7078 proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which));
7079 proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which));
7080
7081 proto.end(prToken);
7082 }
7083
7084 // Sensors (SENSOR_DATA)
7085 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
7086 for (int ise = 0; ise < sensors.size(); ++ise) {
7087 final Uid.Sensor se = sensors.valueAt(ise);
7088 final Timer timer = se.getSensorTime();
7089 if (timer == null) {
7090 continue;
7091 }
7092 final Timer bgTimer = se.getSensorBackgroundTime();
7093 final int sensorNumber = sensors.keyAt(ise);
7094 final long seToken = proto.start(UidProto.SENSORS);
7095
7096 proto.write(UidProto.Sensor.ID, sensorNumber);
7097 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7098 dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which);
7099 dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which);
7100
7101 proto.end(seToken);
7102 }
7103
7104 // State times (STATE_TIME_DATA)
7105 for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) {
7106 long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which));
7107 if (durMs == 0) {
7108 continue;
7109 }
7110 final long stToken = proto.start(UidProto.STATES);
7111 proto.write(UidProto.StateTime.STATE, ips);
7112 proto.write(UidProto.StateTime.DURATION_MS, durMs);
7113 proto.end(stToken);
7114 }
7115
7116 // Syncs (SYNC_DATA)
7117 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
7118 for (int isy = syncs.size() - 1; isy >= 0; --isy) {
7119 final Timer timer = syncs.valueAt(isy);
7120 final Timer bgTimer = timer.getSubTimer();
7121 final long syToken = proto.start(UidProto.SYNCS);
7122
7123 proto.write(UidProto.Sync.NAME, syncs.keyAt(isy));
7124 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7125 dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which);
7126 dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which);
7127
7128 proto.end(syToken);
7129 }
7130
7131 // User activity (USER_ACTIVITY_DATA)
7132 if (u.hasUserActivity()) {
7133 for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) {
7134 int val = u.getUserActivityCount(i, which);
7135 if (val != 0) {
7136 final long uaToken = proto.start(UidProto.USER_ACTIVITY);
7137 proto.write(UidProto.UserActivity.NAME, i);
7138 proto.write(UidProto.UserActivity.COUNT, val);
7139 proto.end(uaToken);
7140 }
7141 }
7142 }
7143
7144 // Vibrator (VIBRATOR_DATA)
7145 dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which);
7146
7147 // Video (VIDEO_DATA)
7148 dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which);
7149
7150 // Wakelocks (WAKELOCK_DATA)
7151 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
7152 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7153 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7154 final long wToken = proto.start(UidProto.WAKELOCKS);
7155 proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw));
7156 dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL),
7157 rawRealtimeUs, which);
7158 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7159 if (pTimer != null) {
7160 dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which);
7161 dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(),
7162 rawRealtimeUs, which);
7163 }
7164 dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW),
7165 rawRealtimeUs, which);
7166 proto.end(wToken);
7167 }
7168
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007169 // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA)
7170 dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(),
7171 rawRealtimeUs, which);
7172
Kweku Adams103351f2017-10-16 14:39:34 -07007173 // Wakeup alarms (WAKEUP_ALARM_DATA)
7174 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
7175 final Uid.Pkg ps = packageStats.valueAt(ipkg);
7176 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
7177 for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) {
7178 final long waToken = proto.start(UidProto.WAKEUP_ALARM);
7179 proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa));
7180 proto.write(UidProto.WakeupAlarm.COUNT,
7181 alarms.valueAt(iwa).getCountLocked(which));
7182 proto.end(waToken);
7183 }
7184 }
7185
7186 // Wifi Controller (WIFI_CONTROLLER_DATA)
7187 dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER,
7188 u.getWifiControllerActivity(), which);
7189
7190 // Wifi data (WIFI_DATA)
7191 final long wToken = proto.start(UidProto.WIFI);
7192 proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS,
7193 roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which)));
7194 dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(),
7195 rawRealtimeUs, which);
7196 proto.write(UidProto.Wifi.RUNNING_DURATION_MS,
7197 roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which)));
7198 dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(),
7199 rawRealtimeUs, which);
7200 proto.end(wToken);
7201
7202 proto.end(uTkn);
7203 }
7204 }
7205
7206 private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) {
Kweku Adams87b19ec2017-10-09 12:40:03 -07007207 final long sToken = proto.start(BatteryStatsProto.SYSTEM);
7208 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
7209 final long rawRealtimeMs = SystemClock.elapsedRealtime();
7210 final long rawRealtimeUs = rawRealtimeMs * 1000;
7211 final int which = STATS_SINCE_CHARGED;
7212
7213 // Battery data (BATTERY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007214 final long bToken = proto.start(SystemProto.BATTERY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007215 proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime());
7216 proto.write(SystemProto.Battery.START_COUNT, getStartCount());
7217 proto.write(SystemProto.Battery.TOTAL_REALTIME_MS,
7218 computeRealtime(rawRealtimeUs, which) / 1000);
7219 proto.write(SystemProto.Battery.TOTAL_UPTIME_MS,
7220 computeUptime(rawUptimeUs, which) / 1000);
7221 proto.write(SystemProto.Battery.BATTERY_REALTIME_MS,
7222 computeBatteryRealtime(rawRealtimeUs, which) / 1000);
7223 proto.write(SystemProto.Battery.BATTERY_UPTIME_MS,
7224 computeBatteryUptime(rawUptimeUs, which) / 1000);
7225 proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS,
7226 computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000);
7227 proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS,
7228 computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000);
7229 proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS,
7230 getScreenDozeTime(rawRealtimeUs, which) / 1000);
7231 proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH,
7232 getEstimatedBatteryCapacity());
7233 proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH,
7234 getMinLearnedBatteryCapacity());
7235 proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH,
7236 getMaxLearnedBatteryCapacity());
Kweku Adams103351f2017-10-16 14:39:34 -07007237 proto.end(bToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007238
7239 // Battery discharge (BATTERY_DISCHARGE_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007240 final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007241 proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE,
7242 getLowDischargeAmountSinceCharge());
7243 proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE,
7244 getHighDischargeAmountSinceCharge());
7245 proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE,
7246 getDischargeAmountScreenOnSinceCharge());
7247 proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE,
7248 getDischargeAmountScreenOffSinceCharge());
7249 proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE,
7250 getDischargeAmountScreenDozeSinceCharge());
7251 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH,
7252 getUahDischarge(which) / 1000);
7253 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF,
7254 getUahDischargeScreenOff(which) / 1000);
7255 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE,
7256 getUahDischargeScreenDoze(which) / 1000);
Mike Ma15313c92017-11-15 17:58:21 -08007257 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE,
7258 getUahDischargeLightDoze(which) / 1000);
7259 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE,
7260 getUahDischargeDeepDoze(which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007261 proto.end(bdToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007262
7263 // Time remaining
7264 long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -07007265 // These are part of a oneof, so we should only set one of them.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007266 if (timeRemainingUs >= 0) {
7267 // Charge time remaining (CHARGE_TIME_REMAIN_DATA)
7268 proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7269 } else {
7270 timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs);
7271 // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA)
7272 if (timeRemainingUs >= 0) {
7273 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7274 } else {
7275 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1);
7276 }
7277 }
7278
7279 // Charge step (CHARGE_STEP_DATA)
7280 dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker());
7281
7282 // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA)
7283 for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007284 final long pdcToken = proto.start(SystemProto.DATA_CONNECTION);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007285 proto.write(SystemProto.DataConnection.NAME, i);
7286 dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i),
7287 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007288 proto.end(pdcToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007289 }
7290
7291 // Discharge step (DISCHARGE_STEP_DATA)
7292 dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker());
7293
7294 // CPU frequencies (GLOBAL_CPU_FREQ_DATA)
7295 final long[] cpuFreqs = getCpuFreqs();
7296 if (cpuFreqs != null) {
7297 for (long i : cpuFreqs) {
7298 proto.write(SystemProto.CPU_FREQUENCY, i);
7299 }
7300 }
7301
7302 // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA)
7303 dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER,
7304 getBluetoothControllerActivity(), which);
7305
7306 // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA)
7307 dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER,
7308 getModemControllerActivity(), which);
7309
7310 // Global network data (GLOBAL_NETWORK_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007311 final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007312 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX,
7313 getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7314 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX,
7315 getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7316 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX,
7317 getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7318 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX,
7319 getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7320 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX,
7321 getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7322 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX,
7323 getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7324 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX,
7325 getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7326 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX,
7327 getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7328 proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX,
7329 getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7330 proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX,
7331 getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
Kweku Adams103351f2017-10-16 14:39:34 -07007332 proto.end(gnToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007333
7334 // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA)
7335 dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER,
7336 getWifiControllerActivity(), which);
7337
7338
7339 // Global wifi (GLOBAL_WIFI_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007340 final long gwToken = proto.start(SystemProto.GLOBAL_WIFI);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007341 proto.write(SystemProto.GlobalWifi.ON_DURATION_MS,
7342 getWifiOnTime(rawRealtimeUs, which) / 1000);
7343 proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS,
7344 getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007345 proto.end(gwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007346
7347 // Kernel wakelock (KERNEL_WAKELOCK_DATA)
7348 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
7349 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007350 final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007351 proto.write(SystemProto.KernelWakelock.NAME, ent.getKey());
7352 dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(),
7353 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007354 proto.end(kwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007355 }
7356
7357 // Misc (MISC_DATA)
7358 // Calculate wakelock times across all uids.
7359 long fullWakeLockTimeTotalUs = 0;
7360 long partialWakeLockTimeTotalUs = 0;
7361
7362 final SparseArray<? extends Uid> uidStats = getUidStats();
7363 for (int iu = 0; iu < uidStats.size(); iu++) {
7364 final Uid u = uidStats.valueAt(iu);
7365
7366 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks =
7367 u.getWakelockStats();
7368 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7369 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7370
7371 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
7372 if (fullWakeTimer != null) {
7373 fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs,
7374 which);
7375 }
7376
7377 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7378 if (partialWakeTimer != null) {
7379 partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked(
7380 rawRealtimeUs, which);
7381 }
7382 }
7383 }
Kweku Adams103351f2017-10-16 14:39:34 -07007384 final long mToken = proto.start(SystemProto.MISC);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007385 proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS,
7386 getScreenOnTime(rawRealtimeUs, which) / 1000);
7387 proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS,
7388 getPhoneOnTime(rawRealtimeUs, which) / 1000);
7389 proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS,
7390 fullWakeLockTimeTotalUs / 1000);
7391 proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS,
7392 partialWakeLockTimeTotalUs / 1000);
7393 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS,
7394 getMobileRadioActiveTime(rawRealtimeUs, which) / 1000);
7395 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS,
7396 getMobileRadioActiveAdjustedTime(which) / 1000);
7397 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT,
7398 getMobileRadioActiveCount(which));
7399 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS,
7400 getMobileRadioActiveUnknownTime(which) / 1000);
7401 proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS,
7402 getInteractiveTime(rawRealtimeUs, which) / 1000);
7403 proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS,
7404 getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000);
7405 proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES,
7406 getNumConnectivityChange(which));
7407 proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS,
7408 getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7409 proto.write(SystemProto.Misc.DEEP_DOZE_COUNT,
7410 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
7411 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS,
7412 getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7413 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT,
7414 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
7415 proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS,
7416 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
7417 proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS,
7418 getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7419 proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT,
7420 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
7421 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS,
7422 getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7423 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT,
7424 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
7425 proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS,
7426 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
Kweku Adams103351f2017-10-16 14:39:34 -07007427 proto.end(mToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007428
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007429 // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA)
7430 // Calculate multicast wakelock stats across all uids.
7431 long multicastWakeLockTimeTotalUs = 0;
7432 int multicastWakeLockCountTotal = 0;
7433
7434 for (int iu = 0; iu < uidStats.size(); iu++) {
7435 final Uid u = uidStats.valueAt(iu);
7436
7437 final Timer mcTimer = u.getMulticastWakelockStats();
7438
7439 if (mcTimer != null) {
7440 multicastWakeLockTimeTotalUs +=
7441 mcTimer.getTotalTimeLocked(rawRealtimeUs, which);
7442 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
7443 }
7444 }
7445
7446 final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL);
7447 proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS,
7448 multicastWakeLockTimeTotalUs / 1000);
7449 proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT,
7450 multicastWakeLockCountTotal);
7451 proto.end(wmctToken);
7452
Kweku Adams87b19ec2017-10-09 12:40:03 -07007453 // Power use item (POWER_USE_ITEM_DATA)
7454 final List<BatterySipper> sippers = helper.getUsageList();
7455 if (sippers != null) {
7456 for (int i = 0; i < sippers.size(); ++i) {
7457 final BatterySipper bs = sippers.get(i);
7458 int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER;
7459 int uid = 0;
7460 switch (bs.drainType) {
7461 case IDLE:
7462 n = SystemProto.PowerUseItem.IDLE;
7463 break;
7464 case CELL:
7465 n = SystemProto.PowerUseItem.CELL;
7466 break;
7467 case PHONE:
7468 n = SystemProto.PowerUseItem.PHONE;
7469 break;
7470 case WIFI:
7471 n = SystemProto.PowerUseItem.WIFI;
7472 break;
7473 case BLUETOOTH:
7474 n = SystemProto.PowerUseItem.BLUETOOTH;
7475 break;
7476 case SCREEN:
7477 n = SystemProto.PowerUseItem.SCREEN;
7478 break;
7479 case FLASHLIGHT:
7480 n = SystemProto.PowerUseItem.FLASHLIGHT;
7481 break;
7482 case APP:
Kweku Adams103351f2017-10-16 14:39:34 -07007483 // dumpProtoAppsLocked will handle this.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007484 continue;
7485 case USER:
7486 n = SystemProto.PowerUseItem.USER;
7487 uid = UserHandle.getUid(bs.userId, 0);
7488 break;
7489 case UNACCOUNTED:
7490 n = SystemProto.PowerUseItem.UNACCOUNTED;
7491 break;
7492 case OVERCOUNTED:
7493 n = SystemProto.PowerUseItem.OVERCOUNTED;
7494 break;
7495 case CAMERA:
7496 n = SystemProto.PowerUseItem.CAMERA;
7497 break;
7498 case MEMORY:
7499 n = SystemProto.PowerUseItem.MEMORY;
7500 break;
7501 }
Kweku Adams103351f2017-10-16 14:39:34 -07007502 final long puiToken = proto.start(SystemProto.POWER_USE_ITEM);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007503 proto.write(SystemProto.PowerUseItem.NAME, n);
7504 proto.write(SystemProto.PowerUseItem.UID, uid);
7505 proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7506 proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7507 proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7508 proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7509 bs.proportionalSmearMah);
Kweku Adams103351f2017-10-16 14:39:34 -07007510 proto.end(puiToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007511 }
7512 }
7513
7514 // Power use summary (POWER_USE_SUMMARY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007515 final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007516 proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH,
7517 helper.getPowerProfile().getBatteryCapacity());
7518 proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower());
7519 proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower());
7520 proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower());
Kweku Adams103351f2017-10-16 14:39:34 -07007521 proto.end(pusToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007522
7523 // RPM stats (RESOURCE_POWER_MANAGER_DATA)
7524 final Map<String, ? extends Timer> rpmStats = getRpmStats();
7525 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
7526 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007527 final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007528 proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey());
7529 dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL,
7530 ent.getValue(), rawRealtimeUs, which);
7531 dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF,
7532 screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007533 proto.end(rpmToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007534 }
7535
7536 // Screen brightness (SCREEN_BRIGHTNESS_DATA)
7537 for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007538 final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007539 proto.write(SystemProto.ScreenBrightness.NAME, i);
7540 dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i),
7541 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007542 proto.end(sbToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007543 }
7544
7545 // Signal scanning time (SIGNAL_SCANNING_TIME_DATA)
7546 dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs,
7547 which);
7548
7549 // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA)
7550 for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007551 final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007552 proto.write(SystemProto.PhoneSignalStrength.NAME, i);
7553 dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i),
7554 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007555 proto.end(pssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007556 }
7557
7558 // Wakeup reasons (WAKEUP_REASON_DATA)
7559 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
7560 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007561 final long wrToken = proto.start(SystemProto.WAKEUP_REASON);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007562 proto.write(SystemProto.WakeupReason.NAME, ent.getKey());
7563 dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007564 proto.end(wrToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007565 }
7566
7567 // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA)
7568 for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007569 final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007570 proto.write(SystemProto.WifiSignalStrength.NAME, i);
7571 dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i),
7572 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007573 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007574 }
7575
7576 // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA)
7577 for (int i = 0; i < NUM_WIFI_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007578 final long wsToken = proto.start(SystemProto.WIFI_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007579 proto.write(SystemProto.WifiState.NAME, i);
7580 dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i),
7581 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007582 proto.end(wsToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007583 }
7584
7585 // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA)
7586 for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007587 final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007588 proto.write(SystemProto.WifiSupplicantState.NAME, i);
7589 dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i),
7590 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007591 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007592 }
7593
7594 proto.end(sToken);
7595 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596}