diff options
author | 2015-10-28 22:07:33 +0000 | |
---|---|---|
committer | 2015-10-28 22:07:33 +0000 | |
commit | 4c9564567b016e44d8ae2fe638df5e72391b843c (patch) | |
tree | 0590d066a80120f8d6aea770003b5f1f7feaa2e7 | |
parent | 2e9aa6fc40afeb691e5d2f82ea962ce65b438768 (diff) | |
parent | ae78bf8552d0a3ff83b8300630d47188434173ea (diff) |
Merge "Add some debugging for device idle alarms."
-rw-r--r-- | services/core/java/com/android/server/AlarmManagerService.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index 4f5fff40d908..ed6fc0057c09 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -95,6 +95,7 @@ class AlarmManagerService extends SystemService { static final boolean DEBUG_VALIDATE = localLOGV || false; static final boolean DEBUG_ALARM_CLOCK = localLOGV || false; static final boolean RECORD_ALARMS_IN_HISTORY = true; + static final boolean RECORD_DEVICE_IDLE_ALARMS = false; static final int ALARM_EVENT = 1; static final String TIMEZONE_PROPERTY = "persist.sys.timezone"; @@ -144,6 +145,16 @@ class AlarmManagerService extends SystemService { */ final SparseLongArray mLastAllowWhileIdleDispatch = new SparseLongArray(); + final static class IdleDispatchEntry { + int uid; + String pkg; + String tag; + String op; + long elapsedRealtime; + long argRealtime; + } + final ArrayList<IdleDispatchEntry> mAllowWhileIdleDispatches = new ArrayList(); + /** * Broadcast options to use for FLAG_ALLOW_WHILE_IDLE. */ @@ -700,6 +711,14 @@ class AlarmManagerService extends SystemService { } void restorePendingWhileIdleAlarmsLocked() { + if (RECORD_DEVICE_IDLE_ALARMS) { + IdleDispatchEntry ent = new IdleDispatchEntry(); + ent.uid = 0; + ent.pkg = "FINISH IDLE"; + ent.elapsedRealtime = SystemClock.elapsedRealtime(); + mAllowWhileIdleDispatches.add(ent); + } + // Bring pending alarms back into the main list. if (mPendingWhileIdleAlarms.size() > 0) { ArrayList<Alarm> alarms = mPendingWhileIdleAlarms; @@ -1006,6 +1025,19 @@ class AlarmManagerService extends SystemService { } } + if (RECORD_DEVICE_IDLE_ALARMS) { + if ((a.flags & AlarmManager.FLAG_ALLOW_WHILE_IDLE) != 0) { + IdleDispatchEntry ent = new IdleDispatchEntry(); + ent.uid = a.uid; + ent.pkg = a.operation.getCreatorPackage(); + ent.tag = a.operation.getTag(""); + ent.op = "SET"; + ent.elapsedRealtime = SystemClock.elapsedRealtime(); + ent.argRealtime = a.whenElapsed; + mAllowWhileIdleDispatches.add(ent); + } + } + int whichBatch = ((a.flags&AlarmManager.FLAG_STANDALONE) != 0) ? -1 : attemptCoalesceLocked(a.whenElapsed, a.maxWhenElapsed); if (whichBatch < 0) { @@ -1028,6 +1060,15 @@ class AlarmManagerService extends SystemService { boolean needRebatch = false; if ((a.flags&AlarmManager.FLAG_IDLE_UNTIL) != 0) { + if (RECORD_DEVICE_IDLE_ALARMS) { + if (mPendingIdleUntil == null) { + IdleDispatchEntry ent = new IdleDispatchEntry(); + ent.uid = 0; + ent.pkg = "START IDLE"; + ent.elapsedRealtime = SystemClock.elapsedRealtime(); + mAllowWhileIdleDispatches.add(ent); + } + } mPendingIdleUntil = a; mConstants.updateAllowWhileIdleMinTimeLocked(); needRebatch = true; @@ -1400,6 +1441,32 @@ class AlarmManagerService extends SystemService { } } + if (RECORD_DEVICE_IDLE_ALARMS) { + pw.println(); + pw.println(" Allow while idle dispatches:"); + for (int i = 0; i < mAllowWhileIdleDispatches.size(); i++) { + IdleDispatchEntry ent = mAllowWhileIdleDispatches.get(i); + pw.print(" "); + TimeUtils.formatDuration(ent.elapsedRealtime, nowELAPSED, pw); + pw.print(": "); + UserHandle.formatUid(pw, ent.uid); + pw.print(":"); + pw.println(ent.pkg); + if (ent.op != null) { + pw.print(" "); + pw.print(ent.op); + pw.print(" / "); + pw.print(ent.tag); + if (ent.argRealtime != 0) { + pw.print(" ("); + TimeUtils.formatDuration(ent.argRealtime, nowELAPSED, pw); + pw.print(")"); + } + pw.println(); + } + } + } + if (WAKEUP_STATS) { pw.println(); pw.println(" Recent Wakeup History:"); @@ -1862,6 +1929,16 @@ class AlarmManagerService extends SystemService { if (alarm.maxWhenElapsed < minTime) { alarm.maxWhenElapsed = minTime; } + if (RECORD_DEVICE_IDLE_ALARMS) { + IdleDispatchEntry ent = new IdleDispatchEntry(); + ent.uid = alarm.uid; + ent.pkg = alarm.operation.getCreatorPackage(); + ent.tag = alarm.operation.getTag(""); + ent.op = "RESCHEDULE"; + ent.elapsedRealtime = nowELAPSED; + ent.argRealtime = lastTime; + mAllowWhileIdleDispatches.add(ent); + } setImplLocked(alarm, true, false); continue; } @@ -2130,6 +2207,15 @@ class AlarmManagerService extends SystemService { if (allowWhileIdle) { // Record the last time this uid handled an ALLOW_WHILE_IDLE alarm. mLastAllowWhileIdleDispatch.put(alarm.uid, nowELAPSED); + if (RECORD_DEVICE_IDLE_ALARMS) { + IdleDispatchEntry ent = new IdleDispatchEntry(); + ent.uid = alarm.uid; + ent.pkg = alarm.operation.getCreatorPackage(); + ent.tag = alarm.operation.getTag(""); + ent.op = "DELIVER"; + ent.elapsedRealtime = nowELAPSED; + mAllowWhileIdleDispatches.add(ent); + } } final BroadcastStats bs = inflight.mBroadcastStats; |