| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | #include <pthread.h>
 | 
					
						
							| 
									
										
										
										
											2013-09-13 15:27:43 +09:00
										 |  |  | #include <dlfcn.h>
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-03 11:53:06 +09:00
										 |  |  | #include "../util/cache.h"
 | 
					
						
							|  |  |  | #include "../util/debug.h"
 | 
					
						
							|  |  |  | #include "../util/hist.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-25 13:45:16 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; | 
					
						
							| 
									
										
										
										
											2013-09-13 15:27:43 +09:00
										 |  |  | void *perf_gtk_handle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef HAVE_GTK2_SUPPORT
 | 
					
						
							|  |  |  | static int setup_gtk_browser(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int (*perf_ui_init)(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (perf_gtk_handle) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	perf_gtk_handle = dlopen(PERF_GTK_DSO, RTLD_LAZY); | 
					
						
							|  |  |  | 	if (perf_gtk_handle == NULL) { | 
					
						
							|  |  |  | 		char buf[PATH_MAX]; | 
					
						
							|  |  |  | 		scnprintf(buf, sizeof(buf), "%s/%s", LIBDIR, PERF_GTK_DSO); | 
					
						
							|  |  |  | 		perf_gtk_handle = dlopen(buf, RTLD_LAZY); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (perf_gtk_handle == NULL) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	perf_ui_init = dlsym(perf_gtk_handle, "perf_gtk__init"); | 
					
						
							|  |  |  | 	if (perf_ui_init == NULL) | 
					
						
							|  |  |  | 		goto out_close; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (perf_ui_init() == 0) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out_close: | 
					
						
							|  |  |  | 	dlclose(perf_gtk_handle); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void exit_gtk_browser(bool wait_for_ok) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void (*perf_ui_exit)(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (perf_gtk_handle == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	perf_ui_exit = dlsym(perf_gtk_handle, "perf_gtk__exit"); | 
					
						
							|  |  |  | 	if (perf_ui_exit == NULL) | 
					
						
							|  |  |  | 		goto out_close; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	perf_ui_exit(wait_for_ok); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out_close: | 
					
						
							|  |  |  | 	dlclose(perf_gtk_handle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	perf_gtk_handle = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline int setup_gtk_browser(void) { return -1; } | 
					
						
							|  |  |  | static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:14:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | void setup_browser(bool fallback_to_pager) | 
					
						
							| 
									
										
										
										
											2011-10-20 16:59:15 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-07 18:02:08 +09:00
										 |  |  | 	if (use_browser < 2 && (!isatty(1) || dump_trace)) | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 		use_browser = 0; | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:05 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 	/* default to TUI */ | 
					
						
							|  |  |  | 	if (use_browser < 0) | 
					
						
							|  |  |  | 		use_browser = 1; | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:05 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 	switch (use_browser) { | 
					
						
							|  |  |  | 	case 2: | 
					
						
							| 
									
										
										
										
											2013-09-13 15:27:43 +09:00
										 |  |  | 		if (setup_gtk_browser() == 0) | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:09 +09:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2013-09-13 15:27:43 +09:00
										 |  |  | 		printf("GTK browser requested but could not find %s\n", | 
					
						
							|  |  |  | 		       PERF_GTK_DSO); | 
					
						
							|  |  |  | 		sleep(1); | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:09 +09:00
										 |  |  | 		/* fall through */ | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 	case 1: | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:09 +09:00
										 |  |  | 		use_browser = 1; | 
					
						
							|  |  |  | 		if (ui__init() == 0) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		/* fall through */ | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2012-05-28 23:53:22 +09:00
										 |  |  | 		use_browser = 0; | 
					
						
							| 
									
										
										
										
											2011-01-31 18:08:39 -02:00
										 |  |  | 		if (fallback_to_pager) | 
					
						
							|  |  |  | 			setup_pager(); | 
					
						
							| 
									
										
										
										
											2012-09-03 11:53:06 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-04 21:49:39 +09:00
										 |  |  | 		perf_hpp__init(); | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-08-10 15:58:50 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void exit_browser(bool wait_for_ok) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 	switch (use_browser) { | 
					
						
							|  |  |  | 	case 2: | 
					
						
							| 
									
										
										
										
											2013-09-13 15:27:43 +09:00
										 |  |  | 		exit_gtk_browser(wait_for_ok); | 
					
						
							| 
									
										
										
										
											2012-04-30 13:55:08 +09:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		ui__exit(wait_for_ok); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-08-10 15:58:50 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |