[Mesa-dev] [PATCH 47/84] st/nine: Print threadid in debug log

Axel Davy axel.davy at ens.fr
Wed Dec 7 22:55:20 UTC 2016


From: Patrick Rudolph <siro at das-labor.org>

To ease debugging.

Signed-off-by: Patrick Rudolph <siro at das-labor.org>
---
 src/gallium/state_trackers/nine/nine_debug.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/gallium/state_trackers/nine/nine_debug.c b/src/gallium/state_trackers/nine/nine_debug.c
index 4779192..4f841e1 100644
--- a/src/gallium/state_trackers/nine/nine_debug.c
+++ b/src/gallium/state_trackers/nine/nine_debug.c
@@ -23,6 +23,7 @@
 #include "nine_debug.h"
 
 #include <ctype.h>
+#include "c11/threads.h"
 
 static const struct debug_named_value nine_debug_flags[] = {
     { "unknown", DBG_UNKNOWN,              "IUnknown implementation." },
@@ -63,6 +64,13 @@ _nine_debug_printf( unsigned long flag,
 {
     static boolean first = TRUE;
     static unsigned long dbg_flags = DBG_ERROR | DBG_WARN;
+    unsigned long tid = 0;
+#if defined(HAVE_PTHREAD)
+#  if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__) && \
+      (__GLIBC__ >= 3 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12))
+    tid = pthread_self();
+#  endif
+#endif
 
     if (first) {
         first = FALSE;
@@ -71,9 +79,8 @@ _nine_debug_printf( unsigned long flag,
     if (dbg_flags & flag) {
         const char *f = func ? strrchr(func, '_') : NULL;
         va_list ap;
-
-        /* inside a class this will print nine:classinlowercase:func: while
-         * outside a class (rarely used) it will just print nine:func:
+        /* inside a class this will print nine:tid:classinlowercase:func: while
+         * outside a class (rarely used) it will just print nine:tid:func
          * the reason for lower case is simply to match the filenames, as it
          * will also strip off the "Nine" */
         if (f && strncmp(func, "Nine", 4) == 0) {
@@ -81,10 +88,15 @@ _nine_debug_printf( unsigned long flag,
             char *ptr = klass;
             for (func += 4; func != f; ++func) { *ptr++ = tolower(*func); }
             *ptr = '\0';
-
-            debug_printf("nine:%s:%s: ", klass, ++f);
+            if (tid)
+                debug_printf("nine:0x%08lx:%s:%s: ", tid, klass, ++f);
+            else
+                debug_printf("nine:%s:%s: ", klass, ++f);
         } else if (func) {
-            debug_printf("nine:%s: ", func);
+            if (tid)
+                debug_printf("nine:0x%08lx:%s ", tid, func);
+            else
+                debug_printf("nine:%s ", func);
         }
 
         va_start(ap, fmt);
-- 
2.10.2



More information about the mesa-dev mailing list