All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH perf/core v2 0/3] perf-probe bugfixes
@ 2015-06-13  1:31 Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout Masami Hiramatsu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2015-06-13  1:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

Hi Arnaldo,

Here is the updated series of bugfix patches for perf-probe.
I've fixed inverted bool flags bug on the 1/3.
This series fixes below bugs;

 - --list shows the list of probes in stderr.
   (It is refined from https://lkml.org/lkml/2015/5/30/34)
 - non-probe-able symbols (out of .text) are not checked when
   using symbol maps.
 - usage message is not shown if the last event is skipped.

Thank you,

---

Masami Hiramatsu (3):
      [BUGFIX] perf probe: List probes in stdout
      [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map
      [BUGFIX] perf probe: Show usage even if the last event is skipped


 tools/perf/util/probe-event.c |  187 ++++++++++++++++++++++++++---------------
 1 file changed, 118 insertions(+), 69 deletions(-)


-- 
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering 
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu.pt@hitachi.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout
  2015-06-13  1:31 [PATCH perf/core v2 0/3] perf-probe bugfixes Masami Hiramatsu
@ 2015-06-13  1:31 ` Masami Hiramatsu
  2015-06-18  8:13   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 3/3] [BUGFIX] perf probe: Show usage even if the last event is skipped Masami Hiramatsu
  2 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2015-06-13  1:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

Since commit 5e17b28f1e24 ("perf probe: Add --quiet option to
suppress output result message") have replaced printf with pr_info,
perf probe -l outputs its result in stderr. However, that is not
what the commit expected.
e.g.
  -----
  # perf probe -l > /dev/null
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)
  -----
With this fix,
  -----
  # perf probe -l > list
  # cat list
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)
  -----
Of course, --quiet(-q) still works on --add/--del.
  -----
  # perf probe -q vfs_write
  # perf probe -l
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)
    probe:vfs_write      (on vfs_write@ksrc/linux-3/fs/read_write.c)
  -----

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Reported-by: Naohiro Aota <naota@elisp.net>

---
 Changes in v2:
  - Fix to reverse the use_stdio flag at each caller.
---
 tools/perf/util/probe-event.c |   49 +++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index daa24a2..c4ab588 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2126,9 +2126,9 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
 	return NULL;
 }
 
-/* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
-				 const char *module)
+static int perf_probe_event__sprintf(struct perf_probe_event *pev,
+				     const char *module,
+				     struct strbuf *result)
 {
 	int i, ret;
 	char buf[128];
@@ -2141,27 +2141,47 @@ static int show_perf_probe_event(struct perf_probe_event *pev,
 
 	ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
 	if (ret < 0)
-		return ret;
+		goto out;
 
-	pr_info("  %-20s (on %s", buf, place);
+	strbuf_addf(result, "  %-20s (on %s", buf, place);
 	if (module)
-		pr_info(" in %s", module);
+		strbuf_addf(result, " in %s", module);
 
 	if (pev->nargs > 0) {
-		pr_info(" with");
+		strbuf_addstr(result, " with");
 		for (i = 0; i < pev->nargs; i++) {
 			ret = synthesize_perf_probe_arg(&pev->args[i],
 							buf, 128);
 			if (ret < 0)
-				break;
-			pr_info(" %s", buf);
+				goto out;
+			strbuf_addf(result, " %s", buf);
 		}
 	}
-	pr_info(")\n");
+	strbuf_addch(result, ')');
+out:
 	free(place);
 	return ret;
 }
 
+/* Show an event */
+static int show_perf_probe_event(struct perf_probe_event *pev,
+				 const char *module, bool use_stdout)
+{
+	struct strbuf buf = STRBUF_INIT;
+	int ret;
+
+	ret = perf_probe_event__sprintf(pev, module, &buf);
+	if (ret >= 0) {
+		if (use_stdout)
+			printf("%s\n", buf.buf);
+		else
+			pr_info("%s\n", buf.buf);
+	}
+	strbuf_release(&buf);
+
+	return ret;
+}
+
 static bool filter_probe_trace_event(struct probe_trace_event *tev,
 				     struct strfilter *filter)
 {
@@ -2200,9 +2220,10 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
 				goto next;
 			ret = convert_to_perf_probe_event(&tev, &pev,
 								is_kprobe);
-			if (ret >= 0)
-				ret = show_perf_probe_event(&pev,
-							    tev.point.module);
+			if (ret < 0)
+				goto next;
+			ret = show_perf_probe_event(&pev, tev.point.module,
+						    true);
 		}
 next:
 		clear_perf_probe_event(&pev);
@@ -2468,7 +2489,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		group = pev->group;
 		pev->event = tev->event;
 		pev->group = tev->group;
-		show_perf_probe_event(pev, tev->point.module);
+		show_perf_probe_event(pev, tev->point.module, false);
 		/* Trick here - restore current event/group */
 		pev->event = (char *)event;
 		pev->group = (char *)group;


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map
  2015-06-13  1:31 [PATCH perf/core v2 0/3] perf-probe bugfixes Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout Masami Hiramatsu
@ 2015-06-13  1:31 ` Masami Hiramatsu
  2015-06-15 18:57   ` Arnaldo Carvalho de Melo
  2015-06-13  1:31 ` [PATCH perf/core v2 3/3] [BUGFIX] perf probe: Show usage even if the last event is skipped Masami Hiramatsu
  2 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2015-06-13  1:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

Fix to check both of non-exist symbols and kprobe blacklist symbols at
symbol-map based converting too.

E.g. without this fix, perf-probe failes to write the event.
  ----
  # perf probe vfs_caches_init_early
  Added new event:
  Failed to write event: Invalid argument
    Error: Failed to add events.
  ----

This fixes it to catch the error before adding probes.
  ----
  # perf probe vfs_caches_init_early
  vfs_caches_init_early is out of .text, skip it.
    Error: Failed to add events.
  ----

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 tools/perf/util/probe-event.c |  113 ++++++++++++++++++++++++++---------------
 1 file changed, 71 insertions(+), 42 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index c4ab588..85c8207 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs)
 		clear_probe_trace_event(tevs + i);
 }
 
