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
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2020 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "LogReaderList.h"
|
|
|
|
// When we are notified a new log entry is available, inform
|
|
// listening sockets who are watching this entry's log id.
|
|
void LogReaderList::NotifyNewLog(LogMask log_mask) const {
|
|
auto lock = std::lock_guard{reader_threads_lock_};
|
|
|
|
for (const auto& entry : reader_threads_) {
|
|
if (!entry->IsWatchingMultiple(log_mask)) {
|
|
continue;
|
|
}
|
|
if (entry->deadline().time_since_epoch().count() != 0) {
|
|
continue;
|
|
}
|
|
entry->triggerReader_Locked();
|
|
}
|
|
}
|