diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2017-11-14 04:23:39 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-11-17 10:16:23 -0500 |
| commit | b135e5ee1a0e325166c30b16cf5493fea44ede45 (patch) | |
| tree | 07035d118a6da9e8b61977bd95ffb215de99e39a | |
| parent | 93d10af26bb7159349158b721ba2e258291d53c3 (diff) | |
perf top: Fix window dimensions change handling
The stdio perf top crashes when we change the terminal
window size. The reason is that we assumed we get the
perf_top pointer as a signal handler argument which is
not the case.
Changing the SIGWINCH handler logic to change global
resize variable, which is checked in the main thread
loop.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ysuzwz77oev1ftgvdscn9bpu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/builtin-top.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 865191281591..4cbd3dd14a33 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
| @@ -77,6 +77,7 @@ | |||
| 77 | #include "sane_ctype.h" | 77 | #include "sane_ctype.h" |
| 78 | 78 | ||
| 79 | static volatile int done; | 79 | static volatile int done; |
| 80 | static volatile int resize; | ||
| 80 | 81 | ||
| 81 | #define HEADER_LINE_NR 5 | 82 | #define HEADER_LINE_NR 5 |
| 82 | 83 | ||
| @@ -86,10 +87,13 @@ static void perf_top__update_print_entries(struct perf_top *top) | |||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | static void perf_top__sig_winch(int sig __maybe_unused, | 89 | static void perf_top__sig_winch(int sig __maybe_unused, |
| 89 | siginfo_t *info __maybe_unused, void *arg) | 90 | siginfo_t *info __maybe_unused, void *arg __maybe_unused) |
| 90 | { | 91 | { |
| 91 | struct perf_top *top = arg; | 92 | resize = 1; |
| 93 | } | ||
| 92 | 94 | ||
| 95 | static void perf_top__resize(struct perf_top *top) | ||
| 96 | { | ||
| 93 | get_term_dimensions(&top->winsize); | 97 | get_term_dimensions(&top->winsize); |
| 94 | perf_top__update_print_entries(top); | 98 | perf_top__update_print_entries(top); |
| 95 | } | 99 | } |
| @@ -480,7 +484,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c) | |||
| 480 | .sa_sigaction = perf_top__sig_winch, | 484 | .sa_sigaction = perf_top__sig_winch, |
| 481 | .sa_flags = SA_SIGINFO, | 485 | .sa_flags = SA_SIGINFO, |
| 482 | }; | 486 | }; |
| 483 | perf_top__sig_winch(SIGWINCH, NULL, top); | 487 | perf_top__resize(top); |
| 484 | sigaction(SIGWINCH, &act, NULL); | 488 | sigaction(SIGWINCH, &act, NULL); |
| 485 | } else { | 489 | } else { |
| 486 | signal(SIGWINCH, SIG_DFL); | 490 | signal(SIGWINCH, SIG_DFL); |
| @@ -1035,6 +1039,11 @@ static int __cmd_top(struct perf_top *top) | |||
| 1035 | 1039 | ||
| 1036 | if (hits == top->samples) | 1040 | if (hits == top->samples) |
| 1037 | ret = perf_evlist__poll(top->evlist, 100); | 1041 | ret = perf_evlist__poll(top->evlist, 100); |
| 1042 | |||
| 1043 | if (resize) { | ||
| 1044 | perf_top__resize(top); | ||
| 1045 | resize = 0; | ||
| 1046 | } | ||
| 1038 | } | 1047 | } |
| 1039 | 1048 | ||
| 1040 | ret = 0; | 1049 | ret = 0; |
