xwm: convert WM_DEBUG into a weston-debug scope

Instead of a compile time choice, offer the XWM debugging messages
through the weston-debug protocol and tool on demand. Users will not
need to recompile weston to get XWM debugging, and it won't flood the
weston log.

The debug scope needs to be initialized in launcher.c for it be
available from start, before the first X11 client tries to connect and
initializes XWM.

Signed-off-by: Pekka Paalanen <pq@iki.fi>

pass the wm_debug scope to weston_debug_scope_printf API to append
the scopename to the timestr

Signed-off-by: Maniraj Devadoss <Maniraj.Devadoss@in.bosch.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
dev
Pekka Paalanen 7 years ago committed by Daniel Stone
parent b3b0065598
commit 9b72eb7930
  1. 7
      xwayland/launcher.c
  2. 86
      xwayland/window-manager.c
  3. 3
      xwayland/xwayland.h

@ -229,6 +229,8 @@ weston_xserver_destroy(struct wl_listener *l, void *data)
if (wxs->loop) if (wxs->loop)
weston_xserver_shutdown(wxs); weston_xserver_shutdown(wxs);
weston_debug_scope_destroy(wxs->wm_debug);
free(wxs); free(wxs);
} }
@ -391,5 +393,10 @@ weston_module_init(struct weston_compositor *compositor)
wxs->destroy_listener.notify = weston_xserver_destroy; wxs->destroy_listener.notify = weston_xserver_destroy;
wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener); wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener);
wxs->wm_debug = weston_compositor_add_debug_scope(wxs->compositor,
"xwm-wm-x11",
"XWM's window management X11 events\n",
NULL, NULL);
return 0; return 0;
} }

