~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/ui/setup.c

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp