Merge "Prune files from /data/anr/ by number as well as age."

This commit is contained in:
Elliott Hughes
2018-03-23 17:36:23 +00:00
committed by Gerrit Code Review

View File

@@ -5681,15 +5681,16 @@ public class ActivityManagerService extends IActivityManager.Stub
* since it's the system_server that creates trace files for most ANRs. * since it's the system_server that creates trace files for most ANRs.
*/ */
private static void maybePruneOldTraces(File tracesDir) { private static void maybePruneOldTraces(File tracesDir) {
final long now = System.currentTimeMillis(); final File[] files = tracesDir.listFiles();
final File[] traceFiles = tracesDir.listFiles(); if (files == null) return;
if (traceFiles != null) { final int max = SystemProperties.getInt("tombstoned.max_anr_count", 64);
for (File file : traceFiles) { final long now = System.currentTimeMillis();
if ((now - file.lastModified()) > DAY_IN_MILLIS) { Arrays.sort(files, Comparator.comparingLong(File::lastModified).reversed());
if (!file.delete()) { for (int i = 0; i < files.length; ++i) {
Slog.w(TAG, "Unable to prune stale trace file: " + file); 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]);
} }
} }
} }