logd: create FlushToState class
ChattyLogBuffer::FlushTo() needs an array of pid_t's to differentiate
between deduplication and spam removal chatty messages, but that won't
be useful to other log buffers, so it doesn't deserve its own entry in
the abstruct LogBuffer::FlushTo() function.
Other log buffers may need their own data stored for each reader, so
we create an interface that the reader itself owns and passes to the
log buffer. It uses a unique_ptr, such that the when the reader is
destroyed, so will this state.
FlushToState will additionally contain the start point, that it will
increment itself and the log mask, which LogBuffers can use to
efficiently keep track of the next elements that will be read during a
call to FlushTo().
Side benefit: this allows ChattyLogBufferTests to correctly report
'identical' instead of 'expired' lines the deduplication tests.
Side benefit #2: This updates LogReaderThread::start() more
aggressively, which should result in readers being disconnected less
often, particularly readers who read only a certain UID.
Test: logging unit tests
Change-Id: I969565eb2996afb1431f20e7ccaaa906fcb8f6d1
diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp
index 35c46aa..fc461fd 100644
--- a/logd/LogReader.cpp
+++ b/logd/LogReader.cpp
@@ -171,16 +171,12 @@
if (start != log_time::EPOCH) {
bool start_time_set = false;
uint64_t last = sequence;
- auto log_find_start = [pid, logMask, start, &sequence, &start_time_set, &last](
- log_id_t element_log_id, pid_t element_pid,
- uint64_t element_sequence, log_time element_realtime,
- uint16_t) -> FilterResult {
+ auto log_find_start = [pid, start, &sequence, &start_time_set, &last](
+ log_id_t, pid_t element_pid, uint64_t element_sequence,
+ log_time element_realtime, uint16_t) -> FilterResult {
if (pid && pid != element_pid) {
return FilterResult::kSkip;
}
- if ((logMask & (1 << element_log_id)) == 0) {
- return FilterResult::kSkip;
- }
if (start == element_realtime) {
sequence = element_sequence;
start_time_set = true;
@@ -195,8 +191,8 @@
}
return FilterResult::kSkip;
};
-
- log_buffer_->FlushTo(socket_log_writer.get(), sequence, nullptr, log_find_start);
+ auto flush_to_state = log_buffer_->CreateFlushToState(sequence, logMask);
+ log_buffer_->FlushTo(socket_log_writer.get(), *flush_to_state, log_find_start);
if (!start_time_set) {
if (nonBlock) {