+static bool kprobe_blacklist__listed(unsigned long address);
+static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
+{
+	/* Get the address of _etext for checking non-probable text symbol */
+	if (kernel_get_symbol_address_by_name("_etext", false) < address)
+		pr_warning("%s is out of .text, skip it.\n", symbol);
+	else if (kprobe_blacklist__listed(address))
+		pr_warning("%s is blacklisted function, skip it.\n", symbol);
+	else
+		return false;
+
+	return true;
+}
+
 #ifdef HAVE_DWARF_SUPPORT
 
 static int kernel_get_module_dso(const char *module, struct dso **pdso)
@@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
 					   bool uprobe)
 {
 	struct ref_reloc_sym *reloc_sym;
-	u64 etext_addr;
 	char *tmp;
 	int i, skipped = 0;
 
@@ -575,31 +588,28 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
 		pr_warning("Relocated base symbol is not found!\n");
 		return -EINVAL;
 	}
-	/* Get the address of _etext for checking non-probable text symbol */
-	etext_addr = kernel_get_symbol_address_by_name("_etext", false);
 
 	for (i = 0; i < ntevs; i++) {
-		if (tevs[i].point.address && !tevs[i].point.retprobe) {
-			/* If we found a wrong one, mark it by NULL symbol */
-			if (etext_addr < tevs[i].point.address) {
-				pr_warning("%s+%lu is out of .text, skip it.\n",
-				   tevs[i].point.symbol, tevs[i].point.offset);
-				tmp = NULL;
-				skipped++;
-			} else {
-				tmp = strdup(reloc_sym->name);
-				if (!tmp)
-					return -ENOMEM;
-			}
-			/* If we have no realname, use symbol for it */
-			if (!tevs[i].point.realname)
-				tevs[i].point.realname = tevs[i].point.symbol;
-			else
-				free(tevs[i].point.symbol);
-			tevs[i].point.symbol = tmp;
-			tevs[i].point.offset = tevs[i].point.address -
-					       reloc_sym->unrelocated_addr;
+		if (!tevs[i].point.address || tevs[i].point.retprobe)
+			continue;
+		/* If we found a wrong one, mark it by NULL symbol */
+		if (kprobe_warn_out_range(tevs[i].point.symbol,
+					  tevs[i].point.address)) {
+			tmp = NULL;
+			skipped++;
+		} else {
+			tmp = strdup(reloc_sym->name);
+			if (!tmp)
+				return -ENOMEM;
 		}
+		/* If we have no realname, use symbol for it */
+		if (!tevs[i].point.realname)
+			tevs[i].point.realname = tevs[i].point.symbol;
+		else
+			free(tevs[i].point.symbol);
+		tevs[i].point.symbol = tmp;
+		tevs[i].point.offset = tevs[i].point.address -
+				       reloc_sym->unrelocated_addr;
 	}
 	return skipped;
 }
@@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
 	return NULL;
 }
 
+static LIST_HEAD(kprobe_blacklist);
+
+static void kprobe_blacklist__init(void)
+{
+	if (!list_empty(&kprobe_blacklist))
+		return;
+
+	if (kprobe_blacklist__load(&kprobe_blacklist) < 0)
+		pr_debug("No kprobe blacklist support, ignored\n");
+}
+
+static void kprobe_blacklist__release(void)
+{
+	kprobe_blacklist__delete(&kprobe_blacklist);
+}
+
+static bool kprobe_blacklist__listed(unsigned long address)
+{
+	return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address);
+}
+
 static int perf_probe_event__sprintf(struct perf_probe_event *pev,
 				     const char *module,
 				     struct strbuf *result)
@@ -2409,8 +2440,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 	char buf[64];
 	const char *event, *group;
 	struct strlist *namelist;
-	LIST_HEAD(blacklist);
-	struct kprobe_blacklist_node *node;
 	bool safename;
 
 	if (pev->uprobes)
@@ -2430,28 +2459,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		ret = -ENOMEM;
 		goto close_out;
 	}
-	/* Get kprobe blacklist if exists */
-	if (!pev->uprobes) {
-		ret = kprobe_blacklist__load(&blacklist);
-		if (ret < 0)
-			pr_debug("No kprobe blacklist support, ignored\n");
-	}
 
 	safename = (pev->point.function && !strisglob(pev->point.function));
 	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 (marked previously) */
