blob: 811091e37da2819565b94f2a3c6c294503ab0b58 [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 /**
661 * Time this uid has any process that is top while the device is sleeping, but none
662 * in the "foreground service" or better state.
663 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800664 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700665 /**
666 * Time this uid has any process in an active foreground state, but none in the
667 * "top sleeping" or better state.
668 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800669 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700670 /**
671 * Time this uid has any process in an active background state, but none in the
672 * "foreground" or better state.
673 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800674 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700675 /**
676 * Time this uid has any processes that are sitting around cached, not in one of the
677 * other active states.
678 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800679 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700680 /**
681 * Total number of process states we track.
682 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800683 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700684
685 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800686 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700687 };
688
689 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800690 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700691
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800692 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693
Robert Greenwalta029ea12013-09-25 16:38:12 -0700694 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
695
Dianne Hackborn617f8772009-03-31 15:04:46 -0700696 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700697 * Note that these must match the constants in android.os.PowerManager.
698 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
699 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700700 */
701 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700702 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700703 };
Bookatzc8c44962017-05-11 12:12:54 -0700704
Phil Weaverda80d672016-03-15 16:25:46 -0700705 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700706
Dianne Hackborn617f8772009-03-31 15:04:46 -0700707 public abstract void noteUserActivityLocked(int type);
708 public abstract boolean hasUserActivity();
709 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700710
711 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800712 public abstract long getNetworkActivityBytes(int type, int which);
713 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800714 public abstract long getMobileRadioActiveTime(int which);
715 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700716
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700717 /**
718 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
719 */
720 public abstract long getUserCpuTimeUs(int which);
721
722 /**
723 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
724 */
725 public abstract long getSystemCpuTimeUs(int which);
726
727 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700728 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700729 * given CPU cluster.
730 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700731 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700732 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700733 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
734 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700735 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700736 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700737
Adam Lesinski5f056f62016-07-14 16:56:08 -0700738 /**
739 * Returns the number of times this UID woke up the Application Processor to
740 * process a mobile radio packet.
741 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
742 */
743 public abstract long getMobileRadioApWakeupCount(int which);
744
745 /**
746 * Returns the number of times this UID woke up the Application Processor to
747 * process a WiFi packet.
748 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
749 */
750 public abstract long getWifiRadioApWakeupCount(int which);
751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800753 /*
754 * FIXME: it's not correct to use this magic value because it
755 * could clash with a sensor handle (which are defined by
756 * the sensor HAL, and therefore out of our control
757 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 // Magic sensor number for the GPS.
759 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800764
Bookatz867c0d72017-03-07 18:23:42 -0800765 /** Returns a Timer for sensor usage when app is in the background. */
766 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 }
768
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700769 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800770 public int mWakeNesting;
771 public long mWakeSumMs;
772 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700773 }
774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 /**
776 * The statistics associated with a particular process.
777 */
778 public static abstract class Proc {
779
Dianne Hackborn287952c2010-09-22 22:34:31 -0700780 public static class ExcessivePower {
781 public static final int TYPE_WAKE = 1;
782 public static final int TYPE_CPU = 2;
783
784 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700785 public long overTime;
786 public long usedTime;
787 }
788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800790 * Returns true if this process is still active in the battery stats.
791 */
792 public abstract boolean isActive();
793
794 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700795 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700797 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 */
799 public abstract long getUserTime(int which);
800
801 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700802 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700804 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 */
806 public abstract long getSystemTime(int which);
807
808 /**
809 * Returns the number of times the process has been started.
810 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700811 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 */
813 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700814
815 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800816 * Returns the number of times the process has crashed.
817 *
818 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
819 */
820 public abstract int getNumCrashes(int which);
821
822 /**
823 * Returns the number of times the process has ANRed.
824 *
825 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
826 */
827 public abstract int getNumAnrs(int which);
828
829 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700830 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700831 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700832 * @return foreground cpu time in microseconds
833 */
834 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700835
Dianne Hackborn287952c2010-09-22 22:34:31 -0700836 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700837
Dianne Hackborn287952c2010-09-22 22:34:31 -0700838 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840
841 /**
842 * The statistics associated with a particular package.
843 */
844 public static abstract class Pkg {
845
846 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700847 * Returns information about all wakeup alarms that have been triggered for this
848 * package. The mapping keys are tag names for the alarms, the counter contains
849 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700851 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852
853 /**
854 * Returns a mapping containing service statistics.
855 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700856 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857
858 /**
859 * The statistics associated with a particular service.
860 */
Joe Onoratoabded112016-02-08 16:49:39 -0800861 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862
863 /**
864 * Returns the amount of time spent started.
865 *
866 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700867 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * @return
869 */
870 public abstract long getStartTime(long batteryUptime, int which);
871
872 /**
873 * Returns the total number of times startService() has been called.
874 *
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 */
877 public abstract int getStarts(int which);
878
879 /**
880 * Returns the total number times the service has been launched.
881 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700882 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 */
884 public abstract int getLaunches(int which);
885 }
886 }
887 }
888
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800889 public static final class LevelStepTracker {
890 public long mLastStepTime = -1;
891 public int mNumStepDurations;
892 public final long[] mStepDurations;
893
894 public LevelStepTracker(int maxLevelSteps) {
895 mStepDurations = new long[maxLevelSteps];
896 }
897
898 public LevelStepTracker(int numSteps, long[] steps) {
899 mNumStepDurations = numSteps;
900 mStepDurations = new long[numSteps];
901 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
902 }
903
904 public long getDurationAt(int index) {
905 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
906 }
907
908 public int getLevelAt(int index) {
909 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
910 >> STEP_LEVEL_LEVEL_SHIFT);
911 }
912
913 public int getInitModeAt(int index) {
914 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
915 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
916 }
917
918 public int getModModeAt(int index) {
919 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
920 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
921 }
922
923 private void appendHex(long val, int topOffset, StringBuilder out) {
924 boolean hasData = false;
925 while (topOffset >= 0) {
926 int digit = (int)( (val>>topOffset) & 0xf );
927 topOffset -= 4;
928 if (!hasData && digit == 0) {
929 continue;
930 }
931 hasData = true;
932 if (digit >= 0 && digit <= 9) {
933 out.append((char)('0' + digit));
934 } else {
935 out.append((char)('a' + digit - 10));
936 }
937 }
938 }
939
940 public void encodeEntryAt(int index, StringBuilder out) {
941 long item = mStepDurations[index];
942 long duration = item & STEP_LEVEL_TIME_MASK;
943 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
944 >> STEP_LEVEL_LEVEL_SHIFT);
945 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
946 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
947 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
948 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
949 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
950 case Display.STATE_OFF: out.append('f'); break;
951 case Display.STATE_ON: out.append('o'); break;
952 case Display.STATE_DOZE: out.append('d'); break;
953 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
954 }
955 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
956 out.append('p');
957 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700958 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
959 out.append('i');
960 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800961 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
962 case Display.STATE_OFF: out.append('F'); break;
963 case Display.STATE_ON: out.append('O'); break;
964 case Display.STATE_DOZE: out.append('D'); break;
965 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
966 }
967 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
968 out.append('P');
969 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700970 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
971 out.append('I');
972 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800973 out.append('-');
974 appendHex(level, 4, out);
975 out.append('-');
976 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
977 }
978
979 public void decodeEntryAt(int index, String value) {
980 final int N = value.length();
981 int i = 0;
982 char c;
983 long out = 0;
984 while (i < N && (c=value.charAt(i)) != '-') {
985 i++;
986 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800987 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800988 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800989 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800990 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800991 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800992 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800993 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
994 << STEP_LEVEL_INITIAL_MODE_SHIFT);
995 break;
996 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
997 << STEP_LEVEL_INITIAL_MODE_SHIFT);
998 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700999 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1000 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1001 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001002 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1003 break;
1004 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1005 break;
1006 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1007 break;
1008 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1009 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1010 break;
1011 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1012 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001013 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001014 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1015 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1016 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001017 }
1018 }
1019 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001020 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001021 while (i < N && (c=value.charAt(i)) != '-') {
1022 i++;
1023 level <<= 4;
1024 if (c >= '0' && c <= '9') {
1025 level += c - '0';
1026 } else if (c >= 'a' && c <= 'f') {
1027 level += c - 'a' + 10;
1028 } else if (c >= 'A' && c <= 'F') {
1029 level += c - 'A' + 10;
1030 }
1031 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001032 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001033 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1034 long duration = 0;
1035 while (i < N && (c=value.charAt(i)) != '-') {
1036 i++;
1037 duration <<= 4;
1038 if (c >= '0' && c <= '9') {
1039 duration += c - '0';
1040 } else if (c >= 'a' && c <= 'f') {
1041 duration += c - 'a' + 10;
1042 } else if (c >= 'A' && c <= 'F') {
1043 duration += c - 'A' + 10;
1044 }
1045 }
1046 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1047 }
1048
1049 public void init() {
1050 mLastStepTime = -1;
1051 mNumStepDurations = 0;
1052 }
1053
1054 public void clearTime() {
1055 mLastStepTime = -1;
1056 }
1057
1058 public long computeTimePerLevel() {
1059 final long[] steps = mStepDurations;
1060 final int numSteps = mNumStepDurations;
1061
1062 // For now we'll do a simple average across all steps.
1063 if (numSteps <= 0) {
1064 return -1;
1065 }
1066 long total = 0;
1067 for (int i=0; i<numSteps; i++) {
1068 total += steps[i] & STEP_LEVEL_TIME_MASK;
1069 }
1070 return total / numSteps;
1071 /*
1072 long[] buckets = new long[numSteps];
1073 int numBuckets = 0;
1074 int numToAverage = 4;
1075 int i = 0;
1076 while (i < numSteps) {
1077 long totalTime = 0;
1078 int num = 0;
1079 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1080 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1081 num++;
1082 }
1083 buckets[numBuckets] = totalTime / num;
1084 numBuckets++;
1085 numToAverage *= 2;
1086 i += num;
1087 }
1088 if (numBuckets < 1) {
1089 return -1;
1090 }
1091 long averageTime = buckets[numBuckets-1];
1092 for (i=numBuckets-2; i>=0; i--) {
1093 averageTime = (averageTime + buckets[i]) / 2;
1094 }
1095 return averageTime;
1096 */
1097 }
1098
1099 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1100 int[] outNumOfInterest) {
1101 final long[] steps = mStepDurations;
1102 final int count = mNumStepDurations;
1103 if (count <= 0) {
1104 return -1;
1105 }
1106 long total = 0;
1107 int numOfInterest = 0;
1108 for (int i=0; i<count; i++) {
1109 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1110 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1111 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1112 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1113 // If the modes of interest didn't change during this step period...
1114 if ((modMode&modesOfInterest) == 0) {
1115 // And the mode values during this period match those we are measuring...
1116 if ((initMode&modesOfInterest) == modeValues) {
1117 // Then this can be used to estimate the total time!
1118 numOfInterest++;
1119 total += steps[i] & STEP_LEVEL_TIME_MASK;
1120 }
1121 }
1122 }
1123 if (numOfInterest <= 0) {
1124 return -1;
1125 }
1126
1127 if (outNumOfInterest != null) {
1128 outNumOfInterest[0] = numOfInterest;
1129 }
1130
1131 // The estimated time is the average time we spend in each level, multipled
1132 // by 100 -- the total number of battery levels
1133 return (total / numOfInterest) * 100;
1134 }
1135
1136 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1137 int stepCount = mNumStepDurations;
1138 final long lastStepTime = mLastStepTime;
1139 if (lastStepTime >= 0 && numStepLevels > 0) {
1140 final long[] steps = mStepDurations;
1141 long duration = elapsedRealtime - lastStepTime;
1142 for (int i=0; i<numStepLevels; i++) {
1143 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1144 long thisDuration = duration / (numStepLevels-i);
1145 duration -= thisDuration;
1146 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1147 thisDuration = STEP_LEVEL_TIME_MASK;
1148 }
1149 steps[0] = thisDuration | modeBits;
1150 }
1151 stepCount += numStepLevels;
1152 if (stepCount > steps.length) {
1153 stepCount = steps.length;
1154 }
1155 }
1156 mNumStepDurations = stepCount;
1157 mLastStepTime = elapsedRealtime;
1158 }
1159
1160 public void readFromParcel(Parcel in) {
1161 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001162 if (N > mStepDurations.length) {
1163 throw new ParcelFormatException("more step durations than available: " + N);
1164 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001165 mNumStepDurations = N;
1166 for (int i=0; i<N; i++) {
1167 mStepDurations[i] = in.readLong();
1168 }
1169 }
1170
1171 public void writeToParcel(Parcel out) {
1172 final int N = mNumStepDurations;
1173 out.writeInt(N);
1174 for (int i=0; i<N; i++) {
1175 out.writeLong(mStepDurations[i]);
1176 }
1177 }
1178 }
1179
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001180 public static final class PackageChange {
1181 public String mPackageName;
1182 public boolean mUpdate;
1183 public int mVersionCode;
1184 }
1185
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001186 public static final class DailyItem {
1187 public long mStartTime;
1188 public long mEndTime;
1189 public LevelStepTracker mDischargeSteps;
1190 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001191 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001192 }
1193
1194 public abstract DailyItem getDailyItemLocked(int daysAgo);
1195
1196 public abstract long getCurrentDailyStartTime();
1197
1198 public abstract long getNextMinDailyDeadline();
1199
1200 public abstract long getNextMaxDailyDeadline();
1201
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001202 public abstract long[] getCpuFreqs();
1203
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001204 public final static class HistoryTag {
1205 public String string;
1206 public int uid;
1207
1208 public int poolIdx;
1209
1210 public void setTo(HistoryTag o) {
1211 string = o.string;
1212 uid = o.uid;
1213 poolIdx = o.poolIdx;
1214 }
1215
1216 public void setTo(String _string, int _uid) {
1217 string = _string;
1218 uid = _uid;
1219 poolIdx = -1;
1220 }
1221
1222 public void writeToParcel(Parcel dest, int flags) {
1223 dest.writeString(string);
1224 dest.writeInt(uid);
1225 }
1226
1227 public void readFromParcel(Parcel src) {
1228 string = src.readString();
1229 uid = src.readInt();
1230 poolIdx = -1;
1231 }
1232
1233 @Override
1234 public boolean equals(Object o) {
1235 if (this == o) return true;
1236 if (o == null || getClass() != o.getClass()) return false;
1237
1238 HistoryTag that = (HistoryTag) o;
1239
1240 if (uid != that.uid) return false;
1241 if (!string.equals(that.string)) return false;
1242
1243 return true;
1244 }
1245
1246 @Override
1247 public int hashCode() {
1248 int result = string.hashCode();
1249 result = 31 * result + uid;
1250 return result;
1251 }
1252 }
1253
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001254 /**
1255 * Optional detailed information that can go into a history step. This is typically
1256 * generated each time the battery level changes.
1257 */
1258 public final static class HistoryStepDetails {
1259 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1260 public int userTime;
1261 public int systemTime;
1262
1263 // Top three apps using CPU in the last step, with times in 1/100 second.
1264 public int appCpuUid1;
1265 public int appCpuUTime1;
1266 public int appCpuSTime1;
1267 public int appCpuUid2;
1268 public int appCpuUTime2;
1269 public int appCpuSTime2;
1270 public int appCpuUid3;
1271 public int appCpuUTime3;
1272 public int appCpuSTime3;
1273
1274 // Information from /proc/stat
1275 public int statUserTime;
1276 public int statSystemTime;
1277 public int statIOWaitTime;
1278 public int statIrqTime;
1279 public int statSoftIrqTime;
1280 public int statIdlTime;
1281
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001282 // Platform-level low power state stats
1283 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001284 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001285
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001286 public HistoryStepDetails() {
1287 clear();
1288 }
1289
1290 public void clear() {
1291 userTime = systemTime = 0;
1292 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1293 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1294 = appCpuUTime3 = appCpuSTime3 = 0;
1295 }
1296
1297 public void writeToParcel(Parcel out) {
1298 out.writeInt(userTime);
1299 out.writeInt(systemTime);
1300 out.writeInt(appCpuUid1);
1301 out.writeInt(appCpuUTime1);
1302 out.writeInt(appCpuSTime1);
1303 out.writeInt(appCpuUid2);
1304 out.writeInt(appCpuUTime2);
1305 out.writeInt(appCpuSTime2);
1306 out.writeInt(appCpuUid3);
1307 out.writeInt(appCpuUTime3);
1308 out.writeInt(appCpuSTime3);
1309 out.writeInt(statUserTime);
1310 out.writeInt(statSystemTime);
1311 out.writeInt(statIOWaitTime);
1312 out.writeInt(statIrqTime);
1313 out.writeInt(statSoftIrqTime);
1314 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001315 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001316 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001317 }
1318
1319 public void readFromParcel(Parcel in) {
1320 userTime = in.readInt();
1321 systemTime = in.readInt();
1322 appCpuUid1 = in.readInt();
1323 appCpuUTime1 = in.readInt();
1324 appCpuSTime1 = in.readInt();
1325 appCpuUid2 = in.readInt();
1326 appCpuUTime2 = in.readInt();
1327 appCpuSTime2 = in.readInt();
1328 appCpuUid3 = in.readInt();
1329 appCpuUTime3 = in.readInt();
1330 appCpuSTime3 = in.readInt();
1331 statUserTime = in.readInt();
1332 statSystemTime = in.readInt();
1333 statIOWaitTime = in.readInt();
1334 statIrqTime = in.readInt();
1335 statSoftIrqTime = in.readInt();
1336 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001337 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001338 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001339 }
1340 }
1341
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001342 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001343 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001344
1345 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001346 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001347
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001348 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001349 public static final byte CMD_NULL = -1;
1350 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001351 public static final byte CMD_CURRENT_TIME = 5;
1352 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001353 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001354 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001355
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001356 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001357
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001358 /**
1359 * Return whether the command code is a delta data update.
1360 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001361 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001362 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001363 }
1364
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001365 public byte batteryLevel;
1366 public byte batteryStatus;
1367 public byte batteryHealth;
1368 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001369
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001370 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001371 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001372
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001373 // The charge of the battery in micro-Ampere-hours.
1374 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001375
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001376 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001377 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001378 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001379 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001380 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1381 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001382 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001383 public static final int STATE_PHONE_STATE_SHIFT = 6;
1384 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001385 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001386 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001387 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001389 // These states always appear directly in the first int token
1390 // of a delta change; they should be ones that change relatively
1391 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001392 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1393 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001394 public static final int STATE_GPS_ON_FLAG = 1<<29;
1395 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001396 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001397 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001398 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001399 // Do not use, this is used for coulomb delta count.
1400 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001401 // These are on the lower bits used for the command; if they change
1402 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001403 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001404 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001405 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001406 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1407 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001408 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001409 // empty slot
1410 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001411
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001412 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001413 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001414
1415 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001416
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001417 public int states;
1418
Dianne Hackborn3251b902014-06-20 14:40:53 -07001419 // Constants from WIFI_SUPPL_STATE_*
1420 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1421 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1422 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1423 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1424 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1425 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1426
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001427 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001428 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1429 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1430 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001431 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001432 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1433 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1434 public static final int STATE2_CHARGING_FLAG = 1<<24;
1435 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1436 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1437 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001438 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001439
1440 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001441 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1442 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001443
1444 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001445
Dianne Hackborn40c87252014-03-19 16:55:40 -07001446 public int states2;
1447
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001448 // The wake lock that was acquired at this point.
1449 public HistoryTag wakelockTag;
1450
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001451 // Kernel wakeup reason at this point.
1452 public HistoryTag wakeReasonTag;
1453
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001454 // Non-null when there is more detailed information at this step.
1455 public HistoryStepDetails stepDetails;
1456
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001457 public static final int EVENT_FLAG_START = 0x8000;
1458 public static final int EVENT_FLAG_FINISH = 0x4000;
1459
1460 // No event in this item.
1461 public static final int EVENT_NONE = 0x0000;
1462 // Event is about a process that is running.
1463 public static final int EVENT_PROC = 0x0001;
1464 // Event is about an application package that is in the foreground.
1465 public static final int EVENT_FOREGROUND = 0x0002;
1466 // Event is about an application package that is at the top of the screen.
1467 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001468 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001469 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001470 // Events for all additional wake locks aquired/release within a wake block.
1471 // These are not generated by default.
1472 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001473 // Event is about an application executing a scheduled job.
1474 public static final int EVENT_JOB = 0x0006;
1475 // Events for users running.
1476 public static final int EVENT_USER_RUNNING = 0x0007;
1477 // Events for foreground user.
1478 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001479 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001480 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001481 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001482 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001483 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001484 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001485 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001486 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001487 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001488 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001489 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001490 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001491 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001492 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001493 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001494 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001495 // Event for a package being on the temporary whitelist.
1496 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001497 // Event for the screen waking up.
1498 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001499 // Event for the UID that woke up the application processor.
1500 // Used for wakeups coming from WiFi, modem, etc.
1501 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001502 // Event for reporting that a specific partial wake lock has been held for a long duration.
1503 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001504
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001505 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001506 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001507 // Mask to extract out only the type part of the event.
1508 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001509
1510 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1511 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1512 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1513 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1514 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1515 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001516 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1517 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001518 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1519 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001520 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1521 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1522 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1523 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1524 public static final int EVENT_USER_FOREGROUND_START =
1525 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1526 public static final int EVENT_USER_FOREGROUND_FINISH =
1527 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001528 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1529 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001530 public static final int EVENT_TEMP_WHITELIST_START =
1531 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1532 public static final int EVENT_TEMP_WHITELIST_FINISH =
1533 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001534 public static final int EVENT_LONG_WAKE_LOCK_START =
1535 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1536 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1537 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001538
1539 // For CMD_EVENT.
1540 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001541 public HistoryTag eventTag;
1542
Dianne Hackborn9a755432014-05-15 17:05:22 -07001543 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001544 public long currentTime;
1545
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001546 // Meta-data when reading.
1547 public int numReadInts;
1548
1549 // Pre-allocated objects.
1550 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001551 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001552 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001553
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001554 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001555 }
Bookatzc8c44962017-05-11 12:12:54 -07001556
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001557 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001558 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001559 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001560 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001561 }
Bookatzc8c44962017-05-11 12:12:54 -07001562
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001563 public int describeContents() {
1564 return 0;
1565 }
1566
1567 public void writeToParcel(Parcel dest, int flags) {
1568 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001569 int bat = (((int)cmd)&0xff)
1570 | ((((int)batteryLevel)<<8)&0xff00)
1571 | ((((int)batteryStatus)<<16)&0xf0000)
1572 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001573 | ((((int)batteryPlugType)<<24)&0xf000000)
1574 | (wakelockTag != null ? 0x10000000 : 0)
1575 | (wakeReasonTag != null ? 0x20000000 : 0)
1576 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001577 dest.writeInt(bat);
1578 bat = (((int)batteryTemperature)&0xffff)
1579 | ((((int)batteryVoltage)<<16)&0xffff0000);
1580 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001581 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001582 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001583 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001584 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001585 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001586 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001587 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001588 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001589 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001590 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001591 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001592 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001593 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001594 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001595 dest.writeLong(currentTime);
1596 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001597 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001598
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001599 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001600 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001601 int bat = src.readInt();
1602 cmd = (byte)(bat&0xff);
1603 batteryLevel = (byte)((bat>>8)&0xff);
1604 batteryStatus = (byte)((bat>>16)&0xf);
1605 batteryHealth = (byte)((bat>>20)&0xf);
1606 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001607 int bat2 = src.readInt();
1608 batteryTemperature = (short)(bat2&0xffff);
1609 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001610 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001611 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001612 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001613 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001614 wakelockTag = localWakelockTag;
1615 wakelockTag.readFromParcel(src);
1616 } else {
1617 wakelockTag = null;
1618 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001619 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001620 wakeReasonTag = localWakeReasonTag;
1621 wakeReasonTag.readFromParcel(src);
1622 } else {
1623 wakeReasonTag = null;
1624 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001625 if ((bat&0x40000000) != 0) {
1626 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001627 eventTag = localEventTag;
1628 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001629 } else {
1630 eventCode = EVENT_NONE;
1631 eventTag = null;
1632 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001633 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001634 currentTime = src.readLong();
1635 } else {
1636 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001637 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001638 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001639 }
1640
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001641 public void clear() {
1642 time = 0;
1643 cmd = CMD_NULL;
1644 batteryLevel = 0;
1645 batteryStatus = 0;
1646 batteryHealth = 0;
1647 batteryPlugType = 0;
1648 batteryTemperature = 0;
1649 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001650 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001651 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001652 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001653 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001654 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001655 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001656 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001657 }
Bookatzc8c44962017-05-11 12:12:54 -07001658
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001659 public void setTo(HistoryItem o) {
1660 time = o.time;
1661 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001662 setToCommon(o);
1663 }
1664
1665 public void setTo(long time, byte cmd, HistoryItem o) {
1666 this.time = time;
1667 this.cmd = cmd;
1668 setToCommon(o);
1669 }
1670
1671 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001672 batteryLevel = o.batteryLevel;
1673 batteryStatus = o.batteryStatus;
1674 batteryHealth = o.batteryHealth;
1675 batteryPlugType = o.batteryPlugType;
1676 batteryTemperature = o.batteryTemperature;
1677 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001678 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001679 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001680 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001681 if (o.wakelockTag != null) {
1682 wakelockTag = localWakelockTag;
1683 wakelockTag.setTo(o.wakelockTag);
1684 } else {
1685 wakelockTag = null;
1686 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001687 if (o.wakeReasonTag != null) {
1688 wakeReasonTag = localWakeReasonTag;
1689 wakeReasonTag.setTo(o.wakeReasonTag);
1690 } else {
1691 wakeReasonTag = null;
1692 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001693 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001694 if (o.eventTag != null) {
1695 eventTag = localEventTag;
1696 eventTag.setTo(o.eventTag);
1697 } else {
1698 eventTag = null;
1699 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001700 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001701 }
1702
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001703 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001704 return batteryLevel == o.batteryLevel
1705 && batteryStatus == o.batteryStatus
1706 && batteryHealth == o.batteryHealth
1707 && batteryPlugType == o.batteryPlugType
1708 && batteryTemperature == o.batteryTemperature
1709 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001710 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001711 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001712 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001713 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001714 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001715
1716 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001717 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001718 return false;
1719 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001720 if (wakelockTag != o.wakelockTag) {
1721 if (wakelockTag == null || o.wakelockTag == null) {
1722 return false;
1723 }
1724 if (!wakelockTag.equals(o.wakelockTag)) {
1725 return false;
1726 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001727 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001728 if (wakeReasonTag != o.wakeReasonTag) {
1729 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1730 return false;
1731 }
1732 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1733 return false;
1734 }
1735 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001736 if (eventTag != o.eventTag) {
1737 if (eventTag == null || o.eventTag == null) {
1738 return false;
1739 }
1740 if (!eventTag.equals(o.eventTag)) {
1741 return false;
1742 }
1743 }
1744 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001745 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001746 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001747
1748 public final static class HistoryEventTracker {
1749 private final HashMap<String, SparseIntArray>[] mActiveEvents
1750 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1751
1752 public boolean updateState(int code, String name, int uid, int poolIdx) {
1753 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1754 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1755 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1756 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001757 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001758 mActiveEvents[idx] = active;
1759 }
1760 SparseIntArray uids = active.get(name);
1761 if (uids == null) {
1762 uids = new SparseIntArray();
1763 active.put(name, uids);
1764 }
1765 if (uids.indexOfKey(uid) >= 0) {
1766 // Already set, nothing to do!
1767 return false;
1768 }
1769 uids.put(uid, poolIdx);
1770 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1771 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1772 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1773 if (active == null) {
1774 // not currently active, nothing to do.
1775 return false;
1776 }
1777 SparseIntArray uids = active.get(name);
1778 if (uids == null) {
1779 // not currently active, nothing to do.
1780 return false;
1781 }
1782 idx = uids.indexOfKey(uid);
1783 if (idx < 0) {
1784 // not currently active, nothing to do.
1785 return false;
1786 }
1787 uids.removeAt(idx);
1788 if (uids.size() <= 0) {
1789 active.remove(name);
1790 }
1791 }
1792 return true;
1793 }
1794
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001795 public void removeEvents(int code) {
1796 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1797 mActiveEvents[idx] = null;
1798 }
1799
Dianne Hackborn37de0982014-05-09 09:32:18 -07001800 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1801 return mActiveEvents[code];
1802 }
1803 }
1804
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001805 public static final class BitDescription {
1806 public final int mask;
1807 public final int shift;
1808 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001809 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001810 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001811 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001812
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001813 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001814 this.mask = mask;
1815 this.shift = -1;
1816 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001817 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001818 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001819 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001820 }
Bookatzc8c44962017-05-11 12:12:54 -07001821
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001822 public BitDescription(int mask, int shift, String name, String shortName,
1823 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001824 this.mask = mask;
1825 this.shift = shift;
1826 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001827 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001828 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001829 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001830 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001831 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001832
Dianne Hackbornfc064132014-06-02 12:42:12 -07001833 /**
1834 * Don't allow any more batching in to the current history event. This
1835 * is called when printing partial histories, so to ensure that the next
1836 * history event will go in to a new batch after what was printed in the
1837 * last partial history.
1838 */
1839 public abstract void commitCurrentHistoryBatchLocked();
1840
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001841 public abstract int getHistoryTotalSize();
1842
1843 public abstract int getHistoryUsedSize();
1844
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001845 public abstract boolean startIteratingHistoryLocked();
1846
Dianne Hackborn099bc622014-01-22 13:39:16 -08001847 public abstract int getHistoryStringPoolSize();
1848
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001849 public abstract int getHistoryStringPoolBytes();
1850
1851 public abstract String getHistoryTagPoolString(int index);
1852
1853 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001854
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001855 public abstract boolean getNextHistoryLocked(HistoryItem out);
1856
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001857 public abstract void finishIteratingHistoryLocked();
1858
1859 public abstract boolean startIteratingOldHistoryLocked();
1860
1861 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1862
1863 public abstract void finishIteratingOldHistoryLocked();
1864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001866 * Return the base time offset for the battery history.
1867 */
1868 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001869
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001870 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 * Returns the number of times the device has been started.
1872 */
1873 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001876 * 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 -08001877 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001878 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 * {@hide}
1880 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001881 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001882
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001883 /**
1884 * Returns the number of times the screen was turned on.
1885 *
1886 * {@hide}
1887 */
1888 public abstract int getScreenOnCount(int which);
1889
Mike Mac2f518a2017-09-19 16:06:03 -07001890 /**
1891 * Returns the time in microseconds that the screen has been dozing while the device was
1892 * running on battery.
1893 *
1894 * {@hide}
1895 */
1896 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
1897
1898 /**
1899 * Returns the number of times the screen was turned dozing.
1900 *
1901 * {@hide}
1902 */
1903 public abstract int getScreenDozeCount(int which);
1904
Jeff Browne95c3cd2014-05-02 16:59:26 -07001905 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1906
Dianne Hackborn617f8772009-03-31 15:04:46 -07001907 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1908 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1909 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1910 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1911 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001912
Dianne Hackborn617f8772009-03-31 15:04:46 -07001913 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1914 "dark", "dim", "medium", "light", "bright"
1915 };
Bookatzc8c44962017-05-11 12:12:54 -07001916
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001917 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1918 "0", "1", "2", "3", "4"
1919 };
1920
Dianne Hackborn617f8772009-03-31 15:04:46 -07001921 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001922
Dianne Hackborn617f8772009-03-31 15:04:46 -07001923 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001924 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001925 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001926 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001927 * {@hide}
1928 */
1929 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001930 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07001933 * Returns the {@link Timer} object that tracks the given screen brightness.
1934 *
1935 * {@hide}
1936 */
1937 public abstract Timer getScreenBrightnessTimer(int brightnessBin);
1938
1939 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001940 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001941 * running on battery.
1942 *
1943 * {@hide}
1944 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001945 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001946
1947 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001948 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001949 *
1950 * {@hide}
1951 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001952 public abstract int getPowerSaveModeEnabledCount(int which);
1953
1954 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001955 * Constant for device idle mode: not active.
1956 */
1957 public static final int DEVICE_IDLE_MODE_OFF = 0;
1958
1959 /**
1960 * Constant for device idle mode: active in lightweight mode.
1961 */
1962 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1963
1964 /**
1965 * Constant for device idle mode: active in full mode.
1966 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001967 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001968
1969 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001970 * Returns the time in microseconds that device has been in idle mode while
1971 * running on battery.
1972 *
1973 * {@hide}
1974 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001975 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001976
1977 /**
1978 * Returns the number of times that the devie has gone in to idle mode.
1979 *
1980 * {@hide}
1981 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001982 public abstract int getDeviceIdleModeCount(int mode, int which);
1983
1984 /**
1985 * Return the longest duration we spent in a particular device idle mode (fully in the
1986 * mode, not in idle maintenance etc).
1987 */
1988 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001989
1990 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001991 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001992 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001993 * counts all of the time that we consider the device to be idle, whether or not
1994 * it is currently in the actual device idle mode.
1995 *
1996 * {@hide}
1997 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001998 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001999
2000 /**
Bookatz8c6571b2017-10-24 15:04:41 -07002001 * Returns the number of times that the device has started idling.
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002002 *
2003 * {@hide}
2004 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002005 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002006
2007 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002008 * Returns the number of times that connectivity state changed.
2009 *
2010 * {@hide}
2011 */
2012 public abstract int getNumConnectivityChange(int which);
2013
2014 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002015 * 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 -08002016 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002017 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 * {@hide}
2019 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002020 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002021
Dianne Hackborn627bba72009-03-24 22:32:56 -07002022 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002023 * Returns the number of times a phone call was activated.
2024 *
2025 * {@hide}
2026 */
2027 public abstract int getPhoneOnCount(int which);
2028
2029 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002030 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002031 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002032 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002033 * {@hide}
2034 */
2035 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002036 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002037
Dianne Hackborn617f8772009-03-31 15:04:46 -07002038 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002039 * Returns the time in microseconds that the phone has been trying to
2040 * acquire a signal.
2041 *
2042 * {@hide}
2043 */
2044 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002045 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002046
2047 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002048 * Returns the {@link Timer} object that tracks how much the phone has been trying to
2049 * acquire a signal.
2050 *
2051 * {@hide}
2052 */
2053 public abstract Timer getPhoneSignalScanningTimer();
2054
2055 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002056 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002057 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002058 * {@hide}
2059 */
2060 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2061
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002062 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002063 * Return the {@link Timer} object used to track the given signal strength's duration and
2064 * counts.
2065 */
2066 protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin);
2067
2068 /**
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002069 * Returns the time in microseconds that the mobile network has been active
2070 * (in a high power state).
2071 *
2072 * {@hide}
2073 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002074 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002075
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002076 /**
2077 * Returns the number of times that the mobile network has transitioned to the
2078 * active state.
2079 *
2080 * {@hide}
2081 */
2082 public abstract int getMobileRadioActiveCount(int which);
2083
2084 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002085 * Returns the time in microseconds that is the difference between the mobile radio
2086 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2087 * from the radio.
2088 *
2089 * {@hide}
2090 */
2091 public abstract long getMobileRadioActiveAdjustedTime(int which);
2092
2093 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002094 * Returns the time in microseconds that the mobile network has been active
2095 * (in a high power state) but not being able to blame on an app.
2096 *
2097 * {@hide}
2098 */
2099 public abstract long getMobileRadioActiveUnknownTime(int which);
2100
2101 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002102 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002103 *
2104 * {@hide}
2105 */
2106 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002107
Dianne Hackborn627bba72009-03-24 22:32:56 -07002108 public static final int DATA_CONNECTION_NONE = 0;
2109 public static final int DATA_CONNECTION_GPRS = 1;
2110 public static final int DATA_CONNECTION_EDGE = 2;
2111 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002112 public static final int DATA_CONNECTION_CDMA = 4;
2113 public static final int DATA_CONNECTION_EVDO_0 = 5;
2114 public static final int DATA_CONNECTION_EVDO_A = 6;
2115 public static final int DATA_CONNECTION_1xRTT = 7;
2116 public static final int DATA_CONNECTION_HSDPA = 8;
2117 public static final int DATA_CONNECTION_HSUPA = 9;
2118 public static final int DATA_CONNECTION_HSPA = 10;
2119 public static final int DATA_CONNECTION_IDEN = 11;
2120 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002121 public static final int DATA_CONNECTION_LTE = 13;
2122 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002123 public static final int DATA_CONNECTION_HSPAP = 15;
2124 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002125
Dianne Hackborn627bba72009-03-24 22:32:56 -07002126 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002127 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002128 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002129 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002130 };
Bookatzc8c44962017-05-11 12:12:54 -07002131
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002132 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002133
Dianne Hackborn627bba72009-03-24 22:32:56 -07002134 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002135 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002136 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002137 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002138 * {@hide}
2139 */
2140 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002141 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002144 * Returns the number of times the phone has entered the given data
2145 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002146 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002147 * {@hide}
2148 */
2149 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002150
Kweku Adams87b19ec2017-10-09 12:40:03 -07002151 /**
2152 * Returns the {@link Timer} object that tracks the phone's data connection type stats.
2153 */
2154 public abstract Timer getPhoneDataConnectionTimer(int dataType);
2155
Dianne Hackborn3251b902014-06-20 14:40:53 -07002156 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2157 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2158 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2159 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2160 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2161 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2162 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2163 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2164 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2165 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2166 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2167 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2168 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2169
2170 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2171
2172 static final String[] WIFI_SUPPL_STATE_NAMES = {
2173 "invalid", "disconn", "disabled", "inactive", "scanning",
2174 "authenticating", "associating", "associated", "4-way-handshake",
2175 "group-handshake", "completed", "dormant", "uninit"
2176 };
2177
2178 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2179 "inv", "dsc", "dis", "inact", "scan",
2180 "auth", "ascing", "asced", "4-way",
2181 "group", "compl", "dorm", "uninit"
2182 };
2183
Mike Mac2f518a2017-09-19 16:06:03 -07002184 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002185 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002186 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2187 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002188 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002189 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2190 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2191 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002192 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002193 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002194 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002195 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002196 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2197 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002198 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002199 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2200 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2201 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2202 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2203 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2204 new String[] {"in", "out", "emergency", "off"},
2205 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002206 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2207 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2208 SignalStrength.SIGNAL_STRENGTH_NAMES,
2209 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002210 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2211 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2212 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002213 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002214
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002215 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2216 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002217 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002218 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002219 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002220 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002221 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002222 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2223 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2224 new String[] { "off", "light", "full", "???" },
2225 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002226 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2227 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2228 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002229 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2230 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2231 new String[] { "0", "1", "2", "3", "4" },
2232 new String[] { "0", "1", "2", "3", "4" }),
2233 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2234 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2235 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002236 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002237 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002238 };
2239
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002240 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002241 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002242 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2243 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002244 };
2245
2246 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002247 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002248 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002249 "Esw", "Ewa", "Elw", "Eec"
2250 };
2251
2252 @FunctionalInterface
2253 public interface IntToString {
2254 String applyAsString(int val);
2255 }
2256
2257 private static final IntToString sUidToString = UserHandle::formatUid;
2258 private static final IntToString sIntToString = Integer::toString;
2259
2260 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2261 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2262 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2263 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2264 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002265 };
2266
Dianne Hackborn617f8772009-03-31 15:04:46 -07002267 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002268 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002269 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002270 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002271 * {@hide}
2272 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002273 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002274
2275 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002276 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002277 * been in the running state while the device was running on battery.
2278 *
2279 * {@hide}
2280 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002281 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002282
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002283 public static final int WIFI_STATE_OFF = 0;
2284 public static final int WIFI_STATE_OFF_SCANNING = 1;
2285 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2286 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2287 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2288 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2289 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2290 public static final int WIFI_STATE_SOFT_AP = 7;
2291
2292 static final String[] WIFI_STATE_NAMES = {
2293 "off", "scanning", "no_net", "disconn",
2294 "sta", "p2p", "sta_p2p", "soft_ap"
2295 };
2296
2297 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2298
2299 /**
2300 * Returns the time in microseconds that WiFi has been running in the given state.
2301 *
2302 * {@hide}
2303 */
2304 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002305 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002306
2307 /**
2308 * Returns the number of times that WiFi has entered the given state.
2309 *
2310 * {@hide}
2311 */
2312 public abstract int getWifiStateCount(int wifiState, int which);
2313
The Android Open Source Project10592532009-03-18 17:39:46 -07002314 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002315 * Returns the {@link Timer} object that tracks the given WiFi state.
2316 *
2317 * {@hide}
2318 */
2319 public abstract Timer getWifiStateTimer(int wifiState);
2320
2321 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002322 * Returns the time in microseconds that the wifi supplicant has been
2323 * in a given state.
2324 *
2325 * {@hide}
2326 */
2327 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2328
2329 /**
2330 * Returns the number of times that the wifi supplicant has transitioned
2331 * to a given state.
2332 *
2333 * {@hide}
2334 */
2335 public abstract int getWifiSupplStateCount(int state, int which);
2336
Kweku Adams87b19ec2017-10-09 12:40:03 -07002337 /**
2338 * Returns the {@link Timer} object that tracks the given wifi supplicant state.
2339 *
2340 * {@hide}
2341 */
2342 public abstract Timer getWifiSupplStateTimer(int state);
2343
Dianne Hackborn3251b902014-06-20 14:40:53 -07002344 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2345
2346 /**
2347 * Returns the time in microseconds that WIFI has been running with
2348 * the given signal strength.
2349 *
2350 * {@hide}
2351 */
2352 public abstract long getWifiSignalStrengthTime(int strengthBin,
2353 long elapsedRealtimeUs, int which);
2354
2355 /**
2356 * Returns the number of times WIFI has entered the given signal strength.
2357 *
2358 * {@hide}
2359 */
2360 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2361
2362 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002363 * Returns the {@link Timer} object that tracks the given WIFI signal strength.
2364 *
2365 * {@hide}
2366 */
2367 public abstract Timer getWifiSignalStrengthTimer(int strengthBin);
2368
2369 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002370 * Returns the time in microseconds that the flashlight has been on while the device was
2371 * running on battery.
2372 *
2373 * {@hide}
2374 */
2375 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2376
2377 /**
2378 * Returns the number of times that the flashlight has been turned on while the device was
2379 * running on battery.
2380 *
2381 * {@hide}
2382 */
2383 public abstract long getFlashlightOnCount(int which);
2384
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002385 /**
2386 * Returns the time in microseconds that the camera has been on while the device was
2387 * running on battery.
2388 *
2389 * {@hide}
2390 */
2391 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2392
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002393 /**
2394 * Returns the time in microseconds that bluetooth scans were running while the device was
2395 * on battery.
2396 *
2397 * {@hide}
2398 */
2399 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002400
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002401 public static final int NETWORK_MOBILE_RX_DATA = 0;
2402 public static final int NETWORK_MOBILE_TX_DATA = 1;
2403 public static final int NETWORK_WIFI_RX_DATA = 2;
2404 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002405 public static final int NETWORK_BT_RX_DATA = 4;
2406 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002407 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2408 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2409 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2410 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2411 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002412
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002413 public abstract long getNetworkActivityBytes(int type, int which);
2414 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002415
Adam Lesinskie08af192015-03-25 16:42:59 -07002416 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002417 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002418 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002419 * actual power data.
2420 */
2421 public abstract boolean hasWifiActivityReporting();
2422
2423 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002424 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2425 * in various radio controller states, such as transmit, receive, and idle.
2426 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002427 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002428 public abstract ControllerActivityCounter getWifiControllerActivity();
2429
2430 /**
2431 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2432 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2433 * actual power data.
2434 */
2435 public abstract boolean hasBluetoothActivityReporting();
2436
2437 /**
2438 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2439 * in various radio controller states, such as transmit, receive, and idle.
2440 * @return non-null {@link ControllerActivityCounter}
2441 */
2442 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2443
2444 /**
2445 * Returns true if the BatteryStats object has detailed modem power reports.
2446 * When true, calling {@link #getModemControllerActivity()} will yield the
2447 * actual power data.
2448 */
2449 public abstract boolean hasModemActivityReporting();
2450
2451 /**
2452 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2453 * in various radio controller states, such as transmit, receive, and idle.
2454 * @return non-null {@link ControllerActivityCounter}
2455 */
2456 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002457
The Android Open Source Project10592532009-03-18 17:39:46 -07002458 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002459 * Return the wall clock time when battery stats data collection started.
2460 */
2461 public abstract long getStartClockTime();
2462
2463 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002464 * Return platform version tag that we were running in when the battery stats started.
2465 */
2466 public abstract String getStartPlatformVersion();
2467
2468 /**
2469 * Return platform version tag that we were running in when the battery stats ended.
2470 */
2471 public abstract String getEndPlatformVersion();
2472
2473 /**
2474 * Return the internal version code of the parcelled format.
2475 */
2476 public abstract int getParcelVersion();
2477
2478 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 * Return whether we are currently running on battery.
2480 */
2481 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 /**
2484 * Returns a SparseArray containing the statistics for each uid.
2485 */
2486 public abstract SparseArray<? extends Uid> getUidStats();
2487
2488 /**
2489 * Returns the current battery uptime in microseconds.
2490 *
2491 * @param curTime the amount of elapsed realtime in microseconds.
2492 */
2493 public abstract long getBatteryUptime(long curTime);
2494
2495 /**
2496 * Returns the current battery realtime in microseconds.
2497 *
2498 * @param curTime the amount of elapsed realtime in microseconds.
2499 */
2500 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002501
The Android Open Source Project10592532009-03-18 17:39:46 -07002502 /**
Evan Millar633a1742009-04-02 16:36:33 -07002503 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002504 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002505 */
Evan Millar633a1742009-04-02 16:36:33 -07002506 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002507
The Android Open Source Project10592532009-03-18 17:39:46 -07002508 /**
Evan Millar633a1742009-04-02 16:36:33 -07002509 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2510 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002511 */
Evan Millar633a1742009-04-02 16:36:33 -07002512 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513
2514 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002515 * Get the amount the battery has discharged since the stats were
2516 * last reset after charging, as a lower-end approximation.
2517 */
2518 public abstract int getLowDischargeAmountSinceCharge();
2519
2520 /**
2521 * Get the amount the battery has discharged since the stats were
2522 * last reset after charging, as an upper-end approximation.
2523 */
2524 public abstract int getHighDischargeAmountSinceCharge();
2525
2526 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002527 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2528 */
2529 public abstract int getDischargeAmount(int which);
2530
2531 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002532 * Get the amount the battery has discharged while the screen was on,
2533 * since the last time power was unplugged.
2534 */
2535 public abstract int getDischargeAmountScreenOn();
2536
2537 /**
2538 * Get the amount the battery has discharged while the screen was on,
2539 * since the last time the device was charged.
2540 */
2541 public abstract int getDischargeAmountScreenOnSinceCharge();
2542
2543 /**
2544 * Get the amount the battery has discharged while the screen was off,
2545 * since the last time power was unplugged.
2546 */
2547 public abstract int getDischargeAmountScreenOff();
2548
2549 /**
2550 * Get the amount the battery has discharged while the screen was off,
2551 * since the last time the device was charged.
2552 */
2553 public abstract int getDischargeAmountScreenOffSinceCharge();
2554
2555 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002556 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002557 * since the last time power was unplugged.
2558 */
2559 public abstract int getDischargeAmountScreenDoze();
2560
2561 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002562 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002563 * since the last time the device was charged.
2564 */
2565 public abstract int getDischargeAmountScreenDozeSinceCharge();
2566
2567 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 * Returns the total, last, or current battery uptime in microseconds.
2569 *
2570 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002571 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 */
2573 public abstract long computeBatteryUptime(long curTime, int which);
2574
2575 /**
2576 * Returns the total, last, or current battery realtime in microseconds.
2577 *
2578 * @param curTime the current 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 computeBatteryRealtime(long curTime, int which);
2582
2583 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002584 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002585 *
2586 * @param curTime the 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.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002588 */
2589 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2590
2591 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002592 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002593 *
2594 * @param curTime the current 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 computeBatteryScreenOffRealtime(long curTime, int which);
2598
2599 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 * Returns the total, last, or current uptime in microseconds.
2601 *
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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 */
2605 public abstract long computeUptime(long curTime, int which);
2606
2607 /**
2608 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002609 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 * @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 computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002614
2615 /**
2616 * Compute an approximation for how much run time (in microseconds) is remaining on
2617 * the battery. Returns -1 if no time can be computed: either there is not
2618 * enough current data to make a decision, or the battery is currently
2619 * charging.
2620 *
2621 * @param curTime The current elepsed realtime in microseconds.
2622 */
2623 public abstract long computeBatteryTimeRemaining(long curTime);
2624
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002625 // The part of a step duration that is the actual time.
2626 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2627
2628 // Bits in a step duration that are the new battery level we are at.
2629 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002630 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002631
2632 // Bits in a step duration that are the initial mode we were in at that step.
2633 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002634 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002635
2636 // Bits in a step duration that indicate which modes changed during that step.
2637 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002638 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002639
2640 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2641 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2642
Santos Cordone94f0502017-02-24 12:31:20 -08002643 // The largest value for screen state that is tracked in battery states. Any values above
2644 // this should be mapped back to one of the tracked values before being tracked here.
2645 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2646
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002647 // Step duration mode: power save is on.
2648 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2649
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002650 // Step duration mode: device is currently in idle mode.
2651 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2652
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002653 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2654 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002655 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2656 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002657 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2658 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2659 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2660 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2661 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002662 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2663 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002664 };
2665 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2666 (Display.STATE_OFF-1),
2667 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002668 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002669 (Display.STATE_ON-1),
2670 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2671 (Display.STATE_DOZE-1),
2672 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2673 (Display.STATE_DOZE_SUSPEND-1),
2674 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002675 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002676 };
2677 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2678 "screen off",
2679 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002680 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002681 "screen on",
2682 "screen on power save",
2683 "screen doze",
2684 "screen doze power save",
2685 "screen doze-suspend",
2686 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002687 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002688 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002689
2690 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002691 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002692 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2693 * a coulomb counter.
2694 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002695 public abstract long getUahDischargeScreenOff(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002696
2697 /**
2698 * Return the amount of battery discharge while the screen was in doze mode, measured in
2699 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2700 * a coulomb counter.
2701 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002702 public abstract long getUahDischargeScreenDoze(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002703
2704 /**
2705 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2706 * non-zero only if the device's battery has a coulomb counter.
2707 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002708 public abstract long getUahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002709
2710 /**
Mike Ma15313c92017-11-15 17:58:21 -08002711 * @return the amount of battery discharge while the device is in light idle mode, measured in
2712 * micro-Ampere-hours.
2713 */
2714 public abstract long getUahDischargeLightDoze(int which);
2715
2716 /**
2717 * @return the amount of battery discharge while the device is in deep idle mode, measured in
2718 * micro-Ampere-hours.
2719 */
2720 public abstract long getUahDischargeDeepDoze(int which);
2721
2722 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002723 * Returns the estimated real battery capacity, which may be less than the capacity
2724 * declared by the PowerProfile.
2725 * @return The estimated battery capacity in mAh.
2726 */
2727 public abstract int getEstimatedBatteryCapacity();
2728
2729 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002730 * @return The minimum learned battery capacity in uAh.
2731 */
2732 public abstract int getMinLearnedBatteryCapacity();
2733
2734 /**
2735 * @return The maximum learned battery capacity in uAh.
2736 */
2737 public abstract int getMaxLearnedBatteryCapacity() ;
2738
2739 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002740 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002741 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002742 public abstract LevelStepTracker getDischargeLevelStepTracker();
2743
2744 /**
2745 * Return the array of daily discharge step durations.
2746 */
2747 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002748
2749 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002750 * Compute an approximation for how much time (in microseconds) remains until the battery
2751 * is fully charged. Returns -1 if no time can be computed: either there is not
2752 * enough current data to make a decision, or the battery is currently
2753 * discharging.
2754 *
2755 * @param curTime The current elepsed realtime in microseconds.
2756 */
2757 public abstract long computeChargeTimeRemaining(long curTime);
2758
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002759 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002760 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002761 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002762 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002763
2764 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002765 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002766 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002767 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002768
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002769 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2770
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002771 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002772
Evan Millarc64edde2009-04-18 12:26:32 -07002773 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774
Bookatz50df7112017-08-04 14:53:26 -07002775 /**
2776 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2777 */
2778 public abstract Map<String, ? extends Timer> getRpmStats();
2779 /**
2780 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2781 */
2782 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2783
2784
James Carr2dd7e5e2016-07-20 18:48:39 -07002785 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2786
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002787 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2788
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002789 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 long days = seconds / (60 * 60 * 24);
2791 if (days != 0) {
2792 out.append(days);
2793 out.append("d ");
2794 }
2795 long used = days * 60 * 60 * 24;
2796
2797 long hours = (seconds - used) / (60 * 60);
2798 if (hours != 0 || used != 0) {
2799 out.append(hours);
2800 out.append("h ");
2801 }
2802 used += hours * 60 * 60;
2803
2804 long mins = (seconds-used) / 60;
2805 if (mins != 0 || used != 0) {
2806 out.append(mins);
2807 out.append("m ");
2808 }
2809 used += mins * 60;
2810
2811 if (seconds != 0 || used != 0) {
2812 out.append(seconds-used);
2813 out.append("s ");
2814 }
2815 }
2816
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002817 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002819 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 sb.append(time - (sec * 1000));
2821 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 }
2823
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002824 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002825 long sec = time / 1000;
2826 formatTimeRaw(sb, sec);
2827 sb.append(time - (sec * 1000));
2828 sb.append("ms");
2829 }
2830
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002831 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002833 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 }
2835 float perc = ((float)num) / ((float)den) * 100;
2836 mFormatBuilder.setLength(0);
2837 mFormatter.format("%.1f%%", perc);
2838 return mFormatBuilder.toString();
2839 }
2840
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002841 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002842 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002843
Evan Millar22ac0432009-03-31 11:33:18 -07002844 if (bytes < BYTES_PER_KB) {
2845 return bytes + "B";
2846 } else if (bytes < BYTES_PER_MB) {
2847 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2848 return mFormatBuilder.toString();
2849 } else if (bytes < BYTES_PER_GB){
2850 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2851 return mFormatBuilder.toString();
2852 } else {
2853 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2854 return mFormatBuilder.toString();
2855 }
2856 }
2857
Kweku Adams103351f2017-10-16 14:39:34 -07002858 private static long roundUsToMs(long timeUs) {
2859 return (timeUs + 500) / 1000;
2860 }
2861
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002862 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002863 if (timer != null) {
2864 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002865 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002866 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2867 return totalTimeMillis;
2868 }
2869 return 0;
2870 }
2871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 /**
2873 *
2874 * @param sb a StringBuilder object.
2875 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002876 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002878 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 * @param linePrefix a String to be prepended to each line of output.
2880 * @return the line prefix
2881 */
2882 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002883 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002886 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002887
Evan Millarc64edde2009-04-18 12:26:32 -07002888 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 if (totalTimeMillis != 0) {
2890 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002891 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002892 if (name != null) {
2893 sb.append(name);
2894 sb.append(' ');
2895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 sb.append('(');
2897 sb.append(count);
2898 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002899 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2900 if (maxDurationMs >= 0) {
2901 sb.append(" max=");
2902 sb.append(maxDurationMs);
2903 }
Bookatz506a8182017-05-01 14:18:42 -07002904 // Put actual time if it is available and different from totalTimeMillis.
2905 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2906 if (totalDurMs > totalTimeMillis) {
2907 sb.append(" actual=");
2908 sb.append(totalDurMs);
2909 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002910 if (timer.isRunningLocked()) {
2911 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2912 if (currentMs >= 0) {
2913 sb.append(" (running for ");
2914 sb.append(currentMs);
2915 sb.append("ms)");
2916 } else {
2917 sb.append(" (running)");
2918 }
2919 }
2920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 return ", ";
2922 }
2923 }
2924 return linePrefix;
2925 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002926
2927 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002928 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002929 *
2930 * @param pw a PrintWriter object to print to.
2931 * @param sb a StringBuilder object.
2932 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002933 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002934 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2935 * @param prefix a String to be prepended to each line of output.
2936 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002937 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002938 */
2939 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002940 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002941 if (timer != null) {
2942 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002943 final long totalTimeMs = (timer.getTotalTimeLocked(
2944 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002945 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002946 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002947 sb.setLength(0);
2948 sb.append(prefix);
2949 sb.append(" ");
2950 sb.append(type);
2951 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002952 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002953 sb.append("realtime (");
2954 sb.append(count);
2955 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002956 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2957 if (maxDurationMs >= 0) {
2958 sb.append(" max=");
2959 sb.append(maxDurationMs);
2960 }
2961 if (timer.isRunningLocked()) {
2962 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2963 if (currentMs >= 0) {
2964 sb.append(" (running for ");
2965 sb.append(currentMs);
2966 sb.append("ms)");
2967 } else {
2968 sb.append(" (running)");
2969 }
2970 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002971 pw.println(sb.toString());
2972 return true;
2973 }
2974 }
2975 return false;
2976 }
Bookatzc8c44962017-05-11 12:12:54 -07002977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 /**
2979 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002980 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 * @param sb a StringBuilder object.
2982 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002983 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002985 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 * @param linePrefix a String to be prepended to each line of output.
2987 * @return the line prefix
2988 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002989 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2990 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 long totalTimeMicros = 0;
2992 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002993 long max = 0;
2994 long current = 0;
2995 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002997 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002998 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002999 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
3000 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07003001 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 }
3003 sb.append(linePrefix);
3004 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
3005 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07003006 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003008 sb.append(',');
3009 sb.append(current);
3010 sb.append(',');
3011 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07003012 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
3013 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
3014 // totalDuration independent of totalTimeMicros (since they are not pooled).
3015 if (name != null) {
3016 sb.append(',');
3017 sb.append(totalDuration);
3018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 return ",";
3020 }
Bookatz506a8182017-05-01 14:18:42 -07003021
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003022 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
3023 String type) {
3024 pw.print(BATTERY_STATS_CHECKIN_VERSION);
3025 pw.print(',');
3026 pw.print(uid);
3027 pw.print(',');
3028 pw.print(category);
3029 pw.print(',');
3030 pw.print(type);
3031 }
3032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 /**
3034 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07003035 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 * @param pw the PageWriter to dump log to
3037 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3038 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3039 * @param args type-dependent data arguments
3040 */
Bookatzc8c44962017-05-11 12:12:54 -07003041 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003043 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003044 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003045 pw.print(',');
3046 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003048 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003049 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07003050
3051 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003052 * Dump a given timer stat for terse checkin mode.
3053 *
3054 * @param pw the PageWriter to dump log to
3055 * @param uid the UID to log
3056 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3057 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3058 * @param timer a {@link Timer} to dump stats for
3059 * @param rawRealtime the current elapsed realtime of the system in microseconds
3060 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3061 */
3062 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
3063 Timer timer, long rawRealtime, int which) {
3064 if (timer != null) {
3065 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003066 final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which));
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003067 final int count = timer.getCountLocked(which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003068 if (totalTime != 0 || count != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003069 dumpLine(pw, uid, category, type, totalTime, count);
3070 }
3071 }
3072 }
3073
3074 /**
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003075 * Dump a given timer stat to the proto stream.
3076 *
3077 * @param proto the ProtoOutputStream to log to
3078 * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK)
3079 * @param timer a {@link Timer} to dump stats for
3080 * @param rawRealtimeUs the current elapsed realtime of the system in microseconds
3081 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3082 */
3083 private static void dumpTimer(ProtoOutputStream proto, long fieldId,
Kweku Adams87b19ec2017-10-09 12:40:03 -07003084 Timer timer, long rawRealtimeUs, int which) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003085 if (timer == null) {
3086 return;
3087 }
3088 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003089 final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which));
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003090 final int count = timer.getCountLocked(which);
Kweku Adams103351f2017-10-16 14:39:34 -07003091 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000);
3092 final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000);
3093 final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000);
3094 if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1
3095 || totalDurationMs != -1) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003096 final long token = proto.start(fieldId);
Kweku Adams103351f2017-10-16 14:39:34 -07003097 proto.write(TimerProto.DURATION_MS, timeMs);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003098 proto.write(TimerProto.COUNT, count);
Kweku Adams103351f2017-10-16 14:39:34 -07003099 // These values will be -1 for timers that don't implement the functionality.
3100 if (maxDurationMs != -1) {
3101 proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs);
3102 }
3103 if (curDurationMs != -1) {
3104 proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs);
3105 }
3106 if (totalDurationMs != -1) {
3107 proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs);
3108 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003109 proto.end(token);
3110 }
3111 }
3112
3113 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003114 * Checks if the ControllerActivityCounter has any data worth dumping.
3115 */
3116 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
3117 if (counter == null) {
3118 return false;
3119 }
3120
3121 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
3122 || counter.getRxTimeCounter().getCountLocked(which) != 0
3123 || counter.getPowerCounter().getCountLocked(which) != 0) {
3124 return true;
3125 }
3126
3127 for (LongCounter c : counter.getTxTimeCounters()) {
3128 if (c.getCountLocked(which) != 0) {
3129 return true;
3130 }
3131 }
3132 return false;
3133 }
3134
3135 /**
3136 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3137 * The order of the arguments in the final check in line is:
3138 *
3139 * idle, rx, power, tx...
3140 *
3141 * where tx... is one or more transmit level times.
3142 */
3143 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3144 String type,
3145 ControllerActivityCounter counter,
3146 int which) {
3147 if (!controllerActivityHasData(counter, which)) {
3148 return;
3149 }
3150
3151 dumpLineHeader(pw, uid, category, type);
3152 pw.print(",");
3153 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3154 pw.print(",");
3155 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3156 pw.print(",");
3157 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3158 for (LongCounter c : counter.getTxTimeCounters()) {
3159 pw.print(",");
3160 pw.print(c.getCountLocked(which));
3161 }
3162 pw.println();
3163 }
3164
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003165 /**
3166 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3167 */
3168 private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId,
3169 ControllerActivityCounter counter,
3170 int which) {
3171 if (!controllerActivityHasData(counter, which)) {
3172 return;
3173 }
3174
3175 final long cToken = proto.start(fieldId);
3176
3177 proto.write(ControllerActivityProto.IDLE_DURATION_MS,
3178 counter.getIdleTimeCounter().getCountLocked(which));
3179 proto.write(ControllerActivityProto.RX_DURATION_MS,
3180 counter.getRxTimeCounter().getCountLocked(which));
3181 proto.write(ControllerActivityProto.POWER_MAH,
3182 counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3183
3184 long tToken;
3185 LongCounter[] txCounters = counter.getTxTimeCounters();
3186 for (int i = 0; i < txCounters.length; ++i) {
3187 LongCounter c = txCounters[i];
3188 tToken = proto.start(ControllerActivityProto.TX);
3189 proto.write(ControllerActivityProto.TxLevel.LEVEL, i);
3190 proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which));
3191 proto.end(tToken);
3192 }
3193
3194 proto.end(cToken);
3195 }
3196
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003197 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3198 String prefix, String controllerName,
3199 ControllerActivityCounter counter,
3200 int which) {
3201 if (controllerActivityHasData(counter, which)) {
3202 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3203 }
3204 }
3205
3206 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3207 String controllerName,
3208 ControllerActivityCounter counter, int which) {
3209 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3210 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3211 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003212 // Battery real time
3213 final long totalControllerActivityTimeMs
3214 = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000;
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003215 long totalTxTimeMs = 0;
3216 for (LongCounter txState : counter.getTxTimeCounters()) {
3217 totalTxTimeMs += txState.getCountLocked(which);
3218 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003219 final long sleepTimeMs
3220 = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003221
3222 sb.setLength(0);
3223 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003224 sb.append(" ");
3225 sb.append(controllerName);
3226 sb.append(" Sleep time: ");
3227 formatTimeMs(sb, sleepTimeMs);
3228 sb.append("(");
3229 sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs));
3230 sb.append(")");
3231 pw.println(sb.toString());
3232
3233 sb.setLength(0);
3234 sb.append(prefix);
3235 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003236 sb.append(controllerName);
3237 sb.append(" Idle time: ");
3238 formatTimeMs(sb, idleTimeMs);
3239 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003240 sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003241 sb.append(")");
3242 pw.println(sb.toString());
3243
3244 sb.setLength(0);
3245 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003246 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003247 sb.append(controllerName);
3248 sb.append(" Rx time: ");
3249 formatTimeMs(sb, rxTimeMs);
3250 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003251 sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003252 sb.append(")");
3253 pw.println(sb.toString());
3254
3255 sb.setLength(0);
3256 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003257 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003258 sb.append(controllerName);
3259 sb.append(" Tx time: ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003260
Siddharth Ray3c648c42017-10-02 17:30:58 -07003261 String [] powerLevel;
3262 switch(controllerName) {
3263 case "Cellular":
3264 powerLevel = new String[] {
3265 " less than 0dBm: ",
3266 " 0dBm to 8dBm: ",
3267 " 8dBm to 15dBm: ",
3268 " 15dBm to 20dBm: ",
3269 " above 20dBm: "};
3270 break;
3271 default:
3272 powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"};
3273 break;
3274 }
3275 final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003276 if (numTxLvls > 1) {
Siddharth Ray3c648c42017-10-02 17:30:58 -07003277 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003278 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3279 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3280 sb.setLength(0);
3281 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003282 sb.append(" ");
3283 sb.append(powerLevel[lvl]);
3284 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003285 formatTimeMs(sb, txLvlTimeMs);
3286 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003287 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003288 sb.append(")");
3289 pw.println(sb.toString());
3290 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003291 } else {
3292 final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which);
3293 formatTimeMs(sb, txLvlTimeMs);
3294 sb.append("(");
3295 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
3296 sb.append(")");
3297 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003298 }
3299
Siddharth Ray3c648c42017-10-02 17:30:58 -07003300 if (powerDrainMaMs > 0) {
3301 sb.setLength(0);
3302 sb.append(prefix);
3303 sb.append(" ");
3304 sb.append(controllerName);
3305 sb.append(" Battery drain: ").append(
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003306 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
Siddharth Ray3c648c42017-10-02 17:30:58 -07003307 sb.append("mAh");
3308 pw.println(sb.toString());
3309 }
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003310 }
3311
3312 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003313 * Temporary for settings.
3314 */
3315 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3316 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3317 }
3318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 /**
3320 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003321 *
Kweku Adams87b19ec2017-10-09 12:40:03 -07003322 * NOTE: all times are expressed in microseconds, unless specified otherwise.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003324 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3325 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 final long rawUptime = SystemClock.uptimeMillis() * 1000;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003327 final long rawRealtimeMs = SystemClock.elapsedRealtime();
3328 final long rawRealtime = rawRealtimeMs * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3331 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003332 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3333 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3334 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 final long totalRealtime = computeRealtime(rawRealtime, which);
3336 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003337 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003338 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003339 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003340 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003341 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3342 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003343 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003344 rawRealtime, which);
3345 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3346 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003347 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003348 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003349 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003350 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003351 final long dischargeCount = getUahDischarge(which);
3352 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
3353 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Ma15313c92017-11-15 17:58:21 -08003354 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
3355 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003356
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003357 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003358
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003359 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003360 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003361
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003362 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003365 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003366 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003367 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003368 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003369 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003370 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003371 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003372 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3373 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003374
Bookatzc8c44962017-05-11 12:12:54 -07003375
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003376 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003377 long fullWakeLockTimeTotal = 0;
3378 long partialWakeLockTimeTotal = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003379 long multicastWakeLockTimeTotalMicros = 0;
3380 int multicastWakeLockCountTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003381
Evan Millar22ac0432009-03-31 11:33:18 -07003382 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003383 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003384
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003385 // First calculating the wakelock stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003386 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3387 = u.getWakelockStats();
3388 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3389 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003390
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003391 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3392 if (fullWakeTimer != null) {
3393 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3394 which);
3395 }
3396
3397 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3398 if (partialWakeTimer != null) {
3399 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3400 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003401 }
3402 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003403
3404 // Now calculating the wifi multicast wakelock stats
3405 final Timer mcTimer = u.getMulticastWakelockStats();
3406 if (mcTimer != null) {
3407 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
3408 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
3409 }
Evan Millar22ac0432009-03-31 11:33:18 -07003410 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003411
3412 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003413 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3414 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3415 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3416 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3417 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3418 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3419 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3420 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003421 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3422 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003423 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3424 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003425 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3426 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003427
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003428 // Dump Modem controller stats
3429 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3430 getModemControllerActivity(), which);
3431
Adam Lesinskie283d332015-04-16 12:29:25 -07003432 // Dump Wifi controller stats
3433 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3434 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003435 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003436 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003437
3438 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3439 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003440
3441 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003442 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3443 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445 // Dump misc stats
3446 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003447 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003448 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003449 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003450 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003451 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003452 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3453 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003454 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003455 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3456 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3457 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3458 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003459 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003460
Dianne Hackborn617f8772009-03-31 15:04:46 -07003461 // Dump screen brightness stats
3462 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3463 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003464 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003465 }
3466 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003467
Dianne Hackborn627bba72009-03-24 22:32:56 -07003468 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003469 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3470 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003471 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003472 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003473 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003474 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003475 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003476 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003477 args[i] = getPhoneSignalStrengthCount(i, which);
3478 }
3479 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003480
Dianne Hackborn627bba72009-03-24 22:32:56 -07003481 // Dump network type stats
3482 args = new Object[NUM_DATA_CONNECTION_TYPES];
3483 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003484 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003485 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003486 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3487 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3488 args[i] = getPhoneDataConnectionCount(i, which);
3489 }
3490 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003491
3492 // Dump wifi state stats
3493 args = new Object[NUM_WIFI_STATES];
3494 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003495 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003496 }
3497 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3498 for (int i=0; i<NUM_WIFI_STATES; i++) {
3499 args[i] = getWifiStateCount(i, which);
3500 }
3501 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3502
Dianne Hackborn3251b902014-06-20 14:40:53 -07003503 // Dump wifi suppl state stats
3504 args = new Object[NUM_WIFI_SUPPL_STATES];
3505 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3506 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3507 }
3508 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3509 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3510 args[i] = getWifiSupplStateCount(i, which);
3511 }
3512 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3513
3514 // Dump wifi signal strength stats
3515 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3516 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3517 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3518 }
3519 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3520 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3521 args[i] = getWifiSignalStrengthCount(i, which);
3522 }
3523 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3524
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003525 // Dump Multicast total stats
3526 dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA,
3527 multicastWakeLockTimeTotalMicros / 1000,
3528 multicastWakeLockCountTotal);
3529
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003530 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003531 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003532 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003533 }
Bookatzc8c44962017-05-11 12:12:54 -07003534
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003535 if (which == STATS_SINCE_UNPLUGGED) {
3536 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3537 getDischargeStartLevel()-getDischargeCurrentLevel(),
3538 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003539 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003540 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003541 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000,
3542 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003543 } else {
3544 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3545 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003546 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003547 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003548 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003549 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000,
3550 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003551 }
Bookatzc8c44962017-05-11 12:12:54 -07003552
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003553 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003554 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003555 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003556 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003557 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003558 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003559 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3560 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003561 }
Evan Millarc64edde2009-04-18 12:26:32 -07003562 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003563 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003564 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003565 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3566 // Not doing the regular wake lock formatting to remain compatible
3567 // with the old checkin format.
3568 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3569 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003570 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003571 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003572 }
3573 }
Evan Millarc64edde2009-04-18 12:26:32 -07003574 }
Bookatzc8c44962017-05-11 12:12:54 -07003575
Bookatz50df7112017-08-04 14:53:26 -07003576 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3577 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3578 if (rpmStats.size() > 0) {
3579 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3580 sb.setLength(0);
3581 Timer totalTimer = ent.getValue();
3582 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3583 int count = totalTimer.getCountLocked(which);
3584 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3585 long screenOffTimeMs = screenOffTimer != null
3586 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3587 int screenOffCount = screenOffTimer != null
3588 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003589 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3590 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3591 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3592 screenOffCount);
3593 } else {
3594 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3595 "\"" + ent.getKey() + "\"", timeMs, count);
3596 }
Bookatz50df7112017-08-04 14:53:26 -07003597 }
3598 }
3599
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003600 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003601 helper.create(this);
3602 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003603 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003604 if (sippers != null && sippers.size() > 0) {
3605 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3606 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003607 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003608 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3609 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
Kweku Adams87b19ec2017-10-09 12:40:03 -07003610 int uid = 0;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003611 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003612 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003613 String label;
3614 switch (bs.drainType) {
3615 case IDLE:
3616 label="idle";
3617 break;
3618 case CELL:
3619 label="cell";
3620 break;
3621 case PHONE:
3622 label="phone";
3623 break;
3624 case WIFI:
3625 label="wifi";
3626 break;
3627 case BLUETOOTH:
3628 label="blue";
3629 break;
3630 case SCREEN:
3631 label="scrn";
3632 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003633 case FLASHLIGHT:
3634 label="flashlight";
3635 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003636 case APP:
3637 uid = bs.uidObj.getUid();
3638 label = "uid";
3639 break;
3640 case USER:
3641 uid = UserHandle.getUid(bs.userId, 0);
3642 label = "user";
3643 break;
3644 case UNACCOUNTED:
3645 label = "unacc";
3646 break;
3647 case OVERCOUNTED:
3648 label = "over";
3649 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003650 case CAMERA:
3651 label = "camera";
3652 break;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003653 case MEMORY:
3654 label = "memory";
3655 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003656 default:
3657 label = "???";
3658 }
3659 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003660 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3661 bs.shouldHide ? 1 : 0,
3662 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3663 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003664 }
3665 }
3666
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003667 final long[] cpuFreqs = getCpuFreqs();
3668 if (cpuFreqs != null) {
3669 sb.setLength(0);
3670 for (int i = 0; i < cpuFreqs.length; ++i) {
3671 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3672 }
3673 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3674 }
3675
Kweku Adams87b19ec2017-10-09 12:40:03 -07003676 // Dump stats per UID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 for (int iu = 0; iu < NU; iu++) {
3678 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003679 if (reqUid >= 0 && uid != reqUid) {
3680 continue;
3681 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003682 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003685 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3686 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3687 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3688 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3689 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3690 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3691 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3692 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003693 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003694 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3695 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003696 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003697 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3698 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003699 // Background data transfers
3700 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3701 which);
3702 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3703 which);
3704 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3705 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3706 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3707 which);
3708 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3709 which);
3710 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3711 which);
3712 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3713 which);
3714
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003715 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3716 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003717 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003718 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3719 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3720 || wifiBytesBgTx > 0
3721 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3722 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003723 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3724 wifiBytesRx, wifiBytesTx,
3725 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003726 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003727 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003728 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3729 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3730 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3731 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003732 }
3733
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003734 // Dump modem controller data, per UID.
3735 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3736 u.getModemControllerActivity(), which);
3737
3738 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003739 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3740 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3741 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003742 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3743 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003744 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3745 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3746 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003747 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003748 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003749 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3750 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003751 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3752 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003753 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003754 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003757 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3758 u.getWifiControllerActivity(), which);
3759
Bookatz867c0d72017-03-07 18:23:42 -08003760 final Timer bleTimer = u.getBluetoothScanTimer();
3761 if (bleTimer != null) {
3762 // Convert from microseconds to milliseconds with rounding
3763 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3764 / 1000;
3765 if (totalTime != 0) {
3766 final int count = bleTimer.getCountLocked(which);
3767 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3768 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003769 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3770 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3771 final long actualTimeBg = bleTimerBg != null ?
3772 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003773 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003774 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3775 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003776 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3777 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3778 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3779 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3780 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3781 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3782 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3783 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3784 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3785 final Timer unoptimizedScanTimerBg =
3786 u.getBluetoothUnoptimizedScanBackgroundTimer();
3787 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3788 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3789 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3790 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3791
Bookatz867c0d72017-03-07 18:23:42 -08003792 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003793 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3794 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3795 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003796 }
3797 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003798
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003799 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3800 u.getBluetoothControllerActivity(), which);
3801
Dianne Hackborn617f8772009-03-31 15:04:46 -07003802 if (u.hasUserActivity()) {
3803 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3804 boolean hasData = false;
3805 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3806 int val = u.getUserActivityCount(i, which);
3807 args[i] = val;
3808 if (val != 0) hasData = true;
3809 }
3810 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003811 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003812 }
3813 }
Bookatzc8c44962017-05-11 12:12:54 -07003814
3815 if (u.getAggregatedPartialWakelockTimer() != null) {
3816 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003817 // Times are since reset (regardless of 'which')
3818 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003819 final Timer bgTimer = timer.getSubTimer();
3820 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003821 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003822 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3823 }
3824
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003825 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3826 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3827 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3828 String linePrefix = "";
3829 sb.setLength(0);
3830 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3831 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003832 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3833 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003834 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003835 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3836 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003837 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3838 rawRealtime, "w", which, linePrefix);
3839
Kweku Adams103351f2017-10-16 14:39:34 -07003840 // Only log if we had at least one wakelock...
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003841 if (sb.length() > 0) {
3842 String name = wakelocks.keyAt(iw);
3843 if (name.indexOf(',') >= 0) {
3844 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
Yi Jin02483362017-08-04 11:30:44 -07003846 if (name.indexOf('\n') >= 0) {
3847 name = name.replace('\n', '_');
3848 }
3849 if (name.indexOf('\r') >= 0) {
3850 name = name.replace('\r', '_');
3851 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003852 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 }
3854 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003855
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003856 // WiFi Multicast Wakelock Statistics
3857 final Timer mcTimer = u.getMulticastWakelockStats();
3858 if (mcTimer != null) {
3859 final long totalMcWakelockTimeMs =
3860 mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ;
3861 final int countMcWakelock = mcTimer.getCountLocked(which);
3862 if(totalMcWakelockTimeMs > 0) {
3863 dumpLine(pw, uid, category, WIFI_MULTICAST_DATA,
3864 totalMcWakelockTimeMs, countMcWakelock);
3865 }
3866 }
3867
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003868 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3869 for (int isy=syncs.size()-1; isy>=0; isy--) {
3870 final Timer timer = syncs.valueAt(isy);
3871 // Convert from microseconds to milliseconds with rounding
3872 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3873 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003874 final Timer bgTimer = timer.getSubTimer();
3875 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003876 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003877 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003878 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003879 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003880 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003881 }
3882 }
3883
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003884 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3885 for (int ij=jobs.size()-1; ij>=0; ij--) {
3886 final Timer timer = jobs.valueAt(ij);
3887 // Convert from microseconds to milliseconds with rounding
3888 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3889 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003890 final Timer bgTimer = timer.getSubTimer();
3891 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003892 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003893 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003894 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003895 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003896 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003897 }
3898 }
3899
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003900 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3901 for (int ic=completions.size()-1; ic>=0; ic--) {
3902 SparseIntArray types = completions.valueAt(ic);
3903 if (types != null) {
3904 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3905 "\"" + completions.keyAt(ic) + "\"",
3906 types.get(JobParameters.REASON_CANCELED, 0),
3907 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3908 types.get(JobParameters.REASON_PREEMPT, 0),
3909 types.get(JobParameters.REASON_TIMEOUT, 0),
3910 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3911 }
3912 }
3913
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003914 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3915 rawRealtime, which);
3916 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3917 rawRealtime, which);
3918 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3919 rawRealtime, which);
3920 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3921 rawRealtime, which);
3922
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003923 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3924 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003925 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003926 final Uid.Sensor se = sensors.valueAt(ise);
3927 final int sensorNumber = sensors.keyAt(ise);
3928 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003929 if (timer != null) {
3930 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003931 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3932 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003933 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003934 final int count = timer.getCountLocked(which);
3935 final Timer bgTimer = se.getSensorBackgroundTime();
3936 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003937 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3938 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3939 final long bgActualTime = bgTimer != null ?
3940 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3941 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3942 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 }
3945 }
3946
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003947 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3948 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003949
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003950 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3951 rawRealtime, which);
3952
3953 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003954 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003955
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003956 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003957 long totalStateTime = 0;
3958 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003959 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3960 totalStateTime += time;
3961 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003962 }
3963 if (totalStateTime > 0) {
3964 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3965 }
3966
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003967 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3968 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003969 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003970 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003971 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003972 }
3973
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003974 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3975 if (cpuFreqs != null) {
3976 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3977 // If total cpuFreqTimes is null, then we don't need to check for
3978 // screenOffCpuFreqTimes.
3979 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3980 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003981 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003982 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003983 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003984 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3985 if (screenOffCpuFreqTimeMs != null) {
3986 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3987 sb.append("," + screenOffCpuFreqTimeMs[i]);
3988 }
3989 } else {
3990 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3991 sb.append(",0");
3992 }
3993 }
3994 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3995 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003996 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003997 }
3998
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003999 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4000 = u.getProcessStats();
4001 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4002 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004003
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004004 final long userMillis = ps.getUserTime(which);
4005 final long systemMillis = ps.getSystemTime(which);
4006 final long foregroundMillis = ps.getForegroundTime(which);
4007 final int starts = ps.getStarts(which);
4008 final int numCrashes = ps.getNumCrashes(which);
4009 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004010
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004011 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
4012 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004013 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
4014 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 }
4016 }
4017
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004018 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4019 = u.getPackageStats();
4020 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4021 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4022 int wakeups = 0;
4023 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4024 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07004025 int count = alarms.valueAt(iwa).getCountLocked(which);
4026 wakeups += count;
4027 String name = alarms.keyAt(iwa).replace(',', '_');
4028 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004029 }
4030 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4031 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4032 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4033 final long startTime = ss.getStartTime(batteryUptime, which);
4034 final int starts = ss.getStarts(which);
4035 final int launches = ss.getLaunches(which);
4036 if (startTime != 0 || starts != 0 || launches != 0) {
4037 dumpLine(pw, uid, category, APK_DATA,
4038 wakeups, // wakeup alarms
4039 packageStats.keyAt(ipkg), // Apk
4040 serviceStats.keyAt(isvc), // service
4041 startTime / 1000, // time spent started, in ms
4042 starts,
4043 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004044 }
4045 }
4046 }
4047 }
4048 }
4049
Dianne Hackborn81038902012-11-26 17:04:09 -08004050 static final class TimerEntry {
4051 final String mName;
4052 final int mId;
4053 final BatteryStats.Timer mTimer;
4054 final long mTime;
4055 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
4056 mName = name;
4057 mId = id;
4058 mTimer = timer;
4059 mTime = time;
4060 }
4061 }
4062
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004063 private void printmAh(PrintWriter printer, double power) {
4064 printer.print(BatteryStatsHelper.makemAh(power));
4065 }
4066
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004067 private void printmAh(StringBuilder sb, double power) {
4068 sb.append(BatteryStatsHelper.makemAh(power));
4069 }
4070
Dianne Hackbornd953c532014-08-16 18:17:38 -07004071 /**
4072 * Temporary for settings.
4073 */
4074 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
4075 int reqUid) {
4076 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
4077 }
4078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004080 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07004081 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 final long rawUptime = SystemClock.uptimeMillis() * 1000;
4083 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07004084 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086
4087 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
4088 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
4089 final long totalRealtime = computeRealtime(rawRealtime, which);
4090 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004091 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
4092 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
4093 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004094 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
4095 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07004096 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004097
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004098 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07004099
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004100 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07004101 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102
Adam Lesinskif9b20a92016-06-17 17:30:01 -07004103 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
4104 if (estimatedBatteryCapacity > 0) {
4105 sb.setLength(0);
4106 sb.append(prefix);
4107 sb.append(" Estimated battery capacity: ");
4108 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
4109 sb.append(" mAh");
4110 pw.println(sb.toString());
4111 }
4112
Jocelyn Dangc627d102017-04-14 13:15:14 -07004113 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
4114 if (minLearnedBatteryCapacity > 0) {
4115 sb.setLength(0);
4116 sb.append(prefix);
4117 sb.append(" Min learned battery capacity: ");
4118 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
4119 sb.append(" mAh");
4120 pw.println(sb.toString());
4121 }
4122 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
4123 if (maxLearnedBatteryCapacity > 0) {
4124 sb.setLength(0);
4125 sb.append(prefix);
4126 sb.append(" Max learned battery capacity: ");
4127 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
4128 sb.append(" mAh");
4129 pw.println(sb.toString());
4130 }
4131
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004132 sb.setLength(0);
4133 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004134 sb.append(" Time on battery: ");
4135 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
4136 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
4137 sb.append(") realtime, ");
4138 formatTimeMs(sb, whichBatteryUptime / 1000);
4139 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
4140 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004141 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004142
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004143 sb.setLength(0);
4144 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004145 sb.append(" Time on battery screen off: ");
4146 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
4147 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
4148 sb.append(") realtime, ");
4149 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
4150 sb.append("(");
4151 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
4152 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004153 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004154
4155 sb.setLength(0);
4156 sb.append(prefix);
4157 sb.append(" Time on battery screen doze: ");
4158 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
4159 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
4160 sb.append(")");
4161 pw.println(sb.toString());
4162
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004163 sb.setLength(0);
4164 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004165 sb.append(" Total run time: ");
4166 formatTimeMs(sb, totalRealtime / 1000);
4167 sb.append("realtime, ");
4168 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004169 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07004170 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004171 if (batteryTimeRemaining >= 0) {
4172 sb.setLength(0);
4173 sb.append(prefix);
4174 sb.append(" Battery time remaining: ");
4175 formatTimeMs(sb, batteryTimeRemaining / 1000);
4176 pw.println(sb.toString());
4177 }
4178 if (chargeTimeRemaining >= 0) {
4179 sb.setLength(0);
4180 sb.append(prefix);
4181 sb.append(" Charge time remaining: ");
4182 formatTimeMs(sb, chargeTimeRemaining / 1000);
4183 pw.println(sb.toString());
4184 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004185
Kweku Adams87b19ec2017-10-09 12:40:03 -07004186 final long dischargeCount = getUahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004187 if (dischargeCount >= 0) {
4188 sb.setLength(0);
4189 sb.append(prefix);
4190 sb.append(" Discharge: ");
4191 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
4192 sb.append(" mAh");
4193 pw.println(sb.toString());
4194 }
4195
Kweku Adams87b19ec2017-10-09 12:40:03 -07004196 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004197 if (dischargeScreenOffCount >= 0) {
4198 sb.setLength(0);
4199 sb.append(prefix);
4200 sb.append(" Screen off discharge: ");
4201 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
4202 sb.append(" mAh");
4203 pw.println(sb.toString());
4204 }
4205
Kweku Adams87b19ec2017-10-09 12:40:03 -07004206 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Mac2f518a2017-09-19 16:06:03 -07004207 if (dischargeScreenDozeCount >= 0) {
4208 sb.setLength(0);
4209 sb.append(prefix);
4210 sb.append(" Screen doze discharge: ");
4211 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
4212 sb.append(" mAh");
4213 pw.println(sb.toString());
4214 }
4215
4216 final long dischargeScreenOnCount =
4217 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004218 if (dischargeScreenOnCount >= 0) {
4219 sb.setLength(0);
4220 sb.append(prefix);
4221 sb.append(" Screen on discharge: ");
4222 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4223 sb.append(" mAh");
4224 pw.println(sb.toString());
4225 }
4226
Mike Ma15313c92017-11-15 17:58:21 -08004227 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
4228 if (dischargeLightDozeCount >= 0) {
4229 sb.setLength(0);
4230 sb.append(prefix);
4231 sb.append(" Device light doze discharge: ");
4232 sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0));
4233 sb.append(" mAh");
4234 pw.println(sb.toString());
4235 }
4236
4237 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
4238 if (dischargeDeepDozeCount >= 0) {
4239 sb.setLength(0);
4240 sb.append(prefix);
4241 sb.append(" Device deep doze discharge: ");
4242 sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0));
4243 sb.append(" mAh");
4244 pw.println(sb.toString());
4245 }
4246
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004247 pw.print(" Start clock time: ");
4248 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4249
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004250 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004251 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004252 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004253 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4254 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004255 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004256 rawRealtime, which);
4257 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4258 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004259 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004260 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004261 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4262 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4263 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004264 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004265 sb.append(prefix);
4266 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4267 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004268 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004269 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4270 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004271 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004272 pw.println(sb.toString());
4273 sb.setLength(0);
4274 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004275 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004276 boolean didOne = false;
4277 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004278 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004279 if (time == 0) {
4280 continue;
4281 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004282 sb.append("\n ");
4283 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004284 didOne = true;
4285 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4286 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004287 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004288 sb.append("(");
4289 sb.append(formatRatioLocked(time, screenOnTime));
4290 sb.append(")");
4291 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004292 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004293 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004294 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004295 sb.setLength(0);
4296 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004297 sb.append(" Power save mode enabled: ");
4298 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004299 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004300 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004301 sb.append(")");
4302 pw.println(sb.toString());
4303 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004304 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004305 sb.setLength(0);
4306 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004307 sb.append(" Device light idling: ");
4308 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004309 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004310 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4311 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004312 sb.append("x");
4313 pw.println(sb.toString());
4314 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004315 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004316 sb.setLength(0);
4317 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004318 sb.append(" Idle mode light time: ");
4319 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004320 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004321 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4322 sb.append(") ");
4323 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004324 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004325 sb.append(" -- longest ");
4326 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4327 pw.println(sb.toString());
4328 }
4329 if (deviceIdlingTime != 0) {
4330 sb.setLength(0);
4331 sb.append(prefix);
4332 sb.append(" Device full idling: ");
4333 formatTimeMs(sb, deviceIdlingTime / 1000);
4334 sb.append("(");
4335 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004336 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004337 sb.append("x");
4338 pw.println(sb.toString());
4339 }
4340 if (deviceIdleModeFullTime != 0) {
4341 sb.setLength(0);
4342 sb.append(prefix);
4343 sb.append(" Idle mode full time: ");
4344 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4345 sb.append("(");
4346 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4347 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004348 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004349 sb.append("x");
4350 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004351 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004352 pw.println(sb.toString());
4353 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004354 if (phoneOnTime != 0) {
4355 sb.setLength(0);
4356 sb.append(prefix);
4357 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4358 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004359 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004360 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004361 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004362 if (connChanges != 0) {
4363 pw.print(prefix);
4364 pw.print(" Connectivity changes: "); pw.println(connChanges);
4365 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004366
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004367 // Calculate both wakelock and wifi multicast wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004368 long fullWakeLockTimeTotalMicros = 0;
4369 long partialWakeLockTimeTotalMicros = 0;
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004370 long multicastWakeLockTimeTotalMicros = 0;
4371 int multicastWakeLockCountTotal = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004372
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004373 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004374
Evan Millar22ac0432009-03-31 11:33:18 -07004375 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004376 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004377
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004378 // First calculate wakelock statistics
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004379 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4380 = u.getWakelockStats();
4381 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4382 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004383
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004384 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4385 if (fullWakeTimer != null) {
4386 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4387 rawRealtime, which);
4388 }
4389
4390 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4391 if (partialWakeTimer != null) {
4392 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4393 rawRealtime, which);
4394 if (totalTimeMicros > 0) {
4395 if (reqUid < 0) {
4396 // Only show the ordered list of all wake
4397 // locks if the caller is not asking for data
4398 // about a specific uid.
4399 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4400 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004401 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004402 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004403 }
4404 }
4405 }
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004406
4407 // Next calculate wifi multicast wakelock statistics
4408 final Timer mcTimer = u.getMulticastWakelockStats();
4409 if (mcTimer != null) {
4410 multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which);
4411 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
4412 }
Evan Millar22ac0432009-03-31 11:33:18 -07004413 }
Bookatzc8c44962017-05-11 12:12:54 -07004414
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004415 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4416 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4417 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4418 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4419 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4420 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4421 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4422 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004423 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4424 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004425
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004426 if (fullWakeLockTimeTotalMicros != 0) {
4427 sb.setLength(0);
4428 sb.append(prefix);
4429 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4430 (fullWakeLockTimeTotalMicros + 500) / 1000);
4431 pw.println(sb.toString());
4432 }
4433
4434 if (partialWakeLockTimeTotalMicros != 0) {
4435 sb.setLength(0);
4436 sb.append(prefix);
4437 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4438 (partialWakeLockTimeTotalMicros + 500) / 1000);
4439 pw.println(sb.toString());
4440 }
4441
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004442 if (multicastWakeLockTimeTotalMicros != 0) {
4443 sb.setLength(0);
4444 sb.append(prefix);
4445 sb.append(" Total WiFi Multicast wakelock Count: ");
4446 sb.append(multicastWakeLockCountTotal);
4447 pw.println(sb.toString());
4448
4449 sb.setLength(0);
4450 sb.append(prefix);
4451 sb.append(" Total WiFi Multicast wakelock time: ");
4452 formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000);
4453 pw.println(sb.toString());
4454 }
4455
Siddharth Ray3c648c42017-10-02 17:30:58 -07004456 pw.println("");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004457 pw.print(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004458 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004459 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004460 sb.append(" CONNECTIVITY POWER SUMMARY START");
4461 pw.println(sb.toString());
4462
4463 pw.print(prefix);
4464 sb.setLength(0);
4465 sb.append(prefix);
4466 sb.append(" Logging duration for connectivity statistics: ");
4467 formatTimeMs(sb, whichBatteryRealtime / 1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004468 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004469
4470 sb.setLength(0);
4471 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004472 sb.append(" Cellular Statistics:");
Amith Yamasanif37447b2009-10-08 18:28:01 -07004473 pw.println(sb.toString());
4474
Siddharth Ray3c648c42017-10-02 17:30:58 -07004475 pw.print(prefix);
4476 sb.setLength(0);
4477 sb.append(prefix);
4478 sb.append(" Cellular kernel active time: ");
4479 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
4480 formatTimeMs(sb, mobileActiveTime / 1000);
4481 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4482 sb.append(")");
4483 pw.println(sb.toString());
4484
4485 pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes));
4486 pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes));
4487 pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets);
4488 pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets);
4489
Dianne Hackborn627bba72009-03-24 22:32:56 -07004490 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004491 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004492 sb.append(" Cellular Radio Access Technology:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004493 didOne = false;
4494 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004495 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004496 if (time == 0) {
4497 continue;
4498 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004499 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004500 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004501 didOne = true;
4502 sb.append(DATA_CONNECTION_NAMES[i]);
4503 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004504 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004505 sb.append("(");
4506 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004507 sb.append(") ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004508 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004509 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004510 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004511
4512 sb.setLength(0);
4513 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004514 sb.append(" Cellular Rx signal strength (RSRP):");
4515 final String[] cellularRxSignalStrengthDescription = new String[]{
4516 "very poor (less than -128dBm): ",
4517 "poor (-128dBm to -118dBm): ",
4518 "moderate (-118dBm to -108dBm): ",
4519 "good (-108dBm to -98dBm): ",
4520 "great (greater than -98dBm): "};
4521 didOne = false;
4522 final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS,
4523 cellularRxSignalStrengthDescription.length);
4524 for (int i=0; i<numCellularRxBins; i++) {
4525 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
4526 if (time == 0) {
4527 continue;
4528 }
4529 sb.append("\n ");
4530 sb.append(prefix);
4531 didOne = true;
4532 sb.append(cellularRxSignalStrengthDescription[i]);
4533 sb.append(" ");
4534 formatTimeMs(sb, time/1000);
4535 sb.append("(");
4536 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4537 sb.append(") ");
4538 }
4539 if (!didOne) sb.append(" (no activity)");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004540 pw.println(sb.toString());
4541
Siddharth Ray3c648c42017-10-02 17:30:58 -07004542 printControllerActivity(pw, sb, prefix, "Cellular",
4543 getModemControllerActivity(), which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004544
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004545 pw.print(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004546 sb.setLength(0);
4547 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004548 sb.append(" Wifi Statistics:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004549 pw.println(sb.toString());
4550
Siddharth Ray3c648c42017-10-02 17:30:58 -07004551 pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes));
4552 pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes));
4553 pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets);
4554 pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets);
4555
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004556 sb.setLength(0);
4557 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004558 sb.append(" Wifi states:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004559 didOne = false;
4560 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004561 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004562 if (time == 0) {
4563 continue;
4564 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004565 sb.append("\n ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004566 didOne = true;
4567 sb.append(WIFI_STATE_NAMES[i]);
4568 sb.append(" ");
4569 formatTimeMs(sb, time/1000);
4570 sb.append("(");
4571 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4572 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004573 }
4574 if (!didOne) sb.append(" (no activity)");
4575 pw.println(sb.toString());
4576
4577 sb.setLength(0);
4578 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004579 sb.append(" Wifi supplicant states:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004580 didOne = false;
4581 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4582 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4583 if (time == 0) {
4584 continue;
4585 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004586 sb.append("\n ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004587 didOne = true;
4588 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4589 sb.append(" ");
4590 formatTimeMs(sb, time/1000);
4591 sb.append("(");
4592 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4593 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004594 }
4595 if (!didOne) sb.append(" (no activity)");
4596 pw.println(sb.toString());
4597
4598 sb.setLength(0);
4599 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004600 sb.append(" Wifi Rx signal strength (RSSI):");
4601 final String[] wifiRxSignalStrengthDescription = new String[]{
4602 "very poor (less than -88.75dBm): ",
4603 "poor (-88.75 to -77.5dBm): ",
4604 "moderate (-77.5dBm to -66.25dBm): ",
4605 "good (-66.25dBm to -55dBm): ",
4606 "great (greater than -55dBm): "};
Dianne Hackborn3251b902014-06-20 14:40:53 -07004607 didOne = false;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004608 final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS,
4609 wifiRxSignalStrengthDescription.length);
4610 for (int i=0; i<numWifiRxBins; i++) {
Dianne Hackborn3251b902014-06-20 14:40:53 -07004611 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4612 if (time == 0) {
4613 continue;
4614 }
4615 sb.append("\n ");
4616 sb.append(prefix);
4617 didOne = true;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004618 sb.append(" ");
4619 sb.append(wifiRxSignalStrengthDescription[i]);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004620 formatTimeMs(sb, time/1000);
4621 sb.append("(");
4622 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4623 sb.append(") ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004624 }
4625 if (!didOne) sb.append(" (no activity)");
4626 pw.println(sb.toString());
4627
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004628 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004629
Adam Lesinski50e47602015-12-04 17:04:54 -08004630 pw.print(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004631 sb.setLength(0);
4632 sb.append(prefix);
4633 sb.append(" CONNECTIVITY POWER SUMMARY END");
4634 pw.println(sb.toString());
4635 pw.println("");
4636
4637 pw.print(prefix);
Adam Lesinski50e47602015-12-04 17:04:54 -08004638 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4639 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4640
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004641 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4642 sb.setLength(0);
4643 sb.append(prefix);
4644 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4645 pw.println(sb.toString());
4646
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004647 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4648 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004649
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004650 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004651
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004652 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004653 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004654 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004655 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004656 pw.println(getDischargeStartLevel());
4657 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4658 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004659 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004660 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004661 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004662 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004663 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004664 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004665 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004666 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004667 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004668 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004669 pw.println(getDischargeAmountScreenOff());
4670 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4671 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004672 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004673 } else {
4674 pw.print(prefix); pw.println(" Device battery use since last full charge");
4675 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004676 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004677 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004678 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004679 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004680 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004681 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004682 pw.println(getDischargeAmountScreenOffSinceCharge());
4683 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4684 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004685 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004686 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004687
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004688 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004689 helper.create(this);
4690 helper.refreshStats(which, UserHandle.USER_ALL);
4691 List<BatterySipper> sippers = helper.getUsageList();
4692 if (sippers != null && sippers.size() > 0) {
4693 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4694 pw.print(prefix); pw.print(" Capacity: ");
4695 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004696 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004697 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4698 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4699 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4700 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004701 pw.println();
4702 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004703 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004704 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004705 switch (bs.drainType) {
4706 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004707 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004708 break;
4709 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004710 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004711 break;
4712 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004713 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004714 break;
4715 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004716 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004717 break;
4718 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004719 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004720 break;
4721 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004722 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004723 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004724 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004725 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004726 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004727 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004728 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004729 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004730 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004731 break;
4732 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004733 pw.print(" User "); pw.print(bs.userId);
4734 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004735 break;
4736 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004737 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004738 break;
4739 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004740 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004741 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004742 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004743 pw.print(" Camera: ");
4744 break;
4745 default:
4746 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004747 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004748 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004749 printmAh(pw, bs.totalPowerMah);
4750
Adam Lesinski57123002015-06-12 16:12:07 -07004751 if (bs.usagePowerMah != bs.totalPowerMah) {
4752 // If the usage (generic power) isn't the whole amount, we list out
4753 // what components are involved in the calculation.
4754
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004755 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004756 if (bs.usagePowerMah != 0) {
4757 pw.print(" usage=");
4758 printmAh(pw, bs.usagePowerMah);
4759 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004760 if (bs.cpuPowerMah != 0) {
4761 pw.print(" cpu=");
4762 printmAh(pw, bs.cpuPowerMah);
4763 }
4764 if (bs.wakeLockPowerMah != 0) {
4765 pw.print(" wake=");
4766 printmAh(pw, bs.wakeLockPowerMah);
4767 }
4768 if (bs.mobileRadioPowerMah != 0) {
4769 pw.print(" radio=");
4770 printmAh(pw, bs.mobileRadioPowerMah);
4771 }
4772 if (bs.wifiPowerMah != 0) {
4773 pw.print(" wifi=");
4774 printmAh(pw, bs.wifiPowerMah);
4775 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004776 if (bs.bluetoothPowerMah != 0) {
4777 pw.print(" bt=");
4778 printmAh(pw, bs.bluetoothPowerMah);
4779 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004780 if (bs.gpsPowerMah != 0) {
4781 pw.print(" gps=");
4782 printmAh(pw, bs.gpsPowerMah);
4783 }
4784 if (bs.sensorPowerMah != 0) {
4785 pw.print(" sensor=");
4786 printmAh(pw, bs.sensorPowerMah);
4787 }
4788 if (bs.cameraPowerMah != 0) {
4789 pw.print(" camera=");
4790 printmAh(pw, bs.cameraPowerMah);
4791 }
4792 if (bs.flashlightPowerMah != 0) {
4793 pw.print(" flash=");
4794 printmAh(pw, bs.flashlightPowerMah);
4795 }
4796 pw.print(" )");
4797 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004798
4799 // If there is additional smearing information, include it.
4800 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4801 pw.print(" Including smearing: ");
4802 printmAh(pw, bs.totalSmearedPowerMah);
4803 pw.print(" (");
4804 if (bs.screenPowerMah != 0) {
4805 pw.print(" screen=");
4806 printmAh(pw, bs.screenPowerMah);
4807 }
4808 if (bs.proportionalSmearMah != 0) {
4809 pw.print(" proportional=");
4810 printmAh(pw, bs.proportionalSmearMah);
4811 }
4812 pw.print(" )");
4813 }
4814 if (bs.shouldHide) {
4815 pw.print(" Excluded from smearing");
4816 }
4817
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004818 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004819 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004820 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004821 }
4822
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004823 sippers = helper.getMobilemsppList();
4824 if (sippers != null && sippers.size() > 0) {
4825 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004826 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004827 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004828 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004829 sb.setLength(0);
4830 sb.append(prefix); sb.append(" Uid ");
4831 UserHandle.formatUid(sb, bs.uidObj.getUid());
4832 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4833 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4834 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004835 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004836 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004837 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004838 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004839 sb.setLength(0);
4840 sb.append(prefix);
4841 sb.append(" TOTAL TIME: ");
4842 formatTimeMs(sb, totalTime);
4843 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4844 sb.append(")");
4845 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004846 pw.println();
4847 }
4848
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004849 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4850 @Override
4851 public int compare(TimerEntry lhs, TimerEntry rhs) {
4852 long lhsTime = lhs.mTime;
4853 long rhsTime = rhs.mTime;
4854 if (lhsTime < rhsTime) {
4855 return 1;
4856 }
4857 if (lhsTime > rhsTime) {
4858 return -1;
4859 }
4860 return 0;
4861 }
4862 };
4863
4864 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004865 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4866 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004867 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004868 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4869 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4870 : kernelWakelocks.entrySet()) {
4871 final BatteryStats.Timer timer = ent.getValue();
4872 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004873 if (totalTimeMillis > 0) {
4874 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4875 }
4876 }
4877 if (ktimers.size() > 0) {
4878 Collections.sort(ktimers, timerComparator);
4879 pw.print(prefix); pw.println(" All kernel wake locks:");
4880 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004881 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004882 String linePrefix = ": ";
4883 sb.setLength(0);
4884 sb.append(prefix);
4885 sb.append(" Kernel Wake lock ");
4886 sb.append(timer.mName);
4887 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4888 which, linePrefix);
4889 if (!linePrefix.equals(": ")) {
4890 sb.append(" realtime");
4891 // Only print out wake locks that were held
4892 pw.println(sb.toString());
4893 }
4894 }
4895 pw.println();
4896 }
4897 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004898
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004899 if (timers.size() > 0) {
4900 Collections.sort(timers, timerComparator);
4901 pw.print(prefix); pw.println(" All partial wake locks:");
4902 for (int i=0; i<timers.size(); i++) {
4903 TimerEntry timer = timers.get(i);
4904 sb.setLength(0);
4905 sb.append(" Wake lock ");
4906 UserHandle.formatUid(sb, timer.mId);
4907 sb.append(" ");
4908 sb.append(timer.mName);
4909 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4910 sb.append(" realtime");
4911 pw.println(sb.toString());
4912 }
4913 timers.clear();
4914 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004915 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004916
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004917 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004918 if (wakeupReasons.size() > 0) {
4919 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004920 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004921 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004922 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004923 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4924 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004925 }
4926 Collections.sort(reasons, timerComparator);
4927 for (int i=0; i<reasons.size(); i++) {
4928 TimerEntry timer = reasons.get(i);
4929 String linePrefix = ": ";
4930 sb.setLength(0);
4931 sb.append(prefix);
4932 sb.append(" Wakeup reason ");
4933 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004934 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4935 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004936 pw.println(sb.toString());
4937 }
4938 pw.println();
4939 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004940 }
Evan Millar22ac0432009-03-31 11:33:18 -07004941
James Carr2dd7e5e2016-07-20 18:48:39 -07004942 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004943 if (mMemoryStats.size() > 0) {
4944 pw.println(" Memory Stats");
4945 for (int i = 0; i < mMemoryStats.size(); i++) {
4946 sb.setLength(0);
4947 sb.append(" Bandwidth ");
4948 sb.append(mMemoryStats.keyAt(i));
4949 sb.append(" Time ");
4950 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4951 pw.println(sb.toString());
4952 }
4953 pw.println();
4954 }
4955
4956 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4957 if (rpmStats.size() > 0) {
4958 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4959 if (rpmStats.size() > 0) {
4960 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4961 final String timerName = ent.getKey();
4962 final Timer timer = ent.getValue();
4963 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4964 }
4965 }
4966 pw.println();
4967 }
Bookatz82b341172017-09-07 19:06:08 -07004968 if (SCREEN_OFF_RPM_STATS_ENABLED) {
4969 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07004970 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07004971 pw.print(prefix);
4972 pw.println(" Resource Power Manager Stats for when screen was off");
4973 if (screenOffRpmStats.size() > 0) {
4974 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4975 final String timerName = ent.getKey();
4976 final Timer timer = ent.getValue();
4977 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4978 }
Bookatz50df7112017-08-04 14:53:26 -07004979 }
Bookatz82b341172017-09-07 19:06:08 -07004980 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07004981 }
James Carr2dd7e5e2016-07-20 18:48:39 -07004982 }
4983
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004984 final long[] cpuFreqs = getCpuFreqs();
4985 if (cpuFreqs != null) {
4986 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004987 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004988 for (int i = 0; i < cpuFreqs.length; ++i) {
4989 sb.append(" " + cpuFreqs[i]);
4990 }
4991 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07004992 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004993 }
4994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004995 for (int iu=0; iu<NU; iu++) {
4996 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004997 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004998 continue;
4999 }
Bookatzc8c44962017-05-11 12:12:54 -07005000
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005001 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07005002
5003 pw.print(prefix);
5004 pw.print(" ");
5005 UserHandle.formatUid(pw, uid);
5006 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005008
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005009 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
5010 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
5011 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
5012 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005013 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
5014 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
5015
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005016 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
5017 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005018 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
5019 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005020
5021 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
5022 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
5023
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005024 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
5025 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
5026 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08005027 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
5028 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5029 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
5030 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005031 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005032
Adam Lesinski5f056f62016-07-14 16:56:08 -07005033 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
5034 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
5035
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005036 if (mobileRxBytes > 0 || mobileTxBytes > 0
5037 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005038 pw.print(prefix); pw.print(" Mobile network: ");
5039 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005040 pw.print(formatBytesLocked(mobileTxBytes));
5041 pw.print(" sent (packets "); pw.print(mobileRxPackets);
5042 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005044 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
5045 sb.setLength(0);
5046 sb.append(prefix); sb.append(" Mobile radio active: ");
5047 formatTimeMs(sb, uidMobileActiveTime / 1000);
5048 sb.append("(");
5049 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
5050 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
5051 long packets = mobileRxPackets + mobileTxPackets;
5052 if (packets == 0) {
5053 packets = 1;
5054 }
5055 sb.append(" @ ");
5056 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
5057 sb.append(" mspp");
5058 pw.println(sb.toString());
5059 }
5060
Adam Lesinski5f056f62016-07-14 16:56:08 -07005061 if (mobileWakeup > 0) {
5062 sb.setLength(0);
5063 sb.append(prefix);
5064 sb.append(" Mobile radio AP wakeups: ");
5065 sb.append(mobileWakeup);
5066 pw.println(sb.toString());
5067 }
5068
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005069 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
5070 u.getModemControllerActivity(), which);
5071
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005072 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005073 pw.print(prefix); pw.print(" Wi-Fi network: ");
5074 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005075 pw.print(formatBytesLocked(wifiTxBytes));
5076 pw.print(" sent (packets "); pw.print(wifiRxPackets);
5077 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005078 }
5079
Dianne Hackborn62793e42015-03-09 11:15:41 -07005080 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08005081 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005082 || uidWifiRunningTime != 0) {
5083 sb.setLength(0);
5084 sb.append(prefix); sb.append(" Wifi Running: ");
5085 formatTimeMs(sb, uidWifiRunningTime / 1000);
5086 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
5087 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07005088 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005089 formatTimeMs(sb, fullWifiLockOnTime / 1000);
5090 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
5091 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08005092 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005093 formatTimeMs(sb, wifiScanTime / 1000);
5094 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07005095 whichBatteryRealtime)); sb.append(") ");
5096 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08005097 sb.append("x\n");
5098 // actual and background times are unpooled and since reset (regardless of 'which')
5099 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
5100 formatTimeMs(sb, wifiScanActualTime / 1000);
5101 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
5102 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5103 sb.append(") ");
5104 sb.append(wifiScanCount);
5105 sb.append("x\n");
5106 sb.append(prefix); sb.append(" Background Wifi Scan: ");
5107 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
5108 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
5109 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5110 sb.append(") ");
5111 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07005112 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005113 pw.println(sb.toString());
5114 }
5115
Adam Lesinski5f056f62016-07-14 16:56:08 -07005116 if (wifiWakeup > 0) {
5117 sb.setLength(0);
5118 sb.append(prefix);
5119 sb.append(" WiFi AP wakeups: ");
5120 sb.append(wifiWakeup);
5121 pw.println(sb.toString());
5122 }
5123
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005124 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
5125 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07005126
Adam Lesinski50e47602015-12-04 17:04:54 -08005127 if (btRxBytes > 0 || btTxBytes > 0) {
5128 pw.print(prefix); pw.print(" Bluetooth network: ");
5129 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
5130 pw.print(formatBytesLocked(btTxBytes));
5131 pw.println(" sent");
5132 }
5133
Bookatz867c0d72017-03-07 18:23:42 -08005134 final Timer bleTimer = u.getBluetoothScanTimer();
5135 if (bleTimer != null) {
5136 // Convert from microseconds to milliseconds with rounding
5137 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
5138 / 1000;
5139 if (totalTimeMs != 0) {
5140 final int count = bleTimer.getCountLocked(which);
5141 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
5142 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005143 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5144 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
5145 final long actualTimeMsBg = bleTimerBg != null ?
5146 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005147 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07005148 final int resultCount = u.getBluetoothScanResultCounter() != null ?
5149 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005150 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
5151 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
5152 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
5153 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
5154 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
5155 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5156 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
5157 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
5158 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
5159 final Timer unoptimizedScanTimerBg =
5160 u.getBluetoothUnoptimizedScanBackgroundTimer();
5161 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
5162 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5163 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
5164 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005165
5166 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08005167 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07005168 sb.append(prefix);
5169 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08005170 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07005171 sb.append(" (");
5172 sb.append(count);
5173 sb.append(" times)");
5174 if (bleTimer.isRunningLocked()) {
5175 sb.append(" (currently running)");
5176 }
5177 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005178 }
Bookatzb1f04f32017-05-19 13:57:32 -07005179
5180 sb.append(prefix);
5181 sb.append(" Bluetooth Scan (total actual realtime): ");
5182 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
5183 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005184 sb.append(count);
5185 sb.append(" times)");
5186 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07005187 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08005188 }
Bookatzb1f04f32017-05-19 13:57:32 -07005189 sb.append("\n");
5190 if (actualTimeMsBg > 0 || countBg > 0) {
5191 sb.append(prefix);
5192 sb.append(" Bluetooth Scan (background realtime): ");
5193 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
5194 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005195 sb.append(countBg);
5196 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07005197 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
5198 sb.append(" (currently running in background)");
5199 }
5200 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005201 }
Bookatzb1f04f32017-05-19 13:57:32 -07005202
5203 sb.append(prefix);
5204 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07005205 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07005206 sb.append(" (");
5207 sb.append(resultCountBg);
5208 sb.append(" in background)");
5209
5210 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
5211 sb.append("\n");
5212 sb.append(prefix);
5213 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
5214 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
5215 sb.append(" (max ");
5216 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
5217 sb.append(")");
5218 if (unoptimizedScanTimer != null
5219 && unoptimizedScanTimer.isRunningLocked()) {
5220 sb.append(" (currently running unoptimized)");
5221 }
5222 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
5223 sb.append("\n");
5224 sb.append(prefix);
5225 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
5226 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
5227 sb.append(" (max ");
5228 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
5229 sb.append(")");
5230 if (unoptimizedScanTimerBg.isRunningLocked()) {
5231 sb.append(" (currently running unoptimized in background)");
5232 }
5233 }
5234 }
Bookatz867c0d72017-03-07 18:23:42 -08005235 pw.println(sb.toString());
5236 uidActivity = true;
5237 }
5238 }
5239
5240
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005241
Dianne Hackborn617f8772009-03-31 15:04:46 -07005242 if (u.hasUserActivity()) {
5243 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07005244 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005245 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07005246 if (val != 0) {
5247 if (!hasData) {
5248 sb.setLength(0);
5249 sb.append(" User activity: ");
5250 hasData = true;
5251 } else {
5252 sb.append(", ");
5253 }
5254 sb.append(val);
5255 sb.append(" ");
5256 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
5257 }
5258 }
5259 if (hasData) {
5260 pw.println(sb.toString());
5261 }
5262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005264 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5265 = u.getWakelockStats();
5266 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005267 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005268 int countWakelock = 0;
5269 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5270 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5271 String linePrefix = ": ";
5272 sb.setLength(0);
5273 sb.append(prefix);
5274 sb.append(" Wake lock ");
5275 sb.append(wakelocks.keyAt(iw));
5276 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5277 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005278 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5279 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005280 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005281 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5282 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005283 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5284 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005285 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5286 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005287 sb.append(" realtime");
5288 pw.println(sb.toString());
5289 uidActivity = true;
5290 countWakelock++;
5291
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005292 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5293 rawRealtime, which);
5294 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5295 rawRealtime, which);
5296 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5297 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005298 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005299 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005300 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005301 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005302 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5303 // pooled and therefore just a lower bound)
5304 long actualTotalPartialWakelock = 0;
5305 long actualBgPartialWakelock = 0;
5306 if (u.getAggregatedPartialWakelockTimer() != null) {
5307 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5308 // Convert from microseconds to milliseconds with rounding
5309 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005310 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005311 final Timer bgAggTimer = aggTimer.getSubTimer();
5312 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005313 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005314 }
5315
5316 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5317 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5318 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005319 sb.setLength(0);
5320 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005321 sb.append(" TOTAL wake: ");
5322 boolean needComma = false;
5323 if (totalFullWakelock != 0) {
5324 needComma = true;
5325 formatTimeMs(sb, totalFullWakelock);
5326 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005327 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005328 if (totalPartialWakelock != 0) {
5329 if (needComma) {
5330 sb.append(", ");
5331 }
5332 needComma = true;
5333 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005334 sb.append("blamed partial");
5335 }
5336 if (actualTotalPartialWakelock != 0) {
5337 if (needComma) {
5338 sb.append(", ");
5339 }
5340 needComma = true;
5341 formatTimeMs(sb, actualTotalPartialWakelock);
5342 sb.append("actual partial");
5343 }
5344 if (actualBgPartialWakelock != 0) {
5345 if (needComma) {
5346 sb.append(", ");
5347 }
5348 needComma = true;
5349 formatTimeMs(sb, actualBgPartialWakelock);
5350 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005351 }
5352 if (totalWindowWakelock != 0) {
5353 if (needComma) {
5354 sb.append(", ");
5355 }
5356 needComma = true;
5357 formatTimeMs(sb, totalWindowWakelock);
5358 sb.append("window");
5359 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005360 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005361 if (needComma) {
5362 sb.append(",");
5363 }
5364 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005365 formatTimeMs(sb, totalDrawWakelock);
5366 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005367 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005368 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005369 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005370 }
5371 }
5372
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07005373 // Calculate multicast wakelock stats
5374 final Timer mcTimer = u.getMulticastWakelockStats();
5375 if (mcTimer != null) {
5376 final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which);
5377 final int multicastWakeLockCount = mcTimer.getCountLocked(which);
5378
5379 if (multicastWakeLockTimeMicros > 0) {
5380 sb.setLength(0);
5381 sb.append(prefix);
5382 sb.append(" WiFi Multicast Wakelock");
5383 sb.append(" count = ");
5384 sb.append(multicastWakeLockCount);
5385 sb.append(" time = ");
5386 formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000);
5387 pw.println(sb.toString());
5388 }
5389 }
5390
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005391 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5392 for (int isy=syncs.size()-1; isy>=0; isy--) {
5393 final Timer timer = syncs.valueAt(isy);
5394 // Convert from microseconds to milliseconds with rounding
5395 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5396 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005397 final Timer bgTimer = timer.getSubTimer();
5398 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005399 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005400 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005401 sb.setLength(0);
5402 sb.append(prefix);
5403 sb.append(" Sync ");
5404 sb.append(syncs.keyAt(isy));
5405 sb.append(": ");
5406 if (totalTime != 0) {
5407 formatTimeMs(sb, totalTime);
5408 sb.append("realtime (");
5409 sb.append(count);
5410 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005411 if (bgTime > 0) {
5412 sb.append(", ");
5413 formatTimeMs(sb, bgTime);
5414 sb.append("background (");
5415 sb.append(bgCount);
5416 sb.append(" times)");
5417 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005418 } else {
5419 sb.append("(not used)");
5420 }
5421 pw.println(sb.toString());
5422 uidActivity = true;
5423 }
5424
5425 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5426 for (int ij=jobs.size()-1; ij>=0; ij--) {
5427 final Timer timer = jobs.valueAt(ij);
5428 // Convert from microseconds to milliseconds with rounding
5429 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5430 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005431 final Timer bgTimer = timer.getSubTimer();
5432 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005433 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005434 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005435 sb.setLength(0);
5436 sb.append(prefix);
5437 sb.append(" Job ");
5438 sb.append(jobs.keyAt(ij));
5439 sb.append(": ");
5440 if (totalTime != 0) {
5441 formatTimeMs(sb, totalTime);
5442 sb.append("realtime (");
5443 sb.append(count);
5444 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005445 if (bgTime > 0) {
5446 sb.append(", ");
5447 formatTimeMs(sb, bgTime);
5448 sb.append("background (");
5449 sb.append(bgCount);
5450 sb.append(" times)");
5451 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005452 } else {
5453 sb.append("(not used)");
5454 }
5455 pw.println(sb.toString());
5456 uidActivity = true;
5457 }
5458
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005459 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5460 for (int ic=completions.size()-1; ic>=0; ic--) {
5461 SparseIntArray types = completions.valueAt(ic);
5462 if (types != null) {
5463 pw.print(prefix);
5464 pw.print(" Job Completions ");
5465 pw.print(completions.keyAt(ic));
5466 pw.print(":");
5467 for (int it=0; it<types.size(); it++) {
5468 pw.print(" ");
5469 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5470 pw.print("(");
5471 pw.print(types.valueAt(it));
5472 pw.print("x)");
5473 }
5474 pw.println();
5475 }
5476 }
5477
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005478 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5479 prefix, "Flashlight");
5480 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5481 prefix, "Camera");
5482 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5483 prefix, "Video");
5484 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5485 prefix, "Audio");
5486
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005487 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5488 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005489 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005490 final Uid.Sensor se = sensors.valueAt(ise);
5491 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005492 sb.setLength(0);
5493 sb.append(prefix);
5494 sb.append(" Sensor ");
5495 int handle = se.getHandle();
5496 if (handle == Uid.Sensor.GPS) {
5497 sb.append("GPS");
5498 } else {
5499 sb.append(handle);
5500 }
5501 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005502
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005503 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005504 if (timer != null) {
5505 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005506 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5507 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005508 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005509 final Timer bgTimer = se.getSensorBackgroundTime();
5510 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005511 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5512 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5513 final long bgActualTime = bgTimer != null ?
5514 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5515
Dianne Hackborn61659e52014-07-09 16:13:01 -07005516 //timer.logState();
5517 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005518 if (actualTime != totalTime) {
5519 formatTimeMs(sb, totalTime);
5520 sb.append("blamed realtime, ");
5521 }
5522
5523 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005524 sb.append("realtime (");
5525 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005526 sb.append(" times)");
5527
5528 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005529 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005530 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5531 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005532 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005533 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005535 } else {
5536 sb.append("(not used)");
5537 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005538 } else {
5539 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005540 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005541
5542 pw.println(sb.toString());
5543 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005544 }
5545
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005546 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5547 "Vibrator");
5548 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5549 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005550 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5551 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005552
Dianne Hackborn61659e52014-07-09 16:13:01 -07005553 long totalStateTime = 0;
5554 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5555 long time = u.getProcessStateTime(ips, rawRealtime, which);
5556 if (time > 0) {
5557 totalStateTime += time;
5558 sb.setLength(0);
5559 sb.append(prefix);
5560 sb.append(" ");
5561 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5562 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005563 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005564 pw.println(sb.toString());
5565 uidActivity = true;
5566 }
5567 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005568 if (totalStateTime > 0) {
5569 sb.setLength(0);
5570 sb.append(prefix);
5571 sb.append(" Total running: ");
5572 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5573 pw.println(sb.toString());
5574 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005575
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005576 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5577 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005578 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005579 sb.setLength(0);
5580 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005581 sb.append(" Total cpu time: u=");
5582 formatTimeMs(sb, userCpuTimeUs / 1000);
5583 sb.append("s=");
5584 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005585 pw.println(sb.toString());
5586 }
5587
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005588 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5589 if (cpuFreqTimes != null) {
5590 sb.setLength(0);
5591 sb.append(" Total cpu time per freq:");
5592 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5593 sb.append(" " + cpuFreqTimes[i]);
5594 }
5595 pw.println(sb.toString());
5596 }
5597 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5598 if (screenOffCpuFreqTimes != null) {
5599 sb.setLength(0);
5600 sb.append(" Total screen-off cpu time per freq:");
5601 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5602 sb.append(" " + screenOffCpuFreqTimes[i]);
5603 }
5604 pw.println(sb.toString());
5605 }
5606
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005607 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5608 = u.getProcessStats();
5609 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5610 final Uid.Proc ps = processStats.valueAt(ipr);
5611 long userTime;
5612 long systemTime;
5613 long foregroundTime;
5614 int starts;
5615 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005617 userTime = ps.getUserTime(which);
5618 systemTime = ps.getSystemTime(which);
5619 foregroundTime = ps.getForegroundTime(which);
5620 starts = ps.getStarts(which);
5621 final int numCrashes = ps.getNumCrashes(which);
5622 final int numAnrs = ps.getNumAnrs(which);
5623 numExcessive = which == STATS_SINCE_CHARGED
5624 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005625
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005626 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5627 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5628 sb.setLength(0);
5629 sb.append(prefix); sb.append(" Proc ");
5630 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5631 sb.append(prefix); sb.append(" CPU: ");
5632 formatTimeMs(sb, userTime); sb.append("usr + ");
5633 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5634 formatTimeMs(sb, foregroundTime); sb.append("fg");
5635 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5636 sb.append("\n"); sb.append(prefix); sb.append(" ");
5637 boolean hasOne = false;
5638 if (starts != 0) {
5639 hasOne = true;
5640 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005641 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005642 if (numCrashes != 0) {
5643 if (hasOne) {
5644 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005645 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005646 hasOne = true;
5647 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005648 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005649 if (numAnrs != 0) {
5650 if (hasOne) {
5651 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005653 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005654 }
5655 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005656 pw.println(sb.toString());
5657 for (int e=0; e<numExcessive; e++) {
5658 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5659 if (ew != null) {
5660 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005661 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005662 pw.print("cpu");
5663 } else {
5664 pw.print("unknown");
5665 }
5666 pw.print(" use: ");
5667 TimeUtils.formatDuration(ew.usedTime, pw);
5668 pw.print(" over ");
5669 TimeUtils.formatDuration(ew.overTime, pw);
5670 if (ew.overTime != 0) {
5671 pw.print(" (");
5672 pw.print((ew.usedTime*100)/ew.overTime);
5673 pw.println("%)");
5674 }
5675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005676 }
5677 uidActivity = true;
5678 }
5679 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005680
5681 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5682 = u.getPackageStats();
5683 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5684 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5685 pw.println(":");
5686 boolean apkActivity = false;
5687 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5688 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5689 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5690 pw.print(prefix); pw.print(" Wakeup alarm ");
5691 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5692 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5693 pw.println(" times");
5694 apkActivity = true;
5695 }
5696 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5697 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5698 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5699 final long startTime = ss.getStartTime(batteryUptime, which);
5700 final int starts = ss.getStarts(which);
5701 final int launches = ss.getLaunches(which);
5702 if (startTime != 0 || starts != 0 || launches != 0) {
5703 sb.setLength(0);
5704 sb.append(prefix); sb.append(" Service ");
5705 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5706 sb.append(prefix); sb.append(" Created for: ");
5707 formatTimeMs(sb, startTime / 1000);
5708 sb.append("uptime\n");
5709 sb.append(prefix); sb.append(" Starts: ");
5710 sb.append(starts);
5711 sb.append(", launches: "); sb.append(launches);
5712 pw.println(sb.toString());
5713 apkActivity = true;
5714 }
5715 }
5716 if (!apkActivity) {
5717 pw.print(prefix); pw.println(" (nothing executed)");
5718 }
5719 uidActivity = true;
5720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005722 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005723 }
5724 }
5725 }
5726
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005727 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005728 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005729 int diff = oldval ^ newval;
5730 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005731 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005732 for (int i=0; i<descriptions.length; i++) {
5733 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005734 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005735 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005736 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005737 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005738 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005739 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5740 didWake = true;
5741 pw.print("=");
5742 if (longNames) {
5743 UserHandle.formatUid(pw, wakelockTag.uid);
5744 pw.print(":\"");
5745 pw.print(wakelockTag.string);
5746 pw.print("\"");
5747 } else {
5748 pw.print(wakelockTag.poolIdx);
5749 }
5750 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005751 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005752 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005753 pw.print("=");
5754 int val = (newval&bd.mask)>>bd.shift;
5755 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005756 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005757 } else {
5758 pw.print(val);
5759 }
5760 }
5761 }
5762 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005763 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005764 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005765 if (longNames) {
5766 UserHandle.formatUid(pw, wakelockTag.uid);
5767 pw.print(":\"");
5768 pw.print(wakelockTag.string);
5769 pw.print("\"");
5770 } else {
5771 pw.print(wakelockTag.poolIdx);
5772 }
5773 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005774 }
Mike Mac2f518a2017-09-19 16:06:03 -07005775
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005776 public void prepareForDumpLocked() {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07005777 // We don't need to require subclasses implement this.
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005778 }
5779
5780 public static class HistoryPrinter {
5781 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005782 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005783 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005784 int oldStatus = -1;
5785 int oldHealth = -1;
5786 int oldPlug = -1;
5787 int oldTemp = -1;
5788 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005789 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005790 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005791
Dianne Hackborn3251b902014-06-20 14:40:53 -07005792 void reset() {
5793 oldState = oldState2 = 0;
5794 oldLevel = -1;
5795 oldStatus = -1;
5796 oldHealth = -1;
5797 oldPlug = -1;
5798 oldTemp = -1;
5799 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005800 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005801 }
5802
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005803 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005804 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005805 if (!checkin) {
5806 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005807 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005808 pw.print(" (");
5809 pw.print(rec.numReadInts);
5810 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005811 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005812 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5813 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005814 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005815 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005816 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005817 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005818 }
5819 lastTime = rec.time;
5820 }
5821 if (rec.cmd == HistoryItem.CMD_START) {
5822 if (checkin) {
5823 pw.print(":");
5824 }
5825 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005826 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005827 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5828 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005829 if (checkin) {
5830 pw.print(":");
5831 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005832 if (rec.cmd == HistoryItem.CMD_RESET) {
5833 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005834 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005835 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005836 pw.print("TIME:");
5837 if (checkin) {
5838 pw.println(rec.currentTime);
5839 } else {
5840 pw.print(" ");
5841 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5842 rec.currentTime).toString());
5843 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005844 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5845 if (checkin) {
5846 pw.print(":");
5847 }
5848 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005849 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5850 if (checkin) {
5851 pw.print(":");
5852 }
5853 pw.println("*OVERFLOW*");
5854 } else {
5855 if (!checkin) {
5856 if (rec.batteryLevel < 10) pw.print("00");
5857 else if (rec.batteryLevel < 100) pw.print("0");
5858 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005859 if (verbose) {
5860 pw.print(" ");
5861 if (rec.states < 0) ;
5862 else if (rec.states < 0x10) pw.print("0000000");
5863 else if (rec.states < 0x100) pw.print("000000");
5864 else if (rec.states < 0x1000) pw.print("00000");
5865 else if (rec.states < 0x10000) pw.print("0000");
5866 else if (rec.states < 0x100000) pw.print("000");
5867 else if (rec.states < 0x1000000) pw.print("00");
5868 else if (rec.states < 0x10000000) pw.print("0");
5869 pw.print(Integer.toHexString(rec.states));
5870 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005871 } else {
5872 if (oldLevel != rec.batteryLevel) {
5873 oldLevel = rec.batteryLevel;
5874 pw.print(",Bl="); pw.print(rec.batteryLevel);
5875 }
5876 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005877 if (oldStatus != rec.batteryStatus) {
5878 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005879 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005880 switch (oldStatus) {
5881 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005882 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005883 break;
5884 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005885 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005886 break;
5887 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005888 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005889 break;
5890 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005891 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005892 break;
5893 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005894 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005895 break;
5896 default:
5897 pw.print(oldStatus);
5898 break;
5899 }
5900 }
5901 if (oldHealth != rec.batteryHealth) {
5902 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005903 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005904 switch (oldHealth) {
5905 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005906 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005907 break;
5908 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005909 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005910 break;
5911 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005912 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005913 break;
5914 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005915 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005916 break;
5917 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005918 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005919 break;
5920 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005921 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005922 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005923 case BatteryManager.BATTERY_HEALTH_COLD:
5924 pw.print(checkin ? "c" : "cold");
5925 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005926 default:
5927 pw.print(oldHealth);
5928 break;
5929 }
5930 }
5931 if (oldPlug != rec.batteryPlugType) {
5932 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005933 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005934 switch (oldPlug) {
5935 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005936 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005937 break;
5938 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005939 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005940 break;
5941 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005942 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005943 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005944 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005945 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005946 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005947 default:
5948 pw.print(oldPlug);
5949 break;
5950 }
5951 }
5952 if (oldTemp != rec.batteryTemperature) {
5953 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005954 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005955 pw.print(oldTemp);
5956 }
5957 if (oldVolt != rec.batteryVoltage) {
5958 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005959 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005960 pw.print(oldVolt);
5961 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005962 final int chargeMAh = rec.batteryChargeUAh / 1000;
5963 if (oldChargeMAh != chargeMAh) {
5964 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005965 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005966 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005967 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005968 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005969 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005970 printBitDescriptions(pw, oldState2, rec.states2, null,
5971 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005972 if (rec.wakeReasonTag != null) {
5973 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005974 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005975 pw.print(rec.wakeReasonTag.poolIdx);
5976 } else {
5977 pw.print(" wake_reason=");
5978 pw.print(rec.wakeReasonTag.uid);
5979 pw.print(":\"");
5980 pw.print(rec.wakeReasonTag.string);
5981 pw.print("\"");
5982 }
5983 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005984 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005985 pw.print(checkin ? "," : " ");
5986 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5987 pw.print("+");
5988 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5989 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005990 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005991 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5992 : HISTORY_EVENT_NAMES;
5993 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5994 | HistoryItem.EVENT_FLAG_FINISH);
5995 if (idx >= 0 && idx < eventNames.length) {
5996 pw.print(eventNames[idx]);
5997 } else {
5998 pw.print(checkin ? "Ev" : "event");
5999 pw.print(idx);
6000 }
6001 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006002 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006003 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08006004 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08006005 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
6006 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006007 pw.print(":\"");
6008 pw.print(rec.eventTag.string);
6009 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006010 }
6011 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006012 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006013 if (rec.stepDetails != null) {
6014 if (!checkin) {
6015 pw.print(" Details: cpu=");
6016 pw.print(rec.stepDetails.userTime);
6017 pw.print("u+");
6018 pw.print(rec.stepDetails.systemTime);
6019 pw.print("s");
6020 if (rec.stepDetails.appCpuUid1 >= 0) {
6021 pw.print(" (");
6022 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
6023 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6024 if (rec.stepDetails.appCpuUid2 >= 0) {
6025 pw.print(", ");
6026 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
6027 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6028 }
6029 if (rec.stepDetails.appCpuUid3 >= 0) {
6030 pw.print(", ");
6031 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
6032 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6033 }
6034 pw.print(')');
6035 }
6036 pw.println();
6037 pw.print(" /proc/stat=");
6038 pw.print(rec.stepDetails.statUserTime);
6039 pw.print(" usr, ");
6040 pw.print(rec.stepDetails.statSystemTime);
6041 pw.print(" sys, ");
6042 pw.print(rec.stepDetails.statIOWaitTime);
6043 pw.print(" io, ");
6044 pw.print(rec.stepDetails.statIrqTime);
6045 pw.print(" irq, ");
6046 pw.print(rec.stepDetails.statSoftIrqTime);
6047 pw.print(" sirq, ");
6048 pw.print(rec.stepDetails.statIdlTime);
6049 pw.print(" idle");
6050 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
6051 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
6052 + rec.stepDetails.statSoftIrqTime;
6053 int total = totalRun + rec.stepDetails.statIdlTime;
6054 if (total > 0) {
6055 pw.print(" (");
6056 float perc = ((float)totalRun) / ((float)total) * 100;
6057 pw.print(String.format("%.1f%%", perc));
6058 pw.print(" of ");
6059 StringBuilder sb = new StringBuilder(64);
6060 formatTimeMsNoSpace(sb, total*10);
6061 pw.print(sb);
6062 pw.print(")");
6063 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006064 pw.print(", PlatformIdleStat ");
6065 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006066 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006067
6068 pw.print(", SubsystemPowerState ");
6069 pw.print(rec.stepDetails.statSubsystemPowerState);
6070 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006071 } else {
6072 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6073 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
6074 pw.print(rec.stepDetails.userTime);
6075 pw.print(":");
6076 pw.print(rec.stepDetails.systemTime);
6077 if (rec.stepDetails.appCpuUid1 >= 0) {
6078 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
6079 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6080 if (rec.stepDetails.appCpuUid2 >= 0) {
6081 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
6082 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6083 }
6084 if (rec.stepDetails.appCpuUid3 >= 0) {
6085 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
6086 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6087 }
6088 }
6089 pw.println();
6090 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6091 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
6092 pw.print(rec.stepDetails.statUserTime);
6093 pw.print(',');
6094 pw.print(rec.stepDetails.statSystemTime);
6095 pw.print(',');
6096 pw.print(rec.stepDetails.statIOWaitTime);
6097 pw.print(',');
6098 pw.print(rec.stepDetails.statIrqTime);
6099 pw.print(',');
6100 pw.print(rec.stepDetails.statSoftIrqTime);
6101 pw.print(',');
6102 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006103 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006104 if (rec.stepDetails.statPlatformIdleState != null) {
6105 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07006106 if (rec.stepDetails.statSubsystemPowerState != null) {
6107 pw.print(',');
6108 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006109 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006110
6111 if (rec.stepDetails.statSubsystemPowerState != null) {
6112 pw.print(rec.stepDetails.statSubsystemPowerState);
6113 }
6114 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006115 }
6116 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006117 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006118 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006119 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006120 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006121
6122 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
6123 UserHandle.formatUid(pw, uid);
6124 pw.print("=");
6125 pw.print(utime);
6126 pw.print("u+");
6127 pw.print(stime);
6128 pw.print("s");
6129 }
6130
6131 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
6132 pw.print('/');
6133 pw.print(uid);
6134 pw.print(":");
6135 pw.print(utime);
6136 pw.print(":");
6137 pw.print(stime);
6138 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006139 }
6140
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006141 private void printSizeValue(PrintWriter pw, long size) {
6142 float result = size;
6143 String suffix = "";
6144 if (result >= 10*1024) {
6145 suffix = "KB";
6146 result = result / 1024;
6147 }
6148 if (result >= 10*1024) {
6149 suffix = "MB";
6150 result = result / 1024;
6151 }
6152 if (result >= 10*1024) {
6153 suffix = "GB";
6154 result = result / 1024;
6155 }
6156 if (result >= 10*1024) {
6157 suffix = "TB";
6158 result = result / 1024;
6159 }
6160 if (result >= 10*1024) {
6161 suffix = "PB";
6162 result = result / 1024;
6163 }
6164 pw.print((int)result);
6165 pw.print(suffix);
6166 }
6167
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006168 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
6169 String label3, long estimatedTime) {
6170 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006171 return false;
6172 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006173 pw.print(label1);
6174 pw.print(label2);
6175 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006176 StringBuilder sb = new StringBuilder(64);
6177 formatTimeMs(sb, estimatedTime);
6178 pw.print(sb);
6179 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006180 return true;
6181 }
6182
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006183 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
6184 LevelStepTracker steps, boolean checkin) {
6185 if (steps == null) {
6186 return false;
6187 }
6188 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006189 if (count <= 0) {
6190 return false;
6191 }
6192 if (!checkin) {
6193 pw.println(header);
6194 }
Kweku Adams030980a2015-04-01 16:07:48 -07006195 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006196 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006197 long duration = steps.getDurationAt(i);
6198 int level = steps.getLevelAt(i);
6199 long initMode = steps.getInitModeAt(i);
6200 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006201 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006202 lineArgs[0] = Long.toString(duration);
6203 lineArgs[1] = Integer.toString(level);
6204 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6205 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6206 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
6207 case Display.STATE_ON: lineArgs[2] = "s+"; break;
6208 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
6209 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07006210 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006211 }
6212 } else {
6213 lineArgs[2] = "";
6214 }
6215 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6216 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
6217 } else {
6218 lineArgs[3] = "";
6219 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006220 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07006221 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006222 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07006223 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006224 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006225 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
6226 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006227 pw.print(prefix);
6228 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006229 TimeUtils.formatDuration(duration, pw);
6230 pw.print(" to "); pw.print(level);
6231 boolean haveModes = false;
6232 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6233 pw.print(" (");
6234 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6235 case Display.STATE_OFF: pw.print("screen-off"); break;
6236 case Display.STATE_ON: pw.print("screen-on"); break;
6237 case Display.STATE_DOZE: pw.print("screen-doze"); break;
6238 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07006239 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006240 }
6241 haveModes = true;
6242 }
6243 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6244 pw.print(haveModes ? ", " : " (");
6245 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
6246 ? "power-save-on" : "power-save-off");
6247 haveModes = true;
6248 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006249 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6250 pw.print(haveModes ? ", " : " (");
6251 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6252 ? "device-idle-on" : "device-idle-off");
6253 haveModes = true;
6254 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006255 if (haveModes) {
6256 pw.print(")");
6257 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006258 pw.println();
6259 }
6260 }
6261 return true;
6262 }
6263
Kweku Adams87b19ec2017-10-09 12:40:03 -07006264 private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId,
6265 LevelStepTracker steps) {
6266 if (steps == null) {
6267 return;
6268 }
6269 int count = steps.mNumStepDurations;
Kweku Adams87b19ec2017-10-09 12:40:03 -07006270 for (int i = 0; i < count; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07006271 long token = proto.start(fieldId);
Kweku Adams87b19ec2017-10-09 12:40:03 -07006272 proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i));
6273 proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i));
6274
6275 final long initMode = steps.getInitModeAt(i);
6276 final long modMode = steps.getModModeAt(i);
6277
6278 int ds = SystemProto.BatteryLevelStep.DS_MIXED;
6279 if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6280 switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6281 case Display.STATE_OFF:
6282 ds = SystemProto.BatteryLevelStep.DS_OFF;
6283 break;
6284 case Display.STATE_ON:
6285 ds = SystemProto.BatteryLevelStep.DS_ON;
6286 break;
6287 case Display.STATE_DOZE:
6288 ds = SystemProto.BatteryLevelStep.DS_DOZE;
6289 break;
6290 case Display.STATE_DOZE_SUSPEND:
6291 ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND;
6292 break;
6293 default:
6294 ds = SystemProto.BatteryLevelStep.DS_ERROR;
6295 break;
6296 }
6297 }
6298 proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds);
6299
6300 int psm = SystemProto.BatteryLevelStep.PSM_MIXED;
6301 if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6302 psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0
6303 ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF;
6304 }
6305 proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm);
6306
6307 int im = SystemProto.BatteryLevelStep.IM_MIXED;
6308 if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6309 im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6310 ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF;
6311 }
6312 proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im);
6313
6314 proto.end(token);
6315 }
6316 }
6317
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006318 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006319 public static final int DUMP_DAILY_ONLY = 1<<2;
6320 public static final int DUMP_HISTORY_ONLY = 1<<3;
6321 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
6322 public static final int DUMP_VERBOSE = 1<<5;
6323 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006324
Dianne Hackborn37de0982014-05-09 09:32:18 -07006325 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
6326 final HistoryPrinter hprinter = new HistoryPrinter();
6327 final HistoryItem rec = new HistoryItem();
6328 long lastTime = -1;
6329 long baseTime = -1;
6330 boolean printed = false;
6331 HistoryEventTracker tracker = null;
6332 while (getNextHistoryLocked(rec)) {
6333 lastTime = rec.time;
6334 if (baseTime < 0) {
6335 baseTime = lastTime;
6336 }
6337 if (rec.time >= histStart) {
6338 if (histStart >= 0 && !printed) {
6339 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006340 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006341 || rec.cmd == HistoryItem.CMD_START
6342 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006343 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006344 hprinter.printNextItem(pw, rec, baseTime, checkin,
6345 (flags&DUMP_VERBOSE) != 0);
6346 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006347 } else if (rec.currentTime != 0) {
6348 printed = true;
6349 byte cmd = rec.cmd;
6350 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006351 hprinter.printNextItem(pw, rec, baseTime, checkin,
6352 (flags&DUMP_VERBOSE) != 0);
6353 rec.cmd = cmd;
6354 }
6355 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006356 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6357 hprinter.printNextItem(pw, rec, baseTime, checkin,
6358 (flags&DUMP_VERBOSE) != 0);
6359 rec.cmd = HistoryItem.CMD_UPDATE;
6360 }
6361 int oldEventCode = rec.eventCode;
6362 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006363 rec.eventTag = new HistoryTag();
6364 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6365 HashMap<String, SparseIntArray> active
6366 = tracker.getStateForEvent(i);
6367 if (active == null) {
6368 continue;
6369 }
6370 for (HashMap.Entry<String, SparseIntArray> ent
6371 : active.entrySet()) {
6372 SparseIntArray uids = ent.getValue();
6373 for (int j=0; j<uids.size(); j++) {
6374 rec.eventCode = i;
6375 rec.eventTag.string = ent.getKey();
6376 rec.eventTag.uid = uids.keyAt(j);
6377 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006378 hprinter.printNextItem(pw, rec, baseTime, checkin,
6379 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006380 rec.wakeReasonTag = null;
6381 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006382 }
6383 }
6384 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006385 rec.eventCode = oldEventCode;
6386 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006387 tracker = null;
6388 }
6389 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006390 hprinter.printNextItem(pw, rec, baseTime, checkin,
6391 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006392 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6393 // This is an attempt to aggregate the previous state and generate
6394 // fake events to reflect that state at the point where we start
6395 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006396 if (tracker == null) {
6397 tracker = new HistoryEventTracker();
6398 }
6399 tracker.updateState(rec.eventCode, rec.eventTag.string,
6400 rec.eventTag.uid, rec.eventTag.poolIdx);
6401 }
6402 }
6403 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006404 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006405 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6406 }
6407 }
6408
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006409 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6410 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6411 if (steps == null) {
6412 return;
6413 }
6414 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6415 if (timeRemaining >= 0) {
6416 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6417 tmpSb.setLength(0);
6418 formatTimeMs(tmpSb, timeRemaining);
6419 pw.print(tmpSb);
6420 pw.print(" (from "); pw.print(tmpOutInt[0]);
6421 pw.println(" steps)");
6422 }
6423 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6424 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6425 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6426 if (estimatedTime > 0) {
6427 pw.print(prefix); pw.print(label); pw.print(" ");
6428 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6429 pw.print(" time: ");
6430 tmpSb.setLength(0);
6431 formatTimeMs(tmpSb, estimatedTime);
6432 pw.print(tmpSb);
6433 pw.print(" (from "); pw.print(tmpOutInt[0]);
6434 pw.println(" steps)");
6435 }
6436 }
6437 }
6438
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006439 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6440 ArrayList<PackageChange> changes) {
6441 if (changes == null) {
6442 return;
6443 }
6444 pw.print(prefix); pw.println("Package changes:");
6445 for (int i=0; i<changes.size(); i++) {
6446 PackageChange pc = changes.get(i);
6447 if (pc.mUpdate) {
6448 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6449 pw.print(" vers="); pw.println(pc.mVersionCode);
6450 } else {
6451 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6452 }
6453 }
6454 }
6455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 /**
6457 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6458 *
6459 * @param pw a Printer to receive the dump output.
6460 */
6461 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006462 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006463 prepareForDumpLocked();
6464
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006465 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006466 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006467
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006468 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006469 final long historyTotalSize = getHistoryTotalSize();
6470 final long historyUsedSize = getHistoryUsedSize();
6471 if (startIteratingHistoryLocked()) {
6472 try {
6473 pw.print("Battery History (");
6474 pw.print((100*historyUsedSize)/historyTotalSize);
6475 pw.print("% used, ");
6476 printSizeValue(pw, historyUsedSize);
6477 pw.print(" used of ");
6478 printSizeValue(pw, historyTotalSize);
6479 pw.print(", ");
6480 pw.print(getHistoryStringPoolSize());
6481 pw.print(" strings using ");
6482 printSizeValue(pw, getHistoryStringPoolBytes());
6483 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006484 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006485 pw.println();
6486 } finally {
6487 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006488 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006489 }
6490
6491 if (startIteratingOldHistoryLocked()) {
6492 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006493 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006494 pw.println("Old battery History:");
6495 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006496 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006497 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006498 if (baseTime < 0) {
6499 baseTime = rec.time;
6500 }
6501 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006502 }
6503 pw.println();
6504 } finally {
6505 finishIteratingOldHistoryLocked();
6506 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006507 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006508 }
6509
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006510 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006511 return;
6512 }
6513
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006514 if (!filtering) {
6515 SparseArray<? extends Uid> uidStats = getUidStats();
6516 final int NU = uidStats.size();
6517 boolean didPid = false;
6518 long nowRealtime = SystemClock.elapsedRealtime();
6519 for (int i=0; i<NU; i++) {
6520 Uid uid = uidStats.valueAt(i);
6521 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6522 if (pids != null) {
6523 for (int j=0; j<pids.size(); j++) {
6524 Uid.Pid pid = pids.valueAt(j);
6525 if (!didPid) {
6526 pw.println("Per-PID Stats:");
6527 didPid = true;
6528 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006529 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6530 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006531 pw.print(" PID "); pw.print(pids.keyAt(j));
6532 pw.print(" wake time: ");
6533 TimeUtils.formatDuration(time, pw);
6534 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006535 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006536 }
6537 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006538 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006539 pw.println();
6540 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006541 }
6542
6543 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006544 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6545 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006546 long timeRemaining = computeBatteryTimeRemaining(
6547 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006548 if (timeRemaining >= 0) {
6549 pw.print(" Estimated discharge time remaining: ");
6550 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6551 pw.println();
6552 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006553 final LevelStepTracker steps = getDischargeLevelStepTracker();
6554 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6555 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6556 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6557 STEP_LEVEL_MODE_VALUES[i], null));
6558 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006559 pw.println();
6560 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006561 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6562 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006563 long timeRemaining = computeChargeTimeRemaining(
6564 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006565 if (timeRemaining >= 0) {
6566 pw.print(" Estimated charge time remaining: ");
6567 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6568 pw.println();
6569 }
6570 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006571 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006572 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07006573 if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006574 pw.println("Daily stats:");
6575 pw.print(" Current start time: ");
6576 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6577 getCurrentDailyStartTime()).toString());
6578 pw.print(" Next min deadline: ");
6579 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6580 getNextMinDailyDeadline()).toString());
6581 pw.print(" Next max deadline: ");
6582 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6583 getNextMaxDailyDeadline()).toString());
6584 StringBuilder sb = new StringBuilder(64);
6585 int[] outInt = new int[1];
6586 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6587 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006588 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6589 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006590 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006591 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6592 dsteps, false)) {
6593 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6594 sb, outInt);
6595 }
6596 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6597 csteps, false)) {
6598 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6599 sb, outInt);
6600 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006601 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006602 } else {
6603 pw.println(" Current daily steps:");
6604 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6605 sb, outInt);
6606 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6607 sb, outInt);
6608 }
6609 }
6610 DailyItem dit;
6611 int curIndex = 0;
6612 while ((dit=getDailyItemLocked(curIndex)) != null) {
6613 curIndex++;
6614 if ((flags&DUMP_DAILY_ONLY) != 0) {
6615 pw.println();
6616 }
6617 pw.print(" Daily from ");
6618 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6619 pw.print(" to ");
6620 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6621 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006622 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006623 if (dumpDurationSteps(pw, " ",
6624 " Discharge step durations:", dit.mDischargeSteps, false)) {
6625 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6626 sb, outInt);
6627 }
6628 if (dumpDurationSteps(pw, " ",
6629 " Charge step durations:", dit.mChargeSteps, false)) {
6630 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6631 sb, outInt);
6632 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006633 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006634 } else {
6635 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6636 sb, outInt);
6637 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6638 sb, outInt);
6639 }
6640 }
6641 pw.println();
6642 }
6643 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006644 pw.println("Statistics since last charge:");
6645 pw.println(" System starts: " + getStartCount()
6646 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006647 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6648 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006649 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 }
Mike Mac2f518a2017-09-19 16:06:03 -07006652
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006653 // This is called from BatteryStatsService.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006655 public void dumpCheckinLocked(Context context, PrintWriter pw,
6656 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006657 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006658
6659 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006660 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6661 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006662
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006663 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6664
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006665 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006666 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006667 try {
6668 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6669 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6670 pw.print(HISTORY_STRING_POOL); pw.print(',');
6671 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006672 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006673 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006674 pw.print(",\"");
6675 String str = getHistoryTagPoolString(i);
6676 str = str.replace("\\", "\\\\");
6677 str = str.replace("\"", "\\\"");
6678 pw.print(str);
6679 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006680 pw.println();
6681 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006682 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006683 } finally {
6684 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006685 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006686 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006687 }
6688
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006689 if ((flags & DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006690 return;
6691 }
6692
Dianne Hackborne4a59512010-12-07 11:08:07 -08006693 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006694 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006695 for (int i=0; i<apps.size(); i++) {
6696 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006697 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6698 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006699 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006700 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6701 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006702 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006703 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006704 }
6705 SparseArray<? extends Uid> uidStats = getUidStats();
6706 final int NU = uidStats.size();
6707 String[] lineArgs = new String[2];
6708 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006709 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6710 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6711 if (pkgs != null && !pkgs.second.value) {
6712 pkgs.second.value = true;
6713 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006714 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006715 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006716 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6717 (Object[])lineArgs);
6718 }
6719 }
6720 }
6721 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006722 if ((flags & DUMP_DAILY_ONLY) == 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006723 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006724 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006725 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006726 if (timeRemaining >= 0) {
6727 lineArgs[0] = Long.toString(timeRemaining);
6728 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6729 (Object[])lineArgs);
6730 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006731 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006732 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006733 if (timeRemaining >= 0) {
6734 lineArgs[0] = Long.toString(timeRemaining);
6735 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6736 (Object[])lineArgs);
6737 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006738 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6739 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006742
Kweku Adams87b19ec2017-10-09 12:40:03 -07006743 /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006744 public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps,
6745 int flags, long historyStart) {
6746 final ProtoOutputStream proto = new ProtoOutputStream(fd);
6747 final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS);
6748 prepareForDumpLocked();
6749
6750 proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION);
6751 proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion());
6752 proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion());
6753 proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion());
6754
6755 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6756
6757 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
6758 if (startIteratingHistoryLocked()) {
6759 // TODO: implement dumpProtoHistoryLocked(proto);
6760 }
6761 }
6762
6763 if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) {
Kweku Adams103351f2017-10-16 14:39:34 -07006764 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false,
6765 (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
6766 helper.create(this);
6767 helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL);
6768
6769 dumpProtoAppsLocked(proto, helper, apps);
6770 dumpProtoSystemLocked(proto, helper);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006771 }
6772
6773 proto.end(bToken);
6774 proto.flush();
6775 }
Kweku Adams87b19ec2017-10-09 12:40:03 -07006776
Kweku Adams103351f2017-10-16 14:39:34 -07006777 private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper,
6778 List<ApplicationInfo> apps) {
6779 final int which = STATS_SINCE_CHARGED;
6780 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
6781 final long rawRealtimeMs = SystemClock.elapsedRealtime();
6782 final long rawRealtimeUs = rawRealtimeMs * 1000;
6783 final long batteryUptimeUs = getBatteryUptime(rawUptimeUs);
6784
6785 SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>();
6786 if (apps != null) {
6787 for (int i = 0; i < apps.size(); ++i) {
6788 ApplicationInfo ai = apps.get(i);
6789 int aid = UserHandle.getAppId(ai.uid);
6790 ArrayList<String> pkgs = aidToPackages.get(aid);
6791 if (pkgs == null) {
6792 pkgs = new ArrayList<String>();
6793 aidToPackages.put(aid, pkgs);
6794 }
6795 pkgs.add(ai.packageName);
6796 }
6797 }
6798
6799 SparseArray<BatterySipper> uidToSipper = new SparseArray<>();
6800 final List<BatterySipper> sippers = helper.getUsageList();
6801 if (sippers != null) {
6802 for (int i = 0; i < sippers.size(); ++i) {
6803 final BatterySipper bs = sippers.get(i);
6804 if (bs.drainType != BatterySipper.DrainType.APP) {
6805 // Others are handled by dumpProtoSystemLocked()
6806 continue;
6807 }
6808 uidToSipper.put(bs.uidObj.getUid(), bs);
6809 }
6810 }
6811
6812 SparseArray<? extends Uid> uidStats = getUidStats();
6813 final int n = uidStats.size();
6814 for (int iu = 0; iu < n; ++iu) {
6815 final long uTkn = proto.start(BatteryStatsProto.UIDS);
6816 final Uid u = uidStats.valueAt(iu);
6817
6818 final int uid = uidStats.keyAt(iu);
6819 proto.write(UidProto.UID, uid);
6820
6821 // Print packages and apk stats (UID_DATA & APK_DATA)
6822 ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid));
6823 if (pkgs == null) {
6824 pkgs = new ArrayList<String>();
6825 }
6826 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats =
6827 u.getPackageStats();
6828 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
6829 String pkg = packageStats.keyAt(ipkg);
6830 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats =
6831 packageStats.valueAt(ipkg).getServiceStats();
6832 if (serviceStats.size() == 0) {
6833 // Due to the way ActivityManagerService logs wakeup alarms, some packages (for
6834 // example, "android") may be included in the packageStats that aren't part of
6835 // the UID. If they don't have any services, then they shouldn't be listed here.
6836 // These packages won't be a part in the pkgs List.
6837 continue;
6838 }
6839
6840 final long pToken = proto.start(UidProto.PACKAGES);
6841 proto.write(UidProto.Package.NAME, pkg);
6842 // Remove from the packages list since we're logging it here.
6843 pkgs.remove(pkg);
6844
6845 for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) {
6846 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
6847 long sToken = proto.start(UidProto.Package.SERVICES);
6848
6849 proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc));
6850 proto.write(UidProto.Package.Service.START_DURATION_MS,
6851 roundUsToMs(ss.getStartTime(batteryUptimeUs, which)));
6852 proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which));
6853 proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which));
6854
6855 proto.end(sToken);
6856 }
6857 proto.end(pToken);
6858 }
6859 // Print any remaining packages that weren't in the packageStats map. pkgs is pulled
6860 // from PackageManager data. Packages are only included in packageStats if there was
6861 // specific data tracked for them (services and wakeup alarms, etc.).
6862 for (String p : pkgs) {
6863 final long pToken = proto.start(UidProto.PACKAGES);
6864 proto.write(UidProto.Package.NAME, p);
6865 proto.end(pToken);
6866 }
6867
6868 // Total wakelock data (AGGREGATED_WAKELOCK_DATA)
6869 if (u.getAggregatedPartialWakelockTimer() != null) {
6870 final Timer timer = u.getAggregatedPartialWakelockTimer();
6871 // Times are since reset (regardless of 'which')
6872 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
6873 final Timer bgTimer = timer.getSubTimer();
6874 final long bgTimeMs = bgTimer != null
6875 ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
6876 final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK);
6877 proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs);
6878 proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs);
6879 proto.end(awToken);
6880 }
6881
6882 // Audio (AUDIO_DATA)
6883 dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which);
6884
6885 // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA)
6886 dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER,
6887 u.getBluetoothControllerActivity(), which);
6888
6889 // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked)
6890 final Timer bleTimer = u.getBluetoothScanTimer();
6891 if (bleTimer != null) {
6892 final long bmToken = proto.start(UidProto.BLUETOOTH_MISC);
6893
6894 dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer,
6895 rawRealtimeUs, which);
6896 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN,
6897 u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which);
6898 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
6899 dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN,
6900 u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which);
6901 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
6902 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN,
6903 u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which);
6904 // Result counters
6905 proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT,
6906 u.getBluetoothScanResultCounter() != null
6907 ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0);
6908 proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT,
6909 u.getBluetoothScanResultBgCounter() != null
6910 ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0);
6911
6912 proto.end(bmToken);
6913 }
6914
6915 // Camera (CAMERA_DATA)
6916 dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which);
6917
6918 // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA)
6919 final long cpuToken = proto.start(UidProto.CPU);
6920 proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which)));
6921 proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which)));
6922
6923 final long[] cpuFreqs = getCpuFreqs();
6924 if (cpuFreqs != null) {
6925 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
6926 // If total cpuFreqTimes is null, then we don't need to check for
6927 // screenOffCpuFreqTimes.
6928 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
6929 long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
6930 if (screenOffCpuFreqTimeMs == null) {
6931 screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
6932 }
6933 for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) {
6934 long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY);
6935 proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1);
6936 proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS,
6937 cpuFreqTimeMs[ic]);
6938 proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS,
6939 screenOffCpuFreqTimeMs[ic]);
6940 proto.end(cToken);
6941 }
6942 }
6943 }
6944 proto.end(cpuToken);
6945
6946 // Flashlight (FLASHLIGHT_DATA)
6947 dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(),
6948 rawRealtimeUs, which);
6949
6950 // Foreground activity (FOREGROUND_ACTIVITY_DATA)
6951 dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(),
6952 rawRealtimeUs, which);
6953
6954 // Foreground service (FOREGROUND_SERVICE_DATA)
6955 dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(),
6956 rawRealtimeUs, which);
6957
6958 // Job completion (JOB_COMPLETION_DATA)
6959 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
6960 final int[] reasons = new int[]{
6961 JobParameters.REASON_CANCELED,
6962 JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
6963 JobParameters.REASON_PREEMPT,
6964 JobParameters.REASON_TIMEOUT,
6965 JobParameters.REASON_DEVICE_IDLE,
6966 };
6967 for (int ic = 0; ic < completions.size(); ++ic) {
6968 SparseIntArray types = completions.valueAt(ic);
6969 if (types != null) {
6970 final long jcToken = proto.start(UidProto.JOB_COMPLETION);
6971
6972 proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic));
6973
6974 for (int r : reasons) {
6975 long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT);
6976 proto.write(UidProto.JobCompletion.ReasonCount.NAME, r);
6977 proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0));
6978 proto.end(rToken);
6979 }
6980
6981 proto.end(jcToken);
6982 }
6983 }
6984
6985 // Scheduled jobs (JOB_DATA)
6986 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
6987 for (int ij = jobs.size() - 1; ij >= 0; --ij) {
6988 final Timer timer = jobs.valueAt(ij);
6989 final Timer bgTimer = timer.getSubTimer();
6990 final long jToken = proto.start(UidProto.JOBS);
6991
6992 proto.write(UidProto.Job.NAME, jobs.keyAt(ij));
6993 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
6994 dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which);
6995 dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which);
6996
6997 proto.end(jToken);
6998 }
6999
7000 // Modem Controller (MODEM_CONTROLLER_DATA)
7001 dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER,
7002 u.getModemControllerActivity(), which);
7003
7004 // Network stats (NETWORK_DATA)
7005 final long nToken = proto.start(UidProto.NETWORK);
7006 proto.write(UidProto.Network.MOBILE_BYTES_RX,
7007 u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7008 proto.write(UidProto.Network.MOBILE_BYTES_TX,
7009 u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7010 proto.write(UidProto.Network.WIFI_BYTES_RX,
7011 u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7012 proto.write(UidProto.Network.WIFI_BYTES_TX,
7013 u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7014 proto.write(UidProto.Network.BT_BYTES_RX,
7015 u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7016 proto.write(UidProto.Network.BT_BYTES_TX,
7017 u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
7018 proto.write(UidProto.Network.MOBILE_PACKETS_RX,
7019 u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7020 proto.write(UidProto.Network.MOBILE_PACKETS_TX,
7021 u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7022 proto.write(UidProto.Network.WIFI_PACKETS_RX,
7023 u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7024 proto.write(UidProto.Network.WIFI_PACKETS_TX,
7025 u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7026 proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS,
7027 roundUsToMs(u.getMobileRadioActiveTime(which)));
7028 proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT,
7029 u.getMobileRadioActiveCount(which));
7030 proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT,
7031 u.getMobileRadioApWakeupCount(which));
7032 proto.write(UidProto.Network.WIFI_WAKEUP_COUNT,
7033 u.getWifiRadioApWakeupCount(which));
7034 proto.write(UidProto.Network.MOBILE_BYTES_BG_RX,
7035 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which));
7036 proto.write(UidProto.Network.MOBILE_BYTES_BG_TX,
7037 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which));
7038 proto.write(UidProto.Network.WIFI_BYTES_BG_RX,
7039 u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which));
7040 proto.write(UidProto.Network.WIFI_BYTES_BG_TX,
7041 u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which));
7042 proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX,
7043 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which));
7044 proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX,
7045 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which));
7046 proto.write(UidProto.Network.WIFI_PACKETS_BG_RX,
7047 u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which));
7048 proto.write(UidProto.Network.WIFI_PACKETS_BG_TX,
7049 u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which));
7050 proto.end(nToken);
7051
7052 // Power use item (POWER_USE_ITEM_DATA)
7053 BatterySipper bs = uidToSipper.get(uid);
7054 if (bs != null) {
7055 final long bsToken = proto.start(UidProto.POWER_USE_ITEM);
7056 proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7057 proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7058 proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7059 proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7060 bs.proportionalSmearMah);
7061 proto.end(bsToken);
7062 }
7063
7064 // Processes (PROCESS_DATA)
7065 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats =
7066 u.getProcessStats();
7067 for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) {
7068 final Uid.Proc ps = processStats.valueAt(ipr);
7069 final long prToken = proto.start(UidProto.PROCESS);
7070
7071 proto.write(UidProto.Process.NAME, processStats.keyAt(ipr));
7072 proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which));
7073 proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which));
7074 proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which));
7075 proto.write(UidProto.Process.START_COUNT, ps.getStarts(which));
7076 proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which));
7077 proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which));
7078
7079 proto.end(prToken);
7080 }
7081
7082 // Sensors (SENSOR_DATA)
7083 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
7084 for (int ise = 0; ise < sensors.size(); ++ise) {
7085 final Uid.Sensor se = sensors.valueAt(ise);
7086 final Timer timer = se.getSensorTime();
7087 if (timer == null) {
7088 continue;
7089 }
7090 final Timer bgTimer = se.getSensorBackgroundTime();
7091 final int sensorNumber = sensors.keyAt(ise);
7092 final long seToken = proto.start(UidProto.SENSORS);
7093
7094 proto.write(UidProto.Sensor.ID, sensorNumber);
7095 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7096 dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which);
7097 dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which);
7098
7099 proto.end(seToken);
7100 }
7101
7102 // State times (STATE_TIME_DATA)
7103 for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) {
7104 long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which));
7105 if (durMs == 0) {
7106 continue;
7107 }
7108 final long stToken = proto.start(UidProto.STATES);
7109 proto.write(UidProto.StateTime.STATE, ips);
7110 proto.write(UidProto.StateTime.DURATION_MS, durMs);
7111 proto.end(stToken);
7112 }
7113
7114 // Syncs (SYNC_DATA)
7115 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
7116 for (int isy = syncs.size() - 1; isy >= 0; --isy) {
7117 final Timer timer = syncs.valueAt(isy);
7118 final Timer bgTimer = timer.getSubTimer();
7119 final long syToken = proto.start(UidProto.SYNCS);
7120
7121 proto.write(UidProto.Sync.NAME, syncs.keyAt(isy));
7122 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7123 dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which);
7124 dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which);
7125
7126 proto.end(syToken);
7127 }
7128
7129 // User activity (USER_ACTIVITY_DATA)
7130 if (u.hasUserActivity()) {
7131 for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) {
7132 int val = u.getUserActivityCount(i, which);
7133 if (val != 0) {
7134 final long uaToken = proto.start(UidProto.USER_ACTIVITY);
7135 proto.write(UidProto.UserActivity.NAME, i);
7136 proto.write(UidProto.UserActivity.COUNT, val);
7137 proto.end(uaToken);
7138 }
7139 }
7140 }
7141
7142 // Vibrator (VIBRATOR_DATA)
7143 dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which);
7144
7145 // Video (VIDEO_DATA)
7146 dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which);
7147
7148 // Wakelocks (WAKELOCK_DATA)
7149 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
7150 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7151 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7152 final long wToken = proto.start(UidProto.WAKELOCKS);
7153 proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw));
7154 dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL),
7155 rawRealtimeUs, which);
7156 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7157 if (pTimer != null) {
7158 dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which);
7159 dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(),
7160 rawRealtimeUs, which);
7161 }
7162 dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW),
7163 rawRealtimeUs, which);
7164 proto.end(wToken);
7165 }
7166
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007167 // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA)
7168 dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(),
7169 rawRealtimeUs, which);
7170
Kweku Adams103351f2017-10-16 14:39:34 -07007171 // Wakeup alarms (WAKEUP_ALARM_DATA)
7172 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
7173 final Uid.Pkg ps = packageStats.valueAt(ipkg);
7174 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
7175 for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) {
7176 final long waToken = proto.start(UidProto.WAKEUP_ALARM);
7177 proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa));
7178 proto.write(UidProto.WakeupAlarm.COUNT,
7179 alarms.valueAt(iwa).getCountLocked(which));
7180 proto.end(waToken);
7181 }
7182 }
7183
7184 // Wifi Controller (WIFI_CONTROLLER_DATA)
7185 dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER,
7186 u.getWifiControllerActivity(), which);
7187
7188 // Wifi data (WIFI_DATA)
7189 final long wToken = proto.start(UidProto.WIFI);
7190 proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS,
7191 roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which)));
7192 dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(),
7193 rawRealtimeUs, which);
7194 proto.write(UidProto.Wifi.RUNNING_DURATION_MS,
7195 roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which)));
7196 dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(),
7197 rawRealtimeUs, which);
7198 proto.end(wToken);
7199
7200 proto.end(uTkn);
7201 }
7202 }
7203
7204 private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) {
Kweku Adams87b19ec2017-10-09 12:40:03 -07007205 final long sToken = proto.start(BatteryStatsProto.SYSTEM);
7206 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
7207 final long rawRealtimeMs = SystemClock.elapsedRealtime();
7208 final long rawRealtimeUs = rawRealtimeMs * 1000;
7209 final int which = STATS_SINCE_CHARGED;
7210
7211 // Battery data (BATTERY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007212 final long bToken = proto.start(SystemProto.BATTERY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007213 proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime());
7214 proto.write(SystemProto.Battery.START_COUNT, getStartCount());
7215 proto.write(SystemProto.Battery.TOTAL_REALTIME_MS,
7216 computeRealtime(rawRealtimeUs, which) / 1000);
7217 proto.write(SystemProto.Battery.TOTAL_UPTIME_MS,
7218 computeUptime(rawUptimeUs, which) / 1000);
7219 proto.write(SystemProto.Battery.BATTERY_REALTIME_MS,
7220 computeBatteryRealtime(rawRealtimeUs, which) / 1000);
7221 proto.write(SystemProto.Battery.BATTERY_UPTIME_MS,
7222 computeBatteryUptime(rawUptimeUs, which) / 1000);
7223 proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS,
7224 computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000);
7225 proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS,
7226 computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000);
7227 proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS,
7228 getScreenDozeTime(rawRealtimeUs, which) / 1000);
7229 proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH,
7230 getEstimatedBatteryCapacity());
7231 proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH,
7232 getMinLearnedBatteryCapacity());
7233 proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH,
7234 getMaxLearnedBatteryCapacity());
Kweku Adams103351f2017-10-16 14:39:34 -07007235 proto.end(bToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007236
7237 // Battery discharge (BATTERY_DISCHARGE_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007238 final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007239 proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE,
7240 getLowDischargeAmountSinceCharge());
7241 proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE,
7242 getHighDischargeAmountSinceCharge());
7243 proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE,
7244 getDischargeAmountScreenOnSinceCharge());
7245 proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE,
7246 getDischargeAmountScreenOffSinceCharge());
7247 proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE,
7248 getDischargeAmountScreenDozeSinceCharge());
7249 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH,
7250 getUahDischarge(which) / 1000);
7251 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF,
7252 getUahDischargeScreenOff(which) / 1000);
7253 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE,
7254 getUahDischargeScreenDoze(which) / 1000);
Mike Ma15313c92017-11-15 17:58:21 -08007255 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE,
7256 getUahDischargeLightDoze(which) / 1000);
7257 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE,
7258 getUahDischargeDeepDoze(which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007259 proto.end(bdToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007260
7261 // Time remaining
7262 long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -07007263 // These are part of a oneof, so we should only set one of them.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007264 if (timeRemainingUs >= 0) {
7265 // Charge time remaining (CHARGE_TIME_REMAIN_DATA)
7266 proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7267 } else {
7268 timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs);
7269 // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA)
7270 if (timeRemainingUs >= 0) {
7271 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7272 } else {
7273 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1);
7274 }
7275 }
7276
7277 // Charge step (CHARGE_STEP_DATA)
7278 dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker());
7279
7280 // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA)
7281 for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007282 final long pdcToken = proto.start(SystemProto.DATA_CONNECTION);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007283 proto.write(SystemProto.DataConnection.NAME, i);
7284 dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i),
7285 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007286 proto.end(pdcToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007287 }
7288
7289 // Discharge step (DISCHARGE_STEP_DATA)
7290 dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker());
7291
7292 // CPU frequencies (GLOBAL_CPU_FREQ_DATA)
7293 final long[] cpuFreqs = getCpuFreqs();
7294 if (cpuFreqs != null) {
7295 for (long i : cpuFreqs) {
7296 proto.write(SystemProto.CPU_FREQUENCY, i);
7297 }
7298 }
7299
7300 // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA)
7301 dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER,
7302 getBluetoothControllerActivity(), which);
7303
7304 // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA)
7305 dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER,
7306 getModemControllerActivity(), which);
7307
7308 // Global network data (GLOBAL_NETWORK_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007309 final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007310 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX,
7311 getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7312 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX,
7313 getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7314 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX,
7315 getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7316 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX,
7317 getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7318 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX,
7319 getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7320 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX,
7321 getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7322 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX,
7323 getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7324 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX,
7325 getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7326 proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX,
7327 getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7328 proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX,
7329 getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
Kweku Adams103351f2017-10-16 14:39:34 -07007330 proto.end(gnToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007331
7332 // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA)
7333 dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER,
7334 getWifiControllerActivity(), which);
7335
7336
7337 // Global wifi (GLOBAL_WIFI_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007338 final long gwToken = proto.start(SystemProto.GLOBAL_WIFI);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007339 proto.write(SystemProto.GlobalWifi.ON_DURATION_MS,
7340 getWifiOnTime(rawRealtimeUs, which) / 1000);
7341 proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS,
7342 getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007343 proto.end(gwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007344
7345 // Kernel wakelock (KERNEL_WAKELOCK_DATA)
7346 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
7347 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007348 final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007349 proto.write(SystemProto.KernelWakelock.NAME, ent.getKey());
7350 dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(),
7351 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007352 proto.end(kwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007353 }
7354
7355 // Misc (MISC_DATA)
7356 // Calculate wakelock times across all uids.
7357 long fullWakeLockTimeTotalUs = 0;
7358 long partialWakeLockTimeTotalUs = 0;
7359
7360 final SparseArray<? extends Uid> uidStats = getUidStats();
7361 for (int iu = 0; iu < uidStats.size(); iu++) {
7362 final Uid u = uidStats.valueAt(iu);
7363
7364 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks =
7365 u.getWakelockStats();
7366 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7367 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7368
7369 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
7370 if (fullWakeTimer != null) {
7371 fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs,
7372 which);
7373 }
7374
7375 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7376 if (partialWakeTimer != null) {
7377 partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked(
7378 rawRealtimeUs, which);
7379 }
7380 }
7381 }
Kweku Adams103351f2017-10-16 14:39:34 -07007382 final long mToken = proto.start(SystemProto.MISC);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007383 proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS,
7384 getScreenOnTime(rawRealtimeUs, which) / 1000);
7385 proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS,
7386 getPhoneOnTime(rawRealtimeUs, which) / 1000);
7387 proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS,
7388 fullWakeLockTimeTotalUs / 1000);
7389 proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS,
7390 partialWakeLockTimeTotalUs / 1000);
7391 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS,
7392 getMobileRadioActiveTime(rawRealtimeUs, which) / 1000);
7393 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS,
7394 getMobileRadioActiveAdjustedTime(which) / 1000);
7395 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT,
7396 getMobileRadioActiveCount(which));
7397 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS,
7398 getMobileRadioActiveUnknownTime(which) / 1000);
7399 proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS,
7400 getInteractiveTime(rawRealtimeUs, which) / 1000);
7401 proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS,
7402 getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000);
7403 proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES,
7404 getNumConnectivityChange(which));
7405 proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS,
7406 getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7407 proto.write(SystemProto.Misc.DEEP_DOZE_COUNT,
7408 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
7409 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS,
7410 getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7411 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT,
7412 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
7413 proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS,
7414 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
7415 proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS,
7416 getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7417 proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT,
7418 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
7419 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS,
7420 getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7421 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT,
7422 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
7423 proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS,
7424 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
Kweku Adams103351f2017-10-16 14:39:34 -07007425 proto.end(mToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007426
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007427 // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA)
7428 // Calculate multicast wakelock stats across all uids.
7429 long multicastWakeLockTimeTotalUs = 0;
7430 int multicastWakeLockCountTotal = 0;
7431
7432 for (int iu = 0; iu < uidStats.size(); iu++) {
7433 final Uid u = uidStats.valueAt(iu);
7434
7435 final Timer mcTimer = u.getMulticastWakelockStats();
7436
7437 if (mcTimer != null) {
7438 multicastWakeLockTimeTotalUs +=
7439 mcTimer.getTotalTimeLocked(rawRealtimeUs, which);
7440 multicastWakeLockCountTotal += mcTimer.getCountLocked(which);
7441 }
7442 }
7443
7444 final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL);
7445 proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS,
7446 multicastWakeLockTimeTotalUs / 1000);
7447 proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT,
7448 multicastWakeLockCountTotal);
7449 proto.end(wmctToken);
7450
Kweku Adams87b19ec2017-10-09 12:40:03 -07007451 // Power use item (POWER_USE_ITEM_DATA)
7452 final List<BatterySipper> sippers = helper.getUsageList();
7453 if (sippers != null) {
7454 for (int i = 0; i < sippers.size(); ++i) {
7455 final BatterySipper bs = sippers.get(i);
7456 int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER;
7457 int uid = 0;
7458 switch (bs.drainType) {
7459 case IDLE:
7460 n = SystemProto.PowerUseItem.IDLE;
7461 break;
7462 case CELL:
7463 n = SystemProto.PowerUseItem.CELL;
7464 break;
7465 case PHONE:
7466 n = SystemProto.PowerUseItem.PHONE;
7467 break;
7468 case WIFI:
7469 n = SystemProto.PowerUseItem.WIFI;
7470 break;
7471 case BLUETOOTH:
7472 n = SystemProto.PowerUseItem.BLUETOOTH;
7473 break;
7474 case SCREEN:
7475 n = SystemProto.PowerUseItem.SCREEN;
7476 break;
7477 case FLASHLIGHT:
7478 n = SystemProto.PowerUseItem.FLASHLIGHT;
7479 break;
7480 case APP:
Kweku Adams103351f2017-10-16 14:39:34 -07007481 // dumpProtoAppsLocked will handle this.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007482 continue;
7483 case USER:
7484 n = SystemProto.PowerUseItem.USER;
7485 uid = UserHandle.getUid(bs.userId, 0);
7486 break;
7487 case UNACCOUNTED:
7488 n = SystemProto.PowerUseItem.UNACCOUNTED;
7489 break;
7490 case OVERCOUNTED:
7491 n = SystemProto.PowerUseItem.OVERCOUNTED;
7492 break;
7493 case CAMERA:
7494 n = SystemProto.PowerUseItem.CAMERA;
7495 break;
7496 case MEMORY:
7497 n = SystemProto.PowerUseItem.MEMORY;
7498 break;
7499 }
Kweku Adams103351f2017-10-16 14:39:34 -07007500 final long puiToken = proto.start(SystemProto.POWER_USE_ITEM);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007501 proto.write(SystemProto.PowerUseItem.NAME, n);
7502 proto.write(SystemProto.PowerUseItem.UID, uid);
7503 proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7504 proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7505 proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7506 proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7507 bs.proportionalSmearMah);
Kweku Adams103351f2017-10-16 14:39:34 -07007508 proto.end(puiToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007509 }
7510 }
7511
7512 // Power use summary (POWER_USE_SUMMARY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007513 final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007514 proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH,
7515 helper.getPowerProfile().getBatteryCapacity());
7516 proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower());
7517 proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower());
7518 proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower());
Kweku Adams103351f2017-10-16 14:39:34 -07007519 proto.end(pusToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007520
7521 // RPM stats (RESOURCE_POWER_MANAGER_DATA)
7522 final Map<String, ? extends Timer> rpmStats = getRpmStats();
7523 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
7524 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007525 final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007526 proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey());
7527 dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL,
7528 ent.getValue(), rawRealtimeUs, which);
7529 dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF,
7530 screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007531 proto.end(rpmToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007532 }
7533
7534 // Screen brightness (SCREEN_BRIGHTNESS_DATA)
7535 for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007536 final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007537 proto.write(SystemProto.ScreenBrightness.NAME, i);
7538 dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i),
7539 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007540 proto.end(sbToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007541 }
7542
7543 // Signal scanning time (SIGNAL_SCANNING_TIME_DATA)
7544 dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs,
7545 which);
7546
7547 // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA)
7548 for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007549 final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007550 proto.write(SystemProto.PhoneSignalStrength.NAME, i);
7551 dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i),
7552 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007553 proto.end(pssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007554 }
7555
7556 // Wakeup reasons (WAKEUP_REASON_DATA)
7557 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
7558 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007559 final long wrToken = proto.start(SystemProto.WAKEUP_REASON);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007560 proto.write(SystemProto.WakeupReason.NAME, ent.getKey());
7561 dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007562 proto.end(wrToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007563 }
7564
7565 // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA)
7566 for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007567 final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007568 proto.write(SystemProto.WifiSignalStrength.NAME, i);
7569 dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i),
7570 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007571 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007572 }
7573
7574 // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA)
7575 for (int i = 0; i < NUM_WIFI_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007576 final long wsToken = proto.start(SystemProto.WIFI_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007577 proto.write(SystemProto.WifiState.NAME, i);
7578 dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i),
7579 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007580 proto.end(wsToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007581 }
7582
7583 // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA)
7584 for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007585 final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007586 proto.write(SystemProto.WifiSupplicantState.NAME, i);
7587 dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i),
7588 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007589 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007590 }
7591
7592 proto.end(sToken);
7593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594}