diff options
| author | 2018-03-22 14:06:37 -0700 | |
|---|---|---|
| committer | 2018-03-22 14:06:37 -0700 | |
| commit | 08de1891c8adc3f29b754c5786a4929d3fac3779 (patch) | |
| tree | 9e2bf36a565cc211e4124488ccb966a61ae9bfa7 | |
| parent | 72fa61b3250529504a9f5dab2e927a0d2e873f58 (diff) | |
Prune files from /data/anr/ by number as well as age.
tombstoned prunes based on both age and number of files. Until we can
fully switch over to tombstoned, emulate that here too.
Bug: http://b/73140330
Test: ran tests
Change-Id: I824034019e91d541fc7b7ba49d152e1ceaf37621
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 8731cdad69c5..f8a4b674f62c 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -5678,15 +5678,16 @@ public class ActivityManagerService extends IActivityManager.Stub * since it's the system_server that creates trace files for most ANRs. */ private static void maybePruneOldTraces(File tracesDir) { - final long now = System.currentTimeMillis(); - final File[] traceFiles = tracesDir.listFiles(); + final File[] files = tracesDir.listFiles(); + if (files == null) return; - if (traceFiles != null) { - for (File file : traceFiles) { - if ((now - file.lastModified()) > DAY_IN_MILLIS) { - if (!file.delete()) { - Slog.w(TAG, "Unable to prune stale trace file: " + file); - } + final int max = SystemProperties.getInt("tombstoned.max_anr_count", 64); + final long now = System.currentTimeMillis(); + Arrays.sort(files, Comparator.comparingLong(File::lastModified).reversed()); + for (int i = 0; i < files.length; ++i) { + if (i > max || (now - files[i].lastModified()) > DAY_IN_MILLIS) { + if (!files[i].delete()) { + Slog.w(TAG, "Unable to prune stale trace file: " + files[i]); } } } |