[PATCH wayland] debug: add timestamps when logging

Tiago Vignatti tiago.vignatti at intel.com
Thu Jul 14 08:56:40 PDT 2011


Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 wayland/connection.c     |   16 ++++++++++++++--
 wayland/connection.h     |    2 +-
 wayland/wayland-client.c |    9 ++++-----
 wayland/wayland-server.c |    9 ++++-----
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/wayland/connection.c b/wayland/connection.c
index 0f2051a..4f6a845 100644
--- a/wayland/connection.c
+++ b/wayland/connection.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <time.h>
 
 #include "wayland-util.h"
 #include "connection.h"
@@ -684,12 +685,23 @@ wl_closure_send(struct wl_closure *closure, struct wl_connection *connection)
 }
 
 void
-wl_closure_print(struct wl_closure *closure, struct wl_object *target)
+wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 {
 	union wl_value *value;
+	char buffer[4] = "\0";
 	int i;
+	struct timespec tp;
+	unsigned int time;
 
-	fprintf(stderr, "%s@%d.%s(",
+	if (send)
+		sprintf(buffer, " -> ");
+
+	clock_gettime(CLOCK_REALTIME, &tp);
+	time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+
+	fprintf(stderr, "[%10.3f] %s%s@%d.%s(",
+		time / 1000.0,
+		buffer,
 		target->interface->name, target->id,
 		closure->message->name);
 
diff --git a/wayland/connection.h b/wayland/connection.h
index 413977d..5f4588b 100644
--- a/wayland/connection.h
+++ b/wayland/connection.h
@@ -61,7 +61,7 @@ wl_closure_invoke(struct wl_closure *closure,
 void
 wl_closure_send(struct wl_closure *closure, struct wl_connection *connection);
 void
-wl_closure_print(struct wl_closure *closure, struct wl_object *target);
+wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send);
 void
 wl_closure_destroy(struct wl_closure *closure);
 
diff --git a/wayland/wayland-client.c b/wayland/wayland-client.c
index e8266e1..ce27a90 100644
--- a/wayland/wayland-client.c
+++ b/wayland/wayland-client.c
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <stddef.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
@@ -201,10 +202,8 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
 
 	wl_closure_send(closure, proxy->display->connection);
 
-	if (wl_debug) {
-		fprintf(stderr, " -> ");
-		wl_closure_print(closure, &proxy->object);
-	}
+	if (wl_debug)
+		wl_closure_print(closure, &proxy->object, true);
 
 	wl_closure_destroy(closure);
 }
@@ -523,7 +522,7 @@ handle_event(struct wl_display *display,
 					  size, display->objects, message);
 
 	if (wl_debug)
-		wl_closure_print(closure, &proxy->object);
+		wl_closure_print(closure, &proxy->object, false);
 
 	wl_closure_invoke(closure, &proxy->object,
 			  proxy->object.implementation[opcode],
diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index 176859b..d4fdfc7 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -27,6 +27,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
@@ -108,10 +109,8 @@ wl_client_post_event(struct wl_client *client, struct wl_object *sender,
 
 	wl_closure_send(closure, client->connection);
 
-	if (wl_debug) {
-		fprintf(stderr, " -> ");
-		wl_closure_print(closure, sender);
-	}
+	if (wl_debug)
+		wl_closure_print(closure, sender, true);
 
 	wl_closure_destroy(closure);
 }
@@ -202,7 +201,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
 
 
 		if (wl_debug)
-			wl_closure_print(closure, object);
+			wl_closure_print(closure, object, false);
 
 		wl_closure_invoke(closure, object,
 				  object->implementation[opcode], client);
-- 
1.7.2.2



More information about the wayland-devel mailing list