linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Wang Nan <wangnan0@huawei.com>,
	pi3orama@163.com, Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 28/31] perf probe: Move print logic into cmd_probe()
Date: Fri,  4 Sep 2015 13:45:12 -0300	[thread overview]
Message-ID: <1441385115-6744-29-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1441385115-6744-1-git-send-email-acme@kernel.org>

From: Namhyung Kim <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

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1441368963-11565-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-probe.c    | 48 ++++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/probe-event.c | 22 +++-----------------
 tools/perf/util/probe-event.h |  3 +++
 3 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index b81cec33b4b2..b8cf6cb7e1bf 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -311,6 +311,52 @@ static void pr_err_with_code(const char *msg, int err)
 	pr_err("\n");
 }
 
+static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
+{
+	int ret;
+	int i, k;
+	const char *event = NULL, *group = NULL;
+
+	ret = convert_perf_probe_events(pevs, npevs);
+	if (ret < 0)
+		goto out_cleanup;
+
+	ret = apply_perf_probe_events(pevs, npevs);
+	if (ret < 0)
+		goto out_cleanup;
+
+	for (i = k = 0; i < npevs; i++)
+		k += pevs[i].ntevs;
+
+	pr_info("Added new event%s\n", (k > 1) ? "s:" : ":");
+	for (i = 0; i < npevs; i++) {
+		struct perf_probe_event *pev = &pevs[i];
+
+		for (k = 0; k < pev->ntevs; k++) {
+			struct probe_trace_event *tev = &pev->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(pevs, npevs);
+	return ret;
+}
+
 static int
 __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 {
@@ -496,7 +542,7 @@ __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 = perf_add_probe_events(params.events, 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 0d3a051b9202..01b9a5bd9449 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 70c327bd61de..610f743671e1 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -144,6 +144,9 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
 extern int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
 extern void cleanup_perf_probe_events(struct perf_probe_event *pevs, 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.1.0


  parent reply	other threads:[~2015-09-04 16:46 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 16:44 [GIT PULL 00/31] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 01/31] perf tools: Always use non inlined file name for 'srcfile' sort key Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 02/31] perf tools: Copy linux/filter.h to tools/include Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 03/31] tools lib traceevent: Support function __get_dynamic_array_len Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 04/31] perf cpumap: Factor out functions to get core_id and socket_id Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 05/31] perf tools: Store the cpu socket and core ids in the perf.data header Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 06/31] perf stat: Quieten failed to read counter message Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 07/31] perf tools: Remove mountpoint arg from perf_debugfs_mount Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 08/31] perf tools: Move tracing_path stuff under same namespace Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 09/31] tools lib api fs: Move tracing_path interface into api/fs/tracing_path.c Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 10/31] tools lib api fs: Move debugfs__strerror_open into tracing_path.c object Arnaldo Carvalho de Melo
2015-09-04 16:57   ` Raphaël Beamonte
2015-09-04 20:38     ` Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 11/31] tools lib api fs: Add STR and PATH_MAX macros to fs object Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 12/31] tools lib api fs: Move SYSFS_MAGIC PROC_SUPER_MAGIC into fs.c Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 13/31] tools lib api fs: Add debugfs into fs.c object Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 14/31] tools lib api fs: Add tracefs " Arnaldo Carvalho de Melo
2015-09-04 16:44 ` [PATCH 15/31] tools lib api fs: Add FSTYPE__mount() method Arnaldo Carvalho de Melo
2015-09-04 17:02   ` Raphaël Beamonte
2015-09-04 16:45 ` [PATCH 16/31] tools lib api fs: Add FSTYPE__configured() method Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 17/31] perf tools: Display build warning if x86 instruction decoder differs from kernel Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 18/31] perf tools: Add a test for decoding of new x86 instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 19/31] x86/insn: perf tools: Pedantically tweak opcode map for MPX instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 20/31] x86/insn: perf tools: Add new SHA instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 21/31] x86/insn: perf tools: Add new memory instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 22/31] x86/insn: perf tools: Add new memory protection keys instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 23/31] x86/insn: perf tools: Add new xsave instructions Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 24/31] perf session: Don't call dump_sample() when evsel is NULL Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 25/31] perf intel-pt: Add support for PERF_RECORD_SWITCH Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 26/31] perf probe: Split add_perf_probe_events() Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 27/31] perf probe: Link trace_probe_event into perf_probe_event Arnaldo Carvalho de Melo
2015-09-04 16:45 ` Arnaldo Carvalho de Melo [this message]
2015-09-04 16:45 ` [PATCH 29/31] perf probe: Split del_perf_probe_events() Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 30/31] perf probe: Print deleted events in cmd_probe() Arnaldo Carvalho de Melo
2015-09-04 16:45 ` [PATCH 31/31] perf trace: Add read/write to the file group Arnaldo Carvalho de Melo
2015-09-08 14:24 ` [GIT PULL 00/31] perf/core improvements and fixes Ingo Molnar

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=1441385115-6744-29-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    --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;
as well as URLs for NNTP newsgroup(s).