Debug: Enhanced debugging capability

- Change all #if DEBUG_XXX directives to #ifdef, thus making it
  possible to directly enable debugging options with CFLAGS
  (-DDEBUG_XXX).

- Print timestamp before event debugging messages.
This commit is contained in:
Richard Grenville 2012-09-12 09:08:15 +08:00
parent c905c882b4
commit f280750a03
2 changed files with 91 additions and 23 deletions

View File

@ -10,14 +10,14 @@
#include "compton.h" #include "compton.h"
#if DEBUG_EVENTS
static int window_get_name(Window w, char **name);
#endif
/** /**
* Shared * Shared
*/ */
#ifdef DEBUG_EVENTS
struct timeval time_start = { 0, 0 };
#endif
win *list; win *list;
fade *fades; fade *fades;
Display *dpy; Display *dpy;
@ -955,7 +955,7 @@ paint_all(Display *dpy, XserverRegion region) {
region = get_screen_region(dpy); region = get_screen_region(dpy);
} }
#if MONITOR_REPAINT #ifdef MONITOR_REPAINT
root_buffer = root_picture; root_buffer = root_picture;
#else #else
if (!root_buffer) { if (!root_buffer) {
@ -973,14 +973,14 @@ paint_all(Display *dpy, XserverRegion region) {
XFixesSetPictureClipRegion(dpy, root_picture, 0, 0, region); XFixesSetPictureClipRegion(dpy, root_picture, 0, 0, region);
#if MONITOR_REPAINT #ifdef MONITOR_REPAINT
XRenderComposite( XRenderComposite(
dpy, PictOpSrc, black_picture, None, dpy, PictOpSrc, black_picture, None,
root_picture, 0, 0, 0, 0, 0, 0, root_picture, 0, 0, 0, 0, 0, 0,
root_width, root_height); root_width, root_height);
#endif #endif
#if DEBUG_REPAINT #ifdef DEBUG_REPAINT
printf("paint:"); printf("paint:");
#endif #endif
@ -1017,7 +1017,7 @@ paint_all(Display *dpy, XserverRegion region) {
dpy, draw, format, CPSubwindowMode, &pa); dpy, draw, format, CPSubwindowMode, &pa);
} }
#if DEBUG_REPAINT #ifdef DEBUG_REPAINT
printf(" 0x%x", w->id); printf(" 0x%x", w->id);
#endif #endif
@ -1077,7 +1077,7 @@ paint_all(Display *dpy, XserverRegion region) {
t = w; t = w;
} }
#if DEBUG_REPAINT #ifdef DEBUG_REPAINT
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
#endif #endif
@ -1212,7 +1212,7 @@ repair_win(Display *dpy, win *w) {
w->damaged = 1; w->damaged = 1;
} }
#if DEBUG_WINTYPE #ifdef DEBUG_WINTYPE
static const char * static const char *
wintype_name(wintype type) { wintype_name(wintype type) {
const char *t; const char *t;
@ -1357,7 +1357,7 @@ map_win(Display *dpy, Window id,
w->a.map_state = IsViewable; w->a.map_state = IsViewable;
w->window_type = determine_wintype(dpy, w->id, w->id); w->window_type = determine_wintype(dpy, w->id, w->id);
#if DEBUG_WINTYPE #ifdef DEBUG_WINTYPE
printf("window 0x%x type %s\n", printf("window 0x%x type %s\n",
w->id, wintype_name(w->window_type)); w->id, wintype_name(w->window_type));
#endif #endif
@ -1729,7 +1729,7 @@ restack_win(Display *dpy, win *w, Window new_above) {
w->next = *prev; w->next = *prev;
*prev = w; *prev = w;
#if DEBUG_RESTACK #ifdef DEBUG_RESTACK
{ {
const char *desc; const char *desc;
char *window_name; char *window_name;
@ -2087,7 +2087,7 @@ expose_root(Display *dpy, Window root, XRectangle *rects, int nrects) {
add_damage(dpy, region); add_damage(dpy, region);
} }
#if DEBUG_EVENTS || DEBUG_RESTACK #if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
static int window_get_name(Window w, char **name) { static int window_get_name(Window w, char **name) {
Atom prop = XInternAtom(dpy, "_NET_WM_NAME", False); Atom prop = XInternAtom(dpy, "_NET_WM_NAME", False);
Atom utf8_type = XInternAtom(dpy, "UTF8_STRING", False); Atom utf8_type = XInternAtom(dpy, "UTF8_STRING", False);
@ -2104,7 +2104,7 @@ static int window_get_name(Window w, char **name) {
&leftover, (unsigned char **) &data))) { &leftover, (unsigned char **) &data))) {
if (BadWindow == ret) if (BadWindow == ret)
return 0; return 0;
set_ignore(dpy, NextRequest(dpy)); set_ignore(dpy, NextRequest(dpy));
printf("Window %#010lx: _NET_WM_NAME unset, falling back to WM_NAME.\n", w); printf("Window %#010lx: _NET_WM_NAME unset, falling back to WM_NAME.\n", w);
if (!XFetchName(dpy, w, &data)) if (!XFetchName(dpy, w, &data))
return 0; return 0;
@ -2113,7 +2113,9 @@ static int window_get_name(Window w, char **name) {
*name = (char *) data; *name = (char *) data;
return 1; return 1;
} }
#endif
#ifdef DEBUG_EVENTS
static int static int
ev_serial(XEvent *ev) { ev_serial(XEvent *ev) {
if ((ev->type & 0x7f) != KeymapNotify) { if ((ev->type & 0x7f) != KeymapNotify) {
@ -2232,7 +2234,7 @@ ev_create_notify(XCreateWindowEvent *ev) {
inline static void inline static void
ev_configure_notify(XConfigureEvent *ev) { ev_configure_notify(XConfigureEvent *ev) {
#if DEBUG_EVENTS #ifdef DEBUG_EVENTS
printf("{ send_event: %d, above: %#010lx, override_redirect: %d }\n", ev->send_event, ev->above, ev->override_redirect); printf("{ send_event: %d, above: %#010lx, override_redirect: %d }\n", ev->send_event, ev->above, ev->override_redirect);
#endif #endif
configure_win(dpy, ev); configure_win(dpy, ev);
@ -2357,7 +2359,7 @@ static void ev_shape_notify(XShapeEvent *ev) {
inline static void inline static void
ev_handle(XEvent *ev) { ev_handle(XEvent *ev) {
#if DEBUG_EVENTS #ifdef DEBUG_EVENTS
Window w; Window w;
char *window_name; char *window_name;
Bool to_free = False; Bool to_free = False;
@ -2367,7 +2369,7 @@ ev_handle(XEvent *ev) {
discard_ignore(dpy, ev->xany.serial); discard_ignore(dpy, ev->xany.serial);
} }
#if DEBUG_EVENTS #ifdef DEBUG_EVENTS
w = ev_window(ev); w = ev_window(ev);
window_name = "(Failed to get title)"; window_name = "(Failed to get title)";
if (w) { if (w) {
@ -2377,6 +2379,7 @@ ev_handle(XEvent *ev) {
to_free = (Bool) window_get_name(w, &window_name); to_free = (Bool) window_get_name(w, &window_name);
} }
if (ev->type != damage_event + XDamageNotify) { if (ev->type != damage_event + XDamageNotify) {
print_timestamp();
printf("event %10.10s serial %#010x window %#010lx \"%s\"\n", printf("event %10.10s serial %#010x window %#010lx \"%s\"\n",
ev_name(ev), ev_serial(ev), w, window_name); ev_name(ev), ev_serial(ev), w, window_name);
} }
@ -2616,6 +2619,10 @@ main(int argc, char **argv) {
double shadow_green = 0.0; double shadow_green = 0.0;
double shadow_blue = 0.0; double shadow_blue = 0.0;
#ifdef DEBUG_EVENTS
gettimeofday(&time_start, NULL);
#endif
for (i = 0; i < NUM_WINTYPES; ++i) { for (i = 0; i < NUM_WINTYPES; ++i) {
win_type_fade[i] = False; win_type_fade[i] = False;
win_type_shadow[i] = False; win_type_shadow[i] = False;

View File

@ -28,11 +28,19 @@
#endif #endif
#define CAN_DO_USABLE 0 #define CAN_DO_USABLE 0
#define DEBUG_REPAINT 0
#define DEBUG_EVENTS 0 // Debug options, enable them using -D in CFLAGS
#define DEBUG_RESTACK 0 // #define DEBUG_REPAINT 1
#define DEBUG_WINTYPE 0 // #define DEBUG_EVENTS 1
#define MONITOR_REPAINT 0 // #define DEBUG_RESTACK 1
// #define DEBUG_WINTYPE 1
// #define MONITOR_REPAINT 1
#ifdef DEBUG_EVENTS
// For printing timestamps
#include <time.h>
extern struct timeval time_start;
#endif
#define OPAQUE 0xffffffff #define OPAQUE 0xffffffff
#define REGISTER_PROP "_NET_WM_CM_S" #define REGISTER_PROP "_NET_WM_CM_S"
@ -173,6 +181,55 @@ static inline Bool array_wid_exists(const Window *arr,
return False; return False;
} }
#ifdef DEBUG_EVENTS
/*
* Subtracting two struct timeval values.
*
* Taken from glibc manual.
*
* Subtract the `struct timeval' values X and Y,
* storing the result in RESULT.
* Return 1 if the difference is negative, otherwise 0. */
int timeval_subtract (result, x, y)
struct timeval *result, *x, *y;
{
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_usec < y->tv_usec) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000) {
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_usec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
/**
* Print time passed since program starts execution.
*
* Used for debugging.
*/
static inline void print_timestamp(void) {
struct timeval tm, diff;
if (gettimeofday(&tm, NULL))
return;
timeval_subtract(&diff, &tm, &time_start);
printf("[ %5ld.%02ld ] ", diff.tv_sec, diff.tv_usec / 10000);
}
#endif
static int static int
get_time_in_milliseconds(); get_time_in_milliseconds();
@ -338,7 +395,11 @@ error(Display *dpy, XErrorEvent *ev);
static void static void
expose_root(Display *dpy, Window root, XRectangle *rects, int nrects); expose_root(Display *dpy, Window root, XRectangle *rects, int nrects);
#if DEBUG_EVENTS #if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
static int window_get_name(Window w, char **name);
#endif
#ifdef DEBUG_EVENTS
static int static int
ev_serial(XEvent *ev); ev_serial(XEvent *ev);