WAYLAND_DEBUG: produce comparable timestamp values

The previous way to print timestamps would overflow and produce numbers
that didn't match any other system.
The format was also somewhat unintuitive because it was milliseconds
with the microseconds as fraction, which is a rarely used format.

Instead, use a simple HH:MM:SS.xxxxxx format that is hopefully
intuitively understandable as the POSIX/ISO8601 time format followed
by the microseconds.

Signed-off-by: Benjamin Otte <otte@redhat.com>
This commit is contained in:
Benjamin Otte 2026-06-02 07:29:37 +02:00 committed by Pekka Paalanen
parent c28d941787
commit 60d6bb946c
2 changed files with 10 additions and 8 deletions

View file

@ -1547,7 +1547,6 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
struct argument_details arg; struct argument_details arg;
const char *signature = closure->message->signature; const char *signature = closure->message->signature;
struct timespec tp; struct timespec tp;
unsigned int time;
uint32_t nval; uint32_t nval;
FILE *f; FILE *f;
char *buffer; char *buffer;
@ -1558,10 +1557,12 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
return; return;
clock_gettime(CLOCK_REALTIME, &tp); clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); fprintf(f, "%s[%02u:%02u:%02u.%06u] ",
fprintf(f, "%s[%7u.%03u] ",
color ? WL_DEBUG_COLOR_GREEN : "", color ? WL_DEBUG_COLOR_GREEN : "",
time / 1000, time % 1000); (unsigned) ((tp.tv_sec / 3600) % 24),
(unsigned) ((tp.tv_sec / 60) % 60),
(unsigned) (tp.tv_sec % 60),
(unsigned) (tp.tv_nsec / 1000));
#if defined(HAVE_GETTID) #if defined(HAVE_GETTID)
if (include_tid < 0) { if (include_tid < 0) {

View file

@ -1577,7 +1577,6 @@ queue_event(struct wl_display *display, int len)
const struct wl_message *message; const struct wl_message *message;
struct wl_event_queue *queue; struct wl_event_queue *queue;
struct timespec tp; struct timespec tp;
unsigned int time;
int num_zombie_fds; int num_zombie_fds;
wl_connection_copy(display->connection, p, sizeof p); wl_connection_copy(display->connection, p, sizeof p);
@ -1619,11 +1618,13 @@ queue_event(struct wl_display *display, int len)
if (debug_client) { if (debug_client) {
clock_gettime(CLOCK_REALTIME, &tp); clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); fprintf(stderr, "%s[%02u:%02u:%02u.%06u] %sdiscarded %s[%s]%s#%u%s.[event %d]%s"
fprintf(stderr, "%s[%7u.%03u] %sdiscarded %s[%s]%s#%u%s.[event %d]%s"
"(%d fd, %d byte)\n", "(%d fd, %d byte)\n",
debug_color ? WL_DEBUG_COLOR_GREEN : "", debug_color ? WL_DEBUG_COLOR_GREEN : "",
time / 1000, time % 1000, (unsigned) ((tp.tv_sec / 3600) % 24),
(unsigned) ((tp.tv_sec / 60) % 60),
(unsigned) (tp.tv_sec % 60),
(unsigned) (tp.tv_nsec / 1000),
debug_color ? WL_DEBUG_COLOR_RED : "", debug_color ? WL_DEBUG_COLOR_RED : "",
debug_color ? WL_DEBUG_COLOR_BLUE : "", debug_color ? WL_DEBUG_COLOR_BLUE : "",
zombie ? "zombie" : "unknown", zombie ? "zombie" : "unknown",