Skip to content

Commit

Permalink
perf top: Fix window dimensions change handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Nov 17, 2017
1 parent 93d10af commit b135e5e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "sane_ctype.h"

static volatile int done;
static volatile int resize;

#define HEADER_LINE_NR 5

Expand All @@ -86,10 +87,13 @@ static void perf_top__update_print_entries(struct perf_top *top)
}

static void perf_top__sig_winch(int sig __maybe_unused,
siginfo_t *info __maybe_unused, void *arg)
siginfo_t *info __maybe_unused, void *arg __maybe_unused)
{
struct perf_top *top = arg;
resize = 1;
}

static void perf_top__resize(struct perf_top *top)
{
get_term_dimensions(&top->winsize);
perf_top__update_print_entries(top);
}
Expand Down Expand Up @@ -480,7 +484,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
.sa_sigaction = perf_top__sig_winch,
.sa_flags = SA_SIGINFO,
};
perf_top__sig_winch(SIGWINCH, NULL, top);
perf_top__resize(top);
sigaction(SIGWINCH, &act, NULL);
} else {
signal(SIGWINCH, SIG_DFL);
Expand Down Expand Up @@ -1035,6 +1039,11 @@ static int __cmd_top(struct perf_top *top)

if (hits == top->samples)
ret = perf_evlist__poll(top->evlist, 100);

if (resize) {
perf_top__resize(top);
resize = 0;
}
}

ret = 0;
Expand Down

0 comments on commit b135e5e

Please sign in to comment.