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

Commit 9eca0e77 authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge "logd: liblog: logcat: switch to android_log_clockid()"

parents 912ed3d8 77b5696b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
#define _LIBS_LOG_LOGGER_H

#include <stdint.h>
#include <time.h>

#include <log/log.h>
#include <log/log_read.h>

@@ -183,7 +185,7 @@ struct logger_list *android_logger_list_open(log_id_t id,
                                             pid_t pid);
#define android_logger_list_close android_logger_list_free

char android_log_timestamp();
clockid_t android_log_clockid();

/*
 * log_id_t helpers
+10 −10
Original line number Diff line number Diff line
@@ -196,18 +196,18 @@ int __android_log_is_loggable(int prio, const char *tag, int default_prio)
 * rare, we can accept a trylock failure gracefully. Use a separate
 * lock from is_loggable to keep contention down b/25563384.
 */
static pthread_mutex_t lock_timestamp = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t lock_clockid = PTHREAD_MUTEX_INITIALIZER;

char android_log_timestamp()
clockid_t android_log_clockid()
{
    static struct cache r_time_cache = { NULL, -1, 0 };
    static struct cache p_time_cache = { NULL, -1, 0 };
    char retval;
    char c;

    if (pthread_mutex_trylock(&lock_timestamp)) {
    if (pthread_mutex_trylock(&lock_clockid)) {
        /* We are willing to accept some race in this context */
        if (!(retval = p_time_cache.c)) {
            retval = r_time_cache.c;
        if (!(c = p_time_cache.c)) {
            c = r_time_cache.c;
        }
    } else {
        static uint32_t serial;
@@ -217,12 +217,12 @@ char android_log_timestamp()
            refresh_cache(&p_time_cache, "persist.logd.timestamp");
            serial = current_serial;
        }
        if (!(retval = p_time_cache.c)) {
            retval = r_time_cache.c;
        if (!(c = p_time_cache.c)) {
            c = r_time_cache.c;
        }

        pthread_mutex_unlock(&lock_timestamp);
        pthread_mutex_unlock(&lock_clockid);
    }

    return tolower(retval ?: 'r');
    return (tolower(c) == 'm') ? CLOCK_MONOTONIC : CLOCK_REALTIME;
}
+1 −5
Original line number Diff line number Diff line
@@ -212,11 +212,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
     *  };
     */

    if (android_log_timestamp() == 'm') {
        clock_gettime(CLOCK_MONOTONIC, &ts);
    } else {
        clock_gettime(CLOCK_REALTIME, &ts);
    }
    clock_gettime(android_log_clockid(), &ts);

    pmsg_header.magic = LOGGER_MAGIC;
    pmsg_header.len = sizeof(pmsg_header) + sizeof(header);
+2 −2
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ AndroidLogFormat *android_log_format_new()
    p_ret->year_output = false;
    p_ret->zone_output = false;
    p_ret->epoch_output = false;
    p_ret->monotonic_output = android_log_timestamp() == 'm';
    p_ret->monotonic_output = android_log_clockid() == CLOCK_MONOTONIC;

    return p_ret;
}
@@ -1262,7 +1262,7 @@ char *android_log_formatLogLine (
    nsec = entry->tv_nsec;
    if (p_format->monotonic_output) {
        // prevent convertMonotonic from being called if logd is monotonic
        if (android_log_timestamp() != 'm') {
        if (android_log_clockid() != CLOCK_MONOTONIC) {
            struct timespec time;
            convertMonotonic(&time, entry);
            now = time.tv_sec;
+3 −5
Original line number Diff line number Diff line
@@ -398,11 +398,9 @@ static log_time lastLogTime(char *outputFileName) {
        return retval;
    }

    log_time now(CLOCK_REALTIME);
    bool monotonic = android_log_timestamp() == 'm';
    if (monotonic) {
        now = log_time(CLOCK_MONOTONIC);
    }
    clockid_t clock_type = android_log_clockid();
    log_time now(clock_type);
    bool monotonic = clock_type == CLOCK_MONOTONIC;

    std::string directory;
    char *file = strrchr(outputFileName, '/');
Loading