[RFC weston 9/9] compositor: protocol logger WIP

Pekka Paalanen ppaalanen at gmail.com
Sat Jun 3 11:57:11 UTC 2017


From: Pekka Paalanen <pq at iki.fi>

This is better than running Weston with WAYLAND_DEBUG=server:
- It is enabled on demand, no unnecessary flooding and no need to
  restart the compositor if debug was enabled.
- It prints client pointers so that messages with different clients can
  be seen apart.

TODO: parse and print message arguments

Signed-off-by: Pekka Paalanen <pq at iki.fi>
---
 compositor/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/compositor/main.c b/compositor/main.c
index 2eb64d0..d2e2c8a 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -84,6 +84,7 @@ struct wet_compositor {
 
 static FILE *weston_logfile = NULL;
 static struct weston_debug_scope *log_scope;
+static struct weston_debug_scope *protocol_scope;
 
 static int cached_tm_mday = -1;
 
@@ -176,6 +177,40 @@ vlog_continue(const char *fmt, va_list argp)
 	return vfprintf(weston_logfile, fmt, argp);
 }
 
+static void
+protocol_log_fn(void *user_data,
+		enum wl_protocol_logger_type direction,
+		const struct wl_protocol_logger_message *message)
+{
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
+	char timestr[128];
+	struct wl_resource *res = message->resource;
+
+	if (!weston_debug_scope_is_enabled(protocol_scope))
+		return;
+
+	fp = open_memstream(&logstr, &logsize);
+	if (!fp)
+		return;
+
+	fprintf(fp, "%s ", weston_debug_timestamp(timestr, sizeof timestr));
+	fprintf(fp, "client %p %s ", wl_resource_get_client(res),
+		direction == WL_PROTOCOL_LOGGER_REQUEST ? "rq" : "ev");
+	fprintf(fp, "%s@%u.%s(",
+		wl_resource_get_class(res),
+		wl_resource_get_id(res),
+		message->message->name);
+
+	fprintf(fp, ")\n");
+
+	if (fclose(fp) == 0)
+		weston_debug_scope_write(protocol_scope, logstr, logsize);
+
+	free(logstr);
+}
+
 static struct wl_list child_process_list;
 static struct weston_compositor *segv_compositor;
 
@@ -1807,6 +1842,7 @@ int main(int argc, char *argv[])
 	struct weston_seat *seat;
 	struct wet_compositor user_data;
 	int require_input;
+	struct wl_protocol_logger *protologger = NULL;
 
 	const struct weston_option core_options[] = {
 		{ WESTON_OPTION_STRING, "backend", 'B', &backend },
@@ -1897,9 +1933,16 @@ int main(int argc, char *argv[])
 
 	log_scope = weston_compositor_add_debug_scope(ec, "log",
 			"Weston and Wayland log\n", NULL, NULL);
-
-	if (debug_protocol)
+	protocol_scope = weston_compositor_add_debug_scope(ec, "proto",
+			"Wayland protocol dump for all clients.\n",
+			NULL, NULL);
+
+	if (debug_protocol) {
+		protologger = wl_display_add_protocol_logger(display,
+							     protocol_log_fn,
+							     NULL);
 		weston_compositor_enable_debug_protocol(ec);
+	}
 
 	if (weston_compositor_init_config(ec, config) < 0)
 		goto out;
@@ -2009,6 +2052,10 @@ out:
 	/* free(NULL) is valid, and it won't be NULL if it's used */
 	free(user_data.parsed_options);
 
+	if (protologger)
+		wl_protocol_logger_destroy(protologger);
+
+	weston_debug_scope_destroy(protocol_scope);
 	weston_debug_scope_destroy(log_scope);
 	weston_compositor_destroy(ec);
 
-- 
2.10.2



More information about the wayland-devel mailing list