<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 5, 2014 at 11:04 PM, Kristian Høgsberg <span dir="ltr"><<a href="mailto:hoegsberg@gmail.com" target="_blank">hoegsberg@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Dec 18, 2013 at 08:56:20PM -0600, Jason Ekstrand wrote:<br>
> In order to keep from overloading the debug handler, we first squash the<br>
> entire message into a string and call wl_debug once.<br>
><br>
> Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> ---<br>
> src/connection.c | 54 ++++++++++++++++++++++++++++-----------------------<br>
> src/wayland-client.c | 6 ++++++<br>
> src/wayland-client.h | 1 +<br>
> src/wayland-private.h | 2 ++<br>
> src/wayland-server.c | 6 ++++++<br>
> src/wayland-server.h | 1 +<br>
> src/wayland-util.c | 19 ++++++++++++++++++<br>
> 7 files changed, 65 insertions(+), 24 deletions(-)<br>
><br>
> diff --git a/src/connection.c b/src/connection.c<br>
> index 1d8b61b..b7f02b4 100644<br>
> --- a/src/connection.c<br>
> +++ b/src/connection.c<br>
> @@ -1088,67 +1088,73 @@ void<br>
> wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)<br>
> {<br>
> int i;<br>
> + struct wl_array msg;<br>
> struct argument_details arg;<br>
> const char *signature = closure->message->signature;<br>
> struct timespec tp;<br>
> unsigned int time;<br>
><br>
> + wl_array_init(&msg);<br>
> + wl_array_add(&msg, 128); /* This should be big enough for most cases */<br>
> + msg.size = 0;<br>
> +<br>
> clock_gettime(CLOCK_REALTIME, &tp);<br>
> time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);<br>
><br>
> - fprintf(stderr, "[%10.3f] %s%s@%u.%s(",<br>
> - time / 1000.0,<br>
> - send ? " -> " : "",<br>
> - target->interface->name, target->id,<br>
> - closure->message->name);<br>
> + wl_array_printf(&msg, "[%10.3f] %s%s@%u.%s(",<br>
> + time / 1000.0,<br>
> + send ? " -> " : "",<br>
> + target->interface->name, target->id,<br>
> + closure->message->name);<br>
<br>
</div></div>Could we just call wl_debug() instead and avoid building up a string?<br>
The way you've written this, wl_debug() is always called with one complete<br>
line of debug text, but do you actually need that?<br></blockquote><div> <br></div><div>Technically, no. Obviously the debug handler can use something similar to wl_array_printf to let debug messages build up and then split it into lines. In fact, this is exactly what I'll do in my code if you prefer (the debug handler I'm forwarding stuff to needs complete liens). This just makes it a little easier on the debug handler, especially if stuff is multi-threaded.<br>
<br></div><div>--Jason<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
><br>
> for (i = 0; i < closure->count; i++) {<br>
> signature = get_next_argument(signature, &arg);<br>
> if (i > 0)<br>
> - fprintf(stderr, ", ");<br>
> + wl_array_printf(&msg, ", ");<br>
><br>
> switch (arg.type) {<br>
> case 'u':<br>
> - fprintf(stderr, "%u", closure->args[i].u);<br>
> + wl_array_printf(&msg, "%u", closure->args[i].u);<br>
> break;<br>
> case 'i':<br>
> - fprintf(stderr, "%d", closure->args[i].i);<br>
> + wl_array_printf(&msg, "%d", closure->args[i].i);<br>
> break;<br>
> case 'f':<br>
> - fprintf(stderr, "%f",<br>
> - wl_fixed_to_double(closure->args[i].f));<br>
> + wl_array_printf(&msg, "%f",<br>
> + wl_fixed_to_double(closure->args[i].f));<br>
> break;<br>
> case 's':<br>
> - fprintf(stderr, "\"%s\"", closure->args[i].s);<br>
> + wl_array_printf(&msg, "\"%s\"", closure->args[i].s);<br>
> break;<br>
> case 'o':<br>
> if (closure->args[i].o)<br>
> - fprintf(stderr, "%s@%u",<br>
> - closure->args[i].o->interface->name,<br>
> - closure->args[i].o->id);<br>
> + wl_array_printf(&msg, "%s@%u",<br>
> + closure->args[i].o->interface->name,<br>
> + closure->args[i].o->id);<br>
> else<br>
> - fprintf(stderr, "nil");<br>
> + wl_array_printf(&msg, "nil");<br>
> break;<br>
> case 'n':<br>
> - fprintf(stderr, "new id %s@",<br>
> - (closure->message->types[i]) ?<br>
> - closure->message->types[i]->name :<br>
> - "[unknown]");<br>
> + wl_array_printf(&msg, "new id %s@",<br>
> + (closure->message->types[i]) ?<br>
> + closure->message->types[i]->name :<br>
> + "[unknown]");<br>
> if (closure->args[i].n != 0)<br>
> - fprintf(stderr, "%u", closure->args[i].n);<br>
> + wl_array_printf(&msg, "%u", closure->args[i].n);<br>
> else<br>
> - fprintf(stderr, "nil");<br>
> + wl_array_printf(&msg, "nil");<br>
> break;<br>
> case 'a':<br>
> - fprintf(stderr, "array");<br>
> + wl_array_printf(&msg, "array");<br>
> break;<br>
> case 'h':<br>
> - fprintf(stderr, "fd %d", closure->args[i].h);<br>
> + wl_array_printf(&msg, "fd %d", closure->args[i].h);<br>
> break;<br>
> }<br>
> }<br>
><br>
> - fprintf(stderr, ")\n");<br>
> + wl_debug("%s)\n", msg.data);<br>
> + wl_array_release(&msg);<br>
> }<br>
><br>
> void<br>
> diff --git a/src/wayland-client.c b/src/wayland-client.c<br>
> index 799ebab..19d31fc 100644<br>
> --- a/src/wayland-client.c<br>
> +++ b/src/wayland-client.c<br>
> @@ -1587,3 +1587,9 @@ wl_log_set_handler_client(wl_log_func_t handler)<br>
> {<br>
> wl_log_handler = handler;<br>
> }<br>
> +<br>
> +WL_EXPORT void<br>
> +wl_debug_set_handler_client(wl_log_func_t handler)<br>
> +{<br>
> + wl_debug_handler = handler;<br>
> +}<br>
> diff --git a/src/wayland-client.h b/src/wayland-client.h<br>
> index 2a32785..59c06e0 100644<br>
> --- a/src/wayland-client.h<br>
> +++ b/src/wayland-client.h<br>
> @@ -173,6 +173,7 @@ void wl_display_cancel_read(struct wl_display *display);<br>
> int wl_display_read_events(struct wl_display *display);<br>
><br>
> void wl_log_set_handler_client(wl_log_func_t handler);<br>
> +void wl_debug_set_handler_client(wl_log_func_t handler);<br>
><br>
> #ifdef __cplusplus<br>
> }<br>
> diff --git a/src/wayland-private.h b/src/wayland-private.h<br>
> index 67e8783..a74b77c 100644<br>
> --- a/src/wayland-private.h<br>
> +++ b/src/wayland-private.h<br>
> @@ -165,8 +165,10 @@ void<br>
> wl_closure_destroy(struct wl_closure *closure);<br>
><br>
> extern wl_log_func_t wl_log_handler;<br>
> +extern wl_log_func_t wl_debug_handler;<br>
><br>
> void wl_log(const char *fmt, ...);<br>
> +void wl_debug(const char *fmt, ...);<br>
><br>
> struct wl_display;<br>
><br>
> diff --git a/src/wayland-server.c b/src/wayland-server.c<br>
> index e03316c..864d136 100644<br>
> --- a/src/wayland-server.c<br>
> +++ b/src/wayland-server.c<br>
> @@ -1216,6 +1216,12 @@ wl_log_set_handler_server(wl_log_func_t handler)<br>
> wl_log_handler = handler;<br>
> }<br>
><br>
> +WL_EXPORT void<br>
> +wl_debug_set_handler_server(wl_log_func_t handler)<br>
> +{<br>
> + wl_debug_handler = handler;<br>
> +}<br>
> +<br>
> /* Deprecated functions below. */<br>
><br>
> uint32_t<br>
> diff --git a/src/wayland-server.h b/src/wayland-server.h<br>
> index f5427fd..6fe2698 100644<br>
> --- a/src/wayland-server.h<br>
> +++ b/src/wayland-server.h<br>
> @@ -448,6 +448,7 @@ wl_shm_buffer_create(struct wl_client *client,<br>
> int32_t stride, uint32_t format);<br>
><br>
> void wl_log_set_handler_server(wl_log_func_t handler);<br>
> +void wl_debug_set_handler_server(wl_log_func_t handler);<br>
><br>
> #ifdef __cplusplus<br>
> }<br>
> diff --git a/src/wayland-util.c b/src/wayland-util.c<br>
> index c9d6d0e..fe78a94 100644<br>
> --- a/src/wayland-util.c<br>
> +++ b/src/wayland-util.c<br>
> @@ -23,6 +23,7 @@<br>
><br>
> #include <stdlib.h><br>
> #include <stdint.h><br>
> +#include <stdio.h><br>
> #include <string.h><br>
> #include <stdarg.h><br>
> #include <errno.h><br>
> @@ -402,6 +403,12 @@ wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)<br>
> }<br>
><br>
> static void<br>
> +wl_log_stderr_handler(const char *fmt, va_list arg)<br>
> +{<br>
> + vfprintf(stderr, fmt, arg);<br>
> +}<br>
> +<br>
> +static void<br>
> wl_log_noop_handler(const char *fmt, va_list arg)<br>
> {<br>
> }<br>
> @@ -417,3 +424,15 @@ wl_log(const char *fmt, ...)<br>
> wl_log_handler(fmt, argp);<br>
> va_end(argp);<br>
> }<br>
> +<br>
> +wl_log_func_t wl_debug_handler = wl_log_stderr_handler;<br>
> +<br>
> +void<br>
> +wl_debug(const char *fmt, ...)<br>
> +{<br>
> + va_list argp;<br>
> +<br>
> + va_start(argp, fmt);<br>
> + wl_debug_handler(fmt, argp);<br>
> + va_end(argp);<br>
> +}<br>
> --<br>
> 1.8.4.2<br>
><br>
</div></div>> _______________________________________________<br>
> wayland-devel mailing list<br>
> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</blockquote></div><br></div></div>