From 9e18cdcebd893fbbb2369d893be219a7d832865f Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 7 Dec 2015 18:30:58 +0000 Subject: [PATCH] Revert "logd: liblog: logcat: switch to android_log_clockid()" This reverts commit 77b5696b1dea6f7afed89e113e479f4a131c14fc. Change-Id: I7711bf1a7e3f72ed29a2498d7287b725a0e624bd --- include/log/logger.h | 4 +--- liblog/log_is_loggable.c | 20 ++++++++++---------- liblog/logd_write.c | 6 +++++- liblog/logprint.c | 4 ++-- logcat/logcat.cpp | 8 +++++--- logcat/tests/logcat_test.cpp | 4 ++-- logd/LogBuffer.cpp | 4 ++-- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/include/log/logger.h b/include/log/logger.h index 03e84511b..c795253c9 100644 --- a/include/log/logger.h +++ b/include/log/logger.h @@ -11,8 +11,6 @@ #define _LIBS_LOG_LOGGER_H #include -#include - #include #include @@ -185,7 +183,7 @@ struct logger_list *android_logger_list_open(log_id_t id, pid_t pid); #define android_logger_list_close android_logger_list_free -clockid_t android_log_clockid(); +char android_log_timestamp(); /* * log_id_t helpers diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c index 7fc01d9ab..e128edbd8 100644 --- a/liblog/log_is_loggable.c +++ b/liblog/log_is_loggable.c @@ -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_clockid = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t lock_timestamp = PTHREAD_MUTEX_INITIALIZER; -clockid_t android_log_clockid() +char android_log_timestamp() { static struct cache r_time_cache = { NULL, -1, 0 }; static struct cache p_time_cache = { NULL, -1, 0 }; - char c; + char retval; - if (pthread_mutex_trylock(&lock_clockid)) { + if (pthread_mutex_trylock(&lock_timestamp)) { /* We are willing to accept some race in this context */ - if (!(c = p_time_cache.c)) { - c = r_time_cache.c; + if (!(retval = p_time_cache.c)) { + retval = r_time_cache.c; } } else { static uint32_t serial; @@ -217,12 +217,12 @@ clockid_t android_log_clockid() refresh_cache(&p_time_cache, "persist.logd.timestamp"); serial = current_serial; } - if (!(c = p_time_cache.c)) { - c = r_time_cache.c; + if (!(retval = p_time_cache.c)) { + retval = r_time_cache.c; } - pthread_mutex_unlock(&lock_clockid); + pthread_mutex_unlock(&lock_timestamp); } - return (tolower(c) == 'm') ? CLOCK_MONOTONIC : CLOCK_REALTIME; + return tolower(retval ?: 'r'); } diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 11c6d9cc8..83c6dc296 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -212,7 +212,11 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr) * }; */ - clock_gettime(android_log_clockid(), &ts); + if (android_log_timestamp() == 'm') { + clock_gettime(CLOCK_MONOTONIC, &ts); + } else { + clock_gettime(CLOCK_REALTIME, &ts); + } pmsg_header.magic = LOGGER_MAGIC; pmsg_header.len = sizeof(pmsg_header) + sizeof(header); diff --git a/liblog/logprint.c b/liblog/logprint.c index ad52a8119..ebf9786aa 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -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_clockid() == CLOCK_MONOTONIC; + p_ret->monotonic_output = android_log_timestamp() == 'm'; 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_clockid() != CLOCK_MONOTONIC) { + if (android_log_timestamp() != 'm') { struct timespec time; convertMonotonic(&time, entry); now = time.tv_sec; diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 069fc82e5..4d7adf139 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -398,9 +398,11 @@ static log_time lastLogTime(char *outputFileName) { return retval; } - clockid_t clock_type = android_log_clockid(); - log_time now(clock_type); - bool monotonic = clock_type == CLOCK_MONOTONIC; + log_time now(CLOCK_REALTIME); + bool monotonic = android_log_timestamp() == 'm'; + if (monotonic) { + now = log_time(CLOCK_MONOTONIC); + } std::string directory; char *file = strrchr(outputFileName, '/'); diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp index 61b020ccc..153a3fd2b 100644 --- a/logcat/tests/logcat_test.cpp +++ b/logcat/tests/logcat_test.cpp @@ -76,7 +76,7 @@ TEST(logcat, buckets) { TEST(logcat, year) { - if (android_log_clockid() == CLOCK_MONOTONIC) { + if (android_log_timestamp() == 'm') { fprintf(stderr, "Skipping test, logd is monotonic time\n"); return; } @@ -147,7 +147,7 @@ char *fgetLongTime(char *buffer, size_t buflen, FILE *fp) { TEST(logcat, tz) { - if (android_log_clockid() == CLOCK_MONOTONIC) { + if (android_log_timestamp() == 'm') { fprintf(stderr, "Skipping test, logd is monotonic time\n"); return; } diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index c8127c3ac..fd5c066ac 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -128,7 +128,7 @@ void LogBuffer::init() { } } bool lastMonotonic = monotonic; - monotonic = android_log_clockid() == CLOCK_MONOTONIC; + monotonic = android_log_timestamp() == 'm'; if (lastMonotonic == monotonic) { return; } @@ -167,7 +167,7 @@ void LogBuffer::init() { } LogBuffer::LogBuffer(LastLogTimes *times): - monotonic(android_log_clockid() == CLOCK_MONOTONIC), + monotonic(android_log_timestamp() == 'm'), mTimes(*times) { pthread_mutex_init(&mLogElementsLock, NULL);