Skip to content

Commit 6af6d22

Browse files
nabijaczleweliacmel
authored andcommitted
perf TUI: Don't ignore job control
In its infinite wisdom, by default, SLang sets susp undef, and this can only be un-done by calling SLtty_set_suspend_state(true). After every SLang_init_tty(). Additionally, no provisions are made for maintaining the teletype attributes across suspend/continue (outside of curses emulation mode(?!), which provides full support, naturally), so we need to save and restore the flags ourselves, as well as reset the text colours when going under. We need to also re-draw the screen, and raising SIGWINCH, shockingly, Just Works. The correct solution would be to Not Use SLang, but as a stop-gap, this makes TUI 'perf report' usable. Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: yaowenbin <yaowenbin1@huawei.com> Link: https://lore.kernel.org/r/0354dcae23a8713f75f4fed609e0caec3c6e3cd5.1672174189.git.nabijaczleweli@nabijaczleweli.xyz Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 360b045 commit 6af6d22

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
938938
/* reset abort key so that it can get Ctrl-C as a key */
939939
SLang_reset_tty();
940940
SLang_init_tty(0, 0, 0);
941+
SLtty_set_suspend_state(true);
941942

942943
return map_symbol__tui_annotate(&he->ms, evsel, hbt);
943944
}

tools/perf/ui/browsers/hists.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,7 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
30003000
/* reset abort key so that it can get Ctrl-C as a key */
30013001
SLang_reset_tty();
30023002
SLang_init_tty(0, 0, 0);
3003+
SLtty_set_suspend_state(true);
30033004

30043005
if (min_pcnt)
30053006
browser->min_pcnt = min_pcnt;
@@ -3667,6 +3668,7 @@ int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
36673668
/* reset abort key so that it can get Ctrl-C as a key */
36683669
SLang_reset_tty();
36693670
SLang_init_tty(0, 0, 0);
3671+
SLtty_set_suspend_state(true);
36703672

36713673
memset(&action, 0, sizeof(action));
36723674

tools/perf/ui/browsers/scripts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void run_script(char *cmd)
166166
printf("\033[c\033[H\033[J");
167167
fflush(stdout);
168168
SLang_init_tty(0, 0, 0);
169+
SLtty_set_suspend_state(true);
169170
SLsmg_refresh();
170171
}
171172

tools/perf/ui/tui/setup.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#include <signal.h>
33
#include <stdbool.h>
44
#include <stdlib.h>
5+
#include <termios.h>
56
#include <unistd.h>
67
#include <linux/kernel.h>
78
#ifdef HAVE_BACKTRACE_SUPPORT
89
#include <execinfo.h>
910
#endif
1011

12+
#include "../../util/color.h"
1113
#include "../../util/debug.h"
1214
#include "../browser.h"
1315
#include "../helpline.h"
@@ -121,6 +123,23 @@ static void ui__signal(int sig)
121123
exit(0);
122124
}
123125

126+
static void ui__sigcont(int sig)
127+
{
128+
static struct termios tty;
129+
130+
if (sig == SIGTSTP) {
131+
while (tcgetattr(SLang_TT_Read_FD, &tty) == -1 && errno == EINTR)
132+
;
133+
while (write(SLang_TT_Read_FD, PERF_COLOR_RESET, sizeof(PERF_COLOR_RESET) - 1) == -1 && errno == EINTR)
134+
;
135+
raise(SIGSTOP);
136+
} else {
137+
while (tcsetattr(SLang_TT_Read_FD, TCSADRAIN, &tty) == -1 && errno == EINTR)
138+
;
139+
raise(SIGWINCH);
140+
}
141+
}
142+
124143
int ui__init(void)
125144
{
126145
int err;
@@ -135,6 +154,7 @@ int ui__init(void)
135154
err = SLang_init_tty(-1, 0, 0);
136155
if (err < 0)
137156
goto out;
157+
SLtty_set_suspend_state(true);
138158

139159
err = SLkp_init();
140160
if (err < 0) {
@@ -149,6 +169,8 @@ int ui__init(void)
149169
signal(SIGINT, ui__signal);
150170
signal(SIGQUIT, ui__signal);
151171
signal(SIGTERM, ui__signal);
172+
signal(SIGTSTP, ui__sigcont);
173+
signal(SIGCONT, ui__sigcont);
152174

153175
perf_error__register(&perf_tui_eops);
154176

0 commit comments

Comments
 (0)