Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ec71e92 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: rename LogTimes -> LogReaderThread

LogTimes has evolved from being simply a store of the last timestamp
that each reader has read to being a class representing an individual
reader thread, including the thread function, so name it
appropriately.

Test: logging unit tests
Change-Id: I6914824376a6ff1f7509e657fa4dc044ead62954
parent 794acfc0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,9 +36,9 @@ cc_library_static {
        "CommandListener.cpp",
        "LogListener.cpp",
        "LogReader.cpp",
        "LogReaderThread.cpp",
        "LogBuffer.cpp",
        "LogBufferElement.cpp",
        "LogTimes.cpp",
        "LogStatistics.cpp",
        "LogWhiteBlackList.cpp",
        "libaudit.c",
+12 −12
Original line number Diff line number Diff line
@@ -93,16 +93,16 @@ void LogBuffer::init() {
    }

    // Release any sleeping reader threads to dump their current content.
    LogTimeEntry::wrlock();
    LogReaderThread::wrlock();

    LastLogTimes::iterator times = mTimes.begin();
    while (times != mTimes.end()) {
        LogTimeEntry* entry = times->get();
        LogReaderThread* entry = times->get();
        entry->triggerReader_Locked();
        times++;
    }

    LogTimeEntry::unlock();
    LogReaderThread::unlock();
}

