]> git.itanic.dy.fi Git - rrdd/commitdiff
debug: Print thread name on debug prints
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Fri, 8 Jul 2016 19:17:09 +0000 (22:17 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Fri, 8 Jul 2016 19:42:59 +0000 (22:42 +0300)
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 <timo.t.kokkonen@iki.fi>
debug.c

diff --git a/debug.c b/debug.c
index 8bc70fc605bcb499a61c7dcaf7b12a5c11f92324..fe0fc9b139ba661d1c42df4adf7966f47020c985 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -4,8 +4,9 @@
 #include <time.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <time.h>
 #include <unistd.h>
 #include <stdarg.h>
-#include "process.h"
+#include <pthread.h>
 
 
+#include "process.h"
 #include "debug.h"
 
 const char red_color[] = {
 #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 time[32];
        char trace[1024];
        char all_trace[1538];
+       char thread_name[16];
        const char *color_str = assign_color(color);
        int ret;
 
        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));
 
 
        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),
        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(),
                color_str, time,
                getpid(), get_parent_count(),
+               thread_name,
                file, line, normal_color, trace);
 
        ret = write(logfile_fd, all_trace, ret);
                file, line, normal_color, trace);
 
        ret = write(logfile_fd, all_trace, ret);