mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-10-29 05:40:16 -04:00 
			
		
		
		
	debug: Colorize output for easier reading
Signed-off-by: Caitlyn <caitlynrosestewart@gmail.com>
This commit is contained in:
		
							parent
							
								
									827d0c30ad
								
							
						
					
					
						commit
						ecff0ee10c
					
				
					 4 changed files with 69 additions and 18 deletions
				
			
		|  | @ -1494,7 +1494,7 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection) | ||||||
| void | 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, int discarded, uint32_t (*n_parse)(union wl_argument *arg), | 		 int send, int discarded, uint32_t (*n_parse)(union wl_argument *arg), | ||||||
| 		 const char *queue_name) | 		 const char *queue_name, int color) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct argument_details arg; | 	struct argument_details arg; | ||||||
|  | @ -1512,17 +1512,28 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, | ||||||
| 
 | 
 | ||||||
| 	clock_gettime(CLOCK_REALTIME, &tp); | 	clock_gettime(CLOCK_REALTIME, &tp); | ||||||
| 	time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); | 	time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); | ||||||
|  | 	fprintf(f, "%s[%7u.%03u] ", | ||||||
|  | 		color ? WL_DEBUG_COLOR_GREEN : "", | ||||||
|  | 		time / 1000, time % 1000); | ||||||
| 
 | 
 | ||||||
