From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>,
LKML <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, David Ahern <dsahern@gmail.com>,
Stephane Eranian <eranian@google.com>,
Jeremy Eder <jeder@redhat.com>
Subject: [PATCH 06/17] perf ftrace: Split "live" sub-command
Date: Tue, 30 Jul 2013 18:19:03 +0900 [thread overview]
Message-ID: <1375175954-798-7-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1375175954-798-1-git-send-email-namhyung@kernel.org>
From: Namhyung Kim <namhyung.kim@lge.com>
Separate out the default behavior to "live" subcommand. It's a
preparation to support more subcommands like "record" and "report".
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-ftrace.c | 133 ++++++++++++++++++++++++++------------------
1 file changed, 80 insertions(+), 53 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 642aa49c66d7..1bb6d1ff0eb1 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -171,19 +171,13 @@ static int reset_tracing_cpu(void)
return 0;
}
-static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
+static int do_ftrace_live(struct perf_ftrace *ftrace)
{
char *trace_file;
int trace_fd;
char buf[4096];
- struct pollfd pollfd = {
- .events = POLLIN,
- };
-
- if (geteuid() != 0) {
- pr_err("ftrace only works for root!\n");
- return -1;
- }
+ /* sleep 1ms if no data read */
+ struct timespec req = { .tv_nsec = 1000000 };
signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
@@ -196,12 +190,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
if (write_tracing_file("trace", "0") < 0)
goto out;
- if (argc && perf_evlist__prepare_workload(ftrace->evlist,
- &ftrace->target,
- argv, false, true) < 0) {
- goto out;
- }
-
if (set_tracing_pid(ftrace) < 0) {
pr_err("failed to set ftrace pid\n");
goto out_reset;
@@ -233,7 +221,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
}
fcntl(trace_fd, F_SETFL, O_NONBLOCK);
- pollfd.fd = trace_fd;
if (write_tracing_file("tracing_on", "1") < 0) {
pr_err("can't enable tracing\n");
@@ -243,16 +230,18 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
perf_evlist__start_workload(ftrace->evlist);
while (!done) {
- if (poll(&pollfd, 1, -1) < 0)
- break;
+ int n = read(trace_fd, buf, sizeof(buf));
- if (pollfd.revents & POLLIN) {
- int n = read(trace_fd, buf, sizeof(buf));
- if (n < 0)
- break;
- if (fwrite(buf, n, 1, stdout) != 1)
+ if (n < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ goto sleep;
+ else
break;
- }
+ } else if (n == 0) {
+sleep:
+ clock_nanosleep(CLOCK_MONOTONIC, 0, &req, NULL);
+ } else if (fwrite(buf, n, 1, stdout) != 1)
+ break;
}
write_tracing_file("tracing_on", "0");
@@ -274,61 +263,99 @@ out:
return done ? 0 : -1;
}
-int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
+static int
+__cmd_ftrace_live(struct perf_ftrace *ftrace, int argc, const char **argv)
{
- int ret;
- struct perf_ftrace ftrace = {
- .target = { .uid = UINT_MAX, },
- };
- const char * const ftrace_usage[] = {
- "perf ftrace [<options>] [<command>]",
- "perf ftrace [<options>] -- <command> [<options>]",
+ int ret = -1;
+ const char * const live_usage[] = {
+ "perf ftrace live [<options>] [<command>]",
+ "perf ftrace live [<options>] -- <command> [<options>]",
NULL
};
- const struct option ftrace_options[] = {
- OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
+ const struct option live_options[] = {
+ OPT_STRING('t', "tracer", &ftrace->tracer, "tracer",
"tracer to use: function_graph or function"),
- OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
+ OPT_STRING('p', "pid", &ftrace->target.pid, "pid",
"trace on existing process id"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose"),
- OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
+ OPT_BOOLEAN('a', "all-cpus", &ftrace->target.system_wide,
"system-wide collection from all CPUs"),
- OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
+ OPT_STRING('C', "cpu", &ftrace->target.cpu_list, "cpu",
"list of cpus to monitor"),
OPT_END()
};
- argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
- PARSE_OPT_STOP_AT_NON_OPTION);
- if (!argc && perf_target__none(&ftrace.target))
- usage_with_options(ftrace_usage, ftrace_options);
+ argc = parse_options(argc, argv, live_options, live_usage,
+ PARSE_OPT_STOP_AT_NON_OPTION);
+ if (!argc && perf_target__none(&ftrace->target))
+ usage_with_options(live_usage, live_options);
- ret = perf_target__validate(&ftrace.target);
+ ret = perf_target__validate(&ftrace->target);
if (ret) {
char errbuf[512];
- perf_target__strerror(&ftrace.target, ret, errbuf, 512);
+ perf_target__strerror(&ftrace->target, ret, errbuf, 512);
pr_err("%s\n", errbuf);
return -EINVAL;
}
- ftrace.evlist = perf_evlist__new();
- if (ftrace.evlist == NULL)
+ ftrace->evlist = perf_evlist__new();
+ if (ftrace->evlist == NULL)
return -ENOMEM;
- ret = perf_evlist__create_maps(ftrace.evlist, &ftrace.target);
+ ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target);
if (ret < 0)
- goto out_delete_evlist;
+ goto out;
+
+ if (ftrace->tracer == NULL)
+ ftrace->tracer = DEFAULT_TRACER;
+
+ if (argc && perf_evlist__prepare_workload(ftrace->evlist,
+ &ftrace->target,
+ argv, false, true) < 0)
+ goto out_maps;
+
+ ret = do_ftrace_live(ftrace);
+
+out_maps:
+ perf_evlist__delete_maps(ftrace->evlist);
+out:
+ perf_evlist__delete(ftrace->evlist);
+
+ return ret;
+}
+
+int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
+{
+ int ret;
+ struct perf_ftrace ftrace = {
+ .target = { .uid = UINT_MAX, },
+ };
+ const char * const ftrace_usage[] = {
+ "perf ftrace {live} [<options>] [<command>]",
+ "perf ftrace {live} [<options>] -- <command> [<options>]",
+ NULL
+ };
+ const struct option ftrace_options[] = {
+ OPT_END()
+ };
- if (ftrace.tracer == NULL)
- ftrace.tracer = DEFAULT_TRACER;
+ argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
+ PARSE_OPT_STOP_AT_NON_OPTION);
+ if (!argc)
+ usage_with_options(ftrace_usage, ftrace_options);
- ret = __cmd_ftrace(&ftrace, argc, argv);
+ if (geteuid() != 0) {
+ pr_err("ftrace only works for root!\n");
+ return -1;
+ }
- perf_evlist__delete_maps(ftrace.evlist);
-out_delete_evlist:
- perf_evlist__delete(ftrace.evlist);
+ if (strcmp(argv[0], "live") == 0) {
+ ret = __cmd_ftrace_live(&ftrace, argc, argv);
+ } else {
+ usage_with_options(ftrace_usage, ftrace_options);
+ }
return ret;
}
--
1.7.11.7
next prev parent reply other threads:[~2013-07-30 9:19 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-30 9:18 [PATCHSET 00/17] perf tools: Introduce new 'ftrace' command (v4) Namhyung Kim
2013-07-30 9:18 ` [PATCH 01/17] perf util: Save pid-cmdline mapping into tracing header Namhyung Kim
2013-07-30 13:28 ` Arnaldo Carvalho de Melo
2013-07-31 0:51 ` Namhyung Kim
2013-07-31 14:07 ` Arnaldo Carvalho de Melo
2013-08-05 7:17 ` Namhyung Kim
2013-08-07 13:44 ` David Ahern
2013-08-09 5:51 ` Namhyung Kim
2013-07-30 9:18 ` [PATCH 02/17] perf util: Add more debug message on failure path Namhyung Kim
2013-07-30 13:33 ` Arnaldo Carvalho de Melo
2013-07-30 9:19 ` [PATCH 03/17] perf tools: Introduce new 'ftrace' tool Namhyung Kim
2013-07-30 9:19 ` [PATCH 04/17] perf ftrace: Add support for --pid option Namhyung Kim
2013-07-30 9:19 ` [PATCH 05/17] perf ftrace: Add support for -a and -C option Namhyung Kim
2013-07-30 9:19 ` Namhyung Kim [this message]
2013-07-30 9:19 ` [PATCH 07/17] perf ftrace: Add 'record' sub-command Namhyung Kim
2013-07-30 9:19 ` [PATCH 08/17] perf ftrace: Add 'show' sub-command Namhyung Kim
2013-07-30 9:19 ` [PATCH 09/17] perf ftrace: Add 'report' sub-command Namhyung Kim
2013-07-30 9:19 ` [PATCH 10/17] perf ftrace: Add dump_printf() for low-level debugging Namhyung Kim
2013-07-30 9:19 ` [PATCH 11/17] perf ftrace: Use pager for displaying result Namhyung Kim
2013-07-30 9:19 ` [PATCH 12/17] perf ftrace: Cleanup using ftrace_setup/teardown() Namhyung Kim
2013-07-30 9:19 ` [PATCH 13/17] perf tools: Add document for perf-ftrace command Namhyung Kim
2013-07-30 9:19 ` [PATCH 14/17] perf ftrace: Add a signal handler for SIGSEGV Namhyung Kim
2013-07-30 9:19 ` [PATCH 15/17] perf ftrace: Add --clock option Namhyung Kim
2013-07-30 9:19 ` [PATCH 16/17] perf ftrace: Show leaf-functions as oneliner Namhyung Kim
2013-07-30 9:19 ` [PATCH 17/17] perf ftrace: Tidy up the function graph output of 'show' subcommand Namhyung Kim
2013-08-01 12:02 ` [PATCHSET 00/17] perf tools: Introduce new 'ftrace' command (v4) Jiri Olsa
2013-08-02 9:16 ` Ingo Molnar
2013-08-05 7:44 ` Namhyung Kim
[not found] ` <51FB2B90.6090602@gmail.com>
2013-08-02 13:33 ` [PATCH] perf tools: Renaming 'time' variable in perf_time_to_tsc due to name shadowing error Jiri Olsa
2013-08-03 19:23 ` Adrian Hunter
2013-08-05 7:47 ` Jiri Olsa
2013-08-09 10:23 ` [PATCHSET 00/17] perf tools: Introduce new 'ftrace' command (v4) Jiri Olsa
2013-08-13 2:20 ` Namhyung Kim
2013-08-28 14:57 ` Jeremy Eder
2013-08-29 2:56 ` Namhyung Kim
2013-08-09 10:25 ` Jiri Olsa
2013-08-09 10:30 ` 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=1375175954-798-7-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jeder@redhat.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome