From: Timo Kokkonen Date: Fri, 8 Jul 2016 19:17:09 +0000 (+0300) Subject: debug: Print thread name on debug prints X-Git-Url: http://git.itanic.dy.fi/?p=rrdd;a=commitdiff_plain;h=a12fb50d7366155290a6c004916145f16e52127e 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 --- 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);