blob: 6ecf6d5649a77c58bb1ccb3dae023719a437e49f [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
Sudheer Shankab2f83c12017-11-13 19:25:01 -080019import android.app.ActivityManager;
Dianne Hackborn94326cb2017-06-28 16:17:20 -070020import android.app.job.JobParameters;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080021import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080022import android.content.pm.ApplicationInfo;
Bookatz8bdae8d2018-01-16 11:24:30 -080023import android.server.ServerProtoEnums;
Kweku Adams2f73ecd2017-09-27 16:59:19 -070024import android.service.batterystats.BatteryStatsServiceDumpProto;
Wink Saville52840902011-02-18 12:40:47 -080025import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080026import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070027import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070028import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070029import android.util.MutableBoolean;
30import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.Printer;
32import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070033import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070034import android.util.TimeUtils;
Kweku Adams2f73ecd2017-09-27 16:59:19 -070035import android.util.proto.ProtoOutputStream;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070036import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080037
Sudheer Shankab2f83c12017-11-13 19:25:01 -080038import com.android.internal.annotations.VisibleForTesting;
Siddharth Ray78ccaf52017-12-23 16:16:21 -080039import com.android.internal.location.gnssmetrics.GnssMetrics;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080040import com.android.internal.os.BatterySipper;
41import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Kweku Adams2f73ecd2017-09-27 16:59:19 -070043import java.io.FileDescriptor;
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -070044import java.io.PrintWriter;
45import java.util.ArrayList;
46import java.util.Collections;
47import java.util.Comparator;
48import java.util.Formatter;
49import java.util.HashMap;
50import java.util.List;
51import java.util.Map;
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053/**
54 * A class providing access to battery usage statistics, including information on
55 * wakelocks, processes, packages, and services. All times are represented in microseconds
56 * except where indicated otherwise.
57 * @hide
58 */
59public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070060 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
62 private static final boolean LOCAL_LOGV = false;
Bookatz82b341172017-09-07 19:06:08 -070063 /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */
64 protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070065
66 /** @hide */
67 public static final String SERVICE_NAME = "batterystats";
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /**
70 * A constant indicating a partial wake lock timer.
71 */
72 public static final int WAKE_TYPE_PARTIAL = 0;
73
74 /**
75 * A constant indicating a full wake lock timer.
76 */
77 public static final int WAKE_TYPE_FULL = 1;
78
79 /**
80 * A constant indicating a window wake lock timer.
81 */
82 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 /**
85 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 */
87 public static final int SENSOR = 3;
Mike Mac2f518a2017-09-19 16:06:03 -070088
The Android Open Source Project10592532009-03-18 17:39:46 -070089 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070090 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070091 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070092 public static final int WIFI_RUNNING = 4;
Mike Mac2f518a2017-09-19 16:06:03 -070093
Dianne Hackborn617f8772009-03-31 15:04:46 -070094 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070095 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070096 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070097 public static final int FULL_WIFI_LOCK = 5;
Mike Mac2f518a2017-09-19 16:06:03 -070098
The Android Open Source Project10592532009-03-18 17:39:46 -070099 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -0700100 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -0700101 */
Nick Pelly6ccaa542012-06-15 15:22:47 -0700102 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103
Dianne Hackborn62793e42015-03-09 11:15:41 -0700104 /**
105 * A constant indicating a wifi multicast timer
106 */
107 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700110 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700111 */
112 public static final int VIDEO_TURNED_ON = 8;
113
114 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800115 * A constant indicating a vibrator on timer
116 */
117 public static final int VIBRATOR_ON = 9;
118
119 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700120 * A constant indicating a foreground activity timer
121 */
122 public static final int FOREGROUND_ACTIVITY = 10;
123
124 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700125 * A constant indicating a wifi batched scan is active
126 */
127 public static final int WIFI_BATCHED_SCAN = 11;
128
129 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700130 * A constant indicating a process state timer
131 */
132 public static final int PROCESS_STATE = 12;
133
134 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700135 * A constant indicating a sync timer
136 */
137 public static final int SYNC = 13;
138
139 /**
140 * A constant indicating a job timer
141 */
142 public static final int JOB = 14;
143
144 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800145 * A constant indicating an audio turn on timer
146 */
147 public static final int AUDIO_TURNED_ON = 15;
148
149 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700150 * A constant indicating a flashlight turn on timer
151 */
152 public static final int FLASHLIGHT_TURNED_ON = 16;
153
154 /**
155 * A constant indicating a camera turn on timer
156 */
157 public static final int CAMERA_TURNED_ON = 17;
158
159 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700160 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700161 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700162 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700163
164 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800165 * A constant indicating a bluetooth scan timer.
166 */
167 public static final int BLUETOOTH_SCAN_ON = 19;
168
169 /**
Bookatzc8c44962017-05-11 12:12:54 -0700170 * A constant indicating an aggregated partial wake lock timer.
171 */
172 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
173
174 /**
Bookatzb1f04f32017-05-19 13:57:32 -0700175 * A constant indicating a bluetooth scan timer for unoptimized scans.
176 */
177 public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21;
178
179 /**
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700180 * A constant indicating a foreground service timer
181 */
182 public static final int FOREGROUND_SERVICE = 22;
183
184 /**
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -0800185 * A constant indicating an aggregate wifi multicast timer
186 */
187 public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23;
188
189 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 * Include all of the data in the stats, including previously saved data.
191 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700192 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193
194 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 * Include only the current run in the stats.
196 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700197 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
199 /**
200 * Include only the run since the last time the device was unplugged in the stats.
201 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700202 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700203
204 // NOTE: Update this list if you add/change any stats above.
Kweku Adams2f73ecd2017-09-27 16:59:19 -0700205 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700206 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700207 private static final String[] STAT_NAMES = { "l", "c", "u" };
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700210 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700211 *
212 * New in version 19:
213 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800214 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700215 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700216 * New in version 21:
217 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700218 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700219 * - BLE scan result count
220 * - CPU frequency time per uid
221 * New in version 22:
222 * - BLE scan result background count, BLE unoptimized scan time
Bookatz98d4d5c2017-08-01 19:07:54 -0700223 * - Background partial wakelock time & count
224 * New in version 23:
225 * - Logging smeared power model values
226 * New in version 24:
227 * - Fixed bugs in background timers and BLE scan time
228 * New in version 25:
229 * - Package wakeup alarms are now on screen-off timebase
Bookatz50df7112017-08-04 14:53:26 -0700230 * New in version 26:
Bookatz82b341172017-09-07 19:06:08 -0700231 * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
Mike Mac2f518a2017-09-19 16:06:03 -0700232 * New in version 27:
233 * - Always On Display (screen doze mode) time and power
Mike Ma15313c92017-11-15 17:58:21 -0800234 * New in version 28:
235 * - Light/Deep Doze power
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700236 * - WiFi Multicast Wakelock statistics (count & duration)
Kweku Adamsa8943cb2017-12-22 13:21:06 -0800237 * New in version 29:
238 * - Process states re-ordered. TOP_SLEEPING now below BACKGROUND. HEAVY_WEIGHT introduced.
239 * - CPU times per UID process state
zhouwenjie46712bc2018-01-11 15:21:27 -0800240 * New in version 30:
241 * - Uid.PROCESS_STATE_FOREGROUND_SERVICE only tracks
242 * ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE.
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700243 */
zhouwenjie46712bc2018-01-11 15:21:27 -0800244 static final int CHECKIN_VERSION = 30;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700245
246 /**
247 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700249 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700250
Evan Millar22ac0432009-03-31 11:33:18 -0700251 private static final long BYTES_PER_KB = 1024;
252 private static final long BYTES_PER_MB = 1048576; // 1024^2
253 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700254
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700255 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800256 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700257 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700259 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700260 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700261 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
262 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700263 // rpm line is:
264 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
265 // screen-off time, screen-off count
266 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700267 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800268 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700269 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
270 // fgs line is:
271 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
272 // foreground service time, count
273 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700274 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700275 // wl line is:
276 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700277 // full totalTime, 'f', count, current duration, max duration, total duration,
278 // partial totalTime, 'p', count, current duration, max duration, total duration,
279 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
280 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700281 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700282 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700283 // awl line is:
284 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
285 // cumulative partial wakelock duration, cumulative background partial wakelock duration
286 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700287 private static final String SYNC_DATA = "sy";
288 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700289 private static final String JOB_COMPLETION_DATA = "jbc";
Amith Yamasani977e11f2018-02-16 11:29:54 -0800290
291 /**
292 * jbd line is:
293 * BATTERY_STATS_CHECKIN_VERSION, uid, which, "jbd",
294 * jobsDeferredEventCount, jobsDeferredCount, averageLatencyMillis,
295 * count at latency < 1 hr, count at latency < 2 hrs, count at latency < 6 hrs, beyond 6 hrs
296 * <p>
297 * @see #JOB_FRESHNESS_BUCKETS
298 */
299 private static final String JOBS_DEFERRED_DATA = "jbd";
Evan Millarc64edde2009-04-18 12:26:32 -0700300 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700301 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700302 private static final String NETWORK_DATA = "nt";
303 private static final String USER_ACTIVITY_DATA = "ua";
304 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800305 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700306 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700307 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700308 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800309 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
310 private static final String WIFI_CONTROLLER_DATA = "wfcd";
311 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
312 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700313 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700314 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800315 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800316 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
317 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800318 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700319 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700320 private static final String SCREEN_BRIGHTNESS_DATA = "br";
321 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700322 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700323 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
324 private static final String DATA_CONNECTION_TIME_DATA = "dct";
325 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800326 private static final String WIFI_STATE_TIME_DATA = "wst";
327 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700328 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
329 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
330 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
331 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800332 private static final String POWER_USE_SUMMARY_DATA = "pws";
333 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700334 private static final String DISCHARGE_STEP_DATA = "dsd";
335 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700336 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
337 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700338 private static final String FLASHLIGHT_DATA = "fla";
339 private static final String CAMERA_DATA = "cam";
340 private static final String VIDEO_DATA = "vid";
341 private static final String AUDIO_DATA = "aud";
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700342 private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct";
343 private static final String WIFI_MULTICAST_DATA = "wmc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
Adam Lesinski010bf372016-04-11 12:18:18 -0700345 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
346
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700347 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 private final Formatter mFormatter = new Formatter(mFormatBuilder);
349
Siddharth Rayb50a6842017-12-14 15:15:28 -0800350 private static final String CELLULAR_CONTROLLER_NAME = "Cellular";
351 private static final String WIFI_CONTROLLER_NAME = "WiFi";
352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700354 * Indicates times spent by the uid at each cpu frequency in all process states.
355 *
356 * Other types might include times spent in foreground, background etc.
357 */
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800358 @VisibleForTesting
359 public static final String UID_TIMES_TYPE_ALL = "A";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700360
361 /**
Amith Yamasani977e11f2018-02-16 11:29:54 -0800362 * These are the thresholds for bucketing last time since a job was run for an app
363 * that just moved to ACTIVE due to a launch. So if the last time a job ran was less
364 * than 30 minutes ago, then it's reasonably fresh, 2 hours ago, not so fresh and so
365 * on.
366 */
367 public static final long[] JOB_FRESHNESS_BUCKETS = {
368 1 * 60 * 60 * 1000L,
369 2 * 60 * 60 * 1000L,
370 6 * 60 * 60 * 1000L,
371 Long.MAX_VALUE
372 };
373
374 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700375 * State for keeping track of counting information.
376 */
377 public static abstract class Counter {
378
379 /**
380 * Returns the count associated with this Counter for the
381 * selected type of statistics.
382 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700383 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700384 */
Evan Millarc64edde2009-04-18 12:26:32 -0700385 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700386
387 /**
388 * Temporary for debugging.
389 */
390 public abstract void logState(Printer pw, String prefix);
391 }
392
393 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700394 * State for keeping track of long counting information.
395 */
396 public static abstract class LongCounter {
397
398 /**
399 * Returns the count associated with this Counter for the
400 * selected type of statistics.
401 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700402 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700403 */
404 public abstract long getCountLocked(int which);
405
406 /**
407 * Temporary for debugging.
408 */
409 public abstract void logState(Printer pw, String prefix);
410 }
411
412 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700413 * State for keeping track of array of long counting information.
414 */
415 public static abstract class LongCounterArray {
416 /**
417 * Returns the counts associated with this Counter for the
418 * selected type of statistics.
419 *
420 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
421 */
422 public abstract long[] getCountsLocked(int which);
423
424 /**
425 * Temporary for debugging.
426 */
427 public abstract void logState(Printer pw, String prefix);
428 }
429
430 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800431 * Container class that aggregates counters for transmit, receive, and idle state of a
432 * radio controller.
433 */
434 public static abstract class ControllerActivityCounter {
435 /**
436 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
437 * idle state.
438 */
439 public abstract LongCounter getIdleTimeCounter();
440
441 /**
442 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
Siddharth Rayb50a6842017-12-14 15:15:28 -0800443 * scan state.
444 */
445 public abstract LongCounter getScanTimeCounter();
446
447
448 /**
449 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800450 * receive state.
451 */
452 public abstract LongCounter getRxTimeCounter();
453
454 /**
455 * An array of {@link LongCounter}, representing various transmit levels, where each level
456 * may draw a different amount of power. The levels themselves are controller-specific.
457 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
458 * various transmit level states.
459 */
460 public abstract LongCounter[] getTxTimeCounters();
461
462 /**
463 * @return a non-null {@link LongCounter} representing the power consumed by the controller
464 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
465 * yield a value of 0 if the device doesn't support power calculations.
466 */
467 public abstract LongCounter getPowerCounter();
468 }
469
470 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 * State for keeping track of timing information.
472 */
473 public static abstract class Timer {
474
475 /**
476 * Returns the count associated with this Timer for the
477 * selected type of statistics.
478 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700479 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 */
Evan Millarc64edde2009-04-18 12:26:32 -0700481 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482
483 /**
484 * Returns the total time in microseconds associated with this Timer for the
485 * selected type of statistics.
486 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800487 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700488 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 * @return a time in microseconds
490 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800491 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700494 * Returns the total time in microseconds associated with this Timer since the
495 * 'mark' was last set.
496 *
497 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
498 * @return a time in microseconds
499 */
500 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
501
502 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700503 * Returns the max duration if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700504 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700505 */
506 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
507 return -1;
508 }
509
510 /**
511 * Returns the current time the timer has been active, if it is being tracked.
Kweku Adams103351f2017-10-16 14:39:34 -0700512 * Not all Timer subclasses track the max, total, and current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700513 */
514 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
515 return -1;
516 }
517
518 /**
Kweku Adams103351f2017-10-16 14:39:34 -0700519 * Returns the total time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800520 *
521 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
522 * been on since reset.
523 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
524 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
525 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
526 * the actual total time.
Kweku Adams103351f2017-10-16 14:39:34 -0700527 * Not all Timer subclasses track the max, total, and current durations.
Bookatz867c0d72017-03-07 18:23:42 -0800528 */
529 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
530 return -1;
531 }
532
533 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700534 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
535 * used, for example, for tracking background usage. Secondary timers are never pooled.
536 *
537 * Not all Timer subclasses have a secondary timer; those that don't return null.
538 */
539 public Timer getSubTimer() {
540 return null;
541 }
542
543 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700544 * Returns whether the timer is currently running. Some types of timers
545 * (e.g. BatchTimers) don't know whether the event is currently active,
546 * and report false.
547 */
548 public boolean isRunningLocked() {
549 return false;
550 }
551
552 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 * Temporary for debugging.
554 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700555 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557
558 /**
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800559 * Maps the ActivityManager procstate into corresponding BatteryStats procstate.
560 */
561 public static int mapToInternalProcessState(int procState) {
562 if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) {
563 return ActivityManager.PROCESS_STATE_NONEXISTENT;
564 } else if (procState == ActivityManager.PROCESS_STATE_TOP) {
565 return Uid.PROCESS_STATE_TOP;
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -0800566 } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
567 // State when app has put itself in the foreground.
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800568 return Uid.PROCESS_STATE_FOREGROUND_SERVICE;
569 } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
570 // Persistent and other foreground states go here.
571 return Uid.PROCESS_STATE_FOREGROUND;
572 } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) {
573 return Uid.PROCESS_STATE_BACKGROUND;
574 } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
575 return Uid.PROCESS_STATE_TOP_SLEEPING;
576 } else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
577 return Uid.PROCESS_STATE_HEAVY_WEIGHT;
578 } else {
579 return Uid.PROCESS_STATE_CACHED;
580 }
581 }
582
583 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 * The statistics associated with a particular uid.
585 */
586 public static abstract class Uid {
587
588 /**
589 * Returns a mapping containing wakelock statistics.
590 *
591 * @return a Map from Strings to Uid.Wakelock objects.
592 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700593 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594
595 /**
Ahmed ElArabawyddd09692017-10-30 17:58:29 -0700596 * Returns the WiFi Multicast Wakelock statistics.
597 *
598 * @return a Timer Object for the per uid Multicast statistics.
599 */
600 public abstract Timer getMulticastWakelockStats();
601
602 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700603 * Returns a mapping containing sync statistics.
604 *
605 * @return a Map from Strings to Timer objects.
606 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700607 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700608
609 /**
610 * Returns a mapping containing scheduled job statistics.
611 *
612 * @return a Map from Strings to Timer objects.
613 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700614 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700615
616 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700617 * Returns statistics about how jobs have completed.
618 *
619 * @return A Map of String job names to completion type -> count mapping.
620 */
621 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
622
623 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 * The statistics associated with a particular wake lock.
625 */
626 public static abstract class Wakelock {
627 public abstract Timer getWakeTime(int type);
628 }
629
630 /**
Bookatzc8c44962017-05-11 12:12:54 -0700631 * The cumulative time the uid spent holding any partial wakelocks. This will generally
632 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
633 * wakelocks that overlap in time (and therefore over-counts).
634 */
635 public abstract Timer getAggregatedPartialWakelockTimer();
636
637 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 * Returns a mapping containing sensor statistics.
639 *
640 * @return a Map from Integer sensor ids to Uid.Sensor objects.
641 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700642 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643
644 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700645 * Returns a mapping containing active process data.
646 */
647 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700648
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700649 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 * Returns a mapping containing process statistics.
651 *
652 * @return a Map from Strings to Uid.Proc objects.
653 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700654 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655
656 /**
657 * Returns a mapping containing package statistics.
658 *
659 * @return a Map from Strings to Uid.Pkg objects.
660 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700661 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700662
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800663 public abstract ControllerActivityCounter getWifiControllerActivity();
664 public abstract ControllerActivityCounter getBluetoothControllerActivity();
665 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800666
667 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 * {@hide}
669 */
670 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700671
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800672 public abstract void noteWifiRunningLocked(long elapsedRealtime);
673 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
674 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
675 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
676 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
677 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
678 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
679 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
680 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
681 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800682 public abstract void noteActivityResumedLocked(long elapsedRealtime);
683 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800684 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
685 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
686 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700687 public abstract int getWifiScanCount(int which);
Kweku Adams103351f2017-10-16 14:39:34 -0700688 /**
689 * Returns the timer keeping track of wifi scans.
690 */
691 public abstract Timer getWifiScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800692 public abstract int getWifiScanBackgroundCount(int which);
693 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
694 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -0700695 /**
696 * Returns the timer keeping track of background wifi scans.
697 */
698 public abstract Timer getWifiScanBackgroundTimer();
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800699 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700700 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800701 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700702 public abstract Timer getAudioTurnedOnTimer();
703 public abstract Timer getVideoTurnedOnTimer();
704 public abstract Timer getFlashlightTurnedOnTimer();
705 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700706 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700707
708 /**
709 * Returns the timer keeping track of Foreground Service time
710 */
711 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800712 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800713 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700714 public abstract Timer getBluetoothUnoptimizedScanTimer();
715 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700716 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700717 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700718
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700719 public abstract long[] getCpuFreqTimes(int which);
720 public abstract long[] getScreenOffCpuFreqTimes(int which);
Mike Ma3d422c32017-10-25 11:08:57 -0700721 /**
722 * Returns cpu active time of an uid.
723 */
724 public abstract long getCpuActiveTime();
725 /**
726 * Returns cpu times of an uid on each cluster
727 */
728 public abstract long[] getCpuClusterTimes();
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700729
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800730 /**
731 * Returns cpu times of an uid at a particular process state.
732 */
733 public abstract long[] getCpuFreqTimes(int which, int procState);
734 /**
735 * Returns cpu times of an uid while the screen if off at a particular process state.
736 */
737 public abstract long[] getScreenOffCpuFreqTimes(int which, int procState);
738
Dianne Hackborna0200e32016-03-30 18:01:41 -0700739 // Note: the following times are disjoint. They can be added together to find the
740 // total time a uid has had any processes running at all.
741
742 /**
zhouwenjie46712bc2018-01-11 15:21:27 -0800743 * Time this uid has any processes in the top state.
Dianne Hackborna0200e32016-03-30 18:01:41 -0700744 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800745 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700746 /**
zhouwenjie46712bc2018-01-11 15:21:27 -0800747 * Time this uid has any process with a started foreground service, but
Dianne Hackborna0200e32016-03-30 18:01:41 -0700748 * none in the "top" state.
749 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800750 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700751 /**
Dianne Hackborna0200e32016-03-30 18:01:41 -0700752 * Time this uid has any process in an active foreground state, but none in the
zhouwenjie46712bc2018-01-11 15:21:27 -0800753 * "foreground service" or better state. Persistent and other foreground states go here.
Dianne Hackborna0200e32016-03-30 18:01:41 -0700754 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800755 public static final int PROCESS_STATE_FOREGROUND = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700756 /**
757 * Time this uid has any process in an active background state, but none in the
758 * "foreground" or better state.
759 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800760 public static final int PROCESS_STATE_BACKGROUND = 3;
761 /**
762 * Time this uid has any process that is top while the device is sleeping, but not
763 * active for any other reason. We kind-of consider it a kind of cached process
764 * for execution restrictions.
765 */
766 public static final int PROCESS_STATE_TOP_SLEEPING = 4;
767 /**
768 * Time this uid has any process that is in the background but it has an activity
769 * marked as "can't save state". This is essentially a cached process, though the
770 * system will try much harder than normal to avoid killing it.
771 */
772 public static final int PROCESS_STATE_HEAVY_WEIGHT = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700773 /**
774 * Time this uid has any processes that are sitting around cached, not in one of the
775 * other active states.
776 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800777 public static final int PROCESS_STATE_CACHED = 6;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700778 /**
779 * Total number of process states we track.
780 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800781 public static final int NUM_PROCESS_STATE = 7;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700782
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800783 // Used in dump
Dianne Hackborn61659e52014-07-09 16:13:01 -0700784 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800785 "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight",
786 "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700787 };
788
Sudheer Shankab2f83c12017-11-13 19:25:01 -0800789 // Used in checkin dump
790 @VisibleForTesting
791 public static final String[] UID_PROCESS_TYPES = {
792 "T", // TOP
793 "FS", // FOREGROUND_SERVICE
794 "F", // FOREGROUND
795 "B", // BACKGROUND
796 "TS", // TOP_SLEEPING
797 "HW", // HEAVY_WEIGHT
798 "C" // CACHED
799 };
800
801 /**
802 * When the process exits one of these states, we need to make sure cpu time in this state
803 * is not attributed to any non-critical process states.
804 */
805 public static final int[] CRITICAL_PROC_STATES = {
806 PROCESS_STATE_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND
807 };
808
Dianne Hackborn61659e52014-07-09 16:13:01 -0700809 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800810 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700811
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800812 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813
Robert Greenwalta029ea12013-09-25 16:38:12 -0700814 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
815
Dianne Hackborn617f8772009-03-31 15:04:46 -0700816 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700817 * Note that these must match the constants in android.os.PowerManager.
818 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
819 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700820 */
821 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700822 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700823 };
Bookatzc8c44962017-05-11 12:12:54 -0700824
Phil Weaverda80d672016-03-15 16:25:46 -0700825 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700826
Dianne Hackborn617f8772009-03-31 15:04:46 -0700827 public abstract void noteUserActivityLocked(int type);
828 public abstract boolean hasUserActivity();
829 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700830
831 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800832 public abstract long getNetworkActivityBytes(int type, int which);
833 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800834 public abstract long getMobileRadioActiveTime(int which);
835 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700836
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700837 /**
838 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
839 */
840 public abstract long getUserCpuTimeUs(int which);
841
842 /**
843 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
844 */
845 public abstract long getSystemCpuTimeUs(int which);
846
847 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700848 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700849 * given CPU cluster.
850 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700851 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700852 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700853 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
854 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700855 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700856 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700857
Adam Lesinski5f056f62016-07-14 16:56:08 -0700858 /**
859 * Returns the number of times this UID woke up the Application Processor to
860 * process a mobile radio packet.
861 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
862 */
863 public abstract long getMobileRadioApWakeupCount(int which);
864
865 /**
866 * Returns the number of times this UID woke up the Application Processor to
867 * process a WiFi packet.
868 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
869 */
870 public abstract long getWifiRadioApWakeupCount(int which);
871
Amith Yamasani977e11f2018-02-16 11:29:54 -0800872 /**
873 * Appends the deferred jobs data to the StringBuilder passed in, in checkin format
874 * @param sb StringBuilder that can be overwritten with the deferred jobs data
875 * @param which one of STATS_*
876 */
877 public abstract void getDeferredJobsCheckinLineLocked(StringBuilder sb, int which);
878
879 /**
880 * Appends the deferred jobs data to the StringBuilder passed in
881 * @param sb StringBuilder that can be overwritten with the deferred jobs data
882 * @param which one of STATS_*
883 */
884 public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which);
885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800887 /*
888 * FIXME: it's not correct to use this magic value because it
889 * could clash with a sensor handle (which are defined by
890 * the sensor HAL, and therefore out of our control
891 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 // Magic sensor number for the GPS.
893 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800898
Bookatz867c0d72017-03-07 18:23:42 -0800899 /** Returns a Timer for sensor usage when app is in the background. */
900 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
902
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700903 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800904 public int mWakeNesting;
905 public long mWakeSumMs;
906 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700907 }
908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 /**
910 * The statistics associated with a particular process.
911 */
912 public static abstract class Proc {
913
Dianne Hackborn287952c2010-09-22 22:34:31 -0700914 public static class ExcessivePower {
915 public static final int TYPE_WAKE = 1;
916 public static final int TYPE_CPU = 2;
917
918 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700919 public long overTime;
920 public long usedTime;
921 }
922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800924 * Returns true if this process is still active in the battery stats.
925 */
926 public abstract boolean isActive();
927
928 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700929 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700931 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 */
933 public abstract long getUserTime(int which);
934
935 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700936 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700938 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 */
940 public abstract long getSystemTime(int which);
941
942 /**
943 * Returns the number of times the process has been started.
944 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700945 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 */
947 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700948
949 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800950 * Returns the number of times the process has crashed.
951 *
952 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
953 */
954 public abstract int getNumCrashes(int which);
955
956 /**
957 * Returns the number of times the process has ANRed.
958 *
959 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
960 */
961 public abstract int getNumAnrs(int which);
962
963 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700964 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700965 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700966 * @return foreground cpu time in microseconds
967 */
968 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700969
Dianne Hackborn287952c2010-09-22 22:34:31 -0700970 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700971
Dianne Hackborn287952c2010-09-22 22:34:31 -0700972 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
974
975 /**
976 * The statistics associated with a particular package.
977 */
978 public static abstract class Pkg {
979
980 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700981 * Returns information about all wakeup alarms that have been triggered for this
982 * package. The mapping keys are tag names for the alarms, the counter contains
983 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700985 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986
987 /**
988 * Returns a mapping containing service statistics.
989 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700990 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991
992 /**
993 * The statistics associated with a particular service.
994 */
Joe Onoratoabded112016-02-08 16:49:39 -0800995 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996
997 /**
998 * Returns the amount of time spent started.
999 *
1000 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001001 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 * @return
1003 */
1004 public abstract long getStartTime(long batteryUptime, int which);
1005
1006 /**
1007 * Returns the total number of times startService() has been called.
1008 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001009 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 */
1011 public abstract int getStarts(int which);
1012
1013 /**
1014 * Returns the total number times the service has been launched.
1015 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001016 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 */
1018 public abstract int getLaunches(int which);
1019 }
1020 }
1021 }
1022
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001023 public static final class LevelStepTracker {
1024 public long mLastStepTime = -1;
1025 public int mNumStepDurations;
1026 public final long[] mStepDurations;
1027
1028 public LevelStepTracker(int maxLevelSteps) {
1029 mStepDurations = new long[maxLevelSteps];
1030 }
1031
1032 public LevelStepTracker(int numSteps, long[] steps) {
1033 mNumStepDurations = numSteps;
1034 mStepDurations = new long[numSteps];
1035 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
1036 }
1037
1038 public long getDurationAt(int index) {
1039 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
1040 }
1041
1042 public int getLevelAt(int index) {
1043 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
1044 >> STEP_LEVEL_LEVEL_SHIFT);
1045 }
1046
1047 public int getInitModeAt(int index) {
1048 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
1049 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
1050 }
1051
1052 public int getModModeAt(int index) {
1053 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
1054 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
1055 }
1056
1057 private void appendHex(long val, int topOffset, StringBuilder out) {
1058 boolean hasData = false;
1059 while (topOffset >= 0) {
1060 int digit = (int)( (val>>topOffset) & 0xf );
1061 topOffset -= 4;
1062 if (!hasData && digit == 0) {
1063 continue;
1064 }
1065 hasData = true;
1066 if (digit >= 0 && digit <= 9) {
1067 out.append((char)('0' + digit));
1068 } else {
1069 out.append((char)('a' + digit - 10));
1070 }
1071 }
1072 }
1073
1074 public void encodeEntryAt(int index, StringBuilder out) {
1075 long item = mStepDurations[index];
1076 long duration = item & STEP_LEVEL_TIME_MASK;
1077 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
1078 >> STEP_LEVEL_LEVEL_SHIFT);
1079 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
1080 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
1081 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
1082 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
1083 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
1084 case Display.STATE_OFF: out.append('f'); break;
1085 case Display.STATE_ON: out.append('o'); break;
1086 case Display.STATE_DOZE: out.append('d'); break;
1087 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
1088 }
1089 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
1090 out.append('p');
1091 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001092 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
1093 out.append('i');
1094 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001095 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
1096 case Display.STATE_OFF: out.append('F'); break;
1097 case Display.STATE_ON: out.append('O'); break;
1098 case Display.STATE_DOZE: out.append('D'); break;
1099 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
1100 }
1101 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
1102 out.append('P');
1103 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001104 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
1105 out.append('I');
1106 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001107 out.append('-');
1108 appendHex(level, 4, out);
1109 out.append('-');
1110 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
1111 }
1112
1113 public void decodeEntryAt(int index, String value) {
1114 final int N = value.length();
1115 int i = 0;
1116 char c;
1117 long out = 0;
1118 while (i < N && (c=value.charAt(i)) != '-') {
1119 i++;
1120 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001121 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001122 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001123 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001124 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001125 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001126 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001127 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1128 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1129 break;
1130 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1131 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1132 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001133 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1134 << STEP_LEVEL_INITIAL_MODE_SHIFT);
1135 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001136 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1137 break;
1138 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1139 break;
1140 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
1141 break;
1142 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
1143 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1144 break;
1145 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
1146 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001147 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001148 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
1149 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
1150 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001151 }
1152 }
1153 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001154 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001155 while (i < N && (c=value.charAt(i)) != '-') {
1156 i++;
1157 level <<= 4;
1158 if (c >= '0' && c <= '9') {
1159 level += c - '0';
1160 } else if (c >= 'a' && c <= 'f') {
1161 level += c - 'a' + 10;
1162 } else if (c >= 'A' && c <= 'F') {
1163 level += c - 'A' + 10;
1164 }
1165 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001166 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001167 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1168 long duration = 0;
1169 while (i < N && (c=value.charAt(i)) != '-') {
1170 i++;
1171 duration <<= 4;
1172 if (c >= '0' && c <= '9') {
1173 duration += c - '0';
1174 } else if (c >= 'a' && c <= 'f') {
1175 duration += c - 'a' + 10;
1176 } else if (c >= 'A' && c <= 'F') {
1177 duration += c - 'A' + 10;
1178 }
1179 }
1180 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1181 }
1182
1183 public void init() {
1184 mLastStepTime = -1;
1185 mNumStepDurations = 0;
1186 }
1187
1188 public void clearTime() {
1189 mLastStepTime = -1;
1190 }
1191
1192 public long computeTimePerLevel() {
1193 final long[] steps = mStepDurations;
1194 final int numSteps = mNumStepDurations;
1195
1196 // For now we'll do a simple average across all steps.
1197 if (numSteps <= 0) {
1198 return -1;
1199 }
1200 long total = 0;
1201 for (int i=0; i<numSteps; i++) {
1202 total += steps[i] & STEP_LEVEL_TIME_MASK;
1203 }
1204 return total / numSteps;
1205 /*
1206 long[] buckets = new long[numSteps];
1207 int numBuckets = 0;
1208 int numToAverage = 4;
1209 int i = 0;
1210 while (i < numSteps) {
1211 long totalTime = 0;
1212 int num = 0;
1213 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1214 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1215 num++;
1216 }
1217 buckets[numBuckets] = totalTime / num;
1218 numBuckets++;
1219 numToAverage *= 2;
1220 i += num;
1221 }
1222 if (numBuckets < 1) {
1223 return -1;
1224 }
1225 long averageTime = buckets[numBuckets-1];
1226 for (i=numBuckets-2; i>=0; i--) {
1227 averageTime = (averageTime + buckets[i]) / 2;
1228 }
1229 return averageTime;
1230 */
1231 }
1232
1233 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1234 int[] outNumOfInterest) {
1235 final long[] steps = mStepDurations;
1236 final int count = mNumStepDurations;
1237 if (count <= 0) {
1238 return -1;
1239 }
1240 long total = 0;
1241 int numOfInterest = 0;
1242 for (int i=0; i<count; i++) {
1243 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1244 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1245 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1246 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1247 // If the modes of interest didn't change during this step period...
1248 if ((modMode&modesOfInterest) == 0) {
1249 // And the mode values during this period match those we are measuring...
1250 if ((initMode&modesOfInterest) == modeValues) {
1251 // Then this can be used to estimate the total time!
1252 numOfInterest++;
1253 total += steps[i] & STEP_LEVEL_TIME_MASK;
1254 }
1255 }
1256 }
1257 if (numOfInterest <= 0) {
1258 return -1;
1259 }
1260
1261 if (outNumOfInterest != null) {
1262 outNumOfInterest[0] = numOfInterest;
1263 }
1264
1265 // The estimated time is the average time we spend in each level, multipled
1266 // by 100 -- the total number of battery levels
1267 return (total / numOfInterest) * 100;
1268 }
1269
1270 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1271 int stepCount = mNumStepDurations;
1272 final long lastStepTime = mLastStepTime;
1273 if (lastStepTime >= 0 && numStepLevels > 0) {
1274 final long[] steps = mStepDurations;
1275 long duration = elapsedRealtime - lastStepTime;
1276 for (int i=0; i<numStepLevels; i++) {
1277 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1278 long thisDuration = duration / (numStepLevels-i);
1279 duration -= thisDuration;
1280 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1281 thisDuration = STEP_LEVEL_TIME_MASK;
1282 }
1283 steps[0] = thisDuration | modeBits;
1284 }
1285 stepCount += numStepLevels;
1286 if (stepCount > steps.length) {
1287 stepCount = steps.length;
1288 }
1289 }
1290 mNumStepDurations = stepCount;
1291 mLastStepTime = elapsedRealtime;
1292 }
1293
1294 public void readFromParcel(Parcel in) {
1295 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001296 if (N > mStepDurations.length) {
1297 throw new ParcelFormatException("more step durations than available: " + N);
1298 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001299 mNumStepDurations = N;
1300 for (int i=0; i<N; i++) {
1301 mStepDurations[i] = in.readLong();
1302 }
1303 }
1304
1305 public void writeToParcel(Parcel out) {
1306 final int N = mNumStepDurations;
1307 out.writeInt(N);
1308 for (int i=0; i<N; i++) {
1309 out.writeLong(mStepDurations[i]);
1310 }
1311 }
1312 }
1313
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001314 public static final class PackageChange {
1315 public String mPackageName;
1316 public boolean mUpdate;
Dianne Hackborn3accca02013-09-20 09:32:11 -07001317 public long mVersionCode;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001318 }
1319
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001320 public static final class DailyItem {
1321 public long mStartTime;
1322 public long mEndTime;
1323 public LevelStepTracker mDischargeSteps;
1324 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001325 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001326 }
1327
1328 public abstract DailyItem getDailyItemLocked(int daysAgo);
1329
1330 public abstract long getCurrentDailyStartTime();
1331
1332 public abstract long getNextMinDailyDeadline();
1333
1334 public abstract long getNextMaxDailyDeadline();
1335
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001336 public abstract long[] getCpuFreqs();
1337
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001338 public final static class HistoryTag {
1339 public String string;
1340 public int uid;
1341
1342 public int poolIdx;
1343
1344 public void setTo(HistoryTag o) {
1345 string = o.string;
1346 uid = o.uid;
1347 poolIdx = o.poolIdx;
1348 }
1349
1350 public void setTo(String _string, int _uid) {
1351 string = _string;
1352 uid = _uid;
1353 poolIdx = -1;
1354 }
1355
1356 public void writeToParcel(Parcel dest, int flags) {
1357 dest.writeString(string);
1358 dest.writeInt(uid);
1359 }
1360
1361 public void readFromParcel(Parcel src) {
1362 string = src.readString();
1363 uid = src.readInt();
1364 poolIdx = -1;
1365 }
1366
1367 @Override
1368 public boolean equals(Object o) {
1369 if (this == o) return true;
1370 if (o == null || getClass() != o.getClass()) return false;
1371
1372 HistoryTag that = (HistoryTag) o;
1373
1374 if (uid != that.uid) return false;
1375 if (!string.equals(that.string)) return false;
1376
1377 return true;
1378 }
1379
1380 @Override
1381 public int hashCode() {
1382 int result = string.hashCode();
1383 result = 31 * result + uid;
1384 return result;
1385 }
1386 }
1387
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001388 /**
1389 * Optional detailed information that can go into a history step. This is typically
1390 * generated each time the battery level changes.
1391 */
1392 public final static class HistoryStepDetails {
1393 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1394 public int userTime;
1395 public int systemTime;
1396
1397 // Top three apps using CPU in the last step, with times in 1/100 second.
1398 public int appCpuUid1;
1399 public int appCpuUTime1;
1400 public int appCpuSTime1;
1401 public int appCpuUid2;
1402 public int appCpuUTime2;
1403 public int appCpuSTime2;
1404 public int appCpuUid3;
1405 public int appCpuUTime3;
1406 public int appCpuSTime3;
1407
1408 // Information from /proc/stat
1409 public int statUserTime;
1410 public int statSystemTime;
1411 public int statIOWaitTime;
1412 public int statIrqTime;
1413 public int statSoftIrqTime;
1414 public int statIdlTime;
1415
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001416 // Platform-level low power state stats
1417 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001418 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001419
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001420 public HistoryStepDetails() {
1421 clear();
1422 }
1423
1424 public void clear() {
1425 userTime = systemTime = 0;
1426 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1427 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1428 = appCpuUTime3 = appCpuSTime3 = 0;
1429 }
1430
1431 public void writeToParcel(Parcel out) {
1432 out.writeInt(userTime);
1433 out.writeInt(systemTime);
1434 out.writeInt(appCpuUid1);
1435 out.writeInt(appCpuUTime1);
1436 out.writeInt(appCpuSTime1);
1437 out.writeInt(appCpuUid2);
1438 out.writeInt(appCpuUTime2);
1439 out.writeInt(appCpuSTime2);
1440 out.writeInt(appCpuUid3);
1441 out.writeInt(appCpuUTime3);
1442 out.writeInt(appCpuSTime3);
1443 out.writeInt(statUserTime);
1444 out.writeInt(statSystemTime);
1445 out.writeInt(statIOWaitTime);
1446 out.writeInt(statIrqTime);
1447 out.writeInt(statSoftIrqTime);
1448 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001449 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001450 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001451 }
1452
1453 public void readFromParcel(Parcel in) {
1454 userTime = in.readInt();
1455 systemTime = in.readInt();
1456 appCpuUid1 = in.readInt();
1457 appCpuUTime1 = in.readInt();
1458 appCpuSTime1 = in.readInt();
1459 appCpuUid2 = in.readInt();
1460 appCpuUTime2 = in.readInt();
1461 appCpuSTime2 = in.readInt();
1462 appCpuUid3 = in.readInt();
1463 appCpuUTime3 = in.readInt();
1464 appCpuSTime3 = in.readInt();
1465 statUserTime = in.readInt();
1466 statSystemTime = in.readInt();
1467 statIOWaitTime = in.readInt();
1468 statIrqTime = in.readInt();
1469 statSoftIrqTime = in.readInt();
1470 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001471 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001472 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001473 }
1474 }
1475
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001476 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001477 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001478
1479 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001480 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001481
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001482 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001483 public static final byte CMD_NULL = -1;
1484 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001485 public static final byte CMD_CURRENT_TIME = 5;
1486 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001487 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001488 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001489
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001490 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001491
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001492 /**
1493 * Return whether the command code is a delta data update.
1494 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001495 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001496 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001497 }
1498
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001499 public byte batteryLevel;
1500 public byte batteryStatus;
1501 public byte batteryHealth;
1502 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001503
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001504 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001505 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001506
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001507 // The charge of the battery in micro-Ampere-hours.
1508 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001509
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001510 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001511 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001512 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001513 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001514 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1515 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001516 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001517 public static final int STATE_PHONE_STATE_SHIFT = 6;
1518 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001519 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001520 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001521 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001522
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001523 // These states always appear directly in the first int token
1524 // of a delta change; they should be ones that change relatively
1525 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001526 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1527 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001528 public static final int STATE_GPS_ON_FLAG = 1<<29;
1529 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001530 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001531 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001532 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001533 // Do not use, this is used for coulomb delta count.
1534 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001535 // These are on the lower bits used for the command; if they change
1536 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001537 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001538 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001539 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001540 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1541 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001542 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001543 // empty slot
1544 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001545
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001546 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001547 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001548
1549 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001550
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001551 public int states;
1552
Dianne Hackborn3251b902014-06-20 14:40:53 -07001553 // Constants from WIFI_SUPPL_STATE_*
1554 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1555 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1556 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1557 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1558 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1559 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
Siddharth Ray78ccaf52017-12-23 16:16:21 -08001560 // Values for NUM_GPS_SIGNAL_QUALITY_LEVELS
1561 public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7;
1562 public static final int STATE2_GPS_SIGNAL_QUALITY_MASK =
1563 0x1 << STATE2_GPS_SIGNAL_QUALITY_SHIFT;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001564
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001565 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001566 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1567 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1568 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001569 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001570 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1571 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1572 public static final int STATE2_CHARGING_FLAG = 1<<24;
1573 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1574 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1575 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001576 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Siddharth Rayf5e796a2018-01-22 18:18:17 -08001577 public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001578
1579 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001580 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1581 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001582
1583 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001584
Dianne Hackborn40c87252014-03-19 16:55:40 -07001585 public int states2;
1586
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001587 // The wake lock that was acquired at this point.
1588 public HistoryTag wakelockTag;
1589
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001590 // Kernel wakeup reason at this point.
1591 public HistoryTag wakeReasonTag;
1592
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001593 // Non-null when there is more detailed information at this step.
1594 public HistoryStepDetails stepDetails;
1595
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001596 public static final int EVENT_FLAG_START = 0x8000;
1597 public static final int EVENT_FLAG_FINISH = 0x4000;
1598
1599 // No event in this item.
1600 public static final int EVENT_NONE = 0x0000;
1601 // Event is about a process that is running.
1602 public static final int EVENT_PROC = 0x0001;
1603 // Event is about an application package that is in the foreground.
1604 public static final int EVENT_FOREGROUND = 0x0002;
1605 // Event is about an application package that is at the top of the screen.
1606 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001607 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001608 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001609 // Events for all additional wake locks aquired/release within a wake block.
1610 // These are not generated by default.
1611 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001612 // Event is about an application executing a scheduled job.
1613 public static final int EVENT_JOB = 0x0006;
1614 // Events for users running.
1615 public static final int EVENT_USER_RUNNING = 0x0007;
1616 // Events for foreground user.
1617 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001618 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001619 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001620 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001621 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001622 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001623 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001624 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001625 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001626 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001627 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001628 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001629 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001630 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001631 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001632 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001633 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001634 // Event for a package being on the temporary whitelist.
1635 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001636 // Event for the screen waking up.
1637 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001638 // Event for the UID that woke up the application processor.
1639 // Used for wakeups coming from WiFi, modem, etc.
1640 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001641 // Event for reporting that a specific partial wake lock has been held for a long duration.
1642 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001643
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001644 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001645 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001646 // Mask to extract out only the type part of the event.
1647 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001648
1649 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1650 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1651 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1652 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1653 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1654 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001655 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1656 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001657 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1658 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001659 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1660 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1661 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1662 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1663 public static final int EVENT_USER_FOREGROUND_START =
1664 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1665 public static final int EVENT_USER_FOREGROUND_FINISH =
1666 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001667 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1668 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001669 public static final int EVENT_TEMP_WHITELIST_START =
1670 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1671 public static final int EVENT_TEMP_WHITELIST_FINISH =
1672 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001673 public static final int EVENT_LONG_WAKE_LOCK_START =
1674 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1675 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1676 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001677
1678 // For CMD_EVENT.
1679 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001680 public HistoryTag eventTag;
1681
Dianne Hackborn9a755432014-05-15 17:05:22 -07001682 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001683 public long currentTime;
1684
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001685 // Meta-data when reading.
1686 public int numReadInts;
1687
1688 // Pre-allocated objects.
1689 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001690 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001691 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001692
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001693 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001694 }
Bookatzc8c44962017-05-11 12:12:54 -07001695
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001696 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001697 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001698 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001699 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001700 }
Bookatzc8c44962017-05-11 12:12:54 -07001701
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001702 public int describeContents() {
1703 return 0;
1704 }
1705
1706 public void writeToParcel(Parcel dest, int flags) {
1707 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001708 int bat = (((int)cmd)&0xff)
1709 | ((((int)batteryLevel)<<8)&0xff00)
1710 | ((((int)batteryStatus)<<16)&0xf0000)
1711 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001712 | ((((int)batteryPlugType)<<24)&0xf000000)
1713 | (wakelockTag != null ? 0x10000000 : 0)
1714 | (wakeReasonTag != null ? 0x20000000 : 0)
1715 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001716 dest.writeInt(bat);
1717 bat = (((int)batteryTemperature)&0xffff)
1718 | ((((int)batteryVoltage)<<16)&0xffff0000);
1719 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001720 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001721 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001722 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001723 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001724 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001725 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001726 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001727 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001728 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001729 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001730 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001731 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001732 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001733 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001734 dest.writeLong(currentTime);
1735 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001736 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001737
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001738 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001739 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001740 int bat = src.readInt();
1741 cmd = (byte)(bat&0xff);
1742 batteryLevel = (byte)((bat>>8)&0xff);
1743 batteryStatus = (byte)((bat>>16)&0xf);
1744 batteryHealth = (byte)((bat>>20)&0xf);
1745 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001746 int bat2 = src.readInt();
1747 batteryTemperature = (short)(bat2&0xffff);
1748 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001749 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001750 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001751 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001752 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001753 wakelockTag = localWakelockTag;
1754 wakelockTag.readFromParcel(src);
1755 } else {
1756 wakelockTag = null;
1757 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001758 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001759 wakeReasonTag = localWakeReasonTag;
1760 wakeReasonTag.readFromParcel(src);
1761 } else {
1762 wakeReasonTag = null;
1763 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001764 if ((bat&0x40000000) != 0) {
1765 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001766 eventTag = localEventTag;
1767 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001768 } else {
1769 eventCode = EVENT_NONE;
1770 eventTag = null;
1771 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001772 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001773 currentTime = src.readLong();
1774 } else {
1775 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001776 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001777 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001778 }
1779
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001780 public void clear() {
1781 time = 0;
1782 cmd = CMD_NULL;
1783 batteryLevel = 0;
1784 batteryStatus = 0;
1785 batteryHealth = 0;
1786 batteryPlugType = 0;
1787 batteryTemperature = 0;
1788 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001789 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001790 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001791 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001792 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001793 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001794 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001795 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001796 }
Bookatzc8c44962017-05-11 12:12:54 -07001797
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001798 public void setTo(HistoryItem o) {
1799 time = o.time;
1800 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001801 setToCommon(o);
1802 }
1803
1804 public void setTo(long time, byte cmd, HistoryItem o) {
1805 this.time = time;
1806 this.cmd = cmd;
1807 setToCommon(o);
1808 }
1809
1810 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001811 batteryLevel = o.batteryLevel;
1812 batteryStatus = o.batteryStatus;
1813 batteryHealth = o.batteryHealth;
1814 batteryPlugType = o.batteryPlugType;
1815 batteryTemperature = o.batteryTemperature;
1816 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001817 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001818 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001819 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001820 if (o.wakelockTag != null) {
1821 wakelockTag = localWakelockTag;
1822 wakelockTag.setTo(o.wakelockTag);
1823 } else {
1824 wakelockTag = null;
1825 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001826 if (o.wakeReasonTag != null) {
1827 wakeReasonTag = localWakeReasonTag;
1828 wakeReasonTag.setTo(o.wakeReasonTag);
1829 } else {
1830 wakeReasonTag = null;
1831 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001832 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001833 if (o.eventTag != null) {
1834 eventTag = localEventTag;
1835 eventTag.setTo(o.eventTag);
1836 } else {
1837 eventTag = null;
1838 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001839 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001840 }
1841
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001842 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001843 return batteryLevel == o.batteryLevel
1844 && batteryStatus == o.batteryStatus
1845 && batteryHealth == o.batteryHealth
1846 && batteryPlugType == o.batteryPlugType
1847 && batteryTemperature == o.batteryTemperature
1848 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001849 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001850 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001851 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001852 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001853 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001854
1855 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001856 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001857 return false;
1858 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001859 if (wakelockTag != o.wakelockTag) {
1860 if (wakelockTag == null || o.wakelockTag == null) {
1861 return false;
1862 }
1863 if (!wakelockTag.equals(o.wakelockTag)) {
1864 return false;
1865 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001866 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001867 if (wakeReasonTag != o.wakeReasonTag) {
1868 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1869 return false;
1870 }
1871 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1872 return false;
1873 }
1874 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001875 if (eventTag != o.eventTag) {
1876 if (eventTag == null || o.eventTag == null) {
1877 return false;
1878 }
1879 if (!eventTag.equals(o.eventTag)) {
1880 return false;
1881 }
1882 }
1883 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001884 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001885 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001886
1887 public final static class HistoryEventTracker {
1888 private final HashMap<String, SparseIntArray>[] mActiveEvents
1889 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1890
1891 public boolean updateState(int code, String name, int uid, int poolIdx) {
1892 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1893 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1894 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1895 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001896 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001897 mActiveEvents[idx] = active;
1898 }
1899 SparseIntArray uids = active.get(name);
1900 if (uids == null) {
1901 uids = new SparseIntArray();
1902 active.put(name, uids);
1903 }
1904 if (uids.indexOfKey(uid) >= 0) {
1905 // Already set, nothing to do!
1906 return false;
1907 }
1908 uids.put(uid, poolIdx);
1909 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1910 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1911 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1912 if (active == null) {
1913 // not currently active, nothing to do.
1914 return false;
1915 }
1916 SparseIntArray uids = active.get(name);
1917 if (uids == null) {
1918 // not currently active, nothing to do.
1919 return false;
1920 }
1921 idx = uids.indexOfKey(uid);
1922 if (idx < 0) {
1923 // not currently active, nothing to do.
1924 return false;
1925 }
1926 uids.removeAt(idx);
1927 if (uids.size() <= 0) {
1928 active.remove(name);
1929 }
1930 }
1931 return true;
1932 }
1933
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001934 public void removeEvents(int code) {
1935 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1936 mActiveEvents[idx] = null;
1937 }
1938
Dianne Hackborn37de0982014-05-09 09:32:18 -07001939 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1940 return mActiveEvents[code];
1941 }
1942 }
1943
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001944 public static final class BitDescription {
1945 public final int mask;
1946 public final int shift;
1947 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001948 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001949 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001950 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001951
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001952 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001953 this.mask = mask;
1954 this.shift = -1;
1955 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001956 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001957 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001958 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001959 }
Bookatzc8c44962017-05-11 12:12:54 -07001960
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001961 public BitDescription(int mask, int shift, String name, String shortName,
1962 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001963 this.mask = mask;
1964 this.shift = shift;
1965 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001966 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001967 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001968 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001969 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001970 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001971
Dianne Hackbornfc064132014-06-02 12:42:12 -07001972 /**
1973 * Don't allow any more batching in to the current history event. This
1974 * is called when printing partial histories, so to ensure that the next
1975 * history event will go in to a new batch after what was printed in the
1976 * last partial history.
1977 */
1978 public abstract void commitCurrentHistoryBatchLocked();
1979
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001980 public abstract int getHistoryTotalSize();
1981
1982 public abstract int getHistoryUsedSize();
1983
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001984 public abstract boolean startIteratingHistoryLocked();
1985
Dianne Hackborn099bc622014-01-22 13:39:16 -08001986 public abstract int getHistoryStringPoolSize();
1987
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001988 public abstract int getHistoryStringPoolBytes();
1989
1990 public abstract String getHistoryTagPoolString(int index);
1991
1992 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001993
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001994 public abstract boolean getNextHistoryLocked(HistoryItem out);
1995
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001996 public abstract void finishIteratingHistoryLocked();
1997
1998 public abstract boolean startIteratingOldHistoryLocked();
1999
2000 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
2001
2002 public abstract void finishIteratingOldHistoryLocked();
2003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07002005 * Return the base time offset for the battery history.
2006 */
2007 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07002008
Dianne Hackbornb5e31652010-09-07 12:13:55 -07002009 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 * Returns the number of times the device has been started.
2011 */
2012 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07002013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002015 * 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 -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 getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002021
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002022 /**
2023 * Returns the number of times the screen was turned on.
2024 *
2025 * {@hide}
2026 */
2027 public abstract int getScreenOnCount(int which);
2028
Mike Mac2f518a2017-09-19 16:06:03 -07002029 /**
2030 * Returns the time in microseconds that the screen has been dozing while the device was
2031 * running on battery.
2032 *
2033 * {@hide}
2034 */
2035 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
2036
2037 /**
2038 * Returns the number of times the screen was turned dozing.
2039 *
2040 * {@hide}
2041 */
2042 public abstract int getScreenDozeCount(int which);
2043
Jeff Browne95c3cd2014-05-02 16:59:26 -07002044 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
2045
Dianne Hackborn617f8772009-03-31 15:04:46 -07002046 public static final int SCREEN_BRIGHTNESS_DARK = 0;
2047 public static final int SCREEN_BRIGHTNESS_DIM = 1;
2048 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
2049 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
2050 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07002051
Dianne Hackborn617f8772009-03-31 15:04:46 -07002052 static final String[] SCREEN_BRIGHTNESS_NAMES = {
2053 "dark", "dim", "medium", "light", "bright"
2054 };
Bookatzc8c44962017-05-11 12:12:54 -07002055
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002056 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
2057 "0", "1", "2", "3", "4"
2058 };
2059
Dianne Hackborn617f8772009-03-31 15:04:46 -07002060 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07002061
Dianne Hackborn617f8772009-03-31 15:04:46 -07002062 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002063 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07002064 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07002065 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002066 * {@hide}
2067 */
2068 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002069 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002072 * Returns the {@link Timer} object that tracks the given screen brightness.
2073 *
2074 * {@hide}
2075 */
2076 public abstract Timer getScreenBrightnessTimer(int brightnessBin);
2077
2078 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002079 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002080 * running on battery.
2081 *
2082 * {@hide}
2083 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002084 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002085
2086 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002087 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002088 *
2089 * {@hide}
2090 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002091 public abstract int getPowerSaveModeEnabledCount(int which);
2092
2093 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002094 * Constant for device idle mode: not active.
2095 */
Bookatz8bdae8d2018-01-16 11:24:30 -08002096 public static final int DEVICE_IDLE_MODE_OFF = ServerProtoEnums.DEVICE_IDLE_MODE_OFF; // 0
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002097
2098 /**
2099 * Constant for device idle mode: active in lightweight mode.
2100 */
Bookatz8bdae8d2018-01-16 11:24:30 -08002101 public static final int DEVICE_IDLE_MODE_LIGHT = ServerProtoEnums.DEVICE_IDLE_MODE_LIGHT; // 1
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002102
2103 /**
2104 * Constant for device idle mode: active in full mode.
2105 */
Bookatz8bdae8d2018-01-16 11:24:30 -08002106 public static final int DEVICE_IDLE_MODE_DEEP = ServerProtoEnums.DEVICE_IDLE_MODE_DEEP; // 2
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002107
2108 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002109 * Returns the time in microseconds that device has been in idle mode while
2110 * running on battery.
2111 *
2112 * {@hide}
2113 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002114 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002115
2116 /**
2117 * Returns the number of times that the devie has gone in to idle mode.
2118 *
2119 * {@hide}
2120 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002121 public abstract int getDeviceIdleModeCount(int mode, int which);
2122
2123 /**
2124 * Return the longest duration we spent in a particular device idle mode (fully in the
2125 * mode, not in idle maintenance etc).
2126 */
2127 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002128
2129 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002130 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002131 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002132 * counts all of the time that we consider the device to be idle, whether or not
2133 * it is currently in the actual device idle mode.
2134 *
2135 * {@hide}
2136 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002137 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002138
2139 /**
Bookatz8c6571b2017-10-24 15:04:41 -07002140 * Returns the number of times that the device has started idling.
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002141 *
2142 * {@hide}
2143 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002144 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002145
2146 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002147 * Returns the number of times that connectivity state changed.
2148 *
2149 * {@hide}
2150 */
2151 public abstract int getNumConnectivityChange(int which);
2152
Siddharth Ray78ccaf52017-12-23 16:16:21 -08002153
2154 /**
2155 * Returns the time in microseconds that the phone has been running with
2156 * the given GPS signal quality level
2157 *
2158 * {@hide}
2159 */
2160 public abstract long getGpsSignalQualityTime(int strengthBin,
2161 long elapsedRealtimeUs, int which);
2162
2163 /**
2164 * Returns the GPS battery drain in mA-ms
2165 *
2166 * {@hide}
2167 */
2168 public abstract long getGpsBatteryDrainMaMs();
2169
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002170 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002171 * 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 -08002172 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002173 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 * {@hide}
2175 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002176 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07002177
Dianne Hackborn627bba72009-03-24 22:32:56 -07002178 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002179 * Returns the number of times a phone call was activated.
2180 *
2181 * {@hide}
2182 */
2183 public abstract int getPhoneOnCount(int which);
2184
2185 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002186 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002187 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002188 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002189 * {@hide}
2190 */
2191 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002192 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002193
Dianne Hackborn617f8772009-03-31 15:04:46 -07002194 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002195 * Returns the time in microseconds that the phone has been trying to
2196 * acquire a signal.
2197 *
2198 * {@hide}
2199 */
2200 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002201 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002202
2203 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002204 * Returns the {@link Timer} object that tracks how much the phone has been trying to
2205 * acquire a signal.
2206 *
2207 * {@hide}
2208 */
2209 public abstract Timer getPhoneSignalScanningTimer();
2210
2211 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002212 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002213 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002214 * {@hide}
2215 */
2216 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2217
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002218 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002219 * Return the {@link Timer} object used to track the given signal strength's duration and
2220 * counts.
2221 */
2222 protected abstract Timer getPhoneSignalStrengthTimer(int strengthBin);
2223
2224 /**
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002225 * Returns the time in microseconds that the mobile network has been active
2226 * (in a high power state).
2227 *
2228 * {@hide}
2229 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002230 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002231
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002232 /**
2233 * Returns the number of times that the mobile network has transitioned to the
2234 * active state.
2235 *
2236 * {@hide}
2237 */
2238 public abstract int getMobileRadioActiveCount(int which);
2239
2240 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002241 * Returns the time in microseconds that is the difference between the mobile radio
2242 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2243 * from the radio.
2244 *
2245 * {@hide}
2246 */
2247 public abstract long getMobileRadioActiveAdjustedTime(int which);
2248
2249 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002250 * Returns the time in microseconds that the mobile network has been active
2251 * (in a high power state) but not being able to blame on an app.
2252 *
2253 * {@hide}
2254 */
2255 public abstract long getMobileRadioActiveUnknownTime(int which);
2256
2257 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002258 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002259 *
2260 * {@hide}
2261 */
2262 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002263
Dianne Hackborn627bba72009-03-24 22:32:56 -07002264 public static final int DATA_CONNECTION_NONE = 0;
2265 public static final int DATA_CONNECTION_GPRS = 1;
2266 public static final int DATA_CONNECTION_EDGE = 2;
2267 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002268 public static final int DATA_CONNECTION_CDMA = 4;
2269 public static final int DATA_CONNECTION_EVDO_0 = 5;
2270 public static final int DATA_CONNECTION_EVDO_A = 6;
2271 public static final int DATA_CONNECTION_1xRTT = 7;
2272 public static final int DATA_CONNECTION_HSDPA = 8;
2273 public static final int DATA_CONNECTION_HSUPA = 9;
2274 public static final int DATA_CONNECTION_HSPA = 10;
2275 public static final int DATA_CONNECTION_IDEN = 11;
2276 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002277 public static final int DATA_CONNECTION_LTE = 13;
2278 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002279 public static final int DATA_CONNECTION_HSPAP = 15;
Siddharth Rayc72081d2018-02-13 11:31:54 -08002280 public static final int DATA_CONNECTION_GSM = 16;
2281 public static final int DATA_CONNECTION_TD_SCDMA = 17;
2282 public static final int DATA_CONNECTION_IWLAN = 18;
2283 public static final int DATA_CONNECTION_LTE_CA = 19;
2284 public static final int DATA_CONNECTION_OTHER = 20;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002285
Dianne Hackborn627bba72009-03-24 22:32:56 -07002286 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002287 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002288 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Siddharth Rayc72081d2018-02-13 11:31:54 -08002289 "ehrpd", "hspap", "gsm", "td_scdma", "iwlan", "lte_ca", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002290 };
Bookatzc8c44962017-05-11 12:12:54 -07002291
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002292 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002293
Dianne Hackborn627bba72009-03-24 22:32:56 -07002294 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002295 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002296 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002297 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002298 * {@hide}
2299 */
2300 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002301 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002304 * Returns the number of times the phone has entered the given data
2305 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002306 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002307 * {@hide}
2308 */
2309 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002310
Kweku Adams87b19ec2017-10-09 12:40:03 -07002311 /**
2312 * Returns the {@link Timer} object that tracks the phone's data connection type stats.
2313 */
2314 public abstract Timer getPhoneDataConnectionTimer(int dataType);
2315
Dianne Hackborn3251b902014-06-20 14:40:53 -07002316 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2317 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2318 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2319 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2320 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2321 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2322 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2323 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2324 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2325 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2326 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2327 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2328 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2329
2330 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2331
2332 static final String[] WIFI_SUPPL_STATE_NAMES = {
2333 "invalid", "disconn", "disabled", "inactive", "scanning",
2334 "authenticating", "associating", "associated", "4-way-handshake",
2335 "group-handshake", "completed", "dormant", "uninit"
2336 };
2337
2338 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2339 "inv", "dsc", "dis", "inact", "scan",
2340 "auth", "ascing", "asced", "4-way",
2341 "group", "compl", "dorm", "uninit"
2342 };
2343
Mike Mac2f518a2017-09-19 16:06:03 -07002344 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002345 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002346 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2347 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002348 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002349 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2350 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2351 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002352 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002353 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002354 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002355 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002356 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2357 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002358 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002359 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2360 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2361 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2362 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2363 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2364 new String[] {"in", "out", "emergency", "off"},
2365 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002366 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2367 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2368 SignalStrength.SIGNAL_STRENGTH_NAMES,
2369 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002370 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2371 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2372 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002373 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002374
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002375 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2376 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002377 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002378 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002379 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002380 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002381 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002382 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2383 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2384 new String[] { "off", "light", "full", "???" },
2385 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002386 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2387 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2388 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002389 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2390 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2391 new String[] { "0", "1", "2", "3", "4" },
2392 new String[] { "0", "1", "2", "3", "4" }),
2393 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2394 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2395 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002396 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002397 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Siddharth Rayf5e796a2018-01-22 18:18:17 -08002398 new BitDescription(HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG,
2399 "cellular_high_tx_power", "Chtp"),
Siddharth Ray78ccaf52017-12-23 16:16:21 -08002400 new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK,
2401 HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss",
Siddharth Rayf5e796a2018-01-22 18:18:17 -08002402 new String[] { "poor", "good"}, new String[] { "poor", "good"})
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002403 };
2404
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002405 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002406 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002407 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2408 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002409 };
2410
2411 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002412 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002413 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002414 "Esw", "Ewa", "Elw", "Eec"
2415 };
2416
2417 @FunctionalInterface
2418 public interface IntToString {
2419 String applyAsString(int val);
2420 }
2421
2422 private static final IntToString sUidToString = UserHandle::formatUid;
2423 private static final IntToString sIntToString = Integer::toString;
2424
2425 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2426 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2427 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2428 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2429 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002430 };
2431
Dianne Hackborn617f8772009-03-31 15:04:46 -07002432 /**
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08002433 * Returns total time for WiFi Multicast Wakelock timer.
2434 * Note that this may be different from the sum of per uid timer values.
2435 *
2436 * {@hide}
2437 */
2438 public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which);
2439
2440 /**
2441 * Returns total time for WiFi Multicast Wakelock timer
2442 * Note that this may be different from the sum of per uid timer values.
2443 *
2444 * {@hide}
2445 */
2446 public abstract int getWifiMulticastWakelockCount(int which);
2447
2448 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002449 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002450 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002451 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002452 * {@hide}
2453 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002454 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002455
2456 /**
Siddharth Rayb50a6842017-12-14 15:15:28 -08002457 * Returns the time in microseconds that wifi has been active while the device was
2458 * running on battery.
2459 *
2460 * {@hide}
2461 */
2462 public abstract long getWifiActiveTime(long elapsedRealtimeUs, int which);
2463
2464 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002465 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002466 * been in the running state while the device was running on battery.
2467 *
2468 * {@hide}
2469 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002470 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002471
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002472 public static final int WIFI_STATE_OFF = 0;
2473 public static final int WIFI_STATE_OFF_SCANNING = 1;
2474 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2475 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2476 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2477 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2478 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2479 public static final int WIFI_STATE_SOFT_AP = 7;
2480
2481 static final String[] WIFI_STATE_NAMES = {
2482 "off", "scanning", "no_net", "disconn",
2483 "sta", "p2p", "sta_p2p", "soft_ap"
2484 };
2485
2486 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2487
2488 /**
2489 * Returns the time in microseconds that WiFi has been running in the given state.
2490 *
2491 * {@hide}
2492 */
2493 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002494 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002495
2496 /**
2497 * Returns the number of times that WiFi has entered the given state.
2498 *
2499 * {@hide}
2500 */
2501 public abstract int getWifiStateCount(int wifiState, int which);
2502
The Android Open Source Project10592532009-03-18 17:39:46 -07002503 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002504 * Returns the {@link Timer} object that tracks the given WiFi state.
2505 *
2506 * {@hide}
2507 */
2508 public abstract Timer getWifiStateTimer(int wifiState);
2509
2510 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002511 * Returns the time in microseconds that the wifi supplicant has been
2512 * in a given state.
2513 *
2514 * {@hide}
2515 */
2516 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2517
2518 /**
2519 * Returns the number of times that the wifi supplicant has transitioned
2520 * to a given state.
2521 *
2522 * {@hide}
2523 */
2524 public abstract int getWifiSupplStateCount(int state, int which);
2525
Kweku Adams87b19ec2017-10-09 12:40:03 -07002526 /**
2527 * Returns the {@link Timer} object that tracks the given wifi supplicant state.
2528 *
2529 * {@hide}
2530 */
2531 public abstract Timer getWifiSupplStateTimer(int state);
2532
Dianne Hackborn3251b902014-06-20 14:40:53 -07002533 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2534
2535 /**
2536 * Returns the time in microseconds that WIFI has been running with
2537 * the given signal strength.
2538 *
2539 * {@hide}
2540 */
2541 public abstract long getWifiSignalStrengthTime(int strengthBin,
2542 long elapsedRealtimeUs, int which);
2543
2544 /**
2545 * Returns the number of times WIFI has entered the given signal strength.
2546 *
2547 * {@hide}
2548 */
2549 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2550
2551 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002552 * Returns the {@link Timer} object that tracks the given WIFI signal strength.
2553 *
2554 * {@hide}
2555 */
2556 public abstract Timer getWifiSignalStrengthTimer(int strengthBin);
2557
2558 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002559 * Returns the time in microseconds that the flashlight has been on while the device was
2560 * running on battery.
2561 *
2562 * {@hide}
2563 */
2564 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2565
2566 /**
2567 * Returns the number of times that the flashlight has been turned on while the device was
2568 * running on battery.
2569 *
2570 * {@hide}
2571 */
2572 public abstract long getFlashlightOnCount(int which);
2573
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002574 /**
2575 * Returns the time in microseconds that the camera has been on while the device was
2576 * running on battery.
2577 *
2578 * {@hide}
2579 */
2580 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2581
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002582 /**
2583 * Returns the time in microseconds that bluetooth scans were running while the device was
2584 * on battery.
2585 *
2586 * {@hide}
2587 */
2588 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002589
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002590 public static final int NETWORK_MOBILE_RX_DATA = 0;
2591 public static final int NETWORK_MOBILE_TX_DATA = 1;
2592 public static final int NETWORK_WIFI_RX_DATA = 2;
2593 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002594 public static final int NETWORK_BT_RX_DATA = 4;
2595 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002596 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2597 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2598 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2599 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2600 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002601
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002602 public abstract long getNetworkActivityBytes(int type, int which);
2603 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002604
Adam Lesinskie08af192015-03-25 16:42:59 -07002605 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002606 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002607 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002608 * actual power data.
2609 */
2610 public abstract boolean hasWifiActivityReporting();
2611
2612 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002613 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2614 * in various radio controller states, such as transmit, receive, and idle.
2615 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002616 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002617 public abstract ControllerActivityCounter getWifiControllerActivity();
2618
2619 /**
2620 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2621 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2622 * actual power data.
2623 */
2624 public abstract boolean hasBluetoothActivityReporting();
2625
2626 /**
2627 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2628 * in various radio controller states, such as transmit, receive, and idle.
2629 * @return non-null {@link ControllerActivityCounter}
2630 */
2631 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2632
2633 /**
2634 * Returns true if the BatteryStats object has detailed modem power reports.
2635 * When true, calling {@link #getModemControllerActivity()} will yield the
2636 * actual power data.
2637 */
2638 public abstract boolean hasModemActivityReporting();
2639
2640 /**
2641 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2642 * in various radio controller states, such as transmit, receive, and idle.
2643 * @return non-null {@link ControllerActivityCounter}
2644 */
2645 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002646
The Android Open Source Project10592532009-03-18 17:39:46 -07002647 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002648 * Return the wall clock time when battery stats data collection started.
2649 */
2650 public abstract long getStartClockTime();
2651
2652 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002653 * Return platform version tag that we were running in when the battery stats started.
2654 */
2655 public abstract String getStartPlatformVersion();
2656
2657 /**
2658 * Return platform version tag that we were running in when the battery stats ended.
2659 */
2660 public abstract String getEndPlatformVersion();
2661
2662 /**
2663 * Return the internal version code of the parcelled format.
2664 */
2665 public abstract int getParcelVersion();
2666
2667 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 * Return whether we are currently running on battery.
2669 */
2670 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 /**
2673 * Returns a SparseArray containing the statistics for each uid.
2674 */
2675 public abstract SparseArray<? extends Uid> getUidStats();
2676
2677 /**
2678 * Returns the current battery uptime in microseconds.
2679 *
2680 * @param curTime the amount of elapsed realtime in microseconds.
2681 */
2682 public abstract long getBatteryUptime(long curTime);
2683
2684 /**
2685 * Returns the current battery realtime in microseconds.
2686 *
2687 * @param curTime the amount of elapsed realtime in microseconds.
2688 */
2689 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002690
The Android Open Source Project10592532009-03-18 17:39:46 -07002691 /**
Evan Millar633a1742009-04-02 16:36:33 -07002692 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002693 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002694 */
Evan Millar633a1742009-04-02 16:36:33 -07002695 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002696
The Android Open Source Project10592532009-03-18 17:39:46 -07002697 /**
Evan Millar633a1742009-04-02 16:36:33 -07002698 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2699 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002700 */
Evan Millar633a1742009-04-02 16:36:33 -07002701 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702
2703 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002704 * Get the amount the battery has discharged since the stats were
2705 * last reset after charging, as a lower-end approximation.
2706 */
2707 public abstract int getLowDischargeAmountSinceCharge();
2708
2709 /**
2710 * Get the amount the battery has discharged since the stats were
2711 * last reset after charging, as an upper-end approximation.
2712 */
2713 public abstract int getHighDischargeAmountSinceCharge();
2714
2715 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002716 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2717 */
2718 public abstract int getDischargeAmount(int which);
2719
2720 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002721 * Get the amount the battery has discharged while the screen was on,
2722 * since the last time power was unplugged.
2723 */
2724 public abstract int getDischargeAmountScreenOn();
2725
2726 /**
2727 * Get the amount the battery has discharged while the screen was on,
2728 * since the last time the device was charged.
2729 */
2730 public abstract int getDischargeAmountScreenOnSinceCharge();
2731
2732 /**
2733 * Get the amount the battery has discharged while the screen was off,
2734 * since the last time power was unplugged.
2735 */
2736 public abstract int getDischargeAmountScreenOff();
2737
2738 /**
2739 * Get the amount the battery has discharged while the screen was off,
2740 * since the last time the device was charged.
2741 */
2742 public abstract int getDischargeAmountScreenOffSinceCharge();
2743
2744 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002745 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002746 * since the last time power was unplugged.
2747 */
2748 public abstract int getDischargeAmountScreenDoze();
2749
2750 /**
Kweku Adams87b19ec2017-10-09 12:40:03 -07002751 * Get the amount the battery has discharged while the screen was dozing,
Mike Mac2f518a2017-09-19 16:06:03 -07002752 * since the last time the device was charged.
2753 */
2754 public abstract int getDischargeAmountScreenDozeSinceCharge();
2755
2756 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 * Returns the total, last, or current battery uptime in microseconds.
2758 *
2759 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002760 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 */
2762 public abstract long computeBatteryUptime(long curTime, int which);
2763
2764 /**
2765 * Returns the total, last, or current battery realtime in microseconds.
2766 *
2767 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002768 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002769 */
2770 public abstract long computeBatteryRealtime(long curTime, int which);
2771
2772 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002773 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002774 *
2775 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002776 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002777 */
2778 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2779
2780 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002781 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002782 *
2783 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002784 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002785 */
2786 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2787
2788 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 * Returns the total, last, or current uptime in microseconds.
2790 *
2791 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002792 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 */
2794 public abstract long computeUptime(long curTime, int which);
2795
2796 /**
2797 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002798 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002800 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 */
2802 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002803
2804 /**
2805 * Compute an approximation for how much run time (in microseconds) is remaining on
2806 * the battery. Returns -1 if no time can be computed: either there is not
2807 * enough current data to make a decision, or the battery is currently
2808 * charging.
2809 *
2810 * @param curTime The current elepsed realtime in microseconds.
2811 */
2812 public abstract long computeBatteryTimeRemaining(long curTime);
2813
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002814 // The part of a step duration that is the actual time.
2815 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2816
2817 // Bits in a step duration that are the new battery level we are at.
2818 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002819 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002820
2821 // Bits in a step duration that are the initial mode we were in at that step.
2822 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002823 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002824
2825 // Bits in a step duration that indicate which modes changed during that step.
2826 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002827 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002828
2829 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2830 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2831
Santos Cordone94f0502017-02-24 12:31:20 -08002832 // The largest value for screen state that is tracked in battery states. Any values above
2833 // this should be mapped back to one of the tracked values before being tracked here.
2834 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2835
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002836 // Step duration mode: power save is on.
2837 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2838
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002839 // Step duration mode: device is currently in idle mode.
2840 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2841
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002842 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2843 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002844 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2845 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002846 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2847 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2848 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2849 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2850 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002851 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2852 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002853 };
2854 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2855 (Display.STATE_OFF-1),
2856 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002857 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002858 (Display.STATE_ON-1),
2859 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2860 (Display.STATE_DOZE-1),
2861 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2862 (Display.STATE_DOZE_SUSPEND-1),
2863 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002864 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002865 };
2866 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2867 "screen off",
2868 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002869 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002870 "screen on",
2871 "screen on power save",
2872 "screen doze",
2873 "screen doze power save",
2874 "screen doze-suspend",
2875 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002876 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002877 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002878
2879 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002880 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002881 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2882 * a coulomb counter.
2883 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002884 public abstract long getUahDischargeScreenOff(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002885
2886 /**
2887 * Return the amount of battery discharge while the screen was in doze mode, measured in
2888 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2889 * a coulomb counter.
2890 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002891 public abstract long getUahDischargeScreenDoze(int which);
Mike Mac2f518a2017-09-19 16:06:03 -07002892
2893 /**
2894 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2895 * non-zero only if the device's battery has a coulomb counter.
2896 */
Kweku Adams87b19ec2017-10-09 12:40:03 -07002897 public abstract long getUahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002898
2899 /**
Mike Ma15313c92017-11-15 17:58:21 -08002900 * @return the amount of battery discharge while the device is in light idle mode, measured in
2901 * micro-Ampere-hours.
2902 */
2903 public abstract long getUahDischargeLightDoze(int which);
2904
2905 /**
2906 * @return the amount of battery discharge while the device is in deep idle mode, measured in
2907 * micro-Ampere-hours.
2908 */
2909 public abstract long getUahDischargeDeepDoze(int which);
2910
2911 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002912 * Returns the estimated real battery capacity, which may be less than the capacity
2913 * declared by the PowerProfile.
2914 * @return The estimated battery capacity in mAh.
2915 */
2916 public abstract int getEstimatedBatteryCapacity();
2917
2918 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002919 * @return The minimum learned battery capacity in uAh.
2920 */
2921 public abstract int getMinLearnedBatteryCapacity();
2922
2923 /**
2924 * @return The maximum learned battery capacity in uAh.
2925 */
2926 public abstract int getMaxLearnedBatteryCapacity() ;
2927
2928 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002929 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002930 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002931 public abstract LevelStepTracker getDischargeLevelStepTracker();
2932
2933 /**
2934 * Return the array of daily discharge step durations.
2935 */
2936 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002937
2938 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002939 * Compute an approximation for how much time (in microseconds) remains until the battery
2940 * is fully charged. Returns -1 if no time can be computed: either there is not
2941 * enough current data to make a decision, or the battery is currently
2942 * discharging.
2943 *
2944 * @param curTime The current elepsed realtime in microseconds.
2945 */
2946 public abstract long computeChargeTimeRemaining(long curTime);
2947
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002948 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002949 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002950 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002951 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002952
2953 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002954 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002955 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002956 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002957
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002958 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2959
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002960 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002961
Evan Millarc64edde2009-04-18 12:26:32 -07002962 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963
Bookatz50df7112017-08-04 14:53:26 -07002964 /**
2965 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2966 */
2967 public abstract Map<String, ? extends Timer> getRpmStats();
2968 /**
2969 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2970 */
2971 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2972
2973
James Carr2dd7e5e2016-07-20 18:48:39 -07002974 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2975
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002976 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2977
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002978 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 long days = seconds / (60 * 60 * 24);
2980 if (days != 0) {
2981 out.append(days);
2982 out.append("d ");
2983 }
2984 long used = days * 60 * 60 * 24;
2985
2986 long hours = (seconds - used) / (60 * 60);
2987 if (hours != 0 || used != 0) {
2988 out.append(hours);
2989 out.append("h ");
2990 }
2991 used += hours * 60 * 60;
2992
2993 long mins = (seconds-used) / 60;
2994 if (mins != 0 || used != 0) {
2995 out.append(mins);
2996 out.append("m ");
2997 }
2998 used += mins * 60;
2999
3000 if (seconds != 0 || used != 0) {
3001 out.append(seconds-used);
3002 out.append("s ");
3003 }
3004 }
3005
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003006 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003008 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 sb.append(time - (sec * 1000));
3010 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 }
3012
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003013 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003014 long sec = time / 1000;
3015 formatTimeRaw(sb, sec);
3016 sb.append(time - (sec * 1000));
3017 sb.append("ms");
3018 }
3019
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003020 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003022 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 }
3024 float perc = ((float)num) / ((float)den) * 100;
3025 mFormatBuilder.setLength(0);
3026 mFormatter.format("%.1f%%", perc);
3027 return mFormatBuilder.toString();
3028 }
3029
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003030 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07003031 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07003032
Evan Millar22ac0432009-03-31 11:33:18 -07003033 if (bytes < BYTES_PER_KB) {
3034 return bytes + "B";
3035 } else if (bytes < BYTES_PER_MB) {
3036 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
3037 return mFormatBuilder.toString();
3038 } else if (bytes < BYTES_PER_GB){
3039 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
3040 return mFormatBuilder.toString();
3041 } else {
3042 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
3043 return mFormatBuilder.toString();
3044 }
3045 }
3046
Kweku Adams103351f2017-10-16 14:39:34 -07003047 private static long roundUsToMs(long timeUs) {
3048 return (timeUs + 500) / 1000;
3049 }
3050
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003051 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003052 if (timer != null) {
3053 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003054 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003055 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
3056 return totalTimeMillis;
3057 }
3058 return 0;
3059 }
3060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 /**
3062 *
3063 * @param sb a StringBuilder object.
3064 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003065 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003067 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 * @param linePrefix a String to be prepended to each line of output.
3069 * @return the line prefix
3070 */
3071 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003072 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003075 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003076
Evan Millarc64edde2009-04-18 12:26:32 -07003077 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 if (totalTimeMillis != 0) {
3079 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003080 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08003081 if (name != null) {
3082 sb.append(name);
3083 sb.append(' ');
3084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 sb.append('(');
3086 sb.append(count);
3087 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07003088 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
3089 if (maxDurationMs >= 0) {
3090 sb.append(" max=");
3091 sb.append(maxDurationMs);
3092 }
Bookatz506a8182017-05-01 14:18:42 -07003093 // Put actual time if it is available and different from totalTimeMillis.
3094 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
3095 if (totalDurMs > totalTimeMillis) {
3096 sb.append(" actual=");
3097 sb.append(totalDurMs);
3098 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07003099 if (timer.isRunningLocked()) {
3100 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
3101 if (currentMs >= 0) {
3102 sb.append(" (running for ");
3103 sb.append(currentMs);
3104 sb.append("ms)");
3105 } else {
3106 sb.append(" (running)");
3107 }
3108 }
3109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 return ", ";
3111 }
3112 }
3113 return linePrefix;
3114 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003115
3116 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07003117 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003118 *
3119 * @param pw a PrintWriter object to print to.
3120 * @param sb a StringBuilder object.
3121 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08003122 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003123 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
3124 * @param prefix a String to be prepended to each line of output.
3125 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07003126 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003127 */
3128 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07003129 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003130 if (timer != null) {
3131 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07003132 final long totalTimeMs = (timer.getTotalTimeLocked(
3133 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003134 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003135 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003136 sb.setLength(0);
3137 sb.append(prefix);
3138 sb.append(" ");
3139 sb.append(type);
3140 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07003141 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003142 sb.append("realtime (");
3143 sb.append(count);
3144 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07003145 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
3146 if (maxDurationMs >= 0) {
3147 sb.append(" max=");
3148 sb.append(maxDurationMs);
3149 }
3150 if (timer.isRunningLocked()) {
3151 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
3152 if (currentMs >= 0) {
3153 sb.append(" (running for ");
3154 sb.append(currentMs);
3155 sb.append("ms)");
3156 } else {
3157 sb.append(" (running)");
3158 }
3159 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003160 pw.println(sb.toString());
3161 return true;
3162 }
3163 }
3164 return false;
3165 }
Bookatzc8c44962017-05-11 12:12:54 -07003166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 /**
3168 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07003169 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 * @param sb a StringBuilder object.
3171 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003172 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003174 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 * @param linePrefix a String to be prepended to each line of output.
3176 * @return the line prefix
3177 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003178 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
3179 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 long totalTimeMicros = 0;
3181 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07003182 long max = 0;
3183 long current = 0;
3184 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003186 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07003187 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003188 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
3189 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07003190 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
3192 sb.append(linePrefix);
3193 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
3194 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07003195 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07003197 sb.append(',');
3198 sb.append(current);
3199 sb.append(',');
3200 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07003201 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
3202 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
3203 // totalDuration independent of totalTimeMicros (since they are not pooled).
3204 if (name != null) {
3205 sb.append(',');
3206 sb.append(totalDuration);
3207 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 return ",";
3209 }
Bookatz506a8182017-05-01 14:18:42 -07003210
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003211 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
3212 String type) {
3213 pw.print(BATTERY_STATS_CHECKIN_VERSION);
3214 pw.print(',');
3215 pw.print(uid);
3216 pw.print(',');
3217 pw.print(category);
3218 pw.print(',');
3219 pw.print(type);
3220 }
3221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 /**
3223 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07003224 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 * @param pw the PageWriter to dump log to
3226 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3227 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3228 * @param args type-dependent data arguments
3229 */
Bookatzc8c44962017-05-11 12:12:54 -07003230 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003232 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003233 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003234 pw.print(',');
3235 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003237 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07003239
3240 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003241 * Dump a given timer stat for terse checkin mode.
3242 *
3243 * @param pw the PageWriter to dump log to
3244 * @param uid the UID to log
3245 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
3246 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
3247 * @param timer a {@link Timer} to dump stats for
3248 * @param rawRealtime the current elapsed realtime of the system in microseconds
3249 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3250 */
3251 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
3252 Timer timer, long rawRealtime, int which) {
3253 if (timer != null) {
3254 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003255 final long totalTime = roundUsToMs(timer.getTotalTimeLocked(rawRealtime, which));
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003256 final int count = timer.getCountLocked(which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003257 if (totalTime != 0 || count != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003258 dumpLine(pw, uid, category, type, totalTime, count);
3259 }
3260 }
3261 }
3262
3263 /**
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003264 * Dump a given timer stat to the proto stream.
3265 *
3266 * @param proto the ProtoOutputStream to log to
3267 * @param fieldId type of data, the field to save to (e.g. AggregatedBatteryStats.WAKELOCK)
3268 * @param timer a {@link Timer} to dump stats for
3269 * @param rawRealtimeUs the current elapsed realtime of the system in microseconds
3270 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
3271 */
3272 private static void dumpTimer(ProtoOutputStream proto, long fieldId,
Kweku Adams87b19ec2017-10-09 12:40:03 -07003273 Timer timer, long rawRealtimeUs, int which) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003274 if (timer == null) {
3275 return;
3276 }
3277 // Convert from microseconds to milliseconds with rounding
Kweku Adams103351f2017-10-16 14:39:34 -07003278 final long timeMs = roundUsToMs(timer.getTotalTimeLocked(rawRealtimeUs, which));
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003279 final int count = timer.getCountLocked(which);
Kweku Adams103351f2017-10-16 14:39:34 -07003280 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs / 1000);
3281 final long curDurationMs = timer.getCurrentDurationMsLocked(rawRealtimeUs / 1000);
3282 final long totalDurationMs = timer.getTotalDurationMsLocked(rawRealtimeUs / 1000);
3283 if (timeMs != 0 || count != 0 || maxDurationMs != -1 || curDurationMs != -1
3284 || totalDurationMs != -1) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003285 final long token = proto.start(fieldId);
Kweku Adams103351f2017-10-16 14:39:34 -07003286 proto.write(TimerProto.DURATION_MS, timeMs);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003287 proto.write(TimerProto.COUNT, count);
Kweku Adams103351f2017-10-16 14:39:34 -07003288 // These values will be -1 for timers that don't implement the functionality.
3289 if (maxDurationMs != -1) {
3290 proto.write(TimerProto.MAX_DURATION_MS, maxDurationMs);
3291 }
3292 if (curDurationMs != -1) {
3293 proto.write(TimerProto.CURRENT_DURATION_MS, curDurationMs);
3294 }
3295 if (totalDurationMs != -1) {
3296 proto.write(TimerProto.TOTAL_DURATION_MS, totalDurationMs);
3297 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003298 proto.end(token);
3299 }
3300 }
3301
3302 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003303 * Checks if the ControllerActivityCounter has any data worth dumping.
3304 */
3305 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
3306 if (counter == null) {
3307 return false;
3308 }
3309
3310 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
3311 || counter.getRxTimeCounter().getCountLocked(which) != 0
3312 || counter.getPowerCounter().getCountLocked(which) != 0) {
3313 return true;
3314 }
3315
3316 for (LongCounter c : counter.getTxTimeCounters()) {
3317 if (c.getCountLocked(which) != 0) {
3318 return true;
3319 }
3320 }
3321 return false;
3322 }
3323
3324 /**
3325 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3326 * The order of the arguments in the final check in line is:
3327 *
3328 * idle, rx, power, tx...
3329 *
3330 * where tx... is one or more transmit level times.
3331 */
3332 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3333 String type,
3334 ControllerActivityCounter counter,
3335 int which) {
3336 if (!controllerActivityHasData(counter, which)) {
3337 return;
3338 }
3339
3340 dumpLineHeader(pw, uid, category, type);
3341 pw.print(",");
3342 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3343 pw.print(",");
3344 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3345 pw.print(",");
3346 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3347 for (LongCounter c : counter.getTxTimeCounters()) {
3348 pw.print(",");
3349 pw.print(c.getCountLocked(which));
3350 }
3351 pw.println();
3352 }
3353
Kweku Adams2f73ecd2017-09-27 16:59:19 -07003354 /**
3355 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3356 */
3357 private static void dumpControllerActivityProto(ProtoOutputStream proto, long fieldId,
3358 ControllerActivityCounter counter,
3359 int which) {
3360 if (!controllerActivityHasData(counter, which)) {
3361 return;
3362 }
3363
3364 final long cToken = proto.start(fieldId);
3365
3366 proto.write(ControllerActivityProto.IDLE_DURATION_MS,
3367 counter.getIdleTimeCounter().getCountLocked(which));
3368 proto.write(ControllerActivityProto.RX_DURATION_MS,
3369 counter.getRxTimeCounter().getCountLocked(which));
3370 proto.write(ControllerActivityProto.POWER_MAH,
3371 counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3372
3373 long tToken;
3374 LongCounter[] txCounters = counter.getTxTimeCounters();
3375 for (int i = 0; i < txCounters.length; ++i) {
3376 LongCounter c = txCounters[i];
3377 tToken = proto.start(ControllerActivityProto.TX);
3378 proto.write(ControllerActivityProto.TxLevel.LEVEL, i);
3379 proto.write(ControllerActivityProto.TxLevel.DURATION_MS, c.getCountLocked(which));
3380 proto.end(tToken);
3381 }
3382
3383 proto.end(cToken);
3384 }
3385
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003386 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3387 String prefix, String controllerName,
3388 ControllerActivityCounter counter,
3389 int which) {
3390 if (controllerActivityHasData(counter, which)) {
3391 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3392 }
3393 }
3394
3395 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3396 String controllerName,
3397 ControllerActivityCounter counter, int which) {
3398 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3399 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3400 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003401 // Battery real time
3402 final long totalControllerActivityTimeMs
3403 = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000;
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003404 long totalTxTimeMs = 0;
3405 for (LongCounter txState : counter.getTxTimeCounters()) {
3406 totalTxTimeMs += txState.getCountLocked(which);
3407 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003408 final long sleepTimeMs
3409 = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003410
Siddharth Rayb50a6842017-12-14 15:15:28 -08003411 if (controllerName.equals(WIFI_CONTROLLER_NAME)) {
3412 final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which);
3413 sb.setLength(0);
3414 sb.append(prefix);
3415 sb.append(" ");
3416 sb.append(controllerName);
3417 sb.append(" Scan time: ");
3418 formatTimeMs(sb, scanTimeMs);
3419 sb.append("(");
3420 sb.append(formatRatioLocked(scanTimeMs, totalControllerActivityTimeMs));
3421 sb.append(")");
3422 pw.println(sb.toString());
3423 }
3424
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003425 sb.setLength(0);
3426 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003427 sb.append(" ");
3428 sb.append(controllerName);
3429 sb.append(" Sleep time: ");
3430 formatTimeMs(sb, sleepTimeMs);
3431 sb.append("(");
3432 sb.append(formatRatioLocked(sleepTimeMs, totalControllerActivityTimeMs));
3433 sb.append(")");
3434 pw.println(sb.toString());
3435
3436 sb.setLength(0);
3437 sb.append(prefix);
3438 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003439 sb.append(controllerName);
3440 sb.append(" Idle time: ");
3441 formatTimeMs(sb, idleTimeMs);
3442 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003443 sb.append(formatRatioLocked(idleTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003444 sb.append(")");
3445 pw.println(sb.toString());
3446
3447 sb.setLength(0);
3448 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003449 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003450 sb.append(controllerName);
3451 sb.append(" Rx time: ");
3452 formatTimeMs(sb, rxTimeMs);
3453 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003454 sb.append(formatRatioLocked(rxTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003455 sb.append(")");
3456 pw.println(sb.toString());
3457
3458 sb.setLength(0);
3459 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003460 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003461 sb.append(controllerName);
3462 sb.append(" Tx time: ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003463
Siddharth Ray3c648c42017-10-02 17:30:58 -07003464 String [] powerLevel;
3465 switch(controllerName) {
Siddharth Rayb50a6842017-12-14 15:15:28 -08003466 case CELLULAR_CONTROLLER_NAME:
Siddharth Ray3c648c42017-10-02 17:30:58 -07003467 powerLevel = new String[] {
3468 " less than 0dBm: ",
3469 " 0dBm to 8dBm: ",
3470 " 8dBm to 15dBm: ",
3471 " 15dBm to 20dBm: ",
3472 " above 20dBm: "};
3473 break;
3474 default:
3475 powerLevel = new String[] {"[0]", "[1]", "[2]", "[3]", "[4]"};
3476 break;
3477 }
3478 final int numTxLvls = Math.min(counter.getTxTimeCounters().length, powerLevel.length);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003479 if (numTxLvls > 1) {
Siddharth Ray3c648c42017-10-02 17:30:58 -07003480 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003481 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3482 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3483 sb.setLength(0);
3484 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07003485 sb.append(" ");
3486 sb.append(powerLevel[lvl]);
3487 sb.append(" ");
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003488 formatTimeMs(sb, txLvlTimeMs);
3489 sb.append("(");
Siddharth Ray3c648c42017-10-02 17:30:58 -07003490 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003491 sb.append(")");
3492 pw.println(sb.toString());
3493 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07003494 } else {
3495 final long txLvlTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which);
3496 formatTimeMs(sb, txLvlTimeMs);
3497 sb.append("(");
3498 sb.append(formatRatioLocked(txLvlTimeMs, totalControllerActivityTimeMs));
3499 sb.append(")");
3500 pw.println(sb.toString());
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003501 }
3502
Siddharth Ray3c648c42017-10-02 17:30:58 -07003503 if (powerDrainMaMs > 0) {
3504 sb.setLength(0);
3505 sb.append(prefix);
3506 sb.append(" ");
3507 sb.append(controllerName);
3508 sb.append(" Battery drain: ").append(
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003509 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
Siddharth Ray3c648c42017-10-02 17:30:58 -07003510 sb.append("mAh");
3511 pw.println(sb.toString());
3512 }
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003513 }
3514
3515 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003516 * Temporary for settings.
3517 */
3518 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3519 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3520 }
3521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 /**
3523 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003524 *
Kweku Adams87b19ec2017-10-09 12:40:03 -07003525 * NOTE: all times are expressed in microseconds, unless specified otherwise.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003527 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3528 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 final long rawUptime = SystemClock.uptimeMillis() * 1000;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003530 final long rawRealtimeMs = SystemClock.elapsedRealtime();
3531 final long rawRealtime = rawRealtimeMs * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3534 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003535 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3536 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3537 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 final long totalRealtime = computeRealtime(rawRealtime, which);
3539 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003540 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003541 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003542 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003543 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003544 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3545 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003546 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003547 rawRealtime, which);
3548 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3549 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003550 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003551 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003552 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003553 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Kweku Adams87b19ec2017-10-09 12:40:03 -07003554 final long dischargeCount = getUahDischarge(which);
3555 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
3556 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Ma15313c92017-11-15 17:58:21 -08003557 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
3558 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003559
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003560 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003561
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003562 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003563 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003564
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003565 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003568 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003569 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003570 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003571 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003572 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003573 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003574 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003575 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3576 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003577
Bookatzc8c44962017-05-11 12:12:54 -07003578
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08003579 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003580 long fullWakeLockTimeTotal = 0;
3581 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003582
Evan Millar22ac0432009-03-31 11:33:18 -07003583 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003584 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003585
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003586 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3587 = u.getWakelockStats();
3588 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3589 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003590
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003591 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3592 if (fullWakeTimer != null) {
3593 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3594 which);
3595 }
3596
3597 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3598 if (partialWakeTimer != null) {
3599 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3600 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003601 }
3602 }
3603 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003604
3605 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003606 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3607 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3608 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3609 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3610 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3611 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3612 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3613 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003614 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3615 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003616 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3617 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003618 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3619 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003620
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003621 // Dump Modem controller stats
3622 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3623 getModemControllerActivity(), which);
3624
Adam Lesinskie283d332015-04-16 12:29:25 -07003625 // Dump Wifi controller stats
3626 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3627 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003628 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003629 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003630
3631 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3632 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003633
3634 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003635 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3636 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 // Dump misc stats
3639 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003640 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003641 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003642 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003643 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003644 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003645 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3646 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003647 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003648 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3649 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3650 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3651 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003652 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003653
Dianne Hackborn617f8772009-03-31 15:04:46 -07003654 // Dump screen brightness stats
3655 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3656 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003657 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003658 }
3659 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003660
Dianne Hackborn627bba72009-03-24 22:32:56 -07003661 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003662 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3663 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003664 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003665 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003666 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003667 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003668 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003669 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003670 args[i] = getPhoneSignalStrengthCount(i, which);
3671 }
3672 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003673
Dianne Hackborn627bba72009-03-24 22:32:56 -07003674 // Dump network type stats
3675 args = new Object[NUM_DATA_CONNECTION_TYPES];
3676 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003677 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003678 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003679 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3680 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3681 args[i] = getPhoneDataConnectionCount(i, which);
3682 }
3683 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003684
3685 // Dump wifi state stats
3686 args = new Object[NUM_WIFI_STATES];
3687 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003688 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003689 }
3690 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3691 for (int i=0; i<NUM_WIFI_STATES; i++) {
3692 args[i] = getWifiStateCount(i, which);
3693 }
3694 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3695
Dianne Hackborn3251b902014-06-20 14:40:53 -07003696 // Dump wifi suppl state stats
3697 args = new Object[NUM_WIFI_SUPPL_STATES];
3698 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3699 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3700 }
3701 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3702 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3703 args[i] = getWifiSupplStateCount(i, which);
3704 }
3705 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3706
3707 // Dump wifi signal strength stats
3708 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3709 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3710 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3711 }
3712 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3713 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3714 args[i] = getWifiSignalStrengthCount(i, which);
3715 }
3716 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3717
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003718 // Dump Multicast total stats
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08003719 final long multicastWakeLockTimeTotalMicros =
3720 getWifiMulticastWakelockTime(rawRealtime, which);
3721 final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which);
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07003722 dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA,
3723 multicastWakeLockTimeTotalMicros / 1000,
3724 multicastWakeLockCountTotal);
3725
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003726 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003727 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003728 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003729 }
Bookatzc8c44962017-05-11 12:12:54 -07003730
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003731 if (which == STATS_SINCE_UNPLUGGED) {
3732 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3733 getDischargeStartLevel()-getDischargeCurrentLevel(),
3734 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003735 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003736 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003737 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000,
3738 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003739 } else {
3740 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3741 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003742 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003743 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003744 dischargeCount / 1000, dischargeScreenOffCount / 1000,
Mike Ma15313c92017-11-15 17:58:21 -08003745 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000,
3746 dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003747 }
Bookatzc8c44962017-05-11 12:12:54 -07003748
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003749 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003750 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003751 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003752 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003753 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003754 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003755 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3756 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003757 }
Evan Millarc64edde2009-04-18 12:26:32 -07003758 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003759 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003760 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003761 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3762 // Not doing the regular wake lock formatting to remain compatible
3763 // with the old checkin format.
3764 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3765 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003766 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003767 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003768 }
3769 }
Evan Millarc64edde2009-04-18 12:26:32 -07003770 }
Bookatzc8c44962017-05-11 12:12:54 -07003771
Bookatz50df7112017-08-04 14:53:26 -07003772 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3773 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3774 if (rpmStats.size() > 0) {
3775 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3776 sb.setLength(0);
3777 Timer totalTimer = ent.getValue();
3778 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3779 int count = totalTimer.getCountLocked(which);
3780 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3781 long screenOffTimeMs = screenOffTimer != null
3782 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3783 int screenOffCount = screenOffTimer != null
3784 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003785 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3786 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3787 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3788 screenOffCount);
3789 } else {
3790 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3791 "\"" + ent.getKey() + "\"", timeMs, count);
3792 }
Bookatz50df7112017-08-04 14:53:26 -07003793 }
3794 }
3795
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003796 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003797 helper.create(this);
3798 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003799 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003800 if (sippers != null && sippers.size() > 0) {
3801 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3802 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003803 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003804 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3805 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
Kweku Adams87b19ec2017-10-09 12:40:03 -07003806 int uid = 0;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003807 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003808 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003809 String label;
3810 switch (bs.drainType) {
3811 case IDLE:
3812 label="idle";
3813 break;
3814 case CELL:
3815 label="cell";
3816 break;
3817 case PHONE:
3818 label="phone";
3819 break;
3820 case WIFI:
3821 label="wifi";
3822 break;
3823 case BLUETOOTH:
3824 label="blue";
3825 break;
3826 case SCREEN:
3827 label="scrn";
3828 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003829 case FLASHLIGHT:
3830 label="flashlight";
3831 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003832 case APP:
3833 uid = bs.uidObj.getUid();
3834 label = "uid";
3835 break;
3836 case USER:
3837 uid = UserHandle.getUid(bs.userId, 0);
3838 label = "user";
3839 break;
3840 case UNACCOUNTED:
3841 label = "unacc";
3842 break;
3843 case OVERCOUNTED:
3844 label = "over";
3845 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003846 case CAMERA:
3847 label = "camera";
3848 break;
Kweku Adams87b19ec2017-10-09 12:40:03 -07003849 case MEMORY:
3850 label = "memory";
3851 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003852 default:
3853 label = "???";
3854 }
3855 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003856 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3857 bs.shouldHide ? 1 : 0,
3858 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3859 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003860 }
3861 }
3862
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003863 final long[] cpuFreqs = getCpuFreqs();
3864 if (cpuFreqs != null) {
3865 sb.setLength(0);
3866 for (int i = 0; i < cpuFreqs.length; ++i) {
3867 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3868 }
3869 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3870 }
3871
Kweku Adams87b19ec2017-10-09 12:40:03 -07003872 // Dump stats per UID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 for (int iu = 0; iu < NU; iu++) {
3874 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003875 if (reqUid >= 0 && uid != reqUid) {
3876 continue;
3877 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003878 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003881 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3882 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3883 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3884 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3885 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3886 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3887 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3888 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003889 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003890 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3891 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003892 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003893 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3894 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003895 // Background data transfers
3896 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3897 which);
3898 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3899 which);
3900 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3901 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3902 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3903 which);
3904 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3905 which);
3906 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3907 which);
3908 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3909 which);
3910
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003911 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3912 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003913 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003914 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3915 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3916 || wifiBytesBgTx > 0
3917 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3918 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003919 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3920 wifiBytesRx, wifiBytesTx,
3921 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003922 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003923 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003924 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3925 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3926 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3927 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003928 }
3929
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003930 // Dump modem controller data, per UID.
3931 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3932 u.getModemControllerActivity(), which);
3933
3934 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003935 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3936 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3937 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003938 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3939 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003940 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3941 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3942 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003943 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003944 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003945 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3946 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003947 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3948 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003949 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003950 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003953 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3954 u.getWifiControllerActivity(), which);
3955
Bookatz867c0d72017-03-07 18:23:42 -08003956 final Timer bleTimer = u.getBluetoothScanTimer();
3957 if (bleTimer != null) {
3958 // Convert from microseconds to milliseconds with rounding
3959 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3960 / 1000;
3961 if (totalTime != 0) {
3962 final int count = bleTimer.getCountLocked(which);
3963 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3964 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003965 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3966 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3967 final long actualTimeBg = bleTimerBg != null ?
3968 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003969 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003970 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3971 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003972 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3973 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3974 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3975 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3976 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3977 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3978 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3979 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3980 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3981 final Timer unoptimizedScanTimerBg =
3982 u.getBluetoothUnoptimizedScanBackgroundTimer();
3983 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3984 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3985 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3986 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3987
Bookatz867c0d72017-03-07 18:23:42 -08003988 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003989 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3990 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3991 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003992 }
3993 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003994
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003995 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3996 u.getBluetoothControllerActivity(), which);
3997
Dianne Hackborn617f8772009-03-31 15:04:46 -07003998 if (u.hasUserActivity()) {
3999 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
4000 boolean hasData = false;
4001 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
4002 int val = u.getUserActivityCount(i, which);
4003 args[i] = val;
4004 if (val != 0) hasData = true;
4005 }
4006 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07004007 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004008 }
4009 }
Bookatzc8c44962017-05-11 12:12:54 -07004010
4011 if (u.getAggregatedPartialWakelockTimer() != null) {
4012 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07004013 // Times are since reset (regardless of 'which')
4014 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07004015 final Timer bgTimer = timer.getSubTimer();
4016 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004017 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07004018 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
4019 }
4020
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004021 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
4022 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4023 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4024 String linePrefix = "";
4025 sb.setLength(0);
4026 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
4027 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004028 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4029 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004030 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004031 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
4032 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004033 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
4034 rawRealtime, "w", which, linePrefix);
4035
Kweku Adams103351f2017-10-16 14:39:34 -07004036 // Only log if we had at least one wakelock...
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004037 if (sb.length() > 0) {
4038 String name = wakelocks.keyAt(iw);
4039 if (name.indexOf(',') >= 0) {
4040 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004041 }
Yi Jin02483362017-08-04 11:30:44 -07004042 if (name.indexOf('\n') >= 0) {
4043 name = name.replace('\n', '_');
4044 }
4045 if (name.indexOf('\r') >= 0) {
4046 name = name.replace('\r', '_');
4047 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004048 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004049 }
4050 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004051
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004052 // WiFi Multicast Wakelock Statistics
4053 final Timer mcTimer = u.getMulticastWakelockStats();
4054 if (mcTimer != null) {
4055 final long totalMcWakelockTimeMs =
4056 mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ;
4057 final int countMcWakelock = mcTimer.getCountLocked(which);
4058 if(totalMcWakelockTimeMs > 0) {
4059 dumpLine(pw, uid, category, WIFI_MULTICAST_DATA,
4060 totalMcWakelockTimeMs, countMcWakelock);
4061 }
4062 }
4063
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004064 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4065 for (int isy=syncs.size()-1; isy>=0; isy--) {
4066 final Timer timer = syncs.valueAt(isy);
4067 // Convert from microseconds to milliseconds with rounding
4068 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4069 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004070 final Timer bgTimer = timer.getSubTimer();
4071 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004072 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07004073 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004074 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004075 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07004076 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004077 }
4078 }
4079
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004080 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4081 for (int ij=jobs.size()-1; ij>=0; ij--) {
4082 final Timer timer = jobs.valueAt(ij);
4083 // Convert from microseconds to milliseconds with rounding
4084 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4085 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07004086 final Timer bgTimer = timer.getSubTimer();
4087 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004088 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07004089 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004090 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004091 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07004092 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004093 }
4094 }
4095
Dianne Hackborn94326cb2017-06-28 16:17:20 -07004096 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
4097 for (int ic=completions.size()-1; ic>=0; ic--) {
4098 SparseIntArray types = completions.valueAt(ic);
4099 if (types != null) {
4100 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
4101 "\"" + completions.keyAt(ic) + "\"",
4102 types.get(JobParameters.REASON_CANCELED, 0),
4103 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
4104 types.get(JobParameters.REASON_PREEMPT, 0),
4105 types.get(JobParameters.REASON_TIMEOUT, 0),
4106 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
4107 }
4108 }
4109
Amith Yamasani977e11f2018-02-16 11:29:54 -08004110 // Dump deferred jobs stats
4111 u.getDeferredJobsCheckinLineLocked(sb, which);
4112 if (sb.length() > 0) {
4113 dumpLine(pw, uid, category, JOBS_DEFERRED_DATA, sb.toString());
4114 }
4115
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004116 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
4117 rawRealtime, which);
4118 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
4119 rawRealtime, which);
4120 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
4121 rawRealtime, which);
4122 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
4123 rawRealtime, which);
4124
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004125 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4126 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004127 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004128 final Uid.Sensor se = sensors.valueAt(ise);
4129 final int sensorNumber = sensors.keyAt(ise);
4130 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004131 if (timer != null) {
4132 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004133 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
4134 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07004135 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08004136 final int count = timer.getCountLocked(which);
4137 final Timer bgTimer = se.getSensorBackgroundTime();
4138 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004139 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4140 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
4141 final long bgActualTime = bgTimer != null ?
4142 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4143 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
4144 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 }
4147 }
4148
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004149 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
4150 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004151
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07004152 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
4153 rawRealtime, which);
4154
4155 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004156 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004157
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004158 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07004159 long totalStateTime = 0;
4160 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08004161 final long time = u.getProcessStateTime(ips, rawRealtime, which);
4162 totalStateTime += time;
4163 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07004164 }
4165 if (totalStateTime > 0) {
4166 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
4167 }
4168
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004169 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4170 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07004171 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004172 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07004173 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004174 }
4175
Sudheer Shankaa87245d2017-08-10 12:02:31 -07004176 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
4177 if (cpuFreqs != null) {
4178 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
4179 // If total cpuFreqTimes is null, then we don't need to check for
4180 // screenOffCpuFreqTimes.
4181 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
4182 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004183 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07004184 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004185 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07004186 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
4187 if (screenOffCpuFreqTimeMs != null) {
4188 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
4189 sb.append("," + screenOffCpuFreqTimeMs[i]);
4190 }
4191 } else {
4192 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
4193 sb.append(",0");
4194 }
4195 }
4196 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
4197 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004198 }
Sudheer Shankab2f83c12017-11-13 19:25:01 -08004199
4200 for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) {
4201 final long[] timesMs = u.getCpuFreqTimes(which, procState);
4202 if (timesMs != null && timesMs.length == cpuFreqs.length) {
4203 sb.setLength(0);
4204 for (int i = 0; i < timesMs.length; ++i) {
4205 sb.append((i == 0 ? "" : ",") + timesMs[i]);
4206 }
4207 final long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(
4208 which, procState);
4209 if (screenOffTimesMs != null) {
4210 for (int i = 0; i < screenOffTimesMs.length; ++i) {
4211 sb.append("," + screenOffTimesMs[i]);
4212 }
4213 } else {
4214 for (int i = 0; i < timesMs.length; ++i) {
4215 sb.append(",0");
4216 }
4217 }
4218 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA,
4219 Uid.UID_PROCESS_TYPES[procState], timesMs.length, sb.toString());
4220 }
4221 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004222 }
4223
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004224 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4225 = u.getProcessStats();
4226 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4227 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004228
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004229 final long userMillis = ps.getUserTime(which);
4230 final long systemMillis = ps.getSystemTime(which);
4231 final long foregroundMillis = ps.getForegroundTime(which);
4232 final int starts = ps.getStarts(which);
4233 final int numCrashes = ps.getNumCrashes(which);
4234 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004235
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004236 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
4237 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08004238 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
4239 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 }
4241 }
4242
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004243 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4244 = u.getPackageStats();
4245 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4246 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4247 int wakeups = 0;
4248 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4249 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07004250 int count = alarms.valueAt(iwa).getCountLocked(which);
4251 wakeups += count;
4252 String name = alarms.keyAt(iwa).replace(',', '_');
4253 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004254 }
4255 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4256 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4257 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4258 final long startTime = ss.getStartTime(batteryUptime, which);
4259 final int starts = ss.getStarts(which);
4260 final int launches = ss.getLaunches(which);
4261 if (startTime != 0 || starts != 0 || launches != 0) {
4262 dumpLine(pw, uid, category, APK_DATA,
4263 wakeups, // wakeup alarms
4264 packageStats.keyAt(ipkg), // Apk
4265 serviceStats.keyAt(isvc), // service
4266 startTime / 1000, // time spent started, in ms
4267 starts,
4268 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 }
4270 }
4271 }
4272 }
4273 }
4274
Dianne Hackborn81038902012-11-26 17:04:09 -08004275 static final class TimerEntry {
4276 final String mName;
4277 final int mId;
4278 final BatteryStats.Timer mTimer;
4279 final long mTime;
4280 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
4281 mName = name;
4282 mId = id;
4283 mTimer = timer;
4284 mTime = time;
4285 }
4286 }
4287
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004288 private void printmAh(PrintWriter printer, double power) {
4289 printer.print(BatteryStatsHelper.makemAh(power));
4290 }
4291
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004292 private void printmAh(StringBuilder sb, double power) {
4293 sb.append(BatteryStatsHelper.makemAh(power));
4294 }
4295
Dianne Hackbornd953c532014-08-16 18:17:38 -07004296 /**
4297 * Temporary for settings.
4298 */
4299 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
4300 int reqUid) {
4301 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
4302 }
4303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004305 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07004306 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 final long rawUptime = SystemClock.uptimeMillis() * 1000;
4308 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07004309 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311
4312 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
4313 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
4314 final long totalRealtime = computeRealtime(rawRealtime, which);
4315 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004316 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
4317 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
4318 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004319 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
4320 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07004321 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004322
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004323 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07004324
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004325 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07004326 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327
Adam Lesinskif9b20a92016-06-17 17:30:01 -07004328 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
4329 if (estimatedBatteryCapacity > 0) {
4330 sb.setLength(0);
4331 sb.append(prefix);
4332 sb.append(" Estimated battery capacity: ");
4333 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
4334 sb.append(" mAh");
4335 pw.println(sb.toString());
4336 }
4337
Jocelyn Dangc627d102017-04-14 13:15:14 -07004338 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
4339 if (minLearnedBatteryCapacity > 0) {
4340 sb.setLength(0);
4341 sb.append(prefix);
4342 sb.append(" Min learned battery capacity: ");
4343 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
4344 sb.append(" mAh");
4345 pw.println(sb.toString());
4346 }
4347 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
4348 if (maxLearnedBatteryCapacity > 0) {
4349 sb.setLength(0);
4350 sb.append(prefix);
4351 sb.append(" Max learned battery capacity: ");
4352 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
4353 sb.append(" mAh");
4354 pw.println(sb.toString());
4355 }
4356
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004357 sb.setLength(0);
4358 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004359 sb.append(" Time on battery: ");
4360 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
4361 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
4362 sb.append(") realtime, ");
4363 formatTimeMs(sb, whichBatteryUptime / 1000);
4364 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
4365 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004366 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004367
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004368 sb.setLength(0);
4369 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07004370 sb.append(" Time on battery screen off: ");
4371 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
4372 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
4373 sb.append(") realtime, ");
4374 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
4375 sb.append("(");
4376 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
4377 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004378 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07004379
4380 sb.setLength(0);
4381 sb.append(prefix);
4382 sb.append(" Time on battery screen doze: ");
4383 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
4384 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
4385 sb.append(")");
4386 pw.println(sb.toString());
4387
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004388 sb.setLength(0);
4389 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004390 sb.append(" Total run time: ");
4391 formatTimeMs(sb, totalRealtime / 1000);
4392 sb.append("realtime, ");
4393 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004394 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07004395 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07004396 if (batteryTimeRemaining >= 0) {
4397 sb.setLength(0);
4398 sb.append(prefix);
4399 sb.append(" Battery time remaining: ");
4400 formatTimeMs(sb, batteryTimeRemaining / 1000);
4401 pw.println(sb.toString());
4402 }
4403 if (chargeTimeRemaining >= 0) {
4404 sb.setLength(0);
4405 sb.append(prefix);
4406 sb.append(" Charge time remaining: ");
4407 formatTimeMs(sb, chargeTimeRemaining / 1000);
4408 pw.println(sb.toString());
4409 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004410
Kweku Adams87b19ec2017-10-09 12:40:03 -07004411 final long dischargeCount = getUahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004412 if (dischargeCount >= 0) {
4413 sb.setLength(0);
4414 sb.append(prefix);
4415 sb.append(" Discharge: ");
4416 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
4417 sb.append(" mAh");
4418 pw.println(sb.toString());
4419 }
4420
Kweku Adams87b19ec2017-10-09 12:40:03 -07004421 final long dischargeScreenOffCount = getUahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004422 if (dischargeScreenOffCount >= 0) {
4423 sb.setLength(0);
4424 sb.append(prefix);
4425 sb.append(" Screen off discharge: ");
4426 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
4427 sb.append(" mAh");
4428 pw.println(sb.toString());
4429 }
4430
Kweku Adams87b19ec2017-10-09 12:40:03 -07004431 final long dischargeScreenDozeCount = getUahDischargeScreenDoze(which);
Mike Mac2f518a2017-09-19 16:06:03 -07004432 if (dischargeScreenDozeCount >= 0) {
4433 sb.setLength(0);
4434 sb.append(prefix);
4435 sb.append(" Screen doze discharge: ");
4436 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
4437 sb.append(" mAh");
4438 pw.println(sb.toString());
4439 }
4440
4441 final long dischargeScreenOnCount =
4442 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07004443 if (dischargeScreenOnCount >= 0) {
4444 sb.setLength(0);
4445 sb.append(prefix);
4446 sb.append(" Screen on discharge: ");
4447 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4448 sb.append(" mAh");
4449 pw.println(sb.toString());
4450 }
4451
Mike Ma15313c92017-11-15 17:58:21 -08004452 final long dischargeLightDozeCount = getUahDischargeLightDoze(which);
4453 if (dischargeLightDozeCount >= 0) {
4454 sb.setLength(0);
4455 sb.append(prefix);
4456 sb.append(" Device light doze discharge: ");
4457 sb.append(BatteryStatsHelper.makemAh(dischargeLightDozeCount / 1000.0));
4458 sb.append(" mAh");
4459 pw.println(sb.toString());
4460 }
4461
4462 final long dischargeDeepDozeCount = getUahDischargeDeepDoze(which);
4463 if (dischargeDeepDozeCount >= 0) {
4464 sb.setLength(0);
4465 sb.append(prefix);
4466 sb.append(" Device deep doze discharge: ");
4467 sb.append(BatteryStatsHelper.makemAh(dischargeDeepDozeCount / 1000.0));
4468 sb.append(" mAh");
4469 pw.println(sb.toString());
4470 }
4471
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004472 pw.print(" Start clock time: ");
4473 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4474
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004475 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004476 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004477 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004478 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4479 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004480 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004481 rawRealtime, which);
4482 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4483 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004484 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004485 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004486 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4487 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4488 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004489 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004490 sb.append(prefix);
4491 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4492 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004493 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004494 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4495 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004496 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004497 pw.println(sb.toString());
4498 sb.setLength(0);
4499 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004500 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004501 boolean didOne = false;
4502 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004503 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004504 if (time == 0) {
4505 continue;
4506 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004507 sb.append("\n ");
4508 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004509 didOne = true;
4510 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4511 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004512 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004513 sb.append("(");
4514 sb.append(formatRatioLocked(time, screenOnTime));
4515 sb.append(")");
4516 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004517 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004518 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004519 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004520 sb.setLength(0);
4521 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004522 sb.append(" Power save mode enabled: ");
4523 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004524 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004525 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004526 sb.append(")");
4527 pw.println(sb.toString());
4528 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004529 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004530 sb.setLength(0);
4531 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004532 sb.append(" Device light idling: ");
4533 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004534 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004535 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4536 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004537 sb.append("x");
4538 pw.println(sb.toString());
4539 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004540 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004541 sb.setLength(0);
4542 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004543 sb.append(" Idle mode light time: ");
4544 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004545 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004546 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4547 sb.append(") ");
4548 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004549 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004550 sb.append(" -- longest ");
4551 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4552 pw.println(sb.toString());
4553 }
4554 if (deviceIdlingTime != 0) {
4555 sb.setLength(0);
4556 sb.append(prefix);
4557 sb.append(" Device full idling: ");
4558 formatTimeMs(sb, deviceIdlingTime / 1000);
4559 sb.append("(");
4560 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004561 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004562 sb.append("x");
4563 pw.println(sb.toString());
4564 }
4565 if (deviceIdleModeFullTime != 0) {
4566 sb.setLength(0);
4567 sb.append(prefix);
4568 sb.append(" Idle mode full time: ");
4569 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4570 sb.append("(");
4571 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4572 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004573 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004574 sb.append("x");
4575 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004576 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004577 pw.println(sb.toString());
4578 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004579 if (phoneOnTime != 0) {
4580 sb.setLength(0);
4581 sb.append(prefix);
4582 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4583 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004584 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004585 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004586 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004587 if (connChanges != 0) {
4588 pw.print(prefix);
4589 pw.print(" Connectivity changes: "); pw.println(connChanges);
4590 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004591
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08004592 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004593 long fullWakeLockTimeTotalMicros = 0;
4594 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004595
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004596 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004597
Evan Millar22ac0432009-03-31 11:33:18 -07004598 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004599 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004600
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004601 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4602 = u.getWakelockStats();
4603 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4604 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004605
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004606 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4607 if (fullWakeTimer != null) {
4608 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4609 rawRealtime, which);
4610 }
4611
4612 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4613 if (partialWakeTimer != null) {
4614 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4615 rawRealtime, which);
4616 if (totalTimeMicros > 0) {
4617 if (reqUid < 0) {
4618 // Only show the ordered list of all wake
4619 // locks if the caller is not asking for data
4620 // about a specific uid.
4621 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4622 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004623 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004624 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004625 }
4626 }
4627 }
4628 }
Bookatzc8c44962017-05-11 12:12:54 -07004629
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004630 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4631 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4632 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4633 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4634 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4635 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4636 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4637 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004638 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4639 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004640
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004641 if (fullWakeLockTimeTotalMicros != 0) {
4642 sb.setLength(0);
4643 sb.append(prefix);
4644 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4645 (fullWakeLockTimeTotalMicros + 500) / 1000);
4646 pw.println(sb.toString());
4647 }
4648
4649 if (partialWakeLockTimeTotalMicros != 0) {
4650 sb.setLength(0);
4651 sb.append(prefix);
4652 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4653 (partialWakeLockTimeTotalMicros + 500) / 1000);
4654 pw.println(sb.toString());
4655 }
4656
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08004657 final long multicastWakeLockTimeTotalMicros =
4658 getWifiMulticastWakelockTime(rawRealtime, which);
4659 final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which);
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07004660 if (multicastWakeLockTimeTotalMicros != 0) {
4661 sb.setLength(0);
4662 sb.append(prefix);
4663 sb.append(" Total WiFi Multicast wakelock Count: ");
4664 sb.append(multicastWakeLockCountTotal);
4665 pw.println(sb.toString());
4666
4667 sb.setLength(0);
4668 sb.append(prefix);
4669 sb.append(" Total WiFi Multicast wakelock time: ");
4670 formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000);
4671 pw.println(sb.toString());
4672 }
4673
Siddharth Ray3c648c42017-10-02 17:30:58 -07004674 pw.println("");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004675 pw.print(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004676 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004677 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004678 sb.append(" CONNECTIVITY POWER SUMMARY START");
4679 pw.println(sb.toString());
4680
4681 pw.print(prefix);
4682 sb.setLength(0);
4683 sb.append(prefix);
4684 sb.append(" Logging duration for connectivity statistics: ");
4685 formatTimeMs(sb, whichBatteryRealtime / 1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004686 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004687
4688 sb.setLength(0);
4689 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004690 sb.append(" Cellular Statistics:");
Amith Yamasanif37447b2009-10-08 18:28:01 -07004691 pw.println(sb.toString());
4692
Siddharth Ray3c648c42017-10-02 17:30:58 -07004693 pw.print(prefix);
4694 sb.setLength(0);
4695 sb.append(prefix);
4696 sb.append(" Cellular kernel active time: ");
4697 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
4698 formatTimeMs(sb, mobileActiveTime / 1000);
4699 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4700 sb.append(")");
4701 pw.println(sb.toString());
4702
4703 pw.print(" Cellular data received: "); pw.println(formatBytesLocked(mobileRxTotalBytes));
4704 pw.print(" Cellular data sent: "); pw.println(formatBytesLocked(mobileTxTotalBytes));
4705 pw.print(" Cellular packets received: "); pw.println(mobileRxTotalPackets);
4706 pw.print(" Cellular packets sent: "); pw.println(mobileTxTotalPackets);
4707
Dianne Hackborn627bba72009-03-24 22:32:56 -07004708 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004709 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004710 sb.append(" Cellular Radio Access Technology:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004711 didOne = false;
4712 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004713 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004714 if (time == 0) {
4715 continue;
4716 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004717 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004718 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004719 didOne = true;
4720 sb.append(DATA_CONNECTION_NAMES[i]);
4721 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004722 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004723 sb.append("(");
4724 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004725 sb.append(") ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004726 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004727 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004728 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004729
4730 sb.setLength(0);
4731 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004732 sb.append(" Cellular Rx signal strength (RSRP):");
4733 final String[] cellularRxSignalStrengthDescription = new String[]{
4734 "very poor (less than -128dBm): ",
4735 "poor (-128dBm to -118dBm): ",
4736 "moderate (-118dBm to -108dBm): ",
4737 "good (-108dBm to -98dBm): ",
4738 "great (greater than -98dBm): "};
4739 didOne = false;
4740 final int numCellularRxBins = Math.min(SignalStrength.NUM_SIGNAL_STRENGTH_BINS,
4741 cellularRxSignalStrengthDescription.length);
4742 for (int i=0; i<numCellularRxBins; i++) {
4743 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
4744 if (time == 0) {
4745 continue;
4746 }
4747 sb.append("\n ");
4748 sb.append(prefix);
4749 didOne = true;
4750 sb.append(cellularRxSignalStrengthDescription[i]);
4751 sb.append(" ");
4752 formatTimeMs(sb, time/1000);
4753 sb.append("(");
4754 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4755 sb.append(") ");
4756 }
4757 if (!didOne) sb.append(" (no activity)");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004758 pw.println(sb.toString());
4759
Siddharth Rayb50a6842017-12-14 15:15:28 -08004760 printControllerActivity(pw, sb, prefix, CELLULAR_CONTROLLER_NAME,
Siddharth Ray3c648c42017-10-02 17:30:58 -07004761 getModemControllerActivity(), which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004762
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004763 pw.print(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004764 sb.setLength(0);
4765 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004766 sb.append(" Wifi Statistics:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004767 pw.println(sb.toString());
4768
Siddharth Rayb50a6842017-12-14 15:15:28 -08004769 pw.print(prefix);
4770 sb.setLength(0);
4771 sb.append(prefix);
4772 sb.append(" Wifi kernel active time: ");
4773 final long wifiActiveTime = getWifiActiveTime(rawRealtime, which);
4774 formatTimeMs(sb, wifiActiveTime / 1000);
4775 sb.append("("); sb.append(formatRatioLocked(wifiActiveTime, whichBatteryRealtime));
4776 sb.append(")");
4777 pw.println(sb.toString());
4778
Siddharth Ray3c648c42017-10-02 17:30:58 -07004779 pw.print(" Wifi data received: "); pw.println(formatBytesLocked(wifiRxTotalBytes));
4780 pw.print(" Wifi data sent: "); pw.println(formatBytesLocked(wifiTxTotalBytes));
4781 pw.print(" Wifi packets received: "); pw.println(wifiRxTotalPackets);
4782 pw.print(" Wifi packets sent: "); pw.println(wifiTxTotalPackets);
4783
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004784 sb.setLength(0);
4785 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004786 sb.append(" Wifi states:");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004787 didOne = false;
4788 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004789 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004790 if (time == 0) {
4791 continue;
4792 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004793 sb.append("\n ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004794 didOne = true;
4795 sb.append(WIFI_STATE_NAMES[i]);
4796 sb.append(" ");
4797 formatTimeMs(sb, time/1000);
4798 sb.append("(");
4799 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4800 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004801 }
4802 if (!didOne) sb.append(" (no activity)");
4803 pw.println(sb.toString());
4804
4805 sb.setLength(0);
4806 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004807 sb.append(" Wifi supplicant states:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004808 didOne = false;
4809 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4810 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4811 if (time == 0) {
4812 continue;
4813 }
Siddharth Ray3c648c42017-10-02 17:30:58 -07004814 sb.append("\n ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004815 didOne = true;
4816 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4817 sb.append(" ");
4818 formatTimeMs(sb, time/1000);
4819 sb.append("(");
4820 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4821 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004822 }
4823 if (!didOne) sb.append(" (no activity)");
4824 pw.println(sb.toString());
4825
4826 sb.setLength(0);
4827 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004828 sb.append(" Wifi Rx signal strength (RSSI):");
4829 final String[] wifiRxSignalStrengthDescription = new String[]{
4830 "very poor (less than -88.75dBm): ",
4831 "poor (-88.75 to -77.5dBm): ",
4832 "moderate (-77.5dBm to -66.25dBm): ",
4833 "good (-66.25dBm to -55dBm): ",
4834 "great (greater than -55dBm): "};
Dianne Hackborn3251b902014-06-20 14:40:53 -07004835 didOne = false;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004836 final int numWifiRxBins = Math.min(NUM_WIFI_SIGNAL_STRENGTH_BINS,
4837 wifiRxSignalStrengthDescription.length);
4838 for (int i=0; i<numWifiRxBins; i++) {
Dianne Hackborn3251b902014-06-20 14:40:53 -07004839 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4840 if (time == 0) {
4841 continue;
4842 }
4843 sb.append("\n ");
4844 sb.append(prefix);
4845 didOne = true;
Siddharth Ray3c648c42017-10-02 17:30:58 -07004846 sb.append(" ");
4847 sb.append(wifiRxSignalStrengthDescription[i]);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004848 formatTimeMs(sb, time/1000);
4849 sb.append("(");
4850 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4851 sb.append(") ");
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004852 }
4853 if (!didOne) sb.append(" (no activity)");
4854 pw.println(sb.toString());
4855
Siddharth Rayb50a6842017-12-14 15:15:28 -08004856 printControllerActivity(pw, sb, prefix, WIFI_CONTROLLER_NAME,
4857 getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004858
Adam Lesinski50e47602015-12-04 17:04:54 -08004859 pw.print(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004860 sb.setLength(0);
4861 sb.append(prefix);
Siddharth Ray78ccaf52017-12-23 16:16:21 -08004862 sb.append(" GPS Statistics:");
4863 pw.println(sb.toString());
4864
4865 sb.setLength(0);
4866 sb.append(prefix);
4867 sb.append(" GPS signal quality (Top 4 Average CN0):");
4868 final String[] gpsSignalQualityDescription = new String[]{
4869 "poor (less than 20 dBHz): ",
4870 "good (greater than 20 dBHz): "};
4871 final int numGpsSignalQualityBins = Math.min(GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS,
4872 gpsSignalQualityDescription.length);
4873 for (int i=0; i<numGpsSignalQualityBins; i++) {
4874 final long time = getGpsSignalQualityTime(i, rawRealtime, which);
4875 sb.append("\n ");
4876 sb.append(prefix);
4877 sb.append(" ");
4878 sb.append(gpsSignalQualityDescription[i]);
4879 formatTimeMs(sb, time/1000);
4880 sb.append("(");
4881 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4882 sb.append(") ");
4883 }
4884 pw.println(sb.toString());
4885
4886 final long gpsBatteryDrainMaMs = getGpsBatteryDrainMaMs();
4887 if (gpsBatteryDrainMaMs > 0) {
4888 pw.print(prefix);
4889 sb.setLength(0);
4890 sb.append(prefix);
4891 sb.append(" Battery Drain (mAh): ");
4892 sb.append(Double.toString(((double) gpsBatteryDrainMaMs)/(3600 * 1000)));
4893 pw.println(sb.toString());
4894 }
4895
4896 pw.print(prefix);
4897 sb.setLength(0);
4898 sb.append(prefix);
Siddharth Ray3c648c42017-10-02 17:30:58 -07004899 sb.append(" CONNECTIVITY POWER SUMMARY END");
4900 pw.println(sb.toString());
4901 pw.println("");
4902
4903 pw.print(prefix);
Adam Lesinski50e47602015-12-04 17:04:54 -08004904 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4905 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4906
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004907 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4908 sb.setLength(0);
4909 sb.append(prefix);
4910 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4911 pw.println(sb.toString());
4912
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004913 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4914 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004915
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004916 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004917
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004918 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004919 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004920 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004921 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004922 pw.println(getDischargeStartLevel());
4923 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4924 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004925 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004926 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004927 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004928 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004929 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004930 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004931 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004932 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004933 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004934 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004935 pw.println(getDischargeAmountScreenOff());
4936 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4937 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004938 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004939 } else {
4940 pw.print(prefix); pw.println(" Device battery use since last full charge");
4941 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004942 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004943 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004944 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004945 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004946 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004947 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004948 pw.println(getDischargeAmountScreenOffSinceCharge());
4949 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4950 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004951 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004952 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004953
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004954 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004955 helper.create(this);
4956 helper.refreshStats(which, UserHandle.USER_ALL);
4957 List<BatterySipper> sippers = helper.getUsageList();
4958 if (sippers != null && sippers.size() > 0) {
4959 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4960 pw.print(prefix); pw.print(" Capacity: ");
4961 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004962 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004963 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4964 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4965 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4966 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004967 pw.println();
4968 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004969 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004970 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004971 switch (bs.drainType) {
4972 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004973 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004974 break;
4975 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004976 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004977 break;
4978 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004979 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004980 break;
4981 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004982 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004983 break;
4984 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004985 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004986 break;
4987 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004988 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004989 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004990 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004991 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004992 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004993 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004994 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004995 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004996 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004997 break;
4998 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004999 pw.print(" User "); pw.print(bs.userId);
5000 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005001 break;
5002 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005003 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005004 break;
5005 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005006 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005007 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07005008 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005009 pw.print(" Camera: ");
5010 break;
5011 default:
5012 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07005013 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005014 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005015 printmAh(pw, bs.totalPowerMah);
5016
Adam Lesinski57123002015-06-12 16:12:07 -07005017 if (bs.usagePowerMah != bs.totalPowerMah) {
5018 // If the usage (generic power) isn't the whole amount, we list out
5019 // what components are involved in the calculation.
5020
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005021 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07005022 if (bs.usagePowerMah != 0) {
5023 pw.print(" usage=");
5024 printmAh(pw, bs.usagePowerMah);
5025 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005026 if (bs.cpuPowerMah != 0) {
5027 pw.print(" cpu=");
5028 printmAh(pw, bs.cpuPowerMah);
5029 }
5030 if (bs.wakeLockPowerMah != 0) {
5031 pw.print(" wake=");
5032 printmAh(pw, bs.wakeLockPowerMah);
5033 }
5034 if (bs.mobileRadioPowerMah != 0) {
5035 pw.print(" radio=");
5036 printmAh(pw, bs.mobileRadioPowerMah);
5037 }
5038 if (bs.wifiPowerMah != 0) {
5039 pw.print(" wifi=");
5040 printmAh(pw, bs.wifiPowerMah);
5041 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005042 if (bs.bluetoothPowerMah != 0) {
5043 pw.print(" bt=");
5044 printmAh(pw, bs.bluetoothPowerMah);
5045 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005046 if (bs.gpsPowerMah != 0) {
5047 pw.print(" gps=");
5048 printmAh(pw, bs.gpsPowerMah);
5049 }
5050 if (bs.sensorPowerMah != 0) {
5051 pw.print(" sensor=");
5052 printmAh(pw, bs.sensorPowerMah);
5053 }
5054 if (bs.cameraPowerMah != 0) {
5055 pw.print(" camera=");
5056 printmAh(pw, bs.cameraPowerMah);
5057 }
5058 if (bs.flashlightPowerMah != 0) {
5059 pw.print(" flash=");
5060 printmAh(pw, bs.flashlightPowerMah);
5061 }
5062 pw.print(" )");
5063 }
Bookatz17d7d9d2017-06-08 14:50:46 -07005064
5065 // If there is additional smearing information, include it.
5066 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
5067 pw.print(" Including smearing: ");
5068 printmAh(pw, bs.totalSmearedPowerMah);
5069 pw.print(" (");
5070 if (bs.screenPowerMah != 0) {
5071 pw.print(" screen=");
5072 printmAh(pw, bs.screenPowerMah);
5073 }
5074 if (bs.proportionalSmearMah != 0) {
5075 pw.print(" proportional=");
5076 printmAh(pw, bs.proportionalSmearMah);
5077 }
5078 pw.print(" )");
5079 }
5080 if (bs.shouldHide) {
5081 pw.print(" Excluded from smearing");
5082 }
5083
Adam Lesinski628ef9c2015-06-10 13:08:57 -07005084 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005085 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08005086 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08005087 }
5088
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005089 sippers = helper.getMobilemsppList();
5090 if (sippers != null && sippers.size() > 0) {
5091 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08005092 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005093 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005094 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005095 sb.setLength(0);
5096 sb.append(prefix); sb.append(" Uid ");
5097 UserHandle.formatUid(sb, bs.uidObj.getUid());
5098 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
5099 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
5100 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08005101 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005102 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08005103 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005104 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08005105 sb.setLength(0);
5106 sb.append(prefix);
5107 sb.append(" TOTAL TIME: ");
5108 formatTimeMs(sb, totalTime);
5109 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
5110 sb.append(")");
5111 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005112 pw.println();
5113 }
5114
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005115 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
5116 @Override
5117 public int compare(TimerEntry lhs, TimerEntry rhs) {
5118 long lhsTime = lhs.mTime;
5119 long rhsTime = rhs.mTime;
5120 if (lhsTime < rhsTime) {
5121 return 1;
5122 }
5123 if (lhsTime > rhsTime) {
5124 return -1;
5125 }
5126 return 0;
5127 }
5128 };
5129
5130 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005131 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
5132 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005133 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005134 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
5135 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
5136 : kernelWakelocks.entrySet()) {
5137 final BatteryStats.Timer timer = ent.getValue();
5138 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005139 if (totalTimeMillis > 0) {
5140 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
5141 }
5142 }
5143 if (ktimers.size() > 0) {
5144 Collections.sort(ktimers, timerComparator);
5145 pw.print(prefix); pw.println(" All kernel wake locks:");
5146 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005147 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005148 String linePrefix = ": ";
5149 sb.setLength(0);
5150 sb.append(prefix);
5151 sb.append(" Kernel Wake lock ");
5152 sb.append(timer.mName);
5153 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
5154 which, linePrefix);
5155 if (!linePrefix.equals(": ")) {
5156 sb.append(" realtime");
5157 // Only print out wake locks that were held
5158 pw.println(sb.toString());
5159 }
5160 }
5161 pw.println();
5162 }
5163 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005164
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005165 if (timers.size() > 0) {
5166 Collections.sort(timers, timerComparator);
5167 pw.print(prefix); pw.println(" All partial wake locks:");
5168 for (int i=0; i<timers.size(); i++) {
5169 TimerEntry timer = timers.get(i);
5170 sb.setLength(0);
5171 sb.append(" Wake lock ");
5172 UserHandle.formatUid(sb, timer.mId);
5173 sb.append(" ");
5174 sb.append(timer.mName);
5175 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
5176 sb.append(" realtime");
5177 pw.println(sb.toString());
5178 }
5179 timers.clear();
5180 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08005181 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005182
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005183 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005184 if (wakeupReasons.size() > 0) {
5185 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005186 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07005187 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005188 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07005189 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
5190 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005191 }
5192 Collections.sort(reasons, timerComparator);
5193 for (int i=0; i<reasons.size(); i++) {
5194 TimerEntry timer = reasons.get(i);
5195 String linePrefix = ": ";
5196 sb.setLength(0);
5197 sb.append(prefix);
5198 sb.append(" Wakeup reason ");
5199 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07005200 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
5201 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005202 pw.println(sb.toString());
5203 }
5204 pw.println();
5205 }
Dianne Hackborn81038902012-11-26 17:04:09 -08005206 }
Evan Millar22ac0432009-03-31 11:33:18 -07005207
James Carr2dd7e5e2016-07-20 18:48:39 -07005208 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07005209 if (mMemoryStats.size() > 0) {
5210 pw.println(" Memory Stats");
5211 for (int i = 0; i < mMemoryStats.size(); i++) {
5212 sb.setLength(0);
5213 sb.append(" Bandwidth ");
5214 sb.append(mMemoryStats.keyAt(i));
5215 sb.append(" Time ");
5216 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
5217 pw.println(sb.toString());
5218 }
5219 pw.println();
5220 }
5221
5222 final Map<String, ? extends Timer> rpmStats = getRpmStats();
5223 if (rpmStats.size() > 0) {
5224 pw.print(prefix); pw.println(" Resource Power Manager Stats");
5225 if (rpmStats.size() > 0) {
5226 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
5227 final String timerName = ent.getKey();
5228 final Timer timer = ent.getValue();
5229 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
5230 }
5231 }
5232 pw.println();
5233 }
Bookatz82b341172017-09-07 19:06:08 -07005234 if (SCREEN_OFF_RPM_STATS_ENABLED) {
5235 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07005236 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07005237 pw.print(prefix);
5238 pw.println(" Resource Power Manager Stats for when screen was off");
5239 if (screenOffRpmStats.size() > 0) {
5240 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
5241 final String timerName = ent.getKey();
5242 final Timer timer = ent.getValue();
5243 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
5244 }
Bookatz50df7112017-08-04 14:53:26 -07005245 }
Bookatz82b341172017-09-07 19:06:08 -07005246 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07005247 }
James Carr2dd7e5e2016-07-20 18:48:39 -07005248 }
5249
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005250 final long[] cpuFreqs = getCpuFreqs();
5251 if (cpuFreqs != null) {
5252 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07005253 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005254 for (int i = 0; i < cpuFreqs.length; ++i) {
5255 sb.append(" " + cpuFreqs[i]);
5256 }
5257 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07005258 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005259 }
5260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005261 for (int iu=0; iu<NU; iu++) {
5262 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005263 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08005264 continue;
5265 }
Bookatzc8c44962017-05-11 12:12:54 -07005266
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005267 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07005268
5269 pw.print(prefix);
5270 pw.print(" ");
5271 UserHandle.formatUid(pw, uid);
5272 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005274
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005275 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
5276 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
5277 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
5278 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005279 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
5280 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
5281
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005282 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
5283 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005284 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
5285 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08005286
5287 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
5288 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
5289
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005290 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
5291 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
5292 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08005293 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
5294 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5295 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
5296 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005297 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005298
Adam Lesinski5f056f62016-07-14 16:56:08 -07005299 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
5300 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
5301
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005302 if (mobileRxBytes > 0 || mobileTxBytes > 0
5303 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005304 pw.print(prefix); pw.print(" Mobile network: ");
5305 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005306 pw.print(formatBytesLocked(mobileTxBytes));
5307 pw.print(" sent (packets "); pw.print(mobileRxPackets);
5308 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005310 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
5311 sb.setLength(0);
5312 sb.append(prefix); sb.append(" Mobile radio active: ");
5313 formatTimeMs(sb, uidMobileActiveTime / 1000);
5314 sb.append("(");
5315 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
5316 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
5317 long packets = mobileRxPackets + mobileTxPackets;
5318 if (packets == 0) {
5319 packets = 1;
5320 }
5321 sb.append(" @ ");
5322 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
5323 sb.append(" mspp");
5324 pw.println(sb.toString());
5325 }
5326
Adam Lesinski5f056f62016-07-14 16:56:08 -07005327 if (mobileWakeup > 0) {
5328 sb.setLength(0);
5329 sb.append(prefix);
5330 sb.append(" Mobile radio AP wakeups: ");
5331 sb.append(mobileWakeup);
5332 pw.println(sb.toString());
5333 }
5334
Siddharth Rayb50a6842017-12-14 15:15:28 -08005335 printControllerActivityIfInteresting(pw, sb, prefix + " ",
5336 CELLULAR_CONTROLLER_NAME, u.getModemControllerActivity(), which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005337
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005338 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005339 pw.print(prefix); pw.print(" Wi-Fi network: ");
5340 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005341 pw.print(formatBytesLocked(wifiTxBytes));
5342 pw.print(" sent (packets "); pw.print(wifiRxPackets);
5343 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07005344 }
5345
Dianne Hackborn62793e42015-03-09 11:15:41 -07005346 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08005347 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005348 || uidWifiRunningTime != 0) {
5349 sb.setLength(0);
5350 sb.append(prefix); sb.append(" Wifi Running: ");
5351 formatTimeMs(sb, uidWifiRunningTime / 1000);
5352 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
5353 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07005354 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005355 formatTimeMs(sb, fullWifiLockOnTime / 1000);
5356 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
5357 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08005358 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005359 formatTimeMs(sb, wifiScanTime / 1000);
5360 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07005361 whichBatteryRealtime)); sb.append(") ");
5362 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08005363 sb.append("x\n");
5364 // actual and background times are unpooled and since reset (regardless of 'which')
5365 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
5366 formatTimeMs(sb, wifiScanActualTime / 1000);
5367 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
5368 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5369 sb.append(") ");
5370 sb.append(wifiScanCount);
5371 sb.append("x\n");
5372 sb.append(prefix); sb.append(" Background Wifi Scan: ");
5373 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
5374 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
5375 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
5376 sb.append(") ");
5377 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07005378 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08005379 pw.println(sb.toString());
5380 }
5381
Adam Lesinski5f056f62016-07-14 16:56:08 -07005382 if (wifiWakeup > 0) {
5383 sb.setLength(0);
5384 sb.append(prefix);
5385 sb.append(" WiFi AP wakeups: ");
5386 sb.append(wifiWakeup);
5387 pw.println(sb.toString());
5388 }
5389
Siddharth Rayb50a6842017-12-14 15:15:28 -08005390 printControllerActivityIfInteresting(pw, sb, prefix + " ", WIFI_CONTROLLER_NAME,
Adam Lesinski21f76aa2016-01-25 12:27:06 -08005391 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07005392
Adam Lesinski50e47602015-12-04 17:04:54 -08005393 if (btRxBytes > 0 || btTxBytes > 0) {
5394 pw.print(prefix); pw.print(" Bluetooth network: ");
5395 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
5396 pw.print(formatBytesLocked(btTxBytes));
5397 pw.println(" sent");
5398 }
5399
Bookatz867c0d72017-03-07 18:23:42 -08005400 final Timer bleTimer = u.getBluetoothScanTimer();
5401 if (bleTimer != null) {
5402 // Convert from microseconds to milliseconds with rounding
5403 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
5404 / 1000;
5405 if (totalTimeMs != 0) {
5406 final int count = bleTimer.getCountLocked(which);
5407 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
5408 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005409 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5410 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
5411 final long actualTimeMsBg = bleTimerBg != null ?
5412 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005413 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07005414 final int resultCount = u.getBluetoothScanResultCounter() != null ?
5415 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07005416 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
5417 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
5418 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
5419 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
5420 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
5421 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5422 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
5423 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
5424 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
5425 final Timer unoptimizedScanTimerBg =
5426 u.getBluetoothUnoptimizedScanBackgroundTimer();
5427 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
5428 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5429 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
5430 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005431
5432 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08005433 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07005434 sb.append(prefix);
5435 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08005436 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07005437 sb.append(" (");
5438 sb.append(count);
5439 sb.append(" times)");
5440 if (bleTimer.isRunningLocked()) {
5441 sb.append(" (currently running)");
5442 }
5443 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005444 }
Bookatzb1f04f32017-05-19 13:57:32 -07005445
5446 sb.append(prefix);
5447 sb.append(" Bluetooth Scan (total actual realtime): ");
5448 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
5449 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005450 sb.append(count);
5451 sb.append(" times)");
5452 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07005453 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08005454 }
Bookatzb1f04f32017-05-19 13:57:32 -07005455 sb.append("\n");
5456 if (actualTimeMsBg > 0 || countBg > 0) {
5457 sb.append(prefix);
5458 sb.append(" Bluetooth Scan (background realtime): ");
5459 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
5460 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08005461 sb.append(countBg);
5462 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07005463 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
5464 sb.append(" (currently running in background)");
5465 }
5466 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08005467 }
Bookatzb1f04f32017-05-19 13:57:32 -07005468
5469 sb.append(prefix);
5470 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07005471 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07005472 sb.append(" (");
5473 sb.append(resultCountBg);
5474 sb.append(" in background)");
5475
5476 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
5477 sb.append("\n");
5478 sb.append(prefix);
5479 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
5480 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
5481 sb.append(" (max ");
5482 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
5483 sb.append(")");
5484 if (unoptimizedScanTimer != null
5485 && unoptimizedScanTimer.isRunningLocked()) {
5486 sb.append(" (currently running unoptimized)");
5487 }
5488 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
5489 sb.append("\n");
5490 sb.append(prefix);
5491 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
5492 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
5493 sb.append(" (max ");
5494 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
5495 sb.append(")");
5496 if (unoptimizedScanTimerBg.isRunningLocked()) {
5497 sb.append(" (currently running unoptimized in background)");
5498 }
5499 }
5500 }
Bookatz867c0d72017-03-07 18:23:42 -08005501 pw.println(sb.toString());
5502 uidActivity = true;
5503 }
5504 }
5505
5506
Adam Lesinski9f55cc72016-01-27 20:42:14 -08005507
Dianne Hackborn617f8772009-03-31 15:04:46 -07005508 if (u.hasUserActivity()) {
5509 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07005510 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005511 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07005512 if (val != 0) {
5513 if (!hasData) {
5514 sb.setLength(0);
5515 sb.append(" User activity: ");
5516 hasData = true;
5517 } else {
5518 sb.append(", ");
5519 }
5520 sb.append(val);
5521 sb.append(" ");
5522 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
5523 }
5524 }
5525 if (hasData) {
5526 pw.println(sb.toString());
5527 }
5528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005529
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005530 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5531 = u.getWakelockStats();
5532 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005533 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005534 int countWakelock = 0;
5535 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5536 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5537 String linePrefix = ": ";
5538 sb.setLength(0);
5539 sb.append(prefix);
5540 sb.append(" Wake lock ");
5541 sb.append(wakelocks.keyAt(iw));
5542 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5543 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005544 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5545 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005546 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005547 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5548 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005549 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5550 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005551 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5552 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005553 sb.append(" realtime");
5554 pw.println(sb.toString());
5555 uidActivity = true;
5556 countWakelock++;
5557
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005558 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5559 rawRealtime, which);
5560 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5561 rawRealtime, which);
5562 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5563 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005564 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005565 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005566 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005567 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005568 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5569 // pooled and therefore just a lower bound)
5570 long actualTotalPartialWakelock = 0;
5571 long actualBgPartialWakelock = 0;
5572 if (u.getAggregatedPartialWakelockTimer() != null) {
5573 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5574 // Convert from microseconds to milliseconds with rounding
5575 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005576 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005577 final Timer bgAggTimer = aggTimer.getSubTimer();
5578 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005579 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005580 }
5581
5582 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5583 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5584 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005585 sb.setLength(0);
5586 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005587 sb.append(" TOTAL wake: ");
5588 boolean needComma = false;
5589 if (totalFullWakelock != 0) {
5590 needComma = true;
5591 formatTimeMs(sb, totalFullWakelock);
5592 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005593 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005594 if (totalPartialWakelock != 0) {
5595 if (needComma) {
5596 sb.append(", ");
5597 }
5598 needComma = true;
5599 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005600 sb.append("blamed partial");
5601 }
5602 if (actualTotalPartialWakelock != 0) {
5603 if (needComma) {
5604 sb.append(", ");
5605 }
5606 needComma = true;
5607 formatTimeMs(sb, actualTotalPartialWakelock);
5608 sb.append("actual partial");
5609 }
5610 if (actualBgPartialWakelock != 0) {
5611 if (needComma) {
5612 sb.append(", ");
5613 }
5614 needComma = true;
5615 formatTimeMs(sb, actualBgPartialWakelock);
5616 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005617 }
5618 if (totalWindowWakelock != 0) {
5619 if (needComma) {
5620 sb.append(", ");
5621 }
5622 needComma = true;
5623 formatTimeMs(sb, totalWindowWakelock);
5624 sb.append("window");
5625 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005626 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005627 if (needComma) {
5628 sb.append(",");
5629 }
5630 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005631 formatTimeMs(sb, totalDrawWakelock);
5632 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005633 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005634 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005635 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005636 }
5637 }
5638
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07005639 // Calculate multicast wakelock stats
5640 final Timer mcTimer = u.getMulticastWakelockStats();
5641 if (mcTimer != null) {
5642 final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which);
5643 final int multicastWakeLockCount = mcTimer.getCountLocked(which);
5644
5645 if (multicastWakeLockTimeMicros > 0) {
5646 sb.setLength(0);
5647 sb.append(prefix);
5648 sb.append(" WiFi Multicast Wakelock");
5649 sb.append(" count = ");
5650 sb.append(multicastWakeLockCount);
5651 sb.append(" time = ");
5652 formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000);
5653 pw.println(sb.toString());
5654 }
5655 }
5656
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005657 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5658 for (int isy=syncs.size()-1; isy>=0; isy--) {
5659 final Timer timer = syncs.valueAt(isy);
5660 // Convert from microseconds to milliseconds with rounding
5661 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5662 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005663 final Timer bgTimer = timer.getSubTimer();
5664 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005665 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005666 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005667 sb.setLength(0);
5668 sb.append(prefix);
5669 sb.append(" Sync ");
5670 sb.append(syncs.keyAt(isy));
5671 sb.append(": ");
5672 if (totalTime != 0) {
5673 formatTimeMs(sb, totalTime);
5674 sb.append("realtime (");
5675 sb.append(count);
5676 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005677 if (bgTime > 0) {
5678 sb.append(", ");
5679 formatTimeMs(sb, bgTime);
5680 sb.append("background (");
5681 sb.append(bgCount);
5682 sb.append(" times)");
5683 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005684 } else {
5685 sb.append("(not used)");
5686 }
5687 pw.println(sb.toString());
5688 uidActivity = true;
5689 }
5690
5691 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5692 for (int ij=jobs.size()-1; ij>=0; ij--) {
5693 final Timer timer = jobs.valueAt(ij);
5694 // Convert from microseconds to milliseconds with rounding
5695 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5696 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005697 final Timer bgTimer = timer.getSubTimer();
5698 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005699 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005700 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005701 sb.setLength(0);
5702 sb.append(prefix);
5703 sb.append(" Job ");
5704 sb.append(jobs.keyAt(ij));
5705 sb.append(": ");
5706 if (totalTime != 0) {
5707 formatTimeMs(sb, totalTime);
5708 sb.append("realtime (");
5709 sb.append(count);
5710 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005711 if (bgTime > 0) {
5712 sb.append(", ");
5713 formatTimeMs(sb, bgTime);
5714 sb.append("background (");
5715 sb.append(bgCount);
5716 sb.append(" times)");
5717 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005718 } else {
5719 sb.append("(not used)");
5720 }
5721 pw.println(sb.toString());
5722 uidActivity = true;
5723 }
5724
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005725 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5726 for (int ic=completions.size()-1; ic>=0; ic--) {
5727 SparseIntArray types = completions.valueAt(ic);
5728 if (types != null) {
5729 pw.print(prefix);
5730 pw.print(" Job Completions ");
5731 pw.print(completions.keyAt(ic));
5732 pw.print(":");
5733 for (int it=0; it<types.size(); it++) {
5734 pw.print(" ");
5735 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5736 pw.print("(");
5737 pw.print(types.valueAt(it));
5738 pw.print("x)");
5739 }
5740 pw.println();
5741 }
5742 }
5743
Amith Yamasani977e11f2018-02-16 11:29:54 -08005744 u.getDeferredJobsLineLocked(sb, which);
5745 if (sb.length() > 0) {
5746 pw.print(" Jobs deferred on launch "); pw.println(sb.toString());
5747 }
5748
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005749 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5750 prefix, "Flashlight");
5751 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5752 prefix, "Camera");
5753 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5754 prefix, "Video");
5755 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5756 prefix, "Audio");
5757
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005758 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5759 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005760 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005761 final Uid.Sensor se = sensors.valueAt(ise);
5762 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005763 sb.setLength(0);
5764 sb.append(prefix);
5765 sb.append(" Sensor ");
5766 int handle = se.getHandle();
5767 if (handle == Uid.Sensor.GPS) {
5768 sb.append("GPS");
5769 } else {
5770 sb.append(handle);
5771 }
5772 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005773
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005774 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005775 if (timer != null) {
5776 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005777 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5778 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005779 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005780 final Timer bgTimer = se.getSensorBackgroundTime();
5781 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005782 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5783 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5784 final long bgActualTime = bgTimer != null ?
5785 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5786
Dianne Hackborn61659e52014-07-09 16:13:01 -07005787 //timer.logState();
5788 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005789 if (actualTime != totalTime) {
5790 formatTimeMs(sb, totalTime);
5791 sb.append("blamed realtime, ");
5792 }
5793
5794 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005795 sb.append("realtime (");
5796 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005797 sb.append(" times)");
5798
5799 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005800 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005801 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5802 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005803 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005804 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005805 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005806 } else {
5807 sb.append("(not used)");
5808 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005809 } else {
5810 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005812
5813 pw.println(sb.toString());
5814 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005815 }
5816
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005817 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5818 "Vibrator");
5819 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5820 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005821 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5822 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005823
Dianne Hackborn61659e52014-07-09 16:13:01 -07005824 long totalStateTime = 0;
5825 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5826 long time = u.getProcessStateTime(ips, rawRealtime, which);
5827 if (time > 0) {
5828 totalStateTime += time;
5829 sb.setLength(0);
5830 sb.append(prefix);
5831 sb.append(" ");
5832 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5833 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005834 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005835 pw.println(sb.toString());
5836 uidActivity = true;
5837 }
5838 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005839 if (totalStateTime > 0) {
5840 sb.setLength(0);
5841 sb.append(prefix);
5842 sb.append(" Total running: ");
5843 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5844 pw.println(sb.toString());
5845 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005846
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005847 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5848 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005849 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005850 sb.setLength(0);
5851 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005852 sb.append(" Total cpu time: u=");
5853 formatTimeMs(sb, userCpuTimeUs / 1000);
5854 sb.append("s=");
5855 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005856 pw.println(sb.toString());
5857 }
5858
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005859 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5860 if (cpuFreqTimes != null) {
5861 sb.setLength(0);
5862 sb.append(" Total cpu time per freq:");
5863 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5864 sb.append(" " + cpuFreqTimes[i]);
5865 }
5866 pw.println(sb.toString());
5867 }
5868 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5869 if (screenOffCpuFreqTimes != null) {
5870 sb.setLength(0);
5871 sb.append(" Total screen-off cpu time per freq:");
5872 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5873 sb.append(" " + screenOffCpuFreqTimes[i]);
5874 }
5875 pw.println(sb.toString());
5876 }
5877
Sudheer Shankab2f83c12017-11-13 19:25:01 -08005878 for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) {
5879 final long[] cpuTimes = u.getCpuFreqTimes(which, procState);
5880 if (cpuTimes != null) {
5881 sb.setLength(0);
5882 sb.append(" Cpu times per freq at state "
5883 + Uid.PROCESS_STATE_NAMES[procState] + ":");
5884 for (int i = 0; i < cpuTimes.length; ++i) {
5885 sb.append(" " + cpuTimes[i]);
5886 }
5887 pw.println(sb.toString());
5888 }
5889
5890 final long[] screenOffCpuTimes = u.getScreenOffCpuFreqTimes(which, procState);
5891 if (screenOffCpuTimes != null) {
5892 sb.setLength(0);
5893 sb.append(" Screen-off cpu times per freq at state "
5894 + Uid.PROCESS_STATE_NAMES[procState] + ":");
5895 for (int i = 0; i < screenOffCpuTimes.length; ++i) {
5896 sb.append(" " + screenOffCpuTimes[i]);
5897 }
5898 pw.println(sb.toString());
5899 }
5900 }
5901
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005902 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5903 = u.getProcessStats();
5904 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5905 final Uid.Proc ps = processStats.valueAt(ipr);
5906 long userTime;
5907 long systemTime;
5908 long foregroundTime;
5909 int starts;
5910 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005912 userTime = ps.getUserTime(which);
5913 systemTime = ps.getSystemTime(which);
5914 foregroundTime = ps.getForegroundTime(which);
5915 starts = ps.getStarts(which);
5916 final int numCrashes = ps.getNumCrashes(which);
5917 final int numAnrs = ps.getNumAnrs(which);
5918 numExcessive = which == STATS_SINCE_CHARGED
5919 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005921 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5922 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5923 sb.setLength(0);
5924 sb.append(prefix); sb.append(" Proc ");
5925 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5926 sb.append(prefix); sb.append(" CPU: ");
5927 formatTimeMs(sb, userTime); sb.append("usr + ");
5928 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5929 formatTimeMs(sb, foregroundTime); sb.append("fg");
5930 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5931 sb.append("\n"); sb.append(prefix); sb.append(" ");
5932 boolean hasOne = false;
5933 if (starts != 0) {
5934 hasOne = true;
5935 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005936 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005937 if (numCrashes != 0) {
5938 if (hasOne) {
5939 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005940 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005941 hasOne = true;
5942 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005943 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005944 if (numAnrs != 0) {
5945 if (hasOne) {
5946 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005948 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005949 }
5950 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005951 pw.println(sb.toString());
5952 for (int e=0; e<numExcessive; e++) {
5953 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5954 if (ew != null) {
5955 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005956 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005957 pw.print("cpu");
5958 } else {
5959 pw.print("unknown");
5960 }
5961 pw.print(" use: ");
5962 TimeUtils.formatDuration(ew.usedTime, pw);
5963 pw.print(" over ");
5964 TimeUtils.formatDuration(ew.overTime, pw);
5965 if (ew.overTime != 0) {
5966 pw.print(" (");
5967 pw.print((ew.usedTime*100)/ew.overTime);
5968 pw.println("%)");
5969 }
5970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 }
5972 uidActivity = true;
5973 }
5974 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005975
5976 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5977 = u.getPackageStats();
5978 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5979 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5980 pw.println(":");
5981 boolean apkActivity = false;
5982 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5983 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5984 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5985 pw.print(prefix); pw.print(" Wakeup alarm ");
5986 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5987 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5988 pw.println(" times");
5989 apkActivity = true;
5990 }
5991 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5992 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5993 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5994 final long startTime = ss.getStartTime(batteryUptime, which);
5995 final int starts = ss.getStarts(which);
5996 final int launches = ss.getLaunches(which);
5997 if (startTime != 0 || starts != 0 || launches != 0) {
5998 sb.setLength(0);
5999 sb.append(prefix); sb.append(" Service ");
6000 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
6001 sb.append(prefix); sb.append(" Created for: ");
6002 formatTimeMs(sb, startTime / 1000);
6003 sb.append("uptime\n");
6004 sb.append(prefix); sb.append(" Starts: ");
6005 sb.append(starts);
6006 sb.append(", launches: "); sb.append(launches);
6007 pw.println(sb.toString());
6008 apkActivity = true;
6009 }
6010 }
6011 if (!apkActivity) {
6012 pw.print(prefix); pw.println(" (nothing executed)");
6013 }
6014 uidActivity = true;
6015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006016 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006017 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 }
6019 }
6020 }
6021
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006022 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006023 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006024 int diff = oldval ^ newval;
6025 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006026 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006027 for (int i=0; i<descriptions.length; i++) {
6028 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006029 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006030 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006031 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006032 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006033 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006034 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
6035 didWake = true;
6036 pw.print("=");
6037 if (longNames) {
6038 UserHandle.formatUid(pw, wakelockTag.uid);
6039 pw.print(":\"");
6040 pw.print(wakelockTag.string);
6041 pw.print("\"");
6042 } else {
6043 pw.print(wakelockTag.poolIdx);
6044 }
6045 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006046 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006047 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006048 pw.print("=");
6049 int val = (newval&bd.mask)>>bd.shift;
6050 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006051 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006052 } else {
6053 pw.print(val);
6054 }
6055 }
6056 }
6057 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006058 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07006059 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006060 if (longNames) {
6061 UserHandle.formatUid(pw, wakelockTag.uid);
6062 pw.print(":\"");
6063 pw.print(wakelockTag.string);
6064 pw.print("\"");
6065 } else {
6066 pw.print(wakelockTag.poolIdx);
6067 }
6068 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07006069 }
Mike Mac2f518a2017-09-19 16:06:03 -07006070
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006071 public void prepareForDumpLocked() {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006072 // We don't need to require subclasses implement this.
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006073 }
6074
6075 public static class HistoryPrinter {
6076 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07006077 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006078 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006079 int oldStatus = -1;
6080 int oldHealth = -1;
6081 int oldPlug = -1;
6082 int oldTemp = -1;
6083 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07006084 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006085 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006086
Dianne Hackborn3251b902014-06-20 14:40:53 -07006087 void reset() {
6088 oldState = oldState2 = 0;
6089 oldLevel = -1;
6090 oldStatus = -1;
6091 oldHealth = -1;
6092 oldPlug = -1;
6093 oldTemp = -1;
6094 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07006095 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07006096 }
6097
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006098 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07006099 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006100 if (!checkin) {
6101 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006102 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006103 pw.print(" (");
6104 pw.print(rec.numReadInts);
6105 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006106 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006107 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6108 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006109 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006110 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006111 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006112 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006113 }
6114 lastTime = rec.time;
6115 }
6116 if (rec.cmd == HistoryItem.CMD_START) {
6117 if (checkin) {
6118 pw.print(":");
6119 }
6120 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07006121 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006122 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
6123 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006124 if (checkin) {
6125 pw.print(":");
6126 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006127 if (rec.cmd == HistoryItem.CMD_RESET) {
6128 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07006129 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006130 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006131 pw.print("TIME:");
6132 if (checkin) {
6133 pw.println(rec.currentTime);
6134 } else {
6135 pw.print(" ");
6136 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6137 rec.currentTime).toString());
6138 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006139 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
6140 if (checkin) {
6141 pw.print(":");
6142 }
6143 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006144 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
6145 if (checkin) {
6146 pw.print(":");
6147 }
6148 pw.println("*OVERFLOW*");
6149 } else {
6150 if (!checkin) {
6151 if (rec.batteryLevel < 10) pw.print("00");
6152 else if (rec.batteryLevel < 100) pw.print("0");
6153 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07006154 if (verbose) {
6155 pw.print(" ");
6156 if (rec.states < 0) ;
6157 else if (rec.states < 0x10) pw.print("0000000");
6158 else if (rec.states < 0x100) pw.print("000000");
6159 else if (rec.states < 0x1000) pw.print("00000");
6160 else if (rec.states < 0x10000) pw.print("0000");
6161 else if (rec.states < 0x100000) pw.print("000");
6162 else if (rec.states < 0x1000000) pw.print("00");
6163 else if (rec.states < 0x10000000) pw.print("0");
6164 pw.print(Integer.toHexString(rec.states));
6165 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006166 } else {
6167 if (oldLevel != rec.batteryLevel) {
6168 oldLevel = rec.batteryLevel;
6169 pw.print(",Bl="); pw.print(rec.batteryLevel);
6170 }
6171 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006172 if (oldStatus != rec.batteryStatus) {
6173 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006174 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006175 switch (oldStatus) {
6176 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006177 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006178 break;
6179 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006180 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006181 break;
6182 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006183 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006184 break;
6185 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006186 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006187 break;
6188 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006189 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006190 break;
6191 default:
6192 pw.print(oldStatus);
6193 break;
6194 }
6195 }
6196 if (oldHealth != rec.batteryHealth) {
6197 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006198 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006199 switch (oldHealth) {
6200 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006201 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006202 break;
6203 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006204 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006205 break;
6206 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006207 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006208 break;
6209 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006210 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006211 break;
6212 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006213 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006214 break;
6215 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006216 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006217 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08006218 case BatteryManager.BATTERY_HEALTH_COLD:
6219 pw.print(checkin ? "c" : "cold");
6220 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006221 default:
6222 pw.print(oldHealth);
6223 break;
6224 }
6225 }
6226 if (oldPlug != rec.batteryPlugType) {
6227 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006228 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006229 switch (oldPlug) {
6230 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006231 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006232 break;
6233 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006234 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006235 break;
6236 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006237 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006238 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07006239 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006240 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07006241 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006242 default:
6243 pw.print(oldPlug);
6244 break;
6245 }
6246 }
6247 if (oldTemp != rec.batteryTemperature) {
6248 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006249 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006250 pw.print(oldTemp);
6251 }
6252 if (oldVolt != rec.batteryVoltage) {
6253 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006254 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006255 pw.print(oldVolt);
6256 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07006257 final int chargeMAh = rec.batteryChargeUAh / 1000;
6258 if (oldChargeMAh != chargeMAh) {
6259 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07006260 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07006261 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07006262 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006263 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08006264 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07006265 printBitDescriptions(pw, oldState2, rec.states2, null,
6266 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006267 if (rec.wakeReasonTag != null) {
6268 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006269 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006270 pw.print(rec.wakeReasonTag.poolIdx);
6271 } else {
6272 pw.print(" wake_reason=");
6273 pw.print(rec.wakeReasonTag.uid);
6274 pw.print(":\"");
6275 pw.print(rec.wakeReasonTag.string);
6276 pw.print("\"");
6277 }
6278 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08006279 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08006280 pw.print(checkin ? "," : " ");
6281 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
6282 pw.print("+");
6283 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
6284 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006285 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08006286 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
6287 : HISTORY_EVENT_NAMES;
6288 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
6289 | HistoryItem.EVENT_FLAG_FINISH);
6290 if (idx >= 0 && idx < eventNames.length) {
6291 pw.print(eventNames[idx]);
6292 } else {
6293 pw.print(checkin ? "Ev" : "event");
6294 pw.print(idx);
6295 }
6296 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006297 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006298 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08006299 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08006300 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
6301 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006302 pw.print(":\"");
6303 pw.print(rec.eventTag.string);
6304 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08006305 }
6306 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006307 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006308 if (rec.stepDetails != null) {
6309 if (!checkin) {
6310 pw.print(" Details: cpu=");
6311 pw.print(rec.stepDetails.userTime);
6312 pw.print("u+");
6313 pw.print(rec.stepDetails.systemTime);
6314 pw.print("s");
6315 if (rec.stepDetails.appCpuUid1 >= 0) {
6316 pw.print(" (");
6317 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
6318 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6319 if (rec.stepDetails.appCpuUid2 >= 0) {
6320 pw.print(", ");
6321 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
6322 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6323 }
6324 if (rec.stepDetails.appCpuUid3 >= 0) {
6325 pw.print(", ");
6326 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
6327 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6328 }
6329 pw.print(')');
6330 }
6331 pw.println();
6332 pw.print(" /proc/stat=");
6333 pw.print(rec.stepDetails.statUserTime);
6334 pw.print(" usr, ");
6335 pw.print(rec.stepDetails.statSystemTime);
6336 pw.print(" sys, ");
6337 pw.print(rec.stepDetails.statIOWaitTime);
6338 pw.print(" io, ");
6339 pw.print(rec.stepDetails.statIrqTime);
6340 pw.print(" irq, ");
6341 pw.print(rec.stepDetails.statSoftIrqTime);
6342 pw.print(" sirq, ");
6343 pw.print(rec.stepDetails.statIdlTime);
6344 pw.print(" idle");
6345 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
6346 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
6347 + rec.stepDetails.statSoftIrqTime;
6348 int total = totalRun + rec.stepDetails.statIdlTime;
6349 if (total > 0) {
6350 pw.print(" (");
6351 float perc = ((float)totalRun) / ((float)total) * 100;
6352 pw.print(String.format("%.1f%%", perc));
6353 pw.print(" of ");
6354 StringBuilder sb = new StringBuilder(64);
6355 formatTimeMsNoSpace(sb, total*10);
6356 pw.print(sb);
6357 pw.print(")");
6358 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006359 pw.print(", PlatformIdleStat ");
6360 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006361 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006362
6363 pw.print(", SubsystemPowerState ");
6364 pw.print(rec.stepDetails.statSubsystemPowerState);
6365 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006366 } else {
6367 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6368 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
6369 pw.print(rec.stepDetails.userTime);
6370 pw.print(":");
6371 pw.print(rec.stepDetails.systemTime);
6372 if (rec.stepDetails.appCpuUid1 >= 0) {
6373 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
6374 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
6375 if (rec.stepDetails.appCpuUid2 >= 0) {
6376 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
6377 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
6378 }
6379 if (rec.stepDetails.appCpuUid3 >= 0) {
6380 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
6381 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
6382 }
6383 }
6384 pw.println();
6385 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6386 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
6387 pw.print(rec.stepDetails.statUserTime);
6388 pw.print(',');
6389 pw.print(rec.stepDetails.statSystemTime);
6390 pw.print(',');
6391 pw.print(rec.stepDetails.statIOWaitTime);
6392 pw.print(',');
6393 pw.print(rec.stepDetails.statIrqTime);
6394 pw.print(',');
6395 pw.print(rec.stepDetails.statSoftIrqTime);
6396 pw.print(',');
6397 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07006398 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006399 if (rec.stepDetails.statPlatformIdleState != null) {
6400 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07006401 if (rec.stepDetails.statSubsystemPowerState != null) {
6402 pw.print(',');
6403 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07006404 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00006405
6406 if (rec.stepDetails.statSubsystemPowerState != null) {
6407 pw.print(rec.stepDetails.statSubsystemPowerState);
6408 }
6409 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006410 }
6411 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006412 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006413 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006414 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006415 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08006416
6417 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
6418 UserHandle.formatUid(pw, uid);
6419 pw.print("=");
6420 pw.print(utime);
6421 pw.print("u+");
6422 pw.print(stime);
6423 pw.print("s");
6424 }
6425
6426 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
6427 pw.print('/');
6428 pw.print(uid);
6429 pw.print(":");
6430 pw.print(utime);
6431 pw.print(":");
6432 pw.print(stime);
6433 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006434 }
6435
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006436 private void printSizeValue(PrintWriter pw, long size) {
6437 float result = size;
6438 String suffix = "";
6439 if (result >= 10*1024) {
6440 suffix = "KB";
6441 result = result / 1024;
6442 }
6443 if (result >= 10*1024) {
6444 suffix = "MB";
6445 result = result / 1024;
6446 }
6447 if (result >= 10*1024) {
6448 suffix = "GB";
6449 result = result / 1024;
6450 }
6451 if (result >= 10*1024) {
6452 suffix = "TB";
6453 result = result / 1024;
6454 }
6455 if (result >= 10*1024) {
6456 suffix = "PB";
6457 result = result / 1024;
6458 }
6459 pw.print((int)result);
6460 pw.print(suffix);
6461 }
6462
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006463 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
6464 String label3, long estimatedTime) {
6465 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006466 return false;
6467 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006468 pw.print(label1);
6469 pw.print(label2);
6470 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006471 StringBuilder sb = new StringBuilder(64);
6472 formatTimeMs(sb, estimatedTime);
6473 pw.print(sb);
6474 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08006475 return true;
6476 }
6477
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006478 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
6479 LevelStepTracker steps, boolean checkin) {
6480 if (steps == null) {
6481 return false;
6482 }
6483 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006484 if (count <= 0) {
6485 return false;
6486 }
6487 if (!checkin) {
6488 pw.println(header);
6489 }
Kweku Adams030980a2015-04-01 16:07:48 -07006490 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006491 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006492 long duration = steps.getDurationAt(i);
6493 int level = steps.getLevelAt(i);
6494 long initMode = steps.getInitModeAt(i);
6495 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006496 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006497 lineArgs[0] = Long.toString(duration);
6498 lineArgs[1] = Integer.toString(level);
6499 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6500 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6501 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
6502 case Display.STATE_ON: lineArgs[2] = "s+"; break;
6503 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
6504 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07006505 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006506 }
6507 } else {
6508 lineArgs[2] = "";
6509 }
6510 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6511 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
6512 } else {
6513 lineArgs[3] = "";
6514 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006515 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07006516 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006517 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07006518 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006519 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006520 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
6521 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006522 pw.print(prefix);
6523 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006524 TimeUtils.formatDuration(duration, pw);
6525 pw.print(" to "); pw.print(level);
6526 boolean haveModes = false;
6527 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6528 pw.print(" (");
6529 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6530 case Display.STATE_OFF: pw.print("screen-off"); break;
6531 case Display.STATE_ON: pw.print("screen-on"); break;
6532 case Display.STATE_DOZE: pw.print("screen-doze"); break;
6533 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07006534 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006535 }
6536 haveModes = true;
6537 }
6538 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6539 pw.print(haveModes ? ", " : " (");
6540 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
6541 ? "power-save-on" : "power-save-off");
6542 haveModes = true;
6543 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006544 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6545 pw.print(haveModes ? ", " : " (");
6546 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6547 ? "device-idle-on" : "device-idle-off");
6548 haveModes = true;
6549 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07006550 if (haveModes) {
6551 pw.print(")");
6552 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006553 pw.println();
6554 }
6555 }
6556 return true;
6557 }
6558
Kweku Adams87b19ec2017-10-09 12:40:03 -07006559 private static void dumpDurationSteps(ProtoOutputStream proto, long fieldId,
6560 LevelStepTracker steps) {
6561 if (steps == null) {
6562 return;
6563 }
6564 int count = steps.mNumStepDurations;
Kweku Adams87b19ec2017-10-09 12:40:03 -07006565 for (int i = 0; i < count; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07006566 long token = proto.start(fieldId);
Kweku Adams87b19ec2017-10-09 12:40:03 -07006567 proto.write(SystemProto.BatteryLevelStep.DURATION_MS, steps.getDurationAt(i));
6568 proto.write(SystemProto.BatteryLevelStep.LEVEL, steps.getLevelAt(i));
6569
6570 final long initMode = steps.getInitModeAt(i);
6571 final long modMode = steps.getModModeAt(i);
6572
6573 int ds = SystemProto.BatteryLevelStep.DS_MIXED;
6574 if ((modMode & STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
6575 switch ((int) (initMode & STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
6576 case Display.STATE_OFF:
6577 ds = SystemProto.BatteryLevelStep.DS_OFF;
6578 break;
6579 case Display.STATE_ON:
6580 ds = SystemProto.BatteryLevelStep.DS_ON;
6581 break;
6582 case Display.STATE_DOZE:
6583 ds = SystemProto.BatteryLevelStep.DS_DOZE;
6584 break;
6585 case Display.STATE_DOZE_SUSPEND:
6586 ds = SystemProto.BatteryLevelStep.DS_DOZE_SUSPEND;
6587 break;
6588 default:
6589 ds = SystemProto.BatteryLevelStep.DS_ERROR;
6590 break;
6591 }
6592 }
6593 proto.write(SystemProto.BatteryLevelStep.DISPLAY_STATE, ds);
6594
6595 int psm = SystemProto.BatteryLevelStep.PSM_MIXED;
6596 if ((modMode & STEP_LEVEL_MODE_POWER_SAVE) == 0) {
6597 psm = (initMode & STEP_LEVEL_MODE_POWER_SAVE) != 0
6598 ? SystemProto.BatteryLevelStep.PSM_ON : SystemProto.BatteryLevelStep.PSM_OFF;
6599 }
6600 proto.write(SystemProto.BatteryLevelStep.POWER_SAVE_MODE, psm);
6601
6602 int im = SystemProto.BatteryLevelStep.IM_MIXED;
6603 if ((modMode & STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
6604 im = (initMode & STEP_LEVEL_MODE_DEVICE_IDLE) != 0
6605 ? SystemProto.BatteryLevelStep.IM_ON : SystemProto.BatteryLevelStep.IM_OFF;
6606 }
6607 proto.write(SystemProto.BatteryLevelStep.IDLE_MODE, im);
6608
6609 proto.end(token);
6610 }
6611 }
6612
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006613 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006614 public static final int DUMP_DAILY_ONLY = 1<<2;
6615 public static final int DUMP_HISTORY_ONLY = 1<<3;
6616 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
6617 public static final int DUMP_VERBOSE = 1<<5;
6618 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006619
Dianne Hackborn37de0982014-05-09 09:32:18 -07006620 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
6621 final HistoryPrinter hprinter = new HistoryPrinter();
6622 final HistoryItem rec = new HistoryItem();
6623 long lastTime = -1;
6624 long baseTime = -1;
6625 boolean printed = false;
6626 HistoryEventTracker tracker = null;
6627 while (getNextHistoryLocked(rec)) {
6628 lastTime = rec.time;
6629 if (baseTime < 0) {
6630 baseTime = lastTime;
6631 }
6632 if (rec.time >= histStart) {
6633 if (histStart >= 0 && !printed) {
6634 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006635 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006636 || rec.cmd == HistoryItem.CMD_START
6637 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006638 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006639 hprinter.printNextItem(pw, rec, baseTime, checkin,
6640 (flags&DUMP_VERBOSE) != 0);
6641 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006642 } else if (rec.currentTime != 0) {
6643 printed = true;
6644 byte cmd = rec.cmd;
6645 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006646 hprinter.printNextItem(pw, rec, baseTime, checkin,
6647 (flags&DUMP_VERBOSE) != 0);
6648 rec.cmd = cmd;
6649 }
6650 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006651 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6652 hprinter.printNextItem(pw, rec, baseTime, checkin,
6653 (flags&DUMP_VERBOSE) != 0);
6654 rec.cmd = HistoryItem.CMD_UPDATE;
6655 }
6656 int oldEventCode = rec.eventCode;
6657 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006658 rec.eventTag = new HistoryTag();
6659 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6660 HashMap<String, SparseIntArray> active
6661 = tracker.getStateForEvent(i);
6662 if (active == null) {
6663 continue;
6664 }
6665 for (HashMap.Entry<String, SparseIntArray> ent
6666 : active.entrySet()) {
6667 SparseIntArray uids = ent.getValue();
6668 for (int j=0; j<uids.size(); j++) {
6669 rec.eventCode = i;
6670 rec.eventTag.string = ent.getKey();
6671 rec.eventTag.uid = uids.keyAt(j);
6672 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006673 hprinter.printNextItem(pw, rec, baseTime, checkin,
6674 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006675 rec.wakeReasonTag = null;
6676 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006677 }
6678 }
6679 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006680 rec.eventCode = oldEventCode;
6681 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006682 tracker = null;
6683 }
6684 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006685 hprinter.printNextItem(pw, rec, baseTime, checkin,
6686 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006687 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6688 // This is an attempt to aggregate the previous state and generate
6689 // fake events to reflect that state at the point where we start
6690 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006691 if (tracker == null) {
6692 tracker = new HistoryEventTracker();
6693 }
6694 tracker.updateState(rec.eventCode, rec.eventTag.string,
6695 rec.eventTag.uid, rec.eventTag.poolIdx);
6696 }
6697 }
6698 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006699 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006700 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6701 }
6702 }
6703
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006704 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6705 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6706 if (steps == null) {
6707 return;
6708 }
6709 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6710 if (timeRemaining >= 0) {
6711 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6712 tmpSb.setLength(0);
6713 formatTimeMs(tmpSb, timeRemaining);
6714 pw.print(tmpSb);
6715 pw.print(" (from "); pw.print(tmpOutInt[0]);
6716 pw.println(" steps)");
6717 }
6718 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6719 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6720 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6721 if (estimatedTime > 0) {
6722 pw.print(prefix); pw.print(label); pw.print(" ");
6723 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6724 pw.print(" time: ");
6725 tmpSb.setLength(0);
6726 formatTimeMs(tmpSb, estimatedTime);
6727 pw.print(tmpSb);
6728 pw.print(" (from "); pw.print(tmpOutInt[0]);
6729 pw.println(" steps)");
6730 }
6731 }
6732 }
6733
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006734 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6735 ArrayList<PackageChange> changes) {
6736 if (changes == null) {
6737 return;
6738 }
6739 pw.print(prefix); pw.println("Package changes:");
6740 for (int i=0; i<changes.size(); i++) {
6741 PackageChange pc = changes.get(i);
6742 if (pc.mUpdate) {
6743 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6744 pw.print(" vers="); pw.println(pc.mVersionCode);
6745 } else {
6746 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6747 }
6748 }
6749 }
6750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 /**
6752 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6753 *
6754 * @param pw a Printer to receive the dump output.
6755 */
6756 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006757 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006758 prepareForDumpLocked();
6759
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006760 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006761 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006762
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006763 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006764 final long historyTotalSize = getHistoryTotalSize();
6765 final long historyUsedSize = getHistoryUsedSize();
6766 if (startIteratingHistoryLocked()) {
6767 try {
6768 pw.print("Battery History (");
6769 pw.print((100*historyUsedSize)/historyTotalSize);
6770 pw.print("% used, ");
6771 printSizeValue(pw, historyUsedSize);
6772 pw.print(" used of ");
6773 printSizeValue(pw, historyTotalSize);
6774 pw.print(", ");
6775 pw.print(getHistoryStringPoolSize());
6776 pw.print(" strings using ");
6777 printSizeValue(pw, getHistoryStringPoolBytes());
6778 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006779 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006780 pw.println();
6781 } finally {
6782 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006783 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006784 }
6785
6786 if (startIteratingOldHistoryLocked()) {
6787 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006788 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006789 pw.println("Old battery History:");
6790 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006791 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006792 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006793 if (baseTime < 0) {
6794 baseTime = rec.time;
6795 }
6796 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006797 }
6798 pw.println();
6799 } finally {
6800 finishIteratingOldHistoryLocked();
6801 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006802 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006803 }
6804
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006805 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006806 return;
6807 }
6808
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006809 if (!filtering) {
6810 SparseArray<? extends Uid> uidStats = getUidStats();
6811 final int NU = uidStats.size();
6812 boolean didPid = false;
6813 long nowRealtime = SystemClock.elapsedRealtime();
6814 for (int i=0; i<NU; i++) {
6815 Uid uid = uidStats.valueAt(i);
6816 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6817 if (pids != null) {
6818 for (int j=0; j<pids.size(); j++) {
6819 Uid.Pid pid = pids.valueAt(j);
6820 if (!didPid) {
6821 pw.println("Per-PID Stats:");
6822 didPid = true;
6823 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006824 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6825 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006826 pw.print(" PID "); pw.print(pids.keyAt(j));
6827 pw.print(" wake time: ");
6828 TimeUtils.formatDuration(time, pw);
6829 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006830 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006831 }
6832 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006833 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006834 pw.println();
6835 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006836 }
6837
6838 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006839 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6840 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006841 long timeRemaining = computeBatteryTimeRemaining(
6842 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006843 if (timeRemaining >= 0) {
6844 pw.print(" Estimated discharge time remaining: ");
6845 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6846 pw.println();
6847 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006848 final LevelStepTracker steps = getDischargeLevelStepTracker();
6849 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6850 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6851 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6852 STEP_LEVEL_MODE_VALUES[i], null));
6853 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006854 pw.println();
6855 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006856 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6857 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006858 long timeRemaining = computeChargeTimeRemaining(
6859 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006860 if (timeRemaining >= 0) {
6861 pw.print(" Estimated charge time remaining: ");
6862 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6863 pw.println();
6864 }
6865 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006866 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006867 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07006868 if (!filtering || (flags & DUMP_DAILY_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006869 pw.println("Daily stats:");
6870 pw.print(" Current start time: ");
6871 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6872 getCurrentDailyStartTime()).toString());
6873 pw.print(" Next min deadline: ");
6874 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6875 getNextMinDailyDeadline()).toString());
6876 pw.print(" Next max deadline: ");
6877 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6878 getNextMaxDailyDeadline()).toString());
6879 StringBuilder sb = new StringBuilder(64);
6880 int[] outInt = new int[1];
6881 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6882 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006883 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6884 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006885 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006886 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6887 dsteps, false)) {
6888 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6889 sb, outInt);
6890 }
6891 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6892 csteps, false)) {
6893 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6894 sb, outInt);
6895 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006896 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006897 } else {
6898 pw.println(" Current daily steps:");
6899 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6900 sb, outInt);
6901 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6902 sb, outInt);
6903 }
6904 }
6905 DailyItem dit;
6906 int curIndex = 0;
6907 while ((dit=getDailyItemLocked(curIndex)) != null) {
6908 curIndex++;
6909 if ((flags&DUMP_DAILY_ONLY) != 0) {
6910 pw.println();
6911 }
6912 pw.print(" Daily from ");
6913 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6914 pw.print(" to ");
6915 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6916 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006917 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006918 if (dumpDurationSteps(pw, " ",
6919 " Discharge step durations:", dit.mDischargeSteps, false)) {
6920 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6921 sb, outInt);
6922 }
6923 if (dumpDurationSteps(pw, " ",
6924 " Charge step durations:", dit.mChargeSteps, false)) {
6925 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6926 sb, outInt);
6927 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006928 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006929 } else {
6930 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6931 sb, outInt);
6932 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6933 sb, outInt);
6934 }
6935 }
6936 pw.println();
6937 }
6938 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006939 pw.println("Statistics since last charge:");
6940 pw.println(" System starts: " + getStartCount()
6941 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006942 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6943 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006944 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 }
Mike Mac2f518a2017-09-19 16:06:03 -07006947
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006948 // This is called from BatteryStatsService.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006950 public void dumpCheckinLocked(Context context, PrintWriter pw,
6951 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006952 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006953
6954 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006955 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6956 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006957
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006958 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6959
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006960 if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006961 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006962 try {
6963 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6964 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6965 pw.print(HISTORY_STRING_POOL); pw.print(',');
6966 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006967 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006968 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006969 pw.print(",\"");
6970 String str = getHistoryTagPoolString(i);
6971 str = str.replace("\\", "\\\\");
6972 str = str.replace("\"", "\\\"");
6973 pw.print(str);
6974 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006975 pw.println();
6976 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006977 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006978 } finally {
6979 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006980 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006981 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006982 }
6983
Kweku Adams2f73ecd2017-09-27 16:59:19 -07006984 if ((flags & DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006985 return;
6986 }
6987
Dianne Hackborne4a59512010-12-07 11:08:07 -08006988 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006989 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006990 for (int i=0; i<apps.size(); i++) {
6991 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006992 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6993 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006994 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006995 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6996 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006997 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006998 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006999 }
7000 SparseArray<? extends Uid> uidStats = getUidStats();
7001 final int NU = uidStats.size();
7002 String[] lineArgs = new String[2];
7003 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07007004 int uid = UserHandle.getAppId(uidStats.keyAt(i));
7005 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
7006 if (pkgs != null && !pkgs.second.value) {
7007 pkgs.second.value = true;
7008 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08007009 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07007010 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08007011 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
7012 (Object[])lineArgs);
7013 }
7014 }
7015 }
7016 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007017 if ((flags & DUMP_DAILY_ONLY) == 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08007018 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07007019 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07007020 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07007021 if (timeRemaining >= 0) {
7022 lineArgs[0] = Long.toString(timeRemaining);
7023 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
7024 (Object[])lineArgs);
7025 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08007026 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07007027 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07007028 if (timeRemaining >= 0) {
7029 lineArgs[0] = Long.toString(timeRemaining);
7030 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
7031 (Object[])lineArgs);
7032 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07007033 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
7034 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08007035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 }
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007037
Kweku Adams87b19ec2017-10-09 12:40:03 -07007038 /** Dump #STATS_SINCE_CHARGED batterystats data to a proto. @hide */
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007039 public void dumpProtoLocked(Context context, FileDescriptor fd, List<ApplicationInfo> apps,
Kweku Adams6ccebf22017-12-11 12:30:35 -08007040 int flags) {
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007041 final ProtoOutputStream proto = new ProtoOutputStream(fd);
7042 final long bToken = proto.start(BatteryStatsServiceDumpProto.BATTERYSTATS);
7043 prepareForDumpLocked();
7044
7045 proto.write(BatteryStatsProto.REPORT_VERSION, CHECKIN_VERSION);
7046 proto.write(BatteryStatsProto.PARCEL_VERSION, getParcelVersion());
7047 proto.write(BatteryStatsProto.START_PLATFORM_VERSION, getStartPlatformVersion());
7048 proto.write(BatteryStatsProto.END_PLATFORM_VERSION, getEndPlatformVersion());
7049
Kweku Adams6ccebf22017-12-11 12:30:35 -08007050 // History intentionally not included in proto dump.
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007051
7052 if ((flags & (DUMP_HISTORY_ONLY | DUMP_DAILY_ONLY)) == 0) {
Kweku Adams103351f2017-10-16 14:39:34 -07007053 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false,
7054 (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
7055 helper.create(this);
7056 helper.refreshStats(STATS_SINCE_CHARGED, UserHandle.USER_ALL);
7057
7058 dumpProtoAppsLocked(proto, helper, apps);
7059 dumpProtoSystemLocked(proto, helper);
Kweku Adams2f73ecd2017-09-27 16:59:19 -07007060 }
7061
7062 proto.end(bToken);
7063 proto.flush();
7064 }
Kweku Adams87b19ec2017-10-09 12:40:03 -07007065
Kweku Adams103351f2017-10-16 14:39:34 -07007066 private void dumpProtoAppsLocked(ProtoOutputStream proto, BatteryStatsHelper helper,
7067 List<ApplicationInfo> apps) {
7068 final int which = STATS_SINCE_CHARGED;
7069 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
7070 final long rawRealtimeMs = SystemClock.elapsedRealtime();
7071 final long rawRealtimeUs = rawRealtimeMs * 1000;
7072 final long batteryUptimeUs = getBatteryUptime(rawUptimeUs);
7073
7074 SparseArray<ArrayList<String>> aidToPackages = new SparseArray<>();
7075 if (apps != null) {
7076 for (int i = 0; i < apps.size(); ++i) {
7077 ApplicationInfo ai = apps.get(i);
7078 int aid = UserHandle.getAppId(ai.uid);
7079 ArrayList<String> pkgs = aidToPackages.get(aid);
7080 if (pkgs == null) {
7081 pkgs = new ArrayList<String>();
7082 aidToPackages.put(aid, pkgs);
7083 }
7084 pkgs.add(ai.packageName);
7085 }
7086 }
7087
7088 SparseArray<BatterySipper> uidToSipper = new SparseArray<>();
7089 final List<BatterySipper> sippers = helper.getUsageList();
7090 if (sippers != null) {
7091 for (int i = 0; i < sippers.size(); ++i) {
7092 final BatterySipper bs = sippers.get(i);
7093 if (bs.drainType != BatterySipper.DrainType.APP) {
7094 // Others are handled by dumpProtoSystemLocked()
7095 continue;
7096 }
7097 uidToSipper.put(bs.uidObj.getUid(), bs);
7098 }
7099 }
7100
7101 SparseArray<? extends Uid> uidStats = getUidStats();
7102 final int n = uidStats.size();
7103 for (int iu = 0; iu < n; ++iu) {
7104 final long uTkn = proto.start(BatteryStatsProto.UIDS);
7105 final Uid u = uidStats.valueAt(iu);
7106
7107 final int uid = uidStats.keyAt(iu);
7108 proto.write(UidProto.UID, uid);
7109
7110 // Print packages and apk stats (UID_DATA & APK_DATA)
7111 ArrayList<String> pkgs = aidToPackages.get(UserHandle.getAppId(uid));
7112 if (pkgs == null) {
7113 pkgs = new ArrayList<String>();
7114 }
7115 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats =
7116 u.getPackageStats();
7117 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
7118 String pkg = packageStats.keyAt(ipkg);
7119 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats =
7120 packageStats.valueAt(ipkg).getServiceStats();
7121 if (serviceStats.size() == 0) {
7122 // Due to the way ActivityManagerService logs wakeup alarms, some packages (for
7123 // example, "android") may be included in the packageStats that aren't part of
7124 // the UID. If they don't have any services, then they shouldn't be listed here.
7125 // These packages won't be a part in the pkgs List.
7126 continue;
7127 }
7128
7129 final long pToken = proto.start(UidProto.PACKAGES);
7130 proto.write(UidProto.Package.NAME, pkg);
7131 // Remove from the packages list since we're logging it here.
7132 pkgs.remove(pkg);
7133
7134 for (int isvc = serviceStats.size() - 1; isvc >= 0; --isvc) {
7135 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
7136 long sToken = proto.start(UidProto.Package.SERVICES);
7137
7138 proto.write(UidProto.Package.Service.NAME, serviceStats.keyAt(isvc));
7139 proto.write(UidProto.Package.Service.START_DURATION_MS,
7140 roundUsToMs(ss.getStartTime(batteryUptimeUs, which)));
7141 proto.write(UidProto.Package.Service.START_COUNT, ss.getStarts(which));
7142 proto.write(UidProto.Package.Service.LAUNCH_COUNT, ss.getLaunches(which));
7143
7144 proto.end(sToken);
7145 }
7146 proto.end(pToken);
7147 }
7148 // Print any remaining packages that weren't in the packageStats map. pkgs is pulled
7149 // from PackageManager data. Packages are only included in packageStats if there was
7150 // specific data tracked for them (services and wakeup alarms, etc.).
7151 for (String p : pkgs) {
7152 final long pToken = proto.start(UidProto.PACKAGES);
7153 proto.write(UidProto.Package.NAME, p);
7154 proto.end(pToken);
7155 }
7156
7157 // Total wakelock data (AGGREGATED_WAKELOCK_DATA)
7158 if (u.getAggregatedPartialWakelockTimer() != null) {
7159 final Timer timer = u.getAggregatedPartialWakelockTimer();
7160 // Times are since reset (regardless of 'which')
7161 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
7162 final Timer bgTimer = timer.getSubTimer();
7163 final long bgTimeMs = bgTimer != null
7164 ? bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
7165 final long awToken = proto.start(UidProto.AGGREGATED_WAKELOCK);
7166 proto.write(UidProto.AggregatedWakelock.PARTIAL_DURATION_MS, totTimeMs);
7167 proto.write(UidProto.AggregatedWakelock.BACKGROUND_PARTIAL_DURATION_MS, bgTimeMs);
7168 proto.end(awToken);
7169 }
7170
7171 // Audio (AUDIO_DATA)
7172 dumpTimer(proto, UidProto.AUDIO, u.getAudioTurnedOnTimer(), rawRealtimeUs, which);
7173
7174 // Bluetooth Controller (BLUETOOTH_CONTROLLER_DATA)
7175 dumpControllerActivityProto(proto, UidProto.BLUETOOTH_CONTROLLER,
7176 u.getBluetoothControllerActivity(), which);
7177
7178 // BLE scans (BLUETOOTH_MISC_DATA) (uses totalDurationMsLocked and MaxDurationMsLocked)
7179 final Timer bleTimer = u.getBluetoothScanTimer();
7180 if (bleTimer != null) {
7181 final long bmToken = proto.start(UidProto.BLUETOOTH_MISC);
7182
7183 dumpTimer(proto, UidProto.BluetoothMisc.APPORTIONED_BLE_SCAN, bleTimer,
7184 rawRealtimeUs, which);
7185 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN,
7186 u.getBluetoothScanBackgroundTimer(), rawRealtimeUs, which);
7187 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
7188 dumpTimer(proto, UidProto.BluetoothMisc.UNOPTIMIZED_BLE_SCAN,
7189 u.getBluetoothUnoptimizedScanTimer(), rawRealtimeUs, which);
7190 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
7191 dumpTimer(proto, UidProto.BluetoothMisc.BACKGROUND_UNOPTIMIZED_BLE_SCAN,
7192 u.getBluetoothUnoptimizedScanBackgroundTimer(), rawRealtimeUs, which);
7193 // Result counters
7194 proto.write(UidProto.BluetoothMisc.BLE_SCAN_RESULT_COUNT,
7195 u.getBluetoothScanResultCounter() != null
7196 ? u.getBluetoothScanResultCounter().getCountLocked(which) : 0);
7197 proto.write(UidProto.BluetoothMisc.BACKGROUND_BLE_SCAN_RESULT_COUNT,
7198 u.getBluetoothScanResultBgCounter() != null
7199 ? u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0);
7200
7201 proto.end(bmToken);
7202 }
7203
7204 // Camera (CAMERA_DATA)
7205 dumpTimer(proto, UidProto.CAMERA, u.getCameraTurnedOnTimer(), rawRealtimeUs, which);
7206
7207 // CPU stats (CPU_DATA & CPU_TIMES_AT_FREQ_DATA)
7208 final long cpuToken = proto.start(UidProto.CPU);
7209 proto.write(UidProto.Cpu.USER_DURATION_MS, roundUsToMs(u.getUserCpuTimeUs(which)));
7210 proto.write(UidProto.Cpu.SYSTEM_DURATION_MS, roundUsToMs(u.getSystemCpuTimeUs(which)));
7211
7212 final long[] cpuFreqs = getCpuFreqs();
7213 if (cpuFreqs != null) {
7214 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
7215 // If total cpuFreqTimes is null, then we don't need to check for
7216 // screenOffCpuFreqTimes.
7217 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
7218 long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
7219 if (screenOffCpuFreqTimeMs == null) {
7220 screenOffCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
7221 }
7222 for (int ic = 0; ic < cpuFreqTimeMs.length; ++ic) {
7223 long cToken = proto.start(UidProto.Cpu.BY_FREQUENCY);
7224 proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1);
7225 proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS,
7226 cpuFreqTimeMs[ic]);
7227 proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS,
7228 screenOffCpuFreqTimeMs[ic]);
7229 proto.end(cToken);
7230 }
7231 }
7232 }
Sudheer Shanka6d658d72018-01-01 01:36:49 -08007233
7234 for (int procState = 0; procState < Uid.NUM_PROCESS_STATE; ++procState) {
7235 final long[] timesMs = u.getCpuFreqTimes(which, procState);
7236 if (timesMs != null && timesMs.length == cpuFreqs.length) {
7237 long[] screenOffTimesMs = u.getScreenOffCpuFreqTimes(which, procState);
7238 if (screenOffTimesMs == null) {
7239 screenOffTimesMs = new long[timesMs.length];
7240 }
7241 final long procToken = proto.start(UidProto.Cpu.BY_PROCESS_STATE);
7242 proto.write(UidProto.Cpu.ByProcessState.PROCESS_STATE, procState);
7243 for (int ic = 0; ic < timesMs.length; ++ic) {
7244 long cToken = proto.start(UidProto.Cpu.ByProcessState.BY_FREQUENCY);
7245 proto.write(UidProto.Cpu.ByFrequency.FREQUENCY_INDEX, ic + 1);
7246 proto.write(UidProto.Cpu.ByFrequency.TOTAL_DURATION_MS,
7247 timesMs[ic]);
7248 proto.write(UidProto.Cpu.ByFrequency.SCREEN_OFF_DURATION_MS,
7249 screenOffTimesMs[ic]);
7250 proto.end(cToken);
7251 }
7252 proto.end(procToken);
7253 }
7254 }
Kweku Adams103351f2017-10-16 14:39:34 -07007255 proto.end(cpuToken);
7256
7257 // Flashlight (FLASHLIGHT_DATA)
7258 dumpTimer(proto, UidProto.FLASHLIGHT, u.getFlashlightTurnedOnTimer(),
7259 rawRealtimeUs, which);
7260
7261 // Foreground activity (FOREGROUND_ACTIVITY_DATA)
7262 dumpTimer(proto, UidProto.FOREGROUND_ACTIVITY, u.getForegroundActivityTimer(),
7263 rawRealtimeUs, which);
7264
7265 // Foreground service (FOREGROUND_SERVICE_DATA)
7266 dumpTimer(proto, UidProto.FOREGROUND_SERVICE, u.getForegroundServiceTimer(),
7267 rawRealtimeUs, which);
7268
7269 // Job completion (JOB_COMPLETION_DATA)
7270 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
7271 final int[] reasons = new int[]{
7272 JobParameters.REASON_CANCELED,
7273 JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
7274 JobParameters.REASON_PREEMPT,
7275 JobParameters.REASON_TIMEOUT,
7276 JobParameters.REASON_DEVICE_IDLE,
7277 };
7278 for (int ic = 0; ic < completions.size(); ++ic) {
7279 SparseIntArray types = completions.valueAt(ic);
7280 if (types != null) {
7281 final long jcToken = proto.start(UidProto.JOB_COMPLETION);
7282
7283 proto.write(UidProto.JobCompletion.NAME, completions.keyAt(ic));
7284
7285 for (int r : reasons) {
7286 long rToken = proto.start(UidProto.JobCompletion.REASON_COUNT);
7287 proto.write(UidProto.JobCompletion.ReasonCount.NAME, r);
7288 proto.write(UidProto.JobCompletion.ReasonCount.COUNT, types.get(r, 0));
7289 proto.end(rToken);
7290 }
7291
7292 proto.end(jcToken);
7293 }
7294 }
7295
7296 // Scheduled jobs (JOB_DATA)
7297 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
7298 for (int ij = jobs.size() - 1; ij >= 0; --ij) {
7299 final Timer timer = jobs.valueAt(ij);
7300 final Timer bgTimer = timer.getSubTimer();
7301 final long jToken = proto.start(UidProto.JOBS);
7302
7303 proto.write(UidProto.Job.NAME, jobs.keyAt(ij));
7304 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7305 dumpTimer(proto, UidProto.Job.TOTAL, timer, rawRealtimeUs, which);
7306 dumpTimer(proto, UidProto.Job.BACKGROUND, bgTimer, rawRealtimeUs, which);
7307
7308 proto.end(jToken);
7309 }
7310
7311 // Modem Controller (MODEM_CONTROLLER_DATA)
7312 dumpControllerActivityProto(proto, UidProto.MODEM_CONTROLLER,
7313 u.getModemControllerActivity(), which);
7314
7315 // Network stats (NETWORK_DATA)
7316 final long nToken = proto.start(UidProto.NETWORK);
7317 proto.write(UidProto.Network.MOBILE_BYTES_RX,
7318 u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7319 proto.write(UidProto.Network.MOBILE_BYTES_TX,
7320 u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7321 proto.write(UidProto.Network.WIFI_BYTES_RX,
7322 u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7323 proto.write(UidProto.Network.WIFI_BYTES_TX,
7324 u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7325 proto.write(UidProto.Network.BT_BYTES_RX,
7326 u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7327 proto.write(UidProto.Network.BT_BYTES_TX,
7328 u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
7329 proto.write(UidProto.Network.MOBILE_PACKETS_RX,
7330 u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7331 proto.write(UidProto.Network.MOBILE_PACKETS_TX,
7332 u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7333 proto.write(UidProto.Network.WIFI_PACKETS_RX,
7334 u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7335 proto.write(UidProto.Network.WIFI_PACKETS_TX,
7336 u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7337 proto.write(UidProto.Network.MOBILE_ACTIVE_DURATION_MS,
7338 roundUsToMs(u.getMobileRadioActiveTime(which)));
7339 proto.write(UidProto.Network.MOBILE_ACTIVE_COUNT,
7340 u.getMobileRadioActiveCount(which));
7341 proto.write(UidProto.Network.MOBILE_WAKEUP_COUNT,
7342 u.getMobileRadioApWakeupCount(which));
7343 proto.write(UidProto.Network.WIFI_WAKEUP_COUNT,
7344 u.getWifiRadioApWakeupCount(which));
7345 proto.write(UidProto.Network.MOBILE_BYTES_BG_RX,
7346 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, which));
7347 proto.write(UidProto.Network.MOBILE_BYTES_BG_TX,
7348 u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, which));
7349 proto.write(UidProto.Network.WIFI_BYTES_BG_RX,
7350 u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which));
7351 proto.write(UidProto.Network.WIFI_BYTES_BG_TX,
7352 u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which));
7353 proto.write(UidProto.Network.MOBILE_PACKETS_BG_RX,
7354 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, which));
7355 proto.write(UidProto.Network.MOBILE_PACKETS_BG_TX,
7356 u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, which));
7357 proto.write(UidProto.Network.WIFI_PACKETS_BG_RX,
7358 u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, which));
7359 proto.write(UidProto.Network.WIFI_PACKETS_BG_TX,
7360 u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, which));
7361 proto.end(nToken);
7362
7363 // Power use item (POWER_USE_ITEM_DATA)
7364 BatterySipper bs = uidToSipper.get(uid);
7365 if (bs != null) {
7366 final long bsToken = proto.start(UidProto.POWER_USE_ITEM);
7367 proto.write(UidProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7368 proto.write(UidProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7369 proto.write(UidProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7370 proto.write(UidProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7371 bs.proportionalSmearMah);
7372 proto.end(bsToken);
7373 }
7374
7375 // Processes (PROCESS_DATA)
7376 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats =
7377 u.getProcessStats();
7378 for (int ipr = processStats.size() - 1; ipr >= 0; --ipr) {
7379 final Uid.Proc ps = processStats.valueAt(ipr);
7380 final long prToken = proto.start(UidProto.PROCESS);
7381
7382 proto.write(UidProto.Process.NAME, processStats.keyAt(ipr));
7383 proto.write(UidProto.Process.USER_DURATION_MS, ps.getUserTime(which));
7384 proto.write(UidProto.Process.SYSTEM_DURATION_MS, ps.getSystemTime(which));
7385 proto.write(UidProto.Process.FOREGROUND_DURATION_MS, ps.getForegroundTime(which));
7386 proto.write(UidProto.Process.START_COUNT, ps.getStarts(which));
7387 proto.write(UidProto.Process.ANR_COUNT, ps.getNumAnrs(which));
7388 proto.write(UidProto.Process.CRASH_COUNT, ps.getNumCrashes(which));
7389
7390 proto.end(prToken);
7391 }
7392
7393 // Sensors (SENSOR_DATA)
7394 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
7395 for (int ise = 0; ise < sensors.size(); ++ise) {
7396 final Uid.Sensor se = sensors.valueAt(ise);
7397 final Timer timer = se.getSensorTime();
7398 if (timer == null) {
7399 continue;
7400 }
7401 final Timer bgTimer = se.getSensorBackgroundTime();
7402 final int sensorNumber = sensors.keyAt(ise);
7403 final long seToken = proto.start(UidProto.SENSORS);
7404
7405 proto.write(UidProto.Sensor.ID, sensorNumber);
7406 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7407 dumpTimer(proto, UidProto.Sensor.APPORTIONED, timer, rawRealtimeUs, which);
7408 dumpTimer(proto, UidProto.Sensor.BACKGROUND, bgTimer, rawRealtimeUs, which);
7409
7410 proto.end(seToken);
7411 }
7412
7413 // State times (STATE_TIME_DATA)
7414 for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ++ips) {
7415 long durMs = roundUsToMs(u.getProcessStateTime(ips, rawRealtimeUs, which));
7416 if (durMs == 0) {
7417 continue;
7418 }
7419 final long stToken = proto.start(UidProto.STATES);
7420 proto.write(UidProto.StateTime.STATE, ips);
7421 proto.write(UidProto.StateTime.DURATION_MS, durMs);
7422 proto.end(stToken);
7423 }
7424
7425 // Syncs (SYNC_DATA)
7426 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
7427 for (int isy = syncs.size() - 1; isy >= 0; --isy) {
7428 final Timer timer = syncs.valueAt(isy);
7429 final Timer bgTimer = timer.getSubTimer();
7430 final long syToken = proto.start(UidProto.SYNCS);
7431
7432 proto.write(UidProto.Sync.NAME, syncs.keyAt(isy));
7433 // Background uses totalDurationMsLocked, while total uses totalTimeLocked
7434 dumpTimer(proto, UidProto.Sync.TOTAL, timer, rawRealtimeUs, which);
7435 dumpTimer(proto, UidProto.Sync.BACKGROUND, bgTimer, rawRealtimeUs, which);
7436
7437 proto.end(syToken);
7438 }
7439
7440 // User activity (USER_ACTIVITY_DATA)
7441 if (u.hasUserActivity()) {
7442 for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; ++i) {
7443 int val = u.getUserActivityCount(i, which);
7444 if (val != 0) {
7445 final long uaToken = proto.start(UidProto.USER_ACTIVITY);
7446 proto.write(UidProto.UserActivity.NAME, i);
7447 proto.write(UidProto.UserActivity.COUNT, val);
7448 proto.end(uaToken);
7449 }
7450 }
7451 }
7452
7453 // Vibrator (VIBRATOR_DATA)
7454 dumpTimer(proto, UidProto.VIBRATOR, u.getVibratorOnTimer(), rawRealtimeUs, which);
7455
7456 // Video (VIDEO_DATA)
7457 dumpTimer(proto, UidProto.VIDEO, u.getVideoTurnedOnTimer(), rawRealtimeUs, which);
7458
7459 // Wakelocks (WAKELOCK_DATA)
7460 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
7461 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7462 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7463 final long wToken = proto.start(UidProto.WAKELOCKS);
7464 proto.write(UidProto.Wakelock.NAME, wakelocks.keyAt(iw));
7465 dumpTimer(proto, UidProto.Wakelock.FULL, wl.getWakeTime(WAKE_TYPE_FULL),
7466 rawRealtimeUs, which);
7467 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7468 if (pTimer != null) {
7469 dumpTimer(proto, UidProto.Wakelock.PARTIAL, pTimer, rawRealtimeUs, which);
7470 dumpTimer(proto, UidProto.Wakelock.BACKGROUND_PARTIAL, pTimer.getSubTimer(),
7471 rawRealtimeUs, which);
7472 }
7473 dumpTimer(proto, UidProto.Wakelock.WINDOW, wl.getWakeTime(WAKE_TYPE_WINDOW),
7474 rawRealtimeUs, which);
7475 proto.end(wToken);
7476 }
7477
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007478 // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA)
7479 dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(),
7480 rawRealtimeUs, which);
7481
Kweku Adams103351f2017-10-16 14:39:34 -07007482 // Wakeup alarms (WAKEUP_ALARM_DATA)
7483 for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) {
7484 final Uid.Pkg ps = packageStats.valueAt(ipkg);
7485 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
7486 for (int iwa = alarms.size() - 1; iwa >= 0; --iwa) {
7487 final long waToken = proto.start(UidProto.WAKEUP_ALARM);
7488 proto.write(UidProto.WakeupAlarm.NAME, alarms.keyAt(iwa));
7489 proto.write(UidProto.WakeupAlarm.COUNT,
7490 alarms.valueAt(iwa).getCountLocked(which));
7491 proto.end(waToken);
7492 }
7493 }
7494
7495 // Wifi Controller (WIFI_CONTROLLER_DATA)
7496 dumpControllerActivityProto(proto, UidProto.WIFI_CONTROLLER,
7497 u.getWifiControllerActivity(), which);
7498
7499 // Wifi data (WIFI_DATA)
7500 final long wToken = proto.start(UidProto.WIFI);
7501 proto.write(UidProto.Wifi.FULL_WIFI_LOCK_DURATION_MS,
7502 roundUsToMs(u.getFullWifiLockTime(rawRealtimeUs, which)));
7503 dumpTimer(proto, UidProto.Wifi.APPORTIONED_SCAN, u.getWifiScanTimer(),
7504 rawRealtimeUs, which);
7505 proto.write(UidProto.Wifi.RUNNING_DURATION_MS,
7506 roundUsToMs(u.getWifiRunningTime(rawRealtimeUs, which)));
7507 dumpTimer(proto, UidProto.Wifi.BACKGROUND_SCAN, u.getWifiScanBackgroundTimer(),
7508 rawRealtimeUs, which);
7509 proto.end(wToken);
7510
7511 proto.end(uTkn);
7512 }
7513 }
7514
7515 private void dumpProtoSystemLocked(ProtoOutputStream proto, BatteryStatsHelper helper) {
Kweku Adams87b19ec2017-10-09 12:40:03 -07007516 final long sToken = proto.start(BatteryStatsProto.SYSTEM);
7517 final long rawUptimeUs = SystemClock.uptimeMillis() * 1000;
7518 final long rawRealtimeMs = SystemClock.elapsedRealtime();
7519 final long rawRealtimeUs = rawRealtimeMs * 1000;
7520 final int which = STATS_SINCE_CHARGED;
7521
7522 // Battery data (BATTERY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007523 final long bToken = proto.start(SystemProto.BATTERY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007524 proto.write(SystemProto.Battery.START_CLOCK_TIME_MS, getStartClockTime());
7525 proto.write(SystemProto.Battery.START_COUNT, getStartCount());
7526 proto.write(SystemProto.Battery.TOTAL_REALTIME_MS,
7527 computeRealtime(rawRealtimeUs, which) / 1000);
7528 proto.write(SystemProto.Battery.TOTAL_UPTIME_MS,
7529 computeUptime(rawUptimeUs, which) / 1000);
7530 proto.write(SystemProto.Battery.BATTERY_REALTIME_MS,
7531 computeBatteryRealtime(rawRealtimeUs, which) / 1000);
7532 proto.write(SystemProto.Battery.BATTERY_UPTIME_MS,
7533 computeBatteryUptime(rawUptimeUs, which) / 1000);
7534 proto.write(SystemProto.Battery.SCREEN_OFF_REALTIME_MS,
7535 computeBatteryScreenOffRealtime(rawRealtimeUs, which) / 1000);
7536 proto.write(SystemProto.Battery.SCREEN_OFF_UPTIME_MS,
7537 computeBatteryScreenOffUptime(rawUptimeUs, which) / 1000);
7538 proto.write(SystemProto.Battery.SCREEN_DOZE_DURATION_MS,
7539 getScreenDozeTime(rawRealtimeUs, which) / 1000);
7540 proto.write(SystemProto.Battery.ESTIMATED_BATTERY_CAPACITY_MAH,
7541 getEstimatedBatteryCapacity());
7542 proto.write(SystemProto.Battery.MIN_LEARNED_BATTERY_CAPACITY_UAH,
7543 getMinLearnedBatteryCapacity());
7544 proto.write(SystemProto.Battery.MAX_LEARNED_BATTERY_CAPACITY_UAH,
7545 getMaxLearnedBatteryCapacity());
Kweku Adams103351f2017-10-16 14:39:34 -07007546 proto.end(bToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007547
7548 // Battery discharge (BATTERY_DISCHARGE_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007549 final long bdToken = proto.start(SystemProto.BATTERY_DISCHARGE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007550 proto.write(SystemProto.BatteryDischarge.LOWER_BOUND_SINCE_CHARGE,
7551 getLowDischargeAmountSinceCharge());
7552 proto.write(SystemProto.BatteryDischarge.UPPER_BOUND_SINCE_CHARGE,
7553 getHighDischargeAmountSinceCharge());
7554 proto.write(SystemProto.BatteryDischarge.SCREEN_ON_SINCE_CHARGE,
7555 getDischargeAmountScreenOnSinceCharge());
7556 proto.write(SystemProto.BatteryDischarge.SCREEN_OFF_SINCE_CHARGE,
7557 getDischargeAmountScreenOffSinceCharge());
7558 proto.write(SystemProto.BatteryDischarge.SCREEN_DOZE_SINCE_CHARGE,
7559 getDischargeAmountScreenDozeSinceCharge());
7560 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH,
7561 getUahDischarge(which) / 1000);
7562 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_OFF,
7563 getUahDischargeScreenOff(which) / 1000);
7564 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_SCREEN_DOZE,
7565 getUahDischargeScreenDoze(which) / 1000);
Mike Ma15313c92017-11-15 17:58:21 -08007566 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_LIGHT_DOZE,
7567 getUahDischargeLightDoze(which) / 1000);
7568 proto.write(SystemProto.BatteryDischarge.TOTAL_MAH_DEEP_DOZE,
7569 getUahDischargeDeepDoze(which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007570 proto.end(bdToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007571
7572 // Time remaining
7573 long timeRemainingUs = computeChargeTimeRemaining(rawRealtimeUs);
Kweku Adams103351f2017-10-16 14:39:34 -07007574 // These are part of a oneof, so we should only set one of them.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007575 if (timeRemainingUs >= 0) {
7576 // Charge time remaining (CHARGE_TIME_REMAIN_DATA)
7577 proto.write(SystemProto.CHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7578 } else {
7579 timeRemainingUs = computeBatteryTimeRemaining(rawRealtimeUs);
7580 // Discharge time remaining (DISCHARGE_TIME_REMAIN_DATA)
7581 if (timeRemainingUs >= 0) {
7582 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, timeRemainingUs / 1000);
7583 } else {
7584 proto.write(SystemProto.DISCHARGE_TIME_REMAINING_MS, -1);
7585 }
7586 }
7587
7588 // Charge step (CHARGE_STEP_DATA)
7589 dumpDurationSteps(proto, SystemProto.CHARGE_STEP, getChargeLevelStepTracker());
7590
7591 // Phone data connection (DATA_CONNECTION_TIME_DATA and DATA_CONNECTION_COUNT_DATA)
7592 for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007593 final long pdcToken = proto.start(SystemProto.DATA_CONNECTION);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007594 proto.write(SystemProto.DataConnection.NAME, i);
7595 dumpTimer(proto, SystemProto.DataConnection.TOTAL, getPhoneDataConnectionTimer(i),
7596 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007597 proto.end(pdcToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007598 }
7599
7600 // Discharge step (DISCHARGE_STEP_DATA)
7601 dumpDurationSteps(proto, SystemProto.DISCHARGE_STEP, getDischargeLevelStepTracker());
7602
7603 // CPU frequencies (GLOBAL_CPU_FREQ_DATA)
7604 final long[] cpuFreqs = getCpuFreqs();
7605 if (cpuFreqs != null) {
7606 for (long i : cpuFreqs) {
7607 proto.write(SystemProto.CPU_FREQUENCY, i);
7608 }
7609 }
7610
7611 // Bluetooth controller (GLOBAL_BLUETOOTH_CONTROLLER_DATA)
7612 dumpControllerActivityProto(proto, SystemProto.GLOBAL_BLUETOOTH_CONTROLLER,
7613 getBluetoothControllerActivity(), which);
7614
7615 // Modem controller (GLOBAL_MODEM_CONTROLLER_DATA)
7616 dumpControllerActivityProto(proto, SystemProto.GLOBAL_MODEM_CONTROLLER,
7617 getModemControllerActivity(), which);
7618
7619 // Global network data (GLOBAL_NETWORK_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007620 final long gnToken = proto.start(SystemProto.GLOBAL_NETWORK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007621 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_RX,
7622 getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which));
7623 proto.write(SystemProto.GlobalNetwork.MOBILE_BYTES_TX,
7624 getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which));
7625 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_RX,
7626 getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which));
7627 proto.write(SystemProto.GlobalNetwork.MOBILE_PACKETS_TX,
7628 getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which));
7629 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_RX,
7630 getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which));
7631 proto.write(SystemProto.GlobalNetwork.WIFI_BYTES_TX,
7632 getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which));
7633 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_RX,
7634 getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which));
7635 proto.write(SystemProto.GlobalNetwork.WIFI_PACKETS_TX,
7636 getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which));
7637 proto.write(SystemProto.GlobalNetwork.BT_BYTES_RX,
7638 getNetworkActivityBytes(NETWORK_BT_RX_DATA, which));
7639 proto.write(SystemProto.GlobalNetwork.BT_BYTES_TX,
7640 getNetworkActivityBytes(NETWORK_BT_TX_DATA, which));
Kweku Adams103351f2017-10-16 14:39:34 -07007641 proto.end(gnToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007642
7643 // Wifi controller (GLOBAL_WIFI_CONTROLLER_DATA)
7644 dumpControllerActivityProto(proto, SystemProto.GLOBAL_WIFI_CONTROLLER,
7645 getWifiControllerActivity(), which);
7646
7647
7648 // Global wifi (GLOBAL_WIFI_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007649 final long gwToken = proto.start(SystemProto.GLOBAL_WIFI);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007650 proto.write(SystemProto.GlobalWifi.ON_DURATION_MS,
7651 getWifiOnTime(rawRealtimeUs, which) / 1000);
7652 proto.write(SystemProto.GlobalWifi.RUNNING_DURATION_MS,
7653 getGlobalWifiRunningTime(rawRealtimeUs, which) / 1000);
Kweku Adams103351f2017-10-16 14:39:34 -07007654 proto.end(gwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007655
7656 // Kernel wakelock (KERNEL_WAKELOCK_DATA)
7657 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
7658 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007659 final long kwToken = proto.start(SystemProto.KERNEL_WAKELOCK);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007660 proto.write(SystemProto.KernelWakelock.NAME, ent.getKey());
7661 dumpTimer(proto, SystemProto.KernelWakelock.TOTAL, ent.getValue(),
7662 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007663 proto.end(kwToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007664 }
7665
7666 // Misc (MISC_DATA)
7667 // Calculate wakelock times across all uids.
7668 long fullWakeLockTimeTotalUs = 0;
7669 long partialWakeLockTimeTotalUs = 0;
7670
7671 final SparseArray<? extends Uid> uidStats = getUidStats();
7672 for (int iu = 0; iu < uidStats.size(); iu++) {
7673 final Uid u = uidStats.valueAt(iu);
7674
7675 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks =
7676 u.getWakelockStats();
7677 for (int iw = wakelocks.size() - 1; iw >= 0; --iw) {
7678 final Uid.Wakelock wl = wakelocks.valueAt(iw);
7679
7680 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
7681 if (fullWakeTimer != null) {
7682 fullWakeLockTimeTotalUs += fullWakeTimer.getTotalTimeLocked(rawRealtimeUs,
7683 which);
7684 }
7685
7686 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
7687 if (partialWakeTimer != null) {
7688 partialWakeLockTimeTotalUs += partialWakeTimer.getTotalTimeLocked(
7689 rawRealtimeUs, which);
7690 }
7691 }
7692 }
Kweku Adams103351f2017-10-16 14:39:34 -07007693 final long mToken = proto.start(SystemProto.MISC);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007694 proto.write(SystemProto.Misc.SCREEN_ON_DURATION_MS,
7695 getScreenOnTime(rawRealtimeUs, which) / 1000);
7696 proto.write(SystemProto.Misc.PHONE_ON_DURATION_MS,
7697 getPhoneOnTime(rawRealtimeUs, which) / 1000);
7698 proto.write(SystemProto.Misc.FULL_WAKELOCK_TOTAL_DURATION_MS,
7699 fullWakeLockTimeTotalUs / 1000);
7700 proto.write(SystemProto.Misc.PARTIAL_WAKELOCK_TOTAL_DURATION_MS,
7701 partialWakeLockTimeTotalUs / 1000);
7702 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_DURATION_MS,
7703 getMobileRadioActiveTime(rawRealtimeUs, which) / 1000);
7704 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_ADJUSTED_TIME_MS,
7705 getMobileRadioActiveAdjustedTime(which) / 1000);
7706 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_COUNT,
7707 getMobileRadioActiveCount(which));
7708 proto.write(SystemProto.Misc.MOBILE_RADIO_ACTIVE_UNKNOWN_DURATION_MS,
7709 getMobileRadioActiveUnknownTime(which) / 1000);
7710 proto.write(SystemProto.Misc.INTERACTIVE_DURATION_MS,
7711 getInteractiveTime(rawRealtimeUs, which) / 1000);
7712 proto.write(SystemProto.Misc.BATTERY_SAVER_MODE_ENABLED_DURATION_MS,
7713 getPowerSaveModeEnabledTime(rawRealtimeUs, which) / 1000);
7714 proto.write(SystemProto.Misc.NUM_CONNECTIVITY_CHANGES,
7715 getNumConnectivityChange(which));
7716 proto.write(SystemProto.Misc.DEEP_DOZE_ENABLED_DURATION_MS,
7717 getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7718 proto.write(SystemProto.Misc.DEEP_DOZE_COUNT,
7719 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
7720 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_DURATION_MS,
7721 getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtimeUs, which) / 1000);
7722 proto.write(SystemProto.Misc.DEEP_DOZE_IDLING_COUNT,
7723 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
7724 proto.write(SystemProto.Misc.LONGEST_DEEP_DOZE_DURATION_MS,
7725 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
7726 proto.write(SystemProto.Misc.LIGHT_DOZE_ENABLED_DURATION_MS,
7727 getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7728 proto.write(SystemProto.Misc.LIGHT_DOZE_COUNT,
7729 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
7730 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_DURATION_MS,
7731 getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtimeUs, which) / 1000);
7732 proto.write(SystemProto.Misc.LIGHT_DOZE_IDLING_COUNT,
7733 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
7734 proto.write(SystemProto.Misc.LONGEST_LIGHT_DOZE_DURATION_MS,
7735 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
Kweku Adams103351f2017-10-16 14:39:34 -07007736 proto.end(mToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007737
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007738 // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA)
Ahmed ElArabawyf88571f2017-11-28 12:18:10 -08007739 final long multicastWakeLockTimeTotalUs =
7740 getWifiMulticastWakelockTime(rawRealtimeUs, which);
7741 final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which);
Ahmed ElArabawyddd09692017-10-30 17:58:29 -07007742 final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL);
7743 proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS,
7744 multicastWakeLockTimeTotalUs / 1000);
7745 proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT,
7746 multicastWakeLockCountTotal);
7747 proto.end(wmctToken);
7748
Kweku Adams87b19ec2017-10-09 12:40:03 -07007749 // Power use item (POWER_USE_ITEM_DATA)
7750 final List<BatterySipper> sippers = helper.getUsageList();
7751 if (sippers != null) {
7752 for (int i = 0; i < sippers.size(); ++i) {
7753 final BatterySipper bs = sippers.get(i);
7754 int n = SystemProto.PowerUseItem.UNKNOWN_SIPPER;
7755 int uid = 0;
7756 switch (bs.drainType) {
7757 case IDLE:
7758 n = SystemProto.PowerUseItem.IDLE;
7759 break;
7760 case CELL:
7761 n = SystemProto.PowerUseItem.CELL;
7762 break;
7763 case PHONE:
7764 n = SystemProto.PowerUseItem.PHONE;
7765 break;
7766 case WIFI:
7767 n = SystemProto.PowerUseItem.WIFI;
7768 break;
7769 case BLUETOOTH:
7770 n = SystemProto.PowerUseItem.BLUETOOTH;
7771 break;
7772 case SCREEN:
7773 n = SystemProto.PowerUseItem.SCREEN;
7774 break;
7775 case FLASHLIGHT:
7776 n = SystemProto.PowerUseItem.FLASHLIGHT;
7777 break;
7778 case APP:
Kweku Adams103351f2017-10-16 14:39:34 -07007779 // dumpProtoAppsLocked will handle this.
Kweku Adams87b19ec2017-10-09 12:40:03 -07007780 continue;
7781 case USER:
7782 n = SystemProto.PowerUseItem.USER;
7783 uid = UserHandle.getUid(bs.userId, 0);
7784 break;
7785 case UNACCOUNTED:
7786 n = SystemProto.PowerUseItem.UNACCOUNTED;
7787 break;
7788 case OVERCOUNTED:
7789 n = SystemProto.PowerUseItem.OVERCOUNTED;
7790 break;
7791 case CAMERA:
7792 n = SystemProto.PowerUseItem.CAMERA;
7793 break;
7794 case MEMORY:
7795 n = SystemProto.PowerUseItem.MEMORY;
7796 break;
7797 }
Kweku Adams103351f2017-10-16 14:39:34 -07007798 final long puiToken = proto.start(SystemProto.POWER_USE_ITEM);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007799 proto.write(SystemProto.PowerUseItem.NAME, n);
7800 proto.write(SystemProto.PowerUseItem.UID, uid);
7801 proto.write(SystemProto.PowerUseItem.COMPUTED_POWER_MAH, bs.totalPowerMah);
7802 proto.write(SystemProto.PowerUseItem.SHOULD_HIDE, bs.shouldHide);
7803 proto.write(SystemProto.PowerUseItem.SCREEN_POWER_MAH, bs.screenPowerMah);
7804 proto.write(SystemProto.PowerUseItem.PROPORTIONAL_SMEAR_MAH,
7805 bs.proportionalSmearMah);
Kweku Adams103351f2017-10-16 14:39:34 -07007806 proto.end(puiToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007807 }
7808 }
7809
7810 // Power use summary (POWER_USE_SUMMARY_DATA)
Kweku Adams103351f2017-10-16 14:39:34 -07007811 final long pusToken = proto.start(SystemProto.POWER_USE_SUMMARY);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007812 proto.write(SystemProto.PowerUseSummary.BATTERY_CAPACITY_MAH,
7813 helper.getPowerProfile().getBatteryCapacity());
7814 proto.write(SystemProto.PowerUseSummary.COMPUTED_POWER_MAH, helper.getComputedPower());
7815 proto.write(SystemProto.PowerUseSummary.MIN_DRAINED_POWER_MAH, helper.getMinDrainedPower());
7816 proto.write(SystemProto.PowerUseSummary.MAX_DRAINED_POWER_MAH, helper.getMaxDrainedPower());
Kweku Adams103351f2017-10-16 14:39:34 -07007817 proto.end(pusToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007818
7819 // RPM stats (RESOURCE_POWER_MANAGER_DATA)
7820 final Map<String, ? extends Timer> rpmStats = getRpmStats();
7821 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
7822 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007823 final long rpmToken = proto.start(SystemProto.RESOURCE_POWER_MANAGER);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007824 proto.write(SystemProto.ResourcePowerManager.NAME, ent.getKey());
7825 dumpTimer(proto, SystemProto.ResourcePowerManager.TOTAL,
7826 ent.getValue(), rawRealtimeUs, which);
7827 dumpTimer(proto, SystemProto.ResourcePowerManager.SCREEN_OFF,
7828 screenOffRpmStats.get(ent.getKey()), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007829 proto.end(rpmToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007830 }
7831
7832 // Screen brightness (SCREEN_BRIGHTNESS_DATA)
7833 for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007834 final long sbToken = proto.start(SystemProto.SCREEN_BRIGHTNESS);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007835 proto.write(SystemProto.ScreenBrightness.NAME, i);
7836 dumpTimer(proto, SystemProto.ScreenBrightness.TOTAL, getScreenBrightnessTimer(i),
7837 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007838 proto.end(sbToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007839 }
7840
7841 // Signal scanning time (SIGNAL_SCANNING_TIME_DATA)
7842 dumpTimer(proto, SystemProto.SIGNAL_SCANNING, getPhoneSignalScanningTimer(), rawRealtimeUs,
7843 which);
7844
7845 // Phone signal strength (SIGNAL_STRENGTH_TIME_DATA and SIGNAL_STRENGTH_COUNT_DATA)
7846 for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007847 final long pssToken = proto.start(SystemProto.PHONE_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007848 proto.write(SystemProto.PhoneSignalStrength.NAME, i);
7849 dumpTimer(proto, SystemProto.PhoneSignalStrength.TOTAL, getPhoneSignalStrengthTimer(i),
7850 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007851 proto.end(pssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007852 }
7853
7854 // Wakeup reasons (WAKEUP_REASON_DATA)
7855 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
7856 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Kweku Adams103351f2017-10-16 14:39:34 -07007857 final long wrToken = proto.start(SystemProto.WAKEUP_REASON);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007858 proto.write(SystemProto.WakeupReason.NAME, ent.getKey());
7859 dumpTimer(proto, SystemProto.WakeupReason.TOTAL, ent.getValue(), rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007860 proto.end(wrToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007861 }
7862
7863 // Wifi signal strength (WIFI_SIGNAL_STRENGTH_TIME_DATA and WIFI_SIGNAL_STRENGTH_COUNT_DATA)
7864 for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007865 final long wssToken = proto.start(SystemProto.WIFI_SIGNAL_STRENGTH);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007866 proto.write(SystemProto.WifiSignalStrength.NAME, i);
7867 dumpTimer(proto, SystemProto.WifiSignalStrength.TOTAL, getWifiSignalStrengthTimer(i),
7868 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007869 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007870 }
7871
7872 // Wifi state (WIFI_STATE_TIME_DATA and WIFI_STATE_COUNT_DATA)
7873 for (int i = 0; i < NUM_WIFI_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007874 final long wsToken = proto.start(SystemProto.WIFI_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007875 proto.write(SystemProto.WifiState.NAME, i);
7876 dumpTimer(proto, SystemProto.WifiState.TOTAL, getWifiStateTimer(i),
7877 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007878 proto.end(wsToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007879 }
7880
7881 // Wifi supplicant state (WIFI_SUPPL_STATE_TIME_DATA and WIFI_SUPPL_STATE_COUNT_DATA)
7882 for (int i = 0; i < NUM_WIFI_SUPPL_STATES; ++i) {
Kweku Adams103351f2017-10-16 14:39:34 -07007883 final long wssToken = proto.start(SystemProto.WIFI_SUPPLICANT_STATE);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007884 proto.write(SystemProto.WifiSupplicantState.NAME, i);
7885 dumpTimer(proto, SystemProto.WifiSupplicantState.TOTAL, getWifiSupplStateTimer(i),
7886 rawRealtimeUs, which);
Kweku Adams103351f2017-10-16 14:39:34 -07007887 proto.end(wssToken);
Kweku Adams87b19ec2017-10-09 12:40:03 -07007888 }
7889
7890 proto.end(sToken);
7891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892}