All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Lubashev <ilubashe@akamai.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Igor Lubashev <ilubashe@akamai.com>, Jiri Olsa <jolsa@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/3] perf top: Allow running without stdin
Date: Tue, 22 Oct 2019 21:54:51 -0400	[thread overview]
Message-ID: <1571795693-23558-2-git-send-email-ilubashe@akamai.com> (raw)
In-Reply-To: <1571795693-23558-1-git-send-email-ilubashe@akamai.com>

Allow perf top --stdio to run without access to stdin.
This lets perf top to run in a batch mode until interrupted.

The following now works as expected:

  $ perf top < /dev/null

Signed-off-by: Igor Lubashev <ilubashe@akamai.com>
---
 tools/perf/builtin-top.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index d96f24c8770d..fbc0dc135b8a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -665,6 +665,7 @@ static void display_setup_sig(void)
 static void *display_thread(void *arg)
 {
 	struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
+	nfds_t nfds = 1;
 	struct termios save;
 	struct perf_top *top = arg;
 	int delay_msecs, c;
@@ -684,7 +685,8 @@ static void *display_thread(void *arg)
 	delay_msecs = top->delay_secs * MSEC_PER_SEC;
 	set_term_quiet_input(&save);
 	/* trash return*/
-	getc(stdin);
+	if (getc(stdin) == EOF)
+		nfds = 0;
 
 	while (!done) {
 		perf_top__print_sym_table(top);
@@ -692,7 +694,7 @@ static void *display_thread(void *arg)
 		 * Either timeout expired or we got an EINTR due to SIGWINCH,
 		 * refresh screen in both cases.
 		 */
-		switch (poll(&stdin_poll, 1, delay_msecs)) {
+		switch (poll(&stdin_poll, nfds, delay_msecs)) {
 		case 0:
 			continue;
 		case -1:
@@ -701,6 +703,10 @@ static void *display_thread(void *arg)
 			__fallthrough;
 		default:
 			c = getc(stdin);
+			if (c == EOF) {
+				nfds = 0;
+				continue;
+			}
 			tcsetattr(0, TCSAFLUSH, &save);
 
 			if (perf_top__handle_keypress(top, c))
-- 
2.7.4


  reply	other threads:[~2019-10-23  1:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23  1:54 [PATCH 0/3] perf: Allow running without stdin Igor Lubashev
2019-10-23  1:54 ` Igor Lubashev [this message]
2019-10-23  1:54 ` [PATCH 2/3] perf kvm: " Igor Lubashev
2019-10-23 10:42   ` Jiri Olsa
2019-10-23 16:06     ` Lubashev, Igor
2019-11-08 19:55     ` Lubashev, Igor
2019-10-23  1:54 ` [PATCH 3/3] perf kvm: Use evlist layer api when possible Igor Lubashev
2019-10-23 12:58   ` Arnaldo Carvalho de Melo
2019-11-12 11:18   ` [tip: perf/core] " tip-bot2 for Igor Lubashev
2019-10-24  8:24 ` [PATCH 0/3] perf: Allow running without stdin Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1571795693-23558-2-git-send-email-ilubashe@akamai.com \
    --to=ilubashe@akamai.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.