+		/* Skip if the symbol is out of .text or blacklisted */
 		if (!tev->point.symbol)
 			continue;
-		/* Ensure that the address is NOT blacklisted */
-		node = kprobe_blacklist__find_by_address(&blacklist,
-							 tev->point.address);
-		if (node) {
-			pr_warning("Warning: Skipped probing on blacklisted function: %s\n", node->symbol);
-			continue;
-		}
 
 		if (pev->event)
 			event = pev->event;
@@ -2513,7 +2529,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 			 tev->event);
 	}
 
-	kprobe_blacklist__delete(&blacklist);
 	strlist__delete(namelist);
 close_out:
 	close(fd);
@@ -2563,7 +2578,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 	struct perf_probe_point *pp = &pev->point;
 	struct probe_trace_point *tp;
 	int num_matched_functions;
-	int ret, i, j;
+	int ret, i, j, skipped = 0;
 
 	map = get_target_map(pev->target, pev->uprobes);
 	if (!map) {
@@ -2631,7 +2646,12 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 		}
 		/* Add one probe point */
 		tp->address = map->unmap_ip(map, sym->start) + pp->offset;
-		if (reloc_sym) {
+		/* If we found a wrong one, mark it by NULL symbol */
+		if (!pev->uprobes &&
+		    kprobe_warn_out_range(sym->name, tp->address)) {
+			tp->symbol = NULL;	/* Skip it */
+			skipped++;
+		} else if (reloc_sym) {
 			tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out);
 			tp->offset = tp->address - reloc_sym->addr;
 		} else {
@@ -2667,6 +2687,10 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 		}
 		arch__fix_tev_from_maps(pev, tev, map);
 	}
+	if (ret == skipped) {
+		ret = -ENOENT;
+		goto err_out;
+	}
 
 out:
 	put_target_map(map, pev->uprobes);
@@ -2737,6 +2761,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
 	/* Loop 1: convert all events */
 	for (i = 0; i < npevs; i++) {
 		pkgs[i].pev = &pevs[i];
+		/* Init kprobe blacklist if needed */
+		if (!pkgs[i].pev->uprobes)
+			kprobe_blacklist__init();
 		/* Convert with or without debuginfo */
 		ret  = convert_to_probe_trace_events(pkgs[i].pev,
 						     &pkgs[i].tevs);
@@ -2744,6 +2771,8 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
 			goto end;
 		pkgs[i].ntevs = ret;
 	}
+	/* This just release blacklist only if allocated */
+	kprobe_blacklist__release();
 
 	/* Loop 2: add all events */
 	for (i = 0; i < npevs; i++) {


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH perf/core v2 3/3] [BUGFIX] perf probe: Show usage even if the last event is skipped
  2015-06-13  1:31 [PATCH perf/core v2 0/3] perf-probe bugfixes Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout Masami Hiramatsu
  2015-06-13  1:31 ` [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map Masami Hiramatsu
@ 2015-06-13  1:31 ` Masami Hiramatsu
  2 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2015-06-13  1:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

When the last part of converted events are blacklisted or out-of-text,
those are skipped and perf probe doesn't show usage examples.
This fixes it to show the example even if the last part of event list
is skipped.

E.g. without this patch, events are added, but suddenly end;
  ----
  # perf probe vfs_*
  vfs_caches_init_early is out of .text, skip it.
  vfs_caches_init is out of .text, skip it.
  Added new events:
    probe:vfs_fallocate  (on vfs_*)
    probe:vfs_open       (on vfs_*)
  ...
    probe:vfs_dentry_acceptable (on vfs_*)
    probe:vfs_load_quota_inode (on vfs_*)
  #
  ----
With this fix;
  ----
  # perf probe vfs_*
  vfs_caches_init_early is out of .text, skip it.
  vfs_caches_init is out of .text, skip it.
  Added new events:
    probe:vfs_fallocate  (on vfs_*)
  ...
    probe:vfs_load_quota_inode (on vfs_*)

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

	perf record -e probe:vfs_load_quota_inode -aR sleep 1

  #
  ----

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 tools/perf/util/probe-event.c |   35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 85c8207..65a1c82 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2157,7 +2157,8 @@ static bool kprobe_blacklist__listed(unsigned long address)
 	return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address);
 }
 
