[PATCH 14/20] perf top: Use poller object for display thread stdin
From: Jiri Olsa
Date: Mon Aug 11 2014 - 04:51:16 EST
Using poller object to handle user input for stdio top.
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Jean Pihet <jean.pihet@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/builtin-top.c | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 9b4edf0bd49f..8d0ed211fd7b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -422,26 +422,22 @@ static int perf_top__key_mapped(struct perf_top *top, int c)
return 0;
}
-static bool perf_top__handle_keypress(struct perf_top *top, int c)
+static bool perf_top__handle_keypress(struct perf_top *top, int c,
+ struct poller *poller)
{
bool ret = true;
if (!perf_top__key_mapped(top, c)) {
- struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
- struct termios tc, save;
+ struct termios save;
perf_top__print_mapped_keys(top);
fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
fflush(stdout);
- tcgetattr(0, &save);
- tc = save;
- tc.c_lflag &= ~(ICANON | ECHO);
- tc.c_cc[VMIN] = 0;
- tc.c_cc[VTIME] = 0;
- tcsetattr(0, TCSANOW, &tc);
+ set_term_quiet_input(&save);
+ if (poller__poll(poller, -1) < 0)
+ return 0;
- poll(&stdin_poll, 1, -1);
c = getc(stdin);
tcsetattr(0, TCSAFLUSH, &save);
@@ -595,11 +591,19 @@ static void display_setup_sig(void)
static void *display_thread(void *arg)
{
- struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
+ struct poller poller;
+ struct poller_item in = {
+ .fd = fileno(stdin),
+ };
struct termios save;
struct perf_top *top = arg;
int delay_msecs, c;
+ if (poller__add(&poller, &in)) {
+ done = 1;
+ return NULL;
+ }
+
display_setup_sig();
pthread__unblock_sigwinch();
repeat:
@@ -610,23 +614,14 @@ repeat:
while (!done) {
perf_top__print_sym_table(top);
- /*
- * Either timeout expired or we got an EINTR due to SIGWINCH,
- * refresh screen in both cases.
- */
- switch (poll(&stdin_poll, 1, delay_msecs)) {
- case 0:
- continue;
- case -1:
- if (errno == EINTR)
- continue;
- /* Fall trhu */
- default:
+
+ if (poller__poll(&poller, delay_msecs) > 0) {
c = getc(stdin);
tcsetattr(0, TCSAFLUSH, &save);
- if (perf_top__handle_keypress(top, c))
+ if (perf_top__handle_keypress(top, c, &poller))
goto repeat;
+
done = 1;
}
}
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/