mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>
Subject: [PATCH 08/14] perf ftrace: Split "live" sub-command
Date: Tue, 23 Apr 2013 17:31:06 +0900	[thread overview]
Message-ID: <1366705872-12132-9-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1366705872-12132-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 | 109 +++++++++++++++++++++++++++-----------------
 1 file changed, 68 insertions(+), 41 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 04ca2303b63b..6d991c44948f 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -131,7 +131,7 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace)
 	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;
@@ -140,11 +140,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
 		.events = POLLIN,
 	};
 
-	if (geteuid() != 0) {
-		pr_err("ftrace only works for root!\n");
-		return -1;
-	}
-
 	signal(SIGINT, sig_handler);
 	signal(SIGUSR1, sig_handler);
 	signal(SIGCHLD, sig_handler);
@@ -156,12 +151,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;
@@ -234,61 +223,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"),
-	OPT_STRING('p', "pid", &ftrace.target.tid, "pid",
+	OPT_STRING('p', "pid", &ftrace->target.tid, "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 (ftrace->tracer == NULL)
+		ftrace->tracer = DEFAULT_TRACER;
 
-	ret = __cmd_ftrace(&ftrace, argc, argv);
+	if (argc && perf_evlist__prepare_workload(ftrace->evlist,
+						  &ftrace->target,
+						  argv, false, true) < 0)
+		goto out_maps;
+
+	ret = do_ftrace_live(ftrace);
 
-	perf_evlist__delete_maps(ftrace.evlist);
-out_delete_evlist:
-	perf_evlist__delete(ftrace.evlist);
+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()
+	};
+
+	argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
+			     PARSE_OPT_STOP_AT_NON_OPTION);
+	if (!argc)
+		usage_with_options(ftrace_usage, ftrace_options);
+
+	if (geteuid() != 0) {
+		pr_err("ftrace only works for root!\n");
+		return -1;
+	}
+
+	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


  parent reply	other threads:[~2013-04-23  8:33 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-23  8:30 [RFC 00/14] perf tools: Introduce new 'ftrace' command Namhyung Kim
2013-04-23  8:30 ` [PATCH 01/14] perf util: Move debugfs/tracing helper functions to util.c Namhyung Kim
2013-04-24 12:32   ` Jiri Olsa
2013-04-23  8:31 ` [PATCH 02/14] perf util: Use evsel->name to get tracepoint_paths Namhyung Kim
2013-04-23 13:07   ` Steven Rostedt
2013-04-24 10:36     ` Namhyung Kim
2013-04-24 12:42   ` Jiri Olsa
2013-04-25  5:58     ` Namhyung Kim
2013-04-23  8:31 ` [PATCH 03/14] perf util: Save pid-cmdline mapping into tracing header Namhyung Kim
2013-04-23  8:31 ` [PATCH 04/14] perf util: Add more debug message on failure path Namhyung Kim
2013-04-23  8:31 ` [PATCH 05/14] perf tools: Introduce new 'ftrace' tool Namhyung Kim
2013-04-24 14:09   ` Jiri Olsa
2013-04-25  6:06     ` Namhyung Kim
2013-04-25  9:09       ` Jiri Olsa
2013-04-25  9:51         ` Namhyung Kim
2013-04-25 13:05           ` Steven Rostedt
2013-04-25 14:49             ` Jiri Olsa
2013-04-26 13:34             ` David Ahern
2013-04-26 13:50               ` Steven Rostedt
2013-04-23  8:31 ` [PATCH 06/14] perf ftrace: Add support for --pid option Namhyung Kim
2013-04-23  8:31 ` [PATCH 07/14] perf ftrace: Add support for -a and -C option Namhyung Kim
2013-04-23  8:31 ` Namhyung Kim [this message]
2013-04-23  8:31 ` [PATCH 09/14] perf ftrace: Add 'record' sub-command Namhyung Kim
2013-04-24 14:12   ` Jiri Olsa
2013-04-25  6:24     ` Namhyung Kim
2013-04-26  8:35       ` Jiri Olsa
2013-04-26 13:44       ` David Ahern
2013-05-06  1:57         ` Namhyung Kim
2013-05-06  3:22           ` David Ahern
2013-05-06  1:44       ` Namhyung Kim
2013-05-06 12:04         ` Jiri Olsa
2013-05-08  5:27           ` Namhyung Kim
2013-04-23  8:31 ` [PATCH 10/14] perf ftrace: Add 'show' sub-command Namhyung Kim
2013-04-23  8:31 ` [PATCH 11/14] perf ftrace: Add 'report' sub-command Namhyung Kim
2013-04-23  8:31 ` [PATCH 12/14] perf ftrace: Use pager for displaying result Namhyung Kim
2013-04-24 14:17   ` Jiri Olsa
2013-04-25  6:50     ` Namhyung Kim
2013-04-26  8:40       ` Jiri Olsa
2013-05-06  1:52         ` Namhyung Kim
2013-05-06 11:38           ` Jiri Olsa
2013-05-08  5:49             ` Namhyung Kim
2013-05-10  9:04               ` Jiri Olsa
2013-05-13  8:53                 ` Namhyung Kim
2013-05-13 13:42                   ` Jiri Olsa
2013-05-14  0:58                     ` Namhyung Kim
2013-04-23  8:31 ` [PATCH 13/14] perf ftrace: Cleanup using ftrace_setup/teardown() Namhyung Kim
2013-04-23  8:31 ` [PATCH 14/14] perf tools: Add document for perf-ftrace command Namhyung Kim
2013-04-23 15:53   ` Steven Rostedt
2013-04-24 10:39     ` Namhyung Kim
2013-04-23 15:58 ` [RFC 00/14] perf tools: Introduce new 'ftrace' command Steven Rostedt
2013-04-23 17:19   ` Pekka Enberg
2013-04-24  6:50     ` Ingo Molnar
2013-04-24  9:52       ` Namhyung Kim
2013-04-24 11:15         ` zhangwei(Jovi)
2013-04-25  5:53           ` Namhyung Kim
2013-04-24  9:29     ` Namhyung Kim
2013-04-24  9:27   ` Namhyung Kim
2013-04-24 11:14     ` zhangwei(Jovi)
2013-04-25  5:45       ` Namhyung Kim

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=1366705872-12132-9-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=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

all inboxes | Powered by JetHome®