]> xenbits.xensource.com Git - libvirt.git/commitdiff
Include a thread identifier in log messages
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 18 Nov 2010 13:03:56 +0000 (13:03 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 23 Nov 2010 14:09:35 +0000 (14:09 +0000)
To allow messages from different threads to be untangled,
include an integer thread identifier in log messages.

* src/util/logging.c: Include thread ID
* src/util/threads.h, src/util/threads.h, src/util/threads-pthread.c:
  Add new virThreadSelfID() function
* configure.ac: Check for sys/syscall.h

configure.ac
src/libvirt_private.syms
src/util/logging.c
src/util/threads-pthread.c
src/util/threads-win32.c
src/util/threads.h

index d21d558a70f9dbb6803f2160c250f8753d93673e..fca93fcf819d141803cee192fa6c3b67186f0573 100644 (file)
@@ -110,7 +110,7 @@ LIBS=$old_libs
 dnl Availability of various common headers (non-fatal if missing).
 AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/un.h \
   sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
-  sys/un.h])
+  sys/un.h sys/syscall.h])
 
 AC_CHECK_LIB([intl],[gettext],[])
 
index 10ae74f4ad1147589a287535a4b3400c0cbc78a8..0547cdfa021d3efebdb4bddc04fe819ea631050d 100644 (file)
@@ -734,6 +734,7 @@ virThreadCreate;
 virThreadIsSelf;
 virThreadJoin;
 virThreadSelf;
+virThreadSelfID;
 
 
 # usb.h
index ac38d4d98d802ad97956181aed69d80b2797466b..d65dec077c7f6b7278fd7bb6b6a4e3cece215530 100644 (file)
@@ -548,14 +548,16 @@ void virLogMessage(const char *category, int priority, const char *funcname,
     localtime_r(&cur_time.tv_sec, &time_info);
 
     if ((funcname != NULL)) {
-        ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s:%lld : %s\n",
+        ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %d: %s : %s:%lld : %s\n",
                           time_info.tm_hour, time_info.tm_min,
                           time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+                          virThreadSelfID(),
                           virLogPriorityString(priority), funcname, linenr, str);
     } else {
-        ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s\n",
+        ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %d: %s : %s\n",
                           time_info.tm_hour, time_info.tm_min,
                           time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+                          virThreadSelfID(),
                           virLogPriorityString(priority), str);
     }
     VIR_FREE(str);
index 34d9ce847483defa75e8305dbe85848e0590728d..02070ae3509065a0fe1595e2b3134a1fe3b35df1 100644 (file)
 
 #include <config.h>
 
+#include <unistd.h>
+#if HAVE_SYS_SYSCALL_H
+# include <sys/syscall.h>
+#endif
+
 
 /* Nothing special required for pthreads */
 int virThreadInitialize(void)
@@ -170,6 +175,17 @@ bool virThreadIsSelf(virThreadPtr thread)
     return pthread_equal(pthread_self(), thread->thread) ? true : false;
 }
 
+int virThreadSelfID(void)
+{
+#if defined(HAVE_SYS_SYSCALL_H) && defined(SYS_gettid)
+    pid_t tid;
+    tid = syscall(SYS_gettid);
+    return (int)tid;
+#else
+    return (int)pthread_self();
+#endif
+}
+
 void virThreadJoin(virThreadPtr thread)
 {
     pthread_join(thread->thread, NULL);
index de73fd56857a03a2a5bd7febec7db9c33c930fa6..33be4cf47739e6c4a1e35a661ba5f05acc23a1fb 100644 (file)
@@ -288,6 +288,12 @@ bool virThreadIsSelf(virThreadPtr thread)
     return self.thread == thread->thread ? true : false;
 }
 
+int virThreadSelfID(void)
+{
+    return (int)GetCurrentThreadId();
+}
+
+
 void virThreadJoin(virThreadPtr thread)
 {
     if (thread->joinable) {
index b3b827d3e538c4dff36e2ea731d12eb24edb6c8e..fa00a91014d543fabe306ab20949a065346fd986 100644 (file)
@@ -51,6 +51,7 @@ int virThreadCreate(virThreadPtr thread,
 void virThreadSelf(virThreadPtr thread);
 bool virThreadIsSelf(virThreadPtr thread);
 void virThreadJoin(virThreadPtr thread);
+int virThreadSelfID(void);
 
 int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
 int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;