aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2012-04-30 00:55:08 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-05-02 15:17:34 -0400
commit281ef544a8476f750b9f378593c42b3e8a0b8788 (patch)
tree685e23ed105380b167a36ccac54130c42aaf38c9
parent28e62b90d95a4ed8ae2ba93879003665051581a6 (diff)
perf ui: Add gtk2 support into setup_browser()
Now setup_browser can handle gtk2 front-end so split the TUI code to ui/tui/setup.c in order to remove dependency. To this end, make ui__init/exit global symbols and take an argument. Also split gtk code to ui/gtk/setup.c. Signed-off-by: Namhyung Kim <namhyung.kim@lge.com> Acked-by: Pekka Enberg <penberg@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Pekka Enberg <penberg@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1335761711-31403-5-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Makefile6
-rw-r--r--tools/perf/builtin-report.c10
-rw-r--r--tools/perf/ui/gtk/browser.c10
-rw-r--r--tools/perf/ui/gtk/setup.c12
-rw-r--r--tools/perf/ui/setup.c169
-rw-r--r--tools/perf/ui/tui/setup.c140
-rw-r--r--tools/perf/util/cache.h23
7 files changed, 205 insertions, 165 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 4122a668952e..4734f41f801d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -483,6 +483,7 @@ else
483 LIB_OBJS += $(OUTPUT)ui/helpline.o 483 LIB_OBJS += $(OUTPUT)ui/helpline.o
484 LIB_OBJS += $(OUTPUT)ui/progress.o 484 LIB_OBJS += $(OUTPUT)ui/progress.o
485 LIB_OBJS += $(OUTPUT)ui/util.o 485 LIB_OBJS += $(OUTPUT)ui/util.o
486 LIB_OBJS += $(OUTPUT)ui/tui/setup.o
486 LIB_H += ui/browser.h 487 LIB_H += ui/browser.h
487 LIB_H += ui/browsers/map.h 488 LIB_H += ui/browsers/map.h
488 LIB_H += ui/helpline.h 489 LIB_H += ui/helpline.h
@@ -505,6 +506,11 @@ else
505 BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0) 506 BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0)
506 EXTLIBS += $(shell pkg-config --libs gtk+-2.0) 507 EXTLIBS += $(shell pkg-config --libs gtk+-2.0)
507 LIB_OBJS += $(OUTPUT)ui/gtk/browser.o 508 LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
509 LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
510 # Make sure that it'd be included only once.
511 ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),)
512 LIB_OBJS += $(OUTPUT)ui/setup.o
513 endif
508 endif 514 endif
509endif 515endif
510 516
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 06115ffaa0b4..5df829f5bbf4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -676,14 +676,10 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
676 676
677 } 677 }
678 678
679 if (strcmp(report.input_name, "-") != 0) { 679 if (strcmp(report.input_name, "-") != 0)
680 if (report.use_gtk) 680 setup_browser(true);
681 perf_gtk__setup_browser(true); 681 else
682 else
683 setup_browser(true);
684 } else {
685 use_browser = 0; 682 use_browser = 0;
686 }
687 683
688 /* 684 /*
689 * Only in the newt browser we are doing integrated annotation, 685 * Only in the newt browser we are doing integrated annotation,
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index 5eafd9b3b783..0656c381a89c 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -9,16 +9,6 @@
9 9
10#define MAX_COLUMNS 32 10#define MAX_COLUMNS 32
11 11
12void perf_gtk__setup_browser(bool fallback_to_pager __used)
13{
14 gtk_init(NULL, NULL);
15}
16
17void perf_gtk__exit_browser(bool wait_for_ok __used)
18{
19 gtk_main_quit();
20}
21
22static void perf_gtk__signal(int sig) 12static void perf_gtk__signal(int sig)
23{ 13{
24 psignal(sig, "perf"); 14 psignal(sig, "perf");
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
new file mode 100644
index 000000000000..8c3b573e863d
--- /dev/null
+++ b/tools/perf/ui/gtk/setup.c
@@ -0,0 +1,12 @@
1#include "gtk.h"
2#include "../../util/cache.h"
3
4void perf_gtk__init(bool fallback_to_pager __used)
5{
6 gtk_init(NULL, NULL);
7}
8
9void perf_gtk__exit(bool wait_for_ok __used)
10{
11 gtk_main_quit();
12}
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index becdcd0d9ce7..98130e099a0d 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -1,161 +1,44 @@
1#include <newt.h>
2#include <signal.h>
3#include <stdbool.h>
4
5#include "../cache.h" 1#include "../cache.h"
6#include "../debug.h" 2#include "../debug.h"
7#include "browser.h"
8#include "helpline.h"
9#include "ui.h"
10#include "util.h"
11#include "libslang.h"
12#include "keysyms.h"
13
14pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
15
16static volatile int ui__need_resize;
17
18void ui__refresh_dimensions(bool force)
19{
20 if (force || ui__need_resize) {
21 ui__need_resize = 0;
22 pthread_mutex_lock(&ui__lock);
23 SLtt_get_screen_size();
24 SLsmg_reinit_smg();
25 pthread_mutex_unlock(&ui__lock);
26 }
27}
28
29static void ui__sigwinch(int sig __used)
30{
31 ui__need_resize = 1;
32}
33
34static void ui__setup_sigwinch(void)
35{
36 static bool done;
37
38 if (done)
39 return;
40
41 done = true;
42 pthread__unblock_sigwinch();
43 signal(SIGWINCH, ui__sigwinch);
44}
45
46int ui__getch(int delay_secs)
47{
48 struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
49 fd_set read_set;
50 int err, key;
51
52 ui__setup_sigwinch();
53
54 FD_ZERO(&read_set);
55 FD_SET(0, &read_set);
56
57 if (delay_secs) {
58 timeout.tv_sec = delay_secs;
59 timeout.tv_usec = 0;
60 }
61
62 err = select(1, &read_set, NULL, NULL, ptimeout);
63
64 if (err == 0)
65 return K_TIMER;
66
67 if (err == -1) {
68 if (errno == EINTR)
69 return K_RESIZE;
70 return K_ERROR;
71 }
72 3
73 key = SLang_getkey();
74 if (key != K_ESC)
75 return key;
76 4
77 FD_ZERO(&read_set); 5void setup_browser(bool fallback_to_pager)
78 FD_SET(0, &read_set);
79 timeout.tv_sec = 0;
80 timeout.tv_usec = 20;
81 err = select(1, &read_set, NULL, NULL, &timeout);
82 if (err == 0)
83 return K_ESC;
84
85 SLang_ungetkey(key);
86 return SLkp_getkey();
87}
88
89static void newt_suspend(void *d __used)
90{
91 newtSuspend();
92 raise(SIGTSTP);
93 newtResume();
94}
95
96static void ui__exit(void);
97
98static void ui__signal(int sig)
99{
100 ui__exit();
101 psignal(sig, "perf");
102 exit(0);
103}
104
105static int ui__init(void)
106{ 6{
107 int err; 7 if (!isatty(1) || dump_trace)
108 8 use_browser = 0;
109 newtInit();
110 err = SLkp_init();
111 if (err < 0) {
112 pr_err("TUI initialization failed.\n");
113 goto out;
114 }
115
116 SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
117 9
118 newtSetSuspendCallback(newt_suspend, NULL); 10 /* default to TUI */
119 ui_helpline__init(); 11 if (use_browser < 0)
120 ui_browser__init(); 12 use_browser = 1;
121 13
122 signal(SIGSEGV, ui__signal); 14 switch (use_browser) {
123 signal(SIGFPE, ui__signal); 15 case 2:
124 signal(SIGINT, ui__signal); 16 perf_gtk__init(fallback_to_pager);
125 signal(SIGQUIT, ui__signal); 17 break;
126 signal(SIGTERM, ui__signal);
127out:
128 return err;
129}
130 18
131static void ui__exit(void) 19 case 1:
132{ 20 ui__init(fallback_to_pager);
133 SLtt_set_cursor_visibility(1); 21 break;
134 SLsmg_refresh();
135 SLsmg_reset_smg();
136 SLang_reset_tty();
137}
138 22
139void setup_browser(bool fallback_to_pager) 23 default:
140{
141 if (!isatty(1) || !use_browser || dump_trace) {
142 use_browser = 0;
143 if (fallback_to_pager) 24 if (fallback_to_pager)
144 setup_pager(); 25 setup_pager();
145 return; 26 break;
146 } 27 }
147
148 use_browser = 1;
149 ui__init();
150} 28}
151 29
152void exit_browser(bool wait_for_ok) 30void exit_browser(bool wait_for_ok)
153{ 31{
154 if (use_browser > 0) { 32 switch (use_browser) {
155 if (wait_for_ok) 33 case 2:
156 ui__question_window("Fatal Error", 34 perf_gtk__exit(wait_for_ok);
157 ui_helpline__last_msg, 35 break;
158 "Press any key...", 0); 36
159 ui__exit(); 37 case 1:
38 ui__exit(wait_for_ok);
39 break;
40
41 default:
42 break;
160 } 43 }
161} 44}
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
new file mode 100644
index 000000000000..0194cea2ea0e
--- /dev/null
+++ b/tools/perf/ui/tui/setup.c
@@ -0,0 +1,140 @@
1#include <newt.h>
2#include <signal.h>
3#include <stdbool.h>
4
5#include "../../util/cache.h"
6#include "../../util/debug.h"
7#include "../browser.h"
8#include "../helpline.h"
9#include "../ui.h"
10#include "../util.h"
11#include "../libslang.h"
12#include "../keysyms.h"
13
14pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
15
16static volatile int ui__need_resize;
17
18void ui__refresh_dimensions(bool force)
19{
20 if (force || ui__need_resize) {
21 ui__need_resize = 0;
22 pthread_mutex_lock(&ui__lock);
23 SLtt_get_screen_size();
24 SLsmg_reinit_smg();
25 pthread_mutex_unlock(&ui__lock);
26 }
27}
28
29static void ui__sigwinch(int sig __used)
30{
31 ui__need_resize = 1;
32}
33
34static void ui__setup_sigwinch(void)
35{
36 static bool done;
37
38 if (done)
39 return;
40
41 done = true;
42 pthread__unblock_sigwinch();
43 signal(SIGWINCH, ui__sigwinch);
44}
45
46int ui__getch(int delay_secs)
47{
48 struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
49 fd_set read_set;
50 int err, key;
51
52 ui__setup_sigwinch();
53
54 FD_ZERO(&read_set);
55 FD_SET(0, &read_set);
56
57 if (delay_secs) {
58 timeout.tv_sec = delay_secs;
59 timeout.tv_usec = 0;
60 }
61
62 err = select(1, &read_set, NULL, NULL, ptimeout);
63
64 if (err == 0)
65 return K_TIMER;
66
67 if (err == -1) {
68 if (errno == EINTR)
69 return K_RESIZE;
70 return K_ERROR;
71 }
72
73 key = SLang_getkey();
74 if (key != K_ESC)
75 return key;
76
77 FD_ZERO(&read_set);
78 FD_SET(0, &read_set);
79 timeout.tv_sec = 0;
80 timeout.tv_usec = 20;
81 err = select(1, &read_set, NULL, NULL, &timeout);
82 if (err == 0)
83 return K_ESC;
84
85 SLang_ungetkey(key);
86 return SLkp_getkey();
87}
88
89static void newt_suspend(void *d __used)
90{
91 newtSuspend();
92 raise(SIGTSTP);
93 newtResume();
94}
95
96static void ui__signal(int sig)
97{
98 ui__exit(false);
99 psignal(sig, "perf");
100 exit(0);
101}
102
103int ui__init(bool fallback_to_pager __used)
104{
105 int err;
106
107 newtInit();
108 err = SLkp_init();
109 if (err < 0) {
110 pr_err("TUI initialization failed.\n");
111 goto out;
112 }
113
114 SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
115
116 newtSetSuspendCallback(newt_suspend, NULL);
117 ui_helpline__init();
118 ui_browser__init();
119
120 signal(SIGSEGV, ui__signal);
121 signal(SIGFPE, ui__signal);
122 signal(SIGINT, ui__signal);
123 signal(SIGQUIT, ui__signal);
124 signal(SIGTERM, ui__signal);
125out:
126 return err;
127}
128
129void ui__exit(bool wait_for_ok)
130{
131 if (wait_for_ok)
132 ui__question_window("Fatal Error",
133 ui_helpline__last_msg,
134 "Press any key...", 0);
135
136 SLtt_set_cursor_visibility(1);
137 SLsmg_refresh();
138 SLsmg_reset_smg();
139 SLang_reset_tty();
140}
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 3428b777396d..761d4e998101 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -33,7 +33,7 @@ extern int pager_use_color;
33 33
34extern int use_browser; 34extern int use_browser;
35 35
36#ifdef NO_NEWT_SUPPORT 36#if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT)
37static inline void setup_browser(bool fallback_to_pager) 37static inline void setup_browser(bool fallback_to_pager)
38{ 38{
39 if (fallback_to_pager) 39 if (fallback_to_pager)
@@ -43,19 +43,32 @@ static inline void exit_browser(bool wait_for_ok __used) {}
43#else 43#else
44void setup_browser(bool fallback_to_pager); 44void setup_browser(bool fallback_to_pager);
45void exit_browser(bool wait_for_ok); 45void exit_browser(bool wait_for_ok);
46
47#ifdef NO_NEWT_SUPPORT
48static inline int ui__init(bool fallback_to_pager)
49{
50 if (fallback_to_pager)
51 setup_pager();
52 return 0;
53}
54static inline void ui__exit(bool wait_for_ok __used) {}
55#else
56int ui__init(bool fallback_to_pager);
57void ui__exit(bool wait_for_ok);
46#endif 58#endif
47 59
48#ifdef NO_GTK2_SUPPORT 60#ifdef NO_GTK2_SUPPORT
49static inline void perf_gtk__setup_browser(bool fallback_to_pager) 61static inline void perf_gtk__init(bool fallback_to_pager)
50{ 62{
51 if (fallback_to_pager) 63 if (fallback_to_pager)
52 setup_pager(); 64 setup_pager();
53} 65}
54static inline void perf_gtk__exit_browser(bool wait_for_ok __used) {} 66static inline void perf_gtk__exit(bool wait_for_ok __used) {}
55#else 67#else
56void perf_gtk__setup_browser(bool fallback_to_pager); 68void perf_gtk__init(bool fallback_to_pager);
57void perf_gtk__exit_browser(bool wait_for_ok); 69void perf_gtk__exit(bool wait_for_ok);
58#endif 70#endif
71#endif /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */
59 72
60char *alias_lookup(const char *alias); 73char *alias_lookup(const char *alias);
61int split_cmdline(char *cmdline, const char ***argv); 74int split_cmdline(char *cmdline, const char ***argv);