Skip to content

Add a thread ID to WAYLAND_DEBUG output.

Kyle Brenneman requested to merge kbrenneman/wayland:debug-print-thread-id into main

This adds an option to show the thread ID in the WAYLAND_DEBUG output when it sends a request or dispatches an event.

Since wl_surface requests are not thread-safe (jadahl has a very good explanation of why that is at !423 (comment 2561310)), being able to know which requests are being sent on different threads will make it much easier to diagnose any threading-related problems.

Note that event queue names do not serve the same purpose. For one, you only get an event queue name if an application or library assigns one, and not all of them do. When I'm trying to diagnose a bug report, I can't reasonably ask an end user to modify and rebuild an entire application and its dependencies just to produce a easier log file.

In addition, an event queue only controls dispatching events, which does not necessarily mean separate threads. In addition, dispatching events on a thread doesn't necessarily mean you're sending requests from that same thread. And of course, a lot of Wayland objects would never need an event queue because they don't have any events.

Anyway, the first commit in this set just adds the result of gettid() to the output line in wl_closure_print. The second commit, per @daniels's suggestion, makes that output conditional, so it'll only print the thread ID if you set the environment variable WAYLAND_DEBUG_THREAD_ID=1. By default, the debug output is the same as it is now.

Note that since this relies on gettid, it'll only work on Linux. Adding something equivalent for other systems should be easy enough, though, if that's needed or wanted.

Merge request reports