1 // SPDX-License-Identifier: GPL-2.0
5 #include "../util/cache.h"
6 #include "../util/debug.h"
7 #include "../util/hist.h"
8 #include "../util/util.h"
10 pthread_mutex_t ui__lock
= PTHREAD_MUTEX_INITIALIZER
;
11 void *perf_gtk_handle
;
14 #define PERF_GTK_DSO "libperf-gtk.so"
16 #ifdef HAVE_GTK2_SUPPORT
18 static int setup_gtk_browser(void)
20 int (*perf_ui_init
)(void);
25 perf_gtk_handle
= dlopen(PERF_GTK_DSO
, RTLD_LAZY
);
26 if (perf_gtk_handle
== NULL
) {
28 scnprintf(buf
, sizeof(buf
), "%s/%s", LIBDIR
, PERF_GTK_DSO
);
29 perf_gtk_handle
= dlopen(buf
, RTLD_LAZY
);
31 if (perf_gtk_handle
== NULL
)
34 perf_ui_init
= dlsym(perf_gtk_handle
, "perf_gtk__init");
35 if (perf_ui_init
== NULL
)
38 if (perf_ui_init() == 0)
42 dlclose(perf_gtk_handle
);
46 static void exit_gtk_browser(bool wait_for_ok
)
48 void (*perf_ui_exit
)(bool);
50 if (perf_gtk_handle
== NULL
)
53 perf_ui_exit
= dlsym(perf_gtk_handle
, "perf_gtk__exit");
54 if (perf_ui_exit
== NULL
)
57 perf_ui_exit(wait_for_ok
);
60 dlclose(perf_gtk_handle
);
62 perf_gtk_handle
= NULL
;
65 static inline int setup_gtk_browser(void) { return -1; }
66 static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused
) {}
69 int stdio__config_color(const struct option
*opt __maybe_unused
,
70 const char *mode
, int unset __maybe_unused
)
72 perf_use_color_default
= perf_config_colorbool("color.ui", mode
, -1);
76 void setup_browser(bool fallback_to_pager
)
78 if (use_browser
< 2 && (!isatty(1) || dump_trace
))
85 switch (use_browser
) {
87 if (setup_gtk_browser() == 0)
89 printf("GTK browser requested but could not find %s\n",
100 if (fallback_to_pager
)
106 void exit_browser(bool wait_for_ok
)
108 switch (use_browser
) {
110 exit_gtk_browser(wait_for_ok
);
114 ui__exit(wait_for_ok
);