mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Include a thread identifier in log messages
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
This commit is contained in:
parent
388fa6257e
commit
9288c31bf7
@ -110,7 +110,7 @@ LIBS=$old_libs
|
|||||||
dnl Availability of various common headers (non-fatal if missing).
|
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 \
|
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/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],[])
|
AC_CHECK_LIB([intl],[gettext],[])
|
||||||
|
|
||||||
|
@ -734,6 +734,7 @@ virThreadCreate;
|
|||||||
virThreadIsSelf;
|
virThreadIsSelf;
|
||||||
virThreadJoin;
|
virThreadJoin;
|
||||||
virThreadSelf;
|
virThreadSelf;
|
||||||
|
virThreadSelfID;
|
||||||
|
|
||||||
|
|
||||||
# usb.h
|
# usb.h
|
||||||
|
@ -548,14 +548,16 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
|||||||
localtime_r(&cur_time.tv_sec, &time_info);
|
localtime_r(&cur_time.tv_sec, &time_info);
|
||||||
|
|
||||||
if ((funcname != NULL)) {
|
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_hour, time_info.tm_min,
|
||||||
time_info.tm_sec, (int) cur_time.tv_usec / 1000,
|
time_info.tm_sec, (int) cur_time.tv_usec / 1000,
|
||||||
|
virThreadSelfID(),
|
||||||
virLogPriorityString(priority), funcname, linenr, str);
|
virLogPriorityString(priority), funcname, linenr, str);
|
||||||
} else {
|
} 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_hour, time_info.tm_min,
|
||||||
time_info.tm_sec, (int) cur_time.tv_usec / 1000,
|
time_info.tm_sec, (int) cur_time.tv_usec / 1000,
|
||||||
|
virThreadSelfID(),
|
||||||
virLogPriorityString(priority), str);
|
virLogPriorityString(priority), str);
|
||||||
}
|
}
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
|
@ -21,6 +21,11 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#if HAVE_SYS_SYSCALL_H
|
||||||
|
# include <sys/syscall.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Nothing special required for pthreads */
|
/* Nothing special required for pthreads */
|
||||||
int virThreadInitialize(void)
|
int virThreadInitialize(void)
|
||||||
@ -170,6 +175,17 @@ bool virThreadIsSelf(virThreadPtr thread)
|
|||||||
return pthread_equal(pthread_self(), thread->thread) ? true : false;
|
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)
|
void virThreadJoin(virThreadPtr thread)
|
||||||
{
|
{
|
||||||
pthread_join(thread->thread, NULL);
|
pthread_join(thread->thread, NULL);
|
||||||
|
@ -288,6 +288,12 @@ bool virThreadIsSelf(virThreadPtr thread)
|
|||||||
return self.thread == thread->thread ? true : false;
|
return self.thread == thread->thread ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int virThreadSelfID(void)
|
||||||
|
{
|
||||||
|
return (int)GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void virThreadJoin(virThreadPtr thread)
|
void virThreadJoin(virThreadPtr thread)
|
||||||
{
|
{
|
||||||
if (thread->joinable) {
|
if (thread->joinable) {
|
||||||
|
@ -51,6 +51,7 @@ int virThreadCreate(virThreadPtr thread,
|
|||||||
void virThreadSelf(virThreadPtr thread);
|
void virThreadSelf(virThreadPtr thread);
|
||||||
bool virThreadIsSelf(virThreadPtr thread);
|
bool virThreadIsSelf(virThreadPtr thread);
|
||||||
void virThreadJoin(virThreadPtr thread);
|
void virThreadJoin(virThreadPtr thread);
|
||||||
|
int virThreadSelfID(void);
|
||||||
|
|
||||||
int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
|
int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
|
int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
Loading…
Reference in New Issue
Block a user