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

Commit a5151972 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: build liblogd and its test on host

Plus the various fixups needed for building on host.

Test: run these tests on host
Change-Id: I85e6c989068f80c5a80eaf5ad149fdad0a045c08
parent 43f3f761
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ cc_defaults {
cc_library_static {
    name: "liblogd",
    defaults: ["logd_defaults"],

    host_supported: true,
    srcs: [
        "ChattyLogBuffer.cpp",
        "LogReaderList.cpp",
@@ -148,6 +148,7 @@ cc_defaults {
//   adb shell /data/nativetest/logd-unit-tests/logd-unit-tests
cc_test {
    name: "logd-unit-tests",
    host_supported: true,
    defaults: ["logd-unit-test-defaults"],
}

+9 −21
Original line number Diff line number Diff line
@@ -426,31 +426,14 @@ LogBufferElementCollection::iterator ChattyLogBuffer::erase(LogBufferElementColl
// Define a temporary mechanism to report the last LogBufferElement pointer
// for the specified uid, pid and tid. Used below to help merge-sort when
// pruning for worst UID.
class LogBufferElementKey {
    const union {
        struct {
            uint32_t uid;
            uint16_t pid;
            uint16_t tid;
        } __packed;
        uint64_t value;
    } __packed;

  public:
    LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid) : uid(uid), pid(pid), tid(tid) {}
    explicit LogBufferElementKey(uint64_t key) : value(key) {}

    uint64_t getKey() { return value; }
};

class LogBufferElementLast {
    typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap;
    LogBufferElementMap map;

  public:
    bool coalesce(LogBufferElement* element, uint16_t dropped) {
        LogBufferElementKey key(element->getUid(), element->getPid(), element->getTid());
        LogBufferElementMap::iterator it = map.find(key.getKey());
        uint64_t key = LogBufferElementKey(element->getUid(), element->getPid(), element->getTid());
        LogBufferElementMap::iterator it = map.find(key);
        if (it != map.end()) {
            LogBufferElement* found = it->second;
            uint16_t moreDropped = found->getDropped();
@@ -465,8 +448,8 @@ class LogBufferElementLast {
    }

    void add(LogBufferElement* element) {
        LogBufferElementKey key(element->getUid(), element->getPid(), element->getTid());
        map[key.getKey()] = element;
        uint64_t key = LogBufferElementKey(element->getUid(), element->getPid(), element->getTid());
        map[key] = element;
    }

    void clear() { map.clear(); }
@@ -483,6 +466,11 @@ class LogBufferElementLast {
            }
        }
    }

  private:
    uint64_t LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid) {
        return uint64_t(uid) << 32 | uint64_t(pid) << 16 | uint64_t(tid);
    }
};

// If the selected reader is blocking our pruning progress, decide on
+4 −4
Original line number Diff line number Diff line
@@ -183,16 +183,16 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogStatistics* st
    }
    if (name) {
        char* buf = nullptr;
        asprintf(&buf, "(%s)", name);
        if (buf) {
        int result = asprintf(&buf, "(%s)", name);
        if (result != -1) {
            free(const_cast<char*>(name));
            name = buf;
        }
    }
    if (commName) {
        char* buf = nullptr;
        asprintf(&buf, " %s", commName);
        if (buf) {
        int result = asprintf(&buf, " %s", commName);
        if (result != -1) {
            free(const_cast<char*>(commName));
            commName = buf;
        }
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,16 @@
using android::base::Join;
using android::base::StringPrintf;

#ifndef __ANDROID__
unsigned long __android_logger_get_buffer_size(log_id_t) {
    return 1024 * 1024;
}

bool __android_logger_valid_buffer_size(unsigned long) {
    return true;
}
#endif

void android::prdebug(const char* fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
+5 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <android-base/macros.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
#include <android-base/threads.h>
#include <log/log_event_list.h>
#include <log/log_properties.h>
#include <log/log_read.h>
@@ -551,9 +552,9 @@ void LogTags::WritePmsgEventLogTags(uint32_t tag, uid_t uid) {

    android_log_header_t header = {
            .id = LOG_ID_EVENTS,
        .tid = (uint16_t)gettid(),
        .realtime.tv_sec = (uint32_t)ts.tv_sec,
        .realtime.tv_nsec = (uint32_t)ts.tv_nsec,
            .tid = static_cast<uint16_t>(android::base::GetThreadId()),
            .realtime.tv_sec = static_cast<uint32_t>(ts.tv_sec),
            .realtime.tv_nsec = static_cast<uint32_t>(ts.tv_nsec),
    };

    uint32_t outTag = TAG_DEF_LOG_TAG;
Loading