[PATCH] debug: select only needed interfaces when tracing
Tiago Vignatti
tiago.vignatti at intel.com
Wed Jul 27 08:12:08 PDT 2011
If WAYLAND_DEBUG is set, then it prints all the interfaces but the ones
starting with '-'. So it is possible to group several interfaces to
exclude when tracing, using comma for separating them. For instance,
setting WAYLAND_DEBUG="-wl_input_device, -wl_shell" will print all the
interfaces but not the input-device neither the shell ones.
Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
wayland/Makefile.am | 2 +
wayland/connection.c | 4 ++
wayland/debug-trace.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++
wayland/debug-trace.h | 35 +++++++++++++++++
wayland/wayland-client.c | 14 ++-----
wayland/wayland-server.c | 14 ++-----
6 files changed, 142 insertions(+), 20 deletions(-)
create mode 100644 wayland/debug-trace.c
create mode 100644 wayland/debug-trace.h
diff --git a/wayland/Makefile.am b/wayland/Makefile.am
index 8a73cd3..af032cc 100644
--- a/wayland/Makefile.am
+++ b/wayland/Makefile.am
@@ -12,6 +12,8 @@ include_HEADERS = \
libwayland_util_la_SOURCES = \
connection.c \
connection.h \
+ debug-trace.c \
+ debug-trace.h \
wayland-util.c \
wayland-util.h \
wayland-hash.c
diff --git a/wayland/connection.c b/wayland/connection.c
index 467a2d0..a7062e3 100644
--- a/wayland/connection.c
+++ b/wayland/connection.c
@@ -38,6 +38,7 @@
#include "wayland-util.h"
#include "connection.h"
+#include "debug-trace.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
@@ -696,6 +697,9 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
struct timespec tp;
unsigned int time;
+ if (!wl_debug_trace_select(target->interface->name))
+ return;
+
clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
diff --git a/wayland/debug-trace.c b/wayland/debug-trace.c
new file mode 100644
index 0000000..a9c3fd2
--- /dev/null
+++ b/wayland/debug-trace.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * Author:
+ * Tiago Vignatti <vignatti at freedesktop.org>
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "wayland-util.h"
+#include "debug-trace.h"
+
+static int wl_debug = 0;
+static struct wl_list donot_trace_list;
+
+struct debug_interface {
+ char *name;
+ struct wl_list link;
+};
+
+static void
+parse(char *env) {
+ char *tok = NULL;
+
+ tok = strtok (env, ",");
+ while (tok) {
+ /* trim blank space */
+ while(isblank(*tok))
+ tok++;
+
+ if (*tok == '-') {
+ struct debug_interface *interface = NULL;
+
+ interface = malloc (sizeof *interface);
+
+ tok++;
+ interface->name = strdup (tok);
+ wl_list_insert(&donot_trace_list, &interface->link);
+ }
+ tok = strtok (NULL, ",");
+ }
+}
+
+WL_EXPORT void
+wl_debug_init(void)
+{
+ char *debug;
+
+ debug = getenv("WAYLAND_DEBUG");
+ if (!debug)
+ return;
+
+ wl_list_init(&donot_trace_list);
+ parse(debug);
+
+ wl_debug = 1;
+}
+
+WL_EXPORT int
+wl_debug_trace_select(const char *name)
+{
+ struct debug_interface *p;
+
+ if (!wl_debug)
+ return 0;
+
+ wl_list_for_each(p, &donot_trace_list, link)
+ if (!strcmp(name, p->name))
+ return 0;
+
+ return 1;
+}
diff --git a/wayland/debug-trace.h b/wayland/debug-trace.h
new file mode 100644
index 0000000..df37b29
--- /dev/null
+++ b/wayland/debug-trace.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * Author:
+ * Tiago Vignatti <vignatti at freedesktop.org>
+ *
+ */
+
+/*
+ * if WAYLAND_DEBUG is set, then it prints all the interfaces but the ones
+ * starting with '-'. So it is possible to group several interfaces to
+ * exclude when tracing, using comma for separating them. For instance, setting
+ * WAYLAND_DEBUG="-wl_input_device, -wl_shell" will print all the interfaces
+ * but not the input-device neither the shell ones.
+ */
+void wl_debug_init(void);
+int wl_debug_trace_select(const char *name);
diff --git a/wayland/wayland-client.c b/wayland/wayland-client.c
index 9d1f66b..a788a2a 100644
--- a/wayland/wayland-client.c
+++ b/wayland/wayland-client.c
@@ -38,6 +38,7 @@
#include "connection.h"
#include "wayland-util.h"
#include "wayland-client.h"
+#include "debug-trace.h"
struct wl_global_listener {
wl_display_global_func_t handler;
@@ -93,8 +94,6 @@ struct wl_display {
uint32_t key;
};
-static int wl_debug = 0;
-
static int
connection_update(struct wl_connection *connection,
uint32_t mask, void *data)
@@ -202,8 +201,7 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
wl_closure_send(closure, proxy->display->connection);
- if (wl_debug)
- wl_closure_print(closure, &proxy->object, true);
+ wl_closure_print(closure, &proxy->object, true);
wl_closure_destroy(closure);
}
@@ -361,13 +359,10 @@ WL_EXPORT struct wl_display *
wl_display_connect(const char *name)
{
struct wl_display *display;
- const char *debug;
char *connection, *end;
int flags;
- debug = getenv("WAYLAND_DEBUG");
- if (debug)
- wl_debug = 1;
+ wl_debug_init();
display = malloc(sizeof *display);
if (display == NULL)
@@ -526,8 +521,7 @@ handle_event(struct wl_display *display,
abort();
}
- if (wl_debug)
- wl_closure_print(closure, &proxy->object, false);
+ 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 2019cb4..b75df67 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -44,6 +44,7 @@
#include "wayland-server.h"
#include "wayland-server-protocol.h"
#include "connection.h"
+#include "debug-trace.h"
struct wl_socket {
int fd;
@@ -92,8 +93,6 @@ struct wl_global {
struct wl_list link;
};
-static int wl_debug = 0;
-
WL_EXPORT void
wl_client_post_event(struct wl_client *client, struct wl_object *sender,
uint32_t opcode, ...)
@@ -109,8 +108,7 @@ wl_client_post_event(struct wl_client *client, struct wl_object *sender,
wl_closure_send(closure, client->connection);
- if (wl_debug)
- wl_closure_print(closure, sender, true);
+ wl_closure_print(closure, sender, true);
wl_closure_destroy(closure);
}
@@ -200,8 +198,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
}
- if (wl_debug)
- wl_closure_print(closure, object, false);
+ wl_closure_print(closure, object, false);
wl_closure_invoke(closure, object,
object->implementation[opcode], client);
@@ -583,11 +580,8 @@ WL_EXPORT struct wl_display *
wl_display_create(void)
{
struct wl_display *display;
- const char *debug;
- debug = getenv("WAYLAND_DEBUG");
- if (debug)
- wl_debug = 1;
+ wl_debug_init();
display = malloc(sizeof *display);
if (display == NULL)
--
1.7.2.2
More information about the wayland-devel
mailing list