public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	Wang Nan <wangnan0@huawei.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Subject: [RFC/PATCH 3/3] perf probe: Move print logic into cmd_probe()
Date: Fri,  4 Sep 2015 02:28:57 +0900	[thread overview]
Message-ID: <1441301337-18954-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1441301337-18954-1-git-send-email-namhyung@kernel.org>

Showing actual trace event when adding perf events is only needed in
perf probe command.  But the add functionality itself can be used by
other places.  So move the printing code into the cmd_probe().

Also it combines the output if more than one event is added.

Before:
  $ sudo perf probe -a do_fork -a do_exit
  Added new event:
  probe:do_fork        (on do_fork)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_fork -aR sleep 1

  Added new events:
  probe:do_exit        (on do_exit)
  probe:do_exit_1      (on do_exit)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_exit_1 -aR sleep 1

After:
  $ sudo perf probe -a do_fork -a do_exit
  Added new events:
  probe:do_fork        (on do_fork)
  probe:do_exit        (on do_exit)
  probe:do_exit_1      (on do_exit)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_exit_1 -aR sleep 1

Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-probe.c    | 39 ++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/probe-event.c | 22 +++-------------------
 tools/perf/util/probe-event.h |  3 +++
 3 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index b81cec33b4b2..827eb7ed92b2 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -403,6 +403,9 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_END()
 	};
 	int ret;
+	int i, k;
+	struct probe_event_package *pkgs = NULL;
+	const char *event = NULL, *group = NULL;
 
 	set_option_flag(options, 'a', "add", PARSE_OPT_EXCLUSIVE);
 	set_option_flag(options, 'd', "del", PARSE_OPT_EXCLUSIVE);
@@ -496,7 +499,41 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 			usage_with_options(probe_usage, options);
 		}
 
-		ret = add_perf_probe_events(params.events, params.nevents);
+		ret = __add_perf_probe_events(params.events, params.nevents,
+					      &pkgs);
+		if (ret < 0)
+			goto out_cleanup;
+
+		for (i = k = 0; i < params.nevents; i++)
+			k += pkgs[i].ntevs;
+
+		pr_info("Added new event%s\n", (k > 1) ? "s:" : ":");
+		for (i = 0; i < params.nevents; i++) {
+			struct perf_probe_event *pev = pkgs[i].pev;
+
+			for (k = 0; k < pkgs[i].ntevs; k++) {
+				struct probe_trace_event *tev = &pkgs[i].tevs[k];
+
+				/* We use tev's name for showing new events */
+				show_perf_probe_event(tev->group, tev->event, pev,
+						      tev->point.module, false);
+
+				/* Save the last valid name */
+				event = tev->event;
+				group = tev->group;
+			}
+		}
+
+		/* Note that it is possible to skip all events because of blacklist */
+		if (event) {
+			/* Show how to use the event. */
+			pr_info("\nYou can now use it in all perf tools, such as:\n\n");
+			pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
+		}
+
+out_cleanup:
+		cleanup_perf_probe_events(pkgs, params.nevents);
+
 		if (ret < 0) {
 			pr_err_with_code("  Error: Failed to add events.", ret);
 			return ret;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index eef39338bb2a..9c68fc551f9e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2180,9 +2180,9 @@ out:
 }
 
 /* Show an event */
-static int show_perf_probe_event(const char *group, const char *event,
-				 struct perf_probe_event *pev,
-				 const char *module, bool use_stdout)
+int show_perf_probe_event(const char *group, const char *event,
+			  struct perf_probe_event *pev,
+			  const char *module, bool use_stdout)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int ret;
@@ -2399,7 +2399,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 {
 	int i, fd, ret;
 	struct probe_trace_event *tev = NULL;
-	const char *event = NULL, *group = NULL;
 	struct strlist *namelist;
 
 	fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
@@ -2415,7 +2414,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 	}
 
 	ret = 0;
-	pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
 	for (i = 0; i < ntevs; i++) {
 		tev = &tevs[i];
 		/* Skip if the symbol is out of .text or blacklisted */
@@ -2432,13 +2430,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		if (ret < 0)
 			break;
 
-		/* We use tev's name for showing new events */
-		show_perf_probe_event(tev->group, tev->event, pev,
-				      tev->point.module, false);
-		/* Save the last valid name */
-		event = tev->event;
-		group = tev->group;
-
 		/*
 		 * Probes after the first probe which comes from same
 		 * user input are always allowed to add suffix, because
@@ -2450,13 +2441,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 	if (ret == -EINVAL && pev->uprobes)
 		warn_uprobe_event_compat(tev);
 
-	/* Note that it is possible to skip all events because of blacklist */
-	if (ret >= 0 && event) {
-		/* Show how to use the event. */
-		pr_info("\nYou can now use it in all perf tools, such as:\n\n");
-		pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
-	}
-
 	strlist__delete(namelist);
 close_out:
 	close(fd);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 73f922fa7cac..843d1feffc97 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -149,6 +149,9 @@ extern int __add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
 extern void cleanup_perf_probe_events(struct probe_event_package *pkgs,
 				      int npevs);
 extern int del_perf_probe_events(struct strfilter *filter);
+extern int show_perf_probe_event(const char *group, const char *event,
+				 struct perf_probe_event *pev,
+				 const char *module, bool use_stdout);
 extern int show_perf_probe_events(struct strfilter *filter);
 extern int show_line_range(struct line_range *lr, const char *module,
 			   bool user);
-- 
2.5.0


  parent reply	other threads:[~2015-09-03 17:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-03 17:28 [RFC/PATCH 1/3] perf probe: Split add_perf_probe_events() Namhyung Kim
2015-09-03 17:28 ` [RFC/PATCH 2/3] perf probe: Rename __event_package to probe_event_package Namhyung Kim
2015-09-04  2:11   ` 平松雅巳 / HIRAMATU,MASAMI
2015-09-04  6:09     ` Namhyung Kim
2015-09-04  7:55       ` 平松雅巳 / HIRAMATU,MASAMI
2015-09-03 17:28 ` Namhyung Kim [this message]
2015-09-04  2:17   ` [RFC/PATCH 3/3] perf probe: Move print logic into cmd_probe() 平松雅巳 / HIRAMATU,MASAMI
2015-09-04  2:11 ` [RFC/PATCH 1/3] perf probe: Split add_perf_probe_events() 平松雅巳 / HIRAMATU,MASAMI

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=1441301337-18954-3-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=wangnan0@huawei.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