summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-12-01 15:57:25 -0800
committerMark Salyzyn <salyzyn@google.com>2015-12-07 18:45:31 +0000
commitba7a9a016bf011fdf45b6736d4c6d6795faba9d3 (patch)
tree628cdad8728c49ec03a7ccf2caec93caea8a0882
parentb566435b02d90663b5a26ba795bfb2f0102e8833 (diff)
downloadcore-ba7a9a016bf011fdf45b6736d4c6d6795faba9d3.tar.gz
core-ba7a9a016bf011fdf45b6736d4c6d6795faba9d3.tar.bz2
core-ba7a9a016bf011fdf45b6736d4c6d6795faba9d3.zip
logd: liblog: logcat: switch to android_log_clockid() (2)
android_log_timestamp returns the property leading letter, it is better to return a clockid_t with android_log_clockid() Bug: 23668800 Change-Id: I38dee773bf3844177826b03a26b03215c79a5359
-rw-r--r--include/log/logger.h8
-rw-r--r--liblog/log_is_loggable.c20
-rw-r--r--liblog/logd_write.c6
-rw-r--r--liblog/logprint.c4
-rw-r--r--logcat/logcat.cpp8
-rw-r--r--logcat/tests/logcat_test.cpp4
-rw-r--r--logd/LogBuffer.cpp4
7 files changed, 27 insertions, 27 deletions
diff --git a/include/log/logger.h b/include/log/logger.h
index c795253c9..ff70529fb 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -11,6 +11,10 @@
#define _LIBS_LOG_LOGGER_H
#include <stdint.h>
+#ifdef __linux__
+#include <time.h> /* clockid_t definition */
+#endif
+
#include <log/log.h>
#include <log/log_read.h>
@@ -183,7 +187,9 @@ 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();
+#ifdef __linux__
+clockid_t android_log_clockid();
+#endif
/*
* log_id_t helpers
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
index e128edbd8..7fc01d9ab 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_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;
}
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 83c6dc296..11c6d9cc8 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -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);
diff --git a/liblog/logprint.c b/liblog/logprint.c
index ebf9786aa..ad52a8119 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_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;
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 22645f56e..0c59f2307 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -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, '/');
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 153a3fd2b..61b020ccc 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_timestamp() == 'm') {
+ if (android_log_clockid() == CLOCK_MONOTONIC) {
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_timestamp() == 'm') {
+ if (android_log_clockid() == CLOCK_MONOTONIC) {
fprintf(stderr, "Skipping test, logd is monotonic time\n");
return;
}
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index fd5c066ac..c8127c3ac 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -128,7 +128,7 @@ void LogBuffer::init() {
}
}
bool lastMonotonic = monotonic;
- monotonic = android_log_timestamp() == 'm';
+ monotonic = android_log_clockid() == CLOCK_MONOTONIC;
if (lastMonotonic == monotonic) {
return;
}
@@ -167,7 +167,7 @@ void LogBuffer::init() {
}
LogBuffer::LogBuffer(LastLogTimes *times):
- monotonic(android_log_timestamp() == 'm'),
+ monotonic(android_log_clockid() == CLOCK_MONOTONIC),
mTimes(*times) {
pthread_mutex_init(&mLogElementsLock, NULL);