aboutsummaryrefslogtreecommitdiffstats
path: root/src/connection.c
diff options
context:
space:
mode:
authorKyle Brenneman <kbrenneman@nvidia.com>2024-09-10 14:36:06 -0600
committerDaniel Stone <daniels@collabora.com>2025-09-15 14:45:53 +0100
commit4673ef7e9ce5de21051b64c39816a98187611966 (patch)
tree9415be5400256dbd69568946381a324fe532a162 /src/connection.c
parentconnection: Add a function to parse WAYLAND_DEBUG tokens (diff)
downloadwayland-4673ef7e9ce5de21051b64c39816a98187611966.tar
wayland-4673ef7e9ce5de21051b64c39816a98187611966.tar.gz
wayland-4673ef7e9ce5de21051b64c39816a98187611966.tar.bz2
wayland-4673ef7e9ce5de21051b64c39816a98187611966.tar.lz
wayland-4673ef7e9ce5de21051b64c39816a98187611966.tar.xz
wayland-4673ef7e9ce5de21051b64c39816a98187611966.tar.zst
wayland-4673ef7e9ce5de21051b64c39816a98187611966.zip
connection: Add a thread ID to WAYLAND_DEBUG output.
If WAYLAND_DEBUG contains the token "thread_id", and gettid() is available, then include the current thread ID in the output from wl_closure_print. If multiple threads are sending requests, then those requests can get interleaved. That's usually fine, but for wl_surface requests and commits, that can cause problems ranging from incorrect behavior to protocol errors. Being able to see which requests are sent by different threads would make such problems much easier to diagnose. Signed-off-by: Kyle Brenneman <kbrenneman@nvidia.com>
Diffstat (limited to 'src/connection.c')
-rw-r--r--src/connection.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/connection.c b/src/connection.c
index 9c6a6b0..2d1e8d1 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -26,6 +26,8 @@
#define _GNU_SOURCE
+#include "../config.h"
+
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
@@ -1538,6 +1540,9 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
int send, int discarded, uint32_t (*n_parse)(union wl_argument *arg),
const char *queue_name, int color)
{
+#if defined(HAVE_GETTID)
+ static int include_tid = -1;
+#endif // defined(HAVE_GETTID)
int i;
struct argument_details arg;
const char *signature = closure->message->signature;
@@ -1558,6 +1563,18 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
color ? WL_DEBUG_COLOR_GREEN : "",
time / 1000, time % 1000);
+#if defined(HAVE_GETTID)
+ if (include_tid < 0) {
+ include_tid = wl_check_env_token(getenv("WAYLAND_DEBUG"), "thread_id");
+ }
+
+ if (include_tid) {
+ fprintf(f, "%sTID#%d ",
+ color ? WL_DEBUG_COLOR_CYAN : "",
+ (int) gettid());
+ }
+#endif
+
if (queue_name) {
fprintf(f, "%s{%s} ",
color ? WL_DEBUG_COLOR_YELLOW : "",