@ -193,23 +193,27 @@ static void
xserver_map_shell_surface(struct weston_wm_window *window, xserver_map_shell_surface(struct weston_wm_window *window,
struct weston_surface *surface); struct weston_surface *surface);
static int __attribute__ ((format (printf, 1, 2))) static bool
wm_log(const char *fmt, ...) wm_debug_is_enabled(struct weston_wm *wm)
{ {
#ifdef WM_DEBUG return weston_debug_scope_is_enabled(wm->server->wm_debug);
int l; }
va_list argp;
va_start(argp, fmt); static void __attribute__ ((format (printf, 2, 3)))
l = weston_vlog(fmt, argp); wm_printf(struct weston_wm *wm, const char *fmt, ...)
va_end(argp); {
va_list ap;
char timestr[128];
return l; if (wm_debug_is_enabled(wm))
#else weston_debug_scope_printf(wm->server->wm_debug, "%s ",
return 0; weston_debug_scope_timestamp(wm->server->wm_debug,
#endif timestr, sizeof timestr));
}
va_start(ap, fmt);
weston_debug_scope_vprintf(wm->server->wm_debug, fmt, ap);
va_end(ap);
}
static void static void
weston_output_weak_ref_init(struct weston_output_weak_ref *ref) weston_output_weak_ref_init(struct weston_output_weak_ref *ref)
{ {
@ -717,7 +721,7 @@ weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *ev
uint32_t mask, values[16]; uint32_t mask, values[16];
int x, y, width, height, i = 0; int x, y, width, height, i = 0;
wm_log("XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n", wm_printf(wm, "XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n",
configure_request->window, configure_request->window,
configure_request->x, configure_request->y, configure_request->x, configure_request->y,
configure_request->width, configure_request->height); configure_request->width, configure_request->height);
@ -786,7 +790,7 @@ weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *eve
wm->server->compositor->xwayland_interface; wm->server->compositor->xwayland_interface;
struct weston_wm_window *window; struct weston_wm_window *window;
wm_log("XCB_CONFIGURE_NOTIFY (window %d) %d,%d @ %dx%d%s\n", wm_printf(wm, "XCB_CONFIGURE_NOTIFY (window %d) %d,%d @ %dx%d%s\n",
configure_notify->window, configure_notify->window,
configure_notify->x, configure_notify->y, configure_notify->x, configure_notify->y,
configure_notify->width, configure_notify->height, configure_notify->width, configure_notify->height,
@ -839,7 +843,7 @@ weston_wm_create_surface(struct wl_listener *listener, void *data)
if (wl_resource_get_client(surface->resource) != wm->server->client) if (wl_resource_get_client(surface->resource) != wm->server->client)
return; return;
wm_log("XWM: create weston_surface %p\n", surface); wm_printf(wm, "XWM: create weston_surface %p\n", surface);
wl_list_for_each(window, &wm->unpaired_window_list, link) wl_list_for_each(window, &wm->unpaired_window_list, link)
if (window->surface_id == if (window->surface_id ==
@ -1096,7 +1100,7 @@ weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
struct weston_output *output; struct weston_output *output;
if (our_resource(wm, map_request->window)) { if (our_resource(wm, map_request->window)) {
wm_log("XCB_MAP_REQUEST (window %d, ours)\n", wm_printf(wm, "XCB_MAP_REQUEST (window %d, ours)\n",
map_request->window); map_request->window);
return; return;
} }
@ -1126,7 +1130,7 @@ weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
weston_wm_window_create_frame(window); /* sets frame_id */ weston_wm_window_create_frame(window); /* sets frame_id */
assert(window->frame_id != XCB_WINDOW_NONE); assert(window->frame_id != XCB_WINDOW_NONE);
wm_log("XCB_MAP_REQUEST (window %d, %p, frame %d, %dx%d @ %d,%d)\n", wm_printf(wm, "XCB_MAP_REQUEST (window %d, %p, frame %d, %dx%d @ %d,%d)\n",
window->id, window, window->frame_id, window->id, window, window->frame_id,
window->width, window->height, window->width, window->height,
window->map_request_x, window->map_request_y); window->map_request_x, window->map_request_y);
@ -1157,12 +1161,12 @@ weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event)
xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event; xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event;
if (our_resource(wm, map_notify->window)) { if (our_resource(wm, map_notify->window)) {
wm_log("XCB_MAP_NOTIFY (window %d, ours)\n", wm_printf(wm, "XCB_MAP_NOTIFY (window %d, ours)\n",
map_notify->window); map_notify->window);
return; return;
} }
wm_log("XCB_MAP_NOTIFY (window %d%s)\n", map_notify->window, wm_printf(wm, "XCB_MAP_NOTIFY (window %d%s)\n", map_notify->window,
map_notify->override_redirect ? ", override" : ""); map_notify->override_redirect ? ", override" : "");
} }
@ -1173,7 +1177,7 @@ weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event)
(xcb_unmap_notify_event_t *) event; (xcb_unmap_notify_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
wm_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n", wm_printf(wm, "XCB_UNMAP_NOTIFY (window %d, event %d%s)\n",
unmap_notify->window, unmap_notify->window,
unmap_notify->event, unmap_notify->event,
our_resource(wm, unmap_notify->window) ? ", ours" : ""); our_resource(wm, unmap_notify->window) ? ", ours" : "");
@ -1216,7 +1220,7 @@ weston_wm_window_draw_decoration(struct weston_wm_window *window)
cairo_t *cr; cairo_t *cr;
int width, height; int width, height;
wm_log("XWM: draw decoration, win %d\n", window->id); wm_printf(window->wm, "XWM: draw decoration, win %d\n", window->id);
weston_wm_window_get_frame_size(window, &width, &height); weston_wm_window_get_frame_size(window, &width, &height);
@ -1279,7 +1283,7 @@ weston_wm_window_set_pending_state(struct weston_wm_window *window)
input_h = height; input_h = height;
} }
wm_log("XWM: win %d geometry: %d,%d %dx%d\n", wm_printf(window->wm, "XWM: win %d geometry: %d,%d %dx%d\n",
window->id, input_x, input_y, input_w, input_h); window->id, input_x, input_y, input_w, input_h);
pixman_region32_fini(&window->surface->pending.input); pixman_region32_fini(&window->surface->pending.input);
@ -1347,7 +1351,7 @@ weston_wm_window_schedule_repaint(struct weston_wm_window *window)
if (window->repaint_source) if (window->repaint_source)
return; return;
wm_log("XWM: schedule repaint, win %d\n", window->id); wm_printf(wm, "XWM: schedule repaint, win %d\n", window->id);
window->repaint_source = window->repaint_source =
wl_event_loop_add_idle(wm->server->loop, wl_event_loop_add_idle(wm->server->loop,
@ -1360,18 +1364,24 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
xcb_property_notify_event_t *property_notify = xcb_property_notify_event_t *property_notify =
(xcb_property_notify_event_t *) event; (xcb_property_notify_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
FILE *fp; FILE *fp = NULL;
char *logstr; char *logstr;
size_t logsize; size_t logsize;
char timestr[128];
if (!wm_lookup_window(wm, property_notify->window, &window)) if (!wm_lookup_window(wm, property_notify->window, &window))
return; return;
window->properties_dirty = 1; window->properties_dirty = 1;
if (wm_debug_is_enabled(wm))
fp = open_memstream(&logstr, &logsize); fp = open_memstream(&logstr, &logsize);
if (fp) { if (fp) {
fprintf(fp, "XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window); fprintf(fp, "%s XCB_PROPERTY_NOTIFY: window %d, ",
weston_debug_scope_timestamp(wm->server->wm_debug,
timestr, sizeof timestr),
property_notify->window);
if (property_notify->state == XCB_PROPERTY_DELETE) if (property_notify->state == XCB_PROPERTY_DELETE)
fprintf(fp, "deleted %s\n", fprintf(fp, "deleted %s\n",
get_atom_name(wm->conn, property_notify->atom)); get_atom_name(wm->conn, property_notify->atom));
@ -1380,7 +1390,8 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
property_notify->atom); property_notify->atom);
if (fclose(fp) == 0) if (fclose(fp) == 0)
wm_log("%s", logstr); weston_debug_scope_write(wm->server->wm_debug,
logstr, logsize);
free(logstr); free(logstr);
} else { } else {
/* read_and_dump_property() is a X11 roundtrip. /* read_and_dump_property() is a X11 roundtrip.
@ -1406,7 +1417,7 @@ weston_wm_window_create(struct weston_wm *wm,
window = zalloc(sizeof *window); window = zalloc(sizeof *window);
if (window == NULL) { if (window == NULL) {
wm_log("failed to allocate window\n"); wm_printf(wm, "failed to allocate window\n");
return; return;
} }
@ -1479,7 +1490,7 @@ weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event)
xcb_create_notify_event_t *create_notify = xcb_create_notify_event_t *create_notify =
(xcb_create_notify_event_t *) event; (xcb_create_notify_event_t *) event;
wm_log("XCB_CREATE_NOTIFY (window %d, at (%d, %d), width %d, height %d%s%s)\n", wm_printf(wm, "XCB_CREATE_NOTIFY (window %d, at (%d, %d), width %d, height %d%s%s)\n",
create_notify->window, create_notify->window,
create_notify->x, create_notify->y, create_notify->x, create_notify->y,
create_notify->width, create_notify->height, create_notify->width, create_notify->height,
@ -1502,7 +1513,7 @@ weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event
(xcb_destroy_notify_event_t *) event; (xcb_destroy_notify_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
wm_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n", wm_printf(wm, "XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
destroy_notify->window, destroy_notify->window,
destroy_notify->event, destroy_notify->event,
our_resource(wm, destroy_notify->window) ? ", ours" : ""); our_resource(wm, destroy_notify->window) ? ", ours" : "");
@ -1523,7 +1534,7 @@ weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *even
(xcb_reparent_notify_event_t *) event; (xcb_reparent_notify_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
wm_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d%s)\n", wm_printf(wm, "XCB_REPARENT_NOTIFY (window %d, parent %d, event %d%s)\n",
reparent_notify->window, reparent_notify->window,
reparent_notify->parent, reparent_notify->parent,
reparent_notify->event, reparent_notify->event,
@ -1734,7 +1745,7 @@ surface_destroy(struct wl_listener *listener, void *data)
container_of(listener, container_of(listener,
struct weston_wm_window, surface_destroy_listener); struct weston_wm_window, surface_destroy_listener);
wm_log("surface for xid %d destroyed\n", window->id); wm_printf(window->wm, "surface for xid %d destroyed\n", window->id);
/* This should have been freed by the shell. /* This should have been freed by the shell.
* Don't try to use it later. */ * Don't try to use it later. */
@ -1750,7 +1761,8 @@ weston_wm_window_handle_surface_id(struct weston_wm_window *window,
struct wl_resource *resource; struct wl_resource *resource;
if (window->surface_id != 0) { if (window->surface_id != 0) {
wm_log("already have surface id for window %d\n", window->id); wm_printf(wm, "already have surface id for window %d\n",
window->id);
return; return;
} }
@ -1782,7 +1794,7 @@ weston_wm_handle_client_message(struct weston_wm *wm,
(xcb_client_message_event_t *) event; (xcb_client_message_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n", wm_printf(wm, "XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n",
get_atom_name(wm->conn, client_message->type), get_atom_name(wm->conn, client_message->type),
client_message->data.data32[0], client_message->data.data32[0],
client_message->data.data32[1], client_message->data.data32[1],
@ -2007,7 +2019,7 @@ weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event)
uint32_t button_id; uint32_t button_id;
uint32_t double_click = 0; uint32_t double_click = 0;
wm_log("XCB_BUTTON_%s (detail %d)\n", wm_printf(wm, "XCB_BUTTON_%s (detail %d)\n",
button->response_type == XCB_BUTTON_PRESS ? button->response_type == XCB_BUTTON_PRESS ?
"PRESS" : "RELEASE", button->detail); "PRESS" : "RELEASE", button->detail);
@ -2221,7 +2233,7 @@ weston_wm_handle_event(int fd, uint32_t mask, void *data)
weston_wm_handle_destroy_notify(wm, event); weston_wm_handle_destroy_notify(wm, event);
break; break;
case XCB_MAPPING_NOTIFY: case XCB_MAPPING_NOTIFY:
wm_log("XCB_MAPPING_NOTIFY\n"); wm_printf(wm, "XCB_MAPPING_NOTIFY\n");
break; break;
case XCB_PROPERTY_NOTIFY: case XCB_PROPERTY_NOTIFY:
weston_wm_handle_property_notify(wm, event); weston_wm_handle_property_notify(wm, event);
@ -2837,7 +2849,7 @@ xserver_map_shell_surface(struct weston_wm_window *window,
window->surface, window->surface,
&shell_client); &shell_client);
wm_log("XWM: map shell surface, win %d, weston_surface %p, xwayland surface %p\n", wm_printf(wm, "XWM: map shell surface, win %d, weston_surface %p, xwayland surface %p\n",
window->id, window->surface, window->shsurf); window->id, window->surface, window->shsurf);
if (window->name) if (window->name)

@ -33,6 +33,7 @@
#include "compositor.h" #include "compositor.h"
#include "compositor/weston.h" #include "compositor/weston.h"
#include "xwayland-api.h" #include "xwayland-api.h"
#include "weston-debug.h"
#define SEND_EVENT_MASK (0x80) #define SEND_EVENT_MASK (0x80)
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK) #define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
@ -52,6 +53,8 @@ struct weston_xserver {
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
weston_xwayland_spawn_xserver_func_t spawn_func; weston_xwayland_spawn_xserver_func_t spawn_func;
void *user_data; void *user_data;
struct weston_debug_scope *wm_debug;
}; };
struct weston_wm { struct weston_wm {

Loading…
Cancel
Save