From: David Ahern <dsahern@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: acme@ghostprotocols.net, mingo@kernel.org, fweisbec@gmail.com,
peterz@infradead.org, jolsa@redhat.com, namhyung@kernel.org,
xiaoguangrong@linux.vnet.ibm.com, runzhen@linux.vnet.ibm.com,
David Ahern <dsahern@gmail.com>
Subject: [PATCH 16/16] perf kvm: set live mode refresh time dynamically
Date: Sat, 25 May 2013 18:24:56 -0600 [thread overview]
Message-ID: <1369527896-3650-17-git-send-email-dsahern@gmail.com> (raw)
In-Reply-To: <1369527896-3650-1-git-send-email-dsahern@gmail.com>
David's patch (https://lkml.org/lkml/2013/5/9/125 ) add a live mode for
perf kvm stat, but his patch can't set the refresh frequency
dynamically.
This patch accepts user's input and changes the value of
kvm->display_time variable.
For example, when the live mode is running, you press any key, it will
prints:
Mapped keys:
[d] set refresh frequency
[q] quit
Enter selection, or unmapped key to continue:
Enter refresh frequency(seconds): 2
Then, the live mode will refresh the screen every 2 seconds.
Signed-off-by: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
tools/perf/builtin-kvm.c | 42 ++++++++++++++++++++++++++++++++++++++----
tools/perf/util/top.c | 4 ++++
2 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 7392538..3e3f6e2 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -111,7 +111,7 @@ struct perf_kvm_stat {
struct rb_root result;
int timerfd;
- unsigned int display_time;
+ int display_time;
bool live;
};
@@ -1021,17 +1021,51 @@ static int fd_set_nonblock(int fd)
return 0;
}
+static void perf_kvm_live__print_mapped_keys(void)
+{
+ fprintf(stdout, "\nMapped keys:\n");
+ fprintf(stdout, "\t[d] set refresh frequency\n");
+ fprintf(stdout, "\t[q] quit\n");
+}
+
static
-int perf_kvm__handle_stdin(struct termios *tc_now, struct termios *tc_save)
+int perf_kvm__handle_stdin(struct perf_kvm_stat *kvm,
+ struct termios *tc_now,
+ struct termios *tc_save)
{
int c;
+ struct pollfd stdin_poll = { .fd = 0, .events = POLLIN};
tcsetattr(0, TCSANOW, tc_now);
c = getc(stdin);
tcsetattr(0, TCSAFLUSH, tc_save);
+ if (c == -1)
+ return 0;
if (c == 'q')
return 1;
+ perf_kvm_live__print_mapped_keys();
+ fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
+ fflush(stdout);
+
+ tcsetattr(0, TCSANOW, tc_now);
+ poll(&stdin_poll, 1, -1);
+ c = getc(stdin);
+ tcsetattr(0, TCSAFLUSH, tc_save);
+
+ switch (c) {
+ case 'q':
+ return 1;
+ case 'd':
+ prompt_integer(&kvm->display_time,
+ "Enter refresh frequency(seconds)");
+ if (kvm->display_time < 1)
+ kvm->display_time = 1;
+ if (perf_kvm__timerfd_set(kvm) < 0)
+ return 1;
+ default:
+ break;
+ }
return 0;
}
@@ -1108,7 +1142,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
goto out;
if (pollfds[nr_stdin].revents & POLLIN)
- done = perf_kvm__handle_stdin(&tc, &save);
+ done = perf_kvm__handle_stdin(kvm, &tc, &save);
if (!rc && !done)
err = poll(pollfds, nr_fds, 100);
@@ -1349,7 +1383,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
"be more verbose (show counter open errors, etc)"),
OPT_BOOLEAN('a', "all-cpus", &kvm->opts.target.system_wide,
"system-wide collection from all CPUs"),
- OPT_UINTEGER('d', "display", &kvm->display_time,
+ OPT_INTEGER('d', "display", &kvm->display_time,
"time in seconds between display updates"),
OPT_STRING(0, "event", &kvm->report_event, "report event",
"event for reporting: vmexit, mmio, ioport"),
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 1a2eaec..10bff6d 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -121,8 +121,12 @@ void prompt_integer(int *target, const char *msg)
char *buf = malloc(0), *p;
size_t dummy = 0;
int tmp;
+ struct pollfd stdin_poll = { .fd = 0, .events = POLLIN};
fprintf(stdout, "\n%s: ", msg);
+ fflush(stdout);
+ poll(&stdin_poll, 1, -1);
+
if (getline(&buf, &dummy, stdin) < 0)
return;
--
1.7.10.1
prev parent reply other threads:[~2013-05-26 0:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 0:24 [PATCH 00/16] perf: kvm live mode David Ahern
2013-05-26 0:24 ` [PATCH 01/16] perf evlist: restore methods removed in earlier cleanup David Ahern
2013-05-26 0:24 ` [PATCH 02/16] perf evlist: move tracepoint processing code to evlist.c David Ahern
2013-05-26 0:24 ` [PATCH 03/16 v2] perf evlist: add initialzation function for tracepoints David Ahern
2013-05-26 0:24 ` [PATCH 04/16 v2] perf session: export a few functions for event processing David Ahern
2013-05-26 0:24 ` [PATCH 05/16] perf top: move CONSOLE_CLEAR to header file David Ahern
2013-05-26 0:24 ` [PATCH 06/16] perf kvm: handle realloc failures David Ahern
2013-05-31 11:49 ` [tip:perf/core] perf kvm: Handle " tip-bot for David Ahern
2013-05-26 0:24 ` [PATCH 07/16] perf kvm: split out tracepoints from record args David Ahern
2013-05-26 0:24 ` [PATCH 08/16] perf stats: fix divide by 0 in variance David Ahern
2013-05-31 11:51 ` [tip:perf/core] perf stats: Fix " tip-bot for David Ahern
2013-05-26 0:24 ` [PATCH 09/16] perf stats: add max and min stats David Ahern
2013-05-26 0:24 ` [PATCH 10/16 v2] perf kvm: add live mode David Ahern
2013-05-26 0:24 ` [PATCH 11/16] perf kvm: add min and max stats to display David Ahern
2013-05-26 0:24 ` [PATCH 12/16] perf kvm: option to print events that exceed a threshold David Ahern
2013-05-26 0:24 ` [PATCH 13/16] perf kvm: debug for missing vmexit/vmentry event David Ahern
2013-05-26 0:24 ` [PATCH 14/16] perf kvm: reuse some code of perf_kvm__timerfd_create() David Ahern
2013-09-12 13:08 ` Ingo Molnar
2013-09-12 13:34 ` David Ahern
2013-09-12 13:40 ` Ingo Molnar
2013-10-29 13:23 ` Ingo Molnar
2013-10-29 13:53 ` David Ahern
2013-10-29 13:58 ` Ingo Molnar
2013-05-26 0:24 ` [PATCH 15/16] perf kvm: move the prompt_integer() to /util/top.c David Ahern
2013-05-26 0:24 ` David Ahern [this message]
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=1369527896-3650-17-git-send-email-dsahern@gmail.com \
--to=dsahern@gmail.com \
--cc=acme@ghostprotocols.net \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=runzhen@linux.vnet.ibm.com \
--cc=xiaoguangrong@linux.vnet.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox