blob: fd183e4d620086b3a818abc541f8c507b7166ad6 [file] [log] [blame]
Mark Salyzyn0175b072014-02-26 09:50:16 -08001/*
2 * Copyright (C) 2012-2014 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 */
Tom Cherryd5b38382020-05-12 13:16:41 -070016// for manual checking of stale entries during ChattyLogBuffer::erase()
Mark Salyzyn60636fa2016-10-24 16:22:17 -070017//#define DEBUG_CHECK_FOR_STALE_ENTRIES
Mark Salyzyn0175b072014-02-26 09:50:16 -080018
Tom Cherryd5b38382020-05-12 13:16:41 -070019#include "ChattyLogBuffer.h"
20
Mark Salyzyn671e3432014-05-06 07:34:59 -070021#include <ctype.h>
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080022#include <endian.h>
Mark Salyzyn202e1532015-02-09 08:21:05 -080023#include <errno.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080024#include <stdio.h>
25#include <string.h>
Mark Salyzyn8fcfd852016-10-24 08:20:26 -070026#include <sys/cdefs.h>
Mark Salyzyn57a0af92014-05-09 17:44:18 -070027#include <sys/user.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080028#include <time.h>
29#include <unistd.h>
30
Tom Cherryb398a7c2020-05-20 12:09:22 -070031#include <limits>
Mark Salyzyn511338d2015-05-19 09:12:30 -070032#include <unordered_map>
Tom Cherry10d086e2019-08-21 14:16:34 -070033#include <utility>
Mark Salyzyn511338d2015-05-19 09:12:30 -070034
Mark Salyzynf10e2732016-09-27 13:08:23 -070035#include <private/android_logger.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080036
Mark Salyzyna2c02222016-12-13 10:31:29 -080037#include "LogUtils.h"
Mark Salyzyn0175b072014-02-26 09:50:16 -080038
Mark Salyzyn8fcfd852016-10-24 08:20:26 -070039#ifndef __predict_false
40#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
41#endif
42
Tom Cherryd5b38382020-05-12 13:16:41 -070043ChattyLogBuffer::ChattyLogBuffer(LogReaderList* reader_list, LogTags* tags, PruneList* prune,
44 LogStatistics* stats)
Tom Cherry8f613462020-05-12 12:46:43 -070045 : SimpleLogBuffer(reader_list, tags, stats), prune_(prune) {}
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070046
Tom Cherrya26f7df2020-05-19 17:48:42 -070047ChattyLogBuffer::~ChattyLogBuffer() {}
Mark Salyzyna2c02222016-12-13 10:31:29 -080048
Mark Salyzyn501c3732017-03-10 14:31:54 -080049enum match_type { DIFFERENT, SAME, SAME_LIBLOG };
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080050
Tom Cherry9787f9a2020-05-19 19:01:16 -070051static enum match_type Identical(const LogBufferElement& elem, const LogBufferElement& last) {
52 ssize_t lenl = elem.msg_len();
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070053 if (lenl <= 0) return DIFFERENT; // value if this represents a chatty elem
Tom Cherry9787f9a2020-05-19 19:01:16 -070054 ssize_t lenr = last.msg_len();
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070055 if (lenr <= 0) return DIFFERENT; // value if this represents a chatty elem
Tom Cherry9787f9a2020-05-19 19:01:16 -070056 if (elem.uid() != last.uid()) return DIFFERENT;
57 if (elem.pid() != last.pid()) return DIFFERENT;
58 if (elem.tid() != last.tid()) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080059
60 // last is more than a minute old, stop squashing identical messages
Tom Cherry9787f9a2020-05-19 19:01:16 -070061 if (elem.realtime().nsec() > (last.realtime().nsec() + 60 * NS_PER_SEC)) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080062
63 // Identical message
Tom Cherry9787f9a2020-05-19 19:01:16 -070064 const char* msgl = elem.msg();
65 const char* msgr = last.msg();
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080066 if (lenl == lenr) {
67 if (!fastcmp<memcmp>(msgl, msgr, lenl)) return SAME;
68 // liblog tagged messages (content gets summed)
Tom Cherry9787f9a2020-05-19 19:01:16 -070069 if (elem.log_id() == LOG_ID_EVENTS && lenl == sizeof(android_log_event_int_t) &&
Tom Cherryd5b38382020-05-12 13:16:41 -070070 !fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_int_t) - sizeof(int32_t)) &&
Tom Cherry9787f9a2020-05-19 19:01:16 -070071 elem.GetTag() == LIBLOG_LOG_TAG) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080072 return SAME_LIBLOG;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070073 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080074 }
Mark Salyzyna2c02222016-12-13 10:31:29 -080075
76 // audit message (except sequence number) identical?
Tom Cherry3dd3ec32020-06-02 15:39:21 -070077 if (IsBinary(last.log_id()) &&
78 lenl > static_cast<ssize_t>(sizeof(android_log_event_string_t)) &&
Tom Cherryd5b38382020-05-12 13:16:41 -070079 lenr > static_cast<ssize_t>(sizeof(android_log_event_string_t))) {
80 if (fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_string_t) - sizeof(int32_t))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080081 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070082 }
Mark Salyzyna2c02222016-12-13 10:31:29 -080083 msgl += sizeof(android_log_event_string_t);
84 lenl -= sizeof(android_log_event_string_t);
85 msgr += sizeof(android_log_event_string_t);
86 lenr -= sizeof(android_log_event_string_t);
87 }
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070088 static const char avc[] = "): avc: ";
Mark Salyzyn501c3732017-03-10 14:31:54 -080089 const char* avcl = android::strnstr(msgl, lenl, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080090 if (!avcl) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080091 lenl -= avcl - msgl;
Mark Salyzyn501c3732017-03-10 14:31:54 -080092 const char* avcr = android::strnstr(msgr, lenr, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080093 if (!avcr) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080094 lenr -= avcr - msgr;
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080095 if (lenl != lenr) return DIFFERENT;
Tom Cherryd5b38382020-05-12 13:16:41 -070096 if (fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc), lenl - strlen(avc))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080097 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070098 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080099 return SAME;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800100}
101
Tom Cherry8f613462020-05-12 12:46:43 -0700102void ChattyLogBuffer::LogInternal(LogBufferElement&& elem) {
Tom Cherrya26f7df2020-05-19 17:48:42 -0700103 // b/137093665: don't coalesce security messages.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700104 if (elem.log_id() == LOG_ID_SECURITY) {
Tom Cherry8f613462020-05-12 12:46:43 -0700105 SimpleLogBuffer::LogInternal(std::move(elem));
106 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700107 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700108 int log_id = elem.log_id();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700109
Tom Cherrya26f7df2020-05-19 17:48:42 -0700110 // Initialize last_logged_elements_ to a copy of elem if logging the first element for a log_id.
111 if (!last_logged_elements_[log_id]) {
Tom Cherry13224722020-05-19 18:02:00 -0700112 last_logged_elements_[log_id].emplace(elem);
Tom Cherry8f613462020-05-12 12:46:43 -0700113 SimpleLogBuffer::LogInternal(std::move(elem));
114 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700115 }
116
Tom Cherry13224722020-05-19 18:02:00 -0700117 LogBufferElement& current_last = *last_logged_elements_[log_id];
Tom Cherry9787f9a2020-05-19 19:01:16 -0700118 enum match_type match = Identical(elem, current_last);
Tom Cherrya26f7df2020-05-19 17:48:42 -0700119
120 if (match == DIFFERENT) {
121 if (duplicate_elements_[log_id]) {
Tom Cherrya26f7df2020-05-19 17:48:42 -0700122 // If we previously had 3+ identical messages, log the chatty message.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700123 if (duplicate_elements_[log_id]->dropped_count() > 0) {
Tom Cherry8f613462020-05-12 12:46:43 -0700124 SimpleLogBuffer::LogInternal(std::move(*duplicate_elements_[log_id]));
Mark Salyzyna2c02222016-12-13 10:31:29 -0800125 }
Tom Cherry13224722020-05-19 18:02:00 -0700126 duplicate_elements_[log_id].reset();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700127 // Log the saved copy of the last identical message seen.
Tom Cherry8f613462020-05-12 12:46:43 -0700128 SimpleLogBuffer::LogInternal(std::move(current_last));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700129 }
Tom Cherry13224722020-05-19 18:02:00 -0700130 last_logged_elements_[log_id].emplace(elem);
Tom Cherry8f613462020-05-12 12:46:43 -0700131 SimpleLogBuffer::LogInternal(std::move(elem));
132 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700133 }
134
135 // 2 identical message: set duplicate_elements_ appropriately.
136 if (!duplicate_elements_[log_id]) {
Tom Cherry13224722020-05-19 18:02:00 -0700137 duplicate_elements_[log_id].emplace(std::move(current_last));
138 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700139 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700140 }
141
142 // 3+ identical LIBLOG event messages: coalesce them into last_logged_elements_.
143 if (match == SAME_LIBLOG) {
144 const android_log_event_int_t* current_last_event =
Tom Cherry9787f9a2020-05-19 19:01:16 -0700145 reinterpret_cast<const android_log_event_int_t*>(current_last.msg());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700146 int64_t current_last_count = current_last_event->payload.data;
147 android_log_event_int_t* elem_event =
Tom Cherry9787f9a2020-05-19 19:01:16 -0700148 reinterpret_cast<android_log_event_int_t*>(const_cast<char*>(elem.msg()));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700149 int64_t elem_count = elem_event->payload.data;
150
151 int64_t total = current_last_count + elem_count;
152 if (total > std::numeric_limits<int32_t>::max()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700153 SimpleLogBuffer::LogInternal(std::move(current_last));
Tom Cherry13224722020-05-19 18:02:00 -0700154 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700155 return;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800156 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700157 stats()->AddTotal(current_last.log_id(), current_last.msg_len());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700158 elem_event->payload.data = total;
Tom Cherry13224722020-05-19 18:02:00 -0700159 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700160 return;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800161 }
Mark Salyzyn0175b072014-02-26 09:50:16 -0800162
Tom Cherrya26f7df2020-05-19 17:48:42 -0700163 // 3+ identical messages (not LIBLOG) messages: increase the drop count.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700164 uint16_t dropped_count = duplicate_elements_[log_id]->dropped_count();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700165 if (dropped_count == std::numeric_limits<uint16_t>::max()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700166 SimpleLogBuffer::LogInternal(std::move(*duplicate_elements_[log_id]));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700167 dropped_count = 0;
168 }
169 // We're dropping the current_last log so add its stats to the total.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700170 stats()->AddTotal(current_last.log_id(), current_last.msg_len());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700171 // Use current_last for tracking the dropped count to always use the latest timestamp.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700172 current_last.SetDropped(dropped_count + 1);
Tom Cherry13224722020-05-19 18:02:00 -0700173 duplicate_elements_[log_id].emplace(std::move(current_last));
174 last_logged_elements_[log_id].emplace(std::move(elem));
Mark Salyzyna2c02222016-12-13 10:31:29 -0800175}
176
Tom Cherry8f613462020-05-12 12:46:43 -0700177LogBufferElementCollection::iterator ChattyLogBuffer::Erase(LogBufferElementCollection::iterator it,
Tom Cherryd5b38382020-05-12 13:16:41 -0700178 bool coalesce) {
Tom Cherry13224722020-05-19 18:02:00 -0700179 LogBufferElement& element = *it;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700180 log_id_t id = element.log_id();
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700181
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700182 // Remove iterator references in the various lists that will become stale
183 // after the element is erased from the main logging list.
184
Mark Salyzyn501c3732017-03-10 14:31:54 -0800185 { // start of scope for found iterator
Tom Cherry9787f9a2020-05-19 19:01:16 -0700186 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element.GetTag() : element.uid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700187 LogBufferIteratorMap::iterator found = mLastWorst[id].find(key);
188 if ((found != mLastWorst[id].end()) && (it == found->second)) {
189 mLastWorst[id].erase(found);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700190 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700191 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700192
Mark Salyzyn501c3732017-03-10 14:31:54 -0800193 { // start of scope for pid found iterator
Tom Cherry9787f9a2020-05-19 19:01:16 -0700194 // element->uid() may not be AID_SYSTEM for next-best-watermark.
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700195 // will not assume id != LOG_ID_EVENTS or LOG_ID_SECURITY for KISS and
196 // long term code stability, find() check should be fast for those ids.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700197 LogBufferPidIteratorMap::iterator found = mLastWorstPidOfSystem[id].find(element.pid());
Tom Cherryd5b38382020-05-12 13:16:41 -0700198 if (found != mLastWorstPidOfSystem[id].end() && it == found->second) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700199 mLastWorstPidOfSystem[id].erase(found);
200 }
201 }
202
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700203#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
204 LogBufferElementCollection::iterator bad = it;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700205 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element->GetTag() : element->uid();
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700206#endif
Tom Cherry13224722020-05-19 18:02:00 -0700207
208 if (coalesce) {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700209 stats()->Erase(element.ToLogStatisticsElement());
Tom Cherry13224722020-05-19 18:02:00 -0700210 } else {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700211 stats()->Subtract(element.ToLogStatisticsElement());
Tom Cherry13224722020-05-19 18:02:00 -0700212 }
213
Tom Cherry8f613462020-05-12 12:46:43 -0700214 it = SimpleLogBuffer::Erase(it);
Tom Cherry13224722020-05-19 18:02:00 -0700215
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700216#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
217 log_id_for_each(i) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800218 for (auto b : mLastWorst[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700219 if (bad == b.second) {
Tom Cherryf93b4002020-06-03 09:23:49 -0700220 LOG(ERROR) << StringPrintf("stale mLastWorst[%d] key=%d mykey=%d", i, b.first, key);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700221 }
222 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800223 for (auto b : mLastWorstPidOfSystem[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700224 if (bad == b.second) {
Tom Cherryf93b4002020-06-03 09:23:49 -0700225 LOG(ERROR) << StringPrintf("stale mLastWorstPidOfSystem[%d] pid=%d", i, b.first);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700226 }
227 }
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700228 }
229#endif
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700230 return it;
231}
232
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700233// Define a temporary mechanism to report the last LogBufferElement pointer
234// for the specified uid, pid and tid. Used below to help merge-sort when
235// pruning for worst UID.
Mark Salyzyn511338d2015-05-19 09:12:30 -0700236class LogBufferElementLast {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800237 typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap;
Mark Salyzyn511338d2015-05-19 09:12:30 -0700238 LogBufferElementMap map;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700239
Tom Cherryd5b38382020-05-12 13:16:41 -0700240 public:
Chih-Hung Hsieh08d470b2018-08-13 14:22:56 -0700241 bool coalesce(LogBufferElement* element, uint16_t dropped) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700242 uint64_t key = LogBufferElementKey(element->uid(), element->pid(), element->tid());
Tom Cherrya5151972020-05-15 11:39:58 -0700243 LogBufferElementMap::iterator it = map.find(key);
Mark Salyzyn511338d2015-05-19 09:12:30 -0700244 if (it != map.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800245 LogBufferElement* found = it->second;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700246 uint16_t moreDropped = found->dropped_count();
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700247 if ((dropped + moreDropped) > USHRT_MAX) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700248 map.erase(it);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700249 } else {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700250 found->SetDropped(dropped + moreDropped);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700251 return true;
252 }
253 }
254 return false;
255 }
256
Mark Salyzyn501c3732017-03-10 14:31:54 -0800257 void add(LogBufferElement* element) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700258 uint64_t key = LogBufferElementKey(element->uid(), element->pid(), element->tid());
Tom Cherrya5151972020-05-15 11:39:58 -0700259 map[key] = element;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700260 }
261
Tom Cherryd5b38382020-05-12 13:16:41 -0700262 void clear() { map.clear(); }
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700263
Mark Salyzyn501c3732017-03-10 14:31:54 -0800264 void clear(LogBufferElement* element) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700265 uint64_t current = element->realtime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC);
Mark Salyzyn501c3732017-03-10 14:31:54 -0800266 for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) {
267 LogBufferElement* mapElement = it->second;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700268 if (mapElement->dropped_count() >= EXPIRE_THRESHOLD &&
269 current > mapElement->realtime().nsec()) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700270 it = map.erase(it);
271 } else {
272 ++it;
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700273 }
274 }
275 }
Tom Cherrya5151972020-05-15 11:39:58 -0700276
277 private:
278 uint64_t LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid) {
279 return uint64_t(uid) << 32 | uint64_t(pid) << 16 | uint64_t(tid);
280 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700281};
282
Mark Salyzyn0175b072014-02-26 09:50:16 -0800283// prune "pruneRows" of type "id" from the buffer.
284//
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700285// This garbage collection task is used to expire log entries. It is called to
286// remove all logs (clear), all UID logs (unprivileged clear), or every
287// 256 or 10% of the total logs (whichever is less) to prune the logs.
288//
289// First there is a prep phase where we discover the reader region lock that
290// acts as a backstop to any pruning activity to stop there and go no further.
291//
292// There are three major pruning loops that follow. All expire from the oldest
293// entries. Since there are multiple log buffers, the Android logging facility
294// will appear to drop entries 'in the middle' when looking at multiple log
295// sources and buffers. This effect is slightly more prominent when we prune
296// the worst offender by logging source. Thus the logs slowly loose content
297// and value as you move back in time. This is preferred since chatty sources
298// invariably move the logs value down faster as less chatty sources would be
299// expired in the noise.
300//
Tom Cherry0efb4102020-06-16 10:14:09 -0700301// The first pass prunes elements that match 3 possible rules:
302// 1) A high priority prune rule, for example ~100/20, which indicates elements from UID 100 and PID
303// 20 should be pruned in this first pass.
304// 2) The default chatty pruning rule, ~!. This rule sums the total size spent on log messages for
305// each UID this log buffer. If the highest sum consumes more than 12.5% of the log buffer, then
306// these elements from that UID are pruned.
307// 3) The default AID_SYSTEM pruning rule, ~1000/!. This rule is a special case to 2), if
308// AID_SYSTEM is the top consumer of the log buffer, then this rule sums the total size spent on
309// log messages for each PID in AID_SYSTEM in this log buffer and prunes elements from the PID
310// with the highest sum.
311// This pass reevaluates the sums for rules 2) and 3) for every log message pruned. It creates
312// 'chatty' entries for the elements that it prunes and merges related chatty entries together. It
313// completes when one of three conditions have been met:
314// 1) The requested element count has been pruned.
315// 2) There are no elements that match any of these rules.
316// 3) A reader is referencing the oldest element that would match these rules.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700317//
Tom Cherry0efb4102020-06-16 10:14:09 -0700318// The second pass prunes elements starting from the beginning of the log. It skips elements that
319// match any low priority prune rules. It completes when one of three conditions have been met:
320// 1) The requested element count has been pruned.
321// 2) All elements except those mwatching low priority prune rules have been pruned.
322// 3) A reader is referencing the oldest element that would match these rules.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700323//
Tom Cherry0efb4102020-06-16 10:14:09 -0700324// The final pass only happens if there are any low priority prune rules and if the first two passes
325// were unable to prune the requested number of elements. It prunes elements all starting from the
326// beginning of the log, regardless of if they match any low priority prune rules.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700327//
Tom Cherry0efb4102020-06-16 10:14:09 -0700328// If the requested number of logs was unable to be pruned, KickReader() is called to mitigate the
329// situation before the next call to Prune() and the function returns false. Otherwise, if the
330// requested number of logs or all logs present in the buffer are pruned, in the case of Clear(),
331// it returns true.
Tom Cherry8f613462020-05-12 12:46:43 -0700332bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
Tom Cherry6ec71e92020-05-04 12:53:36 -0700333 LogReaderThread* oldest = nullptr;
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700334 bool clearAll = pruneRows == ULONG_MAX;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800335
Tom Cherry8f613462020-05-12 12:46:43 -0700336 auto reader_threads_lock = std::lock_guard{reader_list()->reader_threads_lock()};
Mark Salyzyn0175b072014-02-26 09:50:16 -0800337
338 // Region locked?
Tom Cherry8f613462020-05-12 12:46:43 -0700339 for (const auto& reader_thread : reader_list()->reader_threads()) {
Tom Cherry68630a02020-05-11 16:29:29 -0700340 if (!reader_thread->IsWatching(id)) {
341 continue;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800342 }
Tom Cherry68630a02020-05-11 16:29:29 -0700343 if (!oldest || oldest->start() > reader_thread->start() ||
344 (oldest->start() == reader_thread->start() &&
345 reader_thread->deadline().time_since_epoch().count() != 0)) {
346 oldest = reader_thread.get();
347 }
Mark Salyzyn0175b072014-02-26 09:50:16 -0800348 }
349
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800350 LogBufferElementCollection::iterator it;
351
Mark Salyzyn501c3732017-03-10 14:31:54 -0800352 if (__predict_false(caller_uid != AID_ROOT)) { // unlikely
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700353 // Only here if clear all request from non system source, so chatty
354 // filter logistics is not required.
Tom Cherry385c2c92020-04-29 17:58:18 -0700355 it = GetOldest(id);
Tom Cherry8f613462020-05-12 12:46:43 -0700356 while (it != logs().end()) {
Tom Cherry13224722020-05-19 18:02:00 -0700357 LogBufferElement& element = *it;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700358
Tom Cherry9787f9a2020-05-19 19:01:16 -0700359 if (element.log_id() != id || element.uid() != caller_uid) {
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700360 ++it;
361 continue;
362 }
363
Tom Cherry9787f9a2020-05-19 19:01:16 -0700364 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700365 KickReader(oldest, id, pruneRows);
Tom Cherrya863b1a2020-06-10 14:52:46 -0700366 return false;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700367 }
368
Tom Cherry8f613462020-05-12 12:46:43 -0700369 it = Erase(it);
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700370 if (--pruneRows == 0) {
Tom Cherrya863b1a2020-06-10 14:52:46 -0700371 return true;
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700372 }
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700373 }
Tom Cherrya863b1a2020-06-10 14:52:46 -0700374 return true;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700375 }
376
Tom Cherry0efb4102020-06-16 10:14:09 -0700377 // First prune pass.
378 bool check_high_priority = id != LOG_ID_SECURITY && prune_->HasHighPriorityPruneRules();
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700379 while (!clearAll && (pruneRows > 0)) {
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800380 // recalculate the worst offender on every batched pass
Tom Cherry9787f9a2020-05-19 19:01:16 -0700381 int worst = -1; // not valid for uid() or getKey()
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800382 size_t worst_sizes = 0;
383 size_t second_worst_sizes = 0;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800384 pid_t worstPid = 0; // POSIX guarantees PID != 0
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800385
Tom Cherry0efb4102020-06-16 10:14:09 -0700386 if (worstUidEnabledForLogid(id) && prune_->worst_uid_enabled()) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700387 // Calculate threshold as 12.5% of available storage
Tom Cherry8f613462020-05-12 12:46:43 -0700388 size_t threshold = max_size(id) / 8;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700389
Tom Cherryb6b78e92020-05-07 09:13:12 -0700390 if (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) {
Tom Cherry8f613462020-05-12 12:46:43 -0700391 stats()->WorstTwoTags(threshold, &worst, &worst_sizes, &second_worst_sizes);
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700392 // per-pid filter for AID_SYSTEM sources is too complex
Mark Salyzyn6a066942016-07-14 15:34:30 -0700393 } else {
Tom Cherry8f613462020-05-12 12:46:43 -0700394 stats()->WorstTwoUids(id, threshold, &worst, &worst_sizes, &second_worst_sizes);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700395
Tom Cherry0efb4102020-06-16 10:14:09 -0700396 if (worst == AID_SYSTEM && prune_->worst_pid_of_system_enabled()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700397 stats()->WorstTwoSystemPids(id, worst_sizes, &worstPid, &second_worst_sizes);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700398 }
399 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800400 }
401
Tom Cherry0efb4102020-06-16 10:14:09 -0700402 // skip if we have neither a worst UID or high priority prune rules
403 if (worst == -1 && !check_high_priority) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700404 break;
405 }
406
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800407 bool kick = false;
Tom Cherry385c2c92020-04-29 17:58:18 -0700408 bool leading = true; // true if starting from the oldest log entry, false if starting from
409 // a specific chatty entry.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700410 // Perform at least one mandatory garbage collection cycle in following
411 // - clear leading chatty tags
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700412 // - coalesce chatty tags
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700413 // - check age-out of preserved logs
414 bool gc = pruneRows <= 1;
Mark Salyzyn6a066942016-07-14 15:34:30 -0700415 if (!gc && (worst != -1)) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800416 { // begin scope for worst found iterator
Tom Cherryd5b38382020-05-12 13:16:41 -0700417 LogBufferIteratorMap::iterator found = mLastWorst[id].find(worst);
Tom Cherry8f613462020-05-12 12:46:43 -0700418 if (found != mLastWorst[id].end() && found->second != logs().end()) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700419 leading = false;
420 it = found->second;
421 }
422 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800423 if (worstPid) { // begin scope for pid worst found iterator
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700424 // FYI: worstPid only set if !LOG_ID_EVENTS and
425 // !LOG_ID_SECURITY, not going to make that assumption ...
Tom Cherryd5b38382020-05-12 13:16:41 -0700426 LogBufferPidIteratorMap::iterator found = mLastWorstPidOfSystem[id].find(worstPid);
Tom Cherry8f613462020-05-12 12:46:43 -0700427 if (found != mLastWorstPidOfSystem[id].end() && found->second != logs().end()) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700428 leading = false;
429 it = found->second;
430 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700431 }
432 }
Tom Cherry385c2c92020-04-29 17:58:18 -0700433 if (leading) {
434 it = GetOldest(id);
435 }
Tom Cherrybd80e562020-05-18 08:58:50 -0700436 static const log_time too_old{EXPIRE_HOUR_THRESHOLD * 60 * 60, 0};
Mark Salyzynccfe8442015-08-24 13:43:27 -0700437 LogBufferElementCollection::iterator lastt;
Tom Cherry8f613462020-05-12 12:46:43 -0700438 lastt = logs().end();
Mark Salyzynccfe8442015-08-24 13:43:27 -0700439 --lastt;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700440 LogBufferElementLast last;
Tom Cherry8f613462020-05-12 12:46:43 -0700441 while (it != logs().end()) {
Tom Cherry13224722020-05-19 18:02:00 -0700442 LogBufferElement& element = *it;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800443
Tom Cherry9787f9a2020-05-19 19:01:16 -0700444 if (oldest && oldest->start() <= element.sequence()) {
Mark Salyzyn0878a7c2017-05-11 13:28:33 -0700445 // Do not let chatty eliding trigger any reader mitigation
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800446 break;
447 }
448
Tom Cherry9787f9a2020-05-19 19:01:16 -0700449 if (element.log_id() != id) {
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800450 ++it;
451 continue;
452 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700453 // below this point element->log_id() == id
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800454
Tom Cherry9787f9a2020-05-19 19:01:16 -0700455 uint16_t dropped = element.dropped_count();
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800456
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700457 // remove any leading drops
458 if (leading && dropped) {
Tom Cherry8f613462020-05-12 12:46:43 -0700459 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700460 continue;
461 }
462
Tom Cherry13224722020-05-19 18:02:00 -0700463 if (dropped && last.coalesce(&element, dropped)) {
Tom Cherry8f613462020-05-12 12:46:43 -0700464 it = Erase(it, true);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700465 continue;
466 }
467
Tom Cherry9787f9a2020-05-19 19:01:16 -0700468 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element.GetTag()
469 : element.uid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700470
Tom Cherry0efb4102020-06-16 10:14:09 -0700471 if (check_high_priority && prune_->IsHighPriority(&element)) {
Tom Cherry13224722020-05-19 18:02:00 -0700472 last.clear(&element);
Tom Cherry8f613462020-05-12 12:46:43 -0700473 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700474 if (dropped) {
475 continue;
476 }
477
478 pruneRows--;
479 if (pruneRows == 0) {
480 break;
481 }
482
Mark Salyzyn6a066942016-07-14 15:34:30 -0700483 if (key == worst) {
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700484 kick = true;
485 if (worst_sizes < second_worst_sizes) {
486 break;
487 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700488 worst_sizes -= element.msg_len();
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700489 }
490 continue;
491 }
492
Tom Cherry9787f9a2020-05-19 19:01:16 -0700493 if (element.realtime() < (lastt->realtime() - too_old) ||
494 element.realtime() > lastt->realtime()) {
Mark Salyzynccfe8442015-08-24 13:43:27 -0700495 break;
496 }
497
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700498 if (dropped) {
Tom Cherry13224722020-05-19 18:02:00 -0700499 last.add(&element);
Tom Cherry9787f9a2020-05-19 19:01:16 -0700500 if (worstPid && ((!gc && element.pid() == worstPid) ||
501 mLastWorstPidOfSystem[id].find(element.pid()) ==
Tom Cherryd5b38382020-05-12 13:16:41 -0700502 mLastWorstPidOfSystem[id].end())) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700503 // element->uid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700504 // watermark if current one empty. id is not LOG_ID_EVENTS
505 // or LOG_ID_SECURITY because of worstPid check.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700506 mLastWorstPidOfSystem[id][element.pid()] = it;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700507 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800508 if ((!gc && !worstPid && (key == worst)) ||
509 (mLastWorst[id].find(key) == mLastWorst[id].end())) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700510 mLastWorst[id][key] = it;
Mark Salyzyn49afe0d2015-08-24 13:43:27 -0700511 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800512 ++it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700513 continue;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800514 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700515
Tom Cherry9787f9a2020-05-19 19:01:16 -0700516 if (key != worst || (worstPid && element.pid() != worstPid)) {
Mark Salyzyn59212762015-06-01 09:41:19 -0700517 leading = false;
Tom Cherry13224722020-05-19 18:02:00 -0700518 last.clear(&element);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700519 ++it;
520 continue;
521 }
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700522 // key == worst below here
Tom Cherry9787f9a2020-05-19 19:01:16 -0700523 // If worstPid set, then element->pid() == worstPid below here
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700524
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700525 pruneRows--;
526 if (pruneRows == 0) {
527 break;
528 }
529
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700530 kick = true;
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700531
Tom Cherry9787f9a2020-05-19 19:01:16 -0700532 uint16_t len = element.msg_len();
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700533
534 // do not create any leading drops
535 if (leading) {
Tom Cherry8f613462020-05-12 12:46:43 -0700536 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700537 } else {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700538 stats()->Drop(element.ToLogStatisticsElement());
Tom Cherry9787f9a2020-05-19 19:01:16 -0700539 element.SetDropped(1);
Tom Cherry13224722020-05-19 18:02:00 -0700540 if (last.coalesce(&element, 1)) {
Tom Cherry8f613462020-05-12 12:46:43 -0700541 it = Erase(it, true);
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700542 } else {
Tom Cherry13224722020-05-19 18:02:00 -0700543 last.add(&element);
Tom Cherryd5b38382020-05-12 13:16:41 -0700544 if (worstPid && (!gc || mLastWorstPidOfSystem[id].find(worstPid) ==
545 mLastWorstPidOfSystem[id].end())) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700546 // element->uid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700547 // watermark if current one empty. id is not
548 // LOG_ID_EVENTS or LOG_ID_SECURITY because of worstPid.
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700549 mLastWorstPidOfSystem[id][worstPid] = it;
550 }
Tom Cherryd5b38382020-05-12 13:16:41 -0700551 if ((!gc && !worstPid) || mLastWorst[id].find(worst) == mLastWorst[id].end()) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700552 mLastWorst[id][worst] = it;
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700553 }
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700554 ++it;
555 }
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700556 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700557 if (worst_sizes < second_worst_sizes) {
558 break;
559 }
560 worst_sizes -= len;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800561 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700562 last.clear();
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800563
Tom Cherry0efb4102020-06-16 10:14:09 -0700564 if (!kick || !prune_->worst_uid_enabled()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800565 break; // the following loop will ask bad clients to skip/drop
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800566 }
567 }
568
Tom Cherry0efb4102020-06-16 10:14:09 -0700569 // Second prune pass.
570 bool skipped_low_priority_prune = false;
571 bool check_low_priority =
572 id != LOG_ID_SECURITY && prune_->HasLowPriorityPruneRules() && !clearAll;
Tom Cherry385c2c92020-04-29 17:58:18 -0700573 it = GetOldest(id);
Tom Cherry0efb4102020-06-16 10:14:09 -0700574 while (pruneRows > 0 && it != logs().end()) {
Tom Cherry13224722020-05-19 18:02:00 -0700575 LogBufferElement& element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700576
Tom Cherry9787f9a2020-05-19 19:01:16 -0700577 if (element.log_id() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700578 it++;
579 continue;
580 }
581
Tom Cherry9787f9a2020-05-19 19:01:16 -0700582 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry0efb4102020-06-16 10:14:09 -0700583 if (!skipped_low_priority_prune) KickReader(oldest, id, pruneRows);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700584 break;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800585 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700586
Tom Cherry0efb4102020-06-16 10:14:09 -0700587 if (check_low_priority && !element.dropped_count() && prune_->IsLowPriority(&element)) {
588 skipped_low_priority_prune = true;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700589 it++;
590 continue;
591 }
592
Tom Cherry8f613462020-05-12 12:46:43 -0700593 it = Erase(it);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700594 pruneRows--;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800595 }
596
Tom Cherry0efb4102020-06-16 10:14:09 -0700597 // Third prune pass.
598 if (skipped_low_priority_prune && pruneRows > 0) {
Tom Cherry385c2c92020-04-29 17:58:18 -0700599 it = GetOldest(id);
Tom Cherry0efb4102020-06-16 10:14:09 -0700600 while (it != logs().end() && pruneRows > 0) {
Tom Cherry13224722020-05-19 18:02:00 -0700601 LogBufferElement& element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700602
Tom Cherry9787f9a2020-05-19 19:01:16 -0700603 if (element.log_id() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700604 ++it;
605 continue;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800606 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700607
Tom Cherry9787f9a2020-05-19 19:01:16 -0700608 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700609 KickReader(oldest, id, pruneRows);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700610 break;
611 }
612
Tom Cherry8f613462020-05-12 12:46:43 -0700613 it = Erase(it);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700614 pruneRows--;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800615 }
616 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800617
Tom Cherrya863b1a2020-06-10 14:52:46 -0700618 return pruneRows == 0 || it == logs().end();
Mark Salyzyn0175b072014-02-26 09:50:16 -0800619}