From a12fb50d7366155290a6c004916145f16e52127e Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Fri, 8 Jul 2016 22:17:09 +0300 Subject: [PATCH] debug: Print thread name on debug prints Many different threads might be calling the same functions concurrently. Add the name of the thread so that it becomes more obvious which thread is emitting the given print. Signed-off-by: Timo Kokkonen --- debug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/debug.c b/debug.c index 8bc70fc..fe0fc9b 100644 --- a/debug.c +++ b/debug.c @@ -4,8 +4,9 @@ #include #include #include -#include "process.h" +#include +#include "process.h" #include "debug.h" const char red_color[] = { @@ -43,6 +44,7 @@ void print_trace(const char *file, int line, int color, int l, char time[32]; char trace[1024]; char all_trace[1538]; + char thread_name[16]; const char *color_str = assign_color(color); int ret; @@ -55,10 +57,13 @@ void print_trace(const char *file, int line, int color, int l, strftime(time, sizeof(time), "%d.%m.%Y %T", localtime(&t)); + pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name)); + ret = snprintf(all_trace, sizeof(all_trace), - "%s%s [%5d.%d] %s:%d %s %s", + "%s%s [%5d.%d] %s %s:%d %s %s", color_str, time, getpid(), get_parent_count(), + thread_name, file, line, normal_color, trace); ret = write(logfile_fd, all_trace, ret); -- 2.44.0