-static int perf_probe_event__sprintf(struct perf_probe_event *pev,
+static int perf_probe_event__sprintf(const char *group, const char *event,
+				     struct perf_probe_event *pev,
 				     const char *module,
 				     struct strbuf *result)
 {
@@ -2170,7 +2171,7 @@ static int perf_probe_event__sprintf(struct perf_probe_event *pev,
 	if (!place)
 		return -EINVAL;
 
-	ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
+	ret = e_snprintf(buf, 128, "%s:%s", group, event);
 	if (ret < 0)
 		goto out;
 
@@ -2195,13 +2196,14 @@ out:
 }
 
 /* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
+static 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;
 
-	ret = perf_probe_event__sprintf(pev, module, &buf);
+	ret = perf_probe_event__sprintf(group, event, pev, module, &buf);
 	if (ret >= 0) {
 		if (use_stdout)
 			printf("%s\n", buf.buf);
@@ -2253,7 +2255,8 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
 								is_kprobe);
 			if (ret < 0)
 				goto next;
-			ret = show_perf_probe_event(&pev, tev.point.module,
+			ret = show_perf_probe_event(pev.group, pev.event,
+						    &pev, tev.point.module,
 						    true);
 		}
 next:
@@ -2438,7 +2441,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 	int i, fd, ret;
 	struct probe_trace_event *tev = NULL;
 	char buf[64];
-	const char *event, *group;
+	const char *event = NULL, *group = NULL;
 	struct strlist *namelist;
 	bool safename;
 
@@ -2500,15 +2503,12 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		/* Add added event name to namelist */
 		strlist__add(namelist, event);
 
-		/* Trick here - save current event/group */
-		event = pev->event;
-		group = pev->group;
-		pev->event = tev->event;
-		pev->group = tev->group;
-		show_perf_probe_event(pev, tev->point.module, false);
-		/* Trick here - restore current event/group */
-		pev->event = (char *)event;
-		pev->group = (char *)group;
+		/* 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
@@ -2522,11 +2522,10 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		warn_uprobe_event_compat(tev);
 
 	/* Note that it is possible to skip all events because of blacklist */
-	if (ret >= 0 && tev->event) {
+	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", tev->group,
-			 tev->event);
+		pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
 	}
 
 	strlist__delete(namelist);


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map
  2015-06-13  1:31 ` [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map Masami Hiramatsu
@ 2015-06-15 18:57   ` Arnaldo Carvalho de Melo
  2015-06-16 11:10     ` Masami Hiramatsu
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-06-15 18:57 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

Em Sat, Jun 13, 2015 at 10:31:18AM +0900, Masami Hiramatsu escreveu:
> Fix to check both of non-exist symbols and kprobe blacklist symbols at
> symbol-map based converting too.
> 
> E.g. without this fix, perf-probe failes to write the event.
>   ----
>   # perf probe vfs_caches_init_early
>   Added new event:
>   Failed to write event: Invalid argument
>     Error: Failed to add events.
>   ----

Well, here, after I applied 1/3 in this series, before this patch, I
get:


[root@zoo ~]# grep vfs_caches_init_early /proc/kallsyms 
ffffffff81d8e60f T vfs_caches_init_early
[root@zoo ~]# perf probe vfs_caches_init_early
vfs_caches_init_early+0 is out of .text, skip it.
Probe point 'vfs_caches_init_early' not found.
  Error: Failed to add events.
[root@zoo ~]#

What am I doind wrong? I am getting the message you said I should get after
applying your patch, before I apply it... /me confused :-\

First patch applied, waiting for you on this and the next.

- Arnaldo

> 
> This fixes it to catch the error before adding probes.
>   ----
>   # perf probe vfs_caches_init_early
>   vfs_caches_init_early is out of .text, skip it.
>     Error: Failed to add events.
>   ----
> 
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> ---
>  tools/perf/util/probe-event.c |  113 ++++++++++++++++++++++++++---------------
>  1 file changed, 71 insertions(+), 42 deletions(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index c4ab588..85c8207 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs)
>  		clear_probe_trace_event(tevs + i);
>  }
>  
> +static bool kprobe_blacklist__listed(unsigned long address);
> +static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
> +{
> +	/* Get the address of _etext for checking non-probable text symbol */
> +	if (kernel_get_symbol_address_by_name("_etext", false) < address)
> +		pr_warning("%s is out of .text, skip it.\n", symbol);
> +	else if (kprobe_blacklist__listed(address))
> +		pr_warning("%s is blacklisted function, skip it.\n", symbol);
> +	else
> +		return false;
> +
> +	return true;
> +}
> +
>  #ifdef HAVE_DWARF_SUPPORT
>  
>  static int kernel_get_module_dso(const char *module, struct dso **pdso)
> @@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
>  					   bool uprobe)
>  {
>  	struct ref_reloc_sym *reloc_sym;
> -	u64 etext_addr;
>  	char *tmp;
>  	int i, skipped = 0;
>  
> @@ -575,31 +588,28 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
>  		pr_warning("Relocated base symbol is not found!\n");
>  		return -EINVAL;
>  	}
> -	/* Get the address of _etext for checking non-probable text symbol */
> -	etext_addr = kernel_get_symbol_address_by_name("_etext", false);
>  
>  	for (i = 0; i < ntevs; i++) {
> -		if (tevs[i].point.address && !tevs[i].point.retprobe) {
> -			/* If we found a wrong one, mark it by NULL symbol */
> -			if (etext_addr < tevs[i].point.address) {
> -				pr_warning("%s+%lu is out of .text, skip it.\n",
> -				   tevs[i].point.symbol, tevs[i].point.offset);
> -				tmp = NULL;
> -				skipped++;
> -			} else {
> -				tmp = strdup(reloc_sym->name);
> -				if (!tmp)
> -					return -ENOMEM;
> -			}
> -			/* If we have no realname, use symbol for it */
> -			if (!tevs[i].point.realname)
> -				tevs[i].point.realname = tevs[i].point.symbol;
> -			else
> -				free(tevs[i].point.symbol);
> -			tevs[i].point.symbol = tmp;
> -			tevs[i].point.offset = tevs[i].point.address -
> -					       reloc_sym->unrelocated_addr;
> +		if (!tevs[i].point.address || tevs[i].point.retprobe)
> +			continue;
> +		/* If we found a wrong one, mark it by NULL symbol */
> +		if (kprobe_warn_out_range(tevs[i].point.symbol,
> +					  tevs[i].point.address)) {
> +			tmp = NULL;
> +			skipped++;
> +		} else {
> +			tmp = strdup(reloc_sym->name);
> +			if (!tmp)
> +				return -ENOMEM;
>  		}
> +		/* If we have no realname, use symbol for it */
> +		if (!tevs[i].point.realname)
> +			tevs[i].point.realname = tevs[i].point.symbol;
> +		else
> +			free(tevs[i].point.symbol);
> +		tevs[i].point.symbol = tmp;
> +		tevs[i].point.offset = tevs[i].point.address -
> +				       reloc_sym->unrelocated_addr;
>  	}
>  	return skipped;
>  }
> @@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
>  	return NULL;
>  }
>  
> +static LIST_HEAD(kprobe_blacklist);
> +
> +static void kprobe_blacklist__init(void)
> +{
> +	if (!list_empty(&kprobe_blacklist))
> +		return;
> +
> +	if (kprobe_blacklist__load(&kprobe_blacklist) < 0)
> +		pr_debug("No kprobe blacklist support, ignored\n");
> +}
> +
> +static void kprobe_blacklist__release(void)
> +{
> +	kprobe_blacklist__delete(&kprobe_blacklist);
> +}
> +
> +static bool kprobe_blacklist__listed(unsigned long address)
> +{
> +	return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address);
> +}
> +
>  static int perf_probe_event__sprintf(struct perf_probe_event *pev,
>  				     const char *module,
>  				     struct strbuf *result)
> @@ -2409,8 +2440,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>  	char buf[64];
>  	const char *event, *group;
>  	struct strlist *namelist;
> -	LIST_HEAD(blacklist);
> -	struct kprobe_blacklist_node *node;
>  	bool safename;
>  
>  	if (pev->uprobes)
> @@ -2430,28 +2459,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>  		ret = -ENOMEM;
>  		goto close_out;
>  	}
> -	/* Get kprobe blacklist if exists */
> -	if (!pev->uprobes) {
> -		ret = kprobe_blacklist__load(&blacklist);
> -		if (ret < 0)
> -			pr_debug("No kprobe blacklist support, ignored\n");
> -	}
>  
>  	safename = (pev->point.function && !strisglob(pev->point.function));
>  	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 (marked previously) */
> +		/* Skip if the symbol is out of .text or blacklisted */
>  		if (!tev->point.symbol)
>  			continue;
> -		/* Ensure that the address is NOT blacklisted */
> -		node = kprobe_blacklist__find_by_address(&blacklist,
> -							 tev->point.address);
> -		if (node) {
> -			pr_warning("Warning: Skipped probing on blacklisted function: %s\n", node->symbol);
> -			continue;
> -		}
>  
>  		if (pev->event)
>  			event = pev->event;
> @@ -2513,7 +2529,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>  			 tev->event);
>  	}
>  
> -	kprobe_blacklist__delete(&blacklist);
>  	strlist__delete(namelist);
>  close_out:
>  	close(fd);
> @@ -2563,7 +2578,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>  	struct perf_probe_point *pp = &pev->point;
>  	struct probe_trace_point *tp;
>  	int num_matched_functions;
> -	int ret, i, j;
> +	int ret, i, j, skipped = 0;
>  
>  	map = get_target_map(pev->target, pev->uprobes);
>  	if (!map) {
> @@ -2631,7 +2646,12 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>  		}
>  		/* Add one probe point */
>  		tp->address = map->unmap_ip(map, sym->start) + pp->offset;
> -		if (reloc_sym) {
> +		/* If we found a wrong one, mark it by NULL symbol */
> +		if (!pev->uprobes &&
> +		    kprobe_warn_out_range(sym->name, tp->address)) {
> +			tp->symbol = NULL;	/* Skip it */
> +			skipped++;
> +		} else if (reloc_sym) {
>  			tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out);
>  			tp->offset = tp->address - reloc_sym->addr;
>  		} else {
> @@ -2667,6 +2687,10 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>  		}
>  		arch__fix_tev_from_maps(pev, tev, map);
>  	}
> +	if (ret == skipped) {
> +		ret = -ENOENT;
> +		goto err_out;
> +	}
>  
>  out:
>  	put_target_map(map, pev->uprobes);
> @@ -2737,6 +2761,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
>  	/* Loop 1: convert all events */
>  	for (i = 0; i < npevs; i++) {
>  		pkgs[i].pev = &pevs[i];
> +		/* Init kprobe blacklist if needed */
> +		if (!pkgs[i].pev->uprobes)
> +			kprobe_blacklist__init();
>  		/* Convert with or without debuginfo */
>  		ret  = convert_to_probe_trace_events(pkgs[i].pev,
>  						     &pkgs[i].tevs);
> @@ -2744,6 +2771,8 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
>  			goto end;
>  		pkgs[i].ntevs = ret;
>  	}
> +	/* This just release blacklist only if allocated */
> +	kprobe_blacklist__release();
>  
>  	/* Loop 2: add all events */
>  	for (i = 0; i < npevs; i++) {

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map
  2015-06-15 18:57   ` Arnaldo Carvalho de Melo
@ 2015-06-16 11:10     ` Masami Hiramatsu
  0 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2015-06-16 11:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Naohiro Aota, Peter Zijlstra, Linux Kernel Mailing List,
	David Ahern, namhyung, Jiri Olsa, Ingo Molnar

On 2015/06/16 3:57, Arnaldo Carvalho de Melo wrote:
> Em Sat, Jun 13, 2015 at 10:31:18AM +0900, Masami Hiramatsu escreveu:
>> Fix to check both of non-exist symbols and kprobe blacklist symbols at
>> symbol-map based converting too.
>>
>> E.g. without this fix, perf-probe failes to write the event.
>>   ----
>>   # perf probe vfs_caches_init_early
>>   Added new event:
>>   Failed to write event: Invalid argument
>>     Error: Failed to add events.
>>   ----
> 
> Well, here, after I applied 1/3 in this series, before this patch, I
> get:
> 
> 
> [root@zoo ~]# grep vfs_caches_init_early /proc/kallsyms 
> ffffffff81d8e60f T vfs_caches_init_early
> [root@zoo ~]# perf probe vfs_caches_init_early
> vfs_caches_init_early+0 is out of .text, skip it.
> Probe point 'vfs_caches_init_early' not found.
>   Error: Failed to add events.
> [root@zoo ~]#
> 
> What am I doind wrong? I am getting the message you said I should get after
> applying your patch, before I apply it... /me confused :-\

Hmm, right, I also checked you right. Maybe I misused bad binary
(of kernel?)... sorry about that.

Anyway, this patch is also fixing another bug to return error if
the symbol is blacklisted. I'll fix the comment and sort the bugs
out.

Thank you,

> 
> First patch applied, waiting for you on this and the next.
> 
> - Arnaldo
> 
>>
>> This fixes it to catch the error before adding probes.
>>   ----
>>   # perf probe vfs_caches_init_early
>>   vfs_caches_init_early is out of .text, skip it.
>>     Error: Failed to add events.
>>   ----
>>
>> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> ---
>>  tools/perf/util/probe-event.c |  113 ++++++++++++++++++++++++++---------------
>>  1 file changed, 71 insertions(+), 42 deletions(-)
>>
>> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
>> index c4ab588..85c8207 100644
>> --- a/tools/perf/util/probe-event.c
>> +++ b/tools/perf/util/probe-event.c
>> @@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs)
>>  		clear_probe_trace_event(tevs + i);
>>  }
>>  
>> +static bool kprobe_blacklist__listed(unsigned long address);
>> +static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
>> +{
>> +	/* Get the address of _etext for checking non-probable text symbol */
>> +	if (kernel_get_symbol_address_by_name("_etext", false) < address)
>> +		pr_warning("%s is out of .text, skip it.\n", symbol);
>> +	else if (kprobe_blacklist__listed(address))
>> +		pr_warning("%s is blacklisted function, skip it.\n", symbol);
>> +	else
>> +		return false;
>> +
>> +	return true;
>> +}
>> +
>>  #ifdef HAVE_DWARF_SUPPORT
>>  
>>  static int kernel_get_module_dso(const char *module, struct dso **pdso)
>> @@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
>>  					   bool uprobe)
>>  {
>>  	struct ref_reloc_sym *reloc_sym;
>> -	u64 etext_addr;
>>  	char *tmp;
>>  	int i, skipped = 0;
>>  
>> @@ -575,31 +588,28 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
>>  		pr_warning("Relocated base symbol is not found!\n");
>>  		return -EINVAL;
>>  	}
>> -	/* Get the address of _etext for checking non-probable text symbol */
>> -	etext_addr = kernel_get_symbol_address_by_name("_etext", false);
>>  
>>  	for (i = 0; i < ntevs; i++) {
>> -		if (tevs[i].point.address && !tevs[i].point.retprobe) {
>> -			/* If we found a wrong one, mark it by NULL symbol */
>> -			if (etext_addr < tevs[i].point.address) {
>> -				pr_warning("%s+%lu is out of .text, skip it.\n",
>> -				   tevs[i].point.symbol, tevs[i].point.offset);
>> -				tmp = NULL;
>> -				skipped++;
>> -			} else {
>> -				tmp = strdup(reloc_sym->name);
>> -				if (!tmp)
>> -					return -ENOMEM;
>> -			}
>> -			/* If we have no realname, use symbol for it */
>> -			if (!tevs[i].point.realname)
>> -				tevs[i].point.realname = tevs[i].point.symbol;
>> -			else
>> -				free(tevs[i].point.symbol);
>> -			tevs[i].point.symbol = tmp;
>> -			tevs[i].point.offset = tevs[i].point.address -
>> -					       reloc_sym->unrelocated_addr;
>> +		if (!tevs[i].point.address || tevs[i].point.retprobe)
>> +			continue;
>> +		/* If we found a wrong one, mark it by NULL symbol */
>> +		if (kprobe_warn_out_range(tevs[i].point.symbol,
>> +					  tevs[i].point.address)) {
>> +			tmp = NULL;
>> +			skipped++;
>> +		} else {
>> +			tmp = strdup(reloc_sym->name);
>> +			if (!tmp)
>> +				return -ENOMEM;
>>  		}
>> +		/* If we have no realname, use symbol for it */
>> +		if (!tevs[i].point.realname)
>> +			tevs[i].point.realname = tevs[i].point.symbol;
>> +		else
>> +			free(tevs[i].point.symbol);
>> +		tevs[i].point.symbol = tmp;
>> +		tevs[i].point.offset = tevs[i].point.address -
>> +				       reloc_sym->unrelocated_addr;
>>  	}
>>  	return skipped;
>>  }
>> @@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
>>  	return NULL;
>>  }
>>  
>> +static LIST_HEAD(kprobe_blacklist);
>> +
>> +static void kprobe_blacklist__init(void)
>> +{
>> +	if (!list_empty(&kprobe_blacklist))
>> +		return;
>> +
>> +	if (kprobe_blacklist__load(&kprobe_blacklist) < 0)
>> +		pr_debug("No kprobe blacklist support, ignored\n");
>> +}
>> +
>> +static void kprobe_blacklist__release(void)
>> +{
>> +	kprobe_blacklist__delete(&kprobe_blacklist);
>> +}
>> +
>> +static bool kprobe_blacklist__listed(unsigned long address)
>> +{
>> +	return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address);
>> +}
>> +
>>  static int perf_probe_event__sprintf(struct perf_probe_event *pev,
>>  				     const char *module,
>>  				     struct strbuf *result)
>> @@ -2409,8 +2440,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>>  	char buf[64];
>>  	const char *event, *group;
>>  	struct strlist *namelist;
>> -	LIST_HEAD(blacklist);
>> -	struct kprobe_blacklist_node *node;
>>  	bool safename;
>>  
>>  	if (pev->uprobes)
>> @@ -2430,28 +2459,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>>  		ret = -ENOMEM;
>>  		goto close_out;
>>  	}
>> -	/* Get kprobe blacklist if exists */
>> -	if (!pev->uprobes) {
>> -		ret = kprobe_blacklist__load(&blacklist);
>> -		if (ret < 0)
>> -			pr_debug("No kprobe blacklist support, ignored\n");
>> -	}
>>  
>>  	safename = (pev->point.function && !strisglob(pev->point.function));
>>  	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 (marked previously) */
>> +		/* Skip if the symbol is out of .text or blacklisted */
>>  		if (!tev->point.symbol)
>>  			continue;
>> -		/* Ensure that the address is NOT blacklisted */
>> -		node = kprobe_blacklist__find_by_address(&blacklist,
>> -							 tev->point.address);
>> -		if (node) {
>> -			pr_warning("Warning: Skipped probing on blacklisted function: %s\n", node->symbol);
>> -			continue;
>> -		}
>>  
>>  		if (pev->event)
>>  			event = pev->event;
>> @@ -2513,7 +2529,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
>>  			 tev->event);
>>  	}
>>  
>> -	kprobe_blacklist__delete(&blacklist);
>>  	strlist__delete(namelist);
>>  close_out:
>>  	close(fd);
>> @@ -2563,7 +2578,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>>  	struct perf_probe_point *pp = &pev->point;
>>  	struct probe_trace_point *tp;
>>  	int num_matched_functions;
>> -	int ret, i, j;
>> +	int ret, i, j, skipped = 0;
>>  
>>  	map = get_target_map(pev->target, pev->uprobes);
>>  	if (!map) {
>> @@ -2631,7 +2646,12 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>>  		}
>>  		/* Add one probe point */
>>  		tp->address = map->unmap_ip(map, sym->start) + pp->offset;
>> -		if (reloc_sym) {
>> +		/* If we found a wrong one, mark it by NULL symbol */
>> +		if (!pev->uprobes &&
>> +		    kprobe_warn_out_range(sym->name, tp->address)) {
>> +			tp->symbol = NULL;	/* Skip it */
>> +			skipped++;
>> +		} else if (reloc_sym) {
>>  			tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out);
>>  			tp->offset = tp->address - reloc_sym->addr;
>>  		} else {
>> @@ -2667,6 +2687,10 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
>>  		}
>>  		arch__fix_tev_from_maps(pev, tev, map);
>>  	}
>> +	if (ret == skipped) {
>> +		ret = -ENOENT;
>> +		goto err_out;
>> +	}
>>  
>>  out:
>>  	put_target_map(map, pev->uprobes);
>> @@ -2737,6 +2761,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
>>  	/* Loop 1: convert all events */
>>  	for (i = 0; i < npevs; i++) {
>>  		pkgs[i].pev = &pevs[i];
>> +		/* Init kprobe blacklist if needed */
>> +		if (!pkgs[i].pev->uprobes)
>> +			kprobe_blacklist__init();
>>  		/* Convert with or without debuginfo */
>>  		ret  = convert_to_probe_trace_events(pkgs[i].pev,
>>  						     &pkgs[i].tevs);
>> @@ -2744,6 +2771,8 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
>>  			goto end;
>>  		pkgs[i].ntevs = ret;
>>  	}
>> +	/* This just release blacklist only if allocated */
>> +	kprobe_blacklist__release();
>>  
>>  	/* Loop 2: add all events */
>>  	for (i = 0; i < npevs; i++) {
> 


-- 
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu.pt@hitachi.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip:perf/core] perf probe: List probes in stdout
  2015-06-13  1:31 ` [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout Masami Hiramatsu
@ 2015-06-18  8:13   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2015-06-18  8:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, tglx, hpa, jolsa, peterz, masami.hiramatsu.pt, naota,
	linux-kernel, dsahern, namhyung, mingo

Commit-ID:  ba7ecb02e7b89b09d8cdf4c1514a386af8916c4b
Gitweb:     http://git.kernel.org/tip/ba7ecb02e7b89b09d8cdf4c1514a386af8916c4b
Author:     Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Sat, 13 Jun 2015 10:31:16 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 16 Jun 2015 10:34:39 -0300

perf probe: List probes in stdout

Since commit 5e17b28f1e24 ("perf probe: Add --quiet option to
suppress output result message") have replaced printf with pr_info,
perf probe -l outputs its result in stderr. However, that is not
what the commit expected.

E.g.:

  # perf probe -l > /dev/null
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)

With this fix:

  # perf probe -l > list
  # cat list
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)

Of course, --quiet(-q) still works on --add/--del.

  # perf probe -q vfs_write
  # perf probe -l
    probe:vfs_read       (on vfs_read@ksrc/linux-3/fs/read_write.c)
    probe:vfs_write      (on vfs_write@ksrc/linux-3/fs/read_write.c)
  -----

Reported-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150613013116.24402.2923.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 49 ++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index daa24a2..c4ab588 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2126,9 +2126,9 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
 	return NULL;
 }
 
