perf TUI: Don't ignore job control
authorAhelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Tue, 27 Dec 2022 20:57:40 +0000 (21:57 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jan 2024 21:29:17 +0000 (18:29 -0300)
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>
tools/perf/ui/browsers/annotate.c
tools/perf/ui/browsers/hists.c
tools/perf/ui/browsers/scripts.c
tools/perf/ui/tui/setup.c

index cb2eb6dcb5321065e15dfeb60c785ab042c85908..ec5e21932876038b99afbfa30560d856efd8afd5 100644 (file)
@@ -938,6 +938,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
        /* reset abort key so that it can get Ctrl-C as a key */
        SLang_reset_tty();
        SLang_init_tty(0, 0, 0);
+       SLtty_set_suspend_state(true);
 
        return map_symbol__tui_annotate(&he->ms, evsel, hbt);
 }
index 3061dea29e6b658981b6d7a483f9c0a95d1a8414..0c02b3a8e121ffaaaa17647237ed5ab2c9ad67d0 100644 (file)
@@ -3000,6 +3000,7 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
        /* reset abort key so that it can get Ctrl-C as a key */
        SLang_reset_tty();
        SLang_init_tty(0, 0, 0);
+       SLtty_set_suspend_state(true);
 
        if (min_pcnt)
                browser->min_pcnt = min_pcnt;
@@ -3667,6 +3668,7 @@ int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
        /* reset abort key so that it can get Ctrl-C as a key */
        SLang_reset_tty();
        SLang_init_tty(0, 0, 0);
+       SLtty_set_suspend_state(true);
 
        memset(&action, 0, sizeof(action));
 
index 47d2c7a8cbe13cba1a3f9d46fd3c720cf0d2149c..50d45054ed6c1b435faf5cb4634ceae6eea03491 100644 (file)
@@ -166,6 +166,7 @@ void run_script(char *cmd)
        printf("\033[c\033[H\033[J");
        fflush(stdout);
        SLang_init_tty(0, 0, 0);
+       SLtty_set_suspend_state(true);
        SLsmg_refresh();
 }
 
index 605d9e175ea73b662a51c9fe0257a073fcfaf199..16c6eff4d24116b0fde68f60319330f1d4a0f1ac 100644 (file)
@@ -2,12 +2,14 @@
 #include <signal.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <termios.h>
 #include <unistd.h>
 #include <linux/kernel.h>
 #ifdef HAVE_BACKTRACE_SUPPORT
 #include <execinfo.h>
 #endif
 
+#include "../../util/color.h"
 #include "../../util/debug.h"
 #include "../browser.h"
 #include "../helpline.h"
@@ -121,6 +123,23 @@ static void ui__signal(int sig)
        exit(0);
 }
 
+static void ui__sigcont(int sig)
+{
+       static struct termios tty;
+
+       if (sig == SIGTSTP) {
+               while (tcgetattr(SLang_TT_Read_FD, &tty) == -1 && errno == EINTR)
+                       ;
+               while (write(SLang_TT_Read_FD, PERF_COLOR_RESET, sizeof(PERF_COLOR_RESET) - 1) == -1 && errno == EINTR)
+                       ;
+               raise(SIGSTOP);
+       } else {
+               while (tcsetattr(SLang_TT_Read_FD, TCSADRAIN, &tty) == -1 && errno == EINTR)
+                       ;
+               raise(SIGWINCH);
+       }
+}
+
 int ui__init(void)
 {
        int err;
@@ -135,6 +154,7 @@ int ui__init(void)
        err = SLang_init_tty(-1, 0, 0);
        if (err < 0)
                goto out;
+       SLtty_set_suspend_state(true);
 
        err = SLkp_init();
        if (err < 0) {
@@ -149,6 +169,8 @@ int ui__init(void)
        signal(SIGINT, ui__signal);
        signal(SIGQUIT, ui__signal);
        signal(SIGTERM, ui__signal);
+       signal(SIGTSTP, ui__sigcont);
+       signal(SIGCONT, ui__sigcont);
 
        perf_error__register(&perf_tui_eops);