LogBuffer::LogBuffer(LastLogTimes* times, LogTags* tags, PruneList* prune)
@@ -579,7 +579,7 @@ class LogBufferElementLast {

// If the selected reader is blocking our pruning progress, decide on
// what kind of mitigation is necessary to unblock the situation.
void LogBuffer::kickMe(LogTimeEntry* me, log_id_t id, unsigned long pruneRows) {
void LogBuffer::kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows) {
    if (stats.sizes(id) > (2 * log_buffer_size(id))) {  // +100%
        // A misbehaving or slow reader has its connection
        // dropped if we hit too much memory pressure.
@@ -647,16 +647,16 @@ void LogBuffer::kickMe(LogTimeEntry* me, log_id_t id, unsigned long pruneRows) {
// LogBuffer::wrlock() must be held when this function is called.
//
bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
    LogTimeEntry* oldest = nullptr;
    LogReaderThread* oldest = nullptr;
    bool busy = false;
    bool clearAll = pruneRows == ULONG_MAX;

    LogTimeEntry::rdlock();
    LogReaderThread::rdlock();

    // Region locked?
    LastLogTimes::iterator times = mTimes.begin();
    while (times != mTimes.end()) {
        LogTimeEntry* entry = times->get();
        LogReaderThread* entry = times->get();
        if (entry->isWatching(id) &&
            (!oldest || (oldest->mStart > entry->mStart) ||
             ((oldest->mStart == entry->mStart) &&
@@ -692,7 +692,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
                break;
            }
        }
        LogTimeEntry::unlock();
        LogReaderThread::unlock();
        return busy;
    }

@@ -953,7 +953,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
        }
    }

    LogTimeEntry::unlock();
    LogReaderThread::unlock();

    return (pruneRows > 0) && busy;
}
@@ -976,10 +976,10 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) {
            // readers and let the clear run (below) deal with determining
            // if we are still blocked and return an error code to caller.
            if (busy) {
                LogTimeEntry::wrlock();
                LogReaderThread::wrlock();
                LastLogTimes::iterator times = mTimes.begin();
                while (times != mTimes.end()) {
                    LogTimeEntry* entry = times->get();
                    LogReaderThread* entry = times->get();
                    // Killer punch
                    if (entry->isWatching(id)) {
                        android::prdebug(
@@ -989,7 +989,7 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) {
                    }
                    times++;
                }
                LogTimeEntry::unlock();
                LogReaderThread::unlock();
            }
        }
        wrlock();
+2 −2
Original line number Diff line number Diff line
@@ -27,9 +27,9 @@
#include <sysutils/SocketClient.h>

#include "LogBufferElement.h"
#include "LogReaderThread.h"
#include "LogStatistics.h"
#include "LogTags.h"
#include "LogTimes.h"
#include "LogWhiteBlackList.h"

//
@@ -152,7 +152,7 @@ class LogBuffer {
    static constexpr size_t maxPrune = 256;

    void maybePrune(log_id_t id);
    void kickMe(LogTimeEntry* me, log_id_t id, unsigned long pruneRows);
    void kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows);

    bool prune(log_id_t id, unsigned long pruneRows, uid_t uid = AID_ROOT);
    LogBufferElementCollection::iterator erase(
+16 −15
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ LogReader::LogReader(LogBuffer* logbuf)
void LogReader::notifyNewLog(log_mask_t log_mask) {
    LastLogTimes& times = mLogbuf.mTimes;

    LogTimeEntry::wrlock();
    LogReaderThread::wrlock();
    for (const auto& entry : times) {
        if (!entry->isWatchingMultiple(log_mask)) {
            continue;
@@ -52,7 +52,7 @@ void LogReader::notifyNewLog(log_mask_t log_mask) {
        }
        entry->triggerReader_Locked();
    }
    LogTimeEntry::unlock();
    LogReaderThread::unlock();
}

// Note returning false will release the SocketClient instance.
@@ -74,15 +74,15 @@ bool LogReader::onDataAvailable(SocketClient* cli) {

    // Clients are only allowed to send one command, disconnect them if they
    // send another.
    LogTimeEntry::wrlock();
    LogReaderThread::wrlock();
    for (const auto& entry : mLogbuf.mTimes) {
        if (entry->mClient == cli) {
            entry->release_Locked();
            LogTimeEntry::unlock();
            LogReaderThread::unlock();
            return false;
        }
    }
    LogTimeEntry::unlock();
    LogReaderThread::unlock();

    unsigned long tail = 0;
    static const char _tail[] = " tail=";
@@ -137,8 +137,8 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
    if (!fastcmp<strncmp>(buffer, "dumpAndClose", 12)) {
        // Allow writer to get some cycles, and wait for pending notifications
        sched_yield();
        LogTimeEntry::wrlock();
        LogTimeEntry::unlock();
        LogReaderThread::wrlock();
        LogReaderThread::unlock();
        sched_yield();
        nonBlock = true;
    }
@@ -217,11 +217,12 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
        timeout = 0;
    }

    LogTimeEntry::wrlock();
    auto entry = std::make_unique<LogTimeEntry>(*this, cli, nonBlock, tail, logMask, pid, start,
    LogReaderThread::wrlock();
    auto entry =
            std::make_unique<LogReaderThread>(*this, cli, nonBlock, tail, logMask, pid, start,
                                              sequence, timeout, privileged, can_read_security);
    if (!entry->startReader_Locked()) {
        LogTimeEntry::unlock();
        LogReaderThread::unlock();
        return false;
    }

@@ -234,24 +235,24 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
    setsockopt(cli->getSocket(), SOL_SOCKET, SO_SNDTIMEO, (const char*)&t,
               sizeof(t));

    LogTimeEntry::unlock();
    LogReaderThread::unlock();

    return true;
}

void LogReader::doSocketDelete(SocketClient* cli) {
    LastLogTimes& times = mLogbuf.mTimes;
    LogTimeEntry::wrlock();
    LogReaderThread::wrlock();
    LastLogTimes::iterator it = times.begin();
    while (it != times.end()) {
        LogTimeEntry* entry = it->get();
        LogReaderThread* entry = it->get();
        if (entry->mClient == cli) {
            entry->release_Locked();
            break;
        }
        it++;
    }
    LogTimeEntry::unlock();
    LogReaderThread::unlock();
}

int LogReader::getLogSocket() {
+2 −5
Original line number Diff line number Diff line
@@ -14,12 +14,11 @@
 * limitations under the License.
 */

#ifndef _LOGD_LOG_WRITER_H__
#define _LOGD_LOG_WRITER_H__
#pragma once

#include <sysutils/SocketListener.h>

#include "LogTimes.h"
#include "LogReaderThread.h"

#define LOGD_SNDTIMEO 32

@@ -44,5 +43,3 @@ class LogReader : public SocketListener {

    void doSocketDelete(SocketClient* cli);
};

#endif
Loading