-/* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
-				 const char *module)
+static int perf_probe_event__sprintf(struct perf_probe_event *pev,
+				     const char *module,
+				     struct strbuf *result)
 {
 	int i, ret;
 	char buf[128];
@@ -2141,27 +2141,47 @@ static int show_perf_probe_event(struct perf_probe_event *pev,
 
 	ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
 	if (ret < 0)
-		return ret;
+		goto out;
 
-	pr_info("  %-20s (on %s", buf, place);
+	strbuf_addf(result, "  %-20s (on %s", buf, place);
 	if (module)
-		pr_info(" in %s", module);
+		strbuf_addf(result, " in %s", module);
 
 	if (pev->nargs > 0) {
-		pr_info(" with");
+		strbuf_addstr(result, " with");
 		for (i = 0; i < pev->nargs; i++) {
 			ret = synthesize_perf_probe_arg(&pev->args[i],
 							buf, 128);
 			if (ret < 0)
-				break;
-			pr_info(" %s", buf);
+				goto out;
+			strbuf_addf(result, " %s", buf);
 		}
 	}
-	pr_info(")\n");
+	strbuf_addch(result, ')');
+out:
 	free(place);
 	return ret;
 }
 
+/* Show an event */
+static int show_perf_probe_event(struct perf_probe_event *pev,
+				 const char *module, bool use_stdout)
+{
+	struct strbuf buf = STRBUF_INIT;
+	int ret;
+
+	ret = perf_probe_event__sprintf(pev, module, &buf);
+	if (ret >= 0) {
+		if (use_stdout)
+			printf("%s\n", buf.buf);
+		else
+			pr_info("%s\n", buf.buf);
+	}
+	strbuf_release(&buf);
+
+	return ret;
+}
+
 static bool filter_probe_trace_event(struct probe_trace_event *tev,
 				     struct strfilter *filter)
 {
@@ -2200,9 +2220,10 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
 				goto next;
 			ret = convert_to_perf_probe_event(&tev, &pev,
 								is_kprobe);
-			if (ret >= 0)
-				ret = show_perf_probe_event(&pev,
-							    tev.point.module);
+			if (ret < 0)
+				goto next;
+			ret = show_perf_probe_event(&pev, tev.point.module,
+						    true);
 		}
 next:
 		clear_perf_probe_event(&pev);
@@ -2468,7 +2489,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 		group = pev->group;
 		pev->event = tev->event;
 		pev->group = tev->group;
-		show_perf_probe_event(pev, tev->point.module);
+		show_perf_probe_event(pev, tev->point.module, false);
 		/* Trick here - restore current event/group */
 		pev->event = (char *)event;
 		pev->group = (char *)group;

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-18  8:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-13  1:31 [PATCH perf/core v2 0/3] perf-probe bugfixes Masami Hiramatsu
2015-06-13  1:31 ` [PATCH perf/core v2 1/3] [BUGFIX] perf probe: List probes in stdout Masami Hiramatsu
2015-06-18  8:13   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2015-06-13  1:31 ` [PATCH perf/core v2 2/3] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map Masami Hiramatsu
2015-06-15 18:57   ` Arnaldo Carvalho de Melo
2015-06-16 11:10     ` Masami Hiramatsu
2015-06-13  1:31 ` [PATCH perf/core v2 3/3] [BUGFIX] perf probe: Show usage even if the last event is skipped Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.