From 62dea2943fd90ff9bf6ca02214596e5f556359a5 Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Fri, 29 May 2020 17:50:14 -0700 Subject: [PATCH] Throttle the dropbox logs per event-type We'd still need to log other type of events if a specfic type of event occurred too frequently and got throttled Bug: 156871564 Test: Manual Change-Id: I94ce76834f8d8e90f7d4e20091786382dfcbc05b --- .../server/am/ActivityManagerService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index a5bb4733a5098..2fbff4c037d40 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -10153,8 +10153,7 @@ public class ActivityManagerService extends IActivityManager.Stub } } - private volatile long mWtfClusterStart; - private volatile int mWtfClusterCount; + private volatile ArrayMap mErrorClusterRecords = new ArrayMap<>(); /** * Write a description of an error (crash, WTF, ANR) to the drop box. @@ -10185,13 +10184,18 @@ public class ActivityManagerService extends IActivityManager.Stub if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return; // Rate-limit how often we're willing to do the heavy lifting below to - // collect and record logs; currently 5 logs per 10 second period. + // collect and record logs; currently 5 logs per 10 second period per eventType. final long now = SystemClock.elapsedRealtime(); - if (now - mWtfClusterStart > 10 * DateUtils.SECOND_IN_MILLIS) { - mWtfClusterStart = now; - mWtfClusterCount = 1; + long[] errRecord = mErrorClusterRecords.get(eventType); + if (errRecord == null) { + errRecord = new long[2]; // [0]: startTime, [1]: count + mErrorClusterRecords.put(eventType, errRecord); + } + if (now - errRecord[0] > 10 * DateUtils.SECOND_IN_MILLIS) { + errRecord[0] = now; + errRecord[1] = 1L; } else { - if (mWtfClusterCount++ >= 5) return; + if (errRecord[1]++ >= 5) return; } final StringBuilder sb = new StringBuilder(1024);