aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/ui/setup.c')
-rw-r--r--tools/perf/ui/setup.c169
1 files changed, 26 insertions, 143 deletions
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index becdcd0d9ce..98130e099a0 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}