]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
0985a948 | 2 | #include <pthread.h> |
fc67297b | 3 | #include <dlfcn.h> |
0985a948 | 4 | |
ea251d51 NK |
5 | #include "../util/cache.h" |
6 | #include "../util/debug.h" | |
7 | #include "../util/hist.h" | |
9a3993d4 | 8 | #include "../util/util.h" |
71172ed9 | 9 | |
0985a948 | 10 | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; |
fc67297b | 11 | void *perf_gtk_handle; |
d25ed5d9 | 12 | int use_browser = -1; |
fc67297b | 13 | |
5068b52f ACM |
14 | #define PERF_GTK_DSO "libperf-gtk.so" |
15 | ||
fc67297b | 16 | #ifdef HAVE_GTK2_SUPPORT |
5068b52f | 17 | |
fc67297b NK |
18 | static int setup_gtk_browser(void) |
19 | { | |
20 | int (*perf_ui_init)(void); | |
21 | ||
22 | if (perf_gtk_handle) | |
23 | return 0; | |
24 | ||
25 | perf_gtk_handle = dlopen(PERF_GTK_DSO, RTLD_LAZY); | |
26 | if (perf_gtk_handle == NULL) { | |
27 | char buf[PATH_MAX]; | |
28 | scnprintf(buf, sizeof(buf), "%s/%s", LIBDIR, PERF_GTK_DSO); | |
29 | perf_gtk_handle = dlopen(buf, RTLD_LAZY); | |
30 | } | |
31 | if (perf_gtk_handle == NULL) | |
32 | return -1; | |
33 | ||
34 | perf_ui_init = dlsym(perf_gtk_handle, "perf_gtk__init"); | |
35 | if (perf_ui_init == NULL) | |
36 | goto out_close; | |
37 | ||
38 | if (perf_ui_init() == 0) | |
39 | return 0; | |
40 | ||
41 | out_close: | |
42 | dlclose(perf_gtk_handle); | |
43 | return -1; | |
44 | } | |
45 | ||
46 | static void exit_gtk_browser(bool wait_for_ok) | |
47 | { | |
48 | void (*perf_ui_exit)(bool); | |
49 | ||
50 | if (perf_gtk_handle == NULL) | |
51 | return; | |
52 | ||
53 | perf_ui_exit = dlsym(perf_gtk_handle, "perf_gtk__exit"); | |
54 | if (perf_ui_exit == NULL) | |
55 | goto out_close; | |
56 | ||
57 | perf_ui_exit(wait_for_ok); | |
58 | ||
59 | out_close: | |
60 | dlclose(perf_gtk_handle); | |
61 | ||
62 | perf_gtk_handle = NULL; | |
63 | } | |
64 | #else | |
65 | static inline int setup_gtk_browser(void) { return -1; } | |
66 | static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {} | |
67 | #endif | |
0985a948 | 68 | |
c09615f2 ACM |
69 | int stdio__config_color(const struct option *opt __maybe_unused, |
70 | const char *mode, int unset __maybe_unused) | |
71 | { | |
72 | perf_use_color_default = perf_config_colorbool("color.ui", mode, -1); | |
73 | return 0; | |
74 | } | |
75 | ||
281ef544 | 76 | void setup_browser(bool fallback_to_pager) |
cf958003 | 77 | { |
2b676bf0 | 78 | if (use_browser < 2 && (!isatty(1) || dump_trace)) |
281ef544 | 79 | use_browser = 0; |
ca09b2e1 | 80 | |
281ef544 NK |
81 | /* default to TUI */ |
82 | if (use_browser < 0) | |
83 | use_browser = 1; | |
ca09b2e1 | 84 | |
281ef544 NK |
85 | switch (use_browser) { |
86 | case 2: | |
fc67297b | 87 | if (setup_gtk_browser() == 0) |
dc41b9b8 | 88 | break; |
fc67297b NK |
89 | printf("GTK browser requested but could not find %s\n", |
90 | PERF_GTK_DSO); | |
91 | sleep(1); | |
dc41b9b8 | 92 | /* fall through */ |
281ef544 | 93 | case 1: |
dc41b9b8 NK |
94 | use_browser = 1; |
95 | if (ui__init() == 0) | |
96 | break; | |
97 | /* fall through */ | |
281ef544 | 98 | default: |
21f0d423 | 99 | use_browser = 0; |
229ade9b ACM |
100 | if (fallback_to_pager) |
101 | setup_pager(); | |
281ef544 | 102 | break; |
1e6dd077 | 103 | } |
1e6dd077 ACM |
104 | } |
105 | ||
106 | void exit_browser(bool wait_for_ok) | |
107 | { | |
281ef544 NK |
108 | switch (use_browser) { |
109 | case 2: | |
fc67297b | 110 | exit_gtk_browser(wait_for_ok); |
281ef544 NK |
111 | break; |
112 | ||
113 | case 1: | |
114 | ui__exit(wait_for_ok); | |
115 | break; | |
116 | ||
117 | default: | |
118 | break; | |
1e6dd077 ACM |
119 | } |
120 | } |