OSDN Git Service

libc: Thread IDs missing from logcat -v thread
authorMark Salyzyn <salyzyn@google.com>
Thu, 20 Mar 2014 23:07:55 +0000 (16:07 -0700)
committerMark Salyzyn <salyzyn@google.com>
Thu, 20 Mar 2014 23:35:18 +0000 (16:35 -0700)
- stuff caller's thread id into the packet.

Bug: 13568206
Change-Id: If8b318ef75c7dcdddb05da8ac3038860f0fda5ec

libc/bionic/libc_logging.cpp

index a4aeced..8e62e40 100644 (file)
@@ -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 = &priority;
-  vec[2].iov_len = 1;
-  vec[3].iov_base = const_cast<char*>(tag);
-  vec[3].iov_len = strlen(tag) + 1;
-  vec[4].iov_base = const_cast<char*>(msg);
-  vec[4].iov_len = strlen(msg) + 1;
+  vec[2].iov_base = &realtime_ts;
+  vec[2].iov_len = sizeof(realtime_ts);
+
+  vec[3].iov_base = &priority;
+  vec[3].iov_len = 1;
+  vec[4].iov_base = const_cast<char*>(tag);
+  vec[4].iov_len = strlen(tag) + 1;
+  vec[5].iov_base = const_cast<char*>(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 = &tag;
-  vec[2].iov_len = sizeof(tag);
-  vec[3].iov_base = &type;
-  vec[3].iov_len = sizeof(type);
-  vec[4].iov_base = const_cast<void*>(payload);
-  vec[4].iov_len = len;
+  vec[2].iov_base = &realtime_ts;
+  vec[2].iov_len = sizeof(realtime_ts);
+
+  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<void*>(payload);
+  vec[5].iov_len = len;
 
   int event_log_fd = __libc_open_log_socket();
 #else