diff options
Diffstat (limited to 'tools/perf/ui/setup.c')
-rw-r--r-- | tools/perf/ui/setup.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index 47d9a571f261..5df5140a9f29 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c | |||
@@ -1,10 +1,64 @@ | |||
1 | #include <pthread.h> | 1 | #include <pthread.h> |
2 | #include <dlfcn.h> | ||
2 | 3 | ||
3 | #include "../util/cache.h" | 4 | #include "../util/cache.h" |
4 | #include "../util/debug.h" | 5 | #include "../util/debug.h" |
5 | #include "../util/hist.h" | 6 | #include "../util/hist.h" |
6 | 7 | ||
7 | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; | 8 | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; |
9 | void *perf_gtk_handle; | ||
10 | |||
11 | #ifdef HAVE_GTK2_SUPPORT | ||
12 | static int setup_gtk_browser(void) | ||
13 | { | ||
14 | int (*perf_ui_init)(void); | ||
15 | |||
16 | if (perf_gtk_handle) | ||
17 | return 0; | ||
18 | |||
19 | perf_gtk_handle = dlopen(PERF_GTK_DSO, RTLD_LAZY); | ||
20 | if (perf_gtk_handle == NULL) { | ||
21 | char buf[PATH_MAX]; | ||
22 | scnprintf(buf, sizeof(buf), "%s/%s", LIBDIR, PERF_GTK_DSO); | ||
23 | perf_gtk_handle = dlopen(buf, RTLD_LAZY); | ||
24 | } | ||
25 | if (perf_gtk_handle == NULL) | ||
26 | return -1; | ||
27 | |||
28 | perf_ui_init = dlsym(perf_gtk_handle, "perf_gtk__init"); | ||
29 | if (perf_ui_init == NULL) | ||
30 | goto out_close; | ||
31 | |||
32 | if (perf_ui_init() == 0) | ||
33 | return 0; | ||
34 | |||
35 | out_close: | ||
36 | dlclose(perf_gtk_handle); | ||
37 | return -1; | ||
38 | } | ||
39 | |||
40 | static void exit_gtk_browser(bool wait_for_ok) | ||
41 | { | ||
42 | void (*perf_ui_exit)(bool); | ||
43 | |||
44 | if (perf_gtk_handle == NULL) | ||
45 | return; | ||
46 | |||
47 | perf_ui_exit = dlsym(perf_gtk_handle, "perf_gtk__exit"); | ||
48 | if (perf_ui_exit == NULL) | ||
49 | goto out_close; | ||
50 | |||
51 | perf_ui_exit(wait_for_ok); | ||
52 | |||
53 | out_close: | ||
54 | dlclose(perf_gtk_handle); | ||
55 | |||
56 | perf_gtk_handle = NULL; | ||
57 | } | ||
58 | #else | ||
59 | static inline int setup_gtk_browser(void) { return -1; } | ||
60 | static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {} | ||
61 | #endif | ||
8 | 62 | ||
9 | void setup_browser(bool fallback_to_pager) | 63 | void setup_browser(bool fallback_to_pager) |
10 | { | 64 | { |
@@ -17,8 +71,11 @@ void setup_browser(bool fallback_to_pager) | |||
17 | 71 | ||
18 | switch (use_browser) { | 72 | switch (use_browser) { |
19 | case 2: | 73 | case 2: |
20 | if (perf_gtk__init() == 0) | 74 | if (setup_gtk_browser() == 0) |
21 | break; | 75 | break; |
76 | printf("GTK browser requested but could not find %s\n", | ||
77 | PERF_GTK_DSO); | ||
78 | sleep(1); | ||
22 | /* fall through */ | 79 | /* fall through */ |
23 | case 1: | 80 | case 1: |
24 | use_browser = 1; | 81 | use_browser = 1; |
@@ -39,7 +96,7 @@ void exit_browser(bool wait_for_ok) | |||
39 | { | 96 | { |
40 | switch (use_browser) { | 97 | switch (use_browser) { |
41 | case 2: | 98 | case 2: |
42 | perf_gtk__exit(wait_for_ok); | 99 | exit_gtk_browser(wait_for_ok); |
43 | break; | 100 | break; |
44 | 101 | ||
45 | case 1: | 102 | case 1: |