From 8664be583a4556e5ca132288e989d307d2df92ce Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 20 Mar 2014 16:07:55 -0700 Subject: [PATCH] libc: Thread IDs missing from logcat -v thread - stuff caller's thread id into the packet. Bug: 13568206 Change-Id: If8b318ef75c7dcdddb05da8ac3038860f0fda5ec --- libc/bionic/libc_logging.cpp | 42 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp index a4aeced40..8e62e408d 100644 --- a/libc/bionic/libc_logging.cpp +++ b/libc/bionic/libc_logging.cpp @@ -494,24 +494,27 @@ static int __libc_write_log(int priority, const char* tag, const char* msg) { return __libc_write_stderr(tag, msg); } - iovec vec[5]; + iovec vec[6]; char log_id = LOG_ID_MAIN; vec[0].iov_base = &log_id; vec[0].iov_len = sizeof(log_id); + uint16_t tid = gettid(); + vec[1].iov_base = &tid; + vec[1].iov_len = sizeof(tid); timespec ts; clock_gettime(CLOCK_REALTIME, &ts); log_time realtime_ts; realtime_ts.tv_sec = ts.tv_sec; realtime_ts.tv_nsec = ts.tv_nsec; - vec[1].iov_base = &realtime_ts; - vec[1].iov_len = sizeof(realtime_ts); + vec[2].iov_base = &realtime_ts; + vec[2].iov_len = sizeof(realtime_ts); - vec[2].iov_base = &priority; - vec[2].iov_len = 1; - vec[3].iov_base = const_cast(tag); - vec[3].iov_len = strlen(tag) + 1; - vec[4].iov_base = const_cast(msg); - vec[4].iov_len = strlen(msg) + 1; + vec[3].iov_base = &priority; + vec[3].iov_len = 1; + vec[4].iov_base = const_cast(tag); + vec[4].iov_len = strlen(tag) + 1; + vec[5].iov_base = const_cast(msg); + vec[5].iov_len = strlen(msg) + 1; #else int main_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/main", O_CLOEXEC | O_WRONLY)); if (main_log_fd == -1) { @@ -553,24 +556,27 @@ int __libc_format_log(int priority, const char* tag, const char* format, ...) { static int __libc_android_log_event(int32_t tag, char type, const void* payload, size_t len) { #ifdef TARGET_USES_LOGD - iovec vec[5]; + iovec vec[6]; char log_id = LOG_ID_EVENTS; vec[0].iov_base = &log_id; vec[0].iov_len = sizeof(log_id); + uint16_t tid = gettid(); + vec[1].iov_base = &tid; + vec[1].iov_len = sizeof(tid); timespec ts; clock_gettime(CLOCK_REALTIME, &ts); log_time realtime_ts; realtime_ts.tv_sec = ts.tv_sec; realtime_ts.tv_nsec = ts.tv_nsec; - vec[1].iov_base = &realtime_ts; - vec[1].iov_len = sizeof(realtime_ts); + vec[2].iov_base = &realtime_ts; + vec[2].iov_len = sizeof(realtime_ts); - vec[2].iov_base = &tag; - vec[2].iov_len = sizeof(tag); - vec[3].iov_base = &type; - vec[3].iov_len = sizeof(type); - vec[4].iov_base = const_cast(payload); - vec[4].iov_len = len; + vec[3].iov_base = &tag; + vec[3].iov_len = sizeof(tag); + vec[4].iov_base = &type; + vec[4].iov_len = sizeof(type); + vec[5].iov_base = const_cast(payload); + vec[5].iov_len = len; int event_log_fd = __libc_open_log_socket(); #else