7 #include <linux/kernel.h>
8 #ifdef HAVE_BACKTRACE_SUPPORT
12 #include "../../util/color.h"
13 #include "../../util/debug.h"
14 #include "../browser.h"
15 #include "../helpline.h"
18 #include "../libslang.h"
19 #include "../keysyms.h"
22 static volatile int ui__need_resize
;
24 extern struct perf_error_ops perf_tui_eops
;
25 extern bool tui_helpline__set
;
27 extern void hist_browser__init_hpp(void);
29 void ui__refresh_dimensions(bool force
)
31 if (force
|| ui__need_resize
) {
33 mutex_lock(&ui__lock
);
34 SLtt_get_screen_size();
36 mutex_unlock(&ui__lock
);
40 static void ui__sigwinch(int sig __maybe_unused
)
45 static void ui__setup_sigwinch(void)
53 pthread__unblock_sigwinch();
54 signal(SIGWINCH
, ui__sigwinch
);
57 int ui__getch(int delay_secs
)
59 struct timeval timeout
, *ptimeout
= delay_secs
? &timeout
: NULL
;
69 timeout
.tv_sec
= delay_secs
;
73 err
= select(1, &read_set
, NULL
, NULL
, ptimeout
);
92 err
= select(1, &read_set
, NULL
, NULL
, &timeout
);
100 #ifdef HAVE_BACKTRACE_SUPPORT
101 static void ui__signal_backtrace(int sig
)
107 psignal(sig
, "perf");
109 printf("-------- backtrace --------\n");
110 size
= backtrace(stackdump
, ARRAY_SIZE(stackdump
));
111 backtrace_symbols_fd(stackdump
, size
, STDOUT_FILENO
);
116 # define ui__signal_backtrace ui__signal
119 static void ui__signal(int sig
)
122 psignal(sig
, "perf");
126 static void ui__sigcont(int sig
)
128 static struct termios tty
;
130 if (sig
== SIGTSTP
) {
131 while (tcgetattr(SLang_TT_Read_FD
, &tty
) == -1 && errno
== EINTR
)
133 while (write(SLang_TT_Read_FD
, PERF_COLOR_RESET
, sizeof(PERF_COLOR_RESET
) - 1) == -1 && errno
== EINTR
)
137 while (tcsetattr(SLang_TT_Read_FD
, TCSADRAIN
, &tty
) == -1 && errno
== EINTR
)
149 SLtt_get_screen_size();
151 err
= SLsmg_init_smg();
154 err
= SLang_init_tty(-1, 0, 0);
157 SLtty_set_suspend_state(true);
161 pr_err("TUI initialization failed.\n");
165 SLkp_define_keysym("^(kB)", SL_KEY_UNTAB
);
167 signal(SIGSEGV
, ui__signal_backtrace
);
168 signal(SIGFPE
, ui__signal_backtrace
);
169 signal(SIGINT
, ui__signal
);
170 signal(SIGQUIT
, ui__signal
);
171 signal(SIGTERM
, ui__signal
);
172 signal(SIGTSTP
, ui__sigcont
);
173 signal(SIGCONT
, ui__sigcont
);
175 perf_error__register(&perf_tui_eops
);
179 tui_progress__init();
181 hist_browser__init_hpp();
186 void ui__exit(bool wait_for_ok
)
188 if (wait_for_ok
&& tui_helpline__set
)
189 ui__question_window("Fatal Error",
190 ui_helpline__last_msg
,
191 "Press any key...", 0);
193 SLtt_set_cursor_visibility(1);
194 if (mutex_trylock(&ui__lock
)) {
197 mutex_unlock(&ui__lock
);
200 perf_error__unregister(&perf_tui_eops
);