| 	fprintf(f, "[%7u.%03u] ", time / 1000, time % 1000); | 	if (queue_name) { | ||||||
|  | 		fprintf(f, "%s{%s} ", | ||||||
|  | 			color ? WL_DEBUG_COLOR_YELLOW : "", | ||||||
|  | 			queue_name); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	if (queue_name) | 	fprintf(f, "%s%s%s%s%s%s%s#%u%s.%s%s(", | ||||||
| 		fprintf(f, "{%s} ", queue_name); | 		color ? WL_DEBUG_COLOR_RED : "", | ||||||
| 
 |  | ||||||
| 	fprintf(f, "%s%s%s#%u.%s(", |  | ||||||
| 		discarded ? "discarded " : "", | 		discarded ? "discarded " : "", | ||||||
|  | 		color ? WL_DEBUG_COLOR_RESET : "", | ||||||
| 		send ? " -> " : "", | 		send ? " -> " : "", | ||||||
| 		target->interface->name, target->id, | 		color ? WL_DEBUG_COLOR_BLUE : "", | ||||||
| 		closure->message->name); | 		target->interface->name, | ||||||
|  | 		color ? WL_DEBUG_COLOR_MAGENTA : "", | ||||||
|  | 		target->id, | ||||||
|  | 		color ? WL_DEBUG_COLOR_CYAN : "", | ||||||
|  | 		closure->message->name, | ||||||
|  | 		color ? WL_DEBUG_COLOR_RESET : ""); | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < closure->count; i++) { | 	for (i = 0; i < closure->count; i++) { | ||||||
| 		signature = get_next_argument(signature, &arg); | 		signature = get_next_argument(signature, &arg); | ||||||
|  | @ -1587,7 +1598,7 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	fprintf(f, ")\n"); | 	fprintf(f, ")%s\n", color ? WL_DEBUG_COLOR_RESET : ""); | ||||||
| 
 | 
 | ||||||
| 	if (fclose(f) == 0) { | 	if (fclose(f) == 0) { | ||||||
| 		fprintf(stderr, "%s", buffer); | 		fprintf(stderr, "%s", buffer); | ||||||
|  |  | ||||||
|  | @ -115,6 +115,7 @@ struct wl_display { | ||||||
| /** \endcond */ | /** \endcond */ | ||||||
| 
 | 
 | ||||||
| static int debug_client = 0; | static int debug_client = 0; | ||||||
|  | static int debug_color = 0; | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * This helper function wakes up all threads that are |  * This helper function wakes up all threads that are | ||||||
|  | @ -936,7 +937,7 @@ wl_proxy_marshal_array_flags(struct wl_proxy *proxy, uint32_t opcode, | ||||||
| 			queue_name = wl_event_queue_get_name(queue); | 			queue_name = wl_event_queue_get_name(queue); | ||||||
| 
 | 
 | ||||||
| 		wl_closure_print(closure, &proxy->object, true, false, NULL, | 		wl_closure_print(closure, &proxy->object, true, false, NULL, | ||||||
| 				 queue_name); | 				 queue_name, debug_color); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (wl_closure_send(closure, proxy->display->connection)) { | 	if (wl_closure_send(closure, proxy->display->connection)) { | ||||||
|  | @ -1229,10 +1230,23 @@ wl_display_connect_to_fd(int fd) | ||||||
| { | { | ||||||
| 	struct wl_display *display; | 	struct wl_display *display; | ||||||
| 	const char *debug; | 	const char *debug; | ||||||
|  | 	const char *no_color; | ||||||
|  | 	const char *force_color; | ||||||
| 
 | 
 | ||||||
|  | 	no_color = getenv("NO_COLOR"); | ||||||
|  | 	force_color = getenv("FORCE_COLOR"); | ||||||
| 	debug = getenv("WAYLAND_DEBUG"); | 	debug = getenv("WAYLAND_DEBUG"); | ||||||
| 	if (debug && (strstr(debug, "client") || strstr(debug, "1"))) | 	if (debug && (strstr(debug, "client") || strstr(debug, "1"))) { | ||||||
| 		debug_client = 1; | 		debug_client = 1; | ||||||
|  | 		if (isatty(fileno(stderr))) | ||||||
|  | 			debug_color = 1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (force_color && force_color[0] != '\0') | ||||||
|  | 		debug_color = 1; | ||||||
|  | 
 | ||||||
|  | 	if (no_color && no_color[0] != '\0') | ||||||
|  | 		debug_color = 0; | ||||||
| 
 | 
 | ||||||
| 	display = zalloc(sizeof *display); | 	display = zalloc(sizeof *display); | ||||||
| 	if (display == NULL) { | 	if (display == NULL) { | ||||||
|  | @ -1578,12 +1592,16 @@ queue_event(struct wl_display *display, int len) | ||||||
| 		if (debug_client) { | 		if (debug_client) { | ||||||
| 			clock_gettime(CLOCK_REALTIME, &tp); | 			clock_gettime(CLOCK_REALTIME, &tp); | ||||||
| 			time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); | 			time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); | ||||||
| 
 | 			fprintf(stderr, "%s[%7u.%03u] %sdiscarded %s[%s]%s#%d%s.[event %d]%s" | ||||||
| 			fprintf(stderr, "[%7u.%03u] discarded [%s]#%d.[event %d]" |  | ||||||
| 				"(%d fd, %d byte)\n", | 				"(%d fd, %d byte)\n", | ||||||
|  | 				debug_color ? WL_DEBUG_COLOR_GREEN : "", | ||||||
| 				time / 1000, time % 1000, | 				time / 1000, time % 1000, | ||||||
|  | 				debug_color ? WL_DEBUG_COLOR_RED : "", | ||||||
|  | 				debug_color ? WL_DEBUG_COLOR_BLUE : "", | ||||||
| 				zombie ? "zombie" : "unknown", | 				zombie ? "zombie" : "unknown", | ||||||
| 				id, opcode, | 				debug_color ? WL_DEBUG_COLOR_MAGENTA : "", id, | ||||||
|  | 				debug_color ? WL_DEBUG_COLOR_BLUE : "", opcode, | ||||||
|  | 				debug_color ? WL_DEBUG_COLOR_RESET : "", | ||||||
| 				num_zombie_fds, size); | 				num_zombie_fds, size); | ||||||
| 		} | 		} | ||||||
| 		if (num_zombie_fds > 0) | 		if (num_zombie_fds > 0) | ||||||
|  | @ -1668,7 +1686,7 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue) | ||||||
| 				 !(proxy->dispatcher || proxy->object.implementation); | 				 !(proxy->dispatcher || proxy->object.implementation); | ||||||
| 
 | 
 | ||||||
| 		wl_closure_print(closure, &proxy->object, false, discarded, | 		wl_closure_print(closure, &proxy->object, false, discarded, | ||||||
| 				 id_from_object, queue->name); | 				 id_from_object, queue->name, debug_color); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (proxy_destroyed) { | 	if (proxy_destroyed) { | ||||||
|  |  | ||||||
|  | @ -50,6 +50,14 @@ | ||||||
| #define WL_BUFFER_DEFAULT_SIZE_POT 12 | #define WL_BUFFER_DEFAULT_SIZE_POT 12 | ||||||
| #define WL_BUFFER_DEFAULT_MAX_SIZE (1 << WL_BUFFER_DEFAULT_SIZE_POT) | #define WL_BUFFER_DEFAULT_MAX_SIZE (1 << WL_BUFFER_DEFAULT_SIZE_POT) | ||||||
| 
 | 
 | ||||||
|  | #define WL_DEBUG_COLOR_RESET "\e[0m" | ||||||
|  | #define WL_DEBUG_COLOR_RED "\e[31m" | ||||||
|  | #define WL_DEBUG_COLOR_GREEN "\e[32m" | ||||||
|  | #define WL_DEBUG_COLOR_YELLOW "\e[33m" | ||||||
|  | #define WL_DEBUG_COLOR_BLUE "\e[34m" | ||||||
|  | #define WL_DEBUG_COLOR_MAGENTA "\e[35m" | ||||||
|  | #define WL_DEBUG_COLOR_CYAN "\e[36m" | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Argument types used in signatures. |  * Argument types used in signatures. | ||||||
|  */ |  */ | ||||||
|  | @ -230,7 +238,7 @@ void | ||||||
| wl_closure_print(struct wl_closure *closure, | wl_closure_print(struct wl_closure *closure, | ||||||
| 		 struct wl_object *target, int send, int discarded, | 		 struct wl_object *target, int send, int discarded, | ||||||
| 		 uint32_t (*n_parse)(union wl_argument *arg), | 		 uint32_t (*n_parse)(union wl_argument *arg), | ||||||
| 		 const char *queue_name); | 		 const char *queue_name, int color); | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| wl_closure_destroy(struct wl_closure *closure); | wl_closure_destroy(struct wl_closure *closure); | ||||||
|  |  | ||||||
|  | @ -149,6 +149,7 @@ struct wl_protocol_logger { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static int debug_server = 0; | static int debug_server = 0; | ||||||
|  | static int debug_color = 0; | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
| log_closure(struct wl_resource *resource, | log_closure(struct wl_resource *resource, | ||||||
|  | @ -160,7 +161,7 @@ log_closure(struct wl_resource *resource, | ||||||
| 	struct wl_protocol_logger_message message; | 	struct wl_protocol_logger_message message; | ||||||
| 
 | 
 | ||||||
| 	if (debug_server) | 	if (debug_server) | ||||||
| 		wl_closure_print(closure, object, send, false, NULL, NULL); | 		wl_closure_print(closure, object, send, false, NULL, NULL, debug_color); | ||||||
| 
 | 
 | ||||||
| 	if (!wl_list_empty(&display->protocol_loggers)) { | 	if (!wl_list_empty(&display->protocol_loggers)) { | ||||||
| 		message.resource = resource; | 		message.resource = resource; | ||||||
|  | @ -1168,10 +1169,23 @@ wl_display_create(void) | ||||||
| { | { | ||||||
| 	struct wl_display *display; | 	struct wl_display *display; | ||||||
| 	const char *debug; | 	const char *debug; | ||||||
|  | 	const char *no_color; | ||||||
|  | 	const char *force_color; | ||||||
| 
 | 
 | ||||||
|  | 	no_color = getenv("NO_COLOR"); | ||||||
|  | 	force_color = getenv("FORCE_COLOR"); | ||||||
| 	debug = getenv("WAYLAND_DEBUG"); | 	debug = getenv("WAYLAND_DEBUG"); | ||||||
| 	if (debug && (strstr(debug, "server") || strstr(debug, "1"))) | 	if (debug && (strstr(debug, "server") || strstr(debug, "1"))) { | ||||||
| 		debug_server = 1; | 		debug_server = 1; | ||||||
|  | 		if (isatty(fileno(stderr))) | ||||||
|  | 			debug_color = 1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (force_color && force_color[0] != '\0') | ||||||
|  | 		debug_color = 1; | ||||||
|  | 
 | ||||||
|  | 	if (no_color && no_color[0] != '\0') | ||||||
|  | 		debug_color = 0; | ||||||
| 
 | 
 | ||||||
| 	display = zalloc(sizeof *display); | 	display = zalloc(sizeof *display); | ||||||
| 	if (display == NULL) | 	if (display == NULL) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Caitlyn
						Caitlyn